package com.gkhy.safePlatform.safeCheck.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountGroupService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.GroupRPCRespDTO;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserRPCRespDTO;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.utils.idService.SnowFlow;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.safeCheck.common.RocketMQTemplateHelper;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskUnit;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskUnitAndWorkDO;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckUnitAndQuota;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckWork;
|
import com.gkhy.safePlatform.safeCheck.enums.*;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckTaskUnitPageReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckTaskUnitReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.req.SafeCheckUnitAndQuotaReqDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskUnitPageRespDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskUnitRespDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckUnitAndQuotaRespDTO;
|
import com.gkhy.safePlatform.safeCheck.model.query.TaskUnitDBQuery;
|
import com.gkhy.safePlatform.safeCheck.mq.msg.SafeCheckCreateTaskMsg;
|
import com.gkhy.safePlatform.safeCheck.service.SafeCheckTaskManagerService;
|
import com.gkhy.safePlatform.safeCheck.service.SafeCheckTaskUnitSchedulesService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckTaskUnitService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckUnitAndQuotaService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckWorkService;
|
import com.gkhy.safePlatform.safeCheck.util.UserInfoUtil;
|
import com.gkhy.safePlatform.safeCheck.util.timeChangeUtil;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.rocketmq.client.producer.SendResult;
|
import org.redisson.api.RLock;
|
import org.redisson.api.RedissonClient;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.swing.text.AbstractDocument;
|
import java.util.*;
|
import java.util.concurrent.TimeUnit;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class SafeCheckTaskManagerServiceImpl implements SafeCheckTaskManagerService {
|
|
@DubboReference(check = false)
|
private AccountAuthService accountAuthService;
|
|
@DubboReference(check = false)
|
private AccountDepartmentService accountDepartmentService;
|
|
@DubboReference(check = false)
|
private AccountGroupService accountGroupService;
|
|
@Autowired
|
private RocketMQTemplateHelper rocketMQTemplateHelper;
|
|
@Value("${rocketmq.topic.safeCheckCreateTaskTopic}")
|
private String safeCheckCreateTaskTopic;
|
|
@Autowired
|
private RedissonClient redissonClient;
|
|
@Autowired
|
private SafeCheckTaskUnitSchedulesService taskUnitSchedulesService;
|
|
@Autowired
|
private SafeCheckTaskUnitService safeCheckTaskUnitService;
|
|
@Autowired
|
private SafeCheckWorkService safeCheckWorkService;
|
|
@Autowired
|
private SafeCheckUnitAndQuotaService safeCheckUnitAndQuotaService;
|
|
|
/**
|
* @description 新建巡检任务单元
|
*/
|
@Transactional
|
@Override
|
public void saveTaskUnit(ContextCacheUser currentUser, SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
|
|
this.paramIsValid(safeCheckTaskUnitReqDTO);
|
|
//0、加分布式锁
|
String lockName = "SAFECHECK_TASK_UNIT_CREATE_"+safeCheckTaskUnitReqDTO.getUnitName();
|
RLock createTaskUnitLock = redissonClient.getLock(lockName);
|
createTaskUnitLock.lock(3, TimeUnit.SECONDS);
|
|
//判断任务单元的名称是否存在
|
SafeCheckTaskUnit unitNameIsExit = safeCheckTaskUnitService.taskUnitNameIsExit(safeCheckTaskUnitReqDTO.getUnitName(), DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
if (unitNameIsExit != null){
|
throw new AusinessException(E.DATA_DATABASE_EXIST,"巡检单元名称已存在");
|
}
|
//雪花算法生成id和uuid
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String taskUnitUuid = UUID.randomUUID().toString();
|
long taskUnitId = snowFlow.nextId();
|
Date date = new Date();
|
|
SafeCheckTaskUnit taskUnit = new SafeCheckTaskUnit();
|
taskUnit.setId(taskUnitId);
|
taskUnit.setUuid(taskUnitUuid);
|
taskUnit.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
|
taskUnit.setTaskUnitStatus(TaskUnitStatusEnum.TASK_UNIT_STATUS_OPEN.getStatus());
|
taskUnit.setUnitName(safeCheckTaskUnitReqDTO.getUnitName());
|
taskUnit.setEnterpriseId(userInfo.getEnterprise().getId());
|
taskUnit.setEnterpriseUuid(userInfo.getEnterprise().getUuid());
|
taskUnit.setCreateUserName(userInfo.getRealName());
|
taskUnit.setFileAddress(safeCheckTaskUnitReqDTO.getFileAddress());
|
|
taskUnit.setGmtCreate(date);
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
taskUnit.setGmtModitify(date);
|
|
|
String workUuid = UUID.randomUUID().toString();
|
long workId = snowFlow.nextId();
|
|
SafeCheckWork work = new SafeCheckWork();
|
BeanUtils.copyProperties(safeCheckTaskUnitReqDTO,work);
|
work.setId(workId);
|
work.setUuid(workUuid);
|
work.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
|
work.setWorkStatus(WorkStatusEnum.WORK_STATUS_OPEN.getStatus());
|
work.setNextNoticeTime(timeChangeUtil.nextNoticeTime(safeCheckTaskUnitReqDTO.getNoticeTime(),
|
safeCheckTaskUnitReqDTO.getNoticeTimeUnit(),safeCheckTaskUnitReqDTO.getFirstStartTime()));
|
work.setNextCheckTime(safeCheckTaskUnitReqDTO.getFirstStartTime());
|
work.setLastCheckTime(safeCheckTaskUnitReqDTO.getFirstStartTime());
|
work.setUnitId(taskUnitId);
|
work.setUnitUuid(taskUnitUuid);
|
int saveWorkResult = safeCheckWorkService.saveWork(work);
|
if (saveWorkResult == 0){
|
throw new AusinessException(E.ADD_FAIL,"调度信息插入失败");
|
}
|
|
//调度信息插入成功后才会往数据库中批量插入巡检链中的巡检点
|
List<SafeCheckUnitAndQuotaReqDTO> points = safeCheckTaskUnitReqDTO.getPoints();
|
List<SafeCheckUnitAndQuota> safeCheckUnitAndQuotas = new ArrayList<>();
|
safeCheckUnitAndQuotas = points.stream().map((point)->{
|
SafeCheckUnitAndQuota safeCheckUnitAndQuota = new SafeCheckUnitAndQuota();
|
BeanUtils.copyProperties(point,safeCheckUnitAndQuota);
|
safeCheckUnitAndQuota.setUnitId(taskUnitId);
|
safeCheckUnitAndQuota.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
|
safeCheckUnitAndQuota.setCreateUserName(userInfo.getRealName());
|
safeCheckUnitAndQuota.setGmtCreate(date);
|
safeCheckUnitAndQuota.setLastEditUserName(userInfo.getRealName());
|
safeCheckUnitAndQuota.setGmtModitify(date);
|
return safeCheckUnitAndQuota;
|
}).collect(Collectors.toList());
|
|
int saveUnitAndQuotaResult = safeCheckUnitAndQuotaService.saveUnitAndQuotas(safeCheckUnitAndQuotas);
|
if (saveUnitAndQuotaResult != safeCheckUnitAndQuotas.size() ){
|
throw new AusinessException(E.ADD_FAIL,"巡检链插入失败");
|
}
|
//保存任务
|
taskUnit.setPointsLength(saveUnitAndQuotaResult);
|
safeCheckTaskUnitService.saveTaskUnit(taskUnit);
|
|
//如果通知时间与当前时间的时间间隔小于任务单元调度的时间,就立即创建任务 目前调度时间是5分钟
|
if (work.getNextNoticeTime().getTime() - (new Date()).getTime() < 5*60*1000){
|
SafeCheckCreateTaskMsg createTaskMsg = new SafeCheckCreateTaskMsg();
|
createTaskMsg.setWorkId(workId);
|
//当前时间30秒后创建任务
|
createTaskMsg.setCreateTaskTime(new Date((new Date()).getTime()+30*1000));
|
rocketMQTemplateHelper.syncSend(safeCheckCreateTaskTopic, createTaskMsg);
|
|
work.setWorkStatus(WorkStatusEnum.WORK_STATUS_DISPATCHING.getStatus());
|
taskUnitSchedulesService.updateWorkStatusById(work);
|
}
|
|
//释放分布式锁
|
createTaskUnitLock.unlock();
|
}
|
|
/**
|
* @description 根据任务单元id删除任务单元
|
*/
|
@Transactional
|
@Override
|
public void deleteTaskUnit(ContextCacheUser currentUser, Long taskUnitId) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
Date date = new Date();
|
//先判断这个point是否存在
|
if (taskUnitId == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元id不能为空");
|
}
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(taskUnitId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
taskUnit.setGmtModitify(date);
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
taskUnit.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
|
List<Integer> taskUnitStatus = new ArrayList<>();
|
taskUnitStatus.add(TaskUnitStatusEnum.TASK_UNIT_STATUS_CLOSE.getStatus().intValue());
|
taskUnitStatus.add(TaskUnitStatusEnum.TASK_UNIT_STATUS_EXPIRE.getStatus().intValue());
|
//step1:先将任务单元表状态置为删除
|
int deleteTaskUnitResult = safeCheckTaskUnitService.deleteTaskUnit(taskUnit, taskUnitStatus, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
if (deleteTaskUnitResult == 0){
|
throw new AusinessException(E.NOT_DELETE,"开启状态的任务单元不允许删除,删除失败");
|
}
|
|
SafeCheckWork work = safeCheckWorkService.getWorkByTaskUnitId(taskUnitId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
|
work.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
|
List<Integer> workStatus = new ArrayList<>();
|
workStatus.add(WorkStatusEnum.WORK_STATUS_CLOSE.getStatus().intValue());
|
workStatus.add(WorkStatusEnum.WORK_STATUS_EXPIRE.getStatus().intValue());
|
//step2:将调度信息删除状态置为删除
|
int deleteWorkResult = safeCheckWorkService.deleteWorkById(work,workStatus,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
if (deleteWorkResult == 0){
|
throw new AusinessException(E.NOT_DELETE,"开启、调度中状态的调度单元不允许删除,删除失败");
|
}
|
|
|
List<SafeCheckUnitAndQuota> unitAndQuotas = safeCheckUnitAndQuotaService.listByTaskUnitId(taskUnitId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
//step3:查看巡检单元与巡检链表中是否存在关联数据
|
|
if (unitAndQuotas != null && unitAndQuotas.size() > 0){
|
unitAndQuotas = unitAndQuotas.stream().map((unitAndQuota)->{
|
unitAndQuota.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
|
unitAndQuota.setLastEditUserName(userInfo.getRealName());
|
unitAndQuota.setGmtModitify(date);
|
return unitAndQuota;
|
}).collect(Collectors.toList());
|
int updateUnitAndQuotaResult = safeCheckUnitAndQuotaService.updateUnitAndQuotasById(unitAndQuotas,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
if (updateUnitAndQuotaResult != unitAndQuotas.size()){
|
throw new AusinessException(E.NOT_DELETE,"巡检任务单元:巡检链删除失败");
|
}
|
}
|
}
|
|
|
/**
|
* @description 根据id更新巡检任务单元信息
|
*/
|
@Transactional
|
@Override
|
public void updateTaskUnitMainById(ContextCacheUser currentUser, SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
|
this.paramIsValid(safeCheckTaskUnitReqDTO);
|
|
String unitName = safeCheckTaskUnitReqDTO.getUnitName();
|
|
//0、加分布式锁
|
String lockName = "SAFECHECK_TASK_UNIT_MAIN_UPDATE_"+unitName;
|
RLock regionUpdateTaskUnitMainLock = redissonClient.getLock(lockName);
|
regionUpdateTaskUnitMainLock.lock(3, TimeUnit.SECONDS);
|
|
SafeCheckTaskUnit newTaskUnit = safeCheckTaskUnitService.taskUnitNameIsExit(safeCheckTaskUnitReqDTO.getUnitName(), DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
Long taskid = safeCheckTaskUnitReqDTO.getId();
|
if (taskid == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元id不能为空");
|
}
|
if (!taskid.equals(newTaskUnit.getId())){
|
throw new AusinessException(E.DATA_DATABASE_EXIST,"巡检单元名称已存在");
|
}
|
Date date = new Date();
|
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(safeCheckTaskUnitReqDTO.getId(), DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
taskUnit.setUnitName(safeCheckTaskUnitReqDTO.getUnitName());
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
taskUnit.setGmtModitify(date);
|
safeCheckTaskUnitService.updateTaskUnitNameById(taskUnit,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
SafeCheckWork oldWork = safeCheckWorkService.getWorkByTaskUnitId(safeCheckTaskUnitReqDTO.getId(), DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
Date oldNextCheckTime = oldWork.getNextCheckTime();
|
BeanUtils.copyProperties(safeCheckTaskUnitReqDTO,oldWork,"id","uuid");
|
if (!safeCheckTaskUnitReqDTO.getFirstStartTime().equals(oldNextCheckTime)){
|
oldWork.setWorkStatus(WorkStatusEnum.WORK_STATUS_OPEN.getStatus());
|
}
|
oldWork.setNextNoticeTime(timeChangeUtil.nextNoticeTime(safeCheckTaskUnitReqDTO.getNoticeTime()
|
,safeCheckTaskUnitReqDTO.getNoticeTimeUnit(),safeCheckTaskUnitReqDTO.getFirstStartTime()));
|
oldWork.setNextCheckTime(safeCheckTaskUnitReqDTO.getFirstStartTime());
|
safeCheckWorkService.updateWorkInfoById(oldWork,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
//1、释放分布式锁
|
regionUpdateTaskUnitMainLock.unlock();
|
}
|
|
/**
|
* @description 根据id更新巡检任务单元状态
|
*/
|
@Transactional
|
@Override
|
public String updateTaskUnitStatusById(ContextCacheUser currentUser, SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
|
Long taskUnitId = safeCheckTaskUnitReqDTO.getId();
|
Integer newTaskUnitStatus = safeCheckTaskUnitReqDTO.getTaskUnitStatus().intValue();
|
Date date = new Date();
|
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(taskUnitId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
Integer oldTaskUnitStatus = taskUnit.getTaskUnitStatus().intValue();
|
if (newTaskUnitStatus == oldTaskUnitStatus){
|
throw new AusinessException(E.UPDATE_FAIL,"巡检任务单元已处于"+TaskUnitStatusEnum.getValue(safeCheckTaskUnitReqDTO.getTaskUnitStatus())+"状态");
|
}
|
taskUnit.setTaskUnitStatus(newTaskUnitStatus.byteValue());
|
taskUnit.setGmtModitify(date);
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
//修改任务单元的状态
|
safeCheckTaskUnitService.updateTaskUniStatusById(taskUnit,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
SafeCheckWork work = safeCheckWorkService.getWorkByTaskUnitId(taskUnitId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
work.setWorkStatus(newTaskUnitStatus.byteValue());
|
//修改任务单元关联调度表的状态
|
safeCheckWorkService.updateWorkStatusById(work,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
//修改巡检链数据的状态
|
List<SafeCheckUnitAndQuota> unitAndQuotas = safeCheckUnitAndQuotaService.listByTaskUnitId(taskUnitId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
if (unitAndQuotas != null && unitAndQuotas.size() > 0){
|
unitAndQuotas = unitAndQuotas.stream().map((unitAndQuota)->{
|
unitAndQuota.setLastEditUserName(userInfo.getRealName());
|
unitAndQuota.setGmtModitify(date);
|
return unitAndQuota;
|
}).collect(Collectors.toList());
|
int updateUnitAndQuotaResult = safeCheckUnitAndQuotaService.updateUnitAndQuotasById(unitAndQuotas,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
if (updateUnitAndQuotaResult != unitAndQuotas.size()){
|
throw new AusinessException(E.UPDATE_FAIL,"巡检任务单元:巡检链状态修改失败");
|
}
|
}
|
String newTaskUnitStatusString = TaskUnitStatusEnum.getValue(newTaskUnitStatus.byteValue());
|
return newTaskUnitStatusString;
|
}
|
|
|
/**
|
* @description 根据任务单元id查询任务单元
|
*/
|
@Override
|
public SafeCheckTaskUnitRespDTO getTaskUnitById(Long taskUnitId) {
|
if (taskUnitId == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检单元id不能为空");
|
}
|
SafeCheckTaskUnitRespDTO taskUnitRespDTO = new SafeCheckTaskUnitRespDTO();
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(taskUnitId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
BeanUtils.copyProperties(taskUnit,taskUnitRespDTO);
|
|
SafeCheckWork work = safeCheckWorkService.getWorkByTaskUnitId(taskUnitId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
BeanUtils.copyProperties(work,taskUnitRespDTO,"id","uuid");
|
List<SafeCheckUnitAndQuota> unitAndQuotas = safeCheckUnitAndQuotaService.listByTaskUnitId(taskUnitId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
if (unitAndQuotas == null || unitAndQuotas.size()==0){
|
taskUnitRespDTO.setPoints(null);
|
}
|
List<SafeCheckUnitAndQuotaRespDTO> points = unitAndQuotas.stream().map((unitAndQuota)->{
|
SafeCheckUnitAndQuotaRespDTO unitAndQuotaRespDTO = new SafeCheckUnitAndQuotaRespDTO();
|
BeanUtils.copyProperties(unitAndQuota,unitAndQuotaRespDTO);
|
return unitAndQuotaRespDTO;
|
}).collect(Collectors.toList());
|
taskUnitRespDTO.setPoints(points);
|
return taskUnitRespDTO;
|
}
|
|
/**
|
* @description 查询所有巡检任务单元数据并进行分页(包含条件查询)
|
*/
|
@Override
|
public IPage listTaskUnitByPage(Page pageInfo, SafeCheckTaskUnitPageReqDTO safeCheckTaskUnitPageReqDTO,ContextCacheUser currentUser) {
|
TaskUnitDBQuery taskUnitDBQuery = new TaskUnitDBQuery();
|
BeanUtils.copyProperties(safeCheckTaskUnitPageReqDTO,taskUnitDBQuery);
|
|
List<Long> depIds = null;
|
if (UserTypeEnum.STAFF.getCode() == currentUser.getType()){
|
ResultVO<List<Long>> resultVO = accountDepartmentService.listDepAndSubDepIds(currentUser.getDepId());
|
depIds = (List<Long>) resultVO.getData();
|
}
|
taskUnitDBQuery.setDepIds(depIds);
|
UserRPCRespDTO userInfo;
|
if (safeCheckTaskUnitPageReqDTO.getCreateUserId() == null) {
|
taskUnitDBQuery.setCreateUserName(null);
|
}else {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(safeCheckTaskUnitPageReqDTO.getCreateUserId());
|
userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
if (userInfo == null){
|
taskUnitDBQuery.setCreateUserName(null);
|
}else {
|
String realName = userInfo.getRealName();
|
taskUnitDBQuery.setCreateUserName(realName);
|
}
|
}
|
IPage pageInfoResult = safeCheckTaskUnitService.listTaskUnitByPage(pageInfo,taskUnitDBQuery);
|
List<SafeCheckTaskUnitAndWorkDO> records = pageInfoResult.getRecords();
|
if (records == null || records.size() == 0){
|
pageInfoResult.setRecords(null);
|
}
|
List<SafeCheckTaskUnitPageRespDTO> pageRespDTOs =records.stream().map((safeCheckTaskUnitAndWorkDO)->{
|
SafeCheckTaskUnitPageRespDTO pageRespDTO = new SafeCheckTaskUnitPageRespDTO();
|
BeanUtils.copyProperties(safeCheckTaskUnitAndWorkDO,pageRespDTO);
|
pageRespDTO.setCheckCycleUnit(TimeUnitEnum.getValue(safeCheckTaskUnitAndWorkDO.getCheckCycleUnit()));
|
return pageRespDTO;
|
}).collect(Collectors.toList());
|
pageInfoResult.setRecords(pageRespDTOs);
|
return pageInfoResult;
|
}
|
|
|
/**
|
* @description 根据巡检点的id删除巡检链中的巡检点
|
*/
|
@Transactional
|
@Override
|
public void deleteTaskUnitPoint(ContextCacheUser currentUser, HashMap<String, Object> taskUnitAndPointId) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
Date date = new Date();
|
Long taskUnitId = (Long) taskUnitAndPointId.get("taskUnitId");
|
if (taskUnitAndPointId == null){
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (taskUnitAndPointId.get("id") == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检点id不能为空");
|
}
|
if (taskUnitId == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检单位id不能为空");
|
}
|
SafeCheckUnitAndQuota unitAndQuota = safeCheckUnitAndQuotaService.
|
getUnitAndQuotaByid(taskUnitAndPointId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
unitAndQuota.setDeleteStatus(DelectStatusEnum.DELECT_YES.getStatus());
|
unitAndQuota.setGmtModitify(date);
|
unitAndQuota.setLastEditUserName(userInfo.getRealName());
|
|
safeCheckUnitAndQuotaService.deleteTaskUnitPoint(unitAndQuota,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
//删除成功后更新巡检任务单元表中巡检链的长度
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(taskUnitId, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
taskUnit.setPointsLength(taskUnit.getPointsLength()-1);
|
taskUnit.setGmtModitify(date);
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
|
safeCheckTaskUnitService.updateTaskUnitPointsLengthById(taskUnit,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
}
|
|
/**
|
* @description 根据巡检任务单元的id及巡检单元与巡检指标关联表的id对巡检点信息内容进行修改
|
*/
|
@Transactional
|
@Override
|
public void updateTaskUnitPointById(ContextCacheUser currentUser, SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
Date date = new Date();
|
this.pointParamIsValid(safeCheckUnitAndQuotaReqDTO);
|
|
HashMap<String, Object> taskUnitAndPointId = new HashMap<>();
|
|
taskUnitAndPointId.put("taskUnitId",safeCheckUnitAndQuotaReqDTO.getUnitId());
|
taskUnitAndPointId.put("id",safeCheckUnitAndQuotaReqDTO.getId());
|
|
SafeCheckUnitAndQuota unitAndQuota = safeCheckUnitAndQuotaService.
|
getUnitAndQuotaByid(taskUnitAndPointId,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
BeanUtils.copyProperties(safeCheckUnitAndQuotaReqDTO,unitAndQuota);
|
unitAndQuota.setLastEditUserName(userInfo.getRealName());
|
unitAndQuota.setGmtModitify(date);
|
safeCheckUnitAndQuotaService.updateTaskUnitPointById(unitAndQuota,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
|
//更新下修改记录
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(safeCheckUnitAndQuotaReqDTO.getUnitId(),
|
DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
taskUnit.setPointsLength(taskUnit.getPointsLength());
|
taskUnit.setGmtModitify(date);
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
|
safeCheckTaskUnitService.updateTaskUnitPointsLengthById(taskUnit,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
}
|
|
/**
|
* @description 往巡检链中新增一个巡检点
|
*/
|
@Transactional
|
@Override
|
public void saveTaskUnitPoint(ContextCacheUser currentUser, SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO) {
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
UserRPCRespDTO userInfo = UserInfoUtil.judgeUserInfo(rpcResult);
|
Date date = new Date();
|
this.pointParamIsValid(safeCheckUnitAndQuotaReqDTO);
|
SafeCheckUnitAndQuota unitAndQuota = new SafeCheckUnitAndQuota();
|
BeanUtils.copyProperties(safeCheckUnitAndQuotaReqDTO,unitAndQuota);
|
unitAndQuota.setDeleteStatus(DelectStatusEnum.DELECT_NO.getStatus());
|
unitAndQuota.setGmtCreate(date);
|
unitAndQuota.setCreateUserName(userInfo.getRealName());
|
unitAndQuota.setGmtModitify(date);
|
unitAndQuota.setLastEditUserName(userInfo.getRealName());
|
safeCheckUnitAndQuotaService.saveTaskUnitPoint(unitAndQuota);
|
|
//新增成功后更新巡检任务单元表中巡检链的长度
|
SafeCheckTaskUnit taskUnit = safeCheckTaskUnitService.getTaskUnitById(safeCheckUnitAndQuotaReqDTO.getUnitId(),
|
DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
taskUnit.setPointsLength(taskUnit.getPointsLength()+ 1);
|
taskUnit.setGmtModitify(date);
|
taskUnit.setLastEditUserName(userInfo.getRealName());
|
|
safeCheckTaskUnitService.updateTaskUnitPointsLengthById(taskUnit,DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
}
|
|
|
/**
|
* @description 新建巡检单元主数据进行参数校验
|
*/
|
private void paramIsValid(SafeCheckTaskUnitReqDTO safeCheckTaskUnitReqDTO){
|
if (safeCheckTaskUnitReqDTO == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getUnitName() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元名称不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getWorkType() == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元作业类型不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getExecClassgroupId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元执行班组不能为空");
|
}
|
//todo 暂时不用部门id
|
// if (safeCheckTaskUnitReqDTO.getExecDepId() == null){
|
// throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元执行部门不能为空");
|
// }
|
if (safeCheckTaskUnitReqDTO.getWorkType() == WorkTypeEnum.WORK_TYPE_CYCLE.getCode()) {
|
if (safeCheckTaskUnitReqDTO.getCheckCycle() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "巡检任务单元巡检周期不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getCheckCycleUnit() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元巡检周期时间单位不能为空");
|
}
|
}
|
if (safeCheckTaskUnitReqDTO.getNoticeTime() == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元提前通知时间不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getNoticeTimeUnit() != null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元提前通知时间单位不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getValidTime() == 0 ){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元有效时间不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getValidTimeUnit() != null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元有效时间单位不能为空");
|
}
|
if (safeCheckTaskUnitReqDTO.getFirstStartTime() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务单元首次作业调度时间不能为空");
|
}
|
|
Date noticeTime = timeChangeUtil.nextNoticeTime(safeCheckTaskUnitReqDTO.getNoticeTime(),
|
safeCheckTaskUnitReqDTO.getNoticeTimeUnit(), safeCheckTaskUnitReqDTO.getFirstStartTime());
|
//新增任务单元设置的通知时间不能在当前时间之前
|
if ((new Date()).compareTo(noticeTime) > 0){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"任务单元设置的通知时间不能在当前时间之前");
|
}
|
//任务执行的间隔时间大于单次任务通知时间加上有效时间:也就是下次通知时间肯定要在本次任务执行之后 todo
|
//1.获得下次通知时间
|
if(safeCheckTaskUnitReqDTO.getWorkType() == WorkTypeEnum.WORK_TYPE_CYCLE.getCode()) {
|
Date nextNoticeTime = timeChangeUtil.nextNoticeTimeByCurrentNoticeTime(safeCheckTaskUnitReqDTO.getCheckCycle(),
|
safeCheckTaskUnitReqDTO.getCheckCycleUnit(), noticeTime);
|
//2.获得本次任务的有效截至日期
|
Date currentTaskvalidTime = timeChangeUtil.nextValidTime(safeCheckTaskUnitReqDTO.getValidTime(), safeCheckTaskUnitReqDTO.getValidTimeUnit()
|
, safeCheckTaskUnitReqDTO.getFirstStartTime());
|
if (nextNoticeTime.compareTo(currentTaskvalidTime) <= 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "巡检周期间隔时间需大于巡检通知时间加上巡检执行有效时间");
|
}
|
}
|
if (safeCheckTaskUnitReqDTO.getPoints() == null && safeCheckTaskUnitReqDTO.getPoints().size() == 0){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"任务单元关联的巡检点不能为空");
|
}
|
for (SafeCheckUnitAndQuotaReqDTO point : safeCheckTaskUnitReqDTO.getPoints()) {
|
this.pointParamIsValidWhenTaskUnitAdd(point);
|
}
|
|
}
|
|
/**
|
* @description 任务单元首次创建时包含的point进行数据校验
|
*/
|
private void pointParamIsValidWhenTaskUnitAdd(SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO){
|
if (safeCheckUnitAndQuotaReqDTO == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检点信息不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getPointId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检点id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getRegionId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检区域id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getRfidId() == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"rfid值不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getQuotaId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检指标id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getQuotaUnit() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检指标单位不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getExecSequence() == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"执行顺序不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getDataReportType() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"数据填报类型能为空");
|
}
|
if(safeCheckUnitAndQuotaReqDTO.getSecondReferenceValue() != null){
|
if (safeCheckUnitAndQuotaReqDTO.getSecondReferenceSign() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"请选择参考值 > or >= 符号");
|
}
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getThirdReferenceValue() != null){
|
if (safeCheckUnitAndQuotaReqDTO.getThirdReferenceValue() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"请选择参考值 < or <= 符号");
|
}
|
}
|
}
|
|
/**
|
* @description 新增巡检点相关参数校验
|
*/
|
private void pointParamIsValid(SafeCheckUnitAndQuotaReqDTO safeCheckUnitAndQuotaReqDTO){
|
if (safeCheckUnitAndQuotaReqDTO == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检点信息不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getUnitId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"任务单元id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getPointId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检点id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getRegionId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检区域id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getRfidId() == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"rfid值不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getQuotaId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检指标id不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getQuotaUnit() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检指标单位不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getExecSequence() == 0){
|
throw new AusinessException(E.DATA_PARAM_NULL,"执行顺序不能为空");
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getDataReportType() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"数据填报类型能为空");
|
}
|
if(safeCheckUnitAndQuotaReqDTO.getSecondReferenceValue() != null){
|
if (safeCheckUnitAndQuotaReqDTO.getSecondReferenceSign() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"请选择参考值 > or >= 符号");
|
}
|
}
|
if (safeCheckUnitAndQuotaReqDTO.getThirdReferenceValue() != null){
|
if (safeCheckUnitAndQuotaReqDTO.getThirdReferenceValue() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"请选择参考值 < or <= 符号");
|
}
|
}
|
}
|
}
|