|
|
|
@ -7,6 +7,7 @@ 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.framework.tenant.core.context.TenantContextHolder; |
|
|
|
|
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.project.vo.*; |
|
|
|
@ -32,12 +33,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.zsw.base.R; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -76,10 +79,10 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
public Long createProject(ProjectCreateReqVO createReqVO) { |
|
|
|
|
// 插入
|
|
|
|
|
ProjectDO project = ProjectConvert.INSTANCE.convert(createReqVO); |
|
|
|
|
//设置项目状态
|
|
|
|
|
//根据育苗时间设置项目状态
|
|
|
|
|
this.checkStateByTime(project); |
|
|
|
|
//检查项目新增、修改时的区域 是否能够使用
|
|
|
|
|
this.checkProjectAreas(BeanUtil.copyProperties(createReqVO, ProjectDO.class)); |
|
|
|
|
this.checkProjectAreas(project); |
|
|
|
|
project.setDeptId(Objects.requireNonNull(SecurityFrameworkUtils.getLoginUser()).getDeptId()); |
|
|
|
|
projectMapper.insert(project); |
|
|
|
|
// 返回
|
|
|
|
@ -91,18 +94,18 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
public void updateProject(ProjectUpdateReqVO updateReqVO) { |
|
|
|
|
// 校验存在
|
|
|
|
|
this.validateProjectExists(updateReqVO.getId()); |
|
|
|
|
//检查项目状态
|
|
|
|
|
this.checkProjectStatus(updateReqVO); |
|
|
|
|
ProjectDO updateObj = ProjectConvert.INSTANCE.convert(updateReqVO); |
|
|
|
|
//根据育苗时间设置项目状态
|
|
|
|
|
this.checkStateByTime(updateObj); |
|
|
|
|
//检查项目对应状态下 信息能否修改
|
|
|
|
|
this.checkProjectStatus(updateObj); |
|
|
|
|
//检查项目新增、修改时的区域 是否能够使用
|
|
|
|
|
this.checkProjectAreas(BeanUtil.copyProperties(updateReqVO, ProjectDO.class)); |
|
|
|
|
this.checkProjectAreas(updateObj); |
|
|
|
|
//项目修改完成时,,项目下有一个以上任务未完成,改项就不能更改为完成
|
|
|
|
|
//如果项目可以更改成完成状态 释放占用区域
|
|
|
|
|
if (updateReqVO.getState().equals(ProjectStateEnum.FINISH)){ |
|
|
|
|
this.checkProjectTaskFinish(updateReqVO); |
|
|
|
|
if (updateObj.getState().equals(ProjectStateEnum.FINISH)){ |
|
|
|
|
this.checkProjectTaskFinish(updateObj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
|
ProjectDO updateObj = ProjectConvert.INSTANCE.convert(updateReqVO); |
|
|
|
|
projectMapper.updateById(updateObj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -180,7 +183,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
LambdaQueryWrapperX<ProjectDO> queryWrapperX = this.miniProjectListQuery(pageDTO); |
|
|
|
|
List<ProjectDO> list = projectMapper.selectPage(pageDTO, queryWrapperX).getList(); |
|
|
|
|
if (ObjectUtil.isEmpty(list)){ |
|
|
|
|
return R.success(new PageVO<ProjectListDTO>()); |
|
|
|
|
return R.success(new PageVO<ProjectListDTO>().setList(new ArrayList<>())); |
|
|
|
|
} |
|
|
|
|
//小程序项目列表数据展示信息组装
|
|
|
|
|
PageVO<ProjectListDTO> returnList = this.miniProjectListAssemble(list); |
|
|
|
@ -192,6 +195,17 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
*/ |
|
|
|
|
private LambdaQueryWrapperX<ProjectDO> miniProjectListQuery(ProjectPageDTO pageDTO){ |
|
|
|
|
LambdaQueryWrapperX<ProjectDO> queryWrapperX = new LambdaQueryWrapperX<>(); |
|
|
|
|
//根据作物名查找
|
|
|
|
|
if (ObjectUtil.isNotEmpty(pageDTO.getCropName())){ |
|
|
|
|
List<CropDO> cropList = cropMapper.selectList(Wrappers.<CropDO>lambdaQuery().like(CropDO::getName, pageDTO.getCropName())); |
|
|
|
|
if (cropList.size() != 0){ |
|
|
|
|
List<Long> cropIdList = cropList.stream().map(CropDO::getId).collect(Collectors.toList()); |
|
|
|
|
queryWrapperX.in(ProjectDO::getCropId, cropIdList); |
|
|
|
|
}else{ |
|
|
|
|
// 作物名查找未找到 给个不可能查到的cropId 直接返回
|
|
|
|
|
return queryWrapperX.eq(ProjectDO::getCropId, 99999L); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
queryWrapperX.eqIfPresent(ProjectDO::getState, pageDTO.getState()); |
|
|
|
|
queryWrapperX.likeIfPresent(ProjectDO::getName, pageDTO.getProjectName()); |
|
|
|
|
queryWrapperX.eq(ProjectDO::getPretendDelete, false); |
|
|
|
@ -212,13 +226,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
queryWrapperX.apply(" ((JSON_CONTAINS(members, '"+ user.getId()+"') or creator = " + getLoginUserId() +"))"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.isNotEmpty(pageDTO.getCropName())){ |
|
|
|
|
List<CropDO> cropList = cropMapper.selectList(Wrappers.<CropDO>lambdaQuery().like(CropDO::getName, pageDTO.getCropName())); |
|
|
|
|
if (cropList.size() != 0){ |
|
|
|
|
List<Long> cropIdList = cropList.stream().map(CropDO::getId).collect(Collectors.toList()); |
|
|
|
|
queryWrapperX.in(ProjectDO::getCropId, cropIdList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//根据区域id展示
|
|
|
|
|
if (ObjectUtil.isNotEmpty(pageDTO.getAreaId())){ |
|
|
|
|
List<AreaDO> allAreaList = areaService.getAreaAndSubArea(pageDTO.getAreaId()); |
|
|
|
@ -297,9 +305,9 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
/** |
|
|
|
|
* 检查项目下所有任务是否完成 |
|
|
|
|
*/ |
|
|
|
|
public void checkProjectTaskFinish(ProjectUpdateReqVO updateReqVO){ |
|
|
|
|
public void checkProjectTaskFinish(ProjectDO updateObj){ |
|
|
|
|
List<TaskDO> taskList = taskMapper.selectList(Wrappers.<TaskDO>lambdaQuery() |
|
|
|
|
.eq(TaskDO::getProjectId, updateReqVO.getId()) |
|
|
|
|
.eq(TaskDO::getProjectId, updateObj.getId()) |
|
|
|
|
.eq(TaskDO::getPretendDelete, false) |
|
|
|
|
.eq(TaskDO::getDraft, false) |
|
|
|
|
.ne(TaskDO::getStatus, TaskStatus.COMPLETE) |
|
|
|
@ -309,12 +317,11 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//释放区域占用
|
|
|
|
|
List<AreaDO> areaList = areaService.getAreaList(updateReqVO.getAreas()); |
|
|
|
|
List<AreaDO> areaList = areaService.getAreaList(updateObj.getAreas()); |
|
|
|
|
areaList.forEach(item -> { |
|
|
|
|
item.setOccupied(false); |
|
|
|
|
areaMapper.updateById(item); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
item.setOccupied(false); |
|
|
|
|
areaMapper.updateById(item); |
|
|
|
|
}); |
|
|
|
|
//检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用
|
|
|
|
|
areaService.checkAreaOccupied(); |
|
|
|
|
} |
|
|
|
@ -340,18 +347,18 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
throw exception(PROJECT_AREA_HAS_OCCUPIED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
areaList.forEach(item ->{ |
|
|
|
|
areaList.forEach(item -> { |
|
|
|
|
item.setOccupied(true); |
|
|
|
|
areaMapper.updateById(item); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//检查区域占用状态 比如二级区域全部占用 对应一级区域变成占用
|
|
|
|
|
areaService.checkAreaOccupied(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void checkProjectStatus(ProjectUpdateReqVO updateProject){ |
|
|
|
|
public void checkProjectStatus(ProjectDO updateProject){ |
|
|
|
|
ProjectDO project = projectMapper.selectById(updateProject.getId()); |
|
|
|
|
//如果项目状态没改,改了其他信息
|
|
|
|
|
if (updateProject.getState().equals(project.getState())){ |
|
|
|
|
if (project.getState().equals(ProjectStateEnum.STARTING)){ |
|
|
|
|
if (project.getCropId() != updateProject.getCropId()){ |
|
|
|
@ -392,6 +399,9 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
* 3、草稿,没填 ——> 项目计划中 |
|
|
|
|
*/ |
|
|
|
|
public void checkStateByTime(ProjectDO projectDO){ |
|
|
|
|
if (projectDO.getState() != null && projectDO.getState().equals(ProjectStateEnum.FINISH)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (ObjectUtil.isNotEmpty(projectDO.getGrowSeedTime())){ |
|
|
|
|
FarmTimeEnum timeEnum = FarmTimeUtil.checkingDate(projectDO.getGrowSeedTime()); |
|
|
|
|
if (timeEnum.equals(FarmTimeEnum.IS_TODAY)){ |
|
|
|
@ -399,11 +409,29 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
}else if (timeEnum.equals(FarmTimeEnum.AFTER_TODAY)){ |
|
|
|
|
projectDO.setState(ProjectStateEnum.PLAN); |
|
|
|
|
}else if (timeEnum.equals(FarmTimeEnum.BEFORE_TODAY)){ |
|
|
|
|
throw exception(GROW_SEED_TIME_IS_BEFORE_TODAY); |
|
|
|
|
projectDO.setState(ProjectStateEnum.STARTING); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
//没填育苗时间 默认 计划中
|
|
|
|
|
projectDO.setState(ProjectStateEnum.PLAN); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0/10 * * * ?") |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void timingCheckProjectState(){ |
|
|
|
|
Boolean oldIgnore = TenantContextHolder.isIgnore(); |
|
|
|
|
try { |
|
|
|
|
TenantContextHolder.setIgnore(true); |
|
|
|
|
List<ProjectDO> list = projectMapper.selectList(Wrappers.<ProjectDO>lambdaQuery().ne(ProjectDO::getDraft, true).eq(ProjectDO::getPretendDelete, false) |
|
|
|
|
.eq(ProjectDO::getState, ProjectStateEnum.PLAN.getCode()).like(ProjectDO::getGrowSeedTime, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))); |
|
|
|
|
list.forEach(item ->{ |
|
|
|
|
item.setState(ProjectStateEnum.STARTING); |
|
|
|
|
this.checkProjectAreas(item); |
|
|
|
|
projectMapper.updateById(item); |
|
|
|
|
}); |
|
|
|
|
}finally { |
|
|
|
|
TenantContextHolder.setIgnore(oldIgnore); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|