فهرست منبع

工作计划导入编写

yusm 1 ماه پیش
والد
کامیت
f94b6fa46e

+ 9 - 1
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/controller/TaskController.java

@@ -296,7 +296,7 @@ public class TaskController {
             String colors = executorList.stream().filter(f->!StringUtils.isEmpty(f.getExecutorId())).map(TaskExecutor::getExecutorColor).collect(Collectors.joining(","));
             task.setExecutorColor(StringUtils.isEmpty(colors)?null:colors);
             //总时长
-            task.setPlanHours(executorList.stream().filter(f->f.getPlanHours() != null).mapToDouble(TaskExecutor::getPlanHours).sum());
+//            task.setPlanHours(executorList.stream().filter(f->f.getPlanHours() != null).mapToDouble(TaskExecutor::getPlanHours).sum());
             //校验总计划工时不得超过父任务的计划工时
             if (task.getParentTid() != null) {
                 Task pTask = taskService.getById(task.getParentTid());
@@ -528,6 +528,7 @@ public class TaskController {
                 informationService.save(information);
             }
             if (!allocateArrayList.isEmpty()) {
+                allocateArrayList.forEach(a->a.setTaskId(task.getId()));
                 taskDailyAllocateService.saveBatch(allocateArrayList);
             }
         } else if (saved && shouldResetAuditStatus) {
@@ -555,7 +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);
+            }
         }
