This commit is contained in:
parent
2307a79659
commit
88218faa48
|
|
@ -45,9 +45,16 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProjectCostDao projectCostDao;
|
private ProjectCostDao projectCostDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NewSettlementService newSettlementService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PlanApplicationDao planApplicationDao;
|
private PlanApplicationDao planApplicationDao;
|
||||||
|
|
||||||
|
// 定义两个格式化器:输入格式(带时分秒)、输出格式(仅年月日)
|
||||||
|
private static final DateTimeFormatter INPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
private static final DateTimeFormatter OUTPUT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安全转换为Double类型
|
* 安全转换为Double类型
|
||||||
*
|
*
|
||||||
|
|
@ -346,9 +353,16 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
System.err.println(daysBetween);
|
System.err.println(daysBetween);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> calculateSettlement(ProjectLeaseCostDetail o) {
|
public Map<String, Object> calculateSettlement(ProjectLeaseCostDetail o) {
|
||||||
|
return newSettlementService.getNewSettlement(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String, Object> calculateSettlement2(ProjectLeaseCostDetail o) {
|
||||||
|
|
||||||
|
|
||||||
// 获取领料明细
|
// 获取领料明细
|
||||||
List<ProjectLeaseCostDetail> leaseDetails = queryProjectLeaseDetails(o);
|
List<ProjectLeaseCostDetail> leaseDetails = queryProjectLeaseDetails(o);
|
||||||
// 获取退料明细
|
// 获取退料明细
|
||||||
|
|
@ -429,11 +443,14 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
|
|
||||||
// 对每种物资类型进行计算
|
// 对每种物资类型进行计算
|
||||||
for (Map.Entry<String, List<ProjectLeaseCostDetail>> entry : groupedByMachineType.entrySet()) {
|
for (Map.Entry<String, List<ProjectLeaseCostDetail>> entry : groupedByMachineType.entrySet()) {
|
||||||
|
boolean add=true;
|
||||||
|
boolean onlyAdd=true;
|
||||||
String machineTypeId = entry.getKey();
|
String machineTypeId = entry.getKey();
|
||||||
List<ProjectLeaseCostDetail> items = entry.getValue();
|
List<ProjectLeaseCostDetail> items = entry.getValue();
|
||||||
if("531".equals(machineTypeId)) {
|
if("3627".equals(machineTypeId)) {
|
||||||
System.err.println(machineTypeId);
|
System.err.println(machineTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按操作时间排序
|
// 按操作时间排序
|
||||||
items.sort(Comparator.comparing(ProjectLeaseCostDetail::getOperateTime,
|
items.sort(Comparator.comparing(ProjectLeaseCostDetail::getOperateTime,
|
||||||
Comparator.nullsFirst(Comparator.naturalOrder())));
|
Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||||
|
|
@ -456,6 +473,8 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
|
|
||||||
// 第一步:处理统计期间开始之前的所有操作,计算期初在用数量
|
// 第一步:处理统计期间开始之前的所有操作,计算期初在用数量
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
DateTimeFormatter formatter_day = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
for (ProjectLeaseCostDetail item : items) {
|
for (ProjectLeaseCostDetail item : items) {
|
||||||
if (item == null || item.getOperateTime() == null) {
|
if (item == null || item.getOperateTime() == null) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -484,11 +503,24 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
if (currentCount > 0) {
|
if (currentCount > 0) {
|
||||||
// 找到统计期间内的第一个操作时间
|
// 找到统计期间内的第一个操作时间
|
||||||
LocalDateTime firstOperateTimeInPeriod = null;
|
LocalDateTime firstOperateTimeInPeriod = null;
|
||||||
for (ProjectLeaseCostDetail item : items) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
ProjectLeaseCostDetail item=items.get(i);
|
||||||
if (item == null || item.getOperateTime() == null) {
|
if (item == null || item.getOperateTime() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LocalDateTime operateTime = LocalDateTime.parse(item.getOperateTime(), formatter);
|
LocalDateTime operateTime = LocalDateTime.parse(item.getOperateTime(), formatter);
|
||||||
|
LocalDateTime startTimes = LocalDateTime.parse(o.getStartTime()+" 00:00:01", formatter);
|
||||||
|
//初始日期没有退料的
|
||||||
|
String fastTimes = formatLocalDateTimeToDate(operateTime);
|
||||||
|
String start_times = formatLocalDateTimeToDate(startTimes);
|
||||||
|
//操作时间--如果操作时间为今天的 并且范围内没退料的
|
||||||
|
if(fastTimes.equals(start_times)) {
|
||||||
|
if(2==item.getOperateType()) {
|
||||||
|
onlyAdd=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!operateTime.isBefore(startDate) && !operateTime.isAfter(endDate)) {
|
if (!operateTime.isBefore(startDate) && !operateTime.isAfter(endDate)) {
|
||||||
if (firstOperateTimeInPeriod == null || operateTime.isBefore(firstOperateTimeInPeriod)) {
|
if (firstOperateTimeInPeriod == null || operateTime.isBefore(firstOperateTimeInPeriod)) {
|
||||||
firstOperateTimeInPeriod = operateTime;
|
firstOperateTimeInPeriod = operateTime;
|
||||||
|
|
@ -499,16 +531,39 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
// 如果统计期间内有操作,计算从开始时间到第一个操作时间的费用
|
// 如果统计期间内有操作,计算从开始时间到第一个操作时间的费用
|
||||||
// 如果统计期间内没有操作,计算从开始时间到结束时间的费用
|
// 如果统计期间内没有操作,计算从开始时间到结束时间的费用
|
||||||
LocalDateTime endTimeForInitialSegment = firstOperateTimeInPeriod != null ? firstOperateTimeInPeriod : endDate;
|
LocalDateTime endTimeForInitialSegment = firstOperateTimeInPeriod != null ? firstOperateTimeInPeriod : endDate;
|
||||||
|
|
||||||
|
|
||||||
long daysBetween = getDay(startDate, endTimeForInitialSegment);
|
long daysBetween = getDay(startDate, endTimeForInitialSegment);
|
||||||
|
LocalDateTime startTimes = LocalDateTime.parse(o.getStartTime()+" 00:00:01", formatter);
|
||||||
|
if(!onlyAdd) {
|
||||||
|
if(daysBetween==0) {
|
||||||
|
daysBetween=1;
|
||||||
|
add=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LocalDateTime lastTimes = LocalDateTime.parse(o.getEndTime()+" 23:59:59", formatter);
|
LocalDateTime lastTimes = LocalDateTime.parse(o.getEndTime()+" 23:59:59", formatter);
|
||||||
if(lastTimes.equals(endTimeForInitialSegment)) {
|
String parsedDateOnly = formatLocalDateTimeToDate(lastTimes);
|
||||||
|
String end_times = formatLocalDateTimeToDate(endTimeForInitialSegment);
|
||||||
|
if(add) {
|
||||||
|
if(parsedDateOnly.equals(end_times)) {
|
||||||
daysBetween+=1;
|
daysBetween+=1;
|
||||||
|
}else {
|
||||||
|
ProjectLeaseCostDetail item=items.get(items.size()-1);
|
||||||
|
LocalDateTime operateTime = LocalDateTime.parse(item.getOperateTime(), formatter);
|
||||||
|
|
||||||
|
|
||||||
|
//判断当前数据是最后一条数据 =====
|
||||||
|
if(2==item.getOperateType() && operateTime.equals(endTimeForInitialSegment)) {
|
||||||
|
daysBetween+=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (daysBetween > 0) {
|
if (daysBetween > 0) {
|
||||||
double segmentAmount = currentCount * unitPrice * daysBetween;
|
double segmentAmount = currentCount * unitPrice * daysBetween;
|
||||||
totalItemAmount += segmentAmount;
|
totalItemAmount += segmentAmount;
|
||||||
|
|
||||||
Map<String, Object> segment = new HashMap<>();
|
Map<String, Object> segment = new HashMap<>();
|
||||||
segment.put("startTime", startDate.toString());
|
segment.put("startTime", startDate.toString());
|
||||||
segment.put("endTime", endTimeForInitialSegment.toString());
|
segment.put("endTime", endTimeForInitialSegment.toString());
|
||||||
|
|
@ -531,7 +586,11 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第二步:处理统计期间内的所有操作
|
// 第二步:处理统计期间内的所有操作
|
||||||
for (ProjectLeaseCostDetail item : items) {
|
//数据加一
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
ProjectLeaseCostDetail item=items.get(i);
|
||||||
|
// }
|
||||||
|
// for (ProjectLeaseCostDetail item : items) {
|
||||||
if (item == null || item.getOperateTime() == null) {
|
if (item == null || item.getOperateTime() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -551,9 +610,21 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
|
|
||||||
// 计算上一个时间点到当前操作时间的租赁费用
|
// 计算上一个时间点到当前操作时间的租赁费用
|
||||||
if (currentCount > 0 && !previousTime.equals(operateTime)) {
|
if (currentCount > 0 && !previousTime.equals(operateTime)) {
|
||||||
|
if("3627".equals(machineTypeId)) {
|
||||||
|
System.err.print(machineTypeId);
|
||||||
|
}
|
||||||
// 计算两个时间点之间的天数
|
// 计算两个时间点之间的天数
|
||||||
long daysBetween = getDay(previousTime, operateTime);
|
long daysBetween = getDay(previousTime, operateTime);
|
||||||
|
LocalDateTime lastTimes = LocalDateTime.parse(o.getEndTime()+" 23:59:59", formatter);
|
||||||
|
String parsedDateOnly = formatLocalDateTimeToDate(lastTimes);
|
||||||
|
String end_times = formatLocalDateTimeToDate(operateTime);
|
||||||
|
if(add) {
|
||||||
|
if(parsedDateOnly.equals(end_times)) {
|
||||||
|
if (daysBetween == 0) {
|
||||||
|
daysBetween=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 如果天数为0(开始时间等于结束时间),跳过这个时间段
|
// 如果天数为0(开始时间等于结束时间),跳过这个时间段
|
||||||
if (daysBetween == 0) {
|
if (daysBetween == 0) {
|
||||||
System.out.println("跳过无效时间段: " + previousTime + " 至 " + operateTime + " (开始时间等于结束时间)");
|
System.out.println("跳过无效时间段: " + previousTime + " 至 " + operateTime + " (开始时间等于结束时间)");
|
||||||
|
|
@ -563,6 +634,23 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
daysBetween = 1;
|
daysBetween = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(add) {
|
||||||
|
if(parsedDateOnly.equals(end_times)) {
|
||||||
|
daysBetween+=1;
|
||||||
|
}else {
|
||||||
|
//计算--
|
||||||
|
|
||||||
|
if(i==items.size()-1 && 2==item.getOperateType()) {
|
||||||
|
long datadelNum = item.getReturnNum() != null ? item.getReturnNum() : 0;
|
||||||
|
if(currentCount==datadelNum) {
|
||||||
|
daysBetween+=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
// 计算该时间段的租赁费用
|
// 计算该时间段的租赁费用
|
||||||
double segmentAmount = currentCount * unitPrice * daysBetween;
|
double segmentAmount = currentCount * unitPrice * daysBetween;
|
||||||
|
|
@ -576,7 +664,9 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
segment.put("count", currentCount);
|
segment.put("count", currentCount);
|
||||||
segment.put("amount", segmentAmount);
|
segment.put("amount", segmentAmount);
|
||||||
segments.add(segment);
|
segments.add(segment);
|
||||||
|
if("3627".equals(machineTypeId)) {
|
||||||
|
System.err.print(machineTypeId);
|
||||||
|
}
|
||||||
// 添加调试信息
|
// 添加调试信息
|
||||||
System.out.println("物资ID: " + machineTypeId + ", 时段: " + previousTime + " 至 " + operateTime
|
System.out.println("物资ID: " + machineTypeId + ", 时段: " + previousTime + " 至 " + operateTime
|
||||||
+ ", 天数: " + daysBetween + ", 数量: " + currentCount + ", 单价: " + unitPrice + ", 段金额: "
|
+ ", 天数: " + daysBetween + ", 数量: " + currentCount + ", 单价: " + unitPrice + ", 段金额: "
|
||||||
|
|
@ -613,6 +703,18 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
// 计算两个时间点之间的天数
|
// 计算两个时间点之间的天数
|
||||||
long daysBetween =getDay(previousTime, endDate);
|
long daysBetween =getDay(previousTime, endDate);
|
||||||
|
|
||||||
|
LocalDateTime lastTimes = LocalDateTime.parse(o.getEndTime()+" 23:59:59", formatter);
|
||||||
|
String parsedDateOnly = formatLocalDateTimeToDate(lastTimes);
|
||||||
|
String end_times = formatLocalDateTimeToDate(previousTime);
|
||||||
|
if(add) {
|
||||||
|
if(parsedDateOnly.equals(end_times)) {
|
||||||
|
if (daysBetween == 0) {
|
||||||
|
daysBetween=1;
|
||||||
|
add=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 如果天数为0(开始时间等于结束时间),跳过这个时间段
|
// 如果天数为0(开始时间等于结束时间),跳过这个时间段
|
||||||
if (daysBetween == 0) {
|
if (daysBetween == 0) {
|
||||||
System.out.println("跳过无效时间段: " + previousTime + " 至 " + endDate + " (开始时间等于结束时间)");
|
System.out.println("跳过无效时间段: " + previousTime + " 至 " + endDate + " (开始时间等于结束时间)");
|
||||||
|
|
@ -621,9 +723,13 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
if (daysBetween < 1) {
|
if (daysBetween < 1) {
|
||||||
daysBetween = 1;
|
daysBetween = 1;
|
||||||
}else {
|
}else {
|
||||||
|
if(add) {
|
||||||
daysBetween+=1;
|
daysBetween+=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 计算该时间段的租赁费用
|
// 计算该时间段的租赁费用
|
||||||
double segmentAmount = currentCount * unitPrice * daysBetween;
|
double segmentAmount = currentCount * unitPrice * daysBetween;
|
||||||
totalItemAmount += segmentAmount;
|
totalItemAmount += segmentAmount;
|
||||||
|
|
@ -636,7 +742,9 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
segment.put("count", currentCount);
|
segment.put("count", currentCount);
|
||||||
segment.put("amount", segmentAmount);
|
segment.put("amount", segmentAmount);
|
||||||
segments.add(segment);
|
segments.add(segment);
|
||||||
|
if("3627".equals(machineTypeId)) {
|
||||||
|
System.err.print(machineTypeId);
|
||||||
|
}
|
||||||
// 添加调试信息
|
// 添加调试信息
|
||||||
System.out.println("物资ID: " + machineTypeId + ", 时段: " + previousTime + " 至 " + endDate + ", 天数: "
|
System.out.println("物资ID: " + machineTypeId + ", 时段: " + previousTime + " 至 " + endDate + ", 天数: "
|
||||||
+ daysBetween + ", 数量: " + currentCount + ", 单价: " + unitPrice + ", 段金额: " + segmentAmount);
|
+ daysBetween + ", 数量: " + currentCount + ", 单价: " + unitPrice + ", 段金额: " + segmentAmount);
|
||||||
|
|
@ -707,6 +815,31 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新的结算逻辑
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Map<String, Object> getNewSettlement() {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核心方法:将LocalDateTime格式化为yyyy-MM-dd字符串
|
||||||
|
* @param dateTime 待格式化的LocalDateTime对象
|
||||||
|
* @return 仅年月日的字符串,格式为yyyy-MM-dd
|
||||||
|
*/
|
||||||
|
public static String formatLocalDateTimeToDate(LocalDateTime dateTime) {
|
||||||
|
if (dateTime == null) {
|
||||||
|
return null; // 处理空值,避免空指针
|
||||||
|
}
|
||||||
|
return dateTime.format(OUTPUT_FORMATTER);
|
||||||
|
}
|
||||||
public long getDay(LocalDateTime operateTime,LocalDateTime endtime) {
|
public long getDay(LocalDateTime operateTime,LocalDateTime endtime) {
|
||||||
LocalDate startDate = operateTime.toLocalDate();
|
LocalDate startDate = operateTime.toLocalDate();
|
||||||
LocalDate endDate = endtime.toLocalDate();
|
LocalDate endDate = endtime.toLocalDate();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue