i皖送费用推送定时任务
This commit is contained in:
parent
03f6d6fa87
commit
eacf57e3ef
|
|
@ -498,6 +498,7 @@ public class DateTimeHelper {
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getLastDay() {
|
public static String getLastDay() {
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
// 获取当前月最后一天
|
// 获取当前月最后一天
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.bonus.common.core.annotation.Excel;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
@ -20,6 +21,7 @@ import java.util.List;
|
||||||
* @Description: i皖送费用推送
|
* @Description: i皖送费用推送
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
public class IwsCostPushBean implements Serializable {
|
public class IwsCostPushBean implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1473066593962126100L;
|
private static final long serialVersionUID = -1473066593962126100L;
|
||||||
|
|
@ -82,6 +84,11 @@ public class IwsCostPushBean implements Serializable {
|
||||||
|
|
||||||
private BigDecimal leasePrice;
|
private BigDecimal leasePrice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总费用(统计领料 丢失 报废 维修费用)
|
||||||
|
*/
|
||||||
|
private BigDecimal totalMoney;
|
||||||
|
|
||||||
private String time;
|
private String time;
|
||||||
|
|
||||||
// 月份
|
// 月份
|
||||||
|
|
@ -110,6 +117,10 @@ public class IwsCostPushBean implements Serializable {
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
private LocalDateTime settlementTime;
|
private LocalDateTime settlementTime;
|
||||||
|
|
||||||
|
// 签订时间
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime signTime;
|
||||||
|
|
||||||
// 是否匹配
|
// 是否匹配
|
||||||
@Excel(name = "是否匹配", readConverterExp = "0=未匹配,1=已匹配", sort = 5)
|
@Excel(name = "是否匹配", readConverterExp = "0=未匹配,1=已匹配", sort = 5)
|
||||||
private Byte isMatch = 0;
|
private Byte isMatch = 0;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ public interface IwsCostPushMapper {
|
||||||
*/
|
*/
|
||||||
int insertCalcMonthRecord(IwsCostPushBean record);
|
int insertCalcMonthRecord(IwsCostPushBean record);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入项目月费用数据 -- 批量
|
||||||
|
*/
|
||||||
|
int insertProjectMonthCosts(List<IwsCostPushBean> recordList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据协议ID查询领用物资数据
|
* 根据协议ID查询领用物资数据
|
||||||
* @param record 协议信息及条件
|
* @param record 协议信息及条件
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.material.push.domain.IwsCostPushBean;
|
import com.bonus.material.push.domain.IwsCostPushBean;
|
||||||
import com.bonus.material.push.mapper.IwsCostPushMapper;
|
import com.bonus.material.push.mapper.IwsCostPushMapper;
|
||||||
import com.bonus.material.push.service.IwsCostPushService;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -17,10 +20,7 @@ import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.time.temporal.TemporalAdjusters;
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : 阮世耀
|
* @author : 阮世耀
|
||||||
|
|
@ -35,6 +35,9 @@ public class IwsCostPushServiceImpl implements IwsCostPushService {
|
||||||
@Resource
|
@Resource
|
||||||
private IwsCostPushMapper iwsCostPushMapper;
|
private IwsCostPushMapper iwsCostPushMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISltAgreementInfoService sltAgreementInfoService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据给定的条件查找协议信息
|
* 根据给定的条件查找协议信息
|
||||||
|
|
@ -55,6 +58,7 @@ public class IwsCostPushServiceImpl implements IwsCostPushService {
|
||||||
return iwsCostPushMapper.getCostPushCheckList(o);
|
return iwsCostPushMapper.getCostPushCheckList(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算月结费用
|
* 计算月结费用
|
||||||
*
|
*
|
||||||
|
|
@ -63,38 +67,34 @@ public class IwsCostPushServiceImpl implements IwsCostPushService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult computeTheMonthCost(IwsCostPushBean costDto) {
|
public AjaxResult computeTheMonthCost(IwsCostPushBean costDto) {
|
||||||
// 获取当月第一天的日期和最后一天日期
|
// 获取当前年月 例如:2025-01
|
||||||
String firstDay = DateTimeHelper.getFirstDay();
|
|
||||||
String lastDay = DateTimeHelper.getLastDay();
|
|
||||||
// 获取当前年月 2025-01
|
|
||||||
String month = DateTimeHelper.getNowMonth();
|
String month = DateTimeHelper.getNowMonth();
|
||||||
|
// 获取当月第一天的日期和最后一天日期
|
||||||
|
LocalDateTime firstDayOfMonth = getFirstDayOfMonth(month);
|
||||||
|
LocalDateTime lastDayOfMonth = getLastDayOfMonthZ(month);
|
||||||
|
|
||||||
costDto.setMonth(month);
|
costDto.setMonth(month);
|
||||||
costDto.setStartTime(firstDay);
|
|
||||||
costDto.setEndTime(lastDay);
|
|
||||||
|
|
||||||
// 清除旧的费用计算数据
|
// 清除旧的费用计算数据
|
||||||
// cleanSameMonthOldRecords(record);
|
// cleanSameMonthOldRecords(record);
|
||||||
|
|
||||||
// 插入新的当前月份记录,并生成id
|
// 插入新的当前月份,并生成记录id
|
||||||
iwsCostPushMapper.insertCalcMonthRecord(costDto);
|
iwsCostPushMapper.insertCalcMonthRecord(costDto);
|
||||||
|
|
||||||
String taskId = costDto.getId();
|
|
||||||
|
|
||||||
// 查询协议信息列表
|
// 查询协议信息列表
|
||||||
List<IwsCostPushBean> agreementList = iwsCostPushMapper.findAgreement(costDto);
|
List<IwsCostPushBean> agreementList = iwsCostPushMapper.findAgreement(costDto);
|
||||||
|
// 处理数据,计算4项费用
|
||||||
|
computeMonthInfoDetail(agreementList, month, firstDayOfMonth, lastDayOfMonth);
|
||||||
|
// 存入数据库
|
||||||
|
agreementList.forEach(item -> item.setMonth(month));
|
||||||
|
int addProjectMonthCostsMapperResult = iwsCostPushMapper.insertProjectMonthCosts(agreementList);
|
||||||
|
|
||||||
// 处理数据
|
return 0 < addProjectMonthCostsMapperResult ? AjaxResult.success("月结费用计算成功") : AjaxResult.error("月结费用计算失败");
|
||||||
computeMonthInfoDetail(agreementList, costDto, taskId, month);
|
|
||||||
|
|
||||||
// TODO 未完成费用结算 待完善
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据协议ID及月份查询当月租赁费用明细
|
* 根据协议ID及月份查询当月租赁费用明细
|
||||||
*
|
*
|
||||||
* @param record 查询信息
|
* @param record 传入查询的年月:yyyy-MM 及 协议ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<IwsCostPushBean> getLeaseCostsByAgreementIdAndMonth(IwsCostPushBean record) {
|
public List<IwsCostPushBean> getLeaseCostsByAgreementIdAndMonth(IwsCostPushBean record) {
|
||||||
|
|
@ -157,34 +157,77 @@ public class IwsCostPushServiceImpl implements IwsCostPushService {
|
||||||
/**
|
/**
|
||||||
* 计算月结费用详情
|
* 计算月结费用详情
|
||||||
* @param agreementList 协议集合
|
* @param agreementList 协议集合
|
||||||
* @param costDto 要进行结算的信息
|
* @param firstDay 月份第一天
|
||||||
* @param taskId 任务id
|
* @param lastDay 月份最后一天
|
||||||
* @param month 月份
|
|
||||||
*/
|
*/
|
||||||
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()) {
|
if (null == agreementList || agreementList.isEmpty()) {
|
||||||
return;
|
System.err.println("---------agreementList为空----------");
|
||||||
} else {
|
} 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) {
|
for (IwsCostPushBean agreement : agreementList) {
|
||||||
|
// 协议id
|
||||||
|
String agreementId = agreement.getAgreementId();
|
||||||
|
// 更新协议推送状态
|
||||||
updatePushStatus(agreement);
|
updatePushStatus(agreement);
|
||||||
BigDecimal changeMoney = BigDecimal.ZERO;
|
|
||||||
IwsCostPushBean bean = new IwsCostPushBean();
|
|
||||||
bean.setAgreementId(agreement.getAgreementId());
|
|
||||||
|
|
||||||
// 查询领料费用
|
// 对已结算、未结算分开处理
|
||||||
List<IwsCostPushBean> baseInfo = iwsCostPushMapper.getPaidSltBaseInfo(bean);
|
if (0 == agreement.getIsSettlement()) {
|
||||||
List<IwsCostPushBean> l = new ArrayList<>();
|
// 未结算时,无丢失、维修、报废费用
|
||||||
|
agreement.setLostMoney(BigDecimal.ZERO);
|
||||||
|
agreement.setRepairMoney(BigDecimal.ZERO);
|
||||||
|
agreement.setScrapMoney(BigDecimal.ZERO);
|
||||||
|
|
||||||
if (null != baseInfo && !baseInfo.isEmpty()) {
|
// 查询领料费用
|
||||||
l = baseInfo;
|
List<IwsCostPushBean> leaseCostsByAgreementIdAndMonth = this.getLeaseCostsByAgreementIdAndMonth(new IwsCostPushBean()
|
||||||
} else {
|
.setAgreementId(agreementId)
|
||||||
System.err.println("baseInfo为空 = " + baseInfo);
|
.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
|
* 检查是否包含大件及机械化,项目id为空的
|
||||||
* return true 需要推送, false 不需要推送
|
* return true 包含大件、机械化 或 工程id为空, false 不包含
|
||||||
*/
|
*/
|
||||||
private boolean checkPush(IwsCostPushBean o) {
|
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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("-----------四类未结算费用定时器执行完毕-----------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import com.bonus.common.core.web.domain.BaseEntity;
|
import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结算信息对象 slt_agreement_info
|
* 结算信息对象 slt_agreement_info
|
||||||
|
|
@ -15,10 +16,9 @@ import com.bonus.common.core.web.domain.BaseEntity;
|
||||||
* @author xsheng
|
* @author xsheng
|
||||||
* @date 2024-10-16
|
* @date 2024-10-16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ToString
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
public class SltAgreementInfo extends BaseEntity {
|
public class SltAgreementInfo extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
bp.pro_id AS projectId, bp.pro_name AS projectName, bp.pro_code AS projectCode,
|
||||||
bu.unit_name AS unitName,
|
bu.unit_name AS unitName,
|
||||||
bma.agreement_id AS agreementId,bma.`agreement_code` AS agreementCode, bma.is_slt AS isSettlement,
|
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
|
FROM bm_agreement_info bma
|
||||||
LEFT JOIN bm_project bp ON bp.pro_id = bma.project_id
|
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 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>
|
<where>
|
||||||
<if test="agreementCode != null and agreementCode != ''">
|
<if test="agreementCode != null and agreementCode != ''">
|
||||||
AND bma.agreement_code LIKE CONCAT('%',#{agreementCode},'%')
|
AND bma.agreement_code LIKE CONCAT('%',#{agreementCode},'%')
|
||||||
|
|
@ -102,4 +104,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
bma.agreement_id = #{agreementId}
|
bma.agreement_id = #{agreementId}
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
Loading…
Reference in New Issue