diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/config/DateTimeHelper.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/config/DateTimeHelper.java index 0e28aa89..816734fa 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/config/DateTimeHelper.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/config/DateTimeHelper.java @@ -498,6 +498,7 @@ public class DateTimeHelper { return first; } + public static String getLastDay() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // 获取当前月最后一天 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java index 52ff5d9f..2d64295e 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java @@ -4,6 +4,7 @@ import com.bonus.common.core.annotation.Excel; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.experimental.Accessors; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; @@ -20,6 +21,7 @@ import java.util.List; * @Description: i皖送费用推送 */ @Data +@Accessors(chain = true) public class IwsCostPushBean implements Serializable { private static final long serialVersionUID = -1473066593962126100L; @@ -82,6 +84,11 @@ public class IwsCostPushBean implements Serializable { private BigDecimal leasePrice; + /** + * 总费用(统计领料 丢失 报废 维修费用) + */ + private BigDecimal totalMoney; + private String time; // 月份 @@ -110,6 +117,10 @@ public class IwsCostPushBean implements Serializable { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private LocalDateTime settlementTime; + // 签订时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime signTime; + // 是否匹配 @Excel(name = "是否匹配", readConverterExp = "0=未匹配,1=已匹配", sort = 5) private Byte isMatch = 0; 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 2d7100aa..d6decbd8 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 @@ -35,6 +35,11 @@ public interface IwsCostPushMapper { */ int insertCalcMonthRecord(IwsCostPushBean record); + /** + * 插入项目月费用数据 -- 批量 + */ + int insertProjectMonthCosts(List recordList); + /** * 根据协议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 6ff5d48c..1e4fc380 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 @@ -7,6 +7,9 @@ import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.push.domain.IwsCostPushBean; import com.bonus.material.push.mapper.IwsCostPushMapper; import com.bonus.material.push.service.IwsCostPushService; +import com.bonus.material.settlement.domain.SltAgreementInfo; +import com.bonus.material.settlement.domain.vo.SltInfoVo; +import com.bonus.material.settlement.service.ISltAgreementInfoService; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -17,10 +20,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAdjusters; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; /** * @author : 阮世耀 @@ -35,6 +35,9 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { @Resource private IwsCostPushMapper iwsCostPushMapper; + @Resource + private ISltAgreementInfoService sltAgreementInfoService; + /** * 根据给定的条件查找协议信息 @@ -55,6 +58,7 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { return iwsCostPushMapper.getCostPushCheckList(o); } + /** * 计算月结费用 * @@ -63,38 +67,34 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { */ @Override public AjaxResult computeTheMonthCost(IwsCostPushBean costDto) { - // 获取当月第一天的日期和最后一天日期 - String firstDay = DateTimeHelper.getFirstDay(); - String lastDay = DateTimeHelper.getLastDay(); - // 获取当前年月 2025-01 + // 获取当前年月 例如:2025-01 String month = DateTimeHelper.getNowMonth(); + // 获取当月第一天的日期和最后一天日期 + LocalDateTime firstDayOfMonth = getFirstDayOfMonth(month); + LocalDateTime lastDayOfMonth = getLastDayOfMonthZ(month); costDto.setMonth(month); - costDto.setStartTime(firstDay); - costDto.setEndTime(lastDay); // 清除旧的费用计算数据 // cleanSameMonthOldRecords(record); - // 插入新的当前月份记录,并生成id + // 插入新的当前月份,并生成记录id iwsCostPushMapper.insertCalcMonthRecord(costDto); - - String taskId = costDto.getId(); - // 查询协议信息列表 List agreementList = iwsCostPushMapper.findAgreement(costDto); + // 处理数据,计算4项费用 + computeMonthInfoDetail(agreementList, month, firstDayOfMonth, lastDayOfMonth); + // 存入数据库 + agreementList.forEach(item -> item.setMonth(month)); + int addProjectMonthCostsMapperResult = iwsCostPushMapper.insertProjectMonthCosts(agreementList); - // 处理数据 - computeMonthInfoDetail(agreementList, costDto, taskId, month); - - // TODO 未完成费用结算 待完善 - return null; + return 0 < addProjectMonthCostsMapperResult ? AjaxResult.success("月结费用计算成功") : AjaxResult.error("月结费用计算失败"); } /** * 根据协议ID及月份查询当月租赁费用明细 * - * @param record 查询信息 + * @param record 传入查询的年月:yyyy-MM 及 协议ID */ @Override public List getLeaseCostsByAgreementIdAndMonth(IwsCostPushBean record) { @@ -157,34 +157,77 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { /** * 计算月结费用详情 * @param agreementList 协议集合 - * @param costDto 要进行结算的信息 - * @param taskId 任务id - * @param month 月份 + * @param firstDay 月份第一天 + * @param lastDay 月份最后一天 */ - private void computeMonthInfoDetail(List agreementList, IwsCostPushBean costDto, String taskId, String month) { + private void computeMonthInfoDetail(List agreementList, String month, LocalDateTime firstDay, LocalDateTime lastDay) { if (null == agreementList || agreementList.isEmpty()) { - return; + System.err.println("---------agreementList为空----------"); } else { - System.out.println("agreementList = " + agreementList); + System.out.println("agreementList数据不为空"); + + // 过滤异常数据 + agreementList.removeIf(item -> + Objects.isNull(item) || + Objects.isNull(item.getAgreementId()) || + Objects.isNull(item.getSignTime()) || + Objects.isNull(item.getIsSettlement()) || + item.getSignTime().isAfter(lastDay) || item.getSettlementTime().isBefore(firstDay) + ); + for (IwsCostPushBean agreement : agreementList) { + // 协议id + String agreementId = agreement.getAgreementId(); + // 更新协议推送状态 updatePushStatus(agreement); - BigDecimal changeMoney = BigDecimal.ZERO; - IwsCostPushBean bean = new IwsCostPushBean(); - bean.setAgreementId(agreement.getAgreementId()); - // 查询领料费用 - List baseInfo = iwsCostPushMapper.getPaidSltBaseInfo(bean); - List l = new ArrayList<>(); + // 对已结算、未结算分开处理 + if (0 == agreement.getIsSettlement()) { + // 未结算时,无丢失、维修、报废费用 + agreement.setLostMoney(BigDecimal.ZERO); + agreement.setRepairMoney(BigDecimal.ZERO); + agreement.setScrapMoney(BigDecimal.ZERO); - if (null != baseInfo && !baseInfo.isEmpty()) { - l = baseInfo; - } else { - System.err.println("baseInfo为空 = " + baseInfo); + // 查询领料费用 + List leaseCostsByAgreementIdAndMonth = this.getLeaseCostsByAgreementIdAndMonth(new IwsCostPushBean() + .setAgreementId(agreementId) + .setMonth(month) + ); + if (CollectionUtils.isEmpty(leaseCostsByAgreementIdAndMonth)) { + agreement.setLeaseMoney(BigDecimal.ZERO); + } else { + leaseCostsByAgreementIdAndMonth.removeIf(item -> Objects.isNull(item) || Objects.isNull(item.getLeaseMoney())); + // 合并计算领料费用 + agreement.setLeaseMoney(leaseCostsByAgreementIdAndMonth + .stream() + .map(IwsCostPushBean::getLeaseMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add) + ); + } + } else if (1 == agreement.getIsSettlement()) { + // 已结算费用计算 + SltInfoVo sltServiceResult = sltAgreementInfoService.getSltInfo(new SltAgreementInfo().setAgreementId(Long.valueOf(agreementId))); + if (Objects.isNull(sltServiceResult)) { + System.err.println("sltServiceResult为空----null"); + agreement.setLostMoney(BigDecimal.ZERO); + agreement.setRepairMoney(BigDecimal.ZERO); + agreement.setScrapMoney(BigDecimal.ZERO); + agreement.setLeaseMoney(BigDecimal.ZERO); + } else { + // 已经结算时,要统计领料、丢失、维修、报废费用 + agreement.setLostMoney(Optional.ofNullable(sltServiceResult.getLoseCost()).orElse(BigDecimal.ZERO)); + agreement.setRepairMoney(Optional.ofNullable(sltServiceResult.getRepairCost()).orElse(BigDecimal.ZERO)); + agreement.setScrapMoney(Optional.ofNullable(sltServiceResult.getScrapCost()).orElse(BigDecimal.ZERO)); + agreement.setLeaseMoney(Optional.ofNullable(sltServiceResult.getLeaseCost()).orElse(BigDecimal.ZERO)); + } } - if (!l.isEmpty()) { - // TODO 待完善 - } + // 合并统计费用 + agreement.setTotalMoney(agreement.getLeaseMoney() + .add(agreement.getLostMoney()) + .add(agreement.getRepairMoney()) + .add(agreement.getScrapMoney()) + ); } } } @@ -202,11 +245,11 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { } /** - * 检查是否需要推送,包含大件及机械化的不需要进行push - * return true 需要推送, false 不需要推送 + * 检查是否包含大件及机械化,项目id为空的 + * return true 包含大件、机械化 或 工程id为空, false 不包含 */ private boolean checkPush(IwsCostPushBean o) { - return !(o.getUnitName().contains("大件") || o.getUnitName().contains("机械化") || StringUtils.isEmpty(o.getProjectId())); + return (o.getUnitName().contains("大件") || o.getUnitName().contains("机械化") || StringUtils.isEmpty(o.getProjectId())); } /** 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 new file mode 100644 index 00000000..a0d126bc --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/task/IwsCostPushTask.java @@ -0,0 +1,35 @@ +package com.bonus.material.push.task; + +import com.bonus.material.push.domain.IwsCostPushBean; +import com.bonus.material.push.service.IwsCostPushService; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * @author : 阮世耀 + * @version : 1.0 + * @PackagePath: com.bonus.material.push.task + * @CreateTime: 2025-02-15 16:01 + * @Description: i皖送费用推送定时任务类 + */ +@Component +public class IwsCostPushTask { + + @Resource + private IwsCostPushService iwsCostPushService; + + + /** + * 定时任务 -- 计算月结费用 -- 每月最后一天的23点30分执行 + */ + @Scheduled(cron = "0 30 23 L * ?") + public void computeTheMonthCostTask() { + System.out.println("-----------开始计算四类未结算费用定时器-----------"); + iwsCostPushService.computeTheMonthCost(new IwsCostPushBean()); + 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 e1ffc846..ad23a11d 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 @@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.ToString; import com.bonus.common.core.web.domain.BaseEntity; +import lombok.experimental.Accessors; /** * 结算信息对象 slt_agreement_info @@ -15,10 +16,9 @@ import com.bonus.common.core.web.domain.BaseEntity; * @author xsheng * @date 2024-10-16 */ - - @Data @ToString +@Accessors(chain = true) public class SltAgreementInfo extends BaseEntity { private static final long serialVersionUID = 1L; 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 a25747fc..354dba26 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 @@ -9,10 +9,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bp.pro_id AS projectId, bp.pro_name AS projectName, bp.pro_code AS projectCode, bu.unit_name AS unitName, bma.agreement_id AS agreementId,bma.`agreement_code` AS agreementCode, bma.is_slt AS isSettlement, - bma.sign_time AS settlementTime, bma.is_push AS isPush + bma.sign_time AS signTime, bma.is_push AS isPush, + saa.audit_time AS settlementTime FROM bm_agreement_info bma LEFT JOIN bm_project bp ON bp.pro_id = bma.project_id LEFT JOIN bm_unit bu ON bu.unit_id = bma.unit_id + LEFT JOIN slt_agreement_apply saa ON saa.agreement_id = bma.agreement_id AND bma.is_slt = 1 AND bma.agreement_code LIKE CONCAT('%',#{agreementCode},'%') @@ -102,4 +104,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bma.agreement_id = #{agreementId} + + + INSERT INTO project_month_costs( + AGREEMENT_ID, + LEASE_MONEY, + LOST_MONEY, + REPAIR_MONEY, + SCRAP_MONEY, + CHECK_STATUS, + MONTH + ) + VALUES + + ( + #{item.agreementId}, + #{item.leaseMoney}, + #{item.lostMoney}, + #{item.repairMoney}, + #{item.scrapMoney}, + #{item.checkStatus}, + #{item.month} + ) + + \ No newline at end of file