|
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
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.PageParam; |
|
|
|
|
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; |
|
|
|
@ -14,15 +13,19 @@ 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.convert.project.ProjectConvert; |
|
|
|
|
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.project.ProjectDO; |
|
|
|
|
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.crop.CropMapper; |
|
|
|
|
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.enums.FarmTimeEnum; |
|
|
|
|
import cn.iocoder.yudao.module.farm.enums.ProjectStateEnum; |
|
|
|
|
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.util.FarmTimeUtil; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
@ -30,6 +33,7 @@ import com.zsw.base.R;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -64,13 +68,18 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
private AreaService areaService; |
|
|
|
|
@Resource |
|
|
|
|
private AreaMapper areaMapper; |
|
|
|
|
@Resource |
|
|
|
|
private CropMapper cropMapper; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public Long createProject(ProjectCreateReqVO createReqVO) { |
|
|
|
|
//检查项目新增、修改时的区域 是否能够使用
|
|
|
|
|
this.checkProjectAreas(BeanUtil.copyProperties(createReqVO, ProjectDO.class)); |
|
|
|
|
// 插入
|
|
|
|
|
ProjectDO project = ProjectConvert.INSTANCE.convert(createReqVO); |
|
|
|
|
//设置项目状态
|
|
|
|
|
this.checkStateByTime(project); |
|
|
|
|
//检查项目新增、修改时的区域 是否能够使用
|
|
|
|
|
this.checkProjectAreas(BeanUtil.copyProperties(createReqVO, ProjectDO.class)); |
|
|
|
|
project.setDeptId(Objects.requireNonNull(SecurityFrameworkUtils.getLoginUser()).getDeptId()); |
|
|
|
|
projectMapper.insert(project); |
|
|
|
|
// 返回
|
|
|
|
@ -78,6 +87,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void updateProject(ProjectUpdateReqVO updateReqVO) { |
|
|
|
|
// 校验存在
|
|
|
|
|
this.validateProjectExists(updateReqVO.getId()); |
|
|
|
@ -166,7 +176,21 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R<PageVO<ProjectListDTO>> findProjectList(ProjectPageDTO pageDTO){ |
|
|
|
|
PageUtil.startPage(pageDTO); |
|
|
|
|
//小程序项目列表查询条件组装
|
|
|
|
|
LambdaQueryWrapperX<ProjectDO> queryWrapperX = this.miniProjectListQuery(pageDTO); |
|
|
|
|
List<ProjectDO> list = projectMapper.selectPage(pageDTO, queryWrapperX).getList(); |
|
|
|
|
if (ObjectUtil.isEmpty(list)){ |
|
|
|
|
return R.success(new PageVO<ProjectListDTO>()); |
|
|
|
|
} |
|
|
|
|
//小程序项目列表数据展示信息组装
|
|
|
|
|
PageVO<ProjectListDTO> returnList = this.miniProjectListAssemble(list); |
|
|
|
|
return R.success(returnList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 小程序项目列表查询条件组装 |
|
|
|
|
*/ |
|
|
|
|
private LambdaQueryWrapperX<ProjectDO> miniProjectListQuery(ProjectPageDTO pageDTO){ |
|
|
|
|
LambdaQueryWrapperX<ProjectDO> queryWrapperX = new LambdaQueryWrapperX<>(); |
|
|
|
|
queryWrapperX.eqIfPresent(ProjectDO::getState, pageDTO.getState()); |
|
|
|
|
queryWrapperX.likeIfPresent(ProjectDO::getName, pageDTO.getProjectName()); |
|
|
|
@ -188,24 +212,27 @@ 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()); |
|
|
|
|
List<Long> allIdList = allAreaList.stream().map(AreaDO::getId).collect(Collectors.toList()); |
|
|
|
|
queryWrapperX.apply("JSON_OVERLAPS(areas, '"+ allIdList+"') = 1" ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
queryWrapperX.orderByDesc(ProjectDO::getId); |
|
|
|
|
return queryWrapperX; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
PageParam pageParam = new PageParam(); |
|
|
|
|
pageParam.setPageNo(pageDTO.getPageNum()); |
|
|
|
|
pageParam.setPageSize(pageDTO.getPageSize()); |
|
|
|
|
List<ProjectDO> list = projectMapper.selectPage(pageParam, queryWrapperX).getList(); |
|
|
|
|
if (ObjectUtil.isEmpty(list)){ |
|
|
|
|
return R.success(PageUtil.emptyPage(pageDTO, ProjectListDTO.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<Long> idList = list.stream().map(ProjectDO::getId).collect(Collectors.toList()); |
|
|
|
|
/** |
|
|
|
|
* 小程序项目列表数据展示信息组装 |
|
|
|
|
*/ |
|
|
|
|
private PageVO<ProjectListDTO> miniProjectListAssemble(List<ProjectDO> list){ |
|
|
|
|
List<ProjectListDTO> projectListDTOList = BeanUtil.copyToList(list, ProjectListDTO.class); |
|
|
|
|
|
|
|
|
|
//组装 项目成员信息
|
|
|
|
@ -241,6 +268,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//任务完成的
|
|
|
|
|
List<Long> idList = list.stream().map(ProjectDO::getId).collect(Collectors.toList()); |
|
|
|
|
List<TaskDO> taskList = taskMapper.selectList(Wrappers.<TaskDO>lambdaQuery().in(TaskDO::getProjectId, idList) |
|
|
|
|
.eq(TaskDO::getStatus, TaskStatus.COMPLETE.getCode())); |
|
|
|
|
//组装项目的最近一次完成任务信息(区域名、人员名、任务名)
|
|
|
|
@ -250,20 +278,20 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
for (ProjectListDTO projectListDTO : projectListDTOList) { |
|
|
|
|
//如果map 包含项目id
|
|
|
|
|
if (map.containsKey(projectListDTO.getId())){ |
|
|
|
|
map.get(projectListDTO.getId()).stream().findFirst().ifPresent( |
|
|
|
|
item ->{ |
|
|
|
|
TaskAssemblyDTO assemble = taskAssemble.get(item.getId()); |
|
|
|
|
projectListDTO.setAreaName(assemble.getAreaNameList()); |
|
|
|
|
projectListDTO.setExecutorName(assemble.getExecutorNameList()); |
|
|
|
|
projectListDTO.setTaskName(assemble.getTaskName()); |
|
|
|
|
projectListDTO.setFinishTime(assemble.getFinishTime()); |
|
|
|
|
} |
|
|
|
|
map.get(projectListDTO.getId()).stream().findFirst().ifPresent( |
|
|
|
|
item ->{ |
|
|
|
|
TaskAssemblyDTO assemble = taskAssemble.get(item.getId()); |
|
|
|
|
projectListDTO.setAreaName(assemble.getAreaNameList()); |
|
|
|
|
projectListDTO.setExecutorName(assemble.getExecutorNameList()); |
|
|
|
|
projectListDTO.setTaskName(assemble.getTaskName()); |
|
|
|
|
projectListDTO.setFinishTime(assemble.getFinishTime()); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
PageVO<ProjectListDTO> returnList = PageUtil.convertPageInfo(projectListDTOList); |
|
|
|
|
return R.success(returnList); |
|
|
|
|
return returnList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -295,11 +323,13 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
* 检查项目新增、修改时的区域 是否能够使用 |
|
|
|
|
*/ |
|
|
|
|
public void checkProjectAreas(ProjectDO projectDO){ |
|
|
|
|
if (projectDO.getState().equals(ProjectStateEnum.STARTING)){ |
|
|
|
|
if (projectDO.getState() != null && projectDO.getState().equals(ProjectStateEnum.STARTING)){ |
|
|
|
|
ProjectDO old = projectMapper.selectById(projectDO.getId()); |
|
|
|
|
|
|
|
|
|
//区域没修改 跳过下面的检查
|
|
|
|
|
if (old != null && old.getAreas() != null && CollectionUtils.isEqualCollection(projectDO.getAreas(), old.getAreas())){ |
|
|
|
|
if (old != null && old.getAreas() != null |
|
|
|
|
&& !old.getState().equals(ProjectStateEnum.PLAN) |
|
|
|
|
&& CollectionUtils.isEqualCollection(projectDO.getAreas(), old.getAreas())){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -353,4 +383,27 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据项目育苗时间 更改状态 |
|
|
|
|
* 1、今天 ——> 项目进行中 |
|
|
|
|
* 2、今天之后 ——> 项目计划中 |
|
|
|
|
* 3、草稿,没填 ——> 项目计划中 |
|
|
|
|
*/ |
|
|
|
|
public void checkStateByTime(ProjectDO projectDO){ |
|
|
|
|
if (ObjectUtil.isNotEmpty(projectDO.getGrowSeedTime())){ |
|
|
|
|
FarmTimeEnum timeEnum = FarmTimeUtil.checkingDate(projectDO.getGrowSeedTime()); |
|
|
|
|
if (timeEnum.equals(FarmTimeEnum.IS_TODAY)){ |
|
|
|
|
projectDO.setState(ProjectStateEnum.STARTING); |
|
|
|
|
}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); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
//没填育苗时间 默认 计划中
|
|
|
|
|
projectDO.setState(ProjectStateEnum.PLAN); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|