Explorar el Código

mld测试修改

yusm hace 1 mes
padre
commit
7817bda32e

+ 7 - 6
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/controller/TaskController.java

@@ -556,13 +556,14 @@ public class TaskController {
                 taskDailyAllocateService.remove(new QueryWrapper<TaskDailyAllocate>().eq("task_id",task.getId()));
                 taskDailyAllocateService.saveBatch(allocateArrayList);
             }
-        }//todo 需要确认一下审核状态能不能修改
-        else if (saved) {
-            if (!allocateArrayList.isEmpty()) {
-                taskDailyAllocateService.remove(new QueryWrapper<TaskDailyAllocate>().eq("task_id",task.getId()));
-                taskDailyAllocateService.saveBatch(allocateArrayList);
-            }
         }
+        //todo 需要确认一下审核状态能不能修改
+//        else if (saved) {
+//            if (!allocateArrayList.isEmpty()) {
+//                taskDailyAllocateService.remove(new QueryWrapper<TaskDailyAllocate>().eq("task_id",task.getId()));
+//                taskDailyAllocateService.saveBatch(allocateArrayList);
+//            }
+//        }
 
         if (task.getExecutorId() == null) {
             //清空执行人

+ 61 - 0
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/controller/TaskDailyAllocateController.java

@@ -12,7 +12,11 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.time.LocalDate;
+import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -44,6 +48,13 @@ public class TaskDailyAllocateController {
         HttpRespMsg msg = new HttpRespMsg();
         if (StringUtils.isNotEmpty(jsonStr)){
             List<TaskDailyAllocate> taskDailyAllocates = JSONArray.parseArray(jsonStr, TaskDailyAllocate.class);
+
+            String taskTimeNonOverlapping = isTaskTimeNonOverlapping(taskDailyAllocates);
+            if (StringUtils.isNotEmpty(taskTimeNonOverlapping)){
+                msg.setError(taskTimeNonOverlapping);
+                return msg;
+            }
+
             for (TaskDailyAllocate taskDailyAllocate : taskDailyAllocates) {
                 int count=taskDailyAllocateService.getConflict(taskDailyAllocate, request);
                 if(count>0){
@@ -56,5 +67,55 @@ public class TaskDailyAllocateController {
 
     }
 
+    /**
+     * 检查同一用户在同一天的任务时间是否重叠
+     * @param taskDailyAllocates 任务分配列表
+     * @return true=无重叠,false=有重叠
+     */
+    public static String isTaskTimeNonOverlapping(List<TaskDailyAllocate> taskDailyAllocates) {
+        if (taskDailyAllocates == null || taskDailyAllocates.isEmpty()) {
+            return "列表为空";
+        }
+
+        // 1. 按 userId 和 allocateDate 分组
+        Map<String, Map<LocalDate, List<TaskDailyAllocate>>> userDateTasksMap = taskDailyAllocates.stream()
+                .collect(Collectors.groupingBy(
+                        TaskDailyAllocate::getUserId,
+                        Collectors.groupingBy(TaskDailyAllocate::getAllocateDate)
+                ));
+
+        // 2. 遍历每个用户每天的分配情况
+        for (Map.Entry<String, Map<LocalDate, List<TaskDailyAllocate>>> userEntry : userDateTasksMap.entrySet()) {
+            String userId = userEntry.getKey();
+            Map<LocalDate, List<TaskDailyAllocate>> dateTasksMap = userEntry.getValue();
+
+            for (Map.Entry<LocalDate, List<TaskDailyAllocate>> dateEntry : dateTasksMap.entrySet()) {
+                LocalDate date = dateEntry.getKey();
+                List<TaskDailyAllocate> tasks = dateEntry.getValue();
+
+                // 3. 按 startTime 排序
+                tasks.sort(Comparator.comparing(TaskDailyAllocate::getStartTime));
+
+                // 4. 检查相邻任务是否重叠
+                for (int i = 0; i < tasks.size() - 1; i++) {
+                    TaskDailyAllocate current = tasks.get(i);
+                    TaskDailyAllocate next = tasks.get(i + 1);
+
+                    if (current.getEndTime().isAfter(next.getStartTime())) {
+                        System.err.printf(
+                                "时间冲突:用户 %s 在 %s 的任务 %s-%s 与 %s-%s 重叠%n",
+                                userId, date,
+                                current.getStartTime(), current.getEndTime(),
+                                next.getStartTime(), next.getEndTime()
+                        );
+                        return "时间冲突:在 "+date+" 的任务 "+current.getStartTime()+"-"+current.getEndTime()+" 与 "+next.getStartTime()+"-"+next.getEndTime()+" 有冲突";
+
+                    }
+                }
+            }
+        }
+        return "";
+    }
+
 }
 

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -13943,7 +13943,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         } catch (Exception e) {
             e.printStackTrace();
         }
-        msg.data =  pathPrefix + fileName+".xlsx";
+        msg.data =   "/upload/"+ fileName+".xlsx";
         return  msg;
     }
 

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -1538,10 +1538,10 @@ public class ExcelUtil {
 
         // 7. 生成完整文件名
         String fileName = title + ".xlsx";
-        String fullPath = downloadPath  + fileName;
+        String fullPath = "/upload/"  + fileName;
 
         // 8. 写入文件
-        try (FileOutputStream fos = new FileOutputStream(fullPath)) {
+        try (FileOutputStream fos = new FileOutputStream(downloadPath  + fileName)) {
             workbook.write(fos);
         } finally {
             workbook.close();