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 5ab4be6c..e8bececf 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 @@ -34,10 +34,26 @@ public interface ErrorCodeConstants{ ErrorCode PROJECT_AREA_HAS_OCCUPIED = new ErrorCode(1000007014, "项目更新失败,所选区域已被其他进行中项目占用"); - ErrorCode PROJECT_NOT_STARTING = new ErrorCode(1000007015, "任务更新失败,项目还没开始"); + ErrorCode PROJECT_NOT_STARTING = new ErrorCode(1000007015, "任务提交失败,进行中的项目才能新增或修改任务"); ErrorCode DISCUSS_ADD_FAIL = new ErrorCode(1000007016, "活动操作失败,只有任务在进行中才可以新增活动"); - ErrorCode DISCUSS_TASK_IS_DRAFT = new ErrorCode(100000701, "活动操作失败,所属任务为草稿"); + ErrorCode DISCUSS_TASK_IS_DRAFT = new ErrorCode(100000717, "活动操作失败,所属任务为草稿"); + + ErrorCode TASK_STATE_CHANGE_FAIL = new ErrorCode(100000718, "任务更改失败, 计划中或准备中的任务只能更改为开始"); + + ErrorCode TASK_WAS_END = new ErrorCode(100000719, "任务更改失败, 已完成的任务只能更改为任务关闭"); + + ErrorCode TASK_WAS_STARTED = new ErrorCode(100000720, "任务更改失败, 已开始的任务不能更改为计划中或准备中"); + + ErrorCode PROJECT_PLAN_TO_STARTING = new ErrorCode(100000721, "项目更改失败, 计划中的任务只能更改成进行中"); + + 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_AREA = new ErrorCode(100000724, "项目更改失败, 进行中的任务不可修改区域"); } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java index c3885d2c..f5d41881 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussBaseVO.java @@ -1,13 +1,11 @@ package cn.iocoder.yudao.module.farm.controller.admin.discuss.vo; import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.WorkHourBaseVO; -import com.alibaba.fastjson.JSONArray; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import javax.validation.constraints.*; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.List; /** * 农场任务讨论 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -32,7 +30,7 @@ public class DiscussBaseVO { private List areas; - private Integer cropNum; + private Double cropNum; private List workHourList; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java index 71eed14d..78107fb2 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExcelVO.java @@ -1,14 +1,11 @@ package cn.iocoder.yudao.module.farm.controller.admin.discuss.vo; import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.WorkHourBaseVO; -import com.alibaba.fastjson.JSONArray; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; +import java.util.List; /** * 农场任务讨论 Excel VO @@ -35,7 +32,7 @@ public class DiscussExcelVO { private List areas; - private Integer cropNum; + private Double cropNum; @ExcelProperty("") private Date createTime; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java index 11b5566c..f45c1752 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussExportReqVO.java @@ -1,12 +1,13 @@ package cn.iocoder.yudao.module.farm.controller.admin.discuss.vo; -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 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(value = "管理后台 - 农场任务讨论 Excel 导出 Request VO", description = "参数和 DiscussPageReqVO 是一致的") @@ -27,7 +28,7 @@ public class DiscussExportReqVO { private List areas; - private Integer cropNum; + private Double cropNum; @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @ApiModelProperty(value = "开始") diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java index 2940ea89..e33e5c0a 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/discuss/vo/DiscussPageReqVO.java @@ -1,12 +1,16 @@ package cn.iocoder.yudao.module.farm.controller.admin.discuss.vo; -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") @@ -29,7 +33,7 @@ public class DiscussPageReqVO extends PageParam { private List areas; - private Integer cropNum; + private Double cropNum; @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @ApiModelProperty(value = "开始") diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java index ca5e490b..b83c17a0 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/statistical/StatisticalController.java @@ -4,7 +4,9 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.farm.controller.admin.statistical.dto.RequestDTO; -import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.*; +import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.CakeSeries; +import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.StatisticalVo; +import cn.iocoder.yudao.module.farm.controller.admin.statistical.vo.WorkMsg; import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO; import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; @@ -24,10 +26,12 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.text.DateFormat; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; @@ -129,12 +133,12 @@ public class StatisticalController { if (cropMap.containsKey(cropDO.getId())){ CakeSeries cakeSeries = cropMap.get(cropDO.getId()); cakeSeries.setValue(cakeSeries.getValue() + areaSum); - + cakeSeries.setLabelText(cakeSeries.getValue().toString()); }else{ CakeSeries cakeSeries = CakeSeries.builder() .name(cropDO.getName()) .value(areaSum) - .labelText("不知道说啥") + .labelText(areaSum.toString()) .build(); cropMap.put(cropDO.getId(), cakeSeries); } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java index f1accaae..2962f40f 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/dto/TaskDetailDTO.java @@ -1,15 +1,12 @@ package cn.iocoder.yudao.module.farm.controller.admin.task.dto; -import cn.hutool.system.oshi.CpuInfo; 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.system.dal.dataobject.CpUser.CpUserDO; -import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.Date; import java.util.List; @Data @@ -48,7 +45,7 @@ public class TaskDetailDTO extends TaskDO { String apiTaskMsg; //任务下活动累计数量 - Integer cumulativeQuantity; + Double cumulativeQuantity; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java index ceee02bb..240862e4 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/discuss/DiscussDO.java @@ -1,15 +1,16 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.discuss; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.handler.ListIntToListLongTypeHandler; import cn.iocoder.yudao.module.farm.controller.admin.workHour.vo.WorkHourBaseVO; -import cn.iocoder.yudao.module.farm.dal.dataobject.workHour.WorkHourDO; -import com.alibaba.fastjson.JSONArray; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import io.swagger.annotations.ApiModelProperty; import lombok.*; -import java.util.*; -import com.baomidou.mybatisplus.annotation.*; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +import java.util.List; /** * 农场任务讨论 DO @@ -55,7 +56,7 @@ public class DiscussDO extends BaseDO { @TableField(typeHandler = ListIntToListLongTypeHandler.class) private List areas; - private Integer cropNum; + private Double cropNum; @ApiModelProperty("假装删除") 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 d9668a50..701692fb 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 @@ -73,6 +73,8 @@ public class ProjectServiceImpl implements ProjectService { public void updateProject(ProjectUpdateReqVO updateReqVO) { // 校验存在 this.validateProjectExists(updateReqVO.getId()); + //检查项目状态 + this.checkProjectStatus(updateReqVO); //检查项目新增、修改时的区域 是否能够使用 this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); //项目修改完成时,,项目下所有任务未完成不能更改项目状态为完成 @@ -234,7 +236,7 @@ public class ProjectServiceImpl implements ProjectService { * 检查项目新增、修改时的区域 是否能够使用 */ public void checkProjectAreas(ProjectDO projectDO){ - if (!projectDO.getDraft() && projectDO.getState().equals(ProjectStateEnum.STARTING)){ + if (projectDO.getState().equals(ProjectStateEnum.STARTING)){ List areaIdList = projectDO.getAreas().toJavaList(Long.class); for (Long aLong : areaIdList) { LambdaQueryWrapperX queryWrapperX = new LambdaQueryWrapperX<>(); @@ -251,4 +253,37 @@ public class ProjectServiceImpl implements ProjectService { } } + public void checkProjectStatus(ProjectUpdateReqVO updateProject){ + ProjectDO project = projectMapper.selectById(updateProject.getId()); + 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); + } + } + //项目更改失败, 已完成项目不可更改 + if (project.getState().equals(ProjectStateEnum.FINISH)){ + throw exception(PROJECT_FINISH); + } + } + } } 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 32eae185..cbcacce9 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 @@ -6,17 +6,23 @@ import cn.hutool.core.date.DateUtil; 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.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.farm.controller.admin.resource.dto.ResourceDTO; import cn.iocoder.yudao.module.farm.controller.admin.resource.dto.ResourceMsgDTO; import cn.iocoder.yudao.module.farm.controller.admin.task.dto.*; +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.area.AreaDO; import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO; import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; import cn.iocoder.yudao.module.farm.dal.dataobject.resource.ResourceDO; import cn.iocoder.yudao.module.farm.dal.dataobject.resourceType.ResourceTypeDO; +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.crop.CropMapper; @@ -24,6 +30,7 @@ import cn.iocoder.yudao.module.farm.dal.mysql.discuss.DiscussMapper; import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper; import cn.iocoder.yudao.module.farm.dal.mysql.resource.ResourceMapper; import cn.iocoder.yudao.module.farm.dal.mysql.resourceType.ResourceTypeMapper; +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.TaskMemberEnum; @@ -38,19 +45,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zsw.base.R; import org.springframework.stereotype.Service; -import javax.annotation.Resource; - import org.springframework.validation.annotation.Validated; +import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; -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.dal.mysql.task.TaskMapper; - import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*; @@ -91,7 +91,7 @@ public class TaskServiceImpl implements TaskService { @Override public Long createTask(TaskCreateReqVO createReqVO) { TaskDO task = BeanUtil.copyProperties(createReqVO, TaskDO.class); - //检查项目能否开始 + //检查任务能否新增 this.canTheTaskStart(task); //检查任务资源数量 this.checkTaskResourceNumber(task); @@ -105,6 +105,8 @@ public class TaskServiceImpl implements TaskService { @Override public void updateTask(TaskUpdateReqVO updateReqVO) { TaskDO task = BeanUtil.copyProperties(updateReqVO, TaskDO.class); + //项目能否更改状态 + this.checkTaskStatus(updateReqVO); //检查项目能否开始 this.canTheTaskStart(task); // 校验存在 @@ -224,7 +226,7 @@ public class TaskServiceImpl implements TaskService { } //任务活动的累计数量 List discussDOList = discussMapper.selectList(DiscussDO::getTaskId, id); - taskMsg.setCumulativeQuantity(ObjectUtil.isEmpty(discussDOList) ? 0 : discussDOList.stream().mapToInt(DiscussDO::getCropNum).sum()); + taskMsg.setCumulativeQuantity(ObjectUtil.isEmpty(discussDOList) ? 0 : discussDOList.stream().mapToDouble(DiscussDO::getCropNum).sum()); //已选择的二级区域 if (ObjectUtil.isNotEmpty(taskDO.getAreas())){ List secondAreaList = areaMapper.selectList(AreaDO::getId, taskDO.getAreas()); @@ -476,25 +478,24 @@ public class TaskServiceImpl implements TaskService { * 新增或修改检查任务所需资源数量 */ 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 (taskDO.getStatus().equals(TaskStatus.COMPLETE)){ - if (resourceDO.getSolo()){ - resourceDO.setNumber(resourceDO.getNumber() + item.getNum()); - } + List resourceList = taskDO.getResources().toJavaList(ResourceDTO.class); + //任务状态更改成进行中 或 任务状态更改成完成 + if (taskDO.getStatus().equals(TaskStatus.STARTED) || taskDO.getStatus().equals(TaskStatus.COMPLETE)){ + for (ResourceDTO resourceDTO : resourceList) { + ResourceDO resourceDO = resourceMapper.selectById(resourceDTO.getResourceId().get(1)); + //更改成进行中 + if (taskDO.getStatus().equals(TaskStatus.STARTED)){ + resourceDO.setNumber(resourceDO.getNumber() - resourceDTO.getNum()); + } + //更改成已完成 + if (taskDO.getStatus().equals(TaskStatus.COMPLETE)){ + if (resourceDO.getSolo()){ + resourceDO.setNumber(resourceDO.getNumber() + resourceDTO.getNum()); } - resourceMapper.updateById(resourceDO); - }); + } + resourceMapper.updateById(resourceDO); } + } } @@ -503,10 +504,34 @@ public class TaskServiceImpl implements TaskService { * 任务能否开始,只有所属项目开始了才可以开始 */ public void canTheTaskStart(TaskDO taskDO){ - if (!taskDO.getDraft() && taskDO.getStatus().equals(TaskStatus.STARTED)){ - ProjectDO project = projectMapper.selectById(taskDO.getProjectId()); - if (!project.getState().equals(ProjectStateEnum.STARTING)){ - throw exception(PROJECT_NOT_STARTING); + ProjectDO project = projectMapper.selectById(taskDO.getProjectId()); + if (!project.getState().equals(ProjectStateEnum.STARTING)){ + throw exception(PROJECT_NOT_STARTING); + } + } + + public void checkTaskStatus(TaskUpdateReqVO updateVO){ + TaskDO task = taskMapper.selectById(updateVO.getId()); + if (updateVO.getStatus().equals(task.getStatus())) { + + }else{ + //任务更改失败, 计划中或准备中的任务只能更改为开始 + if (task.getStatus().equals(TaskStatus.PLAN) || task.getStatus().equals(TaskStatus.READY)){ + if (!updateVO.getStatus().equals(TaskStatus.STARTED)){ + throw exception(TASK_STATE_CHANGE_FAIL); + } + } + //任务更改失败, 已开始的任务不能更改为计划中或准备中 + if (task.getStatus().equals(TaskStatus.STARTED)){ + if (updateVO.getStatus().equals(TaskStatus.PLAN) || updateVO.getStatus().equals(TaskStatus.READY)){ + throw exception(TASK_WAS_STARTED); + } + } + //任务更改失败, 已完成的任务只能更改为任务关闭 + if (task.getStatus().equals(TaskStatus.COMPLETE)){ + if (!updateVO.getStatus().equals(TaskStatus.END)){ + throw exception(TASK_WAS_END); + } } } }