Browse Source

#巡检计划

zhongwei
yang_shj 4 months ago
parent
commit
413a5c52f2
  1. 144
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java

144
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java

@ -1,12 +1,5 @@
package com.hnac.hzinfo.inspect.plan.service.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hnac.hzims.common.constant.CommonConstant;
import com.hnac.hzinfo.exception.HzServiceException;
import com.hnac.hzinfo.inspect.ai.entity.RobotEntity;
import com.hnac.hzinfo.inspect.plan.vo.PlanOfflineVO;
import org.springblade.system.feign.ISysClient;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -14,8 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.hnac.hzims.operational.duty.feign.IDutyClassClient;
import com.hnac.hzims.common.constant.CommonConstant;
import com.hnac.hzinfo.exception.HzServiceException;
import com.hnac.hzinfo.inspect.obj.entity.ObjectEntity;
import com.hnac.hzinfo.inspect.obj.entity.TemplateEntity;
import com.hnac.hzinfo.inspect.obj.services.ObjectService;
@ -27,6 +22,7 @@ import com.hnac.hzinfo.inspect.plan.entity.*;
import com.hnac.hzinfo.inspect.plan.mapper.PlanMapper;
import com.hnac.hzinfo.inspect.plan.service.*;
import com.hnac.hzinfo.inspect.plan.vo.PlanObjectTemplateVO;
import com.hnac.hzinfo.inspect.plan.vo.PlanOfflineVO;
import com.hnac.hzinfo.inspect.plan.vo.PlanTaskListVO;
import com.hnac.hzinfo.inspect.plan.vo.PlanVO;
import com.hnac.hzinfo.inspect.task.entity.TaskEntity;
@ -35,15 +31,14 @@ import com.hnac.hzinfo.inspect.task.job.service.impl.ConcurrentTaskServcie;
import com.hnac.hzinfo.inspect.task.job.service.impl.SeizeTaskService;
import com.hnac.hzinfo.inspect.task.service.ITaskService;
import org.springblade.core.log.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.system.feign.ISysClient;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -51,7 +46,9 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@ -79,23 +76,8 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
@Autowired
private ITaskService taskService;
@Autowired
private IDutyClassClient dutyClassClient;
@Autowired
private IRouteService routeService;
/**
* 任务提醒缓存名字 cacheName
*/
// private static final String TASK_REMIND_CACHE_NAME = "taskRemindCache";
/**
* 任务开始提醒缓存key cacheName
*/
// private static final String TASK_START_REMIND_KEY = "taskStartRemind";
/**
* 任务结束提醒缓存key cacheName
*/
// private static final String TASK_END_REMIND_KEY = "taskEndRemind";
/**
@ -134,6 +116,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
}
@Override
@Transactional
public Boolean initiateRobotPlan(Long userId, Long robotUserId, Long routeId, String routeName) {
PlanEntity robotPlan = new PlanEntity();
// 获取巡检路线信息
@ -252,87 +235,6 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
}
}
/**
* 插入巡检计划相关表
* @param modify 是否是修改
* @param plan
* @return
*/
private boolean insertPlanRelationsOld(boolean modify,PlanVO plan){
boolean success = false;
//添加巡检计划对象模板(一个对象在一个计划只能出现一次)
List<PlanObjectTemplateVO> obtList = plan.getPlanObjectTemplates().stream().filter(objectEntity->objectEntity.getId()==null).collect(Collectors.toList());
if(obtList.size()>0){
List<Long> planObjectIds = planObjectTemplateService.list(Wrappers.<PlanObjectTemplateEntity>lambdaQuery()
.eq(PlanObjectTemplateEntity::getPlanId,plan.getId())).stream().map(objEntity->objEntity.getObjectId()).distinct().collect(Collectors.toList());
planObjectIds.addAll(obtList.stream().map(planObjectVO->planObjectVO.getObjectId()).collect(Collectors.toList()));
Set<Long> planObjectIdsSet = new HashSet<>(planObjectIds);
boolean repeat = planObjectIds.size()!=planObjectIdsSet.size();
if(repeat){
throw new ServiceException("一个对象在一个计划只能出现一次");
}
List<PlanObjectTemplateEntity> pteList = Lists.newArrayList();
for(PlanObjectTemplateVO tvo :obtList){
PlanObjectTemplateEntity pte = PlanObjectTemplateEntity.builder().objectId(tvo.getObjectId()).templateId(tvo.getTemplateId()).planId(plan.getId()).build();
pte.setId(tvo.getId());
pteList.add(pte);
}
if(pteList.size()>0){
success = planObjectTemplateService.saveOrUpdateBatch(pteList);
}
}
if(modify){//修改先要删除
//巡检计划模式人员
UpdateWrapper<PlanUserEntity> ew = new UpdateWrapper<>();
ew.lambda().eq(PlanUserEntity::getPlanId, plan.getId());
planUserService.remove(ew);
//巡检计划模式岗位
UpdateWrapper<PlanPositionEntity> ew1 = new UpdateWrapper<>();
ew1.lambda().eq(PlanPositionEntity::getPlanId, plan.getId());
planPositionService.remove(ew1);
//巡检计划模式机构
UpdateWrapper<PlanOrgEntity> ew2 = new UpdateWrapper<>();
ew2.lambda().eq(PlanOrgEntity::getPlanId, plan.getId());
planOrgService.remove(ew2);
}
//巡检计划模式人员
List<Long> uVoList = plan.getPlanUsers();
if(Func.isNotEmpty(uVoList)){
List<PlanUserEntity> uList = Lists.newArrayList();
for(Long uId:uVoList){
uList.add(PlanUserEntity.builder().planId(plan.getId()).userId(uId).build());
}
if(uList.size()>0){
success = planUserService.saveBatch(uList);
}
}
//巡检计划模式岗位
List<Long> pVoList = plan.getPlanPosts();
if(Func.isNotEmpty(pVoList)){
List<PlanPositionEntity> pList = Lists.newArrayList();
for(Long pId:pVoList){
pList.add(PlanPositionEntity.builder().planId(plan.getId()).positionId(pId).build());
}
if(pList.size()>0){
success = planPositionService.saveBatch(pList);
}
}
//巡检计划模式机构
List<Long> oVoList = plan.getPlanOrgs();
if(Func.isNotEmpty(oVoList)){
List<PlanOrgEntity> oList = Lists.newArrayList();
for(Long oId:oVoList){
oList.add(PlanOrgEntity.builder().planId(plan.getId()).orgId(oId).build());
}
if(oList.size()>0){
success = planOrgService.saveBatch(oList);
}
}
return success;
}
/**
* 插入巡检计划相关表
@ -394,7 +296,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
for(Long uId:uVoList){
uList.add(PlanUserEntity.builder().planId(plan.getId()).userId(uId).build());
}
if(uList.size()>0){
if(!uList.isEmpty()){
success = planUserService.saveBatch(uList);
}
}
@ -406,7 +308,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
for(Long pId:pVoList){
pList.add(PlanPositionEntity.builder().planId(plan.getId()).positionId(pId).build());
}
if(pList.size()>0){
if(!pList.isEmpty()){
success = planPositionService.saveBatch(pList);
}
}
@ -418,7 +320,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
for(Long oId:oVoList){
oList.add(PlanOrgEntity.builder().planId(plan.getId()).orgId(oId).build());
}
if(oList.size()>0){
if(!oList.isEmpty()){
success = planOrgService.saveBatch(oList);
}
}
@ -480,6 +382,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
}
@Override
@Transactional
public Boolean modifyPlanStatus(Long planId, Integer status){
boolean re;
LambdaUpdateWrapper<PlanEntity> uw = new UpdateWrapper<PlanEntity>().lambda();
@ -551,7 +454,7 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
QueryWrapper<PlanObjectTemplateEntity> qw = new QueryWrapper<>();
qw.lambda().eq(PlanObjectTemplateEntity::getPlanId, id);
List<PlanObjectTemplateEntity> pteList = planObjectTemplateService.list(qw);
if(pteList!=null && pteList.size()>0){
if(pteList!=null && !pteList.isEmpty()){
List<Long> objIds = Lists.newArrayList();
List<Long> tmpIds = Lists.newArrayList();
for(PlanObjectTemplateEntity pote:pteList){
@ -592,8 +495,8 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
UpdateWrapper<PlanPositionEntity> ew = new UpdateWrapper<>();
ew.lambda().eq(PlanPositionEntity::getPlanId, entity.getId());
List<PlanPositionEntity> list = planPositionService.list(ew);
planPostIds = list.stream().map(e->e.getPositionId()).collect(Collectors.toList());
String postIds = String.join(",", list.stream().map(e->String.valueOf(e.getPositionId())).collect(Collectors.toList()));
planPostIds = list.stream().map(PlanPositionEntity::getPositionId).collect(Collectors.toList());
String postIds = list.stream().map(e->String.valueOf(e.getPositionId())).collect(Collectors.joining(","));
planPostNames.addAll(sysClient.getPostNames(postIds).getData());
}
plan.setPlanPosts(planPostIds);
@ -605,25 +508,16 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
UpdateWrapper<PlanOrgEntity> ew = new UpdateWrapper<>();
ew.lambda().eq(PlanOrgEntity::getPlanId, entity.getId());
List<PlanOrgEntity> list = planOrgService.list(ew);
planOrgIds = list.stream().map(e->e.getOrgId()).collect(Collectors.toList());
String orgIds = String.join(",", list.stream().map(e->String.valueOf(e.getOrgId())).collect(Collectors.toList()));
planOrgIds = list.stream().map(PlanOrgEntity::getOrgId).collect(Collectors.toList());
String orgIds = list.stream().map(e->String.valueOf(e.getOrgId())).collect(Collectors.joining(","));
planOrgNames.addAll(sysClient.getDeptNames(orgIds).getData());
}
plan.setPlanOrgs(planOrgIds);
plan.setPlanOrgNames(planOrgNames);
//值班班次
/* if(PlanTypeEnum.CLASS_TYPE.getType().equals(plan.getType())){
PlanClassEntity one = planClassService.getOne(Wrappers.lambdaQuery(PlanClassEntity.class).eq(PlanClassEntity::getPlanId, plan.getId()).last(" limit 1 "));
plan.setClassName(dutyClassClient.getClassName(one.getClassId()));
plan.setClassId(one.getClassId());
}*/
//任务
List<TaskEntity> taskList = taskService.list(Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getPlanId,plan.getId()));
List<PlanTaskListVO> planTaskVO = Lists.newArrayList();
taskList.forEach(entityTask->{
planTaskVO.add(PlanTaskListVO.builder().taskId(entityTask.getId()).batchNumber(entityTask.getBatchNumber()).planStartTime(entityTask.getPlanStartTime()).planEndTime(entityTask.getPlanEndTime()).status(entityTask.getStatus()).build());
});
taskList.forEach(entityTask-> planTaskVO.add(PlanTaskListVO.builder().taskId(entityTask.getId()).batchNumber(entityTask.getBatchNumber()).planStartTime(entityTask.getPlanStartTime()).planEndTime(entityTask.getPlanEndTime()).status(entityTask.getStatus()).build()));
plan.setTasks(planTaskVO);
return plan;
}

Loading…
Cancel
Save