Browse Source

删除无效 任务方法

zyh
小久哥 3 years ago
parent
commit
c0e6c171a6
  1. 6
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java
  2. 22
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java
  3. 14
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java
  4. 89
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

6
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<ResourceMsgDTO> taskResourceList;
//时间
@JsonFormat(pattern = "yyyy-MM-dd")
Date finishTime;
}

22
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<TaskMsgDTO> taskMsgDTOList = taskService.getTaskMsg(taskList);
Map<Long, List<TaskMsgDTO>> taskMsgMap = taskMsgDTOList.stream().collect(Collectors.groupingBy(TaskMsgDTO::getProjectId));
Map<Long, TaskAssemblyDTO> taskAssemble = taskService.taskAssemble(taskList);
Map<Long, List<TaskDO>> 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());
}
);
}
}
}

14
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<TaskDO> getTaskList(TaskExportReqVO exportReqVO);
/**
* @Description 根据taskDOList 获取每个taskDO的 执行人区域任务名
* @param taskDOList 任务List
* @return 返回每个任务的执行人区域任务名
**/
List<TaskMsgDTO> getTaskMsg(List<TaskDO> taskDOList);
/**
* APP 获取任务信息
**/
R<TaskDetailDTO> appGetTask(Long id);
/**
* APP 获取任务列表
**/
R<PageVO<TaskDetailDTO>> apiGetTaskPage(TaskPageDTO pageDTO);
/**
* 根据任务列表 返回每条任务的具体信息
**/
Map<Long, TaskAssemblyDTO> taskAssemble(List<TaskDO> taskDOList);
}

89
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<TaskMsgDTO> getTaskMsg(List<TaskDO> taskList){
Set<Long> personSet = new HashSet<>();
Set<Long> areaSet = new HashSet<>();
Set<Long> taskCateSet = new HashSet<>();
List<TaskMsgDTO> 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<Long> joinPerson = new ArrayList<Long>(personSet);
List<CpUserDO> cpUserList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, joinPerson));
List<Long> joinArea = new ArrayList<Long>(areaSet);
List<AreaDO> areaDOList = areaMapper.selectList(Wrappers.<AreaDO>lambdaQuery().in(AreaDO::getId, joinArea));
List<Long> joinTaskCate = new ArrayList<>(taskCateSet);
List<TaskCateDO> taskCateDOList = taskCateMapper.selectList(Wrappers.<TaskCateDO>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<String> 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<String> 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<TaskDetailDTO> 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<Long> taskCateNameIdList = taskDOList.stream().map(TaskDO::getTaskCateName).collect(Collectors.toList());
List<TaskCateDO> taskMsgList = taskCateMapper.selectList(new LambdaQueryWrapperX<TaskCateDO>().inIfPresent(TaskCateDO::getId, taskCateNameIdList));
//资源 处理下
List<ResourceDTO> resourceAssemble = new ArrayList<>();
for (List<ResourceDTO> dto : resourceMap.values()){
@ -425,6 +342,10 @@ public class TaskServiceImpl implements TaskService {
List<ResourceMsgDTO> 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;

Loading…
Cancel
Save