小久哥 3 years ago
parent
commit
8503e7a69f
  1. 6
      yudao-framework/yudao-common/pom.xml
  2. 98
      yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/page/PageUtil.java
  3. 45
      yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/page/PageVO.java
  4. 3
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserBaseVO.java
  5. 3
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserExcelVO.java
  6. 2
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserExportReqVO.java
  7. 2
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserPageReqVO.java
  8. 6
      zsw-farm/zsw-farm-impl/pom.xml
  9. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java
  10. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java
  11. 26
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java
  12. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java
  13. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskExcelVO.java
  14. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskExportReqVO.java
  15. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageReqVO.java
  16. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageSearchReqVO.java
  17. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java
  18. 6
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java
  19. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectService.java
  20. 175
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java
  21. 10
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java
  22. 101
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

6
yudao-framework/yudao-common/pom.xml

@ -127,6 +127,12 @@
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

98
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/page/PageUtil.java

@ -0,0 +1,98 @@
package cn.iocoder.yudao.framework.common.page;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
import java.util.List;
/**
* 分页工具类
*
* @author xggz <yyimba@qq.com>
* @since 2021/6/4 11:50
*/
@UtilityClass
public class PageUtil<T> {
/**
* 转换PageHelper插件的分页数据
*
* @param pageInfo
* @param <T>
* @return
*/
public <T> PageVO<T> convertPageInfo(PageInfo<T> pageInfo) {
return BeanUtil.copyProperties(pageInfo, PageVO.class);
}
/**
* 转换PageHelper插件的分页数据
*
* @param list
* @param <T>
* @return
*/
public <T> PageVO<T> convertPageInfo(List<T> list) {
return BeanUtil.copyProperties(new PageInfo<T>(list), PageVO.class);
}
/**
* 复制分页数据
*
* @param sourcePage
* @param results
* @param <T>
* @return
*/
public <T> PageVO<T> copyPage(Object sourcePage, List<T> results) {
PageVO<T> targetPage = BeanUtil.copyProperties(sourcePage, PageVO.class);
targetPage.setList(results);
return targetPage;
}
/**
* 返回空白的分页对象
*
* @param pageNum
* @param pageSize
* @param dataClass
* @param <T>
* @return
*/
public <T> PageVO<T> emptyPage(Integer pageNum, Integer pageSize, Class<T> dataClass) {
PageVO page = new PageVO<>();
page.setPageNum(pageNum);
page.setPageSize(pageSize);
page.setSize(0);
page.setPages(0);
page.setTotal(0);
page.setHasNextPage(false);
page.setHasPreviousPage(false);
page.setList(new ArrayList());
return page;
}
/**
* 返回空白的分页对象
*
* @param pageDTO
* @param dataClass
* @param <T>
* @return
*/
public <T> PageVO<T> emptyPage(PageDTO pageDTO, Class<T> dataClass) {
return emptyPage(pageDTO.getPageNum(), pageDTO.getPageSize(), dataClass);
}
/**
* 使用PageHelper设置分页参数
*
* @param pageDTO
*/
public void startPage(PageDTO pageDTO) {
PageHelper.startPage(pageDTO.getPageNum(), pageDTO.getPageSize());
}
}

45
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/page/PageVO.java

@ -0,0 +1,45 @@
package cn.iocoder.yudao.framework.common.page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 分页结果
*
* @author xggz <yyimba@qq.com>
* @since 2021/6/4 10:53
*/
@Data
@ApiModel(value = "PageVO", description = "分页结果")
public class PageVO<T> implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("当前页")
private int pageNum;
@ApiModelProperty("每页的数量")
private int pageSize;
@ApiModelProperty("当前页的数量")
private int size;
@ApiModelProperty("总页数")
private int pages;
@ApiModelProperty("是否有前一页")
private boolean hasPreviousPage = false;
@ApiModelProperty("是否有后一页")
private boolean hasNextPage = false;
@ApiModelProperty("总记录数")
private long total;
@ApiModelProperty("结果集")
private List<T> list;
}

3
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserBaseVO.java

@ -43,4 +43,7 @@ public class CpUserBaseVO {
@ApiModelProperty(value = "企业邮件")
private String bizMail;
@ApiModelProperty(value = "工时")
private Integer workHour;
}

3
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserExcelVO.java

@ -47,4 +47,7 @@ public class CpUserExcelVO {
@ExcelProperty("企业邮件")
private String bizMail;
@ApiModelProperty(value = "工时")
private Integer workHour;
}

2
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserExportReqVO.java

@ -47,4 +47,6 @@ public class CpUserExportReqVO {
@ApiModelProperty(value = "企业邮件")
private String bizMail;
@ApiModelProperty(value = "工时")
private Integer workHour;
}

2
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/CpUser/vo/CpUserPageReqVO.java

@ -49,4 +49,6 @@ public class CpUserPageReqVO extends PageParam {
@ApiModelProperty(value = "企业邮件")
private String bizMail;
@ApiModelProperty(value = "工时")
private Integer workHour;
}

