Browse Source

优化代码

zyh
小久哥 3 years ago
parent
commit
b75d12cb83
  1. 4
      yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java
  2. 11
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/area/dto/AreaDTO.java
  3. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java
  4. 19
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceDTO.java
  5. 19
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/dto/ResourceMsgDTO.java
  6. 9
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java
  7. 7
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/vo/StatisticalVo.java
  8. 32
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java
  9. 52
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskAssemblyDTO.java
  10. 39
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java
  11. 1
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java
  12. 9
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPageDTO.java
  13. 45
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskPreAssemblyDTO.java
  14. 34
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java
  15. 20
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java
  16. 246
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

4
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") @Min(value = 1, message = "页码最小值为 1")
private Integer pageNo = PAGE_NO; private Integer pageNo = PAGE_NO;
@ApiModelProperty(value = "每页条数,最大值为 100", required = true, example = "10") @ApiModelProperty(value = "每页条数,最大值为 500", required = true, example = "10")
@NotNull(message = "每页条数不能为空") @NotNull(message = "每页条数不能为空")
@Min(value = 1, message = "页码最小值为 1") @Min(value = 1, message = "页码最小值为 1")
@Max(value = 100, message = "页码最大值为 100") @Max(value = 500, message = "页码最大值为 500")
private Integer pageSize = PAGE_SIZE; private Integer pageSize = PAGE_SIZE;
} }

11
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;
}

3
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.farm.dal.dataobject.project.ProjectDO;
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*; import lombok.*;
@ -19,6 +20,8 @@ public class ProjectListDTO extends ProjectDO {
List<String> executorName; List<String> executorName;
List<CpUserDO> memberList;
String taskName; String taskName;
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")

19
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<Long> resourceId;
}

19
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;
}

