浏览代码

no message

ly 1 年之前
父节点
当前提交
bbdcf008b8

+ 31 - 3
src/main/java/cn/ezhizao/project/business/order/service/impl/BizArchiveInputServiceImpl.java

@@ -1,6 +1,10 @@
 package cn.ezhizao.project.business.order.service.impl;
 
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.Period;
+import java.time.ZoneId;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -545,9 +549,33 @@ public class BizArchiveInputServiceImpl extends ServiceImpl<BizArchiveInputMappe
                     l.setRecords(records.stream().filter(v -> v.getWorkOrderId().equals(l.getId())).collect(Collectors.toList()));
 //                l.setMonthNum(l.getDetails().stream().mapToInt(v -> v.getServiceNum() + v.getFreeNum()).sum());
                     if (l.getStartMonth() != null) {
-                        Integer monthNun = l.getDetails().stream().mapToInt(v -> v.getServiceNum() + v.getFreeNum()).sum();
+                        Calendar calendar = Calendar.getInstance();
+                        Calendar calendar2 = Calendar.getInstance();
+//                        Integer monthNun = l.getDetails().stream().mapToInt(v -> v.getServiceNum() + v.getFreeNum()).sum();
+//                        int monthNun = LocalDate.now().getMonth().getValue();
                         DateTime startDate = DateTime.of(l.getStartMonth());
-                        DateTime endDate = startDate.offsetNew(DateField.MONTH, monthNun - 1);
+                        Date startMonth = l.getStartMonth();
+                        calendar2.setTime(startMonth);
+                        int year = calendar2.get(Calendar.YEAR);
+                        int month = calendar2.get(Calendar.MONTH) + 1; // 月份从 0 开始,所以加 1
+                        Date date = new Date();
+                        calendar.setTime(date);
+                        int year1 = calendar.get(Calendar.YEAR);
+                        int month1 = calendar.get(Calendar.MONTH) + 1; // 月份从 0 开始,所以加 1
+                        LocalDate date1 = LocalDate.of(year1, month1, 1);
+                        LocalDate date2 = LocalDate.of(year, month, 1);
+                        Period period = Period.between(date2, date1);
+                        int months = period.getYears() * 12 + period.getMonths()+1;
+
+                        // 获取当前日期的 LocalDate 对象
+                        LocalDate now = LocalDate.now();
+
+                        // 将 LocalDate 对象的日期设置为当前月份的第一天
+                        LocalDate firstDayOfMonth = now.withDayOfMonth(1);
+
+                        // 将 LocalDate 对象转换为 Date 对象
+                        Date endDate = Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
+
                         // 已完成月小于结束月才会不停工单只修改完成时间。假设完成月大于剩余的结束月则直接停止。
                         // 一次都没完成的话,也要停止。
 //                        if (records.stream().anyMatch(v -> (v.getYear() + v.getMonth()).compareTo(endDate.toString("yyyyMM")) >= 0) || records.isEmpty()) {
@@ -560,7 +588,7 @@ public class BizArchiveInputServiceImpl extends ServiceImpl<BizArchiveInputMappe
                             l.setIsContinue(0);
                         } else {
                             // 不停止工单 只修改工单完成时间
-                            l.setMonthNum(monthNun);
+                            l.setMonthNum(months);
                             l.setEndMonth(endDate);
                             // 旧任务明细 停止
                             details.stream().filter(v -> v.getWorkOrderId().equals(l.getId())).forEach(v -> v.setIsStop(1));