diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java index cb78185c..986f0bea 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java @@ -40,16 +40,20 @@ public interface IwsCostPushMapper { */ int insertCalcMonthRecord(IwsCostPushBean record); + List selectCalcMonthRecord(IwsCostPushBean record); + /** * 插入项目月费用info数据 -- 批量 */ int insertProjectMonthCosts(List list); + int updateProjectMonthCosts(IwsCostPushBean vo); + List selectHaveProjectMonthCosts(IwsCostPushBean vo); /** * 插入项目月费用details数据 -- 批量 */ int insertProjectMonthCostsDetails(@Param("list") List list); - + List selectHaveProjectMonthCostsDetails(PeriodCostResultVo vo); /** * 根据协议ID查询领用物资数据 * @param record 协议信息及条件 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java index 3822a8da..2a770568 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java @@ -122,7 +122,12 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { //cleanSameMonthOldRecords(record); // 插入新的当前月份,并生成记录id - iwsCostPushMapper.insertCalcMonthRecord(costDto); + List monthList=iwsCostPushMapper.selectCalcMonthRecord(costDto); + if(monthList==null||monthList.size()==0){ + iwsCostPushMapper.insertCalcMonthRecord(costDto); + }else{ + costDto.setTaskId(monthList.get(0).getTaskId()); + } // 查询协议信息列表 List agreementList = iwsCostPushMapper.findAgreement(costDto); @@ -296,9 +301,24 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { .setConsumeMoney(vo.getConsumeCost()) ); } - + List uplist=new ArrayList<>(); + List addlist=new ArrayList<>(); + //将已录入的数据筛选出来 + for(IwsCostPushBean vo:resultArray){ + List haveList=iwsCostPushMapper.selectHaveProjectMonthCosts(vo); + if(haveList!=null&&haveList.size()>0){ + uplist.add(vo); + }else{ + addlist.add(vo); + } + } // 批量插入 -- 存入数据库costs列表 - int addProjectMonthCostsMapperResult = iwsCostPushMapper.insertProjectMonthCosts(resultArray); + int addProjectMonthCostsMapperResult = iwsCostPushMapper.insertProjectMonthCosts(addlist); + try{ + for(IwsCostPushBean vo:uplist){ + iwsCostPushMapper.updateProjectMonthCosts(vo); + } + }catch (Exception e){} // 批量插入 -- 存入数据库租赁费用明细(project_month_info表) if (CollectionUtils.isNotEmpty(unsettlementEquipmentLeaseCostsDetails)) { // (工器具)未结算租赁费用的存入 @@ -306,7 +326,16 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { item.setTaskId(costDto.getTaskId()); item.setEquipmentType((byte) 1); }); - iwsCostPushMapper.insertProjectMonthCostsDetails(unsettlementEquipmentLeaseCostsDetails); + List addDetailList=new ArrayList<>(); + //将已录入的数据筛选出来 + for(PeriodCostResultVo vo:unsettlementEquipmentLeaseCostsDetails){ + List haveList=iwsCostPushMapper.selectHaveProjectMonthCostsDetails(vo); + if(haveList!=null&&haveList.size()>0){ + }else{ + addDetailList.add(vo); + } + } + iwsCostPushMapper.insertProjectMonthCostsDetails(addDetailList); } if (CollectionUtils.isNotEmpty(settlementEquipmentCostsDetails)) { // (工器具)已结算租赁费用的存入 @@ -314,7 +343,16 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { item.setTaskId(costDto.getTaskId()); item.setEquipmentType((byte) 1); }); - iwsCostPushMapper.insertProjectMonthCostsDetails(settlementEquipmentCostsDetails); + List addDetailList=new ArrayList<>(); + //将已录入的数据筛选出来 + for(PeriodCostResultVo vo:settlementEquipmentCostsDetails){ + List haveList=iwsCostPushMapper.selectHaveProjectMonthCostsDetails(vo); + if(haveList!=null&&haveList.size()>0){ + }else{ + addDetailList.add(vo); + } + } + iwsCostPushMapper.insertProjectMonthCostsDetails(addDetailList); } if (CollectionUtils.isNotEmpty(unsettlementSafetyEquipmentLeaseCostsDetails)) { // (安全工器具)未结算租赁费用的存入 @@ -322,7 +360,16 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { item.setTaskId(costDto.getTaskId()); item.setEquipmentType((byte) 2); }); - iwsCostPushMapper.insertProjectMonthCostsDetails(unsettlementSafetyEquipmentLeaseCostsDetails); + List addDetailList=new ArrayList<>(); + //将已录入的数据筛选出来 + for(PeriodCostResultVo vo:unsettlementSafetyEquipmentLeaseCostsDetails){ + List haveList=iwsCostPushMapper.selectHaveProjectMonthCostsDetails(vo); + if(haveList!=null&&haveList.size()>0){ + }else{ + addDetailList.add(vo); + } + } + iwsCostPushMapper.insertProjectMonthCostsDetails(addDetailList); } if (CollectionUtils.isNotEmpty(settlementSafetyEquipmentCostsDetails)) { // (安全工器具)已结算租赁费用的存入 @@ -330,7 +377,16 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { item.setTaskId(costDto.getTaskId()); item.setEquipmentType((byte) 2); }); - iwsCostPushMapper.insertProjectMonthCostsDetails(settlementSafetyEquipmentCostsDetails); + List addDetailList=new ArrayList<>(); + //将已录入的数据筛选出来 + for(PeriodCostResultVo vo:settlementSafetyEquipmentCostsDetails){ + List haveList=iwsCostPushMapper.selectHaveProjectMonthCostsDetails(vo); + if(haveList!=null&&haveList.size()>0){ + }else{ + addDetailList.add(vo); + } + } + iwsCostPushMapper.insertProjectMonthCostsDetails(addDetailList); } return 0 < addProjectMonthCostsMapperResult ? AjaxResult.success("月结费用计算成功") : AjaxResult.error("月结费用计算失败"); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/task/IwsCostPushTask.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/task/IwsCostPushTask.java index 23497206..dfe49877 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/task/IwsCostPushTask.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/task/IwsCostPushTask.java @@ -56,6 +56,7 @@ public class IwsCostPushTask { * 定时任务 -- 计算月结费用 -- 每月最后一天的23点30分执行 */ @Scheduled(cron = "0 30 23 L * ?") +// @Scheduled(fixedDelay = 1000*60*30) public void computeTheMonthCostTask() { System.out.println("-----------开始计算四类未结算费用定时器-----------"); iwsCostPushService.computeTheMonthCost(new IwsCostPushBean()); @@ -66,6 +67,7 @@ public class IwsCostPushTask { /** * 定时任务 -- 保存未结算报表记录(工器具) -- 每月最后一天的23点00分执行 */ +// @Scheduled(fixedDelay = 1000*60*30) @Scheduled(cron = "0 00 23 L * ?", zone = "Asia/Shanghai") public void saveUnSltHistoryReport() { System.out.println("-----------开始执行保存未结算记录定时器-----------"); @@ -170,7 +172,14 @@ public class IwsCostPushTask { } try { - validRecords.forEach(vo -> vo.setYearMonth(DateTime.now().toString("yyyyMM"))); + // 根据 协议ID、结算类型、年月 删除多余数据 + for(SltInfoVo vo:validRecords){ + vo.setYearMonth(DateTime.now().toString("yyyyMM")); + List oldList=sltAgreementInfoMapper.selectOldHistoryReport(vo); + if(oldList!=null&&oldList.size()>0){ + sltAgreementInfoMapper.deleteOldHistoryReport(vo); + } + } int rows = sltAgreementInfoMapper.addSltHistoryReport(validRecords); log.info("未结算报表定时器:保存未结算报表记录完成,受影响行数:{}", rows); @@ -186,6 +195,14 @@ public class IwsCostPushTask { detail.setYearMonth(DateTime.now().toString("yyyyMM")); detail.setSettlementType(1); }); + // 根据 协议ID、结算类型、年月、(1租赁 2维修 3丢失 4报废) 删除多余数据 + for(SltAgreementInfo vo:leaseDetails){ + vo.setCostType("1"); + List oldList=sltAgreementInfoMapper.selectOldHistoryReportDetail(vo); + if(oldList!=null&&oldList.size()>0){ + sltAgreementInfoMapper.deleteOldHistoryReportDetail(vo); + } + } sltAgreementInfoMapper.addSltHistoryReportLeaseDetail(leaseDetails); } @@ -200,6 +217,14 @@ public class IwsCostPushTask { detail.setYearMonth(DateTime.now().toString("yyyyMM")); detail.setSettlementType(1); }); + // 根据 协议ID、结算类型、年月、(1租赁 2维修 3丢失 4报废) 删除多余数据 + for(SltAgreementInfo vo:leaseDetails){ + vo.setCostType("2"); + List oldList=sltAgreementInfoMapper.selectOldHistoryReportDetail(vo); + if(oldList!=null&&oldList.size()>0){ + sltAgreementInfoMapper.deleteOldHistoryReportDetail(vo); + } + } sltAgreementInfoMapper.addSltHistoryReportRepairDetail(repairDetails); } @@ -214,6 +239,14 @@ public class IwsCostPushTask { detail.setYearMonth(DateTime.now().toString("yyyyMM")); detail.setSettlementType(1); }); + // 根据 协议ID、结算类型、年月、(1租赁 2维修 3丢失 4报废) 删除多余数据 + for(SltAgreementInfo vo:leaseDetails){ + vo.setCostType("3"); + List oldList=sltAgreementInfoMapper.selectOldHistoryReportDetail(vo); + if(oldList!=null&&oldList.size()>0){ + sltAgreementInfoMapper.deleteOldHistoryReportDetail(vo); + } + } sltAgreementInfoMapper.addSltHistoryReportLoseDetail(loseDetails); } @@ -228,6 +261,14 @@ public class IwsCostPushTask { detail.setYearMonth(DateTime.now().toString("yyyyMM")); detail.setSettlementType(1); }); + // 根据 协议ID、结算类型、年月、(1租赁 2维修 3丢失 4报废) 删除多余数据 + for(SltAgreementInfo vo:leaseDetails){ + vo.setCostType("4"); + List oldList=sltAgreementInfoMapper.selectOldHistoryReportDetail(vo); + if(oldList!=null&&oldList.size()>0){ + sltAgreementInfoMapper.deleteOldHistoryReportDetail(vo); + } + } sltAgreementInfoMapper.addSltHistoryReportScrapDetail(scrapDetails); } @@ -248,7 +289,6 @@ public class IwsCostPushTask { sltAgreementInfoService.clearCache(); log.info("缓存已清理"); } - System.out.println("-----------保存未结算记录定时器执行完毕-----------"); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java index aa6a404d..80eba344 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementInfo.java @@ -335,4 +335,6 @@ public class SltAgreementInfo extends BaseEntity { * 领料工程id */ private String leaseProId; + + private String costType; } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java index 334c2158..a4d1cbcb 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementInfoMapper.java @@ -32,6 +32,11 @@ public interface SltAgreementInfoMapper { int addSltHistoryReportScrapDetail(List list); + List selectOldHistoryReport(SltInfoVo vo); + int deleteOldHistoryReport(SltInfoVo vo); + List selectOldHistoryReportDetail(SltAgreementInfo vo); + int deleteOldHistoryReportDetail(SltAgreementInfo vo); + List selectSltHistoryReportList(SltHistoryReport sltHistoryReport); List selectSltHistoryLeaseDetail(SltHistoryReportDetail sltHistoryReportDetail); diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml index 835069bb..fd1d1b46 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml @@ -148,6 +148,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" VALUES (#{month}) + + + select + AGREEMENT_ID as agreementId, + LEASE_MONEY as leaseMoney, + CONSUME_MONEY as consumeMoney, + LOST_MONEY as lostMoney, + REPAIR_MONEY as repairMoney, + SCRAP_MONEY as scrapMoney, + TASK_ID as taskId, + TYPE as settlementType + from project_month_costs where + AGREEMENT_ID=#{agreementId} and TASK_ID=#{taskId} and TYPE=#{settlementType} + + + + insert into project_month_info(agreementId, typeId, leaseNum, leaseDate, returnDate, + leasePrice, leaseMoney, taskId, buy_price, money, jiju_type) + values + + ( + #{item.agreementId}, + #{item.typeId}, + #{item.num}, + #{item.calcStartTime}, + #{item.calcEndTime}, + #{item.leasePrice}, + #{item.leaseCost}, + #{item.taskId}, + #{item.buyPrice}, + #{item.consumeCost}, + #{item.equipmentType} + ) + + + + - - insert into project_month_info(agreementId, typeId, leaseNum, leaseDate, returnDate, - leasePrice, leaseMoney, taskId, buy_price, money, jiju_type) - values - - ( - #{item.agreementId}, - #{item.typeId}, - #{item.num}, - #{item.calcStartTime}, - #{item.calcEndTime}, - #{item.leasePrice}, - #{item.leaseCost}, - #{item.taskId}, - #{item.buyPrice}, - #{item.consumeCost}, - #{item.equipmentType} - ) - - - + select a.agreement_id as agreementid,a.settlement_type as settlementtype,a.year_month as yearmonth + from slt_history_report a + where 1=1 + + and a.agreement_id=#{agreementId} + + + and a.settlement_type=#{settlementType} + + + and a.year_month=#{yearMonth} + + + + + delete from slt_history_report where + agreement_id=#{agreementId} + and settlement_type=#{settlementType} + and year_month=#{yearMonth} + + + + + + delete from slt_history_report_detail where + agreement_id=#{agreementId} + and settlement_type=#{settlementType} + and year_month=#{yearMonth} + and cost_type=#{costType} + + insert into slt_agreement_status (slt_task,slt_auditor,slt_status)