| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.importData.Vtil; |
| | | import com.java110.dto.log.AssetImportLogDetailDto; |
| | | import com.java110.dto.msg.MaintenancePaymentPo; |
| | | import com.java110.dto.msg.MpFifthPaymentRecordPo; |
| | |
| | | String flowNumber = getCellValue(cellArray, 1); // 第2列:流转编号 |
| | | String projectName = getCellValue(cellArray, 4); // 第5列:项目名称 |
| | | String ownersCommitteeAmountStr = getCellValue(cellArray, 12); // 第13列:业委会金额 |
| | | if (isBlank(flowNumber) || isBlank(projectName) || isBlank(ownersCommitteeAmountStr)) { |
| | | throw new IllegalArgumentException( |
| | | String.format("核心字段缺失:流转编号[%s]、项目名称[%s]、业委会金额[%s]", |
| | | flowNumber, projectName, ownersCommitteeAmountStr) |
| | | ); |
| | | if (Vtil.defaultValue(getCellValue(cellArray, 1)).equals("")) { |
| | | continue; |
| | | } |
| | | AnnouncementTimeRangePo announcementTimeRangePo = null; |
| | | OwnersCommitteeConventionPo ocoPo = null; |
| | |
| | | |
| | | // 3. 构建3张表的PO对象(字段映射+业务计算) |
| | | MaintenancePayment mainPo = buildMaintenancePaymentPoV2(cellArray);//主表 |
| | | if (!getCellValue(cellArray, 22).isEmpty() && !getCellValue(cellArray, 23).isEmpty()) { |
| | | announcementTimeRangePo = buildAnnouncementTimeRangePo(cellArray, Long.valueOf(mainPo.getId()));//公共收益金 |
| | | } |
| | | if (!getCellValue(cellArray, 26).isEmpty() && !getCellValue(cellArray, 27).isEmpty()) { |
| | | ocoPo = buildOwnersCommitteeConventionPo(cellArray, Long.valueOf(mainPo.getId())); |
| | | } |
| | | if (!getCellValue(cellArray, 29).isEmpty()) { |
| | | owiPo = buildOwnerWithdrawalInfoPo(cellArray, Long.valueOf(mainPo.getId())); |
| | | } |
| | | if (!getCellValue(cellArray, 39).isEmpty()) { |
| | | oqgPo = buildOwnerQualityGuaranteePo(cellArray, Long.valueOf(mainPo.getId())); |
| | | } |
| | | List<MpPaymentRecordPo> paymentRecordPos = buildMpPaymentRecordPos(cellArray, mainPo.getFlowNumber(), String.valueOf(mainPo.getId())); |
| | | List<MpFifthPaymentRecord> fifthPos = buildMpFifthPaymentRecordPos(cellArray, mainPo.getFlowNumber(), String.valueOf(mainPo.getId())); |
| | | if (!getCellValue(cellArray, 137).isEmpty()) { |
| | | ownerRemarkInfoPo = buildOwnerRemarkInfoPo(cellArray, mainPo.getFlowNumber(), String.valueOf(mainPo.getId())); |
| | | } |
| | | // if (!getCellValue(cellArray, 22).isEmpty() && !getCellValue(cellArray, 23).isEmpty()) { |
| | | announcementTimeRangePo = buildAnnouncementTimeRangePo(cellArray, mainPo.getId());//公共收益金 |
| | | // } |
| | | // if (!getCellValue(cellArray, 26).isEmpty() && !getCellValue(cellArray, 27).isEmpty()) { |
| | | ocoPo = buildOwnersCommitteeConventionPo(cellArray, mainPo.getId()); |
| | | // } |
| | | // if (!getCellValue(cellArray, 29).isEmpty()) { |
| | | owiPo = buildOwnerWithdrawalInfoPo(cellArray, mainPo.getId()); |
| | | // } |
| | | // if (!getCellValue(cellArray, 39).isEmpty()) { |
| | | oqgPo = buildOwnerQualityGuaranteePo(cellArray, mainPo.getId()); |
| | | // } |
| | | List<MpPaymentRecordPo> paymentRecordPos = buildMpPaymentRecordPos(cellArray, mainPo.getFlowNumber(), mainPo.getId()); |
| | | List<MpFifthPaymentRecord> fifthPos = buildMpFifthPaymentRecordPos(cellArray, mainPo.getFlowNumber(), mainPo.getId()); |
| | | // if (!getCellValue(cellArray, 137).isEmpty()) { |
| | | ownerRemarkInfoPo = buildOwnerRemarkInfoPo(cellArray, mainPo.getFlowNumber(), mainPo.getId()); |
| | | // } |
| | | |
| | | importData(mainPo, announcementTimeRangePo, ocoPo, owiPo, oqgPo, paymentRecordPos, fifthPos, ownerRemarkInfoPo); |
| | | |
| | | // 5. 更新导入日志状态(成功)- 调用父类方法 |
| | | super.updateImportLogDetailState(logDetailDto.getDetailId()); |
| | | |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new IllegalArgumentException(e.getMessage()); |
| | | } |
| | |
| | | return po; |
| | | } |
| | | |
| | | private OwnerQualityGuaranteePo buildOwnerQualityGuaranteePo(JSONArray cellArray, Long aLong) { |
| | | private OwnerQualityGuaranteePo buildOwnerQualityGuaranteePo(JSONArray cellArray, String aLong) { |
| | | OwnerQualityGuaranteePo po = new OwnerQualityGuaranteePo(); |
| | | long longId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; // 避免负数 |
| | | po.setId(longId); // 主键ID |
| | | po.setMpId(aLong.toString()); |
| | | try { |
| | | po.setQualityGuaranteePeriod2Start(parseDateToString(getCellValue(cellArray, 37))); |
| | | po.setQualityGuaranteePeriod2End(parseDateToString(getCellValue(cellArray, 38))); |
| | | po.setAcceptanceDate(parseDateToString(getCellValue(cellArray, 41))); |
| | | po.setAvailableWithdrawalDate(parseDate(getCellValue(cellArray, 43))); |
| | | } catch (ParseException e) { |
| | | throw new RuntimeException("日期转换错误"); |
| | | } |
| | | po.setMpId(aLong); |
| | | po.setQualityGuaranteePeriod2Start(Vtil.defaultValueToDate(getCellValue(cellArray, 37))); |
| | | po.setQualityGuaranteePeriod2End(Vtil.defaultValueToDate(getCellValue(cellArray, 38))); |
| | | po.setAcceptanceDate(Vtil.defaultValueToDate(getCellValue(cellArray, 41))); |
| | | po.setAvailableWithdrawalDate(Vtil.defaultValueToDate(getCellValue(cellArray, 43))); |
| | | po.setQualityGuaranteeRatio(getCellNum(cellArray, 39)); |
| | | po.setQualityGuaranteeAmount(getCellNum(cellArray, 12) * po.getQualityGuaranteeRatio()); |
| | | po.setAuditStatus(getCellValue(cellArray, 42)); |
| | | return po; |
| | | } |
| | | |
| | | private OwnerWithdrawalInfoPo buildOwnerWithdrawalInfoPo(JSONArray cellArray, Long aLong) { |
| | | private OwnerWithdrawalInfoPo buildOwnerWithdrawalInfoPo(JSONArray cellArray, String aLong) { |
| | | OwnerWithdrawalInfoPo po = new OwnerWithdrawalInfoPo(); |
| | | long longId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; // 避免负数 |
| | | po.setId(longId); // 主键ID |
| | | po.setMpId(aLong.toString()); |
| | | po.setMpId(aLong); |
| | | po.setWithdrawalEncounteredProblem(getCellValue(cellArray, 28)); |
| | | po.setShortageOrArrears(getCellNum(cellArray, 29)); |
| | | po.setRoadName(getCellValue(cellArray, 30)); |
| | |
| | | return po; |
| | | } |
| | | |
| | | private OwnersCommitteeConventionPo buildOwnersCommitteeConventionPo(JSONArray cellArray, Long mpId) { |
| | | private OwnersCommitteeConventionPo buildOwnersCommitteeConventionPo(JSONArray cellArray, String mpId) { |
| | | OwnersCommitteeConventionPo po = new OwnersCommitteeConventionPo(); |
| | | |
| | | long longId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; // 避免负数 |
| | |
| | | return po; |
| | | } |
| | | |
| | | private AnnouncementTimeRangePo buildAnnouncementTimeRangePo(JSONArray cellArray, Long mpId) { |
| | | private AnnouncementTimeRangePo buildAnnouncementTimeRangePo(JSONArray cellArray, String mpId) { |
| | | AnnouncementTimeRangePo po = new AnnouncementTimeRangePo(); |
| | | long longId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; // 避免负数 |
| | | po.setId(longId); // 主键ID |
| | |
| | | po.setReportDepartment(getCellValue(cellArray, 15)); // 第16列:签报部门 |
| | | po.setFundTypeLevel1(getCellValue(cellArray, 16)); // 第17列:基金类型-一级分类 |
| | | po.setFundTypeLevel2(getCellValue(cellArray, 17)); // 第18列:基金类型-二级分类 |
| | | po.setMaintenanceType(getCellValue(cellArray, 18)); // 第19列:幢/全体 |
| | | po.setBuildingOrAll(getCellValue(cellArray, 19)); // 第20列:维修类型 |
| | | po.setMaintenanceType(getCellValue(cellArray, 19)); // 第19列:幢/全体 |
| | | po.setBuildingOrAll(getCellValue(cellArray, 18)); // 第20列:维修类型 |
| | | po.setPayeeName(getCellValue(cellArray, 145)); // 支付公司名称/个人名字 |
| | | po.setIdCardNumber(getCellValue(cellArray, 146)); // 个人身份证号码 |
| | | po.setBankName(getCellValue(cellArray, 147)); // 开户银行 |
| | |
| | | po.setBuildingOrAll(getCellValue(cellArray, 18)); // 第19列:幢/全体 |
| | | po.setMaintenanceType(getCellValue(cellArray, 19)); // 第20列:维修类型 |
| | | po.setQualityGuaranteePeriod1(getCellValue(cellArray, 20)); // 第21列:质保期(第一个) |
| | | po.setPublicIncomeAnnouncement(getCellValue(cellArray, 21)); // 第22列:公共收益金公布情况 |
| | | // po.setPublicIncomeAnnouncement(getCellValue(cellArray, 21)); // 第22列:公共收益金公布情况 |
| | | // 公共收益金公布子字段(第23-26列) |
| | | po.setPlannedAnnouncementStart(getCellValue(cellArray, 21)); // 拟公布-起始(年月) |
| | | po.setPlannedAnnouncementEnd(getCellValue(cellArray, 22)); // 拟公布-止(年月) |
| | |
| | | po.setDoorRoomNumber(getCellValue(cellArray, 34)); // 门室号 |
| | | po.setOwnerAddress(getCellValue(cellArray, 35)); // 业主地址 |
| | | // po.setWithdrawalProblem(getCellValue(cellArray, 36)); // 第38列:支取存在问题 |
| | | po.setProblemDifficulty(getCellValue(cellArray, 36)); // 第39列:问题难度 |
| | | po.setAvailableWithdrawalDate(parseDate(getCellValue(cellArray, 37))); // 第40列:可启动支取日期(年月日) |
| | | po.setQualityGuaranteePeriod2(getCellValue(cellArray, 39) + "~" + getCellValue(cellArray, 40)); // 第41列:质保期(第二个) |
| | | po.setQualityGuaranteeRatio(parseBigDecimal(getCellValue(cellArray, 40))); // 第42列:质保金占比 |
| | | po.setQualityGuaranteeAmount(parseBigDecimal(getCellValue(cellArray, 41))); // 第43列:质保金金额(元) |
| | | po.setReceivedQualityGuarantee(parseBigDecimal(getCellValue(cellArray, 42))); // 第44列:已到账质保金 |
| | | po.setProblemDifficulty(getCellValue(cellArray, 36)); // 第36列:问题难度 |
| | | po.setAvailableWithdrawalDate(parseDate(getCellValue(cellArray, 43))); // 第40列:可启动支取日期(年月日) |
| | | po.setQualityGuaranteePeriod2(getCellValue(cellArray, 37) + "~" + getCellValue(cellArray, 38)); // 第41列:质保期(第二个) |
| | | po.setQualityGuaranteeRatio(parseBigDecimal(getCellValue(cellArray, 39))); // 第42列:质保金占比 |
| | | po.setQualityGuaranteeAmount(parseBigDecimal(getCellValue(cellArray, 40))); // 第43列:质保金金额(元) |
| | | po.setReceivedQualityGuarantee(parseBigDecimal(getCellValue(cellArray, 44))); // 第44列:已到账质保金 |
| | | // po.setStartDate(parseDate(getCellValue(cellArray, 44))); // 第45列:起始(年月日) |
| | | // po.setEndDate(parseDate(getCellValue(cellArray, 45))); // 第46列:终止(年月日) |
| | | |
| | | // -------------------------- 17个自动计算字段(核心业务逻辑)-------------------------- |
| | | // 1. 打印合计 = 第一次~第五次打印金额之和(第47列打印金额+第54列+第61列+第68列+第75列) |
| | | BigDecimal print1 = parseBigDecimal(getCellValue(cellArray, 45)); // 第一次打印金额(第50列) |
| | | BigDecimal print2 = parseBigDecimal(getCellValue(cellArray, 57)); // 第二次打印金额(第57列) |
| | | BigDecimal print3 = parseBigDecimal(getCellValue(cellArray, 69)); // 第三次打印金额(第64列) |
| | | BigDecimal print4 = parseBigDecimal(getCellValue(cellArray, 81)); // 第四次打印金额(第71列) |
| | | BigDecimal print5 = parseBigDecimal(getCellValue(cellArray, 93)); // 第五次打印金额(第78列) |
| | | // BigDecimal printTotal = add(print1, print2, print3, print4, print5); |
| | | // po.setPrintTotal(printTotal); // 自定义字段:打印合计 |
| | | |
| | | // 2. 到账合计 = 第一次~第五次到账金额之和(第51列+第58列+第65列+第72列+第79列) |
| | | BigDecimal arrival1 = parseBigDecimal(getCellValue(cellArray, 48)); // 第一次到账金额(第52列) |
| | | BigDecimal arrival2 = parseBigDecimal(getCellValue(cellArray, 60)); // 第二次到账金额(第59列) |
| | | BigDecimal arrival3 = parseBigDecimal(getCellValue(cellArray, 72)); // 第三次到账金额(第66列) |
| | | BigDecimal arrival4 = parseBigDecimal(getCellValue(cellArray, 84)); // 第四次到账金额(第73列) |
| | | BigDecimal arrival5 = parseBigDecimal(getCellValue(cellArray, 96)); // 第五次到账金额(第80列) |
| | | // BigDecimal arrivalTotal = add(arrival1, arrival2, arrival3, arrival4, arrival5); |
| | | // po.setArrivalTotal(arrivalTotal); // 自定义字段:到账合计 |
| | | |
| | | // 3. 维修基金到账率 = IF(到账合计<>0, 到账合计/业委会金额, 0) |
| | | BigDecimal ownersAmount = po.getOwnersCommitteeAmount(); |
| | | // BigDecimal fundArrivalRate = (arrivalTotal.compareTo(BigDecimal.ZERO) != 0 && ownersAmount.compareTo(BigDecimal.ZERO) != 0) |
| | | // ? arrivalTotal.divide(ownersAmount, 4, BigDecimal.ROUND_HALF_UP) // 保留4位小数 |
| | | // : BigDecimal.ZERO; |
| | | // po.setFundArrivalRate(fundArrivalRate); // 自定义字段:维修基金到账率 |
| | | |
| | | // 4. 尚缺金额 = IF(基金类型<>"维修基金", 0, 业委会金额-到账合计) |
| | | String fundType = po.getFundTypeLevel1(); |
| | | // BigDecimal shortageAmount = ("维修基金".equals(fundType)) |
| | | // ? subtract(ownersAmount, arrivalTotal) |
| | | // : BigDecimal.ZERO; |
| | | // po.setFundShortageAmount(shortageAmount); // 自定义字段:尚缺金额 |
| | | |
| | | // 5. 管理费 = 管理处金额 * 管理费占比(百分比转小数) |
| | | BigDecimal managementFeeRatio = po.getManagementFeeRatio() == null ? BigDecimal.ZERO : po.getManagementFeeRatio().divide(new BigDecimal(100)); |
| | | BigDecimal managementFee = multiply(po.getManagementOfficeAmount(), managementFeeRatio); |
| | | // po.setManagementFee(managementFee); // 自定义字段:管理费 |
| | | |
| | | // 6. 应付金额A = IF(审计金额为空, 业委会金额-管理费, 审计金额-管理费) |
| | | BigDecimal auditAmount = po.getAuditAmount() == null ? BigDecimal.ZERO : po.getAuditAmount(); |
| | | BigDecimal payableA = (auditAmount.compareTo(BigDecimal.ZERO) == 0) |
| | | ? subtract(ownersAmount, managementFee) |
| | | : subtract(auditAmount, managementFee); |
| | | // po.setPayableAmountA(payableA); // 自定义字段:应付金额A |
| | | |
| | | // 7. 应付金额B = 业委会金额-管理费-质保金金额 |
| | | BigDecimal qualityGuaranteeAmount = po.getQualityGuaranteeAmount() == null ? BigDecimal.ZERO : po.getQualityGuaranteeAmount(); |
| | | BigDecimal payableB = subtract(ownersAmount, managementFee, qualityGuaranteeAmount); |
| | | // po.setPayableAmountB(payableB); // 自定义字段:应付金额B |
| | | |
| | | // 8. 应付金额C = 实收金额-实收金额×管理费比例(实收金额取到账合计) |
| | | // BigDecimal payableC = multiply(arrivalTotal, BigDecimal.ONE.subtract(managementFeeRatio)); |
| | | // po.setPayableAmountC(payableC); // 自定义字段:应付金额C |
| | | |
| | | // 9. 拟付合计 = 第一次~第五次拟付金额之和(第82列+第88列+第94列+第100列+第106列) |
| | | BigDecimal plannedPay1 = parseBigDecimal(getCellValue(cellArray, 113)); // 第一次拟付金额(第83列) |
| | | BigDecimal plannedPay2 = parseBigDecimal(getCellValue(cellArray, 119)); // 第二次拟付金额(第89列) |
| | | BigDecimal plannedPay3 = parseBigDecimal(getCellValue(cellArray, 125)); // 第三次拟付金额(第95列) |
| | | BigDecimal plannedPay4 = parseBigDecimal(getCellValue(cellArray, 131)); // 第四次拟付金额(第101列) |
| | | BigDecimal plannedPay5 = parseBigDecimal(getCellValue(cellArray, 137)); // 第五次拟付金额(第107列) |
| | | BigDecimal plannedPayTotal = add(plannedPay1, plannedPay2, plannedPay3, plannedPay4, plannedPay5); |
| | | // po.setPlannedPayTotal(plannedPayTotal); // 自定义字段:拟付合计 |
| | | |
| | | // 10. 实付合计 = 第一次~第五次实付金额之和(第85列+第91列+第97列+第103列+第109列) |
| | | BigDecimal actualPay1 = parseBigDecimal(getCellValue(cellArray, 117)); // 第一次实付金额(第86列) |
| | | BigDecimal actualPay2 = parseBigDecimal(getCellValue(cellArray, 123)); // 第二次实付金额(第92列) |
| | | BigDecimal actualPay3 = parseBigDecimal(getCellValue(cellArray, 130)); // 第三次实付金额(第98列) |
| | | BigDecimal actualPay4 = parseBigDecimal(getCellValue(cellArray, 135)); // 第四次实付金额(第104列) |
| | | BigDecimal actualPay5 = parseBigDecimal(getCellValue(cellArray, 141)); // 第五次实付金额(第110列) |
| | | BigDecimal actualPayTotal = add(actualPay1, actualPay2, actualPay3, actualPay4, actualPay5); |
| | | // po.setActualPayTotal(actualPayTotal); // 自定义字段:实付合计 |
| | | |
| | | // 11. 未付合计 = 审定金额-实付合计(审定金额取审计金额,无则取业委会金额) |
| | | BigDecimal approvedAmount = (auditAmount.compareTo(BigDecimal.ZERO) == 0) ? ownersAmount : auditAmount; |
| | | BigDecimal unpaidTotal = subtract(approvedAmount, actualPayTotal); |
| | | // po.setUnpaidTotal(unpaidTotal); // 自定义字段:未付合计 |
| | | |
| | | // 12. 垫付金额 = 复杂条件判断(基金类型、到账合计、公布情况) |
| | | // BigDecimal advanceAmount = calculateAdvanceAmount(fundType, arrivalTotal, actualPayTotal, po.getPublicIncomeAnnouncement()); |
| | | // po.setAdvanceAmount(advanceAmount); // 自定义字段:垫付金额 |
| | | |
| | | // 13. 未付合计(到账口径) = 按公布情况分支计算 |
| | | // BigDecimal unpaidByArrival = calculateUnpaidByArrival(po.getPublicIncomeAnnouncement(), ownersAmount, managementFee, actualPayTotal, arrivalTotal); |
| | | // po.setUnpaidByArrival(unpaidByArrival); // 自定义字段:未付合计(到账口径) |
| | | |
| | | // 14-16. 待付金额A/B/C |
| | | // po.setPendingPayA(subtract(auditAmount, managementFee)); // 待付金额A = 审价金额 - 管理费 |
| | | // po.setPendingPayB(subtract(auditAmount, qualityGuaranteeAmount, managementFee)); // 待付金额B = 审价金额 - 质保金 - 管理费 |
| | | // po.setPendingPayC(multiply(arrivalTotal, BigDecimal.ONE.subtract(managementFeeRatio))); // 待付金额C = 到账合计*(1-管理费占比) |
| | | |
| | | // 支付信息(第111-116列) |
| | | po.setPayeeName(getCellValue(cellArray, 143)); // 支付公司名称/个人名字 |
| | |
| | | private void buildSinglePaymentRecord(String mpId, JSONArray cellArray, String flowNumber, int printTimes, |
| | | int index, List<MpPaymentRecordPo> pos) throws ParseException { |
| | | |
| | | if (getCellValue(cellArray, index).isEmpty()) { |
| | | return; |
| | | } |
| | | // if (getCellValue(cellArray, index).isEmpty()) { |
| | | // return; |
| | | // } |
| | | |
| | | MpPaymentRecordPo po = new MpPaymentRecordPo(); |
| | | |
| | |
| | | |
| | | private void buildMpFifthPaymentRecordPo(List<MpFifthPaymentRecord> pos, JSONArray cellArray, String flowNumber, String mainPo, int index) { |
| | | |
| | | if (getCellValue(cellArray, index).isEmpty()) { |
| | | return; |
| | | } |
| | | // if (getCellValue(cellArray, index).isEmpty()) { |
| | | // return; |
| | | // } |
| | | |
| | | MpFifthPaymentRecord po = new MpFifthPaymentRecord(); |
| | | |
| | | long longId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; // 避免负数 |
| | | po.setId(longId+""); |
| | | po.setMpId(flowNumber); |
| | | po.setFifthPlannedPaymentAmount(new BigDecimal(getCellValue(cellArray, index)).toString()); |
| | | po.setFifthPlannedPaymentAmount(Vtil.defaultValue(getCellValue(cellArray, index))); |
| | | try { |
| | | po.setPlannedPaymentDate(parseDate(getCellValue(cellArray, index + 1))); |
| | | po.setActualPaymentDate(parseDate(getCellValue(cellArray, index + 5))); |
| | |
| | | } |
| | | po.setCategory(getCellValue(cellArray, index + 2)); |
| | | po.setReimburser(getCellValue(cellArray, index + 3)); |
| | | po.setActualPaymentAmount(new BigDecimal(getCellValue(cellArray, index + 4)).toString()); |
| | | po.setActualPaymentAmount(getCellValue(cellArray, index + 4)); |
| | | } |
| | | |
| | | /** |