| | |
| | | // 是否有真实合同 |
| | | contractNumber.append(newTrueContract); |
| | | } |
| | | if (oldSignYear.equals(newSignYear)) { |
| | | contractNumber.append(resources.getContractNumber().substring(15)); |
| | | } else { |
| | | // 全部公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | Long allCompanySort = contractRepository.countAllContractSort(String.valueOf(calendar.get(Calendar.YEAR)), resources.getContractId()); |
| | | contractNumber.append(String.format("%04d", (allCompanySort == null ? 0L : allCompanySort) + 1)); |
| | | } |
| | | // 全部公司当年编号(以签订日期为准) |
| | | // TODO:250115业务方提出修改为以创建日期为准 |
| | | contractNumber.append(resources.getContractNumber().substring(15)); |
| | | |
| | | if (resources.getContractNumber().equals(contractNumber.toString())) { |
| | | return resources; |
| | |
| | | contractNumber.append("Y"); |
| | | } |
| | | // 全部公司当年编号(以签订日期为准)(因先存后改故排除本身数据) |
| | | // TODO:250115业务方提出修改为以创建日期为准 |
| | | calendar.setTime(resources.getCreateTime()); |
| | | Long allCompanySort = contractRepository.countAllContractSort(String.valueOf(calendar.get(Calendar.YEAR)), resources.getContractId()); |
| | | contractNumber.append(String.format("%04d", (allCompanySort == null ? 0L : allCompanySort) + 1)); |
| | | |
| | |
| | | Map<String, Long> secondMap = contractSecondRepository.findAll().stream().collect(Collectors.toMap(ContractSecond::getSecondName, ContractSecond::getSecondId)); |
| | | Map<String, Long> companyMap = sysCompanyRepository.findAll().stream().collect(Collectors.toMap(SysCompany::getLabel, SysCompany::getId)); |
| | | Map<String, String> provinceMap = chinaAreaMap.get("86").entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat useSdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00"); |
| | | int rowNum = 1; |
| | | |
| | | for (Map<String,Object> row: readAll) { |
| | |
| | | contract.setContractArea(contractArea); |
| | | // 合同所属地区编码 |
| | | int finalRowNum = rowNum; |
| | | String contractAreaCode = Arrays.stream(contractArea.split("/")).filter(item -> StringUtils.isNotBlank(item)).reduce("", (concatStr, itemStr) -> { |
| | | if (concatStr.length() == 0) { |
| | | return provinceMap.get(itemStr); |
| | | } else { |
| | | if (itemStr.equals("本级")) { |
| | | return concatStr; |
| | | try { |
| | | String contractAreaCode = Arrays.stream(contractArea.split("/")).filter(item -> StringUtils.isNotBlank(item)).reduce("", (concatStr, itemStr) -> { |
| | | if (concatStr.length() == 0) { |
| | | return provinceMap.get(itemStr); |
| | | } else { |
| | | List<String> contractAreaCodeList = Arrays.stream(concatStr.split("/")).collect(Collectors.toList()); |
| | | String superAreaCode = contractAreaCodeList.get(contractAreaCodeList.size() - 1); |
| | | Map<String, String> superAreaMap = chinaAreaMap.get(superAreaCode).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); |
| | | if (superAreaMap.containsKey(itemStr)) { |
| | | return concatStr.concat("/").concat(superAreaMap.get(itemStr)); |
| | | } else { |
| | | String newKey = "合同所属地区编码校验未通过"; |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(finalRowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | if (itemStr.equals("本级")) { |
| | | return concatStr; |
| | | } else { |
| | | List<String> contractAreaCodeList = Arrays.stream(concatStr.split("/")).collect(Collectors.toList()); |
| | | String superAreaCode = contractAreaCodeList.get(contractAreaCodeList.size() - 1); |
| | | Map<String, String> superAreaMap = chinaAreaMap.get(superAreaCode).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); |
| | | if (superAreaMap.containsKey(itemStr)) { |
| | | return concatStr.concat("/").concat(superAreaMap.get(itemStr)); |
| | | } else { |
| | | customizeErrorColumn("合同所属地区编码校验未通过", finalRowNum, errorMap); |
| | | return concatStr; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | contract.setContractAreaCode(contractAreaCode); |
| | | }); |
| | | contract.setContractAreaCode(contractAreaCode); |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("合同所属地区输入错误", rowNum, errorMap); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "合同类型", rowNum, errorMap) && checkTypeColumn(row, "合同类型", rowNum, errorMap)) { |
| | | contract.setContractType(ElAdminConstant.Enum.ContractTypeDict.findByImportValue(row.get("合同类型").toString()).getDictValue()); |
| | |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("开票总金额"))) { |
| | | // billingTotalAmount(计算) |
| | | invoice.setBeforeTaxAmount(new BigDecimal(row.get("开票总金额").toString())); |
| | | invoice.setAfterTaxAmount(new BigDecimal(row.get("开票总金额").toString())); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("开票日期"))) { |
| | | // billingTime |
| | | invoice.setBillingTime(Timestamp.valueOf(row.get("开票日期").toString())); |
| | | |
| | | if (checkRequiredColumn(row, "开票日期", rowNum, errorMap)) { |
| | | // billingTime |
| | | try { |
| | | invoice.setBillingTime(Timestamp.valueOf(row.get("开票日期").toString())); |
| | | } catch (IllegalArgumentException illegalArgumentException) { |
| | | try { |
| | | // 仅日期转换问题再次尝试 |
| | | invoice.setBillingTime(Timestamp.valueOf(useSdf.format(sdf.parse(row.get("开票日期").toString())))); |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("开票日期输入错误", rowNum, errorMap); |
| | | } |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("开票日期输入错误", rowNum, errorMap); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "税前开票金额", rowNum, errorMap)) { |
| | | // beforeTaxAmount |
| | | invoice.setBeforeTaxAmount(new BigDecimal(row.get("税前开票金额").toString())); |
| | | |
| | | if (ObjectUtil.isNotEmpty(row.get("税率"))) { |
| | | // taxRate |
| | | invoice.setTaxRate(new BigDecimal(row.get("税率").toString()).multiply(new BigDecimal(100)).doubleValue()); |
| | | invoice.setTaxAmount(new BigDecimal(row.get("税前开票金额").toString()).multiply(new BigDecimal(row.get("税率").toString()))); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "发票类型", rowNum, errorMap) && checkTypeColumn(row, "发票类型", rowNum, errorMap)) { |
| | | // invoiceType |
| | | if (row.get("发票类型").toString().equals("增值税普通发票")) { |
| | | invoice.setInvoiceType(Constant.INVOICE_TYPE_ORDINARY); |
| | | } else if (row.get("发票类型").toString().equals("增值税专用发票")) { |
| | | invoice.setInvoiceType(Constant.INVOICE_TYPE_SPECIAL); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("开票备注"))) { |
| | | // remarks |
| | | invoice.setRemarks(row.get("开票备注").toString()); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("付款总金额"))) { |
| | | // paymentTotalAmount(计算) |
| | | payment.setPaymentAmount(new BigDecimal(row.get("付款总金额").toString())); |
| | | // NOTE:暂定算为合同收入,PaymentType为无处使用字段,此行代码仅为通过验证,可删除 |
| | | payment.setPaymentType(Constant.CONTRACR_REVENUE); |
| | | |
| | | if (checkRequiredColumn(row, "付款时间", rowNum, errorMap)) { |
| | | // paymentTime(合同付款信息) |
| | | try { |
| | | payment.setPaymentTime(Timestamp.valueOf(row.get("付款时间").toString())); |
| | | } catch (IllegalArgumentException illegalArgumentException) { |
| | | try { |
| | | // 仅日期转换问题再次尝试 |
| | | payment.setPaymentTime(Timestamp.valueOf(useSdf.format(sdf.parse(row.get("付款时间").toString())))); |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("付款时间输入错误", rowNum, errorMap); |
| | | } |
| | | } catch (Exception e) { |
| | | customizeErrorColumn("付款时间输入错误", rowNum, errorMap); |
| | | } |
| | | } |
| | | if (checkRequiredColumn(row, "付款类型", rowNum, errorMap) && checkTypeColumn(row, "付款类型", rowNum, errorMap)) { |
| | | // fundType |
| | | if (row.get("付款类型").toString().equals("服务费")) { |
| | | payment.setFundType(Constant.FUND_SERVICE); |
| | | |
| | | if (checkRequiredColumn(row, "服务费开始时间", rowNum, errorMap)) { |
| | | // fundBelongStart |
| | | payment.setFundBelongStart(Timestamp.valueOf(row.get("服务费开始时间").toString())); |
| | | } |
| | | if (checkRequiredColumn(row, "服务费结束时间", rowNum, errorMap)) { |
| | | // fundBelongEnd |
| | | payment.setFundBelongEnd(Timestamp.valueOf(row.get("服务费结束时间").toString())); |
| | | } |
| | | } else if (row.get("付款类型").toString().equals("合同费")) { |
| | | payment.setFundType(Constant.FUND_CONTRACT); |
| | | |
| | | if (ObjectUtil.isNotEmpty(row.get("合同费所属"))) { |
| | | // fundBelong |
| | | payment.setFundBelong(row.get("合同费所属").toString()); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("付款备注"))) { |
| | | // remarks |
| | | payment.setRemarks(row.get("付款备注").toString()); |
| | | } |
| | | } |
| | | } |
| | | // if (checkRequiredColumn(row, "预收款金额", rowNum, errorMap)) { |
| | | // // advancePayment(计算) |
| | |
| | | contract.setContractPaymentState(Constant.PAYMENT_ALREADY); |
| | | } |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotEmpty(row.get("付款时间"))) { |
| | | // paymentTime(合同付款信息) |
| | | payment.setPaymentTime(Timestamp.valueOf(row.get("付款时间").toString())); |
| | | } |
| | | // if (checkRequiredColumn(row, "合同费延期情况", rowNum, errorMap)) { |
| | | // // contractPostponement |
| | |
| | | } |
| | | |
| | | Map<String, Object> supplyMapData = new HashMap<>(); |
| | | if (ObjectUtil.isNotEmpty(invoice.getBeforeTaxAmount())) { |
| | | if (ObjectUtil.isNotEmpty(invoice.getAfterTaxAmount())) { |
| | | supplyMapData.put("invoice", invoice); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(payment.getPaymentAmount())) { |
| | |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else if (key.equals("发票类型")) { |
| | | if (data.get(key).toString().equals("增值税普通发票") || data.get(key).toString().equals("增值税专用发票")) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else if (key.equals("付款类型")) { |
| | | if (data.get(key).toString().equals("服务费") || data.get(key).toString().equals("合同费")) { |
| | | return true; |
| | | } else { |
| | | String newKey = key.concat("输入错误"); |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(newKey, errorRows); |
| | | return false; |
| | | } |
| | | } else { |
| | | String newKey = "校验类型不存在"; |
| | | List<Integer> errorRows = errorMap.containsKey(newKey) ? errorMap.get(newKey) : new ArrayList<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | private Boolean customizeErrorColumn(String key, Integer rowNum, Map<String, List<Integer>> errorMap) { |
| | | List<Integer> errorRows = errorMap.containsKey(key) ? errorMap.get(key) : new ArrayList<>(); |
| | | errorRows.add(rowNum); |
| | | errorMap.put(key, errorRows); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 预警 |
| | | * |