9
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; 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.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.RequestDTO; 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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.text.DateFormat;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -58,6 +54,9 @@ public class StatisticalController {
//获取时间内的所有工时记录 //获取时间内的所有工时记录
List<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>lambdaQuery().ge(WorkHourDO::getCreateTime, time.getStartTime()).le(WorkHourDO::getCreateTime, time.getEndTime())); List<WorkHourDO> workList = workHourMapper.selectList(Wrappers.<WorkHourDO>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<WorkMsg> workMsgList = new ArrayList<>(); List<WorkMsg> workMsgList = new ArrayList<>();
if (ObjectUtil.isEmpty(workList)){ if (ObjectUtil.isEmpty(workList)){

7
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 io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.sql.Date;
import java.util.List; import java.util.List;
@Data @Data
public class StatisticalVo { public class StatisticalVo {
private String startTime;
private String endTime;
@ApiModelProperty("工时统计") @ApiModelProperty("工时统计")
private List<WorkMsg> workMsgList; private List<WorkMsg> workMsgList;

32
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; 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.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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -89,6 +95,14 @@ public class TaskController {
return success(TaskConvert.INSTANCE.convertPage(pageResult)); return success(TaskConvert.INSTANCE.convertPage(pageResult));
} }
@GetMapping("/apiPage")
@ApiOperation("获得农场项目分页及相关信息")
@PreAuthorize("@ss.hasPermission('farm:task:query')")
public CommonResult<PageResult<TaskAssemblyDTO>> getAdminTaskPage(@Valid TaskPageReqVO pageVO) {
PageResult<TaskAssemblyDTO> pageResult = taskService.getAdminTaskPage(pageVO);
return success(pageResult);
}
@GetMapping("/pageSearch") @GetMapping("/pageSearch")
@ApiOperation("搜索条件获得农场项目分页") @ApiOperation("搜索条件获得农场项目分页")
public CommonResult<PageResult<TaskRespVO>> getTaskSearchPage(@Valid TaskPageSearchReqVO pageVO) { public CommonResult<PageResult<TaskRespVO>> getTaskSearchPage(@Valid TaskPageSearchReqVO pageVO) {
@ -109,4 +123,22 @@ public class TaskController {
ExcelUtils.write(response, "农场项目.xls", "数据", TaskExcelVO.class, datas); 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<TaskDetailDTO> appGetTask(@RequestParam("id") Long id){
return taskService.appGetTask(id);
}
@PostMapping("/apiPage")
@ApiOperation("获得农场项目分页")
@PreAuthorize("@ss.hasPermission('farm:task:query')")
public R<PageVO<TaskDetailDTO>> apiGetTaskPage(@RequestBody TaskPageDTO pageDTO) {
return taskService.apiGetTaskPage(pageDTO);
}
} }

52
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<String> areaNameList;
//负责人
String mainPersonName;
//执行人
List<String> executorNameList;
//作物
String cropName;
//任务类型
String taskName;
//任务内容
String taskMsg;
//任务资源
List<ResourceMsgDTO> taskResourceList;
}

39
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<AreaDO> apiArea;
//执行人
List<CpUserDO> apiExecutor;
//负责人
CpUserDO apiMainPerson;
//作物名
String apiCropName;
//任务名
String apiTaskTypeName;
//任务内容
String apiTaskMsg;
}

1
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; 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 cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

9
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 {
}

45
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<ProjectDO> projectDOList;
//区域
List<AreaDO> areaDOList;
//负责人
List<CpUserDO> mainPersonList;
//执行人
List<CpUserDO> executorList;
//作物
List<CropDO> cropDOList;
//任务类型
List<TaskCateDO> taskCateDOList;
//任务内容
List<TaskCateDO> taskMsgList;
//任务资源
Map<Long, List<ResourceMsgDTO>> taskResouceMap;
}

34
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.date.LocalDateTimeUtil;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil; 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.PageUtil;
import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.framework.common.page.PageVO;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 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.CpUser.CpUserService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService; import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.alibaba.fastjson.JSONArray; 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.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.gson.JsonArray;
import com.zsw.base.R; import com.zsw.base.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -169,16 +173,35 @@ public class ProjectServiceImpl implements ProjectService {
} }
List<Long> idList = list.stream().map(ProjectDO::getId).collect(Collectors.toList()); List<Long> idList = list.stream().map(ProjectDO::getId).collect(Collectors.toList());
List<ProjectListDTO> ProjectListDTOList = BeanUtil.copyToList(list, ProjectListDTO.class); List<ProjectListDTO> projectListDTOList = BeanUtil.copyToList(list, ProjectListDTO.class);
//组装 项目成员信息
List<Long> memberIDList = new ArrayList<>();
projectListDTOList.forEach(item ->{
memberIDList.addAll(item.getMembers().toJavaList(Long.class));
});
memberIDList.stream().distinct().collect(Collectors.toList());
List<CpUserDO> cpUserList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, memberIDList));
projectListDTOList.forEach(item ->{
List<CpUserDO> memberList = new ArrayList<>();
List<Long> projectMember = item.getMembers().toJavaList(Long.class);
cpUserList.forEach(user ->{
if (projectMember.contains(user.getId())){
memberList.add(user);
}
});
item.setMemberList(memberList);
});
//任务完成的 //任务完成的
List<TaskDO> taskList = taskMapper.selectList(Wrappers.<TaskDO>lambdaQuery().in(TaskDO::getProjectId, idList) List<TaskDO> taskList = taskMapper.selectList(Wrappers.<TaskDO>lambdaQuery().in(TaskDO::getProjectId, idList)
.eq(TaskDO::getStatus, TaskStatus.COMPLETE.getCode())); .eq(TaskDO::getStatus, TaskStatus.COMPLETE.getCode()));
//组装项目的最近一次完成任务信息(区域名、人员名、任务名)
if (ObjectUtil.isNotEmpty(taskList)) { if (ObjectUtil.isNotEmpty(taskList)) {
List<TaskMsgDTO> taskMsgDTOList = taskService.getTaskMsg(taskList); List<TaskMsgDTO> taskMsgDTOList = taskService.getTaskMsg(taskList);
Map<Long, List<TaskMsgDTO>> taskMsgMap = taskMsgDTOList.stream().collect(Collectors.groupingBy(TaskMsgDTO::getProjectId)); Map<Long, List<TaskMsgDTO>> taskMsgMap = taskMsgDTOList.stream().collect(Collectors.groupingBy(TaskMsgDTO::getProjectId));
for (ProjectListDTO projectListDTO : ProjectListDTOList) { for (ProjectListDTO projectListDTO : projectListDTOList) {
if (taskMsgMap.containsKey(projectListDTO.getId())){ if (taskMsgMap.containsKey(projectListDTO.getId())){
TaskMsgDTO msgDTO = taskMsgMap.get(projectListDTO.getId()).get(0); TaskMsgDTO msgDTO = taskMsgMap.get(projectListDTO.getId()).get(0);
projectListDTO.setAreaName(msgDTO.getAreaName()); projectListDTO.setAreaName(msgDTO.getAreaName());
@ -188,7 +211,8 @@ public class ProjectServiceImpl implements ProjectService {
} }
} }
} }
PageVO<ProjectListDTO> returnList = PageUtil.convertPageInfo(ProjectListDTOList);
PageVO<ProjectListDTO> returnList = PageUtil.convertPageInfo(projectListDTOList);
return R.success(returnList); return R.success(returnList);
} }

