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 7b6d010c..895c85dd 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 @@ -29,5 +29,9 @@ public interface ErrorCodeConstants{ ErrorCode LOG_MSG_NOT_EXISTS = new ErrorCode(1000007012, "农场日志信息不存在"); + ErrorCode PROJECT_TASK_NOT_COMPLETE = new ErrorCode(1000007013, "项目状态更新失败,项目下还有未完成的任务"); + + + ErrorCode PROJECT_AREA_HAS_OCCUPIED = new ErrorCode(1000007014, "项目更新失败,所选区域已被其他进行中项目占用"); } diff --git a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ProjectStateEnum.java b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ProjectStateEnum.java index 00609295..0b0d3a13 100644 --- a/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ProjectStateEnum.java +++ b/zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ProjectStateEnum.java @@ -8,8 +8,8 @@ import lombok.Getter; public enum ProjectStateEnum { PLAN(0,"计划中"), - READY(1,"进行中"), - STARTED(2,"已完成"); + STARTING(1,"进行中"), + FINISH(2,"已完成"); @JsonValue @EnumValue 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 69a52c3f..e9afbfc1 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 @@ -61,7 +61,7 @@ ProjectBaseVO extends ProjectDO { private Integer weight; @ApiModelProperty("草稿") - private Boolean draft; + private Boolean draft = false; private Boolean pretendDelete; 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 8d0d0eb7..229b1131 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 @@ -1,12 +1,7 @@ package cn.iocoder.yudao.module.farm.service.project; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.date.LocalDateTimeUtil; -import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import cn.hutool.system.oshi.CpuInfo; import cn.iocoder.yudao.framework.common.page.PageUtil; import cn.iocoder.yudao.framework.common.page.PageVO; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -14,29 +9,16 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; 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.TaskAssemblyDTO; -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; -import cn.iocoder.yudao.module.farm.dal.mysql.area.AreaMapper; import cn.iocoder.yudao.module.farm.dal.mysql.task.TaskMapper; -import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; +import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; import cn.iocoder.yudao.module.farm.enums.TaskStatus; 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; -import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; -import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; -import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONPObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.github.pagehelper.PageInfo; -import com.google.gson.JsonArray; import com.zsw.base.R; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -80,6 +62,8 @@ public class ProjectServiceImpl implements ProjectService { @Override public Long createProject(ProjectCreateReqVO createReqVO) { + //检查项目新增、修改时的区域 是否能够使用 + this.checkProjectAreas(BeanUtil.copyProperties(createReqVO, ProjectDO.class)); // 插入 ProjectDO project = ProjectConvert.INSTANCE.convert(createReqVO); project.setDeptId(Objects.requireNonNull(SecurityFrameworkUtils.getLoginUser()).getDeptId()); @@ -90,8 +74,15 @@ public class ProjectServiceImpl implements ProjectService { @Override public void updateProject(ProjectUpdateReqVO updateReqVO) { + //检查项目新增、修改时的区域 是否能够使用 + this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); // 校验存在 this.validateProjectExists(updateReqVO.getId()); + //项目修改完成时,,项目下所有任务未完成不能更改项目状态为完成 + if (updateReqVO.getState().equals(ProjectStateEnum.FINISH)){ + this.checkProjectTaskFinish(updateReqVO); + } + // 更新 ProjectDO updateObj = ProjectConvert.INSTANCE.convert(updateReqVO); projectMapper.updateById(updateObj); @@ -224,4 +215,39 @@ public class ProjectServiceImpl implements ProjectService { return R.success(returnList); } + /** + * 检查项目下所有任务是否完成 + */ + public void checkProjectTaskFinish(ProjectUpdateReqVO updateReqVO){ + List taskList = taskMapper.selectList(Wrappers.lambdaQuery() + .eq(TaskDO::getProjectId, updateReqVO.getId()) + .eq(TaskDO::getPretendDelete, false) + .eq(TaskDO::getDraft, false) + .ne(TaskDO::getStatus, TaskStatus.COMPLETE) + ); + if (ObjectUtil.isNotEmpty(taskList)){ + throw exception(PROJECT_TASK_NOT_COMPLETE); + } + } + + /** + * 检查项目新增、修改时的区域 是否能够使用 + */ + public void checkProjectAreas(ProjectDO projectDO){ + if (!projectDO.getDraft() && 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()) + .apply("JSON_CONTAINS(areas, '"+ aLong +"')"); + Long count = projectMapper.selectCount(queryWrapperX); + if (count > 0){ + throw exception(PROJECT_AREA_HAS_OCCUPIED); + } + } + + } + } + }