package com.gkhy.safePlatform.doublePrevention.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.model.resp.DepInfoRPCRespDTO;
|
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.BeanCopyUtils;
|
import com.gkhy.safePlatform.commons.utils.idService.SnowFlow;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.doublePrevention.entity.*;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.CheckResultReportDO;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.req.*;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.resp.*;
|
import com.gkhy.safePlatform.doublePrevention.enums.StatusEnum;
|
import com.gkhy.safePlatform.doublePrevention.enums.SyncEnum;
|
import com.gkhy.safePlatform.doublePrevention.enums.WorkStatusEnum;
|
import com.gkhy.safePlatform.doublePrevention.mq.msg.PreventCreateTaskMsg;
|
import com.gkhy.safePlatform.doublePrevention.mq.msg.PreventNoticeExecTaskMsg;
|
import com.gkhy.safePlatform.doublePrevention.mq.msg.PreventTimeOutTaskMsg;
|
import com.gkhy.safePlatform.doublePrevention.mq.msg.PreventWaitExecTaskMsg;
|
import com.gkhy.safePlatform.doublePrevention.repository.param.*;
|
import com.gkhy.safePlatform.doublePrevention.service.DangerService;
|
import com.gkhy.safePlatform.doublePrevention.service.baseService.*;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.rocketmq.client.producer.SendResult;
|
import org.apache.rocketmq.client.producer.SendStatus;
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
import org.redisson.api.RLock;
|
import org.redisson.api.RedissonClient;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
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 java.util.*;
|
import java.util.concurrent.TimeUnit;
|
|
@Service
|
public class DangerServiceImpl implements DangerService {
|
|
|
@DubboReference(check = false)
|
private AccountAuthService accountAuthService;
|
|
@DubboReference(check = false)
|
private AccountDepartmentService accountDepartmentService;
|
|
@Autowired
|
private RedissonClient redissonClient;
|
|
@Autowired
|
private PreventDangerCheckTaskUnitService preventDangerCheckTaskUnitService;
|
@Autowired
|
private PreventRiskControlMeasureService preventRiskControlMeasureService;
|
@Autowired
|
private PreventDangerCheckWorkService preventDangerCheckWorkService;
|
@Autowired
|
private PreventDangerCheckTaskService preventDangerCheckTaskService;
|
@Autowired
|
private PreventDangerCheckContentService preventDangerCheckContentService;
|
@Autowired
|
private PreventReportConfigService preventReportConfigService;
|
|
@Autowired
|
private PreventTaskAndMeasureService preventTaskAndMeasureService;
|
@Autowired
|
private PreventWorkAndMeasureService preventWorkAndMeasureService;
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@Value("${rocketmq.topic.preventCreateTaskTopic}")
|
private String preventCreateTaskTopic;
|
@Value("${rocketmq.topic.preventNoticeTaskTopic}")
|
private String preventNoticeTaskTopic;
|
@Value("${rocketmq.topic.preventTimeOutTaskTopic}")
|
private String preventTimeOutTaskTopic;
|
@Value("${rocketmq.topic.preventWaitWorkTopic}")
|
private String preventWaitWorkTopic;
|
|
@Autowired
|
private RocketMQTemplate rocketMQTemplate;
|
/**
|
* 隐患排查任务单元-分页查询
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckTaskUnit> getTaskUnitPage(Long userId, PreventDangerCheckTaskUnitQueryReqDTO taskUnitQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<String> measureList = new ArrayList<>();
|
List<PreventDangerCheckTaskUnitQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = taskUnitQueryReqDTO.getPageIndex();
|
Integer pageSize = taskUnitQueryReqDTO.getPageSize();
|
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//获取到所有符合条件的措施
|
IPage<PreventDangerCheckTaskUnit> page =
|
preventDangerCheckTaskUnitService.getTaskUnitPage(new Page<>(pageIndex, pageSize), taskUnitQueryReqDTO);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//遍历结果集,封装数据
|
for (PreventDangerCheckTaskUnit record : page.getRecords()) {
|
List<PreventRiskControlMeasure> measureLists = preventRiskControlMeasureService.getlistByUnitId(record.getId());
|
PreventDangerCheckTaskUnitQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerCheckTaskUnitQueryRespDTO.class);
|
//封装管控措施编码
|
if (measureLists.size() > 0){
|
List<PreventRiskControlMeasureDataRespDTO> measureContentList = new ArrayList<>();
|
for (PreventRiskControlMeasure controlMeasure : measureLists) {
|
PreventDangerCheckContent checkContent = preventDangerCheckContentService.getCheckContentByMeasureId(controlMeasure.getId());
|
PreventRiskControlMeasureDataRespDTO measure = BeanCopyUtils.copyBean(controlMeasure, PreventRiskControlMeasureDataRespDTO.class);
|
measure.setCheckContent(checkContent.getCheckContent());
|
measureContentList.add(measure);
|
}
|
respDTO.setMeasureList(measureContentList);
|
}
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setPageSize((int) page.getSize());
|
list.add(respDTO);
|
}
|
|
resultVO.setCount((int) page.getTotal());
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查任务单元-新增
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckTaskUnit> saveTaskUnit(Long userId, PreventDangerCheckTaskUnitSaveReqDTO taskUnitSaveReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("新增成功");
|
PreventDangerCheckTaskUnit taskUnit = new PreventDangerCheckTaskUnit();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (taskUnitSaveReqDTO.getTaskUnitName() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "隐患排查任务单元名称不能为空");
|
}
|
//检查是否存在同名任务单元
|
PreventDangerCheckTaskUnit taskUnitByName = preventDangerCheckTaskUnitService.getTaskUnitByName(taskUnitSaveReqDTO.getTaskUnitName());
|
if (ObjectUtils.isNotEmpty(taskUnitByName)){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "隐患排查任务单元名称已存在,请修改任务单元名称,或者添加编号");
|
}
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long taskUnitId = snowFlow.nextId();
|
|
//封装新增参数
|
taskUnit.setId(taskUnitId);
|
taskUnit.setUuid(uuid);
|
taskUnit.setTaskUnitName(taskUnitSaveReqDTO.getTaskUnitName());
|
taskUnit.setEnterpriseId((long) 1);
|
taskUnit.setEnterpriseUuid("111");
|
taskUnit.setGmtCreate(date);
|
taskUnit.setGmtModitify(date);
|
taskUnit.setCreateByUserName(userById.getRealName());
|
taskUnit.setLastEditUserName(userById.getRealName());
|
taskUnit.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
|
//填充非必填的参数
|
taskUnit.setNote(taskUnitSaveReqDTO.getNote());
|
//执行新增单元操作
|
int result = preventDangerCheckTaskUnitService.saveTaskUnit(taskUnit);
|
//修改管控措施关联
|
if (taskUnitSaveReqDTO.getMeasureList().size() > 0){
|
for (Long measureId : taskUnitSaveReqDTO.getMeasureList()) {
|
PreventRiskControlMeasure controlMeasureById = preventRiskControlMeasureService.getControlMeasureById(measureId);
|
if (controlMeasureById.getCheckTaskUnitId() == null){
|
preventRiskControlMeasureService.updateControlMeasureByMeasureIdAndUnitId(measureId, taskUnitId);
|
}else {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "该管控措施已经被单元管理");
|
}
|
}
|
}
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查任务单元-修改
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckTaskUnit> updateTaskUnit(Long userId, PreventDangerCheckTaskUnitUpdateReqDTO taskUnitUpdateReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
PreventDangerCheckTaskUnitUpdateParams updateParams = new PreventDangerCheckTaskUnitUpdateParams();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (taskUnitUpdateReqDTO.getTaskUnitName() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "隐患排查任务单元名称不能为空");
|
}
|
//检查是否存在同名任务单元
|
PreventDangerCheckTaskUnit taskUnitByName =
|
preventDangerCheckTaskUnitService.getTaskUnitByName(taskUnitUpdateReqDTO.getTaskUnitName());
|
//如果查询结果不为空,且入参Id与查询到的Id不相等,判断是存在同名任务单元
|
if (ObjectUtils.isNotEmpty(taskUnitByName) && !taskUnitByName.getId().equals(taskUnitUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "隐患排查任务单元名称已存在,请修改任务单元名称,或者添加编号");
|
}
|
//获取需要填充的信息
|
Date date = new Date();
|
|
//封装参数
|
updateParams.setId(taskUnitUpdateReqDTO.getId());
|
updateParams.setTaskUnitName(taskUnitUpdateReqDTO.getTaskUnitName());
|
updateParams.setGmtModitify(date);
|
updateParams.setLastEditUserName(userById.getRealName());
|
//填充非必填的参数
|
updateParams.setNote(taskUnitUpdateReqDTO.getNote());
|
//执行修改
|
int result = preventDangerCheckTaskUnitService.updateTaskUnit(updateParams);
|
|
//进行风险管控措施关联
|
//设置所有关联本单元的管控措施的 UnitId为空
|
PreventDangerCheckWork work = preventDangerCheckWorkService.getWorkByTaskUnitId(taskUnitUpdateReqDTO.getId());
|
if (ObjectUtils.isNotEmpty(work)){
|
preventRiskControlMeasureService.updateControlMeasureByUnitId(taskUnitUpdateReqDTO.getId());
|
}
|
|
//便历措施Code集合,添加关联的taskUnitId的
|
if (taskUnitUpdateReqDTO.getMeasureList().size() > 0){
|
for (Long measureId : taskUnitUpdateReqDTO.getMeasureList()) {
|
PreventRiskControlMeasure controlMeasureById = preventRiskControlMeasureService.getControlMeasureById(measureId);
|
if (controlMeasureById.getCheckTaskUnitId() == null){
|
preventRiskControlMeasureService.updateControlMeasureByMeasureIdAndUnitId(measureId, taskUnitUpdateReqDTO.getId());
|
}else {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "该管控措施已经被单元管理");
|
}
|
}
|
}
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查任务单元-任务单元列表
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckTaskUnit> listTaskUnit(Long valueOf) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
List<PreventDangerCheckTaskUnitListQueryRespDTO> list = new ArrayList<>();
|
|
List<PreventDangerCheckTaskUnit> listTaskUnit = preventDangerCheckTaskUnitService.listTaskUnit();
|
if (ObjectUtils.isEmpty(listTaskUnit)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
for (PreventDangerCheckTaskUnit taskUnit : listTaskUnit) {
|
PreventDangerCheckWork workByTaskUnitId = preventDangerCheckWorkService.getWorkByTaskUnitId(taskUnit.getId());
|
if (ObjectUtils.isEmpty(workByTaskUnitId)){
|
PreventDangerCheckTaskUnitListQueryRespDTO respDTO = BeanCopyUtils.copyBean(taskUnit, PreventDangerCheckTaskUnitListQueryRespDTO.class);
|
list.add(respDTO);
|
}
|
}
|
|
resultVO.setData(list);
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查任务单元-删除
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckTaskUnit> deleteTaskUnit(Long userId, PreventDangerCheckTaskUnitDeleteReqDTO taskUnitDeleteReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
PreventDangerCheckTaskUnitDeleteParams deleteParams = new PreventDangerCheckTaskUnitDeleteParams();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (taskUnitDeleteReqDTO.getId() == null ){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容");
|
}
|
//获取需要填充的信息
|
Date date = new Date();
|
//封装删除需要的参数
|
deleteParams.setId(taskUnitDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
|
//设置所有关联本单元的措施的UnitId为空
|
PreventDangerCheckWork work = preventDangerCheckWorkService.getWorkByTaskUnitId(taskUnitDeleteReqDTO.getId());
|
if (ObjectUtils.isNotEmpty(work)){
|
preventRiskControlMeasureService.updateControlMeasureByUnitId(taskUnitDeleteReqDTO.getId());
|
}
|
int result = preventDangerCheckTaskUnitService.deleteTaskUnit(deleteParams);
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
//隐患排查作业
|
/**
|
* 隐患排查作业-分页查询
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckWork> getCheckWorkPage(Long userId, PreventDangerCheckWorkQueryReqDTO workQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventDangerCheckWorkQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = workQueryReqDTO.getPageIndex();
|
Integer pageSize = workQueryReqDTO.getPageSize();
|
|
//获取用户信息
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//如果传空字符串,转换为null
|
if (workQueryReqDTO.getCheckWorkName() == ""){
|
workQueryReqDTO.setCheckWorkName(null);
|
}
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_TASK_FROM_WORK.getCode());
|
//获取到所有符合条件的作业
|
IPage<PreventDangerCheckWork> page =
|
preventDangerCheckWorkService.getCheckWorkPage(new Page<>(pageIndex, pageSize), workQueryReqDTO);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//封装数据
|
//List<PreventDangerCheckWorkQueryRespDTO> respList = BeanCopyUtils.copyBeanList(page.getRecords(), PreventDangerCheckWorkQueryRespDTO.class);
|
|
for (PreventDangerCheckWork record : page.getRecords()) {
|
PreventDangerCheckWorkQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerCheckWorkQueryRespDTO.class);
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setPageSize((int) page.getSize());
|
if (record.getTaskUnitId() != null){
|
PreventDangerCheckTaskUnit taskUnit = preventDangerCheckTaskUnitService.getTaskUnitById(record.getTaskUnitId());
|
if (ObjectUtils.isNotEmpty(taskUnit)){
|
respDTO.setTaskUnitName(taskUnit.getTaskUnitName());
|
}
|
}
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
respDTO.setDepId(userById.getDepartment().getDepId());
|
list.add(respDTO);
|
}
|
resultVO.setCount((int) page.getTotal());
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查作业-查看检查内容
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckWork> getCheckWorkContent(Long userId, PreventDangerCheckWorkContentQueryReqDTO contentReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
List<String> checkContentList = new ArrayList<>();
|
|
if (contentReqDTO.getId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL,"");
|
}
|
|
//根据id,查询任务单元
|
PreventDangerCheckTaskUnit taskUnitByWorkId = preventDangerCheckTaskUnitService.getTaskUnitByWorkId(contentReqDTO.getId());
|
if (ObjectUtils.isEmpty(taskUnitByWorkId)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//如果结果不为空,查寻对应措施,得到检查内容并封装。
|
if (ObjectUtils.isNotEmpty(taskUnitByWorkId)){
|
//获取任务单元内的管控措施
|
List<PreventRiskControlMeasure> measureListByUnit = preventRiskControlMeasureService.getlistByUnitId(taskUnitByWorkId.getId());
|
//获取管控措施对应的内容
|
for (PreventRiskControlMeasure controlMeasure : measureListByUnit) {
|
PreventDangerCheckContent checkContents = preventDangerCheckContentService.getCheckContentByMeasureId(controlMeasure.getId());
|
checkContentList.add(checkContents.getCheckContent());
|
}
|
}
|
resultVO.setCount(checkContentList.size());
|
resultVO.setData(checkContentList);
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查作业-新增
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckWork> saveCheckWork(Long userId, PreventDangerCheckWorkSaveReqDTO workSaveReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("新增成功");
|
PreventDangerCheckWork checkWork = new PreventDangerCheckWork();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
|
//校验参数,并设置作业类型
|
if (workSaveReqDTO.getCheckWorkType() == 1){
|
checkWork.setCheckWorkType(workSaveReqDTO.getCheckWorkType());
|
}else if(workSaveReqDTO.getCheckWorkType() == 2) {
|
checkWork.setCheckWorkType(workSaveReqDTO.getCheckWorkType());
|
}else {
|
throw new AusinessException(E.DATA_PARAM_NULL, "作业类型选择错误");
|
}
|
//校验参数,并设置时间单位
|
if (workSaveReqDTO.getCheckCycleUnit() == 1){
|
checkWork.setCheckCycleUnit(workSaveReqDTO.getCheckCycleUnit());
|
}else if (workSaveReqDTO.getCheckCycleUnit() == 2) {
|
checkWork.setCheckCycleUnit(workSaveReqDTO.getCheckCycleUnit());
|
}else if (workSaveReqDTO.getCheckCycleUnit() == 3) {
|
checkWork.setCheckCycleUnit(workSaveReqDTO.getCheckCycleUnit());
|
}else if (workSaveReqDTO.getCheckCycleUnit() == 4) {
|
checkWork.setCheckCycleUnit(workSaveReqDTO.getCheckCycleUnit());
|
}else if (workSaveReqDTO.getCheckCycleUnit() == 5) {
|
checkWork.setCheckCycleUnit(workSaveReqDTO.getCheckCycleUnit());
|
}else {
|
throw new AusinessException(E.DATA_PARAM_NULL, "时间单位选择错误");
|
}
|
//校验普通参数
|
if (workSaveReqDTO.getCheckWorkName() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "作业名称不能为空");
|
}
|
//根据workName获取作业信息
|
PreventDangerCheckWork workByName = preventDangerCheckWorkService.getWorkByName(workSaveReqDTO.getCheckWorkName());
|
if (ObjectUtils.isNotEmpty(workByName)){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "作业名称已存在");
|
}
|
if (workSaveReqDTO.getCheckCycle() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "排查周期-数值不能为空");
|
}
|
if (workSaveReqDTO.getNoticeTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "提前通知时间-数值不能为空");
|
}
|
if (workSaveReqDTO.getValidTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "作业有效期不能为空");
|
}
|
if (workSaveReqDTO.getFirstStartTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "首次排查任务开始时间不能为空");
|
}
|
if (workSaveReqDTO.getExecDepId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "任务所属部门不能为空");
|
}
|
//校验部门是否存在
|
ResultVO<DepInfoRPCRespDTO> depInfo = accountDepartmentService.getDepInfoByDepId(userId, workSaveReqDTO.getExecDepId());
|
DepInfoRPCRespDTO execDep = (DepInfoRPCRespDTO)depInfo.getData();
|
if (ObjectUtils.isEmpty(execDep)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "该部门不存在或已被删除,请选择正确的部门");
|
}
|
if (workSaveReqDTO.getTaskUnitId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "任务单元不能为空");
|
}
|
PreventDangerCheckTaskUnit taskUnit = preventDangerCheckTaskUnitService.getTaskUnitById(workSaveReqDTO.getTaskUnitId());
|
if (ObjectUtils.isEmpty(taskUnit)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "该任务单元不存在或已被删除,请选择正确的任务单元");
|
}
|
//A方案 一个作业只能调度一个任务单元
|
PreventDangerCheckWork workByTaskUnitId =
|
preventDangerCheckWorkService.getWorkByTaskUnitId(workSaveReqDTO.getTaskUnitId());
|
if (ObjectUtils.isNotEmpty(workByTaskUnitId)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "该任务单元已经被【" +workByTaskUnitId.getCheckWorkName() +"】作业调度");
|
}
|
if (workSaveReqDTO.getFirstStartTime().getTime() < new Date().getTime()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "首次调度时间应该大于当前时间");
|
}
|
|
//获取巡检作业需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long checkWorkId = snowFlow.nextId();
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_TASK_FROM_WORK.getCode());
|
//封装参数
|
PreventDangerCheckWork checkWorkParams = BeanCopyUtils.copyBean(workSaveReqDTO, PreventDangerCheckWork.class);
|
|
checkWorkParams.setId(checkWorkId);
|
checkWorkParams.setUuid(uuid);
|
checkWorkParams.setCheckWorkStatus(WorkStatusEnum.WORK_OPEN.getCode());
|
checkWorkParams.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
checkWorkParams.setNextCheckTime(null);
|
checkWorkParams.setEnterpriseId((long) 1);
|
checkWorkParams.setEnterpriseUuid("111");
|
checkWorkParams.setExecDepUuid(null);
|
checkWorkParams.setExecDep(execDep.getDepName());
|
checkWorkParams.setGmtCreate(date);
|
checkWorkParams.setGmtModitify(date);
|
checkWorkParams.setCreateByUserName(userById.getRealName());
|
checkWorkParams.setLastEditUserName(userById.getRealName());
|
checkWorkParams.setTaskUnitUuid(taskUnit.getUuid());
|
checkWorkParams.setLastCheckTime(null);
|
checkWorkParams.setCreateByUserId(userId);
|
|
checkWorkParams.setReportTime(null);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()){
|
//自动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
checkWorkParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
checkWorkParams.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//设置本条数据上报更新时间
|
checkWorkParams.setUpdateReportDataTime(date);
|
}
|
//手动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
//设置上报状态为-不上报
|
checkWorkParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
checkWorkParams.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
checkWorkParams.setUpdateReportDataTime(date);
|
}
|
}
|
//如果主配置关闭上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_OFF.getCode()){
|
//设置上报状态为-不上报
|
checkWorkParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
checkWorkParams.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
checkWorkParams.setUpdateReportDataTime(date);
|
}
|
|
//插入作业
|
int result = preventDangerCheckWorkService.saveCheckWork(checkWorkParams);
|
if (result < 0){
|
throw new AusinessException(E.ADD_FAIL, "作业插入失败");
|
}
|
|
//作业与措施的关联表,暂时未使用,只为了上报数据使用
|
//获取措施list
|
List<PreventRiskControlMeasure> measureLists = preventRiskControlMeasureService.getlistByUnitId(workSaveReqDTO.getTaskUnitId());
|
PreventWorkAndMeasure workAndMeasure = new PreventWorkAndMeasure();
|
for (PreventRiskControlMeasure measureList : measureLists) {
|
String workAndMeasureUuid = UUID.randomUUID().toString();
|
workAndMeasure.setId(workAndMeasureUuid);
|
workAndMeasure.setWorkUuid(uuid);
|
workAndMeasure.setMeasureUuid(measureList.getUuid());
|
int resultWorkAndMeasure = preventWorkAndMeasureService.insertWorkAndMeasure(workAndMeasure);
|
if (resultWorkAndMeasure < 0){
|
throw new AusinessException(E.ADD_FAIL, "保存作业与措施的关系失败");
|
}
|
}
|
|
// /**创建作业时,立即进行第一次调度*/
|
// Date nextCheckTime = null;
|
// Date noticeTime = null;
|
// Byte ExecTaskTag;
|
//
|
// //TODO 排班改为在此处判断 暂无
|
// //解析任务通知时间毫秒数
|
// if (workSaveReqDTO.getNoticeTimeUnit() == 1) {
|
// //如果时间单位是分钟
|
// noticeTime = new Date(workSaveReqDTO.getFirstStartTime().getTime() - workSaveReqDTO.getNoticeTime() * 60 * 1000);
|
// }else if (workSaveReqDTO.getNoticeTimeUnit() == 2) {
|
// //如果时间单位是小时
|
// noticeTime = new Date(workSaveReqDTO.getFirstStartTime().getTime() - workSaveReqDTO.getNoticeTime() * 60 * 1000);
|
// }else if (workSaveReqDTO.getNoticeTimeUnit() == 3) {
|
// //如果时间单位是日
|
// noticeTime = new Date(workSaveReqDTO.getFirstStartTime().getTime() - workSaveReqDTO.getNoticeTime() * 24 * 60 * 60 * 1000);
|
// }else if (workSaveReqDTO.getNoticeTimeUnit() == 4) {
|
// //如果时间单位是月
|
// Calendar calendar = Calendar.getInstance();
|
// calendar.setTime(workSaveReqDTO.getFirstStartTime());//设置起时间
|
// calendar.add(Calendar.MONTH, -workSaveReqDTO.getNoticeTime());//增加N个月
|
// noticeTime = calendar.getTime();
|
// }
|
// //获取mq消息体
|
// PreventCreateTaskMsg preventCreateTaskMsg = new PreventCreateTaskMsg();
|
// preventCreateTaskMsg.setWorkId(checkWorkId);
|
// preventCreateTaskMsg.setCreateTaskTime(date);
|
// //发送消息
|
// SendResult sendResult = rocketMQTemplate.syncSend(preventCreateTaskTopic, preventCreateTaskMsg);
|
// if (sendResult.getSendStatus() != SendStatus.SEND_OK) {
|
// throw new BusinessException(ResultCodes.BUSINESS_ERROR);
|
// }
|
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查作业-修改
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckWork> updateCheckWork(Long userId, PreventDangerCheckWorkUpdateReqDTO workUpdateReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
PreventDangerCheckWork checkWork = new PreventDangerCheckWork();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数,并设置作业类型
|
if (workUpdateReqDTO.getCheckWorkType() == 1){
|
checkWork.setCheckWorkType(workUpdateReqDTO.getCheckWorkType());
|
}else if(workUpdateReqDTO.getCheckWorkType() == 2) {
|
checkWork.setCheckWorkType(workUpdateReqDTO.getCheckWorkType());
|
}else {
|
throw new AusinessException(E.DATA_PARAM_NULL, "作业类型选择错误");
|
}
|
//校验参数,并设置时间单位
|
if (workUpdateReqDTO.getCheckCycleUnit() == 1){
|
checkWork.setCheckCycleUnit(workUpdateReqDTO.getCheckCycleUnit());
|
}else if (workUpdateReqDTO.getCheckCycleUnit() == 2) {
|
checkWork.setCheckCycleUnit(workUpdateReqDTO.getCheckCycleUnit());
|
}else if (workUpdateReqDTO.getCheckCycleUnit() == 3) {
|
checkWork.setCheckCycleUnit(workUpdateReqDTO.getCheckCycleUnit());
|
}else if (workUpdateReqDTO.getCheckCycleUnit() == 4) {
|
checkWork.setCheckCycleUnit(workUpdateReqDTO.getCheckCycleUnit());
|
}else if (workUpdateReqDTO.getCheckCycleUnit() == 5) {
|
checkWork.setCheckCycleUnit(workUpdateReqDTO.getCheckCycleUnit());
|
}else {
|
throw new AusinessException(E.DATA_PARAM_NULL, "时间单位选择错误");
|
}
|
//校验参数,并设置作业状态
|
if (workUpdateReqDTO.getCheckWorkType() == 1 ){
|
checkWork.setCheckWorkStatus(workUpdateReqDTO.getCheckWorkStatus());
|
}else if (workUpdateReqDTO.getCheckCycleUnit() == 2) {
|
checkWork.setCheckWorkStatus(workUpdateReqDTO.getCheckWorkStatus());
|
}else if (workUpdateReqDTO.getCheckCycleUnit() == 3) {
|
checkWork.setCheckWorkStatus(workUpdateReqDTO.getCheckWorkStatus());
|
}
|
//校验普通参数
|
if (workUpdateReqDTO.getId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL,"");
|
}
|
if (workUpdateReqDTO.getCheckWorkName() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "作业名称不能为空");
|
}
|
//根据workName获取作业信息
|
PreventDangerCheckWork workByName = preventDangerCheckWorkService.getWorkByName(workUpdateReqDTO.getCheckWorkName());
|
if (ObjectUtils.isNotEmpty(workByName) && !workByName.getId().equals(workUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "作业名称已存在");
|
}
|
if (workUpdateReqDTO.getCheckCycle() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "排查周期-数值不能为空");
|
}
|
if (workUpdateReqDTO.getNoticeTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "提前通知时间-数值不能为空");
|
}
|
if (workUpdateReqDTO.getValidTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "作业有效期不能为空");
|
}
|
|
if (workUpdateReqDTO.getExecDepId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "执行部门不能为空");
|
}
|
//校验部门是否存在
|
ResultVO<DepInfoRPCRespDTO> depInfo = accountDepartmentService.getDepInfoByDepId(userId, workUpdateReqDTO.getExecDepId());
|
DepInfoRPCRespDTO execDep = (DepInfoRPCRespDTO)depInfo.getData();
|
if (ObjectUtils.isEmpty(execDep)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "该部门不存在或已被删除,请选择正确的部门");
|
}
|
if (workUpdateReqDTO.getTaskUnitId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "任务单元不能为空");
|
}
|
PreventDangerCheckTaskUnit taskUnit = preventDangerCheckTaskUnitService.getTaskUnitById(workUpdateReqDTO.getTaskUnitId());
|
if (ObjectUtils.isEmpty(taskUnit)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "该任务单元不存在或已被删除,请选择正确的任务单元");
|
}
|
//A方案 一个作业只能调度一个任务单元,或者若干个管控措施
|
PreventDangerCheckWork workByTaskUnitId =
|
preventDangerCheckWorkService.getWorkByTaskUnitId(workUpdateReqDTO.getTaskUnitId());
|
if (ObjectUtils.isNotEmpty(workByTaskUnitId) && !workByTaskUnitId.getId().equals(workUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_PARAM_NULL, "该任务单元已经被" +workByTaskUnitId.getCheckWorkName() +"作业调度");
|
}
|
if (workUpdateReqDTO.getFirstStartTime().getTime() < new Date().getTime()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "首次调度时间应该大于当前时间");
|
}
|
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_TASK_FROM_WORK.getCode());
|
Date date = new Date();
|
//封装参数
|
PreventDangerCheckWorkUpdateParams updateParams = BeanCopyUtils.copyBean(workUpdateReqDTO, PreventDangerCheckWorkUpdateParams.class);
|
|
updateParams.setGmtModitify(date);
|
updateParams.setLastEditUserName(userById.getRealName());
|
updateParams.setExecDep(execDep.getDepName());
|
updateParams.setTaskUnitUuid(taskUnit.getUuid());
|
updateParams.setNextCheckTime(null);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()){
|
//自动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
updateParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
updateParams.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//设置本条数据上报更新时间
|
updateParams.setUpdateReportDataTime(date);
|
}
|
//手动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
//设置上报状态为-不上报
|
updateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
updateParams.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
updateParams.setUpdateReportDataTime(date);
|
}
|
}
|
//如果主配置关闭上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_OFF.getCode()){
|
//设置上报状态为-不上报
|
updateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
updateParams.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
updateParams.setUpdateReportDataTime(date);
|
}
|
|
int result = preventDangerCheckWorkService.updateCheckWork(updateParams);
|
//获取当前作业
|
PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(workUpdateReqDTO.getId());
|
//重置作业与措施的关联
|
preventWorkAndMeasureService.updateWorkAndMeasure(workById.getUuid());
|
//获取措施list
|
List<PreventRiskControlMeasure> measureLists = preventRiskControlMeasureService.getlistByUnitId(workUpdateReqDTO.getTaskUnitId());
|
PreventWorkAndMeasure workAndMeasure = new PreventWorkAndMeasure();
|
for (PreventRiskControlMeasure measureList : measureLists) {
|
String workAndMeasureUuid = UUID.randomUUID().toString();
|
workAndMeasure.setId(workAndMeasureUuid);
|
workAndMeasure.setWorkUuid(workById.getUuid());
|
workAndMeasure.setMeasureUuid(measureList.getUuid());
|
int resultWorkAndMeasure = preventWorkAndMeasureService.insertWorkAndMeasure(workAndMeasure);
|
if (resultWorkAndMeasure < 0){
|
throw new AusinessException(E.ADD_FAIL, "保存作业与措施的关系失败");
|
}
|
}
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查作业-列表
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckWork> listCheckWork(Long valueOf) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventDangerCheckWork> listCheckWork = preventDangerCheckWorkService.listCheckWork();
|
if (ObjectUtils.isEmpty(listCheckWork)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
List<PreventDangerCheckWorkListQueryRespDTO> respDTOS =
|
BeanCopyUtils.copyBeanList(listCheckWork, PreventDangerCheckWorkListQueryRespDTO.class);
|
|
resultVO.setData(respDTOS);
|
return resultVO;
|
}
|
/**
|
* 排查作业-手工上报-配置
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateCheckWorkReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
if (preventHandReportConfigReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
if (preventHandReportConfigReqDTO.getReportSwitch() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
//查询当前隐患的配置
|
PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(preventHandReportConfigReqDTO.getId());
|
//配置相同,做处理
|
if (workById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同");
|
}
|
int result ;
|
//读取主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_TASK_FROM_WORK.getCode());
|
//只有当开启上报,且类型为手动上报时,可以修改
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
result = preventDangerCheckWorkService.updateCheckWorkReport(preventHandReportConfigReqDTO);
|
|
}else {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作");
|
}
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查作业-删除
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckWork> deleteCheckWork(Long userId, PreventDangerCheckWorkDeleteReqDTO workDeleteReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
PreventDangerCheckWorkDeleteParams deleteParams = new PreventDangerCheckWorkDeleteParams();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (workDeleteReqDTO.getId() == null ){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容");
|
}
|
//获取需要填充的信息
|
Date date = new Date();
|
//封装删除需要的参数
|
deleteParams.setId(workDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(date);
|
|
//删除作业
|
int result = preventDangerCheckWorkService.deleteCheckWork(deleteParams);
|
|
//获取当前作业
|
PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(workDeleteReqDTO.getId());
|
//重置作业与措施的关联
|
preventWorkAndMeasureService.updateWorkAndMeasure(workById.getUuid());
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
//隐患排查任务
|
/**
|
* 隐患排查任务-分页查询
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckTask> getTaskPage(Long userId, PreventDangerCheckTaskQueryReqDTO taskQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
Integer pageIndex = taskQueryReqDTO.getPageIndex();
|
Integer pageSize = taskQueryReqDTO.getPageSize();
|
List<PreventDangerCheckTaskQueryRespDTO> list = new ArrayList<>();
|
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG__CHECK_RECORD.getCode());
|
|
//获取到所有符合条件任务
|
IPage<PreventDangerCheckTask> page =
|
preventDangerCheckTaskService.getTaskPage(new Page<>(pageIndex, pageSize), taskQueryReqDTO);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//遍历任务集合,取出所有的排查任务信息。
|
for (PreventDangerCheckTask record : page.getRecords()) {
|
PreventDangerCheckTaskQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerCheckTaskQueryRespDTO.class);
|
//根据taskId查询任务关联的检查内容
|
List<PreventTaskAndMeasure> listByTaskId = preventTaskAndMeasureService.getListByTaskId(record.getId());
|
//获取隐患排查内容的list
|
List<PreventrCheckContentRespDTO> preventCheckContentRespDTOS = new ArrayList<>();
|
//封装措施数据
|
if (listByTaskId.size() > 0){
|
for (PreventTaskAndMeasure taskAndMeasure : listByTaskId) {
|
PreventrCheckContentRespDTO checkContentRespDTO = BeanCopyUtils.copyBean(taskAndMeasure, PreventrCheckContentRespDTO.class);
|
PreventRiskControlMeasure controlMeasure = preventRiskControlMeasureService.getControlMeasureById(taskAndMeasure.getControlMeasureId());
|
if (ObjectUtils.isNotEmpty(controlMeasure)){
|
checkContentRespDTO.setControlType(controlMeasure.getControlType());
|
checkContentRespDTO.setClassify1(controlMeasure.getClassify1());
|
checkContentRespDTO.setClassify2(controlMeasure.getClassify2());
|
checkContentRespDTO.setClassify3(controlMeasure.getClassify3());
|
if (controlMeasure.getMeasureDesc() != null){
|
checkContentRespDTO.setMeasureDesc(controlMeasure.getMeasureDesc());
|
}
|
if (controlMeasure.getControlMeasureCode() != null){
|
checkContentRespDTO.setControlMeasureCode(controlMeasure.getControlMeasureCode());
|
}
|
}
|
preventCheckContentRespDTOS.add(checkContentRespDTO);
|
}
|
}
|
// PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(record.getCheckWorkId());
|
ResultVO<DepInfoRPCRespDTO> depInfo = accountDepartmentService.getDepInfoByDepId(record.getExecDepId());
|
DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO)depInfo.getData();
|
respDTO.setExecDep(dep.getDepName());
|
respDTO.setCheckContent(preventCheckContentRespDTOS);
|
//封装任务数据
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setPageSize((int) page.getSize());
|
//封装排查内容数据
|
list.add(respDTO);
|
}
|
|
resultVO.setCount((int) page.getTotal());
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
/**
|
* 排查任务-认领任务
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckTask> taskToUser(ContextCacheUser currentUser, PreventDangerCheckTaskDeleteReqDTO taskToUserDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("认领成功");
|
|
//校验
|
PreventDangerCheckTask taskById = preventDangerCheckTaskService.getTaskById(taskToUserDTO.getId());
|
|
if (ObjectUtils.isEmpty(taskById)){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "传参错误,未找到对应任务");
|
}
|
if (ObjectUtils.isNotEmpty(taskById)){
|
if (taskById.getExecUserId() != null){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "当前任务已经被人认领");
|
}
|
if (taskById.getTaskStatus() == 3){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "当前任务已经超时,无法认领");
|
}
|
if (taskById.getTaskStatus() == 2){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "任务已结束,无法认领");
|
}
|
PreventTaskToUserParams taskToUserParams = new PreventTaskToUserParams();
|
//封装参数
|
taskToUserParams.setId(taskToUserDTO.getId());
|
taskToUserParams.setExecUserId(currentUser.getUid());
|
taskToUserParams.setExecUserName(currentUser.getRealName());
|
taskToUserParams.setLastEditUserName(currentUser.getRealName());
|
taskToUserParams.setGmtModitify(new Date());
|
taskToUserParams.setTaskBelong((byte) 2);
|
//执行修改,认领任务
|
int result = preventDangerCheckTaskService.taskToUser(taskToUserParams);
|
resultVO.setCount(result);
|
}
|
|
return resultVO;
|
}
|
|
/**
|
* 排查任务-手工上报-配置
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateCheckTaskReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
if (preventHandReportConfigReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
if (preventHandReportConfigReqDTO.getReportSwitch() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
//查询当前隐患的配置
|
PreventDangerCheckTask taskById = preventDangerCheckTaskService.getTaskById(preventHandReportConfigReqDTO.getId());
|
//配置相同,做处理
|
if (taskById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同");
|
}
|
int result ;
|
//读取主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG__CHECK_RECORD.getCode());
|
//只有当开启上报,且类型为手动上报时,可以修改
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
result = preventDangerCheckTaskService.updateCheckTaskReport(preventHandReportConfigReqDTO);
|
|
}else {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查任务-手动新增--暂时不提供
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckTask> saveTask(Long userId, PreventDangerCheckTaskSaveReqDTO taskSaveReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("新增成功");
|
PreventDangerCheckTask checkTask = new PreventDangerCheckTask();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (taskSaveReqDTO.getStartTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请填写任务开始时间");
|
}
|
if (taskSaveReqDTO.getValidTime() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请填写任务有效时间");
|
}
|
if (taskSaveReqDTO.getExecUserId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请填写执行人姓名");
|
}
|
//获取执行人信息
|
ResultVO<UserRPCRespDTO> execUserResult = accountAuthService.getUserById(taskSaveReqDTO.getExecUserId());
|
UserRPCRespDTO execUser = (UserRPCRespDTO)execUserResult.getData();
|
if (ObjectUtils.isEmpty(execUser)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请填写正确的执行人姓名");
|
}
|
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long taskId = snowFlow.nextId();
|
|
List<Long> measureIdList = new ArrayList<>();
|
//判断任务单元是否为空,不为空,则取出措施id
|
if (taskSaveReqDTO.getTaskUnitId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请选择任务单元");
|
}
|
|
//根据查找单元信息
|
PreventDangerCheckTaskUnit taskUnitById = preventDangerCheckTaskUnitService.getTaskUnitById(taskSaveReqDTO.getTaskUnitId());
|
if (ObjectUtils.isEmpty(taskUnitById)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的任务单元");
|
}
|
//根据单元id查找对应措施id列表-->measureList
|
List<PreventRiskControlMeasure> measureList = preventRiskControlMeasureService.getlistByUnitId(taskSaveReqDTO.getTaskUnitId());
|
//如果单元内措施列表不为空,遍历集合,取出措施id
|
if (measureIdList.size() > 0) {
|
for (Long measureId : measureIdList) {
|
measureIdList.add(measureId);
|
}
|
}
|
//设置任务参数
|
checkTask.setCheckTaskUnitId(taskSaveReqDTO.getTaskUnitId());
|
checkTask.setCheckTaskUnitUuid(taskUnitById.getUuid());
|
// //取出管控措施集合的id
|
// for (Long measureId : taskSaveReqDTO.getControlMeasureId()) {
|
// measureIdList.add(measureId);
|
// }
|
//封装数据
|
checkTask.setId(taskId);
|
checkTask.setUuid(uuid);
|
//
|
checkTask.setStartTime(taskSaveReqDTO.getStartTime());
|
checkTask.setValidTime(taskSaveReqDTO.getValidTime());
|
checkTask.setNoticeTime(date);//需要改为通知时间
|
checkTask.setGmtCreate(date);
|
checkTask.setGmtModitify(date);
|
checkTask.setCreateUserName(userById.getRealName());
|
checkTask.setLastEditUserName(userById.getRealName());
|
checkTask.setResult(null);
|
checkTask.setTaskStatus(WorkStatusEnum.TASK_WAIT.getCode());
|
checkTask.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
checkTask.setCheckWorkId(null);
|
checkTask.setCheckWorkUuid(null);
|
checkTask.setTaskType(WorkStatusEnum.TASK_TYPE_USER_ADD.getCode());
|
checkTask.setTaskCode("task"+ date.toString());//TODO 暂定位task+时间
|
checkTask.setExecUserId(taskSaveReqDTO.getExecUserId());
|
checkTask.setExecUserName(execUser.getRealName());
|
checkTask.setEnterpriseId((long) 1);
|
checkTask.setEnterpriseUuid("111");
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG__CHECK_RECORD.getCode());
|
checkTask.setReportTime(null);
|
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()){
|
//自动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
checkTask.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
checkTask.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//设置本条数据上报更新时间
|
checkTask.setUpdateReportDataTime(date);
|
}
|
//手动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
//设置上报状态为-不上报
|
checkTask.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
checkTask.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
checkTask.setUpdateReportDataTime(date);
|
}
|
}
|
//如果主配置关闭上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_OFF.getCode()){
|
//设置上报状态为-不上报
|
checkTask.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
checkTask.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
checkTask.setUpdateReportDataTime(date);
|
}
|
|
//任务插入
|
int result = preventDangerCheckTaskService.saveTask(checkTask);
|
|
//保存管控措施与任务关联,添加检查内容
|
PreventTaskAndMeasure taskAndMeasure = new PreventTaskAndMeasure();
|
for (Long measureId : measureIdList) {
|
//得到管控措施对应的检查内容
|
PreventDangerCheckContent checkContent = preventDangerCheckContentService.getCheckContentByMeasureId(measureId);
|
//封装数据
|
taskAndMeasure.setCheckTaskId(taskId);
|
taskAndMeasure.setControlMeasureId(measureId);
|
taskAndMeasure.setCheckContent(checkContent.getCheckContent());
|
preventTaskAndMeasureService.saveTaskAndMeasure(taskAndMeasure);
|
}
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
/**
|
* 隐患排查任务-调度
|
*/
|
@Transactional
|
@Override
|
public boolean createAutoTask(Long workId) {
|
|
logger.info("\n【##】自动生成作业-检索作业信息");
|
boolean createResult = false;
|
//查询对应的作业,获取信息
|
PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(workId);
|
|
if (ObjectUtils.isEmpty(workById.getTaskUnitId())){
|
logger.info("【双重预防】任务对应单元已被删除,停止调度");
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST,"任务对应单元已被删除,停止调度");
|
}
|
|
if (ObjectUtils.isEmpty(workById)){
|
return createResult;
|
}
|
|
//0、加分布式锁
|
String lockName = "PREVENT_TASK_CREATE_"+workId;
|
RLock createTaskLock = redissonClient.getLock(lockName);
|
createTaskLock.lock(3, TimeUnit.SECONDS);
|
|
PreventDangerCheckTask checkTask = new PreventDangerCheckTask();
|
|
//获取调度任务时,需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long taskId = snowFlow.nextId();
|
Date validTime = null;
|
Date noticeTime = null;
|
Date nextCheckTime = null;
|
Date checkTime = null;
|
//如果是第一次调度,以firstTime为标准;否则以nextTime为标准
|
if (ObjectUtils.isNotEmpty(workById.getNextCheckTime())){
|
//解析任务有效时间,以本次调度时的预期下次执行时间为基础计算
|
if (workById.getValidTimeUnit() == 1) {
|
//如果时间单位是分钟
|
validTime = new Date(workById.getNextCheckTime().getTime() + workById.getValidTimeUnit() * 60 * 1000);
|
}else if (workById.getValidTimeUnit() == 2) {
|
//如果时间单位是小时
|
validTime = new Date(workById.getNextCheckTime().getTime() + workById.getValidTimeUnit() * 60 * 60 * 1000);
|
}else if (workById.getValidTimeUnit() == 3) {
|
//如果时间单位是日
|
validTime = new Date(workById.getNextCheckTime().getTime() + workById.getValidTimeUnit() * 24 * 60 * 60 * 1000);
|
}else if (workById.getValidTimeUnit() == 4) {
|
//如果时间单位是月
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(workById.getNextCheckTime());//设置起时间
|
calendar.add(Calendar.MONTH, workById.getValidTimeUnit());//增加N个月
|
validTime = calendar.getTime();
|
}
|
//解析任务通知时间
|
if (workById.getNoticeTimeUnit() == 1) {
|
//如果时间单位是分钟
|
noticeTime = new Date(workById.getNextCheckTime().getTime() - workById.getNoticeTimeUnit() * 60 * 1000);
|
}else if (workById.getNoticeTimeUnit() == 2) {
|
//如果时间单位是小时
|
noticeTime = new Date(workById.getNextCheckTime().getTime() - workById.getNoticeTimeUnit() * 60 * 1000);
|
}else if (workById.getNoticeTimeUnit() == 3) {
|
//如果时间单位是日
|
noticeTime = new Date(workById.getNextCheckTime().getTime() - workById.getNoticeTimeUnit() * 24 * 60 * 60 * 1000);
|
}else if (workById.getNoticeTimeUnit() == 4) {
|
//如果时间单位是月
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(workById.getNextCheckTime());//设置起时间
|
calendar.add(Calendar.MONTH, -workById.getNoticeTimeUnit());//增加N个月
|
noticeTime = calendar.getTime();
|
}
|
checkTime = workById.getNextCheckTime();
|
}else {
|
//解析任务有效时间,以本次调度时的预期下次执行时间为基础计算
|
if (workById.getValidTimeUnit() == 1) {
|
//如果时间单位是分钟
|
validTime = new Date(workById.getFirstStartTime().getTime() + workById.getNoticeTimeUnit() * 60 * 1000);
|
}else if (workById.getValidTimeUnit() == 2) {
|
//如果时间单位是小时
|
validTime = new Date(workById.getFirstStartTime().getTime() + workById.getNoticeTimeUnit() * 60 * 60 * 1000);
|
}else if (workById.getValidTimeUnit() == 3) {
|
//如果时间单位是日
|
validTime = new Date(workById.getFirstStartTime().getTime() + workById.getNoticeTimeUnit() * 24 * 60 * 60 * 1000);
|
}else if (workById.getValidTimeUnit() == 4) {
|
//如果时间单位是月
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(workById.getFirstStartTime());//设置起时间
|
calendar.add(Calendar.MONTH, workById.getValidTimeUnit());//增加N个月
|
validTime = calendar.getTime();
|
}
|
//解析任务通知时间
|
if (workById.getNoticeTimeUnit() == 1) {
|
//如果时间单位是分钟
|
noticeTime = new Date(workById.getFirstStartTime().getTime() - workById.getNoticeTimeUnit() * 60 * 1000);
|
}else if (workById.getNoticeTimeUnit() == 2) {
|
//如果时间单位是小时
|
noticeTime = new Date(workById.getFirstStartTime().getTime() - workById.getNoticeTimeUnit() * 60 * 1000);
|
}else if (workById.getNoticeTimeUnit() == 3) {
|
//如果时间单位是日
|
noticeTime = new Date(workById.getFirstStartTime().getTime() - workById.getNoticeTimeUnit() * 24 * 60 * 60 * 1000);
|
}else if (workById.getNoticeTimeUnit() == 4) {
|
//如果时间单位是月
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(workById.getFirstStartTime());//设置起时间
|
calendar.add(Calendar.MONTH, -workById.getNoticeTimeUnit());//增加N个月
|
noticeTime = calendar.getTime();
|
}
|
checkTime = workById.getFirstStartTime();
|
}
|
|
|
//1、加分布式锁锁3秒期间,判断任务是否已经生成,如果已经生成,结束方法
|
PreventDangerCheckTask taskByCheckWorkIdAndStartTime = preventDangerCheckTaskService.getTaskByCheckWorkIdAndStartTime(workId, checkTime);
|
if (ObjectUtils.isNotEmpty(taskByCheckWorkIdAndStartTime)){
|
logger.info("任务已被创建");
|
return false;
|
}
|
|
//解析调度周期时间间隔,work的下次执行时间
|
if (workById.getCheckCycleUnit() == 1) {
|
//如果时间单位是分钟
|
nextCheckTime = new Date(validTime.getTime() + workById.getCheckCycle() * 60 * 1000);
|
}else if (workById.getCheckCycleUnit() == 2) {
|
//如果时间单位是小时
|
nextCheckTime = new Date(validTime.getTime() + workById.getCheckCycle() * 60 * 60 * 1000);
|
}else if (workById.getCheckCycleUnit() == 3) {
|
//如果时间单位是日
|
nextCheckTime = new Date(validTime.getTime() + workById.getCheckCycle() * 24 * 60 * 60 * 1000);
|
}else if (workById.getCheckCycleUnit() == 4) {
|
//如果时间单位是月
|
nextCheckTime = new Date(validTime.getTime() + workById.getCheckCycle() * 24 * 60 * 60 * 1000);
|
}
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG__CHECK_RECORD.getCode());
|
//封装任务数据
|
checkTask.setId(taskId);
|
checkTask.setUuid(uuid);
|
checkTask.setStartTime(checkTime);
|
checkTask.setValidTime(validTime);
|
checkTask.setNoticeTime(noticeTime);
|
checkTask.setGmtCreate(date);
|
checkTask.setGmtModitify(date);
|
checkTask.setCreateUserName(workById.getCreateByUserName());
|
checkTask.setLastEditUserName(workById.getCreateByUserName());
|
checkTask.setResult((byte) 3);//排查结果:1-正常,2-存在隐患,3-未处理
|
checkTask.setTaskStatus(WorkStatusEnum.TASK_WAIT.getCode());
|
checkTask.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
checkTask.setCheckWorkId(workId);
|
checkTask.setCheckWorkUuid(workById.getUuid());
|
checkTask.setTaskCode(workById.getCheckWorkName());
|
checkTask.setExecUserId(null);
|
checkTask.setExecUserName(null);
|
checkTask.setEnterpriseId((long) 1);
|
checkTask.setEnterpriseUuid("111");
|
checkTask.setDesc(null);
|
checkTask.setExecDepId(workById.getExecDepId());
|
checkTask.setExecDepUuid(null);
|
checkTask.setTaskType(workById.getCheckWorkType());
|
checkTask.setTaskBelong((byte) 1);
|
// if (workById.getCheckWorkStatus().equals(WorkStatusEnum.TASK_TYPE_AUTO.getCode())){
|
// checkTask.setTaskType((byte) 1);
|
// }
|
// if (workById.getCheckWorkStatus().equals(WorkStatusEnum.TASK_TYPE_USER_ADD.getCode())){
|
// checkTask.setTaskType((byte) 2);
|
// }
|
//任务参数
|
checkTask.setCheckTaskUnitId(workById.getId());
|
checkTask.setCheckTaskUnitUuid(workById.getUuid());
|
checkTask.setReportTime(null);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()){
|
//自动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
checkTask.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
checkTask.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//设置本条数据上报更新时间
|
checkTask.setUpdateReportDataTime(date);
|
}
|
//手动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
//设置上报状态为-不上报
|
checkTask.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
checkTask.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
checkTask.setUpdateReportDataTime(date);
|
}
|
}
|
//如果主配置关闭上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_OFF.getCode()){
|
//设置上报状态为-不上报
|
checkTask.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
checkTask.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
checkTask.setUpdateReportDataTime(date);
|
}
|
|
int step = 1;
|
|
/**写入任务信息*/
|
int taskResult = preventDangerCheckTaskService.saveTask(checkTask);
|
|
if (taskResult > 0) {
|
PreventTaskAndMeasure taskAndMeasure = new PreventTaskAndMeasure();
|
//查询任务单元对应的管控错措施列表
|
List<PreventRiskControlMeasure> measureList = preventRiskControlMeasureService.getlistByUnitId(workById.getTaskUnitId());
|
/**保存管控措施与任务的关联 */
|
for (PreventRiskControlMeasure measure : measureList) {
|
//得到管控措施对应的检查内容
|
PreventDangerCheckContent checkContent = preventDangerCheckContentService.getCheckContentByMeasureId(measure.getId());
|
//封装数据
|
taskAndMeasure.setId(null);
|
taskAndMeasure.setCheckTaskId(taskId);
|
taskAndMeasure.setControlMeasureId(measure.getId());
|
taskAndMeasure.setCheckContent(checkContent.getCheckContent());
|
taskAndMeasure.setCheckResult((byte) 3);//单项检查结果:1-正常,2-异常,3-未处理
|
taskAndMeasure.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
int result = preventTaskAndMeasureService.saveTaskAndMeasure(taskAndMeasure);
|
if (result == 0){
|
throw new AusinessException(E.ADD_FAIL, "保存对应检查内容失败");
|
}
|
}
|
step = 2;
|
}else {
|
throw new AusinessException(E.ADD_FAIL, "保存任务信息失败");
|
}
|
|
/**修改作业信息*/
|
if (step == 2){
|
CheckWorkAutoUpdateParams updateWorkParams = new CheckWorkAutoUpdateParams();
|
//封装修改参数
|
updateWorkParams.setId(workById.getId());
|
updateWorkParams.setLastCheckTime(checkTime);
|
updateWorkParams.setNextCheckTime(nextCheckTime);
|
if (workById.getCheckWorkType() == 2){
|
updateWorkParams.setCheckWorkStatus((byte) 2);
|
}else if (workById.getCheckWorkType() == 1){
|
updateWorkParams.setCheckWorkStatus((byte) 4);
|
}
|
int result = preventDangerCheckWorkService.updateCheckWorkLastTimeAndNextTime(updateWorkParams);
|
System.out.println("\n【##】修改作业状态成功" + new Date());
|
if (result == 0) {
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
|
}
|
step = 3;
|
}else {
|
throw new AusinessException(E.ADD_FAIL, "修改下次调度时间失败");
|
}
|
|
if(step == 3){
|
//发送执行提醒消息
|
PreventNoticeExecTaskMsg preventNoticeExecTaskMsg = new PreventNoticeExecTaskMsg();
|
preventNoticeExecTaskMsg.setTaskId(taskId);
|
preventNoticeExecTaskMsg.setNoticeTaskTime(noticeTime);
|
SendResult sendResult = rocketMQTemplate.syncSend(preventNoticeTaskTopic, preventNoticeExecTaskMsg);
|
if (sendResult.getSendStatus() != SendStatus.SEND_OK){
|
throw new RuntimeException("MQ发送任务通知信息失败");
|
}
|
logger.info("\n【##】向Notice消息\t" + "MSG ID : " + sendResult.getMsgId()+"\t" +
|
"预计执行时间" + preventNoticeExecTaskMsg.getNoticeTaskTime());
|
step = 4;
|
}else {
|
logger.info("第3步出错");
|
}
|
|
/**向MQ发送消息*/
|
if (step == 4){
|
//发送待执行消息
|
PreventWaitExecTaskMsg preventWaitExecTaskMsg = new PreventWaitExecTaskMsg();
|
//TASK ID
|
preventWaitExecTaskMsg.setTaskId(taskId);
|
//预期执行时间
|
preventWaitExecTaskMsg.setExecTaskTime(workById.getNextCheckTime());
|
SendResult sendResult = rocketMQTemplate.syncSend(preventWaitWorkTopic, preventWaitExecTaskMsg);
|
if (sendResult.getSendStatus() != SendStatus.SEND_OK){
|
throw new RuntimeException("MQ发送作业等待信息失败");
|
}
|
logger.info("\n【##】向WaitExec消息\t" + "MSG ID : " + sendResult.getMsgId()+"\t" +
|
"预计执行时间" + preventWaitExecTaskMsg.getExecTaskTime());
|
step = 5;
|
}else {
|
logger.info("第4步出错");
|
}
|
|
if(step == 5){
|
//发送 改为 任务可调度状态
|
if (workById.getCheckWorkType() == 1){
|
PreventTimeOutTaskMsg preventTimeOutTaskMsg = new PreventTimeOutTaskMsg();
|
preventTimeOutTaskMsg.setTaskId(taskId);
|
preventTimeOutTaskMsg.setWorkId(workId);
|
preventTimeOutTaskMsg.setOutTaskTime(validTime);
|
SendResult sendResult =rocketMQTemplate.syncSend(preventTimeOutTaskTopic, preventTimeOutTaskMsg);
|
if (sendResult.getSendStatus() != SendStatus.SEND_OK){
|
throw new RuntimeException("MQ发送任务状态变更通知信息失败");
|
}
|
logger.info("\n【##】向TimeOut消息\t"+ "MSG ID : " + sendResult.getMsgId()+"\t" +
|
"预计执行时间" +preventTimeOutTaskMsg.getOutTaskTime());
|
}
|
step = 6;
|
createResult = true;
|
}else {
|
logger.info("第5步出错");
|
}
|
|
if (step ==6) {
|
System.out.println("\n【##】任务创建完成:" + taskId + "----任务开始时间" + workById.getNextCheckTime());
|
}else {
|
logger.info("第6步出错");
|
}
|
|
//释放分布式锁
|
createTaskLock.unlock();
|
|
return createResult;
|
}
|
|
/**
|
* 隐患排查任务-数据上报
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerCheckTask> updateTask(Long userId, PreventDangerCheckTaskUpdateReqDTO taskUpdateReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("任务结果提交成功");
|
PreventDangerCheckTaskUpdateParams updateParams = new PreventDangerCheckTaskUpdateParams();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userInfo = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userInfo)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
|
//获取执行人信息
|
PreventDangerCheckTask taskById = preventDangerCheckTaskService.getTaskById(taskUpdateReqDTO.getId());
|
UserRPCRespDTO execUser = (UserRPCRespDTO)rpcResult.getData();
|
if (taskById.getExecUserId() .equals(userInfo.getUid())){
|
throw new AusinessException(E.DATA_PARAM_NULL, "非认领人,无法操作");
|
}
|
if (taskUpdateReqDTO.getCheckResults().size() <= 0){
|
throw new AusinessException(E.DATA_PARAM_NULL, "检查结果不能为空");
|
}
|
|
|
//获取需要填充的信息
|
int tag = 0;
|
Byte resultTag = 1;
|
PreventCheckResultParams checkResultParams = new PreventCheckResultParams();
|
for (CheckResultReportDO CheckResults : taskUpdateReqDTO.getCheckResults()) {
|
//封装填报参数
|
checkResultParams.setId(CheckResults.getId());
|
checkResultParams.setCheckResult(CheckResults.getCheckResult());
|
checkResultParams.setControlMeasureId(CheckResults.getControlMeasureId());
|
preventTaskAndMeasureService.updateCheckResult(checkResultParams);
|
tag = tag + 1;
|
if (CheckResults.getCheckResult().equals(WorkStatusEnum.TASK_EXEC_RESULT_ERROR.getCode())){
|
resultTag = WorkStatusEnum.TASK_EXEC_RESULT_ERROR.getCode();
|
}
|
}
|
if (tag < taskUpdateReqDTO.getCheckResults().size()){
|
throw new AusinessException(E.UPDATE_FAIL, "填报遇到问题,请稍后再尝试");
|
}
|
|
updateParams.setId(taskUpdateReqDTO.getId());
|
updateParams.setLastEditUserName(userInfo.getRealName());
|
updateParams.setGmtModitify(new Date());
|
updateParams.setTaskStatus(WorkStatusEnum.TASK_EXEC_USED.getCode());
|
updateParams.setResult(resultTag);
|
int result = preventDangerCheckTaskService.updateTask(updateParams);
|
if (result < 1){
|
throw new AusinessException(E.UPDATE_FAIL, "任务结果提交失败");
|
}
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患排查任务-删除
|
*/
|
@Override
|
public ResultVO<PreventDangerCheckTask> deleteTask(Long userId, PreventDangerCheckTaskDeleteReqDTO taskDeleteReqDTO) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
PreventDeleteParams deleteParams = new PreventDeleteParams();
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (taskDeleteReqDTO.getId() == null ){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请选择正确的查询内容");
|
}
|
Date date = new Date();
|
//封装参数
|
deleteParams.setId(taskDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(date);
|
|
int deleteResult = preventDangerCheckTaskService.deleteTask(deleteParams);
|
|
resultVO.setCount(deleteResult);
|
|
return resultVO;
|
}
|
|
}
|