From b75d12cb83570b36871a78cbffd8c1c5c510e94a 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:22:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/pojo/PageParam.java | 4 +- .../controller/admin/area/dto/AreaDTO.java | 11 + .../admin/project/dto/ProjectListDTO.java | 3 + .../admin/resource/dto/ResourceDTO.java | 19 ++ .../admin/resource/dto/ResourceMsgDTO.java | 19 ++ .../statistical/StatisticalController.java | 9 +- .../admin/statistical/vo/StatisticalVo.java | 7 + .../controller/admin/task/TaskController.java | 32 +++ .../admin/task/dto/TaskAssemblyDTO.java | 52 ++++ .../admin/task/dto/TaskDetailDTO.java | 39 +++ .../controller/admin/task/dto/TaskMsgDTO.java | 1 - .../admin/task/dto/TaskPageDTO.java | 9 + .../admin/task/dto/TaskPreAssemblyDTO.java | 45 ++++ .../service/project/ProjectServiceImpl.java | 34 ++- .../module/farm/service/task/TaskService.java | 20 +- .../farm/service/task/TaskServiceImpl.java | 246 +++++++++++++++++- 16 files changed, 533 insertions(+), 17 deletions(-) create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceMsgDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPageDTO.java create mode 100644 zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPreAssemblyDTO.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java index 6a4c28e7..9aeedd2a 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java @@ -21,10 +21,10 @@ public class PageParam implements Serializable { @Min(value = 1, message = "页码最小值为 1") private Integer pageNo = PAGE_NO; - @ApiModelProperty(value = "每页条数,最大值为 100", required = true, example = "10") + @ApiModelProperty(value = "每页条数,最大值为 500", required = true, example = "10") @NotNull(message = "每页条数不能为空") @Min(value = 1, message = "页码最小值为 1") - @Max(value = 100, message = "页码最大值为 100") + @Max(value = 500, message = "页码最大值为 500") private Integer pageSize = PAGE_SIZE; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java new file mode 100644 index 00000000..3c762a4e --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.module.farm.controller.admin.area.dto; + +/** + * @Created by jiu on 2022/6/15. + */ +public class AreaDTO { + + String firstAreaName; + + String secondAreaName; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java index a6181042..ce5c06b5 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.project.dto; import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.*; @@ -19,6 +20,8 @@ public class ProjectListDTO extends ProjectDO { List executorName; + List memberList; + String taskName; @JsonFormat(pattern = "yyyy-MM-dd") diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceDTO.java new file mode 100644 index 00000000..b78f080d --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceDTO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.farm.controller.admin.resource.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @Created by jiu on 2022/6/15. + */ +@Data +public class ResourceDTO { + + Integer num; + + Long reource; + + List resourceId; + +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceMsgDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceMsgDTO.java new file mode 100644 index 00000000..a3418d23 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceMsgDTO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.farm.controller.admin.resource.dto; + +import lombok.Data; + +/** + * 任务下的的资源信息 + */ +@Data +public class ResourceMsgDTO { + + //资源种类 + private String resourceType; + + //资源名 + private String resourceName; + + //数量 + private Integer num; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java index d55ec3ab..9d5cbf63 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java @@ -1,9 +1,6 @@ package cn.iocoder.yudao.module.farm.controller.admin.statistical; -import cn.hutool.core.date.DatePattern; -import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.RequestDTO; @@ -28,8 +25,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; +import java.text.DateFormat; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -58,6 +54,9 @@ public class StatisticalController { //获取时间内的所有工时记录 List workList = workHourMapper.selectList(Wrappers.lambdaQuery().ge(WorkHourDO::getCreateTime, time.getStartTime()).le(WorkHourDO::getCreateTime, time.getEndTime())); + vo.setStartTime(DateUtil.format(time.getStartTime(), "yyyy/MM/dd" )); + vo.setEndTime(DateUtil.format(time.getEndTime(), "yyyy/MM/dd" )); + //工时统计 条形图 List workMsgList = new ArrayList<>(); if (ObjectUtil.isEmpty(workList)){ diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java index 7f252c80..49270d79 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java @@ -3,11 +3,18 @@ package cn.iocoder.yudao.module.farm.controller.admin.statistical.vo; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.sql.Date; import java.util.List; @Data public class StatisticalVo { + private String startTime; + + private String endTime; + @ApiModelProperty("工时统计") private List workMsgList; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java index 37cbe4c8..71f06ef1 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java @@ -1,6 +1,12 @@ package cn.iocoder.yudao.module.farm.controller.admin.task; +import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.module.farm.annotation.FarmMsg; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskDetailDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskMsgDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskPageDTO; +import com.zsw.base.R; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -89,6 +95,14 @@ public class TaskController { return success(TaskConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/apiPage") + @ApiOperation("获得农场项目分页及相关信息") + @PreAuthorize("@ss.hasPermission('farm:task:query')") + public CommonResult> getAdminTaskPage(@Valid TaskPageReqVO pageVO) { + PageResult pageResult = taskService.getAdminTaskPage(pageVO); + return success(pageResult); + } + @GetMapping("/pageSearch") @ApiOperation("搜索条件获得农场项目分页") public CommonResult> getTaskSearchPage(@Valid TaskPageSearchReqVO pageVO) { @@ -109,4 +123,22 @@ public class TaskController { ExcelUtils.write(response, "农场项目.xls", "数据", TaskExcelVO.class, datas); } + + @FarmMsg(type = "任务", title = "查看任务") + @GetMapping("/appGet") + @ApiOperation("APP查看农场任务详情") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('farm:task:query')") + public R appGetTask(@RequestParam("id") Long id){ + return taskService.appGetTask(id); + } + + + @PostMapping("/apiPage") + @ApiOperation("获得农场项目分页") + @PreAuthorize("@ss.hasPermission('farm:task:query')") + public R> apiGetTaskPage(@RequestBody TaskPageDTO pageDTO) { + return taskService.apiGetTaskPage(pageDTO); + } + } 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 new file mode 100644 index 00000000..6c43b1f0 --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.farm.controller.admin.task.dto; + +import cn.iocoder.yudao.module.farm.controller.admin.resource.dto.ResourceMsgDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskBaseVO; +import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; +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 lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * 任务 里面所有信息DTO + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class TaskAssemblyDTO extends TaskBaseVO { + + private Long id; + + //项目名 + String projectName; + + //区域 + List areaNameList; + + //负责人 + String mainPersonName; + + //执行人 + List executorNameList; + + //作物 + String cropName; + + //任务类型 + String taskName; + + //任务内容 + String taskMsg; + + //任务资源 + List taskResourceList; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java new file mode 100644 index 00000000..2aa4ce3f --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.farm.controller.admin.task.dto; + +import cn.hutool.system.oshi.CpuInfo; +import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; +import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TaskDetailDTO extends TaskDO { + + //项目名 + String apiProjectName; + + //区域 + List apiArea; + + //执行人 + List apiExecutor; + + //负责人 + CpUserDO apiMainPerson; + + //作物名 + String apiCropName; + + //任务名 + String apiTaskTypeName; + + //任务内容 + String apiTaskMsg; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java index 86d22fb4..51be1660 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.farm.controller.admin.task.dto; -import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPageDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPageDTO.java new file mode 100644 index 00000000..92aef6ce --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPageDTO.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.module.farm.controller.admin.task.dto; + +import cn.iocoder.yudao.framework.common.page.PageDTO; + +/** + * @Created by jiu on 2022/6/15. + */ +public class TaskPageDTO extends PageDTO { +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPreAssemblyDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPreAssemblyDTO.java new file mode 100644 index 00000000..9c9d61ca --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPreAssemblyDTO.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.module.farm.controller.admin.task.dto; + +import cn.iocoder.yudao.module.farm.controller.admin.resource.dto.ResourceMsgDTO; +import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; +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 lombok.Builder; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +/** + * 任务 里面所有信息DTO + */ +@Data +@Builder +public class TaskPreAssemblyDTO { + + //项目名 + List projectDOList; + + //区域 + List areaDOList; + + //负责人 + List mainPersonList; + + //执行人 + List executorList; + + //作物 + List cropDOList; + + //任务类型 + List taskCateDOList; + + //任务内容 + List taskMsgList; + + //任务资源 + Map> taskResouceMap; +} 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 0c46a649..e352c3d3 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 @@ -4,6 +4,9 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.hutool.system.oshi.CpuInfo; import cn.iocoder.yudao.framework.common.page.PageUtil; import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -24,12 +27,13 @@ import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.JSONPObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.pagehelper.PageInfo; +import com.google.gson.JsonArray; import com.zsw.base.R; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -169,16 +173,35 @@ public class ProjectServiceImpl implements ProjectService { } List idList = list.stream().map(ProjectDO::getId).collect(Collectors.toList()); - List ProjectListDTOList = BeanUtil.copyToList(list, ProjectListDTO.class); + List projectListDTOList = BeanUtil.copyToList(list, ProjectListDTO.class); + + //组装 项目成员信息 + List memberIDList = new ArrayList<>(); + projectListDTOList.forEach(item ->{ + memberIDList.addAll(item.getMembers().toJavaList(Long.class)); + }); + memberIDList.stream().distinct().collect(Collectors.toList()); + List cpUserList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, memberIDList)); + projectListDTOList.forEach(item ->{ + List memberList = new ArrayList<>(); + List projectMember = item.getMembers().toJavaList(Long.class); + cpUserList.forEach(user ->{ + if (projectMember.contains(user.getId())){ + memberList.add(user); + } + }); + item.setMemberList(memberList); + }); + //任务完成的 List taskList = taskMapper.selectList(Wrappers.lambdaQuery().in(TaskDO::getProjectId, idList) .eq(TaskDO::getStatus, TaskStatus.COMPLETE.getCode())); - + //组装项目的最近一次完成任务信息(区域名、人员名、任务名) if (ObjectUtil.isNotEmpty(taskList)) { List taskMsgDTOList = taskService.getTaskMsg(taskList); Map> taskMsgMap = taskMsgDTOList.stream().collect(Collectors.groupingBy(TaskMsgDTO::getProjectId)); - for (ProjectListDTO projectListDTO : ProjectListDTOList) { + for (ProjectListDTO projectListDTO : projectListDTOList) { if (taskMsgMap.containsKey(projectListDTO.getId())){ TaskMsgDTO msgDTO = taskMsgMap.get(projectListDTO.getId()).get(0); projectListDTO.setAreaName(msgDTO.getAreaName()); @@ -188,7 +211,8 @@ public class ProjectServiceImpl implements ProjectService { } } } - PageVO returnList = PageUtil.convertPageInfo(ProjectListDTOList); + + PageVO returnList = PageUtil.convertPageInfo(projectListDTOList); return R.success(returnList); } 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 3cb040cf..6324e7b8 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 @@ -3,10 +3,15 @@ package cn.iocoder.yudao.module.farm.service.task; import java.util.*; import javax.validation.*; +import cn.iocoder.yudao.framework.common.page.PageVO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskDetailDTO; import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskMsgDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskPageDTO; import cn.iocoder.yudao.module.farm.controller.admin.task.vo.*; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import com.zsw.base.R; /** * 农场项目 Service 接口 @@ -61,6 +66,8 @@ public interface TaskService { */ PageResult getTaskPage(TaskPageReqVO pageReqVO); + PageResult getAdminTaskPage(TaskPageReqVO pageReqVO); + /** * 搜索条件获得农场项目分页 * @@ -83,6 +90,17 @@ public interface TaskService { * @param taskDOList 任务List * @return 返回每个任务的执行人、区域、任务名 **/ - public List getTaskMsg(List taskDOList); + List getTaskMsg(List taskDOList); + + /** + * APP 获取任务信息 + **/ + R appGetTask(Long id); + + + /** + * APP 获取任务列表 + **/ + R> apiGetTaskPage(TaskPageDTO pageDTO); } 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 1e283dd6..378df3e5 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 @@ -1,23 +1,40 @@ package cn.iocoder.yudao.module.farm.service.task; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.text.StrBuilder; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO; -import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskMsgDTO; +import cn.iocoder.yudao.framework.common.page.PageUtil; +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.resource.dto.ResourceDTO; +import cn.iocoder.yudao.module.farm.controller.admin.resource.dto.ResourceMsgDTO; +import cn.iocoder.yudao.module.farm.controller.admin.task.dto.*; import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; +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.resource.ResourceDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.resourceType.ResourceTypeDO; import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper; +import cn.iocoder.yudao.module.farm.dal.mysql.crop.CropMapper; +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.system.dal.dataobject.CpUser.CpUserDO; -import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; +import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.zsw.base.R; import org.springframework.stereotype.Service; import javax.annotation.Resource; + import org.springframework.validation.annotation.Validated; import java.util.*; +import java.util.stream.Collectors; + import cn.iocoder.yudao.module.farm.controller.admin.task.vo.*; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -45,6 +62,17 @@ public class TaskServiceImpl implements TaskService { private AreaMapper areaMapper; @Resource private TaskCateMapper taskCateMapper; + @Resource + private CpUserService cpUserService; + @Resource + private ProjectMapper projectMapper; + @Resource + private CropMapper cropMapper; + @Resource + private ResourceTypeMapper resourceTypeMapper; + @Resource + private ResourceMapper resourceMapper; + @Override public Long createTask(TaskCreateReqVO createReqVO) { @@ -93,6 +121,33 @@ public class TaskServiceImpl implements TaskService { return taskMapper.selectPage(pageReqVO); } + @Override + public PageResult getAdminTaskPage(TaskPageReqVO pageReqVO){ + PageResult taskPage = taskMapper.selectPage(pageReqVO); + Map map = this.taskAssemble(taskPage.getList()); + List list = new ArrayList<>(); + taskPage.getList().forEach(item ->{ + if (map.containsKey(item.getId())){ + TaskAssemblyDTO dto = map.get(item.getId()); + TaskAssemblyDTO newDTO = BeanUtil.copyProperties(item, TaskAssemblyDTO.class); + newDTO.setProjectName(dto.getProjectName()); + newDTO.setTaskName(dto.getTaskName()); + newDTO.setTaskResourceList(dto.getTaskResourceList()); + newDTO.setAreaNameList(dto.getAreaNameList()); + newDTO.setExecutorNameList(dto.getExecutorNameList()); + newDTO.setTaskMsg(dto.getTaskMsg()); + newDTO.setMainPersonName(dto.getMainPersonName()); + newDTO.setCropName(dto.getCropName()); + list.add(newDTO); + } + }); + PageResult page = new PageResult<>(); + page.setList(list); + page.setTotal(taskPage.getTotal()); + + return page; + } + @Override public PageResult getTaskSearchPage(TaskPageSearchReqVO pageVO){ pageVO.setPageNo(pageVO.getPageNo() - 1); @@ -191,4 +246,189 @@ public class TaskServiceImpl implements TaskService { return taskMsgList; } + public R appGetTask(Long id){ + TaskDO taskDO = taskMapper.selectById(id); + TaskDetailDTO taskMsg = new TaskDetailDTO(); + BeanUtil.copyProperties(taskDO, taskMsg); + List userIdList = taskDO.getExecutorPerson().toJavaList(Long.class); + List userList = cpUserMapper.selectList(Wrappers.lambdaQuery().in(CpUserDO::getId, userIdList)); + //负责人 + taskMsg.setApiMainPerson(cpUserService.getById(String.valueOf(taskMsg.getMainPerson()))); + //执行人 + taskMsg.setApiExecutor(userList); + return R.success(taskMsg); + } + + public R> apiGetTaskPage(TaskPageDTO pageDTO){ + PageUtil.startPage(pageDTO); + LambdaQueryWrapperX lambdaQueryWrapperX = new LambdaQueryWrapperX<>(); + List taskDOList = taskMapper.selectList(lambdaQueryWrapperX); + List taskList = BeanUtil.copyToList(taskDOList, TaskDetailDTO.class); + PageVO pageVO = PageUtil.convertPageInfo(taskList); + return R.success(pageVO); + } + + /** + * 任务里面信息预查询(查出所有需要的) + **/ + public TaskPreAssemblyDTO taskPreAssemble(List taskDOList){ + //项目名 + List projectIdList = taskDOList.stream().map(TaskDO::getProjectId).collect(Collectors.toList()); + List projectDOList = projectMapper.selectList(new LambdaQueryWrapperX().inIfPresent(ProjectDO::getId, projectIdList)); + //区域 + List areaIdList = new ArrayList<>(); + //执行人 + List executorIdList = new ArrayList<>(); + //资源 要处理的数据 + Map> resourceMap = new HashMap<>(); + + for (TaskDO taskDO : taskDOList) { + for (Object area : taskDO.getAreas()) { + areaIdList.addAll(JSONArray.parseArray(area.toString(), Long.class)); + } + executorIdList.addAll(taskDO.getExecutorPerson().toJavaList(Long.class)); + + resourceMap.put(taskDO.getId(), taskDO.getResources().toJavaList(ResourceDTO.class)); + } + + List areaDOList = areaMapper.selectList(new LambdaQueryWrapperX().inIfPresent(AreaDO::getId, areaIdList)); + List executorList = cpUserMapper.selectList(new LambdaQueryWrapperX().inIfPresent(CpUserDO::getId, executorIdList)); + + //负责人 + List mainPersonIdList = taskDOList.stream().map(TaskDO::getMainPerson).collect(Collectors.toList()); + List mainPersonList = cpUserMapper.selectList(new LambdaQueryWrapperX().inIfPresent(CpUserDO::getId, mainPersonIdList)); + + //作物名 + List cropIdList = taskDOList.stream().map(TaskDO::getCropId).collect(Collectors.toList()); + List cropDOList = cropMapper.selectList(new LambdaQueryWrapperX().inIfPresent(CropDO::getId, cropIdList)); + + //任务名 + List taskCateIdList = taskDOList.stream().map(TaskDO::getTaskCateId).collect(Collectors.toList()); + List taskCateDOList = taskCateMapper.selectList(new LambdaQueryWrapperX().inIfPresent(TaskCateDO::getId, taskCateIdList)); + + //任务内容 + 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()){ + resourceAssemble.addAll(dto); + } + List resourceTypeIdList = new ArrayList<>(); + List resourceIdList = new ArrayList<>(); + for (ResourceDTO resourceDTO : resourceAssemble) { + resourceTypeIdList.add(resourceDTO.getResourceId().get(0)); + resourceIdList.add(resourceDTO.getResourceId().get(1)); + } + List resourceTypeList = resourceTypeMapper.selectList(new LambdaQueryWrapperX().inIfPresent(ResourceTypeDO::getId, resourceTypeIdList)); + List resourceList = resourceMapper.selectList(new LambdaQueryWrapperX().inIfPresent(ResourceDO::getId, resourceIdList)); + + Map> taskResouceMap = new HashMap<>(); + for (Long taskId : resourceMap.keySet()){ + List dtoList= new ArrayList<>(); + List innerList = resourceMap.get(taskId); + innerList.forEach(inner ->{ + ResourceMsgDTO msg = new ResourceMsgDTO(); + msg.setNum(inner.getNum()); + resourceTypeList.forEach(type ->{ + if (ObjectUtil.isNotEmpty(inner) && inner.getResourceId().get(0).equals(type.getId())){ + msg.setResourceType(type.getName()); + } + }); + resourceList.forEach(res ->{ + if (ObjectUtil.isNotEmpty(inner) && inner.getResourceId().get(1).equals(res.getId())){ + msg.setResourceName(res.getName()); + } + }); + dtoList.add(msg); + }); + taskResouceMap.put(taskId, dtoList); + } + + return TaskPreAssemblyDTO.builder() + .projectDOList(projectDOList) + .areaDOList(areaDOList) + .executorList(executorList) + .mainPersonList(mainPersonList) + .cropDOList(cropDOList) + .taskCateDOList(taskCateDOList) + .taskMsgList(taskMsgList) + .taskResouceMap(taskResouceMap) + .build(); + + } + + /** + * 任务所需信息组装 + * @param taskDOList 任务列表 + **/ + public Map taskAssemble(List taskDOList){ + TaskPreAssemblyDTO preAssemblyDTO = this.taskPreAssemble(taskDOList); + + Map map = new HashMap<>(); + for (TaskDO taskDO : taskDOList) { + TaskAssemblyDTO dto = new TaskAssemblyDTO(); + //项目名 + preAssemblyDTO.getProjectDOList().stream().filter(project -> project.getId().equals(taskDO.getProjectId())).findFirst() + .ifPresent(item ->{ + dto.setProjectName(item.getName()); + }); + //负责人名 + preAssemblyDTO.getMainPersonList().stream().filter(mainPerson -> mainPerson.getId().equals(taskDO.getMainPerson())).findFirst() + .ifPresent(item ->{ + dto.setMainPersonName(item.getName()); + }); + //作物名 + preAssemblyDTO.getCropDOList().stream().filter(crop -> crop.getId().equals(taskDO.getCropId())).findFirst() + .ifPresent(item ->{ + dto.setCropName(item.getName()); + }); + //任务类型名 + preAssemblyDTO.getTaskCateDOList().stream().filter(taskCate -> taskCate.getId().equals(taskDO.getTaskCateId())).findFirst() + .ifPresent(item ->{ + dto.setTaskName(item.getName()); + }); + //任务内容 + preAssemblyDTO.getTaskMsgList().stream().filter(taskMsg -> taskMsg.getId().equals(taskDO.getTaskCateName())).findFirst() + .ifPresent(item ->{ + dto.setTaskMsg(item.getName()); + }); + //执行人名 + List executorNameList = new ArrayList<>(); + preAssemblyDTO.getExecutorList().forEach(executor ->{ + taskDO.getExecutorPerson().toJavaList(Long.class).forEach(item ->{ + if (executor.getId().equals(item)){ + executorNameList.add( executor.getName()); + } + }); + }); + dto.setExecutorNameList(executorNameList); + //区域名 + List areaNameList = new ArrayList<>(); + for (Object obj : taskDO.getAreas()) { + List areaList = JSONArray.parseArray(obj.toString(), Long.class); + StrBuilder areaName = new StrBuilder(); + areaList.forEach( one ->{ + preAssemblyDTO.getAreaDOList().stream().filter(item -> item.getId().equals(one)).findFirst() + .ifPresent(sonArea ->{ + areaName.append(sonArea.getName()); + }); + + }); + areaNameList.add(areaName.toString()); + } + dto.setAreaNameList(areaNameList); + //资源 + if (preAssemblyDTO.getTaskResouceMap().containsKey(taskDO.getId())){ + List resList = preAssemblyDTO.getTaskResouceMap().get(taskDO.getId()); + dto.setTaskResourceList(resList); + } + map.put(taskDO.getId(), dto); + } + return map; + } + + }