|
@@ -5,10 +5,13 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.entity.dto.QueryVisitPlanDTO;
|
|
|
+import com.management.platform.entity.dto.TaskDto;
|
|
|
+import com.management.platform.entity.vo.DailyTaskVO;
|
|
|
import com.management.platform.entity.vo.MonthActivePlanVO;
|
|
|
import com.management.platform.entity.vo.VisitPlanDetailVO;
|
|
|
import com.management.platform.entity.vo.VisitPlanVO;
|
|
|
import com.management.platform.mapper.*;
|
|
|
+import com.management.platform.service.SysFunctionService;
|
|
|
import com.management.platform.service.VisitPlanService;
|
|
|
import com.management.platform.util.DateTimeUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
@@ -17,10 +20,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -47,6 +50,12 @@ public class VisitPlanServiceImpl extends ServiceImpl<VisitPlanMapper, VisitPlan
|
|
|
@Resource
|
|
|
private ContactsMapper contactsMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SysFunctionService sysFunctionService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TaskMapper taskMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public HttpRespMsg addOrUpdateVisitPlan(VisitPlan visitPlan, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
@@ -350,7 +359,33 @@ public class VisitPlanServiceImpl extends ServiceImpl<VisitPlanMapper, VisitPlan
|
|
|
// IPage<VisitPlanVO> resPage = visitPlanMapper.getPageVisitPlan(page,query);
|
|
|
List<VisitPlanVO> resPage = visitPlanMapper.getListVisitPlan(query);
|
|
|
|
|
|
- httpRespMsg.setData(resPage);
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部任务");
|
|
|
+ boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门任务");
|
|
|
+ Integer departmentId=null;
|
|
|
+ String executor=null;
|
|
|
+
|
|
|
+ if (isAll){
|
|
|
+ departmentId=null;
|
|
|
+ }
|
|
|
+ else if (isNotAll){
|
|
|
+ departmentId= user.getDepartmentId();//找出对应的部门id
|
|
|
+ }else {
|
|
|
+ executor=user.getId();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
|
+ LocalDateTime startDateParse = LocalDateTime.parse(calenderDate + " 00:00", formatter);
|
|
|
+ LocalDateTime endDateParse = startDateParse.plusDays(1L);
|
|
|
+ List<TaskDto> taskList = taskMapper.getTaskListByStartAndEnd(startDateParse, endDateParse, departmentId, executor, companyId);
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("planList",resPage);
|
|
|
+ map.put("taskList",taskList);
|
|
|
+
|
|
|
+ httpRespMsg.setData(map);
|
|
|
+
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
@@ -380,7 +415,89 @@ public class VisitPlanServiceImpl extends ServiceImpl<VisitPlanMapper, VisitPlan
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
List<MonthActivePlanVO> list = visitPlanMapper.getMonthActivePlan(user.getId(),ym);
|
|
|
- httpRespMsg.setData(list);
|
|
|
+
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部任务");
|
|
|
+ boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门任务");
|
|
|
+ Integer departmentId=null;
|
|
|
+ String executor=null;
|
|
|
+
|
|
|
+ if (isAll){
|
|
|
+ departmentId=null;
|
|
|
+ }
|
|
|
+ else if (isNotAll){
|
|
|
+ departmentId= user.getDepartmentId();//找出对应的部门id
|
|
|
+ }else {
|
|
|
+ executor=user.getId();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析为 LocalDate,获取该月的第一天
|
|
|
+ LocalDate startDate = LocalDate.parse(ym + "-01"); // 加上-01表示第一天
|
|
|
+ // 转换为 LocalDateTime
|
|
|
+ LocalDateTime parseStartDate = startDate.atStartOfDay(); // 获取开始时间
|
|
|
+ LocalDateTime parseEndDate = parseStartDate.plusMonths(1L);// 获取结束时间
|
|
|
+ List<TaskDto> taskList = taskMapper.getTaskListByStartAndEnd(parseStartDate, parseEndDate, departmentId, executor, companyId);
|
|
|
+
|
|
|
+ Map<LocalDate, List<TaskDto>> dailyTasks = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ // 生成从startDate到endDate的所有日期,并初始化空列表
|
|
|
+
|
|
|
+ LocalDate parseEnd = startDate.plusMonths(1L).plusDays(-1L);
|
|
|
+ LocalDate currentDate = startDate;
|
|
|
+ while (!currentDate.isAfter(parseEnd)) {
|
|
|
+ dailyTasks.put(currentDate, new ArrayList<>());
|
|
|
+ currentDate = currentDate.plusDays(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历任务,填充到对应的日期
|
|
|
+ for (TaskDto task : taskList) {
|
|
|
+ // 根据实际字段获取任务日期,例如getExecuteDate()
|
|
|
+ LocalDateTime taskStartDate = task.getStartDate();
|
|
|
+ LocalDateTime taskEndDate = task.getEndDate();
|
|
|
+ if (taskStartDate != null && taskEndDate != null) {
|
|
|
+ LocalDate task_start = LocalDate.from(taskStartDate);
|
|
|
+ LocalDate task_end = LocalDate.from(taskEndDate);
|
|
|
+ for (Map.Entry<LocalDate, List<TaskDto>> entry : dailyTasks.entrySet()) {
|
|
|
+ LocalDate date = entry.getKey(); // 获取日期
|
|
|
+ List<TaskDto> tasks = entry.getValue(); // 获取任务列表
|
|
|
+ if (date.isAfter(task_start) && date.isBefore(task_end) || date.isEqual(task_start)) {
|
|
|
+ tasks.add(task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (taskStartDate == null && taskEndDate != null) {
|
|
|
+ LocalDate task_end = LocalDate.from(taskEndDate);
|
|
|
+ for (Map.Entry<LocalDate, List<TaskDto>> entry : dailyTasks.entrySet()) {
|
|
|
+ LocalDate date = entry.getKey(); // 获取日期
|
|
|
+ List<TaskDto> tasks = entry.getValue(); // 获取任务列表
|
|
|
+ if (date.isEqual(task_end)) {
|
|
|
+ tasks.add(task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (taskStartDate != null) {
|
|
|
+ LocalDate task_start = LocalDate.from(taskStartDate);
|
|
|
+ for (Map.Entry<LocalDate, List<TaskDto>> entry : dailyTasks.entrySet()) {
|
|
|
+ LocalDate date = entry.getKey(); // 获取日期
|
|
|
+ List<TaskDto> tasks = entry.getValue(); // 获取任务列表
|
|
|
+ if (date.isEqual(task_start)) {
|
|
|
+ tasks.add(task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //自定义DTO类
|
|
|
+ List<DailyTaskVO> result = dailyTasks.entrySet().stream()
|
|
|
+ .map(entry -> new DailyTaskVO(entry.getKey(), entry.getValue()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<DailyTaskVO> collect = result.stream().filter(r -> !r.getTaskDtoList().isEmpty()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("planList",list);
|
|
|
+ map.put("taskList",collect);
|
|
|
+
|
|
|
+ httpRespMsg.setData(map);
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
}
|