From c0e6c171a68a1b953ec5b817598f32ed161d4e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B9=85=E5=93=A5?= <787952492@qq.com> Date: Wed, 15 Jun 2022 18:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/task/dto/TaskAssemblyDTO.java | 6 ++ .../service/project/ProjectServiceImpl.java | 22 +++-- .../module/farm/service/task/TaskService.java | 14 ++- .../farm/service/task/TaskServiceImpl.java | 89 ++----------------- 4 files changed, 30 insertions(+), 101 deletions(-) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java index 6c43b1f0..588bb6c1 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java @@ -7,11 +7,13 @@ import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO; import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.Date; import java.util.List; import java.util.Map; @@ -49,4 +51,8 @@ public class TaskAssemblyDTO extends TaskBaseVO { //任务资源 List taskResourceList; + + //时间 + @JsonFormat(pattern = "yyyy-MM-dd") + Date finishTime; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java index e352c3d3..95e8b632 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java @@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO; import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO; import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskMsgDTO; import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; @@ -199,15 +200,20 @@ public class ProjectServiceImpl implements ProjectService { .eq(TaskDO::getStatus, TaskStatus.COMPLETE.getCode())); //组装项目的最近一次完成任务信息(区域名、人员名、任务名) if (ObjectUtil.isNotEmpty(taskList)) { - List taskMsgDTOList = taskService.getTaskMsg(taskList); - Map> taskMsgMap = taskMsgDTOList.stream().collect(Collectors.groupingBy(TaskMsgDTO::getProjectId)); + Map taskAssemble = taskService.taskAssemble(taskList); + Map> map = taskList.stream().collect(Collectors.groupingBy(TaskDO::getProjectId)); for (ProjectListDTO projectListDTO : projectListDTOList) { - if (taskMsgMap.containsKey(projectListDTO.getId())){ - TaskMsgDTO msgDTO = taskMsgMap.get(projectListDTO.getId()).get(0); - projectListDTO.setAreaName(msgDTO.getAreaName()); - projectListDTO.setExecutorName(msgDTO.getExecutorName()); - projectListDTO.setTaskName(msgDTO.getTaskName()); - projectListDTO.setFinishTime(msgDTO.getUpdateTime()); + //如果map 包含项目id + if (map.containsKey(projectListDTO.getId())){ + map.get(projectListDTO.getId()).stream().findFirst().ifPresent( + item ->{ + TaskAssemblyDTO assemble = taskAssemble.get(item.getId()); + projectListDTO.setAreaName(assemble.getAreaNameList()); + projectListDTO.setExecutorName(assemble.getExecutorNameList()); + projectListDTO.setTaskName(assemble.getTaskName()); + projectListDTO.setFinishTime(assemble.getFinishTime()); + } + ); } } } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java index 6324e7b8..a171ca11 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java @@ -84,23 +84,19 @@ public interface TaskService { */ List getTaskList(TaskExportReqVO exportReqVO); - - /** - * @Description 根据taskDOList 获取每个taskDO的 执行人、区域、任务名 - * @param taskDOList 任务List - * @return 返回每个任务的执行人、区域、任务名 - **/ - List getTaskMsg(List taskDOList); - /** * APP 获取任务信息 **/ R appGetTask(Long id); - /** * APP 获取任务列表 **/ R> apiGetTaskPage(TaskPageDTO pageDTO); + /** + * 根据任务列表 返回每条任务的具体信息 + **/ + Map taskAssemble(List taskDOList); + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java index 378df3e5..57ba82a7 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java @@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper; import cn.iocoder.yudao.module.farm.dal.mysql.resource.ResourceMapper; import cn.iocoder.yudao.module.farm.dal.mysql.resourceType.ResourceTypeMapper; import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; +import cn.iocoder.yudao.module.farm.enums.TaskStatus; import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; @@ -164,88 +165,6 @@ public class TaskServiceImpl implements TaskService { return taskMapper.selectList(exportReqVO); } - - public List getTaskMsg(List taskList){ - Set personSet = new HashSet<>(); - Set areaSet = new HashSet<>(); - Set taskCateSet = new HashSet<>(); - List taskMsgList = new ArrayList<>(); - - //先获取所有任务得到 去重后的 参与人、区域、任务分类名 - for (TaskDO taskDO : taskList) { - //项目参与人 - taskDO.getExecutorPerson().forEach(p ->{ - if (p != null) { - personSet.add(Long.valueOf( p.toString())); - } - }); - //项目区域 - if (taskDO.getAreas() != null){ - taskDO.getAreas().forEach(area ->{ - JSONArray array = JSONArray.parseArray(area.toString()); - areaSet.add(Long.valueOf(array.get(0).toString())); - areaSet.add(Long.valueOf(array.get(1).toString())); - }); - } - //任务分类名 - taskCateSet.add(taskDO.getTaskCateId()); - } - - //一次查出所需信息 - List joinPerson = new ArrayList(personSet); - List cpUserList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, joinPerson)); - List joinArea = new ArrayList(areaSet); - List areaDOList = areaMapper.selectList(Wrappers.lambdaQuery().in(AreaDO::getId, joinArea)); - List joinTaskCate = new ArrayList<>(taskCateSet); - List taskCateDOList = taskCateMapper.selectList(Wrappers.lambdaQuery().in(TaskCateDO::getId, joinTaskCate)); - - //查询任务的 姓名/区域/任务名 - for (TaskDO taskDO : taskList) { - TaskMsgDTO msgDTO = BeanUtil.copyProperties(taskDO, TaskMsgDTO.class); - //完成时间 - msgDTO.setFinishTime(taskDO.getUpdateTime()); - //任务名 - for (TaskCateDO taskCateDO : taskCateDOList) { - if (taskCateDO.getId().equals(taskDO.getTaskCateId())){ - msgDTO.setTaskName(taskCateDO.getName()); - } - } - - //执行人 - List personNameList = new ArrayList<>(); - for (Long executorPerson : taskDO.getExecutorPerson().toJavaList(Long.class)) { - for (CpUserDO cpUserDO : cpUserList) { - if (cpUserDO.getId().equals(executorPerson)){ - personNameList.add(cpUserDO.getName()); - } - } - msgDTO.setExecutorName(personNameList); - } - //任务区域 - List areaNameList = new ArrayList<>(); - for (Object area : taskDO.getAreas()) { - JSONArray array = JSONArray.parseArray(area.toString()); - Long areaParent = Long.valueOf(String.valueOf(array.get(0))); - Long areaSon = Long.valueOf(String.valueOf(array.get(1))); - StringBuilder areaName = new StringBuilder(); - for (AreaDO areaDO : areaDOList) { - if (areaDO.getId().equals(areaParent)){ - areaName.append(areaDO.getName()); - } - if (areaDO.getId().equals(areaSon)){ - areaName.append(areaDO.getName()); - } - } - if (ObjectUtil.isNotEmpty(areaName)){ - areaNameList.add(areaName.toString()); - } - msgDTO.setAreaName(areaNameList); - } - taskMsgList.add(msgDTO); - } - return taskMsgList; - } - public R appGetTask(Long id){ TaskDO taskDO = taskMapper.selectById(id); TaskDetailDTO taskMsg = new TaskDetailDTO(); @@ -287,7 +206,6 @@ public class TaskServiceImpl implements TaskService { areaIdList.addAll(JSONArray.parseArray(area.toString(), Long.class)); } executorIdList.addAll(taskDO.getExecutorPerson().toJavaList(Long.class)); - resourceMap.put(taskDO.getId(), taskDO.getResources().toJavaList(ResourceDTO.class)); } @@ -310,7 +228,6 @@ public class TaskServiceImpl implements TaskService { List taskCateNameIdList = taskDOList.stream().map(TaskDO::getTaskCateName).collect(Collectors.toList()); List taskMsgList = taskCateMapper.selectList(new LambdaQueryWrapperX().inIfPresent(TaskCateDO::getId, taskCateNameIdList)); - //资源 处理下 List resourceAssemble = new ArrayList<>(); for (List dto : resourceMap.values()){ @@ -425,6 +342,10 @@ public class TaskServiceImpl implements TaskService { List resList = preAssemblyDTO.getTaskResouceMap().get(taskDO.getId()); dto.setTaskResourceList(resList); } + //完成的任务加个时间 + if (taskDO.getStatus().equals(TaskStatus.COMPLETE)){ + dto.setFinishTime(taskDO.getUpdateTime()); + } map.put(taskDO.getId(), dto); } return map;