领料明细导出合并同一天同一型号机具数据
This commit is contained in:
parent
eb6d66c279
commit
693bbe6610
|
|
@ -1,6 +1,5 @@
|
||||||
package com.bonus.cost.service;
|
package com.bonus.cost.service;
|
||||||
|
|
||||||
import com.bonus.core.ExcelUtils;
|
|
||||||
import com.bonus.cost.beans.ProjectCostCalculation;
|
import com.bonus.cost.beans.ProjectCostCalculation;
|
||||||
import com.bonus.cost.beans.ProjectCostCalculationDetail;
|
import com.bonus.cost.beans.ProjectCostCalculationDetail;
|
||||||
import com.bonus.cost.beans.ProjectCostCalculationSegment;
|
import com.bonus.cost.beans.ProjectCostCalculationSegment;
|
||||||
|
|
@ -19,9 +18,7 @@ import org.apache.poi.hssf.usermodel.HSSFFont;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
@ -847,6 +844,9 @@ 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);
|
||||||
|
//同一天的统一类型的机具进行合并
|
||||||
|
leaseDetails = mergeByDay(leaseDetails,1);
|
||||||
|
returnDetails = mergeByDay(returnDetails,2);
|
||||||
//计算差额
|
//计算差额
|
||||||
leaseDetails =calculateMaterialDifference(leaseDetails, returnDetails);
|
leaseDetails =calculateMaterialDifference(leaseDetails, returnDetails);
|
||||||
List<ProjectLeaseCostDetail> allDetails = new ArrayList<>();
|
List<ProjectLeaseCostDetail> allDetails = new ArrayList<>();
|
||||||
|
|
@ -932,6 +932,55 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
return calculation;
|
return calculation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 operateDate 按天合并,累加 leaseNum
|
||||||
|
*/
|
||||||
|
public List<ProjectLeaseCostDetail> mergeByDay(List<ProjectLeaseCostDetail> leases, int i) {
|
||||||
|
List<ProjectLeaseCostDetail> leasesNew = new ArrayList<>();
|
||||||
|
|
||||||
|
// 使用 Map 按日期分组,同一天的合并一起
|
||||||
|
Map<LocalDate, ProjectLeaseCostDetail> mergedMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (ProjectLeaseCostDetail returnDetail : leases) {
|
||||||
|
if ("牵张设备".equals(returnDetail.getMachineCodeName()) ||"施工机械".equals(returnDetail.getMachineCodeName()) ||"仪器设备".equals(returnDetail.getMachineCodeName())){
|
||||||
|
leasesNew.add(returnDetail);
|
||||||
|
}else {
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
String dateOnly = returnDetail.getOperateTime().substring(0, 10);
|
||||||
|
LocalDate dateKey = LocalDate.parse(dateOnly,
|
||||||
|
formatter);
|
||||||
|
if (mergedMap.containsKey(dateKey)) {
|
||||||
|
// 已存在该日期的记录,合并数量
|
||||||
|
ProjectLeaseCostDetail existing = mergedMap.get(dateKey);
|
||||||
|
if (i==1){
|
||||||
|
// 累加 leaseNum
|
||||||
|
existing.setLeaseNum(
|
||||||
|
(existing.getLeaseNum() != null ? existing.getLeaseNum() : 0) +
|
||||||
|
(returnDetail.getLeaseNum() != null ? returnDetail.getLeaseNum() : 0)
|
||||||
|
);
|
||||||
|
}else {
|
||||||
|
// 累加 leaseNum
|
||||||
|
existing.setReturnNum(
|
||||||
|
(existing.getReturnNum() != null ? existing.getReturnNum() : 0) +
|
||||||
|
(returnDetail.getReturnNum() != null ? returnDetail.getReturnNum() : 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 新日期的记录,创建副本(避免修改原对象)
|
||||||
|
mergedMap.put(dateKey, returnDetail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//保存合并后的数据
|
||||||
|
for (Map.Entry<LocalDate, ProjectLeaseCostDetail> entry : mergedMap.entrySet()) {
|
||||||
|
ProjectLeaseCostDetail materialLeases = entry.getValue();
|
||||||
|
leasesNew.add(materialLeases);
|
||||||
|
}
|
||||||
|
return leasesNew;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 计算领退料差额
|
* 计算领退料差额
|
||||||
* @param leaseDetails 领料明细列表
|
* @param leaseDetails 领料明细列表
|
||||||
|
|
@ -999,45 +1048,9 @@ 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 : leasesNew) {
|
for (ProjectLeaseCostDetail lease : leases) {
|
||||||
|
|
||||||
//比较当前退料数量和领料数量
|
//比较当前退料数量和领料数量
|
||||||
if(BigDecimal.valueOf(lease.getLeaseNum()).compareTo(totalReturn)>=0){
|
if(BigDecimal.valueOf(lease.getLeaseNum()).compareTo(totalReturn)>=0){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue