领料明细导出合并同一天同一型号机具数据

This commit is contained in:
马三炮 2026-01-22 15:24:01 +08:00
parent 4065a867a4
commit eb6d66c279
1 changed files with 39 additions and 6 deletions

View File

@ -28,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -849,7 +848,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
List<ProjectLeaseCostDetail> leaseDetails = queryProjectLeaseDetails(queryParam); List<ProjectLeaseCostDetail> leaseDetails = queryProjectLeaseDetails(queryParam);
List<ProjectLeaseCostDetail> returnDetails = queryProjectReturnDetails(queryParam); List<ProjectLeaseCostDetail> returnDetails = queryProjectReturnDetails(queryParam);
//计算差额 //计算差额
calculateMaterialDifference(leaseDetails, returnDetails); leaseDetails =calculateMaterialDifference(leaseDetails, returnDetails);
List<ProjectLeaseCostDetail> allDetails = new ArrayList<>(); List<ProjectLeaseCostDetail> allDetails = new ArrayList<>();
if (leaseDetails != null) { if (leaseDetails != null) {
allDetails.addAll(leaseDetails); allDetails.addAll(leaseDetails);
@ -1000,9 +999,45 @@ public class ProjectCostServiceImpl implements ProjectCostService {
BigDecimal.valueOf(detail.getReturnNum()) : BigDecimal.ZERO; BigDecimal.valueOf(detail.getReturnNum()) : BigDecimal.ZERO;
totalReturn = totalReturn.add(returnQty); totalReturn = totalReturn.add(returnQty);
} }
List<ProjectLeaseCostDetail> leasesNew = new ArrayList<>();
// 使用 Map 按日期分组,同一天的合并一起
Map<LocalDate, ProjectLeaseCostDetail> mergedMap = new LinkedHashMap<>();
for (ProjectLeaseCostDetail detail : leases) {
if ("牵张设备".equals(detail.getMachineCodeName()) ||"施工机械".equals(detail.getMachineCodeName()) ||"仪器设备".equals(detail.getMachineCodeName())){
leasesNew.add(detail);
}else {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String dateOnly = detail.getOperateTime().substring(0, 10);
LocalDate dateKey = LocalDate.parse(dateOnly,
formatter);
if (mergedMap.containsKey(dateKey)) {
// 已存在该日期的记录合并数量
ProjectLeaseCostDetail existing = mergedMap.get(dateKey);
// 累加 leaseNum
existing.setLeaseNum(
(existing.getLeaseNum() != null ? existing.getLeaseNum() : 0) +
(detail.getLeaseNum() != null ? detail.getLeaseNum() : 0)
);
} else {
// 新日期的记录创建副本避免修改原对象
mergedMap.put(dateKey, detail);
}
}
}
//保存合并后的数据
for (Map.Entry<LocalDate, ProjectLeaseCostDetail> entry : mergedMap.entrySet()) {
ProjectLeaseCostDetail materialLeases = entry.getValue();
leasesNew.add(materialLeases);
}
// 按时间顺序处理每次领料 // 按时间顺序处理每次领料
for (ProjectLeaseCostDetail lease : leases) { for (ProjectLeaseCostDetail lease : leasesNew) {
//比较当前退料数量和领料数量 //比较当前退料数量和领料数量
if(BigDecimal.valueOf(lease.getLeaseNum()).compareTo(totalReturn)>=0){ if(BigDecimal.valueOf(lease.getLeaseNum()).compareTo(totalReturn)>=0){
@ -1894,8 +1929,6 @@ public class ProjectCostServiceImpl implements ProjectCostService {
// 获取所有物资的领退记录 // 获取所有物资的领退记录
List<ProjectCostCalculationDetail> details = calculation.getDetails(); List<ProjectCostCalculationDetail> details = calculation.getDetails();
if (details != null && !details.isEmpty()) { if (details != null && !details.isEmpty()) {
int index = 1;
int index2 = 1;
for (ProjectCostCalculationDetail detail : details) { for (ProjectCostCalculationDetail detail : details) {
List<ProjectLeaseCostDetail> operRecords = detail.getDetails(); List<ProjectLeaseCostDetail> operRecords = detail.getDetails();
if (operRecords != null && !operRecords.isEmpty()) { if (operRecords != null && !operRecords.isEmpty()) {
@ -1916,7 +1949,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
row.put("新编码", record.getMachineCode()); row.put("新编码", record.getMachineCode());
row.put("单位", record.getMachineUnit()); row.put("单位", record.getMachineUnit());
row.put("数量", record.getOperateType() == 1 ? record.getLeaseNum() : record.getReturnNum()); row.put("数量", record.getOperateType() == 1 ? record.getLeaseNum() : record.getReturnNum());
row.put("差额", record.getDifferenceQuantity().compareTo(BigDecimal.valueOf(record.getLeaseNum())) > 0 ? record.getLeaseNum():record.getDifferenceQuantity()); row.put("差额", record.getDifferenceQuantity());
row.put("租赁单位", record.getBsName()); row.put("租赁单位", record.getBsName());
row.put("备注",null); row.put("备注",null);
dataList.add(row); dataList.add(row);