Browse Source

业务流程调整

zyh
zhanyunjiu 3 years ago
parent
commit
dc52c30581
  1. 13
      zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java
  2. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java
  3. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExcelVO.java
  4. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExportReqVO.java
  5. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java
  6. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectSearchPageReqVO.java
  7. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceBaseVO.java
  8. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExcelVO.java
  9. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExportReqVO.java
  10. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourcePageReqVO.java
  11. 15
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageReqVO.java
  12. 5
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java
  13. 3
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/resource/ResourceDO.java
  14. 21
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java
  15. 48
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java
  16. 8
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java
  17. 49
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java
  18. 26
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskService.java
  19. 15
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

13
zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java

@ -46,16 +46,21 @@ public interface ErrorCodeConstants{
ErrorCode TASK_WAS_STARTED = new ErrorCode(100000720, "任务更改失败, 已开始的任务不能更改为计划中或准备中"); ErrorCode TASK_WAS_STARTED = new ErrorCode(100000720, "任务更改失败, 已开始的任务不能更改为计划中或准备中");
ErrorCode PROJECT_PLAN_TO_STARTING = new ErrorCode(100000721, "项目更改失败, 计划中的任务只能更改成进行中"); ErrorCode PROJECT_PLAN_TO_STARTING = new ErrorCode(100000721, "项目更改失败, 计划中的项目只能更改成进行中");
ErrorCode PROJECT_STARTING_TO_FINISH = new ErrorCode(100000722, "项目更改失败, 进行中的任务只能更改成已完成"); ErrorCode PROJECT_STARTING_TO_FINISH = new ErrorCode(100000722, "项目更改失败, 进行中的项目只能更改成已完成");
ErrorCode PROJECT_FINISH = new ErrorCode(100000723, "项目更改失败, 已完成项目不可更改"); ErrorCode PROJECT_FINISH = new ErrorCode(100000723, "项目更改失败, 已完成项目不可更改");
ErrorCode PROJECT_STARTING_CANT_CHANGE_CROP = new ErrorCode(100000724, "项目更改失败, 进行中的任务不可修改作物"); ErrorCode PROJECT_STARTING_CANT_CHANGE_CROP = new ErrorCode(100000724, "项目更改失败, 进行中的项目不可修改作物");
ErrorCode PROJECT_STARTING_CANT_CHANGE_AREA = new ErrorCode(100000725, "项目更改失败, 进行中的任务不可修改区域"); ErrorCode PROJECT_STARTING_CANT_CHANGE_AREA = new ErrorCode(100000725, "项目更改失败, 进行中的项目不可修改区域");
ErrorCode DISCUSS_NO_PERMISSION = new ErrorCode(100000726, "活动操作失败, 只有任务创建人或负责人才可以操作"); ErrorCode DISCUSS_NO_PERMISSION = new ErrorCode(100000726, "活动操作失败, 只有任务创建人或负责人才可以操作");
ErrorCode TASK_COMPLETE_CHANGE_FAIL = new ErrorCode(100000727, "任务更改失败, 已完成的任务不能修改任何信息");
ErrorCode TASK_STARTED_FAIL = new ErrorCode(100000728, "任务更改失败, 所选资源已被占用");
} }

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java

@ -40,7 +40,7 @@ ProjectBaseVO extends ProjectDO {
private ProjectStateEnum state; private ProjectStateEnum state;
@ApiModelProperty("父级区域") @ApiModelProperty("父级区域")
private JSONArray areas; private List<Long> areas;
@ApiModelProperty("种植面积") @ApiModelProperty("种植面积")
private Double plantArea; private Double plantArea;

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExcelVO.java

@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* 农场项目 Excel VO * 农场项目 Excel VO
@ -28,7 +29,7 @@ public class ProjectExcelVO {
@ExcelProperty("") @ExcelProperty("")
private ProjectStateEnum state; private ProjectStateEnum state;
private JSONArray areas; private List<Long> areas;
@ApiModelProperty("种植面积") @ApiModelProperty("种植面积")
private Double plantArea; private Double plantArea;

2
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExportReqVO.java

@ -23,7 +23,7 @@ public class ProjectExportReqVO {
private ProjectStateEnum state; private ProjectStateEnum state;
private JSONArray areas; private List<Long> areas;
private Long cropId; private Long cropId;

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java

@ -11,6 +11,7 @@ import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -28,7 +29,7 @@ public class ProjectPageReqVO extends PageParam {
private ProjectStateEnum state; private ProjectStateEnum state;
private JSONArray areas; private List<Long> areas;
@ApiModelProperty("种植面积") @ApiModelProperty("种植面积")
private Double plantArea; private Double plantArea;

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectSearchPageReqVO.java

@ -12,6 +12,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ -29,7 +30,7 @@ public class ProjectSearchPageReqVO extends PageParam {
private ProjectStateEnum state; private ProjectStateEnum state;
private JSONArray areas; private List<Long> areas;
@ApiModelProperty("种植面积") @ApiModelProperty("种植面积")
private Double plantArea; private Double plantArea;

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceBaseVO.java

@ -50,4 +50,7 @@ public class ResourceBaseVO {
private Integer number; private Integer number;
@ApiModelProperty("是否占用")
private Boolean occupied;
} }

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExcelVO.java

@ -51,4 +51,7 @@ public class ResourceExcelVO {
private Integer number; private Integer number;
@ApiModelProperty("是否占用")
private Boolean occupied;
} }

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExportReqVO.java

@ -62,4 +62,7 @@ public class ResourceExportReqVO {
private Integer number; private Integer number;
@ApiModelProperty("是否占用")
private Boolean occupied;
} }

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourcePageReqVO.java

@ -67,4 +67,7 @@ public class ResourcePageReqVO extends PageParam {
private Integer number; private Integer number;
@ApiModelProperty("是否占用")
private Boolean occupied;
} }

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

@ -1,14 +1,19 @@
package cn.iocoder.yudao.module.farm.controller.admin.task.vo; package cn.iocoder.yudao.module.farm.controller.admin.task.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.module.farm.enums.TaskMemberEnum; import cn.iocoder.yudao.module.farm.enums.TaskMemberEnum;
import cn.iocoder.yudao.module.farm.enums.TaskStatus; import cn.iocoder.yudao.module.farm.enums.TaskStatus;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import lombok.*; import io.swagger.annotations.ApiModel;
import java.util.*; import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.*; import lombok.Data;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("管理后台 - 农场项目分页 Request VO") @ApiModel("管理后台 - 农场项目分页 Request VO")
@ -67,7 +72,7 @@ public class TaskPageReqVO extends PageParam {
private Boolean pretendDelete = false; private Boolean pretendDelete = false;
private TaskStatus taskStatus; private TaskStatus status;
@ApiModelProperty("参与状态 我参与 我创建 我负责") @ApiModelProperty("参与状态 我参与 我创建 我负责")
private TaskMemberEnum memberEnum; private TaskMemberEnum memberEnum;

5
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.project;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.handler.ListIntToListLongTypeHandler;
import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum;
@ -54,8 +55,8 @@ public class ProjectDO extends BaseDO {
private ProjectStateEnum state; private ProjectStateEnum state;
@ApiModelProperty("父级区域") @ApiModelProperty("父级区域")
@TableField(typeHandler = JacksonTypeHandler.class) @TableField(typeHandler = ListIntToListLongTypeHandler.class)
private JSONArray areas; private List<Long> areas;
@ApiModelProperty("种植面积") @ApiModelProperty("种植面积")
private Double plantArea; private Double plantArea;

3
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/resource/ResourceDO.java

@ -77,4 +77,7 @@ public class ResourceDO extends BaseDO {
@ApiModelProperty("数量") @ApiModelProperty("数量")
private Integer number; private Integer number;
@ApiModelProperty("是否占用")
private Boolean occupied;
} }

21
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java

@ -1,12 +1,15 @@
package cn.iocoder.yudao.module.farm.service.area; package cn.iocoder.yudao.module.farm.service.area;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.farm.controller.admin.area.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.alibaba.fastjson.JSONArray; import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaCreateReqVO;
import com.google.gson.JsonArray; import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaExportReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaUpdateReqVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/** /**
* Service 接口 * Service 接口
@ -74,4 +77,10 @@ public interface AreaService {
**/ **/
List<String> findAreaName(List<AreaDO> areaList, List<Long> areaArray); List<String> findAreaName(List<AreaDO> areaList, List<Long> areaArray);
/**
* 检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用
*/
void checkAreaOccupied();
} }

48
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.farm.service.area; package cn.iocoder.yudao.module.farm.service.area;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaCreateReqVO; import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaCreateReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaExportReqVO; import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaExportReqVO;
@ -8,6 +9,9 @@ import cn.iocoder.yudao.module.farm.controller.admin.area.vo.AreaUpdateReqVO;
import cn.iocoder.yudao.module.farm.convert.area.AreaConvert; import cn.iocoder.yudao.module.farm.convert.area.AreaConvert;
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.mysql.area.AreaMapper; import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -15,6 +19,7 @@ import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.AREA_NOT_EXISTS; import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.AREA_NOT_EXISTS;
@ -26,6 +31,7 @@ import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.AREA_NOT_EXI
*/ */
@Service @Service
@Validated @Validated
@Slf4j
public class AreaServiceImpl implements AreaService { public class AreaServiceImpl implements AreaService {
@Resource @Resource
@ -109,4 +115,46 @@ public class AreaServiceImpl implements AreaService {
return areaNameList; return areaNameList;
} }
/**
* 检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用
*/
public void checkAreaOccupied(){
List<AreaDO> allList = areaMapper.selectList(Wrappers.<AreaDO>lambdaQuery().eq(AreaDO::getPretendDelete, false));
//需要更改为占用的区域
List<AreaDO> updateList = new ArrayList<>();
//一级
List<AreaDO> firstList = allList.stream().filter(item -> item.getParentId().equals(0l)).collect(Collectors.toList());
for (AreaDO first : firstList) {
//二级区域
List<AreaDO> secondList = allList.stream().filter(item -> item.getParentId().equals(first.getId())).collect(Collectors.toList());
if (ObjectUtil.isNotEmpty(secondList)){
//二级区域 已占用
List<AreaDO> secondOccupiedList = secondList.stream().filter(second -> second.getOccupied()).collect(Collectors.toList());
if (secondList.size() == secondOccupiedList.size()){
//如果相等 把一级区域变成已占用
updateList.add(first.setOccupied(true));
}else{
updateList.add(first.setOccupied(false));
}
for (AreaDO second : secondList) {
//三级区域
List<AreaDO> thirdList = allList.stream().filter(item -> item.getParentId().equals(second.getId())).collect(Collectors.toList());
if (ObjectUtils.isNotEmpty(thirdList)){
//三级区域已占用
List<AreaDO> thirdOccupiedList = thirdList.stream().filter(thi -> thi.getOccupied()).collect(Collectors.toList());
if (thirdList.size() == thirdOccupiedList.size()){
updateList.add(second.setOccupied(true));
}else{
updateList.add(second.setOccupied(false));
}
}
}
}
}
updateList.forEach(update ->{
areaMapper.updateById(update);
});
}
} }

8
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java

@ -33,6 +33,7 @@ import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper; import cn.iocoder.yudao.module.farm.dal.mysql.workHour.WorkHourMapper;
import cn.iocoder.yudao.module.farm.enums.TaskStatus; import cn.iocoder.yudao.module.farm.enums.TaskStatus;
import cn.iocoder.yudao.module.farm.service.area.AreaService; import cn.iocoder.yudao.module.farm.service.area.AreaService;
import cn.iocoder.yudao.module.farm.service.task.TaskService;
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.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper;
@ -87,6 +88,8 @@ public class DiscussServiceImpl implements DiscussService {
private TaskCateMapper taskCateMapper; private TaskCateMapper taskCateMapper;
@Resource @Resource
private CropMapper cropMapper; private CropMapper cropMapper;
@Resource
private TaskService taskService;
@DubboReference @DubboReference
private OpenErpService openErpService; private OpenErpService openErpService;
@ -235,7 +238,7 @@ public class DiscussServiceImpl implements DiscussService {
} }
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
CpUserDO cpUserDO = cpUserService.getByUserId(loginUser.getUsername()); CpUserDO cpUserDO = cpUserService.getByUserId(loginUser.getUsername());
if (taskDO.getMainPerson() != cpUserDO.getId() && !loginUser.getId().equals(taskDO.getCreator())){ if (taskDO.getMainPerson() != cpUserDO.getId() && !loginUser.getId().toString().equals(taskDO.getCreator())){
throw exception(DISCUSS_NO_PERMISSION); throw exception(DISCUSS_NO_PERMISSION);
} }
} }
@ -318,6 +321,9 @@ public class DiscussServiceImpl implements DiscussService {
taskDO.setStatus(TaskStatus.COMPLETE); taskDO.setStatus(TaskStatus.COMPLETE);
taskMapper.updateById(taskDO); taskMapper.updateById(taskDO);
//返还资源
taskService.checkTaskResourceNumber(taskDO);
} }
} }

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

