Browse Source

流程优化

zyh
zhanyunjiu 3 years ago
parent
commit
e44e0e662e
  1. 2
      zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java
  2. 7
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectPageDTO.java
  3. 70
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgServiceImpl.java
  4. 103
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java
  5. 6
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

2
zsw-farm/zsw-farm-api/src/main/java/cn/iocoder/yudao/module/farm/enums/ErrorCodeConstants.java

@ -63,6 +63,8 @@ public interface ErrorCodeConstants{
ErrorCode TASK_STARTED_FAIL = new ErrorCode(100000728, "任务更改失败, 所选资源已被占用");
ErrorCode EXECUTE_TIME_IS_BEFORE_TODAY = new ErrorCode(100000729, "执行时间不能在今天之前,操作失败");
ErrorCode GROW_SEED_TIME_IS_BEFORE_TODAY = new ErrorCode(100000730, "项目育苗时间不能在今天之前");
}

7
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/dto/ProjectPageDTO.java

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.farm.controller.admin.project.dto;
import cn.iocoder.yudao.framework.common.page.PageDTO;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ProjectPageDTO extends PageDTO {
public class ProjectPageDTO extends PageParam {
private static final long serialVersionUID = 1L;
@ -14,6 +14,9 @@ public class ProjectPageDTO extends PageDTO {
@ApiModelProperty("项目名")
private String projectName;
@ApiModelProperty("作物名")
private String cropName;
@ApiModelProperty("时间筛选 1全部 2两周 3三天")
private Integer timeLimit;

70
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/logMsg/LogMsgServiceImpl.java

@ -4,8 +4,16 @@ import cn.hutool.core.bean.BeanUtil;
import cn.iocoder.yudao.framework.common.page.PageDTO;
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.module.farm.controller.admin.logMsg.dto.LogMsgDTO;
import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.LogMsgCreateReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.LogMsgExportReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.LogMsgPageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.LogMsgUpdateReqVO;
import cn.iocoder.yudao.module.farm.convert.logMsg.LogMsgConvert;
import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO;
import cn.iocoder.yudao.module.farm.dal.mysql.logMsg.LogMsgMapper;
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper;
@ -13,21 +21,17 @@ import cn.iocoder.yudao.module.system.service.CpUser.CpUserService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.zsw.base.R;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.iocoder.yudao.module.farm.controller.admin.logMsg.vo.*;
import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.farm.convert.logMsg.LogMsgConvert;
import cn.iocoder.yudao.module.farm.dal.mysql.logMsg.LogMsgMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.LOG_MSG_NOT_EXISTS;
/**
* Service 实现类
@ -104,31 +108,33 @@ public class LogMsgServiceImpl implements LogMsgService {
LambdaQueryWrapperX<LogMsgDO> queryWrapperX = new LambdaQueryWrapperX<>();
queryWrapperX.orderByDesc(LogMsgDO::getId);
List<LogMsgDO> list = logMsgMapper.selectList(queryWrapperX);
if (list.size() != 0){
List<LogMsgDTO> dtoList = BeanUtil.copyToList(list, LogMsgDTO.class);
List<Long> systemUserIdList = dtoList.stream().map(LogMsgDTO::getUserId).collect(Collectors.toList());
List<AdminUserDO> adminUserList = adminUserService.getUsers(systemUserIdList);
List<CpUserDO> cpUserList = adminUserService.getCpUserByAdminUser(systemUserIdList);
Map<Long, CpUserDO> map = new HashMap<>();
adminUserList.forEach(systemUser ->{
cpUserList.forEach(cpUser ->{
if (systemUser.getUsername().equals(cpUser.getUserId())){
map.put(systemUser.getId(), cpUser);
}
});
});
List<LogMsgDTO> dtoList = BeanUtil.copyToList(list, LogMsgDTO.class);
List<Long> systemUserIdList = dtoList.stream().map(LogMsgDTO::getUserId).collect(Collectors.toList());
List<AdminUserDO> adminUserList = adminUserService.getUsers(systemUserIdList);
List<CpUserDO> cpUserList = adminUserService.getCpUserByAdminUser(systemUserIdList);
Map<Long, CpUserDO> map = new HashMap<>();
adminUserList.forEach(systemUser ->{
cpUserList.forEach(cpUser ->{
if (systemUser.getUsername().equals(cpUser.getUserId())){
map.put(systemUser.getId(), cpUser);
dtoList.forEach(msg ->{
if (map.containsKey(msg.getUserId())){
CpUserDO user = map.get(msg.getUserId());
msg.setUserName(user.getName());
msg.setUserIcon(user.getAvatar());
}
});
});
dtoList.forEach(msg ->{
if (map.containsKey(msg.getUserId())){
CpUserDO user = map.get(msg.getUserId());
msg.setUserName(user.getName());
msg.setUserIcon(user.getAvatar());
}
});
PageVO<LogMsgDTO> returnList = PageUtil.convertPageInfo(dtoList);
return R.success(returnList);
PageVO<LogMsgDTO> returnList = PageUtil.convertPageInfo(dtoList);
return R.success(returnList);
}
return R.success(new PageVO<LogMsgDTO>());
}
}

103
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/project/ProjectServiceImpl.java

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

6
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

@ -51,6 +51,7 @@ import com.zsw.base.R;
import lombok.extern.slf4j.Slf4j;
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;
@ -100,6 +101,7 @@ public class TaskServiceImpl implements TaskService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long createTask(TaskCreateReqVO createReqVO) {
TaskDO task = BeanUtil.copyProperties(createReqVO, TaskDO.class);
//检查任务能否新增/修改
@ -116,6 +118,7 @@ public class TaskServiceImpl implements TaskService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTask(TaskUpdateReqVO updateReqVO) {
TaskDO task = BeanUtil.copyProperties(updateReqVO, TaskDO.class);
//检查任务能否新增/修改
@ -580,7 +583,7 @@ public class TaskServiceImpl implements TaskService {
throw exception(EXECUTE_TIME_IS_BEFORE_TODAY);
}else if (timeEnum.equals(FarmTimeEnum.IS_TODAY)){
task.setStatus(TaskStatus.STARTED);
}else{
}else if (timeEnum.equals(FarmTimeEnum.AFTER_TODAY)){
task.setStatus(TaskStatus.READY);
}
}
@ -601,7 +604,6 @@ public class TaskServiceImpl implements TaskService {
.in(TaskDO::getStatus, TaskStatus.PLAN.getCode(), TaskStatus.READY.getCode())
.like(TaskDO::getPlanStartTime, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))));
if (taskList.size() != 0){
log.info("检查任务状态,更改 {} 个", taskList.size());
taskList.forEach(item ->{
item.setStatus(TaskStatus.STARTED);
taskMapper.updateById(item);

Loading…
Cancel
Save