20
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 java.util.*;
import javax.validation.*; 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.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.controller.admin.task.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.zsw.base.R;
/** /**
* 农场项目 Service 接口 * 农场项目 Service 接口
@ -61,6 +66,8 @@ public interface TaskService {
*/ */
PageResult<TaskDO> getTaskPage(TaskPageReqVO pageReqVO); PageResult<TaskDO> getTaskPage(TaskPageReqVO pageReqVO);
PageResult<TaskAssemblyDTO> getAdminTaskPage(TaskPageReqVO pageReqVO);
/** /**
* 搜索条件获得农场项目分页 * 搜索条件获得农场项目分页
* *
@ -83,6 +90,17 @@ public interface TaskService {
* @param taskDOList 任务List * @param taskDOList 任务List
* @return 返回每个任务的执行人区域任务名 * @return 返回每个任务的执行人区域任务名
**/ **/
public List<TaskMsgDTO> getTaskMsg(List<TaskDO> taskDOList); List<TaskMsgDTO> getTaskMsg(List<TaskDO> taskDOList);
/**
* APP 获取任务信息
**/
R<TaskDetailDTO> appGetTask(Long id);
/**
* APP 获取任务列表
**/
R<PageVO<TaskDetailDTO>> apiGetTaskPage(TaskPageDTO pageDTO);
} }

