修改日期
This commit is contained in:
parent
38a49ad0a8
commit
2307a79659
|
|
@ -26,8 +26,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -336,6 +338,14 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
|
||||
return settlementId;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime operateTime = LocalDateTime.parse("2025-04-14 16:14:00", formatter);
|
||||
LocalDateTime endtime = LocalDateTime.parse("2025-05-26 14:21:00", formatter);
|
||||
long daysBetween = java.time.Duration.between(operateTime, endtime).toDays();
|
||||
System.err.println(daysBetween);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> calculateSettlement(ProjectLeaseCostDetail o) {
|
||||
|
|
@ -421,7 +431,9 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
for (Map.Entry<String, List<ProjectLeaseCostDetail>> entry : groupedByMachineType.entrySet()) {
|
||||
String machineTypeId = entry.getKey();
|
||||
List<ProjectLeaseCostDetail> items = entry.getValue();
|
||||
|
||||
if("531".equals(machineTypeId)) {
|
||||
System.err.println(machineTypeId);
|
||||
}
|
||||
// 按操作时间排序
|
||||
items.sort(Comparator.comparing(ProjectLeaseCostDetail::getOperateTime,
|
||||
Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
|
|
@ -487,8 +499,12 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
// 如果统计期间内有操作,计算从开始时间到第一个操作时间的费用
|
||||
// 如果统计期间内没有操作,计算从开始时间到结束时间的费用
|
||||
LocalDateTime endTimeForInitialSegment = firstOperateTimeInPeriod != null ? firstOperateTimeInPeriod : endDate;
|
||||
long daysBetween = java.time.Duration.between(startDate, endTimeForInitialSegment).toDays();
|
||||
long daysBetween = getDay(startDate, endTimeForInitialSegment);
|
||||
|
||||
LocalDateTime lastTimes = LocalDateTime.parse(o.getEndTime()+" 23:59:59", formatter);
|
||||
if(lastTimes.equals(endTimeForInitialSegment)) {
|
||||
daysBetween+=1;
|
||||
}
|
||||
if (daysBetween > 0) {
|
||||
double segmentAmount = currentCount * unitPrice * daysBetween;
|
||||
totalItemAmount += segmentAmount;
|
||||
|
|
@ -536,7 +552,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
// 计算上一个时间点到当前操作时间的租赁费用
|
||||
if (currentCount > 0 && !previousTime.equals(operateTime)) {
|
||||
// 计算两个时间点之间的天数
|
||||
long daysBetween = java.time.Duration.between(previousTime, operateTime).toDays();
|
||||
long daysBetween = getDay(previousTime, operateTime);
|
||||
|
||||
// 如果天数为0(开始时间等于结束时间),跳过这个时间段
|
||||
if (daysBetween == 0) {
|
||||
|
|
@ -547,6 +563,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
daysBetween = 1;
|
||||
}
|
||||
|
||||
|
||||
// 计算该时间段的租赁费用
|
||||
double segmentAmount = currentCount * unitPrice * daysBetween;
|
||||
totalItemAmount += segmentAmount;
|
||||
|
|
@ -594,7 +611,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
// 计算最后一个操作时间点到统计结束时间的租赁费用
|
||||
if (currentCount > 0 && !previousTime.equals(endDate)) {
|
||||
// 计算两个时间点之间的天数
|
||||
long daysBetween = java.time.Duration.between(previousTime, endDate).toDays();
|
||||
long daysBetween =getDay(previousTime, endDate);
|
||||
|
||||
// 如果天数为0(开始时间等于结束时间),跳过这个时间段
|
||||
if (daysBetween == 0) {
|
||||
|
|
@ -603,6 +620,8 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
// 不足一天按一天计算
|
||||
if (daysBetween < 1) {
|
||||
daysBetween = 1;
|
||||
}else {
|
||||
daysBetween+=1;
|
||||
}
|
||||
|
||||
// 计算该时间段的租赁费用
|
||||
|
|
@ -688,6 +707,15 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|||
return result;
|
||||
}
|
||||
|
||||
public long getDay(LocalDateTime operateTime,LocalDateTime endtime) {
|
||||
LocalDate startDate = operateTime.toLocalDate();
|
||||
LocalDate endDate = endtime.toLocalDate();
|
||||
long naturalDays = ChronoUnit.DAYS.between(startDate, endDate);
|
||||
System.out.println("自然日天数差(正确结果):" + naturalDays);
|
||||
return naturalDays;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getAllProjects() {
|
||||
List<PlanProBean> proList = planApplicationDao.getProList(new PlanDevBean());
|
||||
|
|
|
|||
Loading…
Reference in New Issue