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 5c51a36c..d812440f 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 @@ -43,4 +43,11 @@ public class ResourceBaseVO { private Boolean pretendDelete; + private String unit; + + 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 0b8c3d3c..6387ec97 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 @@ -44,4 +44,11 @@ public class ResourceExcelVO { private Boolean pretendDelete; + private String unit; + + 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 cac6bf47..7ffd730f 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 @@ -54,4 +54,11 @@ public class ResourceExportReqVO { private Boolean pretendDelete; + private String unit; + + 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 02368b50..7af3b1e0 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 @@ -56,4 +56,11 @@ public class ResourcePageReqVO extends PageParam { private Boolean pretendDelete = false; + private String unit; + + 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/TaskBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java index ce732b49..cdb3151b 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/vo/TaskBaseVO.java @@ -50,10 +50,10 @@ public class TaskBaseVO { private Integer weight; @ApiModelProperty("任务状态") - private TaskStatus status; + private TaskStatus status = TaskStatus.PLAN; @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/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 d52578d3..53b8d5e2 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 @@ -65,4 +65,13 @@ public class ResourceDO extends BaseDO { public Boolean getSolo() { return solo; } + + @ApiModelProperty("单位") + private String unit; + + @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/project/ProjectServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java index 229b1131..6bb756b5 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 @@ -74,10 +74,10 @@ public class ProjectServiceImpl implements ProjectService { @Override public void updateProject(ProjectUpdateReqVO updateReqVO) { - //检查项目新增、修改时的区域 是否能够使用 - this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); // 校验存在 this.validateProjectExists(updateReqVO.getId()); + //检查项目新增、修改时的区域 是否能够使用 + this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); //项目修改完成时,,项目下所有任务未完成不能更改项目状态为完成 if (updateReqVO.getState().equals(ProjectStateEnum.FINISH)){ this.checkProjectTaskFinish(updateReqVO); 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 7a23fe1f..83a615a7 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 @@ -99,6 +99,8 @@ public class TaskServiceImpl implements TaskService { @Override public Long createTask(TaskCreateReqVO createReqVO) { + //检查任务资源数量 + this.checkTaskResourceNumber(BeanUtil.copyProperties(createReqVO, TaskDO.class)); // 插入 TaskDO task = TaskConvert.INSTANCE.convert(createReqVO); taskMapper.insert(task); @@ -110,6 +112,8 @@ public class TaskServiceImpl implements TaskService { public void updateTask(TaskUpdateReqVO updateReqVO) { // 校验存在 this.validateTaskExists(updateReqVO.getId()); + //检查任务资源数量 + this.checkTaskResourceNumber(BeanUtil.copyProperties(updateReqVO, TaskDO.class)); // 更新 TaskDO updateObj = TaskConvert.INSTANCE.convert(updateReqVO); taskMapper.updateById(updateObj); @@ -472,6 +476,38 @@ public class TaskServiceImpl implements TaskService { return list; } + /** + * 新增或修改检查任务所需资源数量 + */ + public void checkTaskResourceNumber(TaskDO taskDO){ + if (!taskDO.getDraft()){ + List resourceList = taskDO.getResources().toJavaList(ResourceDTO.class); + //任务状态更改成进行中 或 任务状态更改成完成 + if (taskDO.getStatus().equals(TaskStatus.STARTED) || taskDO.getStatus().equals(TaskStatus.COMPLETE)){ + resourceList.forEach(item ->{ + ResourceDO resourceDO = resourceMapper.selectById(item.getResourceId().get(1)); + //更改成进行中 + if (taskDO.getStatus().equals(TaskStatus.STARTED)){ + resourceDO.setNumber(resourceDO.getNumber() - item.getNum()); + if (resourceDO.getSolo()){ + //唯一资源 更改成 已占用 + resourceDO.setOccupied(true); + } + } + //更改成已完成 + if (taskDO.getStatus().equals(TaskStatus.COMPLETE)){ + if (resourceDO.getSolo()){ + //唯一资源 更改成 未占用, 并返还数量 + resourceDO.setOccupied(false); + resourceDO.setNumber(resourceDO.getNumber() + item.getNum()); + } + } + resourceMapper.updateById(resourceDO); + }); + } + } + } + }