246
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; package cn.iocoder.yudao.module.farm.service.task;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO; import cn.iocoder.yudao.framework.common.page.PageUtil;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskMsgDTO; 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.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.dataobject.taskCate.TaskCateDO;
import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper; 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.farm.dal.mysql.taskCate.TaskCateMapper;
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; 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.dal.mysql.CpUser.CpUserMapper;
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zsw.base.R;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.*; import cn.iocoder.yudao.module.farm.controller.admin.task.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -45,6 +62,17 @@ public class TaskServiceImpl implements TaskService {
private AreaMapper areaMapper; private AreaMapper areaMapper;
@Resource @Resource
private TaskCateMapper taskCateMapper; private TaskCateMapper taskCateMapper;
@Resource
private CpUserService cpUserService;
@Resource
private ProjectMapper projectMapper;
@Resource
private CropMapper cropMapper;
@Resource
private ResourceTypeMapper resourceTypeMapper;
@Resource
private ResourceMapper resourceMapper;
@Override @Override
public Long createTask(TaskCreateReqVO createReqVO) { public Long createTask(TaskCreateReqVO createReqVO) {
@ -93,6 +121,33 @@ public class TaskServiceImpl implements TaskService {
return taskMapper.selectPage(pageReqVO); return taskMapper.selectPage(pageReqVO);
} }
@Override
public PageResult<TaskAssemblyDTO> getAdminTaskPage(TaskPageReqVO pageReqVO){
PageResult<TaskDO> taskPage = taskMapper.selectPage(pageReqVO);
Map<Long, TaskAssemblyDTO> map = this.taskAssemble(taskPage.getList());
List<TaskAssemblyDTO> 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<TaskAssemblyDTO> page = new PageResult<>();
page.setList(list);
page.setTotal(taskPage.getTotal());
return page;
}
@Override @Override
public PageResult<TaskDO> getTaskSearchPage(TaskPageSearchReqVO pageVO){ public PageResult<TaskDO> getTaskSearchPage(TaskPageSearchReqVO pageVO){
pageVO.setPageNo(pageVO.getPageNo() - 1); pageVO.setPageNo(pageVO.getPageNo() - 1);
@ -191,4 +246,189 @@ public class TaskServiceImpl implements TaskService {
return taskMsgList; return taskMsgList;
} }
public R<TaskDetailDTO> appGetTask(Long id){
TaskDO taskDO = taskMapper.selectById(id);
TaskDetailDTO taskMsg = new TaskDetailDTO();
BeanUtil.copyProperties(taskDO, taskMsg);
List<Long> userIdList = taskDO.getExecutorPerson().toJavaList(Long.class);
List<CpUserDO> userList = cpUserMapper.selectList(Wrappers.<CpUserDO>lambdaQuery().in(CpUserDO::getId, userIdList));
//负责人
taskMsg.setApiMainPerson(cpUserService.getById(String.valueOf(taskMsg.getMainPerson())));
//执行人
taskMsg.setApiExecutor(userList);
return R.success(taskMsg);
}
public R<PageVO<TaskDetailDTO>> apiGetTaskPage(TaskPageDTO pageDTO){
PageUtil.startPage(pageDTO);
LambdaQueryWrapperX<TaskDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<>();
List<TaskDO> taskDOList = taskMapper.selectList(lambdaQueryWrapperX);
List<TaskDetailDTO> taskList = BeanUtil.copyToList(taskDOList, TaskDetailDTO.class);
PageVO<TaskDetailDTO> pageVO = PageUtil.convertPageInfo(taskList);
return R.success(pageVO);
}
/**
* 任务里面信息预查询(查出所有需要的)
**/
public TaskPreAssemblyDTO taskPreAssemble(List<TaskDO> taskDOList){
//项目名
List<Long> projectIdList = taskDOList.stream().map(TaskDO::getProjectId).collect(Collectors.toList());
List<ProjectDO> projectDOList = projectMapper.selectList(new LambdaQueryWrapperX<ProjectDO>().inIfPresent(ProjectDO::getId, projectIdList));
//区域
List<Long> areaIdList = new ArrayList<>();
//执行人
List<Long> executorIdList = new ArrayList<>();
//资源 要处理的数据
Map<Long,List<ResourceDTO>> 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<AreaDO> areaDOList = areaMapper.selectList(new LambdaQueryWrapperX<AreaDO>().inIfPresent(AreaDO::getId, areaIdList));
List<CpUserDO> executorList = cpUserMapper.selectList(new LambdaQueryWrapperX<CpUserDO>().inIfPresent(CpUserDO::getId, executorIdList));
//负责人
List<Long> mainPersonIdList = taskDOList.stream().map(TaskDO::getMainPerson).collect(Collectors.toList());
List<CpUserDO> mainPersonList = cpUserMapper.selectList(new LambdaQueryWrapperX<CpUserDO>().inIfPresent(CpUserDO::getId, mainPersonIdList));
//作物名
List<Long> cropIdList = taskDOList.stream().map(TaskDO::getCropId).collect(Collectors.toList());
List<CropDO> cropDOList = cropMapper.selectList(new LambdaQueryWrapperX<CropDO>().inIfPresent(CropDO::getId, cropIdList));
//任务名
List<Long> taskCateIdList = taskDOList.stream().map(TaskDO::getTaskCateId).collect(Collectors.toList());
List<TaskCateDO> taskCateDOList = taskCateMapper.selectList(new LambdaQueryWrapperX<TaskCateDO>().inIfPresent(TaskCateDO::getId, taskCateIdList));
//任务内容
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()){
resourceAssemble.addAll(dto);
}
List<Long> resourceTypeIdList = new ArrayList<>();
List<Long> resourceIdList = new ArrayList<>();
for (ResourceDTO resourceDTO : resourceAssemble) {
resourceTypeIdList.add(resourceDTO.getResourceId().get(0));
resourceIdList.add(resourceDTO.getResourceId().get(1));
}
List<ResourceTypeDO> resourceTypeList = resourceTypeMapper.selectList(new LambdaQueryWrapperX<ResourceTypeDO>().inIfPresent(ResourceTypeDO::getId, resourceTypeIdList));
List<ResourceDO> resourceList = resourceMapper.selectList(new LambdaQueryWrapperX<ResourceDO>().inIfPresent(ResourceDO::getId, resourceIdList));
Map<Long, List<ResourceMsgDTO>> taskResouceMap = new HashMap<>();
for (Long taskId : resourceMap.keySet()){
List<ResourceMsgDTO> dtoList= new ArrayList<>();
List<ResourceDTO> 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<Long, TaskAssemblyDTO> taskAssemble(List<TaskDO> taskDOList){
TaskPreAssemblyDTO preAssemblyDTO = this.taskPreAssemble(taskDOList);
Map<Long, TaskAssemblyDTO> 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<String> 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<String> areaNameList = new ArrayList<>();
for (Object obj : taskDO.getAreas()) {
List<Long> 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<ResourceMsgDTO> resList = preAssemblyDTO.getTaskResouceMap().get(taskDO.getId());
dto.setTaskResourceList(resList);
}
map.put(taskDO.getId(), dto);
}
return map;
}
} }

Loading…
Cancel
Save