6
zsw-farm/zsw-farm-impl/pom.xml

@ -59,6 +59,12 @@
<version>1.6.2-snapshot</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>zsw-spi</artifactId>
<version>1.6.2-snapshot</version>
<scope>compile</scope>
</dependency>
</dependencies>

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java

@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.farm.controller.admin.project;
import cn.iocoder.yudao.framework.common.page.PageVO;
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO;
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO;
import com.zsw.base.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -108,7 +110,7 @@ public class ProjectController {
@ApiOperation("小程序项目列表")
@PostMapping("/findProjectList")
public List<ProjectListDTO> findProjectList(ProjectPageDTO pageDTO){
public R<PageVO<ProjectListDTO>> findProjectList(@RequestBody ProjectPageDTO pageDTO){
return projectService.findProjectList(pageDTO);
}

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectListDTO.java

@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO;
import lombok.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Data
@ -18,5 +20,7 @@ public class ProjectListDTO extends ProjectDO {
String taskName;
Date finishTime;
}

26
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskMsgDTO.java

@ -0,0 +1,26 @@
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;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TaskMsgDTO extends TaskDO {
List<String> areaName;
List<String> executorName;
String taskName;
Date finishTime;
}

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java

@ -16,8 +16,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
public class TaskBaseVO {
private Integer projectId;
private Integer cropId;
private Long projectId;
private Long cropId;
private Integer cropNum;
private Long taskCateId;

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskExcelVO.java

@ -19,9 +19,9 @@ public class TaskExcelVO {
private Long id;
@ExcelProperty("")
private Integer projectId;
private Long projectId;
@ExcelProperty("")
private Integer cropId;
private Long cropId;
@ExcelProperty("")
private Integer cropNum;

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskExportReqVO.java

@ -13,8 +13,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
public class TaskExportReqVO {
private Integer projectId;
private Integer cropId;
private Long projectId;
private Long cropId;
private Integer cropNum;
private Long taskCateId;

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageReqVO.java

@ -15,8 +15,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true)
public class TaskPageReqVO extends PageParam {
private Integer projectId;
private Integer cropId;
private Long projectId;
private Long cropId;
private Integer cropNum;
private Long taskCateId;

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageSearchReqVO.java

@ -20,8 +20,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ToString(callSuper = true)
public class TaskPageSearchReqVO extends PageParam {
private Integer projectId;
private Integer cropId;
private Long projectId;
private Long cropId;
private Integer cropNum;
private Long taskCateId;

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/task/TaskDO.java

@ -27,9 +27,9 @@ public class TaskDO extends BaseDO {
private Long id;
@ApiModelProperty("项目id")
private Integer projectId;
private Long projectId;
@ApiModelProperty("作物id")
private Integer cropId;
private Long cropId;
@ApiModelProperty("作物数量")
private Integer cropNum;

6
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java

@ -50,10 +50,4 @@ public interface ProjectMapper extends BaseMapperX<ProjectDO> {
List<ProjectDO> getProjectSearchPage(ProjectSearchPageReqVO reqVO);
default List<ProjectDO> findProjectList(ProjectPageDTO pageDTO){
return selectList(new LambdaQueryWrapperX<ProjectDO>()
.eqIfPresent(ProjectDO::getState, pageDTO.getState())
.orderByDesc(ProjectDO::getId));
}
}

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectService.java

@ -3,11 +3,13 @@ package cn.iocoder.yudao.module.farm.service.project;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.page.PageVO;
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.project.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.zsw.base.R;
/**
* 农场项目 Service 接口
@ -79,6 +81,6 @@ public interface ProjectService {
/**
* @Description 小程序项目列表
**/
List<ProjectListDTO> findProjectList(ProjectPageDTO pageDTO);
R<PageVO<ProjectListDTO>> findProjectList(ProjectPageDTO pageDTO);
}

175
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java

@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.farm.service.project;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.page.PageUtil;
import cn.iocoder.yudao.framework.common.page.PageVO;
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.TaskMsgDTO;
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.farm.dal.dataobject.taskCate.TaskCateDO;
@ -17,8 +20,12 @@ 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.JSONObject;
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.zsw.base.R;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -55,6 +62,8 @@ public class ProjectServiceImpl implements ProjectService {
private AreaMapper areaMapper;
@Resource
private TaskCateMapper taskCateMapper;
@Resource
private TaskService taskService;
@Override
public Long createProject(ProjectCreateReqVO createReqVO) {
@ -119,93 +128,123 @@ public class ProjectServiceImpl implements ProjectService {
}
@Override
public List<ProjectListDTO> findProjectList(ProjectPageDTO pageDTO){
List<ProjectDO> list = projectMapper.findProjectList(pageDTO);
public R<PageVO<ProjectListDTO>> findProjectList(ProjectPageDTO pageDTO){
PageUtil.startPage(pageDTO);
LambdaQueryWrapper<ProjectDO> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(ProjectDO::getState, pageDTO.getState());
List<ProjectDO> list = projectMapper.selectList(queryWrapper);
if (ObjectUtil.isEmpty(list)){
return R.success(PageUtil.emptyPage(pageDTO, ProjectListDTO.class));
}
// List<ProjectDO> list = projectMapper.selectList(Wrappers.<ProjectDO>lambdaQuery()
// .eq(ProjectDO::getState, pageDTO.getState())
// .last("limit " + (pageDTO.getPageNum() -1) * pageDTO.getPageSize() +"," + pageDTO.getPageSize()));
List<Long> idList = list.stream().map(ProjectDO::getId).collect(Collectors.toList());
List<ProjectListDTO> ProjectListDTOList = BeanUtil.copyToList(list, ProjectListDTO.class);
//任务完成的
List<TaskDO> taskList = taskMapper.selectList(Wrappers.<TaskDO>lambdaQuery().in(TaskDO::getProjectId, idList)
.eq(TaskDO::getStatus, TaskStatus.COMPLETE.getCode()));
/* //项目没有任务 跳过
if (ObjectUtil.isNotEmpty(taskList)){
List<TaskMsgDTO> taskMsgDTOList = taskService.getTaskMsg(taskList);
Set<Long> personSet = new HashSet<>();
Set<Long> areaSet = new HashSet<>();
Set<Long> taskCateSet = new HashSet<>();
Set<Long> personSet = new HashSet<>();
Set<Long> areaSet = new HashSet<>();
Set<Long> taskCateSet = new HashSet<>();
taskList.stream().forEach(item ->{
//项目参与人
item.getExecutorPerson().forEach(p ->{
if (p != null) {
personSet.add(Long.valueOf( p.toString()));
taskList.stream().forEach(item ->{
//项目参与人
item.getExecutorPerson().forEach(p ->{
if (p != null) {
personSet.add(Long.valueOf( p.toString()));
}
});
//项目区域
if (item.getAreas() != null){
item.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(item.getTaskCateId());
});
//项目区域
if (item.getAreas() != null){
item.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(item.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));
//拼接 姓名/区域/任务名
List<ProjectListDTO> dto = BeanUtil.copyToList(list, ProjectListDTO.class);
for (ProjectListDTO projectListDTO : dto) {
for (TaskDO taskDO : taskList) {
if (Long.valueOf(taskDO.getProjectId()).equals(projectListDTO.getId())){
//任务名
for (TaskCateDO taskCateDO : taskCateDOList) {
if (taskCateDO.getId().equals(taskDO.getTaskCateId())){
projectListDTO.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());
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 (ProjectListDTO projectListDTO : ProjectListDTOList) {
for (TaskDO taskDO : taskList) {
if (Long.valueOf(taskDO.getProjectId()).equals(projectListDTO.getId())){
//完成时间
projectListDTO.setFinishTime(taskDO.getUpdateTime());
//任务名
for (TaskCateDO taskCateDO : taskCateDOList) {
if (taskCateDO.getId().equals(taskDO.getTaskCateId())){
projectListDTO.setTaskName(taskCateDO.getName());
}
}
projectListDTO.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());
//执行人
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());
}
}
projectListDTO.setExecutorName(personNameList);
}
if (ObjectUtil.isNotEmpty(areaName)){
areaNameList.add(areaName.toString());
//任务区域
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());
}
projectListDTO.setAreaName(areaNameList);
}
projectListDTO.setAreaName(areaNameList);
}
}
}
}*/
if (ObjectUtil.isNotEmpty(taskList)) {
List<TaskMsgDTO> taskMsgDTOList = taskService.getTaskMsg(taskList);
Map<Long, List<TaskMsgDTO>> taskMsgMap = taskMsgDTOList.stream().collect(Collectors.groupingBy(TaskMsgDTO::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());
}
}
}
return dto;
PageVO<ProjectListDTO> returnList = PageUtil.convertPageInfo(ProjectListDTOList);
return R.success(returnList);
}
}

10
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.farm.service.task;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskMsgDTO;
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;
@ -75,4 +77,12 @@ public interface TaskService {
*/
List<TaskDO> getTaskList(TaskExportReqVO exportReqVO);
/**
* @Description 根据taskDOList 获取每个taskDO的 执行人区域任务名
* @param taskDOList 任务List
* @return 返回每个任务的执行人区域任务名
**/
public List<TaskMsgDTO> getTaskMsg(List<TaskDO> taskDOList);
}

101
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

@ -1,5 +1,18 @@
package cn.iocoder.yudao.module.farm.service.task;
import cn.hutool.core.bean.BeanUtil;
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.module.farm.dal.dataobject.area.AreaDO;
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.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 com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -26,6 +39,12 @@ public class TaskServiceImpl implements TaskService {
@Resource
private TaskMapper taskMapper;
@Resource
private CpUserMapper cpUserMapper;
@Resource
private AreaMapper areaMapper;
@Resource
private TaskCateMapper taskCateMapper;
@Override
public Long createTask(TaskCreateReqVO createReqVO) {
@ -90,4 +109,86 @@ 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;
}
}

Loading…
Cancel
Save