i皖送费用推送定时任务

This commit is contained in:
syruan 2025-02-15 16:38:24 +08:00
parent 03f6d6fa87
commit eacf57e3ef
7 changed files with 166 additions and 45 deletions

View File

@ -498,6 +498,7 @@ public class DateTimeHelper {
return first;
}
public static String getLastDay() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// 获取当前月最后一天

View File

@ -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;

View File

@ -35,6 +35,11 @@ public interface IwsCostPushMapper {
*/
int insertCalcMonthRecord(IwsCostPushBean record);
/**
* 插入项目月费用数据 -- 批量
*/
int insertProjectMonthCosts(List<IwsCostPushBean> recordList);
/**
* 根据协议ID查询领用物资数据
* @param record 协议信息及条件

View File

@ -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<IwsCostPushBean> 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<IwsCostPushBean> 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<IwsCostPushBean> agreementList, IwsCostPushBean costDto, String taskId, String month) {
private void computeMonthInfoDetail(List<IwsCostPushBean> 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());
// 对已结算未结算分开处理
if (0 == agreement.getIsSettlement()) {
// 未结算时无丢失维修报废费用
agreement.setLostMoney(BigDecimal.ZERO);
agreement.setRepairMoney(BigDecimal.ZERO);
agreement.setScrapMoney(BigDecimal.ZERO);
// 查询领料费用
List<IwsCostPushBean> baseInfo = iwsCostPushMapper.getPaidSltBaseInfo(bean);
List<IwsCostPushBean> l = new ArrayList<>();
if (null != baseInfo && !baseInfo.isEmpty()) {
l = baseInfo;
List<IwsCostPushBean> leaseCostsByAgreementIdAndMonth = this.getLeaseCostsByAgreementIdAndMonth(new IwsCostPushBean()
.setAgreementId(agreementId)
.setMonth(month)
);
if (CollectionUtils.isEmpty(leaseCostsByAgreementIdAndMonth)) {
agreement.setLeaseMoney(BigDecimal.ZERO);
} else {
System.err.println("baseInfo为空 = " + baseInfo);
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()));
}
/**

View File

@ -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("-----------四类未结算费用定时器执行完毕-----------");
}
}

View File

@ -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;

View File

@ -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
<where>
<if test="agreementCode != null and agreementCode != ''">
AND bma.agreement_code LIKE CONCAT('%',#{agreementCode},'%')
@ -102,4 +104,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bma.agreement_id = #{agreementId}
</where>
</select>
<insert id="insertProjectMonthCosts">
INSERT INTO project_month_costs(
AGREEMENT_ID,
LEASE_MONEY,
LOST_MONEY,
REPAIR_MONEY,
SCRAP_MONEY,
CHECK_STATUS,
MONTH
)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.agreementId},
#{item.leaseMoney},
#{item.lostMoney},
#{item.repairMoney},
#{item.scrapMoney},
#{item.checkStatus},
#{item.month}
)
</foreach>
</insert>
</mapper>