未结算报表历史存储
This commit is contained in:
parent
ed79555cd7
commit
b9c8b4aa67
|
|
@ -1,11 +1,24 @@
|
||||||
package com.bonus.material.push.task;
|
package com.bonus.material.push.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.bonus.material.push.domain.IwsCostPushBean;
|
import com.bonus.material.push.domain.IwsCostPushBean;
|
||||||
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.SltHistoryReportDetail;
|
||||||
|
import com.bonus.material.settlement.domain.vo.SltInfoVo;
|
||||||
|
import com.bonus.material.settlement.mapper.SltAgreementInfoMapper;
|
||||||
|
import com.bonus.material.settlement.service.ISltAgreementInfoService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : 阮世耀
|
* @author : 阮世耀
|
||||||
|
|
@ -15,17 +28,33 @@ import javax.annotation.Resource;
|
||||||
* @Description: i皖送费用推送定时任务类
|
* @Description: i皖送费用推送定时任务类
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
|
@Log4j2
|
||||||
public class IwsCostPushTask {
|
public class IwsCostPushTask {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IwsCostPushService iwsCostPushService;
|
private IwsCostPushService iwsCostPushService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ISltAgreementInfoService sltAgreementInfoService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SltAgreementInfoMapper sltAgreementInfoMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 程序启动完成后立即执行一次
|
||||||
|
*/
|
||||||
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
|
public void runAfterStartup() throws InterruptedException {
|
||||||
|
System.out.println("程序启动完成,立即执行一次任务");
|
||||||
|
// saveUnSltHistoryReport(); // 手动调用定时任务方法
|
||||||
|
// Thread.sleep(10000);
|
||||||
|
// saveUnSltSafetyHistoryReport();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务 -- 计算月结费用 -- 每月最后一天的23点30分执行
|
* 定时任务 -- 计算月结费用 -- 每月最后一天的23点30分执行
|
||||||
*/
|
*/
|
||||||
// @Scheduled(cron = "0 30 23 L * ?")
|
|
||||||
// @Scheduled(cron = "0 03 10 * * ?")
|
|
||||||
@Scheduled(cron = "0 30 23 L * ?")
|
@Scheduled(cron = "0 30 23 L * ?")
|
||||||
public void computeTheMonthCostTask() {
|
public void computeTheMonthCostTask() {
|
||||||
System.out.println("-----------开始计算四类未结算费用定时器-----------");
|
System.out.println("-----------开始计算四类未结算费用定时器-----------");
|
||||||
|
|
@ -34,6 +63,385 @@ public class IwsCostPushTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务 -- 保存未结算报表记录 -- 每月最后一天的23点00分执行
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 00 23 L * ?", zone = "Asia/Shanghai")
|
||||||
|
public void saveUnSltHistoryReport() {
|
||||||
|
System.out.println("-----------开始执行保存未结算记录定时器-----------");
|
||||||
|
// ----------- 查询未结算的全部协议 ---------------
|
||||||
|
List<SltAgreementInfo> list = sltAgreementInfoService.getSltReportList(new SltAgreementInfo());
|
||||||
|
// 如果没有数据,直接终止任务
|
||||||
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
|
log.warn("未结算报表定时器:没有查询到未结算的协议,任务终止!");
|
||||||
|
System.err.println("未结算报表定时器:没有查询到未结算的协议,任务终止");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("查询到未结算协议数量: {}", list.size());
|
||||||
|
|
||||||
|
// ----------- 给查询出来的协议设置权限控制(先查询工器具) ---------------
|
||||||
|
int settlementType = 1; // 1:工器具结算单
|
||||||
|
|
||||||
|
// --------- 拿到list中所有的agreementId存成集合,给每个info赋值 ------------------
|
||||||
|
List<Long> agreementIdsArray = list.stream()
|
||||||
|
.map(SltAgreementInfo::getAgreementId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (agreementIdsArray.isEmpty()) {
|
||||||
|
log.warn("未结算报表定时器:没有查询到有效的协议ID,任务终止!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------- 定义结果集合 ------------------
|
||||||
|
List<SltInfoVo> gqjResultList = new ArrayList<>(list.size());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 批量处理,减少单个查询
|
||||||
|
log.info("开始批量处理 {} 个协议的费用明细", list.size());
|
||||||
|
|
||||||
|
list.forEach(info -> {
|
||||||
|
try {
|
||||||
|
info.setSettlementType(settlementType);
|
||||||
|
info.setAgreementIds(agreementIdsArray);
|
||||||
|
|
||||||
|
// 查询每个协议的各项费用明细
|
||||||
|
SltInfoVo vo = sltAgreementInfoService.getSltInfoReportBatch(info);
|
||||||
|
if (vo != null && !ObjectUtil.isEmpty(vo)) {
|
||||||
|
vo.setAgreementId(info.getAgreementId());
|
||||||
|
vo.setAgreementCode(info.getAgreementCode());
|
||||||
|
vo.setSettlementType(settlementType);
|
||||||
|
gqjResultList.add(vo);
|
||||||
|
log.debug("协议 {} 费用明细处理成功", info.getAgreementCode());
|
||||||
|
} else {
|
||||||
|
log.debug("协议 {} 没有费用明细数据", info.getAgreementCode());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理协议 {} 时出错: {}", info.getAgreementCode(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
log.info("批量处理完成,共获得 {} 条有效费用记录", gqjResultList.size());
|
||||||
|
|
||||||
|
// 数据验证:过滤掉关键字段为空的记录
|
||||||
|
List<SltInfoVo> validRecords = gqjResultList.stream()
|
||||||
|
.filter(vo -> {
|
||||||
|
if (vo.getAgreementId() == null) {
|
||||||
|
log.warn("过滤掉协议ID为空的记录:{}", vo.getAgreementCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (vo.getAgreementCode() == null || vo.getAgreementCode().trim().isEmpty()) {
|
||||||
|
log.warn("过滤掉协议号为空的记录:agreementId={}", vo.getAgreementId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// unitName 和 projectName 允许为空,但记录日志
|
||||||
|
if (vo.getUnitName() == null || vo.getUnitName().trim().isEmpty()) {
|
||||||
|
log.warn("协议 {} 的单位名称为空", vo.getAgreementCode());
|
||||||
|
}
|
||||||
|
if (vo.getProjectName() == null || vo.getProjectName().trim().isEmpty()) {
|
||||||
|
log.warn("协议 {} 的工程名称为空", vo.getAgreementCode());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (validRecords.size() < gqjResultList.size()) {
|
||||||
|
log.warn("数据验证:过滤掉 {} 条无效记录,剩余 {} 条有效记录",
|
||||||
|
gqjResultList.size() - validRecords.size(), validRecords.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存未结算报表记录
|
||||||
|
if (CollectionUtils.isNotEmpty(validRecords)) {
|
||||||
|
log.info("准备保存 {} 条未结算报表记录到数据库", validRecords.size());
|
||||||
|
|
||||||
|
// 打印前几条记录的详细信息用于调试
|
||||||
|
if (log.isDebugEnabled() && !validRecords.isEmpty()) {
|
||||||
|
SltInfoVo firstRecord = validRecords.get(0);
|
||||||
|
log.debug("第一条记录详情:agreementId={}, agreementCode={}, unitName={}, projectName={}, " +
|
||||||
|
"settlementType={}, leaseCost={}, repairCost={}, loseCost={}, scrapCost={}, reductionCost={}",
|
||||||
|
firstRecord.getAgreementId(), firstRecord.getAgreementCode(),
|
||||||
|
firstRecord.getUnitName(), firstRecord.getProjectName(),
|
||||||
|
firstRecord.getSettlementType(), firstRecord.getLeaseCost(),
|
||||||
|
firstRecord.getRepairCost(), firstRecord.getLoseCost(),
|
||||||
|
firstRecord.getScrapCost(), firstRecord.getReductionCost());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
validRecords.forEach(vo -> vo.setYearMonth(DateTime.now().toString("yyyyMM")));
|
||||||
|
int rows = sltAgreementInfoMapper.addSltHistoryReport(validRecords);
|
||||||
|
log.info("未结算报表定时器:保存未结算报表记录完成,受影响行数:{}", rows);
|
||||||
|
|
||||||
|
|
||||||
|
// 提取出来全部的租赁明细数据
|
||||||
|
List<SltAgreementInfo> leaseDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getLeaseList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(leaseDetails)) {
|
||||||
|
leaseDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(1);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportLeaseDetail(leaseDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取出来全部的维修明细数据
|
||||||
|
List<SltAgreementInfo> repairDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getRepairList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(repairDetails)) {
|
||||||
|
repairDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(1);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportRepairDetail(repairDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取出来全部的丢失明细数据
|
||||||
|
List<SltAgreementInfo> loseDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getLoseList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(loseDetails)) {
|
||||||
|
loseDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(1);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportLoseDetail(loseDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取出来全部的报废明细数据
|
||||||
|
List<SltAgreementInfo> scrapDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getScrapList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(scrapDetails)) {
|
||||||
|
scrapDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(1);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportScrapDetail(scrapDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存未结算报表记录到数据库失败,记录数量:{}", validRecords.size(), e);
|
||||||
|
// 打印所有记录的关键信息用于排查
|
||||||
|
validRecords.forEach(vo -> {
|
||||||
|
log.error("失败记录:agreementId={}, agreementCode={}, unitName={}, projectName={}",
|
||||||
|
vo.getAgreementId(), vo.getAgreementCode(), vo.getUnitName(), vo.getProjectName());
|
||||||
|
});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("未结算报表定时器:没有可保存的未结算报表记录!");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存未结算报表记录失败", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
// 在整个批量处理完成后清理缓存,而不是在每次循环中清理
|
||||||
|
sltAgreementInfoService.clearCache();
|
||||||
|
log.info("缓存已清理");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("-----------保存未结算记录定时器执行完毕-----------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务 -- 保存未结算报表记录 -- 每月最后一天的23点10分执行
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 10 23 L * ?", zone = "Asia/Shanghai")
|
||||||
|
public void saveUnSltSafetyHistoryReport() {
|
||||||
|
System.out.println("-----------开始执行保存未结算记录定时器-----------");
|
||||||
|
// ----------- 查询未结算的全部协议 ---------------
|
||||||
|
List<SltAgreementInfo> list = sltAgreementInfoService.getSltReportList(new SltAgreementInfo());
|
||||||
|
// 如果没有数据,直接终止任务
|
||||||
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
|
log.warn("未结算报表定时器:没有查询到未结算的协议,任务终止!");
|
||||||
|
System.err.println("未结算报表定时器:没有查询到未结算的协议,任务终止");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("查询到未结算协议数量: {}", list.size());
|
||||||
|
|
||||||
|
// ----------- 给查询出来的协议设置权限控制(先查询工器具) ---------------
|
||||||
|
int settlementType = 2; // 1:安全工器具结算单
|
||||||
|
|
||||||
|
// --------- 拿到list中所有的agreementId存成集合,给每个info赋值 ------------------
|
||||||
|
List<Long> agreementIdsArray = list.stream()
|
||||||
|
.map(SltAgreementInfo::getAgreementId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (agreementIdsArray.isEmpty()) {
|
||||||
|
log.warn("未结算报表定时器:没有查询到有效的协议ID,任务终止!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------- 定义结果集合 ------------------
|
||||||
|
List<SltInfoVo> gqjResultList = new ArrayList<>(list.size());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 批量处理,减少单个查询
|
||||||
|
log.info("开始批量处理 {} 个协议的费用明细", list.size());
|
||||||
|
|
||||||
|
list.forEach(info -> {
|
||||||
|
try {
|
||||||
|
info.setSettlementType(settlementType);
|
||||||
|
info.setAgreementIds(agreementIdsArray);
|
||||||
|
|
||||||
|
// 查询每个协议的各项费用明细
|
||||||
|
SltInfoVo vo = sltAgreementInfoService.getSltInfoReportBatch(info);
|
||||||
|
if (vo != null && !ObjectUtil.isEmpty(vo)) {
|
||||||
|
vo.setAgreementId(info.getAgreementId());
|
||||||
|
vo.setAgreementCode(info.getAgreementCode());
|
||||||
|
vo.setSettlementType(settlementType);
|
||||||
|
gqjResultList.add(vo);
|
||||||
|
log.debug("协议 {} 费用明细处理成功", info.getAgreementCode());
|
||||||
|
} else {
|
||||||
|
log.debug("协议 {} 没有费用明细数据", info.getAgreementCode());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理协议 {} 时出错: {}", info.getAgreementCode(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
log.info("批量处理完成,共获得 {} 条有效费用记录", gqjResultList.size());
|
||||||
|
|
||||||
|
// 数据验证:过滤掉关键字段为空的记录
|
||||||
|
List<SltInfoVo> validRecords = gqjResultList.stream()
|
||||||
|
.filter(vo -> {
|
||||||
|
if (vo.getAgreementId() == null) {
|
||||||
|
log.warn("过滤掉协议ID为空的记录:{}", vo.getAgreementCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (vo.getAgreementCode() == null || vo.getAgreementCode().trim().isEmpty()) {
|
||||||
|
log.warn("过滤掉协议号为空的记录:agreementId={}", vo.getAgreementId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// unitName 和 projectName 允许为空,但记录日志
|
||||||
|
if (vo.getUnitName() == null || vo.getUnitName().trim().isEmpty()) {
|
||||||
|
log.warn("协议 {} 的单位名称为空", vo.getAgreementCode());
|
||||||
|
}
|
||||||
|
if (vo.getProjectName() == null || vo.getProjectName().trim().isEmpty()) {
|
||||||
|
log.warn("协议 {} 的工程名称为空", vo.getAgreementCode());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (validRecords.size() < gqjResultList.size()) {
|
||||||
|
log.warn("数据验证:过滤掉 {} 条无效记录,剩余 {} 条有效记录",
|
||||||
|
gqjResultList.size() - validRecords.size(), validRecords.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存未结算报表记录
|
||||||
|
if (CollectionUtils.isNotEmpty(validRecords)) {
|
||||||
|
log.info("准备保存 {} 条未结算报表记录到数据库", validRecords.size());
|
||||||
|
|
||||||
|
// 打印前几条记录的详细信息用于调试
|
||||||
|
if (log.isDebugEnabled() && !validRecords.isEmpty()) {
|
||||||
|
SltInfoVo firstRecord = validRecords.get(0);
|
||||||
|
log.debug("第一条记录详情:agreementId={}, agreementCode={}, unitName={}, projectName={}, " +
|
||||||
|
"settlementType={}, leaseCost={}, repairCost={}, loseCost={}, scrapCost={}, reductionCost={}",
|
||||||
|
firstRecord.getAgreementId(), firstRecord.getAgreementCode(),
|
||||||
|
firstRecord.getUnitName(), firstRecord.getProjectName(),
|
||||||
|
firstRecord.getSettlementType(), firstRecord.getLeaseCost(),
|
||||||
|
firstRecord.getRepairCost(), firstRecord.getLoseCost(),
|
||||||
|
firstRecord.getScrapCost(), firstRecord.getReductionCost());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
validRecords.forEach(vo -> vo.setYearMonth(DateTime.now().toString("yyyyMM")));
|
||||||
|
int rows = sltAgreementInfoMapper.addSltHistoryReport(validRecords);
|
||||||
|
log.info("未结算报表定时器:保存未结算报表记录完成,受影响行数:{}", rows);
|
||||||
|
|
||||||
|
|
||||||
|
// 提取出来全部的租赁明细数据
|
||||||
|
List<SltAgreementInfo> leaseDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getLeaseList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(leaseDetails)) {
|
||||||
|
leaseDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(2);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportLeaseDetail(leaseDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取出来全部的维修明细数据
|
||||||
|
List<SltAgreementInfo> repairDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getRepairList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(repairDetails)) {
|
||||||
|
repairDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(2);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportRepairDetail(repairDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取出来全部的丢失明细数据
|
||||||
|
List<SltAgreementInfo> loseDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getLoseList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(loseDetails)) {
|
||||||
|
loseDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(2);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportLoseDetail(loseDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取出来全部的报废明细数据
|
||||||
|
List<SltAgreementInfo> scrapDetails = validRecords.stream()
|
||||||
|
.map(SltInfoVo::getScrapList)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isNotEmpty(scrapDetails)) {
|
||||||
|
scrapDetails.forEach(detail -> {
|
||||||
|
detail.setYearMonth(DateTime.now().toString("yyyyMM"));
|
||||||
|
detail.setSettlementType(2);
|
||||||
|
});
|
||||||
|
sltAgreementInfoMapper.addSltHistoryReportScrapDetail(scrapDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存未结算报表记录到数据库失败,记录数量:{}", validRecords.size(), e);
|
||||||
|
// 打印所有记录的关键信息用于排查
|
||||||
|
validRecords.forEach(vo -> {
|
||||||
|
log.error("失败记录:agreementId={}, agreementCode={}, unitName={}, projectName={}",
|
||||||
|
vo.getAgreementId(), vo.getAgreementCode(), vo.getUnitName(), vo.getProjectName());
|
||||||
|
});
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("未结算报表定时器:没有可保存的未结算报表记录!");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存未结算报表记录失败", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
// 在整个批量处理完成后清理缓存,而不是在每次循环中清理
|
||||||
|
sltAgreementInfoService.clearCache();
|
||||||
|
log.info("缓存已清理");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("-----------保存未结算记录定时器执行完毕-----------");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private ISltAgreementInfoService sltAgreementInfoService;
|
private ISltAgreementInfoService sltAgreementInfoService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
private SltHistoryReportService sltHistoryReportService;
|
private SltHistoryReportService sltHistoryReportService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
|
@ -1529,7 +1530,7 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (agreementIdsArray.isEmpty()) {
|
if (agreementIdsArray.isEmpty()) {
|
||||||
return getDataTable(new ArrayList<>());
|
return getDataTable(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------- 定义返回集合 ------------------
|
// --------- 定义返回集合 ------------------
|
||||||
|
|
@ -1554,14 +1555,6 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 移除领、修、丢、废4项都没有明细的结算信息
|
|
||||||
// dataList.removeIf(vo -> CollectionUtils.isEmpty(vo.getLeaseList())
|
|
||||||
// && CollectionUtils.isEmpty(vo.getRepairList())
|
|
||||||
// && CollectionUtils.isEmpty(vo.getScrapList())
|
|
||||||
// && CollectionUtils.isEmpty(vo.getLoseList())
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|
||||||
TableDataInfo resultTableData = getDataTable(dataList);
|
TableDataInfo resultTableData = getDataTable(dataList);
|
||||||
if (RequestContext.get("unSltAgreementListCount") != null) {
|
if (RequestContext.get("unSltAgreementListCount") != null) {
|
||||||
if (RequestContext.get("unSltAgreementListCount") instanceof Long) {
|
if (RequestContext.get("unSltAgreementListCount") instanceof Long) {
|
||||||
|
|
@ -1590,7 +1583,7 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
* @return 历史报表列表
|
* @return 历史报表列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getHistoryReportList")
|
@GetMapping("/getHistoryReportList")
|
||||||
public TableDataInfo getHistoryReportList(@RequestParam String yearMonth, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
|
public TableDataInfo getHistoryReportList(@RequestParam String yearMonth) {
|
||||||
// 参数验证
|
// 参数验证
|
||||||
if (StrUtil.isBlank(yearMonth)) {
|
if (StrUtil.isBlank(yearMonth)) {
|
||||||
throw new ServiceException("年月参数不能为空");
|
throw new ServiceException("年月参数不能为空");
|
||||||
|
|
@ -1601,10 +1594,13 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
throw new ServiceException("年月格式错误,应为 yyyy-MM");
|
throw new ServiceException("年月格式错误,应为 yyyy-MM");
|
||||||
}
|
}
|
||||||
|
|
||||||
startPage();
|
// 获取结算权限
|
||||||
|
int settlementType = sltAgreementInfoService.checkLoginUserHasSettlementPermission();
|
||||||
|
|
||||||
|
// 设置查询条件
|
||||||
SltHistoryReport query = new SltHistoryReport();
|
SltHistoryReport query = new SltHistoryReport();
|
||||||
query.setYearMonth(yearMonth);
|
query.setSettlementType(settlementType);
|
||||||
|
query.setYearMonth(yearMonth.replace("-", ""));
|
||||||
List<SltHistoryReport> list = sltHistoryReportService.selectHistoryReportList(query);
|
List<SltHistoryReport> list = sltHistoryReportService.selectHistoryReportList(query);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
@ -1628,7 +1624,7 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
|
|
||||||
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
||||||
query.setAgreementId(agreementId);
|
query.setAgreementId(agreementId);
|
||||||
query.setYearMonth(yearMonth);
|
query.setYearMonth(yearMonth.replace("-", ""));
|
||||||
|
|
||||||
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryLeaseCostDetails(query);
|
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryLeaseCostDetails(query);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
|
|
@ -1653,7 +1649,7 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
|
|
||||||
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
||||||
query.setAgreementId(agreementId);
|
query.setAgreementId(agreementId);
|
||||||
query.setYearMonth(yearMonth);
|
query.setYearMonth(yearMonth.replace("-", ""));
|
||||||
|
|
||||||
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryRepairCostDetails(query);
|
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryRepairCostDetails(query);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
|
|
@ -1665,15 +1661,19 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
* @return 历史丢失费用详情列表
|
* @return 历史丢失费用详情列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getHistoryLoseCostDetails")
|
@GetMapping("/getHistoryLoseCostDetails")
|
||||||
public TableDataInfo getHistoryLoseCostDetails(SltHistoryReportDetail query) {
|
public TableDataInfo getHistoryLoseCostDetails(@RequestParam String agreementId, @RequestParam String yearMonth) {
|
||||||
// 参数验证
|
// 参数验证
|
||||||
if (query.getAgreementId() == null || query.getAgreementId().trim().isEmpty()) {
|
if (agreementId == null || agreementId.trim().isEmpty()) {
|
||||||
throw new ServiceException("协议ID不能为空");
|
throw new ServiceException("协议ID不能为空");
|
||||||
}
|
}
|
||||||
if (query.getYearMonth() == null || query.getYearMonth().trim().isEmpty()) {
|
if (yearMonth == null || yearMonth.trim().isEmpty()) {
|
||||||
throw new ServiceException("年月参数不能为空");
|
throw new ServiceException("年月参数不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
||||||
|
query.setAgreementId(agreementId);
|
||||||
|
query.setYearMonth(yearMonth.replace("-", ""));
|
||||||
|
|
||||||
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryLoseCostDetails(query);
|
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryLoseCostDetails(query);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
@ -1696,7 +1696,7 @@ public class SltAgreementInfoController extends BaseController {
|
||||||
|
|
||||||
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
SltHistoryReportDetail query = new SltHistoryReportDetail();
|
||||||
query.setAgreementId(agreementId);
|
query.setAgreementId(agreementId);
|
||||||
query.setYearMonth(yearMonth);
|
query.setYearMonth(yearMonth.replace("-", ""));
|
||||||
|
|
||||||
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryScrapCostDetails(query);
|
List<SltHistoryReportDetail> list = sltHistoryReportService.selectHistoryScrapCostDetails(query);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
|
|
|
||||||
|
|
@ -267,5 +267,8 @@ public class SltAgreementInfo extends BaseEntity {
|
||||||
@ApiModelProperty(value = "可转数量")
|
@ApiModelProperty(value = "可转数量")
|
||||||
private BigDecimal transNum;
|
private BigDecimal transNum;
|
||||||
|
|
||||||
|
@ApiModelProperty("年月")
|
||||||
|
private String yearMonth;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,4 +134,6 @@ public class SltInfoVo {
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date applyTime;
|
private Date applyTime;
|
||||||
|
|
||||||
|
private String yearMonth;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,16 @@ import org.apache.ibatis.annotations.Param;
|
||||||
*/
|
*/
|
||||||
public interface SltAgreementInfoMapper {
|
public interface SltAgreementInfoMapper {
|
||||||
|
|
||||||
|
int addSltHistoryReport(List<SltInfoVo> list);
|
||||||
|
|
||||||
|
int addSltHistoryReportLeaseDetail(List<SltAgreementInfo> list);
|
||||||
|
|
||||||
|
int addSltHistoryReportRepairDetail(List<SltAgreementInfo> list);
|
||||||
|
|
||||||
|
int addSltHistoryReportLoseDetail(List<SltAgreementInfo> list);
|
||||||
|
|
||||||
|
int addSltHistoryReportScrapDetail(List<SltAgreementInfo> list);
|
||||||
|
|
||||||
List<SltHistoryReport> selectSltHistoryReportList(SltHistoryReport sltHistoryReport);
|
List<SltHistoryReport> selectSltHistoryReportList(SltHistoryReport sltHistoryReport);
|
||||||
|
|
||||||
List<SltHistoryReportDetail> selectSltHistoryLeaseDetail(SltHistoryReportDetail sltHistoryReportDetail);
|
List<SltHistoryReportDetail> selectSltHistoryLeaseDetail(SltHistoryReportDetail sltHistoryReportDetail);
|
||||||
|
|
|
||||||
|
|
@ -268,24 +268,29 @@ public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService {
|
||||||
BigDecimal scrapCost= BigDecimal.ZERO, loseCost= BigDecimal.ZERO, reducCost= BigDecimal.ZERO;
|
BigDecimal scrapCost= BigDecimal.ZERO, loseCost= BigDecimal.ZERO, reducCost= BigDecimal.ZERO;
|
||||||
|
|
||||||
if (leaseListCache.get() == null) {
|
if (leaseListCache.get() == null) {
|
||||||
|
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量租赁费用查询");
|
||||||
// 调用一次性批量租赁费用查询
|
// 调用一次性批量租赁费用查询
|
||||||
leaseListCache.set(sltAgreementInfoMapper.getLeaseListBatch(info));
|
leaseListCache.set(sltAgreementInfoMapper.getLeaseListBatch(info));
|
||||||
}
|
}
|
||||||
if (lostListCache.get() == null) {
|
if (lostListCache.get() == null) {
|
||||||
|
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量丢失费用查询");
|
||||||
// 调用一次性批量丢失费用查询
|
// 调用一次性批量丢失费用查询
|
||||||
lostListCache.set(sltAgreementInfoMapper.getLoseListBatch(info));
|
lostListCache.set(sltAgreementInfoMapper.getLoseListBatch(info));
|
||||||
}
|
}
|
||||||
if (reductionListCache.get() == null) {
|
if (reductionListCache.get() == null) {
|
||||||
|
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量减免费用查询");
|
||||||
// 调用一次性批量减免费用查询
|
// 调用一次性批量减免费用查询
|
||||||
SltAgreementReduce bean =new SltAgreementReduce();
|
SltAgreementReduce bean =new SltAgreementReduce();
|
||||||
bean.setAgreementIds(info.getAgreementIds());
|
bean.setAgreementIds(info.getAgreementIds());
|
||||||
reductionListCache.set(sltAgreementRecudceMapper.getReductionListBatch(bean));
|
reductionListCache.set(sltAgreementRecudceMapper.getReductionListBatch(bean));
|
||||||
}
|
}
|
||||||
if (repairListCache.get() == null) {
|
if (repairListCache.get() == null) {
|
||||||
|
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量维修费用查询");
|
||||||
// 调用一次性批量维修费用查询
|
// 调用一次性批量维修费用查询
|
||||||
repairListCache.set(sltAgreementInfoMapper.getRepairDetailsListBatch(info, null));
|
repairListCache.set(sltAgreementInfoMapper.getRepairDetailsListBatch(info, null));
|
||||||
}
|
}
|
||||||
if (scrapListCache.get() == null) {
|
if (scrapListCache.get() == null) {
|
||||||
|
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量报废费用查询");
|
||||||
// 调用一次性批量报废费用查询
|
// 调用一次性批量报废费用查询
|
||||||
scrapListCache.set(sltAgreementInfoMapper.getScrapDetailsListBatch(info));
|
scrapListCache.set(sltAgreementInfoMapper.getScrapDetailsListBatch(info));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1585,8 +1585,118 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
`year_month` as yearMonth,
|
`year_month` as yearMonth,
|
||||||
create_time as createTime
|
create_time as createTime
|
||||||
FROM slt_history_report
|
FROM slt_history_report
|
||||||
WHERE `year_month` = #{yearMonth}
|
WHERE
|
||||||
|
`year_month` = #{yearMonth}
|
||||||
|
and settlement_type = #{settlementType}
|
||||||
ORDER BY create_time DESC
|
ORDER BY create_time DESC
|
||||||
LIMIT #{pageNum}, #{pageSize}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<insert id="addSltHistoryReport">
|
||||||
|
insert into slt_history_report (agreement_id,agreement_code,unit_name,project_name,
|
||||||
|
settlement_type,lease_cost,repair_cost,lose_cost,scrap_cost,reduction_cost,`year_month`,create_time
|
||||||
|
)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.agreementId},
|
||||||
|
#{item.agreementCode},
|
||||||
|
#{item.unitName},
|
||||||
|
#{item.projectName},
|
||||||
|
#{item.settlementType},
|
||||||
|
#{item.leaseCost},
|
||||||
|
#{item.repairCost},
|
||||||
|
#{item.loseCost},
|
||||||
|
#{item.scrapCost},
|
||||||
|
#{item.reductionCost},
|
||||||
|
#{item.yearMonth},
|
||||||
|
NOW()
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="addSltHistoryReportLeaseDetail">
|
||||||
|
insert into slt_history_report_detail
|
||||||
|
(agreement_id,type_name,model_name,mt_unit_name,lease_price,num,back_num,start_time,end_time,lease_days,part_type,cost_type,costs,settlement_type,`year_month`)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.agreementId},
|
||||||
|
#{item.typeName},
|
||||||
|
#{item.modelName},
|
||||||
|
#{item.mtUnitName},
|
||||||
|
#{item.leasePrice},
|
||||||
|
#{item.num},
|
||||||
|
#{item.backNum},
|
||||||
|
#{item.startTime},
|
||||||
|
#{item.endTime},
|
||||||
|
#{item.leaseDays},
|
||||||
|
#{item.partType},
|
||||||
|
1,
|
||||||
|
#{item.costs},
|
||||||
|
#{item.settlementType},
|
||||||
|
#{item.yearMonth}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="addSltHistoryReportRepairDetail">
|
||||||
|
insert into slt_history_report_detail
|
||||||
|
(agreement_id,type_name,model_name,mt_unit_name,lease_price,num,part_type,cost_type,costs,settlement_type,`year_month`)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.agreementId},
|
||||||
|
#{item.typeName},
|
||||||
|
#{item.modelName},
|
||||||
|
#{item.mtUnitName},
|
||||||
|
#{item.leasePrice},
|
||||||
|
#{item.num},
|
||||||
|
#{item.partType},
|
||||||
|
2,
|
||||||
|
#{item.costs},
|
||||||
|
#{item.settlementType},
|
||||||
|
#{item.yearMonth}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="addSltHistoryReportLoseDetail">
|
||||||
|
insert into slt_history_report_detail
|
||||||
|
(agreement_id,type_name,model_name,mt_unit_name,lease_price,num,cost_type,costs,settlement_type,`year_month`)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.agreementId},
|
||||||
|
#{item.typeName},
|
||||||
|
#{item.modelName},
|
||||||
|
#{item.mtUnitName},
|
||||||
|
#{item.leasePrice},
|
||||||
|
#{item.num},
|
||||||
|
3,
|
||||||
|
#{item.costs},
|
||||||
|
#{item.settlementType},
|
||||||
|
#{item.yearMonth}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<insert id="addSltHistoryReportScrapDetail">
|
||||||
|
insert into slt_history_report_detail
|
||||||
|
(agreement_id,type_name,model_name,mt_unit_name,lease_price,num,cost_type,costs,settlement_type,`year_month`)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(
|
||||||
|
#{item.agreementId},
|
||||||
|
#{item.typeName},
|
||||||
|
#{item.modelName},
|
||||||
|
#{item.mtUnitName},
|
||||||
|
#{item.leasePrice},
|
||||||
|
#{item.num},
|
||||||
|
4,
|
||||||
|
#{item.costs},
|
||||||
|
#{item.settlementType},
|
||||||
|
#{item.yearMonth}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue