From dc52c3058185ab2ea8fd112fb527d01b95611b1f Mon Sep 17 00:00:00 2001 From: zhanyunjiu <787952492@qq.com> Date: Thu, 14 Jul 2022 18:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=B5=81=E7=A8=8B=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/farm/enums/ErrorCodeConstants.java | 13 +++-- .../admin/project/vo/ProjectBaseVO.java | 2 +- .../admin/project/vo/ProjectExcelVO.java | 3 +- .../admin/project/vo/ProjectExportReqVO.java | 2 +- .../admin/project/vo/ProjectPageReqVO.java | 3 +- .../project/vo/ProjectSearchPageReqVO.java | 3 +- .../admin/resource/vo/ResourceBaseVO.java | 3 ++ .../admin/resource/vo/ResourceExcelVO.java | 3 ++ .../resource/vo/ResourceExportReqVO.java | 3 ++ .../admin/resource/vo/ResourcePageReqVO.java | 3 ++ .../admin/task/vo/TaskPageReqVO.java | 15 ++++-- .../dal/dataobject/project/ProjectDO.java | 5 +- .../dal/dataobject/resource/ResourceDO.java | 3 ++ .../module/farm/service/area/AreaService.java | 21 +++++--- .../farm/service/area/AreaServiceImpl.java | 48 +++++++++++++++++ .../service/discuss/DiscussServiceImpl.java | 8 ++- .../service/project/ProjectServiceImpl.java | 51 +++++++++++++------ .../module/farm/service/task/TaskService.java | 26 +++++++--- .../farm/service/task/TaskServiceImpl.java | 15 ++++-- 19 files changed, 182 insertions(+), 48 deletions(-) diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java index fb01ab38..dad78503 100644 --- a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java +++ b/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 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_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 TASK_COMPLETE_CHANGE_FAIL = new ErrorCode(100000727, "任务更改失败, 已完成的任务不能修改任何信息"); + + ErrorCode TASK_STARTED_FAIL = new ErrorCode(100000728, "任务更改失败, 所选资源已被占用"); } + diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java index 48bad4a2..771e3f4f 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectBaseVO.java +++ b/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; @ApiModelProperty("父级区域") - private JSONArray areas; + private List areas; @ApiModelProperty("种植面积") private Double plantArea; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExcelVO.java index ee43775b..75a79ce2 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExcelVO.java +++ b/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 java.util.Date; +import java.util.List; /** * 农场项目 Excel VO @@ -28,7 +29,7 @@ public class ProjectExcelVO { @ExcelProperty("") private ProjectStateEnum state; - private JSONArray areas; + private List areas; @ApiModelProperty("种植面积") private Double plantArea; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExportReqVO.java index a1fbd77c..37e59368 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectExportReqVO.java +++ b/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 JSONArray areas; + private List areas; private Long cropId; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java index f674dd9e..d5309c91 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java +++ b/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 java.util.Date; +import java.util.List; 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 JSONArray areas; + private List areas; @ApiModelProperty("种植面积") private Double plantArea; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectSearchPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectSearchPageReqVO.java index 7125f406..61133b3e 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectSearchPageReqVO.java +++ b/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.util.Date; +import java.util.List; 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 JSONArray areas; + private List areas; @ApiModelProperty("种植面积") private Double plantArea; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceBaseVO.java index 4f0ca4f5..bbe81af5 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceBaseVO.java +++ b/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; + @ApiModelProperty("是否占用") + private Boolean occupied; + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExcelVO.java index 58414ca2..89ac7434 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExcelVO.java +++ b/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; + @ApiModelProperty("是否占用") + private Boolean occupied; + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExportReqVO.java index b9759501..2c28b73a 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourceExportReqVO.java +++ b/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; + @ApiModelProperty("是否占用") + private Boolean occupied; + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourcePageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourcePageReqVO.java index 6a77f4d9..e29b9fd7 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/resource/vo/ResourcePageReqVO.java +++ b/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; + @ApiModelProperty("是否占用") + private Boolean occupied; + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageReqVO.java index 86f27087..1c02ce9f 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskPageReqVO.java +++ b/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; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.module.farm.enums.TaskMemberEnum; import cn.iocoder.yudao.module.farm.enums.TaskStatus; import com.alibaba.fastjson.JSONArray; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; 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; @ApiModel("管理后台 - 农场项目分页 Request VO") @@ -67,7 +72,7 @@ public class TaskPageReqVO extends PageParam { private Boolean pretendDelete = false; - private TaskStatus taskStatus; + private TaskStatus status; @ApiModelProperty("参与状态 我参与 我创建 我负责") private TaskMemberEnum memberEnum; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java index 4e83e803..507bbc53 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/project/ProjectDO.java +++ b/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.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.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; @@ -54,8 +55,8 @@ public class ProjectDO extends BaseDO { private ProjectStateEnum state; @ApiModelProperty("父级区域") - @TableField(typeHandler = JacksonTypeHandler.class) - private JSONArray areas; + @TableField(typeHandler = ListIntToListLongTypeHandler.class) + private List areas; @ApiModelProperty("种植面积") private Double plantArea; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/resource/ResourceDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/resource/ResourceDO.java index 4be6b5e3..00ac8a99 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/resource/ResourceDO.java +++ b/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("数量") private Integer number; + + @ApiModelProperty("是否占用") + private Boolean occupied; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java index bc0cb7da..289a8c93 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaService.java +++ b/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; -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 com.alibaba.fastjson.JSONArray; -import com.google.gson.JsonArray; +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.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 接口 @@ -74,4 +77,10 @@ public interface AreaService { **/ List findAreaName(List areaList, List areaArray); + + /** + * 检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用 + */ + void checkAreaOccupied(); + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java index 1c18fd67..5cc6b672 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java +++ b/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; +import cn.hutool.core.util.ObjectUtil; 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.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.dal.dataobject.area.AreaDO; 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.validation.annotation.Validated; @@ -15,6 +19,7 @@ import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; 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.module.farm.enums.ErrorCodeConstants.AREA_NOT_EXISTS; @@ -26,6 +31,7 @@ import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.AREA_NOT_EXI */ @Service @Validated +@Slf4j public class AreaServiceImpl implements AreaService { @Resource @@ -109,4 +115,46 @@ public class AreaServiceImpl implements AreaService { return areaNameList; } + /** + * 检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用 + */ + public void checkAreaOccupied(){ + List allList = areaMapper.selectList(Wrappers.lambdaQuery().eq(AreaDO::getPretendDelete, false)); + //需要更改为占用的区域 + List updateList = new ArrayList<>(); + //一级 + List firstList = allList.stream().filter(item -> item.getParentId().equals(0l)).collect(Collectors.toList()); + for (AreaDO first : firstList) { + //二级区域 + List secondList = allList.stream().filter(item -> item.getParentId().equals(first.getId())).collect(Collectors.toList()); + if (ObjectUtil.isNotEmpty(secondList)){ + //二级区域 已占用 + List 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 thirdList = allList.stream().filter(item -> item.getParentId().equals(second.getId())).collect(Collectors.toList()); + if (ObjectUtils.isNotEmpty(thirdList)){ + //三级区域已占用 + List 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); + }); + + } + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java index e85398dc..7e0cd2ae 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/discuss/DiscussServiceImpl.java +++ b/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.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.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; @@ -87,6 +88,8 @@ public class DiscussServiceImpl implements DiscussService { private TaskCateMapper taskCateMapper; @Resource private CropMapper cropMapper; + @Resource + private TaskService taskService; @DubboReference private OpenErpService openErpService; @@ -235,7 +238,7 @@ public class DiscussServiceImpl implements DiscussService { } LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); 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); } } @@ -318,6 +321,9 @@ public class DiscussServiceImpl implements DiscussService { taskDO.setStatus(TaskStatus.COMPLETE); taskMapper.updateById(taskDO); + //返还资源 + taskService.checkTaskResourceNumber(taskDO); + } } 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 701692fb..b8c266d9 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 @@ -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.task.dto.TaskAssemblyDTO; 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.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.task.TaskMapper; import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; 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.system.dal.dataobject.CpUser.CpUserDO; import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; @@ -56,6 +59,10 @@ public class ProjectServiceImpl implements ProjectService { private CpUserMapper cpUserMapper; @Resource private TaskService taskService; + @Resource + private AreaService areaService; + @Resource + private AreaMapper areaMapper; @Override public Long createProject(ProjectCreateReqVO createReqVO) { @@ -77,7 +84,8 @@ public class ProjectServiceImpl implements ProjectService { this.checkProjectStatus(updateReqVO); //检查项目新增、修改时的区域 是否能够使用 this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); - //项目修改完成时,,项目下所有任务未完成不能更改项目状态为完成 + //项目修改完成时,,项目下有一个以上任务未完成,改项就不能更改为完成 + //如果项目可以更改成完成状态 释放占用区域 if (updateReqVO.getState().equals(ProjectStateEnum.FINISH)){ this.checkProjectTaskFinish(updateReqVO); } @@ -230,6 +238,16 @@ public class ProjectServiceImpl implements ProjectService { if (ObjectUtil.isNotEmpty(taskList)){ throw exception(PROJECT_TASK_NOT_COMPLETE); } + + //释放区域占用 + List 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){ if (projectDO.getState().equals(ProjectStateEnum.STARTING)){ - List areaIdList = projectDO.getAreas().toJavaList(Long.class); - for (Long aLong : areaIdList) { - LambdaQueryWrapperX queryWrapperX = new LambdaQueryWrapperX<>(); - queryWrapperX.eq(ProjectDO::getState, ProjectStateEnum.STARTING) - .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); - } + //检查项目所选区域是否占用 + List areaList = areaService.getAreaList(projectDO.getAreas()); + List occupiedList = areaList.stream().filter(item -> item.getOccupied()).collect(Collectors.toList()); + if (ObjectUtil.isNotEmpty(occupiedList)){ + 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 (project.getState().equals(ProjectStateEnum.STARTING)){ if (project.getCropId() != updateProject.getCropId()){ - //项目更改失败, 进行中的任务不可修改作物 + //项目更改失败, 进行中的项目不可修改作物 throw exception(PROJECT_STARTING_CANT_CHANGE_CROP); } if (!project.getAreas().equals(updateProject.getAreas())){ - //项目更改失败, 进行中的任务不可修改区域 + //项目更改失败, 进行中的项目不可修改区域 throw exception(PROJECT_STARTING_CANT_CHANGE_AREA); } } }else{ - //项目更改失败, 计划中的任务只能更改成进行中 + //项目更改失败, 计划中的项目只能更改成进行中 if (project.getState().equals(ProjectStateEnum.PLAN)){ if (!updateProject.getState().equals(ProjectStateEnum.STARTING)){ throw exception(PROJECT_PLAN_TO_STARTING); } } - //项目更改失败, 进行中的任务只能更改成已完成 + //项目更改失败, 进行中的项目只能更改成已完成 if (project.getState().equals(ProjectStateEnum.STARTING)){ if (!updateProject.getState().equals(ProjectStateEnum.FINISH)){ throw exception(PROJECT_STARTING_TO_FINISH); 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 0b09fc2d..a78fa6e4 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 @@ -1,15 +1,23 @@ 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.*; -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.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 javax.validation.Valid; +import java.util.Collection; +import java.util.List; +import java.util.Map; + /** * 农场项目 Service 接口 * @@ -99,4 +107,10 @@ public interface TaskService { **/ List> whatDayHaveTask(Long projectId); + + /** + * 修改任务已完成 返还资源 + */ + void checkTaskResourceNumber(TaskDO taskDO); + } 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 cbcacce9..2844aa8c 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 @@ -174,7 +174,7 @@ public class TaskServiceImpl implements TaskService { .eqIfPresent(TaskDO::getWeight, pageReqVO.getWeight()) .betweenIfPresent(TaskDO::getCreateTime, pageReqVO.getBeginCreateTime(), pageReqVO.getEndCreateTime()) .eqIfPresent(TaskDO::getPretendDelete, pageReqVO.getPretendDelete()) - .eqIfPresent(TaskDO::getStatus, pageReqVO.getTaskStatus()) + .eqIfPresent(TaskDO::getStatus, pageReqVO.getStatus()) .orderByDesc(TaskDO::getId); PageResult pageResult = taskMapper.selectPage(pageReqVO, queryWrapperX); @@ -192,7 +192,7 @@ public class TaskServiceImpl implements TaskService { public PageResult getAdminTaskPage(TaskPageReqVO pageReqVO){ PageResult taskPage = taskMapper.selectPage(pageReqVO); Map map = this.taskAssemble(taskPage.getList()); - List list = new ArrayList<>(map.values()); + List list = new ArrayList<>(map.values()).stream().sorted(Comparator.comparing(TaskAssemblyDTO::getId).reversed()).collect(Collectors.toList()); PageResult page = new PageResult<>(); page.setList(list); page.setTotal(taskPage.getTotal()); @@ -485,12 +485,19 @@ public class TaskServiceImpl implements TaskService { ResourceDO resourceDO = resourceMapper.selectById(resourceDTO.getResourceId().get(1)); //更改成进行中 if (taskDO.getStatus().equals(TaskStatus.STARTED)){ + if (resourceDO.getOccupied()){ + throw exception(TASK_STARTED_FAIL); + } resourceDO.setNumber(resourceDO.getNumber() - resourceDTO.getNum()); + if (resourceDO.getSolo()){ + resourceDO.setOccupied(true); + } } //更改成已完成 if (taskDO.getStatus().equals(TaskStatus.COMPLETE)){ if (resourceDO.getSolo()){ resourceDO.setNumber(resourceDO.getNumber() + resourceDTO.getNum()); + resourceDO.setOccupied(false); } } resourceMapper.updateById(resourceDO); @@ -513,7 +520,9 @@ public class TaskServiceImpl implements TaskService { public void checkTaskStatus(TaskUpdateReqVO updateVO){ TaskDO task = taskMapper.selectById(updateVO.getId()); if (updateVO.getStatus().equals(task.getStatus())) { - + if (task.getStatus().equals(TaskStatus.COMPLETE)){ + throw exception(TASK_COMPLETE_CHANGE_FAIL); + } }else{ //任务更改失败, 计划中或准备中的任务只能更改为开始 if (task.getStatus().equals(TaskStatus.PLAN) || task.getStatus().equals(TaskStatus.READY)){