package com.gk.hotwork.doublePrevention.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gk.hotwork.Domain.DepartmentInfo; import com.gk.hotwork.Domain.UserInfo; import com.gk.hotwork.Domain.co.ContextCacheUser; import com.gk.hotwork.Domain.Exception.E; import com.gk.hotwork.Domain.Enum.ResultCodes; import com.gk.hotwork.Domain.Exception.BusinessException; import com.gk.hotwork.Domain.dto.UserRPCRespDTO; import com.gk.hotwork.Service.DepartmentService; import com.gk.hotwork.Service.Middle.AccountAuthService; import com.gk.hotwork.Service.Middle.AccountDepartmentService; import com.gk.hotwork.Service.UserService; import com.gk.hotwork.doublePrevention.utils.BeanCopyUtils; import com.gk.hotwork.doublePrevention.utils.SnowFlow; import com.gk.hotwork.Domain.Vo.ResultVO; import com.gk.hotwork.doublePrevention.entity.*; import com.gk.hotwork.doublePrevention.entity.dto.CheckResultReportDO; import com.gk.hotwork.doublePrevention.entity.dto.req.*; import com.gk.hotwork.doublePrevention.entity.dto.resp.*; import com.gk.hotwork.doublePrevention.enums.StatusEnum; import com.gk.hotwork.doublePrevention.enums.SyncEnum; import com.gk.hotwork.doublePrevention.enums.WorkStatusEnum; import com.gk.hotwork.doublePrevention.mq.msg.PreventNoticeExecTaskMsg; import com.gk.hotwork.doublePrevention.mq.msg.PreventTimeOutTaskMsg; import com.gk.hotwork.doublePrevention.mq.msg.PreventWaitExecTaskMsg; import com.gk.hotwork.doublePrevention.repository.param.*; import com.gk.hotwork.doublePrevention.service.DangerService; import com.gk.hotwork.doublePrevention.service.baseService.*; import org.apache.commons.lang3.ObjectUtils; 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.security.core.parameters.P; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.xml.crypto.Data; import java.util.*; import java.util.concurrent.TimeUnit; @Service public class DangerServiceImpl implements DangerService { @Autowired private AccountAuthService accountAuthService; @Autowired private UserService userService; @Autowired 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 DepartmentService departmentService; @Autowired private PreventTaskUnitAndMeasureService preventTaskUnitAndMeasureService; @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 getTaskUnitPage(Long userId, PreventDangerCheckTaskUnitQueryReqDTO taskUnitQueryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); List measureList = new ArrayList<>(); List list = new ArrayList<>(); Integer pageIndex = taskUnitQueryReqDTO.getPageIndex(); Integer pageSize = taskUnitQueryReqDTO.getPageSize(); //获取用户信息 ResultVO 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 page = preventDangerCheckTaskUnitService.getTaskUnitPage(new Page<>(pageIndex, pageSize), taskUnitQueryReqDTO); if (ObjectUtils.isEmpty(page)){ resultVO.setMsg("查询成功,无数据"); return resultVO; } //遍历结果集,封装数据 for (PreventDangerCheckTaskUnit record : page.getRecords()) { //拷贝任务单元数据 PreventDangerCheckTaskUnitQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerCheckTaskUnitQueryRespDTO.class); //获取当前任务单元关联的所有管控措施 List measureLists = preventTaskUnitAndMeasureService.getListByUnitId(record.getId()); //封装管控措施编码 if (measureLists.size() > 0){ List measureContentList = new ArrayList<>(); for (PreventTaskUnitAndMeasure controlMeasure : measureLists) { PreventDangerCheckContent checkContent = preventDangerCheckContentService.getCheckContentByMeasureId(controlMeasure.getMeasureId()); PreventRiskControlMeasureDataRespDTO measure = BeanCopyUtils.copyBean(controlMeasure, PreventRiskControlMeasureDataRespDTO.class); measure.setCheckContent(checkContent.getCheckContent()); measure.setId(controlMeasure.getMeasureId()); 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 saveTaskUnit(Long userId, PreventDangerCheckTaskUnitSaveReqDTO taskUnitSaveReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("新增成功"); PreventDangerCheckTaskUnit taskUnit = new PreventDangerCheckTaskUnit(); ResultVO 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 BusinessException(E.DATA_PARAM_NULL, "隐患排查任务单元名称不能为空"); } //检查是否存在同名任务单元 PreventDangerCheckTaskUnit taskUnitByName = preventDangerCheckTaskUnitService.getTaskUnitByName(taskUnitSaveReqDTO.getTaskUnitName()); if (ObjectUtils.isNotEmpty(taskUnitByName)){ throw new BusinessException(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()); if (ObjectUtils.isEmpty(taskUnitSaveReqDTO.getNote())){ taskUnit.setNote(null); } taskUnit.setNote(taskUnitSaveReqDTO.getNote()); //执行新增单元操作 int result = preventDangerCheckTaskUnitService.saveTaskUnit(taskUnit); //保存管控措施与任务单元的关联 if (taskUnitSaveReqDTO.getMeasureList().size() > 0){ for (Long measureId : taskUnitSaveReqDTO.getMeasureList()) { //获取任务单元与措施关联对象 PreventTaskUnitAndMeasure taskUnitAndMeasure = new PreventTaskUnitAndMeasure(); //查询管控措施 PreventRiskControlMeasure controlMeasureById = preventRiskControlMeasureService.getControlMeasureById(measureId); //封装参数 taskUnitAndMeasure.setTaskUnitId(taskUnitId); taskUnitAndMeasure.setTaskUnitUuid(uuid); taskUnitAndMeasure.setMeasureId(measureId); taskUnitAndMeasure.setMeasureUuid(controlMeasureById.getUuid()); taskUnitAndMeasure.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode()); taskUnitAndMeasure.setGmtCreate(date); taskUnitAndMeasure.setCreateByUserName(userById.getRealName()); taskUnitAndMeasure.setGmtModitify(date); taskUnitAndMeasure.setLastEditUserName(userById.getRealName()); preventTaskUnitAndMeasureService.insert(taskUnitAndMeasure); } } resultVO.setCount(result); return resultVO; } /** * 隐患排查任务单元-修改 */ @Transactional @Override public ResultVO updateTaskUnit(Long userId, PreventDangerCheckTaskUnitUpdateReqDTO taskUnitUpdateReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("修改成功"); PreventDangerCheckTaskUnitUpdateParams updateParams = new PreventDangerCheckTaskUnitUpdateParams(); ResultVO 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 BusinessException(E.DATA_PARAM_NULL, "隐患排查任务单元名称不能为空"); } //检查是否存在同名任务单元 PreventDangerCheckTaskUnit taskUnitByName = preventDangerCheckTaskUnitService.getTaskUnitByName(taskUnitUpdateReqDTO.getTaskUnitName()); //如果查询结果不为空,且入参Id与查询到的Id不相等,判断是存在同名任务单元 if (ObjectUtils.isNotEmpty(taskUnitByName) && !taskUnitByName.getId().equals(taskUnitUpdateReqDTO.getId())){ throw new BusinessException(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); //重置关联关系 PreventTaskUnitAndMeasureParams taskUnitAndMeasureParams = new PreventTaskUnitAndMeasureParams(); taskUnitAndMeasureParams.setTaskUnitId(taskUnitUpdateReqDTO.getId()); taskUnitAndMeasureParams.setGmtModitify(date); taskUnitAndMeasureParams.setLastEditUserName(userById.getRealName()); taskUnitAndMeasureParams.setDeleteStatus(StatusEnum.DELETE_STATUS_DISCARD.getCode()); preventTaskUnitAndMeasureService.deleteTaskUnitAndMeasure(taskUnitAndMeasureParams); //便历措施Code集合,添加关联信息 if (taskUnitUpdateReqDTO.getMeasureList().size() > 0){ for (Long measureId : taskUnitUpdateReqDTO.getMeasureList()) { //获取任务单元与措施关联对象 PreventTaskUnitAndMeasure taskUnitAndMeasure = new PreventTaskUnitAndMeasure(); //查询管控措施 PreventRiskControlMeasure controlMeasureById = preventRiskControlMeasureService.getControlMeasureById(measureId); PreventDangerCheckTaskUnit taskUnitById = preventDangerCheckTaskUnitService.getTaskUnitById(taskUnitUpdateReqDTO.getId()); //封装参数 taskUnitAndMeasure.setTaskUnitId(taskUnitUpdateReqDTO.getId()); taskUnitAndMeasure.setTaskUnitUuid(taskUnitById.getUuid()); taskUnitAndMeasure.setMeasureId(measureId); taskUnitAndMeasure.setMeasureUuid(controlMeasureById.getUuid()); taskUnitAndMeasure.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode()); taskUnitAndMeasure.setGmtCreate(date); taskUnitAndMeasure.setCreateByUserName(userById.getRealName()); taskUnitAndMeasure.setGmtModitify(date); taskUnitAndMeasure.setLastEditUserName(userById.getRealName()); preventTaskUnitAndMeasureService.insert(taskUnitAndMeasure); } } resultVO.setCount(result); return resultVO; } /** * 隐患排查任务单元-任务单元列表 */ @Override public ResultVO listTaskUnit(Long valueOf) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); List list = new ArrayList<>(); List listTaskUnit = preventDangerCheckTaskUnitService.listTaskUnit(); 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 deleteTaskUnit(Long userId, PreventDangerCheckTaskUnitDeleteReqDTO taskUnitDeleteReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("删除成功"); PreventDangerCheckTaskUnitDeleteParams deleteParams = new PreventDangerCheckTaskUnitDeleteParams(); ResultVO 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 BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容"); } //获取需要填充的信息 Date date = new Date(); //封装删除需要的参数 deleteParams.setId(taskUnitDeleteReqDTO.getId()); deleteParams.setGmtModitify(date); deleteParams.setLastEditUserName(userById.getRealName()); //检查该单元是否有措施 List listByUnitId = preventTaskUnitAndMeasureService.getListByUnitId(taskUnitDeleteReqDTO.getId()); //重置关联关系 if (listByUnitId != null && listByUnitId.size() > 0){ PreventTaskUnitAndMeasureParams taskUnitAndMeasureParams = new PreventTaskUnitAndMeasureParams(); taskUnitAndMeasureParams.setTaskUnitId(taskUnitDeleteReqDTO.getId()); taskUnitAndMeasureParams.setGmtModitify(date); taskUnitAndMeasureParams.setLastEditUserName(userById.getRealName()); taskUnitAndMeasureParams.setDeleteStatus(StatusEnum.DELETE_STATUS_DISCARD.getCode()); preventTaskUnitAndMeasureService.deleteTaskUnitAndMeasure(taskUnitAndMeasureParams); } //删除单元 int result = preventDangerCheckTaskUnitService.deleteTaskUnit(deleteParams); resultVO.setCount(result); return resultVO; } //隐患排查作业 /** * 隐患排查作业-分页查询 */ @Override public ResultVO getCheckWorkPage(Long userId, PreventDangerCheckWorkQueryReqDTO workQueryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); List list = new ArrayList<>(); Integer pageIndex = workQueryReqDTO.getPageIndex(); Integer pageSize = workQueryReqDTO.getPageSize(); //获取用户信息 ResultVO 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 page = preventDangerCheckWorkService.getCheckWorkPage(new Page<>(pageIndex, pageSize), workQueryReqDTO); if (ObjectUtils.isEmpty(page)){ resultVO.setMsg("查询成功,无数据"); return resultVO; } //封装数据 //List 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 getCheckWorkContent(Long userId, PreventDangerCheckWorkContentQueryReqDTO contentReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); List checkContentList = new ArrayList<>(); if (contentReqDTO.getId() == null ){ throw new BusinessException(E.DATA_PARAM_NULL,""); } //根据id,查询任务单元 PreventDangerCheckTaskUnit taskUnitByWorkId = preventDangerCheckTaskUnitService.getTaskUnitByWorkId(contentReqDTO.getId()); //如果结果不为空,查寻对应措施,得到检查内容并封装。 if (ObjectUtils.isNotEmpty(taskUnitByWorkId)){ //获取任务单元内的管控措施 List 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 saveCheckWork(Long userId, PreventDangerCheckWorkSaveReqDTO workSaveReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("新增成功"); PreventDangerCheckWork checkWork = new PreventDangerCheckWork(); ResultVO 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 BusinessException(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 BusinessException(E.DATA_PARAM_NULL, "时间单位选择错误"); } //校验普通参数 if (workSaveReqDTO.getCheckWorkName() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "作业名称不能为空"); } //根据workName获取作业信息 PreventDangerCheckWork workByName = preventDangerCheckWorkService.getWorkByName(workSaveReqDTO.getCheckWorkName()); if (ObjectUtils.isNotEmpty(workByName)){ throw new BusinessException(E.DATA_DATABASE_EXIST, "作业名称已存在"); } if (workSaveReqDTO.getCheckCycle() == null){ throw new BusinessException(E.DATA_PARAM_NULL, "排查周期-数值不能为空"); } if (workSaveReqDTO.getNoticeTime() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "提前通知时间-数值不能为空"); } if (workSaveReqDTO.getValidTime() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "作业有效期不能为空"); } if (workSaveReqDTO.getFirstStartTime() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "首次排查任务开始时间不能为空"); } if (workSaveReqDTO.getExecDepId() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "任务所属部门不能为空"); } //校验部门是否存在 DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(workSaveReqDTO.getExecDepId()); if (ObjectUtils.isEmpty(departmentInfo)){ throw new BusinessException(E.DATA_PARAM_NULL, "该部门不存在或已被删除,请选择正确的部门"); } if (workSaveReqDTO.getTaskUnitId() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "任务单元不能为空"); } PreventDangerCheckTaskUnit taskUnit = preventDangerCheckTaskUnitService.getTaskUnitById(workSaveReqDTO.getTaskUnitId()); if (ObjectUtils.isEmpty(taskUnit)){ throw new BusinessException(E.DATA_PARAM_NULL, "该任务单元不存在或已被删除,请选择正确的任务单元"); } //A方案 一个作业只能调度一个任务单元 PreventDangerCheckWork workByTaskUnitId = preventDangerCheckWorkService.getWorkByTaskUnitId(workSaveReqDTO.getTaskUnitId()); if (ObjectUtils.isNotEmpty(workByTaskUnitId)){ throw new BusinessException(E.DATA_PARAM_NULL, "该任务单元已经被【" +workByTaskUnitId.getCheckWorkName() +"】作业调度"); } if (workSaveReqDTO.getFirstStartTime().getTime() < new Date().getTime()){ throw new BusinessException(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(workSaveReqDTO.getFirstStartTime()); checkWorkParams.setEnterpriseId((long) 1); checkWorkParams.setEnterpriseUuid("111"); checkWorkParams.setExecDepUuid(null); checkWorkParams.setExecDep(departmentInfo.getDepartment()); 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 BusinessException(E.ADD_FAIL, "作业插入失败"); } //作业与措施的关联表,暂时未使用,只为了上报数据使用 //获取措施list todo 此处有问题 // List measureLists = preventRiskControlMeasureService.getlistByUnitId(workSaveReqDTO.getTaskUnitId()); List listByUnitId = preventTaskUnitAndMeasureService.getListByUnitId(workSaveReqDTO.getTaskUnitId()); PreventWorkAndMeasure workAndMeasure = new PreventWorkAndMeasure(); for (PreventTaskUnitAndMeasure unitAndMeasure : listByUnitId) { String workAndMeasureUuid = UUID.randomUUID().toString(); workAndMeasure.setId(workAndMeasureUuid); workAndMeasure.setWorkUuid(uuid); workAndMeasure.setWorkId(checkWorkId); workAndMeasure.setMeasureId(unitAndMeasure.getMeasureId()); workAndMeasure.setMeasureUuid(unitAndMeasure.getMeasureUuid()); int resultWorkAndMeasure = preventWorkAndMeasureService.insertWorkAndMeasure(workAndMeasure); if (resultWorkAndMeasure < 1){ throw new BusinessException(E.ADD_FAIL, "保存作业与措施的关系失败"); } } resultVO.setCount(result); return resultVO; } /** * 隐患排查作业-修改 */ @Transactional @Override public ResultVO updateCheckWork(Long userId, PreventDangerCheckWorkUpdateReqDTO workUpdateReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("修改成功"); PreventDangerCheckWork checkWork = new PreventDangerCheckWork(); ResultVO 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 BusinessException(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 BusinessException(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 BusinessException(E.DATA_PARAM_NULL,""); } if (workUpdateReqDTO.getCheckWorkName() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "作业名称不能为空"); } //根据workName获取作业信息 PreventDangerCheckWork workByName = preventDangerCheckWorkService.getWorkByName(workUpdateReqDTO.getCheckWorkName()); if (ObjectUtils.isNotEmpty(workByName) && !workByName.getId().equals(workUpdateReqDTO.getId())){ throw new BusinessException(E.DATA_DATABASE_EXIST, "作业名称已存在"); } // if (workUpdateReqDTO.getCheckWorkStatus() == null){ // throw new BusinessException(E.DATA_DATABASE_EXIST, "作业状态不能为空"); // } if (workUpdateReqDTO.getCheckCycle() == null){ throw new BusinessException(E.DATA_PARAM_NULL, "排查周期-数值不能为空"); } if (workUpdateReqDTO.getNoticeTime() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "提前通知时间-数值不能为空"); } if (workUpdateReqDTO.getValidTime() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "作业有效期不能为空"); } if (workUpdateReqDTO.getExecDepId() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "执行部门不能为空"); } //校验部门是否存在 // ResultVO depInfo = accountDepartmentService.getDepInfoByDepId(userId, workUpdateReqDTO.getExecDepId()); // DepInfoRPCRespDTO execDep = (DepInfoRPCRespDTO)depInfo.getData(); DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(workUpdateReqDTO.getExecDepId()); if (ObjectUtils.isEmpty(departmentInfo)){ throw new BusinessException(E.DATA_PARAM_NULL, "该部门不存在或已被删除,请选择正确的部门"); } if (workUpdateReqDTO.getTaskUnitId() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "任务单元不能为空"); } PreventDangerCheckTaskUnit taskUnit = preventDangerCheckTaskUnitService.getTaskUnitById(workUpdateReqDTO.getTaskUnitId()); if (ObjectUtils.isEmpty(taskUnit)){ throw new BusinessException(E.DATA_PARAM_NULL, "该任务单元不存在或已被删除,请选择正确的任务单元"); } //A方案 一个作业只能调度一个任务单元,或者若干个管控措施 PreventDangerCheckWork workByTaskUnitId = preventDangerCheckWorkService.getWorkByTaskUnitId(workUpdateReqDTO.getTaskUnitId()); if (ObjectUtils.isNotEmpty(workByTaskUnitId) && !workByTaskUnitId.getId().equals(workUpdateReqDTO.getId())){ throw new BusinessException(E.DATA_PARAM_NULL, "该任务单元已经被" +workByTaskUnitId.getCheckWorkName() +"作业调度"); } if (workUpdateReqDTO.getFirstStartTime().getTime() < new Date().getTime()){ throw new BusinessException(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(departmentInfo.getDepartment()); updateParams.setTaskUnitUuid(taskUnit.getUuid()); updateParams.setNextCheckTime(workUpdateReqDTO.getFirstStartTime()); //读取上报主配置,进行任务记录上报配置,如果开启上报功能 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()); if (!workUpdateReqDTO.getTaskUnitId().equals(workById.getTaskUnitId())){ if (ObjectUtils.isNotEmpty(preventWorkAndMeasureService.getWorkAndMeasureByWorkUuid(workById.getUuid()))){ //重置作业与措施的关联 preventWorkAndMeasureService.updateWorkAndMeasure(workById.getUuid()); } } //作业与措施的关联表,暂时未使用,只为了上报数据使用 //获取措施list // List 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 BusinessException(E.ADD_FAIL, "保存作业与措施的关系失败"); // } // } List listByUnitId = preventTaskUnitAndMeasureService.getListByUnitId(workUpdateReqDTO.getTaskUnitId()); PreventWorkAndMeasure workAndMeasure = new PreventWorkAndMeasure(); for (PreventTaskUnitAndMeasure unitAndMeasure : listByUnitId) { String workAndMeasureUuid = UUID.randomUUID().toString(); workAndMeasure.setId(workAndMeasureUuid); workAndMeasure.setWorkUuid(workById.getUuid()); workAndMeasure.setWorkId(workById.getId()); workAndMeasure.setMeasureId(unitAndMeasure.getMeasureId()); workAndMeasure.setMeasureUuid(unitAndMeasure.getMeasureUuid()); int resultWorkAndMeasure = preventWorkAndMeasureService.insertWorkAndMeasure(workAndMeasure); if (resultWorkAndMeasure < 1){ throw new BusinessException(E.ADD_FAIL, "保存作业与措施的关系失败"); } } resultVO.setCount(result); return resultVO; } /** * 隐患排查作业-列表 */ @Override public ResultVO listCheckWork(Long valueOf) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); List listCheckWork = preventDangerCheckWorkService.listCheckWork(); List respDTOS = BeanCopyUtils.copyBeanList(listCheckWork, PreventDangerCheckWorkListQueryRespDTO.class); resultVO.setData(respDTOS); return resultVO; } /** * 排查作业-手工上报-配置 */ @Override public ResultVO updateCheckWorkReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("修改成功"); ResultVO 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 BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法"); } if (preventHandReportConfigReqDTO.getReportSwitch() == null){ throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法"); } //查询当前隐患的配置 PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(preventHandReportConfigReqDTO.getId()); //配置相同,做处理 if (workById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){ throw new BusinessException(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 BusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作"); } resultVO.setCount(result); return resultVO; } /** * 隐患排查作业-删除 */ @Transactional @Override public ResultVO deleteCheckWork(Long userId, PreventDangerCheckWorkDeleteReqDTO workDeleteReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("删除成功"); PreventDangerCheckWorkDeleteParams deleteParams = new PreventDangerCheckWorkDeleteParams(); ResultVO 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 BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容"); } //获取需要填充的信息 Date date = new Date(); //封装删除需要的参数 deleteParams.setId(workDeleteReqDTO.getId()); deleteParams.setGmtModitify(date); deleteParams.setLastEditUserName(userById.getRealName()); deleteParams.setUpdateReportDataTime(date); //获取当前作业 PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(workDeleteReqDTO.getId()); if (ObjectUtils.isNotEmpty(preventWorkAndMeasureService.getWorkAndMeasureByWorkUuid(workById.getUuid()))){ //重置作业与措施的关联 preventWorkAndMeasureService.updateWorkAndMeasure(workById.getUuid()); } //删除作业 int result = preventDangerCheckWorkService.deleteCheckWork(deleteParams); resultVO.setCount(result); return resultVO; } //隐患排查任务 /** * 隐患排查任务-分页查询 */ @Override public ResultVO getTaskPage(Long userId, PreventDangerCheckTaskQueryReqDTO taskQueryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = taskQueryReqDTO.getPageIndex(); Integer pageSize = taskQueryReqDTO.getPageSize(); List list = new ArrayList<>(); //获取用户信息 ResultVO 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 page = preventDangerCheckTaskService.getTaskPage(new Page<>(pageIndex, pageSize), taskQueryReqDTO); if (ObjectUtils.isEmpty(page)){ resultVO.setMsg("查询成功,无数据"); return resultVO; } List taskIdLists = new ArrayList<>(); //取出所有符合条件的任务的id for (PreventDangerCheckTask record : page.getRecords()) { taskIdLists.add(record.getId()); } //取出所有符合条件的任务和措施的对应关系 List taskAndMeasureList = preventTaskAndMeasureService.getListByTaskIdByIdList(taskIdLists); //取出所有符合条件的措施id List measureIdList = new ArrayList<>(); for (PreventTaskAndMeasure preventTaskAndMeasure : taskAndMeasureList) { measureIdList.add(preventTaskAndMeasure.getControlMeasureId()); } //取出所有符合条件措施 List controlMeasureList = preventRiskControlMeasureService.getControlMeasureAndContent(measureIdList); //取出所有部门 List departmentList = departmentService.listDepartmentInfoById(); //遍历任务集合,匹配封装排查任务信息。 //1、遍历所有符合条件的任务 for (PreventDangerCheckTask task : page.getRecords()) { //封装task数据 PreventDangerCheckTaskQueryRespDTO respDTO = BeanCopyUtils.copyBean(task, PreventDangerCheckTaskQueryRespDTO.class); //获取隐患排查内容的list List checkContentRespDTOS = new ArrayList<>(); //2、遍历所有符合条件的对应关系 for (PreventTaskAndMeasure taskAndMeasure : taskAndMeasureList) { if (taskAndMeasure.getCheckTaskId().equals(task.getId())){ //3、遍历所有符合条件的措施数据 for (PreventRiskControlMeasure measure : controlMeasureList) { //4、匹配到任务对应的措施信息,封装检查内容 if (measure.getId().equals(taskAndMeasure.getControlMeasureId())){ PreventrCheckContentRespDTO checkInfo = BeanCopyUtils.copyBean(taskAndMeasure, PreventrCheckContentRespDTO.class); checkInfo.setControlType(measure.getControlType()); checkInfo.setClassify1(measure.getClassify1()); checkInfo.setClassify2(measure.getClassify2()); checkInfo.setClassify3(measure.getClassify3()); checkInfo.setMeasureDesc(measure.getMeasureDesc()); checkInfo.setControlMeasureCode(measure.getControlMeasureCode()); checkContentRespDTOS.add(checkInfo); } } } } //4、遍历部门信息,封装任务执行部门 for (DepartmentInfo department : departmentList) { if (department.getId().equals(task.getExecDepId())){ respDTO.setExecDep(department.getDepartment()); } } respDTO.setCheckContent(checkContentRespDTOS); 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 getTaskPageForMobile(Long userId, PreventDangerCheckTaskQueryReqDTO taskQueryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = taskQueryReqDTO.getPageIndex(); Integer pageSize = taskQueryReqDTO.getPageSize(); List list = new ArrayList<>(); //获取用户信息 ResultVO 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 page = preventDangerCheckTaskService.getTaskPageForMobile(new Page<>(pageIndex, pageSize), taskQueryReqDTO); if (ObjectUtils.isEmpty(page)){ resultVO.setMsg("查询成功,无数据"); return resultVO; } List controlMeasureList = preventRiskControlMeasureService.listAllControlMeasure(); //遍历任务集合,取出所有的排查任务信息。 for (PreventDangerCheckTask record : page.getRecords()) { //取出任务和措施的对应关系 List listByTaskId = preventTaskAndMeasureService.getListByTaskId(record.getId()); PreventDangerCheckTaskQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerCheckTaskQueryRespDTO.class); //获取隐患排查内容的list List preventCheckContentRespDTOS = new ArrayList<>(); //封装措施数据 for (PreventTaskAndMeasure taskAndMeasure : listByTaskId) { PreventrCheckContentRespDTO checkContentRespDTO = BeanCopyUtils.copyBean(taskAndMeasure, PreventrCheckContentRespDTO.class); for (PreventRiskControlMeasure measure : controlMeasureList) { if (measure.getId().equals(taskAndMeasure.getControlMeasureId())){ checkContentRespDTO.setControlType(measure.getControlType()); checkContentRespDTO.setClassify1(measure.getClassify1()); checkContentRespDTO.setClassify2(measure.getClassify2()); checkContentRespDTO.setClassify3(measure.getClassify3()); checkContentRespDTO.setMeasureDesc(measure.getMeasureDesc()); checkContentRespDTO.setControlMeasureCode(measure.getControlMeasureCode()); } } preventCheckContentRespDTOS.add(checkContentRespDTO); // } respDTO.setCheckContent(preventCheckContentRespDTOS); DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(record.getExecDepId()); respDTO.setExecDep(departmentInfo.getDepartment()); //封装任务数据 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; } /** * 隐患排查任务-分页查询-手机端使用-test */ @Override public ResultVO getTaskPageForMobileTest(Long userId, PreventDangerCheckTaskQueryReqDTO taskQueryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = taskQueryReqDTO.getPageIndex(); Integer pageSize = taskQueryReqDTO.getPageSize(); List list = new ArrayList<>(); // System.out.println("进入方法"); //获取用户信息 ResultVO 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 page = preventDangerCheckTaskService.getTaskPageForMobile(new Page<>(pageIndex, pageSize), taskQueryReqDTO); if (ObjectUtils.isEmpty(page)){ resultVO.setMsg("查询成功,无数据"); return resultVO; } if (ObjectUtils.isEmpty(page.getRecords())){ resultVO.setMsg("查询成功,无数据"); return resultVO; } List taskIdLists = new ArrayList<>(); //取出所有符合条件的任务的id for (PreventDangerCheckTask record : page.getRecords()) { taskIdLists.add(record.getId()); } //取出所有符合条件的任务和措施的对应关系 List taskAndMeasureList = preventTaskAndMeasureService.getListByTaskIdByIdList(taskIdLists); //取出所有符合条件的措施id List measureIdList = new ArrayList<>(); for (PreventTaskAndMeasure preventTaskAndMeasure : taskAndMeasureList) { measureIdList.add(preventTaskAndMeasure.getControlMeasureId()); } //取出所有符合条件措施 List controlMeasureList = preventRiskControlMeasureService.getControlMeasureAndContent(measureIdList); //取出所有部门 List departmentList = departmentService.listDepartmentInfoById(); //遍历任务集合,匹配封装排查任务信息。 //1、遍历所有符合条件的任务 for (PreventDangerCheckTask task : page.getRecords()) { //封装task数据 PreventDangerCheckTaskQueryRespDTO respDTO = BeanCopyUtils.copyBean(task, PreventDangerCheckTaskQueryRespDTO.class); //获取隐患排查内容的list List checkContentRespDTOS = new ArrayList<>(); //2、遍历所有符合条件的对应关系 for (PreventTaskAndMeasure taskAndMeasure : taskAndMeasureList) { if (taskAndMeasure.getCheckTaskId().equals(task.getId())){ //3、遍历所有符合条件的措施数据 for (PreventRiskControlMeasure measure : controlMeasureList) { //4、匹配到任务对应的措施信息,封装检查内容 if (measure.getId().equals(taskAndMeasure.getControlMeasureId())){ PreventrCheckContentRespDTO checkInfo = BeanCopyUtils.copyBean(taskAndMeasure, PreventrCheckContentRespDTO.class); checkInfo.setControlType(measure.getControlType()); checkInfo.setClassify1(measure.getClassify1()); checkInfo.setClassify2(measure.getClassify2()); checkInfo.setClassify3(measure.getClassify3()); checkInfo.setMeasureDesc(measure.getMeasureDesc()); checkInfo.setControlMeasureCode(measure.getControlMeasureCode()); checkContentRespDTOS.add(checkInfo); } } } } //4、遍历部门信息,封装任务执行部门 for (DepartmentInfo department : departmentList) { if (department.getId().equals(task.getExecDepId())){ respDTO.setExecDep(department.getDepartment()); } } respDTO.setCheckContent(checkContentRespDTOS); 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 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 BusinessException(E.DATA_DATABASE_EXIST, "传参错误,未找到对应任务"); } if (ObjectUtils.isNotEmpty(taskById)){ if (taskById.getExecUserId() != null){ throw new BusinessException(E.DATA_DATABASE_EXIST, "当前任务已经被人认领"); } if (taskById.getTaskStatus() == 3){ throw new BusinessException(E.DATA_DATABASE_EXIST, "当前任务已经超时,无法认领"); } if (taskById.getTaskStatus() == 2){ throw new BusinessException(E.DATA_DATABASE_EXIST, "任务已结束,无法认领"); } Date date = new Date(); PreventTaskToUserParams taskToUserParams = new PreventTaskToUserParams(); //封装参数 taskToUserParams.setId(taskToUserDTO.getId()); taskToUserParams.setExecUserId(currentUser.getUid()); taskToUserParams.setExecUserName(currentUser.getRealName()); taskToUserParams.setLastEditUserName(currentUser.getRealName()); taskToUserParams.setGmtModitify(date); taskToUserParams.setTaskBelong((byte) 2); taskToUserParams.setBelongTime(date); //执行修改,认领任务 int result = preventDangerCheckTaskService.taskToUser(taskToUserParams); resultVO.setCount(result); } return resultVO; } /** * 排查任务-手工上报-配置 */ @Override public ResultVO updateCheckTaskReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("修改成功"); ResultVO 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 BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法"); } if (preventHandReportConfigReqDTO.getReportSwitch() == null){ throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法"); } //查询当前隐患的配置 PreventDangerCheckTask taskById = preventDangerCheckTaskService.getTaskById(preventHandReportConfigReqDTO.getId()); //配置相同,做处理 if (taskById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){ throw new BusinessException(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 BusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作"); } resultVO.setCount(result); return resultVO; } /** * 隐患排查任务-手动新增--暂时不提供 */ @Transactional @Override public ResultVO saveTask(Long userId, PreventDangerCheckTaskSaveReqDTO taskSaveReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("新增成功"); PreventDangerCheckTask checkTask = new PreventDangerCheckTask(); ResultVO 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 BusinessException(E.DATA_PARAM_NULL, "请填写任务开始时间"); } if (taskSaveReqDTO.getValidTime() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "请填写任务有效时间"); } if (taskSaveReqDTO.getExecUserId() == null ){ throw new BusinessException(E.DATA_PARAM_NULL, "请填写执行人姓名"); } //获取执行人信息 ResultVO execUserResult = accountAuthService.getUserById(taskSaveReqDTO.getExecUserId()); UserRPCRespDTO execUser = (UserRPCRespDTO)execUserResult.getData(); if (ObjectUtils.isEmpty(execUser)){ throw new BusinessException(E.DATA_PARAM_NULL, "请填写正确的执行人姓名"); } //获取需要填充的信息 SnowFlow snowFlow = new SnowFlow();//雪花算法生成器 String uuid = UUID.randomUUID().toString(); Date date = new Date(); long taskId = snowFlow.nextId(); List measureIdList = new ArrayList<>(); //判断任务单元是否为空,不为空,则取出措施id if (taskSaveReqDTO.getTaskUnitId() == null){ throw new BusinessException(E.DATA_PARAM_NULL, "请选择任务单元"); } //查找单元信息 PreventDangerCheckTaskUnit taskUnitById = preventDangerCheckTaskUnitService.getTaskUnitById(taskSaveReqDTO.getTaskUnitId()); if (ObjectUtils.isEmpty(taskUnitById)){ throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的任务单元"); } //根据单元id查找对应措施id列表-->measureList // List measureList = preventRiskControlMeasureService.getlistByUnitId(taskSaveReqDTO.getTaskUnitId()); List listByUnitId = preventTaskUnitAndMeasureService.getListByUnitId(taskSaveReqDTO.getTaskUnitId()); //如果单元内措施列表不为空,遍历集合,取出措施id if (listByUnitId.size() > 0) { for (PreventTaskUnitAndMeasure taskUnitAndMeasure : listByUnitId) { measureIdList.add(taskUnitAndMeasure.getMeasureId()); } } //设置任务参数 checkTask.setCheckTaskUnitId(taskSaveReqDTO.getTaskUnitId()); checkTask.setCheckTaskUnitUuid(taskUnitById.getUuid()); //封装数据 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) { boolean createResult = false; //查询对应的作业,获取信息 PreventDangerCheckWork workById = preventDangerCheckWorkService.getWorkById(workId); if (ObjectUtils.isEmpty(workById.getTaskUnitId())){ logger.info("【双重预防】任务对应单元已被删除,停止调度"); throw new BusinessException(E.DATA_STATUS_NOT_EXIST,"任务对应单元已被删除,停止调度"); } System.out.println("\n【##】调度作业-检索信息"); if (ObjectUtils.isEmpty(workById)){ return createResult; } //0、加分布式锁 // String lockName = "SAFECHECK_TASK_CREATE_"+workId; // RLock createTaskLock = redissonClient.getLock(lockName); // createTaskLock.lock(5, 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.getValidTime() * 60 * 1000); }else if (workById.getValidTimeUnit() == 2) { //如果时间单位是小时 validTime = new Date(workById.getNextCheckTime().getTime() + workById.getValidTime() * 60 * 60 * 1000); }else if (workById.getValidTimeUnit() == 3) { //如果时间单位是日 validTime = new Date(workById.getNextCheckTime().getTime() + workById.getValidTime() * 24 * 60 * 60 * 1000); }else if (workById.getValidTimeUnit() == 4) { //如果时间单位是月 Calendar calendar = Calendar.getInstance(); calendar.setTime(workById.getNextCheckTime());//设置起时间 calendar.add(Calendar.MONTH, workById.getValidTime());//增加N个月 validTime = calendar.getTime(); } //解析任务通知时间 if (workById.getNoticeTimeUnit() == 1) { //如果时间单位是分钟 noticeTime = new Date(workById.getNextCheckTime().getTime() - workById.getNoticeTime() * 60 * 1000); }else if (workById.getNoticeTimeUnit() == 2) { //如果时间单位是小时 noticeTime = new Date(workById.getNextCheckTime().getTime() - workById.getNoticeTime() * 60 * 1000); }else if (workById.getNoticeTimeUnit() == 3) { //如果时间单位是日 noticeTime = new Date(workById.getNextCheckTime().getTime() - workById.getNoticeTime() * 24 * 60 * 60 * 1000); }else if (workById.getNoticeTimeUnit() == 4) { //如果时间单位是月 Calendar calendar = Calendar.getInstance(); calendar.setTime(workById.getNextCheckTime());//设置起时间 calendar.add(Calendar.MONTH, -workById.getNoticeTime());//前移N个月 noticeTime = calendar.getTime(); } checkTime = workById.getNextCheckTime(); }else { //解析任务有效时间,以本次调度时的预期下次执行时间为基础计算 if (workById.getValidTimeUnit() == 1) { //如果时间单位是分钟 validTime = new Date(workById.getFirstStartTime().getTime() + workById.getValidTime() * 60 * 1000); }else if (workById.getValidTimeUnit() == 2) { //如果时间单位是小时 validTime = new Date(workById.getFirstStartTime().getTime() + workById.getValidTime() * 60 * 60 * 1000); }else if (workById.getValidTimeUnit() == 3) { //如果时间单位是日 validTime = new Date(workById.getFirstStartTime().getTime() + workById.getValidTime() * 24 * 60 * 60 * 1000); }else if (workById.getValidTimeUnit() == 4) { //如果时间单位是月 Calendar calendar = Calendar.getInstance(); calendar.setTime(workById.getFirstStartTime());//设置起时间 calendar.add(Calendar.MONTH, workById.getValidTime());//增加N个月 validTime = calendar.getTime(); } //解析任务通知时间 if (workById.getNoticeTimeUnit() == 1) { //如果时间单位是分钟 noticeTime = new Date(workById.getFirstStartTime().getTime() - workById.getNoticeTime() * 60 * 1000); }else if (workById.getNoticeTimeUnit() == 2) { //如果时间单位是小时 noticeTime = new Date(workById.getFirstStartTime().getTime() - workById.getNoticeTime() * 60 * 1000); }else if (workById.getNoticeTimeUnit() == 3) { //如果时间单位是日 noticeTime = new Date(workById.getFirstStartTime().getTime() - workById.getNoticeTime() * 24 * 60 * 60 * 1000); }else if (workById.getNoticeTimeUnit() == 4) { //如果时间单位是月 Calendar calendar = Calendar.getInstance(); calendar.setTime(workById.getFirstStartTime());//设置起时间 calendar.add(Calendar.MONTH, -workById.getNoticeTime());//前移N个月 noticeTime = calendar.getTime(); } checkTime = workById.getFirstStartTime(); } //0、加分布式锁 String lockName = "PREVENT_TASK_CREATE_"+workId; RLock createTaskLock = redissonClient.getLock(lockName); createTaskLock.lock(3, TimeUnit.SECONDS); //锁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); } if (checkTime.getTime() > validTime.getTime()){ logger.info("【双重预防】时间异常,停止调度,等待异常重置"); throw new BusinessException(E.DATA_STATUS_NOT_EXIST,"时间异常,停止调度"); } 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); checkTask.setBelongTime(null); // 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 listByUnitId = preventTaskUnitAndMeasureService.getListByUnitId(workById.getTaskUnitId()); //如果单元内措施列表不为空,遍历集合,取出措施id if (listByUnitId != null && listByUnitId.size() > 0){ /**保存管控措施与任务的关联 */ for (PreventTaskUnitAndMeasure taskUnitAndMeasure : listByUnitId) { //得到管控措施对应的检查内容 PreventDangerCheckContent checkContent = preventDangerCheckContentService.getCheckContentByMeasureId(taskUnitAndMeasure.getMeasureId()); //封装数据 taskAndMeasure.setCheckTaskId(taskId); taskAndMeasure.setControlMeasureId(taskUnitAndMeasure.getMeasureId()); 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 BusinessException(E.ADD_FAIL, "保存对应检查内容失败"); } } } step = 2; }else { throw new BusinessException(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 BusinessException(E.ADD_FAIL, "修改下次调度时间失败"); } // todo // todo if(step == 3){ //发送执行提醒消息 PreventNoticeExecTaskMsg preventNoticeExecTaskMsg = new PreventNoticeExecTaskMsg(); preventNoticeExecTaskMsg.setTaskId(taskId); preventNoticeExecTaskMsg.setNoticeTaskTime(noticeTime); System.out.println("发送mq消息"); SendResult sendResult = rocketMQTemplate.syncSend(preventNoticeTaskTopic, preventNoticeExecTaskMsg); System.out.println("发送成功"); 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 updateTask(Long userId, PreventDangerCheckTaskUpdateReqDTO taskUpdateReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("任务结果提交成功"); PreventDangerCheckTaskUpdateParams updateParams = new PreventDangerCheckTaskUpdateParams(); ResultVO 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 BusinessException(E.DATA_PARAM_NULL, "非认领人,无法操作"); } if (taskUpdateReqDTO.getCheckResults().size() <= 0){ throw new BusinessException(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 BusinessException(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 BusinessException(E.UPDATE_FAIL, "任务结果提交失败"); } return resultVO; } /** * 隐患排查任务-删除 */ @Override public ResultVO deleteTask(Long userId, PreventDangerCheckTaskDeleteReqDTO taskDeleteReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("删除成功"); PreventDeleteParams deleteParams = new PreventDeleteParams(); ResultVO 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 BusinessException(E.DATA_PARAM_NULL, "请选择正确的查询内容"); } UserInfo userInfo = userService.getByUserId(userId); if (userInfo.getType().equals(3)){ throw new BusinessException(E.DATA_PARAM_NULL, "非管理员,无法删除"); } Date date = new Date(); //封装参数 deleteParams.setId(taskDeleteReqDTO.getId()); deleteParams.setGmtModitify(date); deleteParams.setLastEditUserName(userInfo.getRealname()); deleteParams.setUpdateReportDataTime(date); int deleteResult = preventDangerCheckTaskService.deleteTask(deleteParams); resultVO.setCount(deleteResult); return resultVO; } /** * 隐患排查任务单元-批量删除 */ @Override public ResultVO deleteBatchTaskUnit(ContextCacheUser currentUser, DeleteBatchReqDTO deleteBatchReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("删除成功"); int i = 0; //校验参数 if (ObjectUtils.isEmpty(deleteBatchReqDTO)){ throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容"); } //获取需要填充的信息 Date date = new Date(); for (Long id : deleteBatchReqDTO.getIdList()) { PreventDangerCheckTaskUnitDeleteParams deleteParams = new PreventDangerCheckTaskUnitDeleteParams(); //封装删除需要的参数 deleteParams.setId(id); deleteParams.setGmtModitify(date); deleteParams.setLastEditUserName(currentUser.getRealName()); //检查该单元是否有措施 List listByUnitId = preventTaskUnitAndMeasureService.getListByUnitId(id); //重置关联关系 if (listByUnitId != null && listByUnitId.size() > 0){ PreventTaskUnitAndMeasureParams taskUnitAndMeasureParams = new PreventTaskUnitAndMeasureParams(); taskUnitAndMeasureParams.setTaskUnitId(id); taskUnitAndMeasureParams.setGmtModitify(date); taskUnitAndMeasureParams.setLastEditUserName(currentUser.getRealName()); taskUnitAndMeasureParams.setDeleteStatus(StatusEnum.DELETE_STATUS_DISCARD.getCode()); preventTaskUnitAndMeasureService.deleteTaskUnitAndMeasure(taskUnitAndMeasureParams); } //删除单元 int result = preventDangerCheckTaskUnitService.deleteTaskUnit(deleteParams); i++; } resultVO.setCount(i); return resultVO; } }