@ -13,12 +13,15 @@ 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.controller.admin.project.vo.*;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO; import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO;
import cn.iocoder.yudao.module.farm.convert.project.ProjectConvert; import cn.iocoder.yudao.module.farm.convert.project.ProjectConvert;
import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO;
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.farm.dal.dataobject.task.TaskDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper; import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper; import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper;
import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum;
import cn.iocoder.yudao.module.farm.enums.TaskStatus; import cn.iocoder.yudao.module.farm.enums.TaskStatus;
import cn.iocoder.yudao.module.farm.service.area.AreaService;
import cn.iocoder.yudao.module.farm.service.task.TaskService; import cn.iocoder.yudao.module.farm.service.task.TaskService;
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.mysql.CpUser.CpUserMapper; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper;
@ -56,6 +59,10 @@ public class ProjectServiceImpl implements ProjectService {
private CpUserMapper cpUserMapper; private CpUserMapper cpUserMapper;
@Resource @Resource
private TaskService taskService; private TaskService taskService;
@Resource
private AreaService areaService;
@Resource
private AreaMapper areaMapper;
@Override @Override
public Long createProject(ProjectCreateReqVO createReqVO) { public Long createProject(ProjectCreateReqVO createReqVO) {
@ -77,7 +84,8 @@ public class ProjectServiceImpl implements ProjectService {
this.checkProjectStatus(updateReqVO); this.checkProjectStatus(updateReqVO);
//检查项目新增、修改时的区域 是否能够使用 //检查项目新增、修改时的区域 是否能够使用
this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class));
//项目修改完成时,,项目下所有任务未完成不能更改项目状态为完成 //项目修改完成时,,项目下有一个以上任务未完成,改项就不能更改为完成
//如果项目可以更改成完成状态 释放占用区域
if (updateReqVO.getState().equals(ProjectStateEnum.FINISH)){ if (updateReqVO.getState().equals(ProjectStateEnum.FINISH)){
this.checkProjectTaskFinish(updateReqVO); this.checkProjectTaskFinish(updateReqVO);
} }
@ -230,6 +238,16 @@ public class ProjectServiceImpl implements ProjectService {
if (ObjectUtil.isNotEmpty(taskList)){ if (ObjectUtil.isNotEmpty(taskList)){
throw exception(PROJECT_TASK_NOT_COMPLETE); throw exception(PROJECT_TASK_NOT_COMPLETE);
} }
//释放区域占用
List<AreaDO> areaList = areaService.getAreaList(updateReqVO.getAreas());
areaList.forEach(item -> {
item.setOccupied(false);
areaMapper.updateById(item);
}
);
//检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用
areaService.checkAreaOccupied();
} }
/** /**
@ -237,19 +255,20 @@ public class ProjectServiceImpl implements ProjectService {
*/ */
public void checkProjectAreas(ProjectDO projectDO){ public void checkProjectAreas(ProjectDO projectDO){
if (projectDO.getState().equals(ProjectStateEnum.STARTING)){ if (projectDO.getState().equals(ProjectStateEnum.STARTING)){
List<Long> areaIdList = projectDO.getAreas().toJavaList(Long.class); //检查项目所选区域是否占用
for (Long aLong : areaIdList) { List<AreaDO> areaList = areaService.getAreaList(projectDO.getAreas());
LambdaQueryWrapperX<ProjectDO> queryWrapperX = new LambdaQueryWrapperX<>(); List<AreaDO> occupiedList = areaList.stream().filter(item -> item.getOccupied()).collect(Collectors.toList());
queryWrapperX.eq(ProjectDO::getState, ProjectStateEnum.STARTING) if (ObjectUtil.isNotEmpty(occupiedList)){
.neIfPresent(ProjectDO::getId, projectDO.getId())
.eq(ProjectDO::getPretendDelete, false)
.apply("JSON_CONTAINS(areas, '"+ aLong +"')");
Long count = projectMapper.selectCount(queryWrapperX);
if (count > 0){
throw exception(PROJECT_AREA_HAS_OCCUPIED); throw exception(PROJECT_AREA_HAS_OCCUPIED);
} }
}
areaList.forEach(item ->{
item.setOccupied(true);
areaMapper.updateById(item);
});
//检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用
areaService.checkAreaOccupied();
} }
} }
@ -258,23 +277,23 @@ public class ProjectServiceImpl implements ProjectService {
if (updateProject.getState().equals(project.getState())){ if (updateProject.getState().equals(project.getState())){
if (project.getState().equals(ProjectStateEnum.STARTING)){ if (project.getState().equals(ProjectStateEnum.STARTING)){
if (project.getCropId() != updateProject.getCropId()){ if (project.getCropId() != updateProject.getCropId()){
//项目更改失败, 进行中的任务不可修改作物 //项目更改失败, 进行中的项目不可修改作物
throw exception(PROJECT_STARTING_CANT_CHANGE_CROP); throw exception(PROJECT_STARTING_CANT_CHANGE_CROP);
} }
if (!project.getAreas().equals(updateProject.getAreas())){ if (!project.getAreas().equals(updateProject.getAreas())){
//项目更改失败, 进行中的任务不可修改区域 //项目更改失败, 进行中的项目不可修改区域
throw exception(PROJECT_STARTING_CANT_CHANGE_AREA); throw exception(PROJECT_STARTING_CANT_CHANGE_AREA);
} }
} }
}else{ }else{
//项目更改失败, 计划中的任务只能更改成进行中 //项目更改失败, 计划中的项目只能更改成进行中
if (project.getState().equals(ProjectStateEnum.PLAN)){ if (project.getState().equals(ProjectStateEnum.PLAN)){
if (!updateProject.getState().equals(ProjectStateEnum.STARTING)){ if (!updateProject.getState().equals(ProjectStateEnum.STARTING)){
throw exception(PROJECT_PLAN_TO_STARTING); throw exception(PROJECT_PLAN_TO_STARTING);
} }
} }
//项目更改失败, 进行中的任务只能更改成已完成 //项目更改失败, 进行中的项目只能更改成已完成
if (project.getState().equals(ProjectStateEnum.STARTING)){ if (project.getState().equals(ProjectStateEnum.STARTING)){
if (!updateProject.getState().equals(ProjectStateEnum.FINISH)){ if (!updateProject.getState().equals(ProjectStateEnum.FINISH)){
throw exception(PROJECT_STARTING_TO_FINISH); throw exception(PROJECT_STARTING_TO_FINISH);

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

@ -1,15 +1,23 @@
package cn.iocoder.yudao.module.farm.service.task; 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.framework.common.page.PageVO;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.*;
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 cn.iocoder.yudao.framework.common.pojo.PageResult;
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.TaskPageDTO;
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskSummaryDTO;
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskCreateReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskExportReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskUpdateReqVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO;
import com.zsw.base.R; import com.zsw.base.R;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/** /**
* 农场项目 Service 接口 * 农场项目 Service 接口
* *
@ -99,4 +107,10 @@ public interface TaskService {
**/ **/
List<Map<String, String>> whatDayHaveTask(Long projectId); List<Map<String, String>> whatDayHaveTask(Long projectId);
/**
* 修改任务已完成 返还资源
*/
void checkTaskResourceNumber(TaskDO taskDO);
} }

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

@ -174,7 +174,7 @@ public class TaskServiceImpl implements TaskService {
.eqIfPresent(TaskDO::getWeight, pageReqVO.getWeight()) .eqIfPresent(TaskDO::getWeight, pageReqVO.getWeight())
.betweenIfPresent(TaskDO::getCreateTime, pageReqVO.getBeginCreateTime(), pageReqVO.getEndCreateTime()) .betweenIfPresent(TaskDO::getCreateTime, pageReqVO.getBeginCreateTime(), pageReqVO.getEndCreateTime())
.eqIfPresent(TaskDO::getPretendDelete, pageReqVO.getPretendDelete()) .eqIfPresent(TaskDO::getPretendDelete, pageReqVO.getPretendDelete())
.eqIfPresent(TaskDO::getStatus, pageReqVO.getTaskStatus()) .eqIfPresent(TaskDO::getStatus, pageReqVO.getStatus())
.orderByDesc(TaskDO::getId); .orderByDesc(TaskDO::getId);
PageResult<TaskDO> pageResult = taskMapper.selectPage(pageReqVO, queryWrapperX); PageResult<TaskDO> pageResult = taskMapper.selectPage(pageReqVO, queryWrapperX);
@ -192,7 +192,7 @@ public class TaskServiceImpl implements TaskService {
public PageResult<TaskAssemblyDTO> getAdminTaskPage(TaskPageReqVO pageReqVO){ public PageResult<TaskAssemblyDTO> getAdminTaskPage(TaskPageReqVO pageReqVO){
PageResult<TaskDO> taskPage = taskMapper.selectPage(pageReqVO); PageResult<TaskDO> taskPage = taskMapper.selectPage(pageReqVO);
Map<Long, TaskAssemblyDTO> map = this.taskAssemble(taskPage.getList()); Map<Long, TaskAssemblyDTO> map = this.taskAssemble(taskPage.getList());
List<TaskAssemblyDTO> list = new ArrayList<>(map.values()); List<TaskAssemblyDTO> list = new ArrayList<>(map.values()).stream().sorted(Comparator.comparing(TaskAssemblyDTO::getId).reversed()).collect(Collectors.toList());
PageResult<TaskAssemblyDTO> page = new PageResult<>(); PageResult<TaskAssemblyDTO> page = new PageResult<>();
page.setList(list); page.setList(list);
page.setTotal(taskPage.getTotal()); page.setTotal(taskPage.getTotal());
@ -485,12 +485,19 @@ public class TaskServiceImpl implements TaskService {
ResourceDO resourceDO = resourceMapper.selectById(resourceDTO.getResourceId().get(1)); ResourceDO resourceDO = resourceMapper.selectById(resourceDTO.getResourceId().get(1));
//更改成进行中 //更改成进行中
if (taskDO.getStatus().equals(TaskStatus.STARTED)){ if (taskDO.getStatus().equals(TaskStatus.STARTED)){
if (resourceDO.getOccupied()){
throw exception(TASK_STARTED_FAIL);
}
resourceDO.setNumber(resourceDO.getNumber() - resourceDTO.getNum()); resourceDO.setNumber(resourceDO.getNumber() - resourceDTO.getNum());
if (resourceDO.getSolo()){
resourceDO.setOccupied(true);
}
} }
//更改成已完成 //更改成已完成
if (taskDO.getStatus().equals(TaskStatus.COMPLETE)){ if (taskDO.getStatus().equals(TaskStatus.COMPLETE)){
if (resourceDO.getSolo()){ if (resourceDO.getSolo()){
resourceDO.setNumber(resourceDO.getNumber() + resourceDTO.getNum()); resourceDO.setNumber(resourceDO.getNumber() + resourceDTO.getNum());
resourceDO.setOccupied(false);
} }
} }
resourceMapper.updateById(resourceDO); resourceMapper.updateById(resourceDO);
@ -513,7 +520,9 @@ public class TaskServiceImpl implements TaskService {
public void checkTaskStatus(TaskUpdateReqVO updateVO){ public void checkTaskStatus(TaskUpdateReqVO updateVO){
TaskDO task = taskMapper.selectById(updateVO.getId()); TaskDO task = taskMapper.selectById(updateVO.getId());
if (updateVO.getStatus().equals(task.getStatus())) { if (updateVO.getStatus().equals(task.getStatus())) {
if (task.getStatus().equals(TaskStatus.COMPLETE)){
throw exception(TASK_COMPLETE_CHANGE_FAIL);
}
}else{ }else{
//任务更改失败, 计划中或准备中的任务只能更改为开始 //任务更改失败, 计划中或准备中的任务只能更改为开始
if (task.getStatus().equals(TaskStatus.PLAN) || task.getStatus().equals(TaskStatus.READY)){ if (task.getStatus().equals(TaskStatus.PLAN) || task.getStatus().equals(TaskStatus.READY)){

Loading…
Cancel
Save