|
|
@ -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); |
|
|
|