+
         if (task.getExecutorId() == null) {
             //清空执行人
             if (!isNew) {

+ 18 - 2
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/controller/TaskDailyAllocateController.java

@@ -1,14 +1,18 @@
 package com.management.platform.controller;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.management.platform.entity.TaskDailyAllocate;
 import com.management.platform.service.TaskDailyAllocateService;
 import com.management.platform.util.HttpRespMsg;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 /**
  * <p>
@@ -36,8 +40,20 @@ public class TaskDailyAllocateController {
 
     //判断是否冲突
     @RequestMapping("/getConflict")
-    public HttpRespMsg getConflict(Integer taskId, String startTime, String endTime) {
-        return taskDailyAllocateService.getConflict(taskId,  startTime, endTime, request);
+    public HttpRespMsg getConflict(String jsonStr) {
+        HttpRespMsg msg = new HttpRespMsg();
+        if (StringUtils.isNotEmpty(jsonStr)){
+            List<TaskDailyAllocate> taskDailyAllocates = JSONArray.parseArray(jsonStr, TaskDailyAllocate.class);
+            for (TaskDailyAllocate taskDailyAllocate : taskDailyAllocates) {
+                int count=taskDailyAllocateService.getConflict(taskDailyAllocate, request);
+                if(count>0){
+                    msg.setError("选择时间段:"+taskDailyAllocate.getAllocateDate()+"日:"+taskDailyAllocate.getStartTime()+"--"+taskDailyAllocate.getStartTime()+"跟其他时间段存在冲突");
+                    return msg;
+                }
+            }
+        }
+        return msg;
+
     }
 
 }

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/mapper/TaskDailyAllocateMapper.java

@@ -19,5 +19,6 @@ public interface TaskDailyAllocateMapper extends BaseMapper<TaskDailyAllocate> {
 
     ArrayList<TaskDailyAllocate> getUserTaskTimeList(Integer taskId, String userId, LocalDateTime stateTime, LocalDateTime endTime);
 
-    int getConflict(Integer taskId, String startTime, String endTime);
+
+    int getConflict(TaskDailyAllocate taskDailyAllocate);
 }

+ 3 - 1
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/service/TaskDailyAllocateService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.management.platform.util.HttpRespMsg;
 
 import javax.servlet.http.HttpServletRequest;
+import java.time.LocalTime;
 
 /**
  * <p>
@@ -18,5 +19,6 @@ public interface TaskDailyAllocateService extends IService<TaskDailyAllocate> {
 
     HttpRespMsg viewUserTaskSchedule(Integer taskId, String userId, String startTime, String endTime, HttpServletRequest request);
 
-    HttpRespMsg getConflict(Integer taskId, String startTime, String endTime, HttpServletRequest request);
+
+    int getConflict(TaskDailyAllocate taskDailyAllocate, HttpServletRequest request);
 }

+ 5 - 8
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/service/impl/TaskDailyAllocateServiceImpl.java

@@ -10,8 +10,8 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
 
 /**
  * <p>
@@ -35,12 +35,9 @@ public class TaskDailyAllocateServiceImpl extends ServiceImpl<TaskDailyAllocateM
     }
 
     @Override
-    public HttpRespMsg getConflict(Integer taskId, String startTime, String endTime, HttpServletRequest request) {
-        HttpRespMsg msg = new HttpRespMsg();
-        int count= taskDailyAllocateMapper.getConflict(taskId,startTime,endTime);
-        if(count>0){
-            msg.setError("选择时间段:"+startTime+"--"+"endTime:"+endTime+"跟其他时间段存在冲突");
-        }
-        return msg;
+    public int getConflict(TaskDailyAllocate taskDailyAllocate, HttpServletRequest request) {
+        return taskDailyAllocateMapper.getConflict(taskDailyAllocate);
     }
+
+
 }

+ 406 - 187
fhKeeper/formulahousekeeper/management-platform-mld/src/main/java/com/management/platform/service/impl/TaskServiceImpl.java

@@ -5,6 +5,8 @@ import com.aliyun.dingtalkcontact_1_0.models.SearchUserResponse;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.injector.methods.Update;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.util.StringUtil;
 import com.management.platform.controller.TaskController;
@@ -37,8 +39,10 @@ import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
+import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -108,6 +112,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
     private TaskTypeMapper taskTypeMapper;
     @Resource
     CustomerInfoMapper customerInfoMapper;
+    @Resource
+    private TaskDailyAllocateService taskDailyAllocateService;
 
     @Resource
     private InformationService informationService;
@@ -642,6 +648,15 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
             //由于第一行需要指明列对应的标题
             int lastRowNum = sheet.getLastRowNum();
             System.out.println("lastRowNum==>"+lastRowNum);
+            Integer initTaskId=null;
+            Integer initProjectId=null;
+            LocalDateTime initStartDate=null;
+            LocalDateTime initEndDate=null;
+            String initUserStr="";
+            String initExectorColors="";
+            String initExectorIds="";
+            String initExectorNames="";
+            Double initworkHourExector= (double) 0;
             for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
                 ArrayList<TaskExecutor> taskExecutors = new ArrayList<>();
                 XSSFRow row = sheet.getRow(rowIndex);
@@ -649,235 +664,439 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
                 if (row == null) {
                     continue;
                 }
-                for (int i = 0; i < 5; i++) {
+                for (int i = 0; i < 8; i++) {
                     XSSFCell cell = row.getCell(0);
                     if (cell!=null) {
                         cell.setCellType(CellType.STRING);
                     }
                 }
-                XSSFCell typeCell = row.getCell(0);
-                if (typeCell == null||StringUtils.isEmpty(typeCell.getStringCellValue())) {
-                    throw  new Exception("第"+(rowIndex+1)+"行,类型为空");
-                }else {
-                    Optional<TaskType> first = taskTypeList.stream().filter(t -> t.getName().equals(typeCell.getStringCellValue())).findFirst();
-                    if (first.isPresent()){
-                        task.setTaskPlanType(first.get().getId());
-                    }else {
-                        throw  new Exception("第"+(rowIndex+1)+"行,类型填写有误");
-                    }
-                }
-                //类型不为请假
-                if (task.getTaskPlanType()!=3){
-                    XSSFCell projectCell = row.getCell(1);
-                    if (projectCell == null||StringUtils.isEmpty(projectCell.getStringCellValue())) {
-                        throw  new Exception("第"+(rowIndex+1)+"行,项目为空");
-                    }else {
-                        Optional<Project> first = allProjectList.stream().filter(t -> t.getProjectName().equals(projectCell.getStringCellValue())).findFirst();
-                        if (first.isPresent()){
-                            task.setProjectId(first.get().getId());
-                        }else {
-                            throw  new Exception("第"+(rowIndex+1)+"行,项目名称填写有误");
+                if (row.getCell(0)!=null &&row.getCell(10)!=null) {
+                    initTaskId = null;
+                    initProjectId=null;
+                    initStartDate=null;
+                    initEndDate=null;
+                    initUserStr="";
+                    initExectorColors="";
+                    initExectorIds="";
+                    initExectorNames="";
+                    initworkHourExector= (double) 0;
+
+                    XSSFCell typeCell = row.getCell(0);
+                    if (typeCell == null || StringUtils.isEmpty(typeCell.getStringCellValue())) {
+                        throw new Exception("第" + (rowIndex + 1) + "行,类型为空");
+                    } else {
+                        Optional<TaskType> first = taskTypeList.stream().filter(t -> t.getName().equals(typeCell.getStringCellValue())).findFirst();
+                        if (first.isPresent()) {
+                            task.setTaskPlanType(first.get().getId());
+                        } else {
+                            throw new Exception("第" + (rowIndex + 1) + "行,类型填写有误");
                         }
                     }
+                    //类型不为请假
+                    if (task.getTaskPlanType() != 3) {
+                        XSSFCell projectCell = row.getCell(1);
+                        if (projectCell == null || StringUtils.isEmpty(projectCell.getStringCellValue())) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,项目为空");
+                        } else {
+                            Optional<Project> first = allProjectList.stream().filter(t -> t.getProjectName().equals(projectCell.getStringCellValue())).findFirst();
+                            if (first.isPresent()) {
+                                task.setProjectId(first.get().getId());
+                            } else {
+                                throw new Exception("第" + (rowIndex + 1) + "行,项目名称填写有误");
+                            }
+                        }
 
-                    XSSFCell researchCell = row.getCell(2);//研究中心
-                    if (researchCell != null||StringUtils.isNotEmpty(researchCell.getStringCellValue())) {
-                        Optional<ReportExtraDegree> first = customerInfoList.stream().filter(c -> c.getName().equals(researchCell.getStringCellValue().trim())).findFirst();
-                        if (first.isPresent()){
-                            task.setCenterId(first.get().getId());
-                            task.setCenterName(first.get().getName());
-                        }else {
-                            throw  new Exception("第"+(rowIndex+1)+"行,研究中心填写有误");
+                        XSSFCell researchCell = row.getCell(2);//研究中心
+                        if (researchCell != null || StringUtils.isNotEmpty(researchCell.getStringCellValue())) {
+                            Optional<ReportExtraDegree> first = customerInfoList.stream().filter(c -> c.getName().equals(researchCell.getStringCellValue().trim())).findFirst();
+                            if (first.isPresent()) {
+                                task.setCenterId(first.get().getId());
+                                task.setCenterName(first.get().getName());
+                            } else {
+                                throw new Exception("第" + (rowIndex + 1) + "行,研究中心填写有误");
+                            }
                         }
-                    }
 
-                    XSSFCell taskGroupCell = row.getCell(3);//所属任务分组
-                    if (taskGroupCell == null||StringUtils.isEmpty(taskGroupCell.getStringCellValue())) {
-                        throw  new Exception("第"+(rowIndex+1)+"行,任务分组为空");
-                    }else {
-                        Optional<TaskGroup> first = allGroupList.stream().filter(t -> t.getProjectId().equals(task.getProjectId())&&t.getName().equals(taskGroupCell.getStringCellValue())).findFirst();
-                        if (first.isPresent()){
-                            task.setGroupId(first.get().getId());
-                        }else {
-                            throw  new Exception("第"+(rowIndex+1)+"行,任务分组填写有误");
+                        XSSFCell taskGroupCell = row.getCell(3);//所属任务分组
+                        if (taskGroupCell == null || StringUtils.isEmpty(taskGroupCell.getStringCellValue())) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,任务分组为空");
+                        } else {
+                            Optional<TaskGroup> first = allGroupList.stream().filter(t -> t.getProjectId().equals(task.getProjectId()) && t.getName().equals(taskGroupCell.getStringCellValue())).findFirst();
+                            if (first.isPresent()) {
+                                task.setGroupId(first.get().getId());
+                            } else {
+                                throw new Exception("第" + (rowIndex + 1) + "行,任务分组填写有误");
+                            }
                         }
-                    }
 
-                    XSSFCell taskStageCell = row.getCell(4);//所属任务列表
-                    if (taskStageCell == null||StringUtils.isEmpty(taskStageCell.getStringCellValue())) {
-                        throw  new Exception("第"+(rowIndex+1)+"行,任务列表为空");
-                    }else {
-                        Optional<Stages> first = stagesList.stream().filter(t -> t.getGroupId().equals(task.getGroupId())&&t.getStagesName().equals(taskStageCell.getStringCellValue())).findFirst();
-                        if (first.isPresent()){
-                            task.setStagesId(first.get().getId());
-                        }else {
-                            throw  new Exception("第"+(rowIndex+1)+"行,任务列表填写有误");
+                        XSSFCell taskStageCell = row.getCell(4);//所属任务列表
+                        if (taskStageCell == null || StringUtils.isEmpty(taskStageCell.getStringCellValue())) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,任务列表为空");
+                        } else {
+                            Optional<Stages> first = stagesList.stream().filter(t -> t.getGroupId().equals(task.getGroupId()) && t.getStagesName().equals(taskStageCell.getStringCellValue())).findFirst();
+                            if (first.isPresent()) {
+                                task.setStagesId(first.get().getId());
+                            } else {
+                                throw new Exception("第" + (rowIndex + 1) + "行,任务列表填写有误");
+                            }
                         }
-                    }
 
-                    XSSFCell taskContentCell = row.getCell(5);//任务内容
-                    if (taskContentCell == null||StringUtils.isEmpty(taskContentCell.getStringCellValue())) {
-                        throw  new Exception("第"+(rowIndex+1)+"行,任务内容为空");
-                    }else {
-                        task.setName(taskContentCell.getStringCellValue());
-                    }
+                        XSSFCell taskContentCell = row.getCell(5);//任务内容
+                        if (taskContentCell == null || StringUtils.isEmpty(taskContentCell.getStringCellValue())) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,任务内容为空");
+                        } else {
+                            task.setName(taskContentCell.getStringCellValue());
+                        }
 
-                    XSSFCell planHoursCell = row.getCell(9);//计划工时
-                    if(planHoursCell!=null){
-                        planHoursCell.setCellType(CellType.STRING);
-                        task.setPlanHours(Double.parseDouble(planHoursCell.getStringCellValue()));
-                    }
+//                    XSSFCell planHoursCell = row.getCell(9);//计划工时
+//                    if(planHoursCell!=null){
+//                        planHoursCell.setCellType(CellType.STRING);
+//                        task.setPlanHours(Double.parseDouble(planHoursCell.getStringCellValue()));
+//                    }
 
-                    XSSFCell priorityCell = row.getCell(10);//优先级
-                    if(priorityCell!=null){
-                        priorityCell.setCellType(CellType.STRING);
-                        String stringCellValue = priorityCell.getStringCellValue();
-                        if(StringUtils.isNotEmpty(stringCellValue)){
-                            switch (stringCellValue){
-                                case "一般":
-                                    task.setTaskLevel(0);
-                                    break;
-                                case "重要":
-                                    task.setTaskLevel(1);
-                                    break;
-                                case "紧急":
-                                    task.setTaskLevel(2);
-                                    break;
+                        XSSFCell priorityCell = row.getCell(6);//优先级
+                        if (priorityCell != null) {
+                            priorityCell.setCellType(CellType.STRING);
+                            String stringCellValue = priorityCell.getStringCellValue();
+                            if (StringUtils.isNotEmpty(stringCellValue)) {
+                                switch (stringCellValue) {
+                                    case "一般":
+                                        task.setTaskLevel(0);
+                                        break;
+                                    case "重要":
+                                        task.setTaskLevel(1);
+                                        break;
+                                    case "紧急":
+                                        task.setTaskLevel(2);
+                                        break;
+                                }
+                            } else {
+                                task.setTaskLevel(0);
                             }
-                        }else {
+                        } else {
                             task.setTaskLevel(0);
                         }
-                    }else {
-                        task.setTaskLevel(0);
+
+                        XSSFCell descCell = row.getCell(7);//详细描述
+                        if (descCell != null) {
+                            descCell.setCellType(CellType.STRING);
+                            String stringCellValue = descCell.getStringCellValue();
+                            task.setTaskDesc(stringCellValue);
+                        }
                     }
 
-                    XSSFCell descCell = row.getCell(11);//详细描述
-                    if(descCell!=null){
-                        descCell.setCellType(CellType.STRING);
-                        String stringCellValue = descCell.getStringCellValue();
-                        task.setTaskDesc(stringCellValue);
+
+                    XSSFCell startDateCell = row.getCell(8);//开始时间
+                    if (startDateCell != null) {
+                        startDateCell.setCellType(CellType.NUMERIC);
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,开始时间为空");
+                    }
+                    if (startDateCell.getDateCellValue() != null) {
+                        Date dateCellValue = startDateCell.getDateCellValue();
+                        System.out.println("开始日期==" + dateCellValue.toString());
+                        String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
+                        LocalDateTime startDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        task.setStartDate(startDate);
                     }
-                }
 
+                    XSSFCell endDateCell = row.getCell(9);//结束时间
+                    if (endDateCell != null) {
+                        endDateCell.setCellType(CellType.NUMERIC);
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,截止时间为空");
+                    }
+                    if (endDateCell.getDateCellValue() != null) {
+                        Date dateCellValue = endDateCell.getDateCellValue();
+                        System.out.println("开始日期==" + dateCellValue.toString());
+                        String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
+                        LocalDateTime endDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        task.setEndDate(endDate);
+                    }
 
+                    XSSFCell executorCell = row.getCell(10);//执行人
+                    if (executorCell != null) {
+                        executorCell.setCellType(CellType.STRING);
+                        if (executorCell.getStringCellValue().isEmpty()) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人为空");
+                        }
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,执行人为空");
+                    }
 
-                XSSFCell startDateCell = row.getCell(6);//开始时间
-                if (startDateCell != null) {
-                    startDateCell.setCellType(CellType.NUMERIC);
-                }else {
-                    throw  new Exception("第"+(rowIndex+1)+"行,开始时间为空");
-                }
-                if(startDateCell.getDateCellValue() != null){
-                    Date dateCellValue = startDateCell.getDateCellValue();
-                    System.out.println("开始日期=="+dateCellValue.toString());
-                    String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
-                    LocalDateTime startDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                    task.setStartDate(startDate);
-                }
+                    TaskDailyAllocate taskDailyAllocate = new TaskDailyAllocate();
+                    LocalDate date1=null;
+                    LocalDate date2=null;
+                    LocalTime time1=null;
+                    LocalTime time2=null;
+                    XSSFCell startTimeCell = row.getCell(11);//每日开始时间
+                    if (startTimeCell != null) {
+                        startTimeCell.setCellType(CellType.NUMERIC);
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,每日开始时间为空");
+                    }
+                    if (startTimeCell.getDateCellValue() != null) {
+                        Date dateCellValue = startTimeCell.getDateCellValue();
+                        System.out.println("每日开始日期==" + dateCellValue.toString());
+                        String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
+                        LocalDateTime startDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        date1 = startDate.toLocalDate();
+                        time1=startDate.toLocalTime();
+                        taskDailyAllocate.setStartTime(time1);
+                    }
 
-                XSSFCell endDateCell = row.getCell(7);//结束时间
-                if (endDateCell != null) {
-                    endDateCell.setCellType(CellType.NUMERIC);
-                }else {
-                    throw  new Exception("第"+(rowIndex+1)+"行,截止时间为空");
-                }
-                if(endDateCell.getDateCellValue() != null){
-                    Date dateCellValue = endDateCell.getDateCellValue();
-                    System.out.println("开始日期=="+dateCellValue.toString());
-                    String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
-                    LocalDateTime endDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                    task.setEndDate(endDate);
-                }
+                    XSSFCell endTimeCell = row.getCell(12);//每日截止时间
+                    if (endTimeCell != null) {
+                        endTimeCell.setCellType(CellType.NUMERIC);
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,每日截止时间为空");
+                    }
+                    if (endTimeCell.getDateCellValue() != null) {
+                        Date dateCellValue = endTimeCell.getDateCellValue();
+                        System.out.println("每日截止日期==" + dateCellValue.toString());
+                        String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
+                        LocalDateTime endDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        date2 = endDate.toLocalDate();
+                        time2 = endDate.toLocalTime();
+                        taskDailyAllocate.setEndTime(time2);
+                    }
 
-                XSSFCell executorCell = row.getCell(8);//执行人
-                if (executorCell!=null){
-                    executorCell.setCellType(CellType.STRING);
-                    if (executorCell.getStringCellValue().isEmpty()){
-                        throw  new Exception("第"+(rowIndex+1)+"行,执行人为空");
+                    if (date1==null||date2==null|| !date1.isEqual(date2)){
+                        throw new Exception("第" + (rowIndex + 1) + "行,每日开始时间和每日截止时间日期不一致");
+                    }else {
+                        taskDailyAllocate.setAllocateDate(date1);
                     }
-                }else {
-                    throw  new Exception("第"+(rowIndex+1)+"行,执行人为空");
-                }
 
+                    double hoursDifference = Duration.between(time1, time2).getSeconds() / 3600.0;
+                    taskDailyAllocate.setWorkHour(hoursDifference);
+                    taskDailyAllocate.setOverWorkHour(hoursDifference-7.5);
 
-                task.setCompanyId(companyId);
-                task.setCreaterId(userId);
-                task.setCreaterName(creator.getName());
-                task.setCreatorColor(creator.getColor());
-                task.setCreateDate(LocalDate.now());
-                task.setIndate(LocalDateTime.now());
-                task.setTaskStatus(TaskController.STATUS_FIRST_CHECK);
-                taskMapper.insert(task);
+                    task.setCompanyId(companyId);
+                    task.setCreaterId(userId);
+                    task.setCreaterName(creator.getName());
+                    task.setCreatorColor(creator.getColor());
+                    task.setCreateDate(LocalDate.now());
+                    task.setIndate(LocalDateTime.now());
+                    task.setTaskStatus(TaskController.STATUS_FIRST_CHECK);
+                    taskMapper.insert(task);
+                    initTaskId = task.getId();
+                    initProjectId=task.getProjectId();
+                    initStartDate=task.getStartDate();
+                    initEndDate=task.getEndDate();
 
 
-                executorCell.setCellType(CellType.STRING);
-                String executorStr = executorCell.getStringCellValue();
 
-                String[] strings = executorStr.split(",");
+                    executorCell.setCellType(CellType.STRING);
+                    String executorStr = executorCell.getStringCellValue();
+                    initUserStr=executorStr;
 
-                StringJoiner exectorIds = new StringJoiner(",");
-                StringJoiner exectorColors = new StringJoiner(",");
-                for (int i = 0; i < strings.length; i++) {
-                    TaskExecutor taskExecutor = new TaskExecutor();
-                    String string = strings[i];
-                    Optional<User> first = allUserList.stream().filter(u -> u.getName().equals(string)).findFirst();
-                    if (!first.isPresent()) {
-                        throw  new Exception("第"+(rowIndex+1)+"行,执行人填写有误");
-                    }
-                    taskExecutor.setTaskId(task.getId());
-                    User user = first.get();
-                    taskExecutor.setExecutorId(user.getId());
-                    taskExecutor.setExecutorName(user.getName());
-                    taskExecutor.setExecutorColor(user.getColor());
-                    taskExecutor.setPlanHours(task.getPlanHours());
-                    taskExecutor.setProjectId(task.getProjectId());
-
-                    Integer count = taskMapper.getUserConflitTaskCount(user.getId(), task.getId(), task.getStartDate(), task.getEndDate());
-                    if (count > 0) {
-                        throw  new Exception("第"+(rowIndex+1)+"行,执行人"+user.getName()+"在其他任务上有时间冲突");
+
+                    String[] strings = executorStr.split(",");
+
+                    StringJoiner exectorIds = new StringJoiner(",");
+                    StringJoiner exectorColors = new StringJoiner(",");
+                    for (int i = 0; i < strings.length; i++) {
+                        TaskExecutor taskExecutor = new TaskExecutor();
+                        String string = strings[i];
+                        Optional<User> first = allUserList.stream().filter(u -> u.getName().equals(string)).findFirst();
+                        if (!first.isPresent()) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人填写有误");
+                        }
+                        taskExecutor.setTaskId(task.getId());
+                        User user = first.get();
+                        taskExecutor.setExecutorId(user.getId());
+                        taskExecutor.setExecutorName(user.getName());
+                        taskExecutor.setExecutorColor(user.getColor());
+                        taskExecutor.setPlanHours(task.getPlanHours());
+                        taskExecutor.setProjectId(task.getProjectId());
+
+                        Integer count = taskMapper.getUserConflitTaskCount(user.getId(), task.getId(), task.getStartDate(), task.getEndDate());
+                        if (count > 0) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人" + user.getName() + "在其他任务上有时间冲突");
+                        }
+
+                        Optional<Project> projectFirst = allProjectList.stream().filter(t -> t.getId().equals(task.getProjectId())).findFirst();
+                        projectFirst.ifPresent(project -> taskExecutor.setFirstAuditorId(project.getInchargerId()));
+                        Optional<Department> departmentOptional = departmentList.stream().filter(t -> t.getDepartmentId().equals(user.getDepartmentId())).findFirst();
+                        departmentOptional.ifPresent(department -> taskExecutor.setSecondAuditorId(department.getManagerId()));
+                        taskExecutor.setAuditStatus(TaskController.STATUS_FIRST_CHECK);
+                        taskExecutors.add(taskExecutor);
+
+                        exectorIds.add(user.getId());
+                        exectorColors.add(user.getColor());
                     }
+                    task.setExecutorName(executorStr);
+                    initExectorIds=exectorIds.toString();
+                    initExectorColors=exectorColors.toString();
+                    taskDailyAllocate.setUserId(exectorIds.toString());
+                    task.setExecutorId(exectorIds.toString());
+                    task.setExecutorColor(exectorColors.toString());
 
+                    taskMapper.updateById(task);
+                    taskExecutorService.saveBatch(taskExecutors);
+
+                    taskDailyAllocate.setTaskId(task.getId());
+                    taskDailyAllocateService.save(taskDailyAllocate);
+
+                    //给第一审核人发送信息提醒
+                    log.info("添加工作计划,给第一审核人发送信息提醒");
                     Optional<Project> projectFirst = allProjectList.stream().filter(t -> t.getId().equals(task.getProjectId())).findFirst();
-                    projectFirst.ifPresent(project -> taskExecutor.setFirstAuditorId(project.getInchargerId()));
-                    Optional<Department> departmentOptional = departmentList.stream().filter(t -> t.getDepartmentId().equals(user.getDepartmentId())).findFirst();
-                    departmentOptional.ifPresent(department -> taskExecutor.setSecondAuditorId(department.getManagerId()));
-                    taskExecutor.setAuditStatus(TaskController.STATUS_FIRST_CHECK);
-                    taskExecutors.add(taskExecutor);
-
-                    exectorIds.add(user.getId());
-                    exectorColors.add(user.getColor());
+                    if (projectFirst.isPresent()) {
+                        Project project = projectFirst.get();
+                        Information information = new Information();
+                        String executorNames = task.getExecutorList().stream()
+                                .map(TaskExecutor::getExecutorName)
+                                .collect(Collectors.joining(","));
+
+                        String infoMsg = project.getProjectName() + "项目有新的预计FTE计划审批任务" +
+                                (executorNames.isEmpty() ? "" : ",执行人有:" + executorNames) +
+                                ",请您查收.";
+                        information.setMsg(infoMsg);
+                        information.setTaskId(task.getId());
+                        information.setType(11);
+                        information.setJumpType(3);
+                        information.setTime(LocalDateTime.now());
+                        Optional<User> first = allUserList.stream().filter(u -> u.getId().equals(project.getInchargerId())).findFirst();
+                        if (first.isPresent()) {
+                            User owner = first.get();
+                            information.setUserId(owner.getId());
+                        }
+                        informationService.save(information);
+                    }
                 }
-                task.setExecutorName(executorStr);
-                task.setExecutorId(exectorIds.toString());
-                task.setExecutorColor(exectorColors.toString());
+                else if (row.getCell(0)==null &&row.getCell(10)!=null) {
+//                    initTaskId 不用处理
+//                    initUserStr要赋值
+                    TaskDailyAllocate taskDailyAllocate = new TaskDailyAllocate();
+
+                    XSSFCell executorCell = row.getCell(10);//执行人
+                    if (executorCell != null) {
+                        executorCell.setCellType(CellType.STRING);
+                        if (executorCell.getStringCellValue().isEmpty()) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人为空");
+                        }
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,执行人为空");
+                    }
+                    executorCell.setCellType(CellType.STRING);
+                    String executorStr = executorCell.getStringCellValue();
+
+                    LocalDate date1=null;
+                    LocalDate date2=null;
+                    LocalTime time1=null;
+                    LocalTime time2=null;
+                    XSSFCell startDateCell = row.getCell(11);//每日开始时间
+                    if (startDateCell != null) {
+                        startDateCell.setCellType(CellType.NUMERIC);
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,每日开始时间为空");
+                    }
+                    if (startDateCell.getDateCellValue() != null) {
+                        Date dateCellValue = startDateCell.getDateCellValue();
+                        System.out.println("每日开始日期==" + dateCellValue.toString());
+                        String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
+                        LocalDateTime startDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        date1 = startDate.toLocalDate();
+                        time1=startDate.toLocalTime();
+                        taskDailyAllocate.setStartTime(time1);
+                    }
 
-                taskMapper.updateById(task);
-                taskExecutorService.saveBatch(taskExecutors);
+                    XSSFCell endDateCell = row.getCell(12);//每日截止时间
+                    if (endDateCell != null) {
+                        endDateCell.setCellType(CellType.NUMERIC);
+                    } else {
+                        throw new Exception("第" + (rowIndex + 1) + "行,每日截止时间为空");
+                    }
+                    if (endDateCell.getDateCellValue() != null) {
+                        Date dateCellValue = endDateCell.getDateCellValue();
+                        System.out.println("每日截止日期==" + dateCellValue.toString());
+                        String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
+                        LocalDateTime endDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                        date2 = endDate.toLocalDate();
+                        time2 = endDate.toLocalTime();
+                        taskDailyAllocate.setEndTime(time2);
+                    }
 
-                //给第一审核人发送信息提醒
-                log.info("添加工作计划,给第一审核人发送信息提醒");
-                Optional<Project> projectFirst = allProjectList.stream().filter(t -> t.getId().equals(task.getProjectId())).findFirst();
-                if (projectFirst.isPresent()) {
-                    Project project = projectFirst.get();
-                    Information information = new Information();
-                    String executorNames = task.getExecutorList().stream()
-                            .map(TaskExecutor::getExecutorName)
-                            .collect(Collectors.joining(","));
+                    if (date1==null||date2==null|| !date1.isEqual(date2)){
+                        throw new Exception("第" + (rowIndex + 1) + "行,每日开始时间和每日截止时间日期不一致");
+                    }else {
+                        taskDailyAllocate.setAllocateDate(date1);
+                    }
+
+                    double hoursDifference = Duration.between(time1, time2).getSeconds() / 3600.0;
+                    taskDailyAllocate.setWorkHour(hoursDifference);
+                    taskDailyAllocate.setOverWorkHour(hoursDifference-7.5);
+
+                    //如果executorStr==initUserStr,taskExcutor执行人就不用保存
+                    if(executorStr.equals(initUserStr)){
+                        String[] strings = executorStr.split(",");
+                        Optional<User> first = allUserList.stream().filter(u -> u.getName().equals(strings[0])).findFirst();
+                        if (!first.isPresent()) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人填写有误");
+                        }
+                        taskDailyAllocate.setTaskId(initTaskId);
+                        taskDailyAllocate.setUserId(first.get().getId());
+                        taskDailyAllocateService.save(taskDailyAllocate);
+                        initUserStr=executorStr;
+                        initExectorIds+=first.get().getId();
+                        initExectorColors+=first.get().getColor();
+                        initExectorNames+=first.get().getName();
+                        initworkHourExector+=hoursDifference;
+                        taskMapper.update(null,new UpdateWrapper<Task>().set("executor_id",initExectorIds)
+                                .set("executor_color",initExectorColors).set("executor_name",initExectorNames)
+                                .eq("id",initTaskId));
+                        taskExecutorService.update(null,new UpdateWrapper<TaskExecutor>().eq("task_id",initTaskId).eq("executor_id",first.get().getId()).set("plan_hours",initworkHourExector));
+
+                    }else {
+
+                        initworkHourExector=hoursDifference;
+                        String[] strings = executorStr.split(",");
+
+                        TaskExecutor taskExecutor = new TaskExecutor();
+
+                        Optional<User> first = allUserList.stream().filter(u -> u.getName().equals(strings[0])).findFirst();
+                        if (!first.isPresent()) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人填写有误");
+                        }
+                        taskExecutor.setTaskId(initTaskId);
+                        User user = first.get();
+                        taskExecutor.setExecutorId(user.getId());
+                        taskExecutor.setExecutorName(user.getName());
+                        taskExecutor.setExecutorColor(user.getColor());
+                        taskExecutor.setPlanHours(initworkHourExector);//todo 每个执行人的计划工时,要累加
+                        taskExecutor.setProjectId(initProjectId);
+
+                        Integer count = taskMapper.getUserConflitTaskCount(user.getId(), initTaskId, initStartDate, initEndDate);
+                        if (count > 0) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人" + user.getName() + "在其他任务上有时间冲突");
+                        }
+
+                        Integer finalInitProjectId = initProjectId;
+                        Optional<Project> projectFirst = allProjectList.stream().filter(t -> t.getId().equals(finalInitProjectId)).findFirst();
+                        projectFirst.ifPresent(project -> taskExecutor.setFirstAuditorId(project.getInchargerId()));
+                        Optional<Department> departmentOptional = departmentList.stream().filter(t -> t.getDepartmentId().equals(user.getDepartmentId())).findFirst();
+                        departmentOptional.ifPresent(department -> taskExecutor.setSecondAuditorId(department.getManagerId()));
+                        taskExecutor.setAuditStatus(TaskController.STATUS_FIRST_CHECK);
+
+                        if (!first.isPresent()) {
+                            throw new Exception("第" + (rowIndex + 1) + "行,执行人填写有误");
+                        }
+
+                        taskDailyAllocate.setTaskId(initTaskId);
+                        taskDailyAllocate.setUserId(first.get().getId());
+
+                        initUserStr=executorStr;
+                        initExectorIds+=first.get().getId();
+                        initExectorColors+=first.get().getColor();
+                        initExectorNames+=first.get().getName();
+
+                        taskExecutorService.save(taskExecutor);
+                        taskDailyAllocateService.save(taskDailyAllocate);
+                        taskMapper.update(null,new UpdateWrapper<Task>().set("executor_id",initExectorIds)
+                                .set("executor_color",initExectorColors).set("executor_name",initExectorNames)
+                                .eq("id",initTaskId));
 
-                    String infoMsg = project.getProjectName() + "项目有新的预计FTE计划审批任务" +
-                            (executorNames.isEmpty() ? "" : ",执行人有:" + executorNames) +
-                            ",请您查收.";
-                    information.setMsg(infoMsg);
-                    information.setTaskId(task.getId());
-                    information.setType(11);
-                    information.setJumpType(3);
-                    information.setTime(LocalDateTime.now());
-                    Optional<User> first = allUserList.stream().filter(u -> u.getId().equals(project.getInchargerId())).findFirst();
-                    if (first.isPresent()) {
-                        User owner = first.get();
-                        information.setUserId(owner.getId());
                     }
-                    informationService.save(information);
                 }
             }
         } catch (IOException e) {

+ 6 - 5
fhKeeper/formulahousekeeper/management-platform-mld/src/main/resources/mapper/TaskDailyAllocateMapper.xml

@@ -30,14 +30,15 @@
         <if test="taskId != null">
             and t.id != #{taskId}
         </if>
-        and tda.start_time &lt;= #{endTime} and tda.end_time &gt;= #{stateTime}
+        AND TIMESTAMP(tda.allocate_date, tda.start_time) &lt;= #{endTime}
+        AND TIMESTAMP(tda.allocate_date, tda.end_time) &gt;= #{startTime}
     </select>
     <select id="getConflict" resultType="java.lang.Integer">
         select count(*) from task_daily_allocate
-        where start_time &lt;= #{endTime} and end_time &gt;= #{stateTime}
-        <if test="taskId != null">
-            and task_id != #{taskId}
-        </if>
+            where start_time &lt;= #{endTime} and end_time &gt;= #{startTime} and allocate_date=#{allocateDate} and user_id=#{userId}
+            <if test="taskId != null">
+                and task_id != #{taskId}
+            </if>
     </select>
 
 </mapper>