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.Vo.PageQuery;
|
import com.gk.hotwork.Domain.Vo.SearchResultVO;
|
import com.gk.hotwork.Domain.co.ContextCacheUser;
|
import com.gk.hotwork.Domain.dto.DepInfoRPCRespDTO;
|
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.Domain.Exception.E;
|
import com.gk.hotwork.Domain.Enum.ResultCodes;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.doublePrevention.entity.dto.query.OwnRectifyPageQuery;
|
import com.gk.hotwork.doublePrevention.entity.dto.query.db.OwnRectifyPageDBQuery;
|
import com.gk.hotwork.doublePrevention.entity.dto.resp.*;
|
import com.gk.hotwork.doublePrevention.enums.DataConvertEnum;
|
import com.gk.hotwork.doublePrevention.enums.ImageTypeEnum;
|
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.req.*;
|
import com.gk.hotwork.doublePrevention.enums.StatusEnum;
|
import com.gk.hotwork.doublePrevention.enums.SyncEnum;
|
import com.gk.hotwork.doublePrevention.repository.param.*;
|
import com.gk.hotwork.doublePrevention.service.RectifyService;
|
import com.gk.hotwork.doublePrevention.service.baseService.*;
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.redisson.api.RLock;
|
import org.redisson.api.RedissonClient;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDate;
|
import java.time.LocalDateTime;
|
import java.time.LocalTime;
|
import java.time.ZoneId;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.UUID;
|
import java.util.concurrent.TimeUnit;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class RectifyServiceImpl implements RectifyService {
|
|
@Autowired
|
private AccountAuthService accountAuthService;
|
@Autowired
|
private AccountDepartmentService accountDepartmentService;
|
@Autowired
|
private RedissonClient redissonClient;
|
|
@Autowired
|
private PreventDangerManageService preventDangerManageService;
|
@Autowired
|
private PreventDangerRectifyService preventDangerRectifyService;
|
@Autowired
|
private PreventDangerCheckTaskService preventDangerCheckTaskService;
|
@Autowired
|
private PreventProduceDeviceService preventProduceDeviceService;
|
@Autowired
|
private PreventDangerCheckTaskUnitService preventDangerCheckTaskUnitService;
|
@Autowired
|
private PreventReportConfigService preventReportConfigService;
|
@Autowired
|
private PreventRiskAnaUnitService preventRiskAnaUnitService;
|
@Autowired
|
private DepartmentService departmentService;
|
@Autowired
|
private PreventDangerManageTimeoutService preventDangerManageTimeoutService;
|
@Autowired
|
private PreventDangerImageService preventDangerImageService;
|
|
//隐患治理清单
|
/**
|
* 隐患治理清单-分页查询
|
*/
|
@Override
|
public ResultVO<PreventDangerManage> getDangerManagePage(Long userId, PreventDangerManageQueryReqDTO manageQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventDangerManageQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = manageQueryReqDTO.getPageIndex();
|
Integer pageSize = manageQueryReqDTO.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);
|
}
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//获取到所有符合条件的隐患治理清单信息
|
IPage<PreventDangerManage> page =
|
preventDangerManageService.getDangerManagePage(new Page<>(pageIndex, pageSize), manageQueryReqDTO);
|
if (ObjectUtils.isEmpty(page)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//遍历结果集,封装数据
|
for (PreventDangerManage record : page.getRecords()) {
|
PreventDangerManageQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerManageQueryRespDTO.class);
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setPageSize((int) page.getSize());
|
PreventProduceDevice deviceById = preventProduceDeviceService.getDeviceById(record.getProduceDeviceId());
|
if (ObjectUtils.isNotEmpty(deviceById)){
|
respDTO.setProduceDeviceName(deviceById.getProduceDeviceName());
|
}
|
|
PreventRiskAnaUnit riskUnitById = preventRiskAnaUnitService.getRiskUnitById(record.getRiskUnitId());
|
if (ObjectUtils.isNotEmpty(riskUnitById)){
|
respDTO.setRiskUnitName(riskUnitById.getRiskUnitName());
|
}
|
PreventDangerRectify rectifyByManageId = preventDangerRectifyService.getRectifyByManageId(record.getId());
|
// 上报图片
|
List<PreventDangerImage> images = preventDangerImageService.listImagesByParentId(record.getId());
|
if (ObjectUtils.isNotEmpty(rectifyByManageId)){
|
//获取责任人信息
|
ResultVO<UserRPCRespDTO> liablePersonResult = accountAuthService.getUserById(rectifyByManageId.getLiablePersonId());
|
UserRPCRespDTO liablePerson = (UserRPCRespDTO)liablePersonResult.getData();
|
if (rectifyByManageId.getCost() != null){
|
respDTO.setCost(rectifyByManageId.getCost());
|
}
|
if (rectifyByManageId.getRectifyDesc() != null){
|
respDTO.setRectifyDesc(rectifyByManageId.getRectifyDesc());
|
}
|
if (rectifyByManageId.getRectifyInfo() != null){
|
respDTO.setRectifyInfo(rectifyByManageId.getRectifyInfo());
|
}
|
if (rectifyByManageId.getCheckAcceptPersonId() != null){
|
respDTO.setCheckAcceptTime(rectifyByManageId.getCheckAcceptTime());
|
respDTO.setCheckAcceptPerson(rectifyByManageId.getCheckAcceptPerson());
|
respDTO.setCheckAcceptDesc(rectifyByManageId.getCheckAcceptDesc());
|
respDTO.setLiablePersonId(rectifyByManageId.getLiablePersonId());
|
}
|
DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(rectifyByManageId.getRectifyDepId());
|
if (departmentInfo != null) {
|
respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
}
|
respDTO.setCheckAcceptPersonId(rectifyByManageId.getCheckAcceptPersonId());
|
respDTO.setRectifyTime(rectifyByManageId.getRectifyTime());
|
respDTO.setRectifyType(rectifyByManageId.getRectifyType());
|
respDTO.setRectifyDepId(rectifyByManageId.getRectifyDepId());
|
respDTO.setLiablePersonId(rectifyByManageId.getLiablePersonId());
|
respDTO.setLastEditUserName(rectifyByManageId.getLiablePerson());
|
respDTO.setRectifyDepId(rectifyByManageId.getRectifyDepId());
|
respDTO.setTimeOutDesc(respDTO.getTimeOutDesc());
|
respDTO.setRectifyId(rectifyByManageId.getId());
|
|
List<PreventDangerManageImageRespDTO> imageRespDTOs = new ArrayList<>(images.size());
|
PreventDangerManageImageRespDTO reportImage;
|
if (images.size() > 0) {
|
for (PreventDangerImage image : images) {
|
reportImage = new PreventDangerManageImageRespDTO();
|
reportImage.setId(image.getId());
|
reportImage.setImagePath(image.getImagePath());
|
reportImage.setParentId(image.getParentId());
|
reportImage.setType(image.getType());
|
imageRespDTOs.add(reportImage);
|
}
|
}
|
List<String> reportList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.REPORT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> rectifyList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.RECTIFY.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> acceptList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.ACCEPT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
respDTO.setReportImages(reportList);
|
respDTO.setRectifyImages(rectifyList);
|
respDTO.setAcceptImages(acceptList);
|
}
|
DepartmentInfo departmentInfo1 = departmentService.getDepartmentInfoById(record.getDepId());
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
respDTO.setDepName(departmentInfo1.getDepartment());
|
list.add(respDTO);
|
}
|
resultVO.setData(list);
|
resultVO.setCount((int) page.getTotal());
|
|
return resultVO;
|
}
|
/**
|
* 隐患治理清单-列表
|
*/
|
@Override
|
public ResultVO<PreventDangerManage> listDangerManage(Long valueOf) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventDangerManage> dangerManages = preventDangerManageService.listDangerManage();
|
List<PreventDangerManageListQueryRespDTO> respDTOS =
|
BeanCopyUtils.copyBeanList(dangerManages, PreventDangerManageListQueryRespDTO.class);
|
|
resultVO.setData(respDTOS);
|
return resultVO;
|
}
|
/**
|
* 隐患管理-手工上报-配置
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateDangerManagerReport(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 BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
if (preventHandReportConfigReqDTO.getReportSwitch() == null){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
//查询当前隐患的配置
|
PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(preventHandReportConfigReqDTO.getId());
|
//配置相同,做处理
|
if (dangerManageById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同");
|
}
|
int result ;
|
//读取主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//只有当开启上报,且类型为手动上报时,可以修改
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
result = preventDangerManageService.updateDangerManagerReport(preventHandReportConfigReqDTO);
|
|
}else {
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患治理清单-新增
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerManage> saveDangerManage(Long userId, PreventDangerManageSaveReqDTO manageSaveReqDTO) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (manageSaveReqDTO.getDangerLevel() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患等级不能为空");
|
}
|
if (manageSaveReqDTO.getDangerType() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患类型不能为空");
|
}
|
if (manageSaveReqDTO.getDepId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患所属部门不能为空");
|
}
|
if (manageSaveReqDTO.getDangerCode() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患名称不能为空");
|
}
|
// 图片
|
if (manageSaveReqDTO.getReportImages() == null || manageSaveReqDTO.getReportImages().size() < 1) {
|
throw new BusinessException(E.DATA_PARAM_NULL, "图片上传不能为空");
|
}
|
for (String path : manageSaveReqDTO.getReportImages()) {
|
if (StringUtils.isBlank(path)) {
|
throw new BusinessException(E.DATA_PARAM_NULL, "图片上传不能为空路径");
|
}
|
}
|
// 图片
|
if (manageSaveReqDTO.getReportImages().size() > 3) {
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "图片上传不能超过三张");
|
}
|
//校验部门是否存在
|
// ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, manageSaveReqDTO.getDepId());
|
DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(manageSaveReqDTO.getDepId());
|
if(ObjectUtils.isEmpty(departmentInfo)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任部门");
|
}
|
if (manageSaveReqDTO.getRiskUnitId() != null){
|
PreventRiskAnaUnit riskUnitById = preventRiskAnaUnitService.getRiskUnitById(manageSaveReqDTO.getRiskUnitId());
|
if(ObjectUtils.isEmpty(riskUnitById)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确的风险分析单元");
|
}
|
}
|
|
if (manageSaveReqDTO.getProduceDeviceId() != null){
|
PreventProduceDevice deviceById =
|
preventProduceDeviceService.getDeviceById(manageSaveReqDTO.getProduceDeviceId());
|
if (ObjectUtils.isEmpty(deviceById)){
|
throw new BusinessException(E.DATA_PARAM_NULL, "请填写正确的生产装置");
|
}
|
PreventRiskAnaUnit riskUnitById = preventRiskAnaUnitService.getRiskUnitById(manageSaveReqDTO.getRiskUnitId());
|
if (ObjectUtils.isNotEmpty(riskUnitById)){
|
if (!riskUnitById.getProduceDeviceId().equals(manageSaveReqDTO.getProduceDeviceId())){
|
throw new BusinessException(E.DATA_PARAM_NULL, "请填写生产装置对应的分析单元");
|
}
|
}else if (ObjectUtils.isEmpty(riskUnitById)){
|
throw new BusinessException(E.DATA_PARAM_NULL, "请填写生产装置对应的分析单元");
|
}
|
}
|
if (manageSaveReqDTO.getRectifyType() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改类型不能为空");
|
}
|
if (manageSaveReqDTO.getDangerResult() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患可能造成的后果不能为空");
|
}
|
if (manageSaveReqDTO.getLiablePersonId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改责任人不能为空");
|
}
|
//责任人信息
|
ResultVO<UserRPCRespDTO> execUserResult = accountAuthService.getUserById(manageSaveReqDTO.getLiablePersonId());
|
UserRPCRespDTO liableUser = (UserRPCRespDTO)execUserResult.getData();
|
if (ObjectUtils.isEmpty(liableUser)){
|
throw new BusinessException(E.DATA_PARAM_NULL, "该责任人不存在或已被删除,请选择正确的责任人");
|
}
|
if (manageSaveReqDTO.getRectifyTime() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改期限不能为空");
|
}
|
if (manageSaveReqDTO.getRectifyDepId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改部门不能为空");
|
}
|
if (!manageSaveReqDTO.getRectifyDepId().equals(liableUser.getDepartment().getDepId())){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改人不属于该部门");
|
}
|
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long dangerManagerId = snowFlow.nextId();
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
/**设置隐患管理表参数*/
|
PreventDangerManage dangerManage = BeanCopyUtils.copyBean(manageSaveReqDTO, PreventDangerManage.class);
|
dangerManage.setId(dangerManagerId);
|
dangerManage.setUuid(uuid);
|
dangerManage.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
dangerManage.setGmtCreate(date);
|
dangerManage.setGmtModitify(date);
|
dangerManage.setCreateByUserName(userById.getRealName());
|
dangerManage.setLastEditUserName(userById.getRealName());
|
dangerManage.setEnterpriseId((long) 1);
|
dangerManage.setEnterpriseUuid("123124134");
|
dangerManage.setDangerStatus(StatusEnum.DANGER_MANAGER_RECTIFY.getCode());
|
dangerManage.setDangerReview(StatusEnum.DANGER_RECTIFY_WAIT.getCode());
|
dangerManage.setDangerCode(manageSaveReqDTO.getDangerCode());
|
dangerManage.setDangerCloseReason(null);
|
//这暂时不用字段
|
dangerManage.setTaskId(null);
|
dangerManage.setRegistantId(null);
|
dangerManage.setRegisterTime(null);
|
dangerManage.setRegistantName(null);
|
|
/**设置隐患整改验收表的参数*/
|
//获取需要填充的信息
|
String RectifyUuid = UUID.randomUUID().toString();
|
long rectifyId = snowFlow.nextId();
|
//封装参数
|
PreventDangerRectify dangerRectify = BeanCopyUtils.copyBean(manageSaveReqDTO, PreventDangerRectify.class);
|
dangerRectify.setId(rectifyId);
|
dangerRectify.setUuid(RectifyUuid);
|
dangerRectify.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
dangerRectify.setGmtCreate(date);
|
dangerRectify.setCreateByUserName(userById.getRealName());
|
dangerRectify.setGmtModitify(date);
|
dangerRectify.setLastEditUserName(userById.getRealName());
|
dangerRectify.setEnterpriseId((long) 1);
|
dangerRectify.setEnterpriseUuid("1564wq");
|
dangerRectify.setDangerManagerUuid(uuid);
|
dangerRectify.setDangerManagerId(dangerManagerId);
|
dangerRectify.setLiablePerson(liableUser.getRealName());
|
dangerRectify.setDangerCode(null);
|
dangerRectify.setApplyTime(null);
|
dangerRectify.setTimeOutDesc(null);
|
dangerRectify.setRectifyInfo(null);
|
dangerRectify.setCheckAcceptPerson(userById.getRealName());
|
dangerRectify.setRectifyDepId(manageSaveReqDTO.getRectifyDepId());
|
dangerRectify.setDangerReview(StatusEnum.DANGER_RECTIFY_WAIT.getCode());
|
dangerRectify.setCheckAcceptPersonId(userId);
|
dangerRectify.setCheckAcceptPerson(userById.getRealName());
|
// 不确定是否需要的字段
|
dangerRectify.setCheckAcceptTime(null);
|
dangerRectify.setCheckAcceptDesc(null);
|
//TODO
|
//设置上报时间为空,以隐患管理表为主,同时设置上报
|
dangerManage.setReportTime(null);
|
dangerRectify.setReportTime(null);
|
//设置本条数据上报更新时间
|
dangerManage.setUpdateReportDataTime(new Date());
|
dangerRectify.setUpdateReportDataTime(new Date());
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
dangerManage.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
dangerRectify.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
dangerManage.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
dangerManage.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
dangerRectify.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
dangerManage.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
}
|
//生成隐患编码
|
LocalDateTime t = dangerManage.getGmtCreate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
LocalDate localDate = t.toLocalDate();
|
LocalDateTime startTime = LocalDateTime.of(localDate, LocalTime.of(0,0,0));
|
LocalDateTime endTime = LocalDateTime.of(localDate, LocalTime.of(23,59,59));
|
Date start = Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant());
|
Date end = Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant());
|
//1、加分布式锁
|
String lockName = "LOCK_DANGER_CODE_GENERATE";
|
RLock lock = redissonClient.getLock(lockName);
|
lock.lock(3, TimeUnit.SECONDS);
|
int count = -1;
|
try {
|
count = preventDangerManageService.countByCreateTime(start,end);
|
} catch (Exception e) {
|
lock.unlock();
|
throw new BusinessException(E.ADD_FAIL, "保存隐患整改信息失败");
|
}
|
//2、生成编码
|
String serialCode = generateDangerSerialCode(dangerManage.getGmtCreate(),count);
|
if(serialCode == null || serialCode.isEmpty()){
|
throw new BusinessException(E.ADD_FAIL, "保存隐患整改信息失败");
|
}
|
dangerManage.setSerialCode(serialCode);
|
|
|
// 图片
|
List<PreventDangerImage> images = new ArrayList<>();
|
PreventDangerImage image;
|
for (String path : manageSaveReqDTO.getReportImages()) {
|
image = new PreventDangerImage();
|
image.setId(snowFlow.nextId());
|
image.setImagePath(path);
|
image.setParentId(dangerManage.getId());
|
image.setStatus(DataConvertEnum.DELETE_STATUS_USE.getCode());
|
image.setType(ImageTypeEnum.REPORT.getCode());
|
images.add(image);
|
}
|
preventDangerImageService.saveBatch(images);
|
|
|
|
int step = 1;
|
//保存隐患管理信息
|
if (step == 1){
|
int resultManage = preventDangerManageService.saveDangerManage(dangerManage);
|
if (resultManage < 1){
|
throw new BusinessException(E.ADD_FAIL, "保存隐患管理信息失败");
|
}else {
|
step = 2;
|
}
|
}
|
//保存隐患整改信息
|
if (step == 2){
|
int resultRectify = preventDangerRectifyService.saveDangerRectify(dangerRectify);
|
if (resultRectify < 1){
|
throw new BusinessException(E.ADD_FAIL, "保存隐患整改信息失败");
|
}
|
}
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患管理清单-修改
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventDangerManage> updateDangerManage(Long userId, PreventDangerManageUpdateReqDTO manageUpdateReqDTO) {
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//校验参数
|
if (manageUpdateReqDTO.getId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "传参非法");
|
}
|
if (manageUpdateReqDTO.getDangerLevel() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患等级不能为空");
|
}
|
if (manageUpdateReqDTO.getDangerType() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患类型不能为空");
|
}
|
if (manageUpdateReqDTO.getDangerSource() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患来源不能为空");
|
}
|
if (manageUpdateReqDTO.getDepId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患所属部门不能为空");
|
}
|
// 图片
|
if (manageUpdateReqDTO.getReportImages() == null || manageUpdateReqDTO.getReportImages().size() < 1) {
|
throw new BusinessException(E.DATA_PARAM_NULL, "图片上传不能为空");
|
}
|
for (String path : manageUpdateReqDTO.getReportImages()) {
|
if (StringUtils.isBlank(path)) {
|
throw new BusinessException(E.DATA_PARAM_NULL, "图片上传不能为空路径");
|
}
|
}
|
// 图片
|
if (manageUpdateReqDTO.getReportImages().size() > 3) {
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "图片上传不能超过三张");
|
}
|
//校验部门是否存在
|
// ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, manageUpdateReqDTO.getDepId());
|
DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(manageUpdateReqDTO.getDepId());
|
if(ObjectUtils.isEmpty(departmentInfo)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任部门");
|
}
|
if (manageUpdateReqDTO.getRiskUnitId() != null){
|
PreventRiskAnaUnit riskUnitById = preventRiskAnaUnitService.getRiskUnitById(manageUpdateReqDTO.getRiskUnitId());
|
if(ObjectUtils.isEmpty(riskUnitById)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确的风险分析单元");
|
}
|
}
|
if (manageUpdateReqDTO.getProduceDeviceId() != null){
|
PreventProduceDevice deviceById =
|
preventProduceDeviceService.getDeviceById(manageUpdateReqDTO.getProduceDeviceId());
|
if (ObjectUtils.isEmpty(deviceById)){
|
throw new BusinessException(E.DATA_PARAM_NULL, "请填写正确的生产装置");
|
}
|
PreventRiskAnaUnit riskUnitById = preventRiskAnaUnitService.getRiskUnitById(manageUpdateReqDTO.getRiskUnitId());
|
if (!riskUnitById.getProduceDeviceId().equals(manageUpdateReqDTO.getProduceDeviceId())){
|
throw new BusinessException(E.DATA_PARAM_NULL, "请填写生产装置对应的分析单元");
|
}
|
}
|
if (manageUpdateReqDTO.getRectifyType() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改类型不能为空");
|
}
|
if (manageUpdateReqDTO.getLiablePersonId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改责任人不能为空");
|
}
|
if (manageUpdateReqDTO.getRectifyDepId() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改部门不能为空");
|
}
|
//责任人信息
|
ResultVO<UserRPCRespDTO> execUserResult = accountAuthService.getUserById(manageUpdateReqDTO.getLiablePersonId());
|
UserRPCRespDTO liableUser = (UserRPCRespDTO)execUserResult.getData();
|
|
Date date = new Date();
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//封装隐患管理参数
|
PreventDangerRectify rectifyByManageId = preventDangerRectifyService.getRectifyByManageId(manageUpdateReqDTO.getId());
|
PreventDangerManageUpdateParams updateParams = BeanCopyUtils.copyBean(manageUpdateReqDTO, PreventDangerManageUpdateParams.class);
|
updateParams.setLastEditUserName(userById.getRealName());
|
updateParams.setGmtModitify(date);
|
//封装隐患整改参数
|
//PreventDangerRectifyUpdateParams rectifyUpdateParams = new PreventDangerRectifyUpdateParams();
|
PreventDangerRectifyUpdateParams rectifyUpdateParams = BeanCopyUtils.copyBean(manageUpdateReqDTO, PreventDangerRectifyUpdateParams.class);
|
rectifyUpdateParams.setLastEditUserName(userById.getRealName());
|
rectifyUpdateParams.setGmtModitify(date);
|
rectifyUpdateParams.setLiablePerson(liableUser.getRealName());
|
rectifyUpdateParams.setId(rectifyByManageId.getId());
|
|
//设置本条数据上报更新时间
|
rectifyUpdateParams.setUpdateReportDataTime(date);
|
updateParams.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
updateParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
rectifyUpdateParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
updateParams.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
updateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
rectifyUpdateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
updateParams.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
}
|
int rectifyResult = preventDangerRectifyService.updateDangerRectify(rectifyUpdateParams);
|
if (rectifyResult < 1){
|
throw new BusinessException(E.UPDATE_FAIL, "修改隐患整改信息失败");
|
}
|
preventDangerImageService.deleteImageByParentId(manageUpdateReqDTO.getId(), ImageTypeEnum.REPORT);
|
// 图片
|
SnowFlow snowFlow = new SnowFlow();
|
List<PreventDangerImage> images = new ArrayList<>();
|
PreventDangerImage image;
|
for (String path : manageUpdateReqDTO.getReportImages()) {
|
image = new PreventDangerImage();
|
image.setId(snowFlow.nextId());
|
image.setImagePath(path);
|
image.setParentId(manageUpdateReqDTO.getId());
|
image.setStatus(DataConvertEnum.DELETE_STATUS_USE.getCode());
|
image.setType(ImageTypeEnum.REPORT.getCode());
|
images.add(image);
|
}
|
preventDangerImageService.saveBatch(images);
|
|
|
int result = preventDangerManageService.updateDangerManage(updateParams);
|
if (rectifyResult < 1){
|
throw new BusinessException(E.UPDATE_FAIL, "修改管理整改信息失败");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患治理清单-删除
|
*/
|
@Override
|
public ResultVO<PreventDangerManage> deleteDangerManage(Long userId, PreventDangerManageDeleteReqDTO manageDeleteReqDTO) {
|
|
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 (manageDeleteReqDTO.getId() == null ){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容");
|
}
|
PreventDangerRectify rectifyByManageId = preventDangerRectifyService.getRectifyByManageId(manageDeleteReqDTO.getId());
|
if (ObjectUtils.isNotEmpty(rectifyByManageId)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "需要先删除对应的隐患整改");
|
}
|
//获取需要填充的信息
|
Date date = new Date();
|
//封装删除需要的参数
|
deleteParams.setId(manageDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(date);
|
|
int result = preventDangerManageService.deleteDangerManage(deleteParams);
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
//隐患整改清单
|
/**
|
* 隐患整改清单-分页查询
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> getDangerRectifyPage(Long userId, PreventDangerRectifyQueryReqDTO rectifyQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventDangerRectifyQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = rectifyQueryReqDTO.getPageIndex();
|
Integer pageSize = rectifyQueryReqDTO.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);
|
}
|
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
//获取到所有符合条件的隐患治理清单信息
|
Page pageInfo = new Page<>(pageIndex, pageSize);
|
pageInfo.setOptimizeCountSql(false);
|
IPage<PreventDangerRectify> page =
|
preventDangerRectifyService.getDangerRectifyPage(pageInfo, rectifyQueryReqDTO);
|
if (ObjectUtils.isEmpty(page)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
// //遍历结果集,封装数据
|
// //List<PreventDangerRectifyQueryRespDTO> respDTO = BeanCopyUtils.copyBeanList(page.getRecords(), PreventDangerRectifyQueryRespDTO.class);
|
// for (PreventDangerRectify record : page.getRecords()) {
|
// PreventDangerRectifyQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerRectifyQueryRespDTO.class);
|
// PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(record.getDangerManagerId());
|
// //添加部门名称
|
// DepartmentInfo departmentInfo = departmentService.selectSafety(respDTO.getRectifyDepId());
|
// respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
// respDTO.setDangerStatus(dangerManageById.getDangerStatus());
|
// respDTO.setPageIndex((int) page.getCurrent());
|
// respDTO.setPageSize((int) page.getSize());
|
// respDTO.setDangerManagerId(dangerManageById.getId());
|
// respDTO.setReportState(reportConfigById.getReportState());
|
// respDTO.setReportType(reportConfigById.getReportType());
|
// list.add(respDTO);
|
// }
|
//遍历结果集,封装数据
|
for (PreventDangerRectify record : page.getRecords()) {
|
PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(record.getDangerManagerId());
|
|
List<PreventDangerImage> images = preventDangerImageService.listImagesByParentId(record.getDangerManagerId());
|
List<PreventDangerManageImageRespDTO> imageRespDTOs = new ArrayList<>(images.size());
|
PreventDangerManageImageRespDTO reportImage;
|
if (images.size() > 0) {
|
for (PreventDangerImage image : images) {
|
reportImage = new PreventDangerManageImageRespDTO();
|
reportImage.setId(image.getId());
|
reportImage.setImagePath(image.getImagePath());
|
reportImage.setParentId(image.getParentId());
|
reportImage.setType(image.getType());
|
imageRespDTOs.add(reportImage);
|
}
|
}
|
|
if (rectifyQueryReqDTO.getDangerStatus() != null){
|
if(dangerManageById.getDangerStatus().equals(rectifyQueryReqDTO.getDangerStatus())){
|
PreventDangerManageTimeout timeoutResult = preventDangerManageTimeoutService.getByRectifyId(record.getId());
|
PreventDangerRectifyQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerRectifyQueryRespDTO.class);
|
//添加部门名称
|
DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(respDTO.getRectifyDepId());
|
respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
if (ObjectUtils.isNotEmpty(timeoutResult)){
|
respDTO.setTimeoutStatus(timeoutResult.getTimeoutStatus());
|
}
|
respDTO.setSerialCode(dangerManageById.getSerialCode());
|
respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
respDTO.setDangerStatus(dangerManageById.getDangerStatus());
|
respDTO.setDangerManagerId(dangerManageById.getId());
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
respDTO.setDangerCode(dangerManageById.getDangerCode());
|
|
List<String> reportList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.REPORT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> rectifyList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.RECTIFY.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> acceptList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.ACCEPT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
respDTO.setReportImages(reportList);
|
respDTO.setRectifyImages(rectifyList);
|
respDTO.setAcceptImages(acceptList);
|
|
list.add(respDTO);
|
respDTO.setPageIndex(list.indexOf(respDTO));
|
respDTO.setPageSize(pageSize);
|
}
|
}else {
|
PreventDangerManageTimeout timeoutResult = preventDangerManageTimeoutService.getByRectifyId(record.getId());
|
PreventDangerRectifyQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerRectifyQueryRespDTO.class);
|
//添加部门名称
|
DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(respDTO.getRectifyDepId());
|
respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
if (ObjectUtils.isNotEmpty(timeoutResult)){
|
respDTO.setTimeoutStatus(timeoutResult.getTimeoutStatus());
|
}
|
respDTO.setSerialCode(dangerManageById.getSerialCode());
|
if (departmentInfo != null) {
|
respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
}
|
respDTO.setDangerStatus(dangerManageById.getDangerStatus());
|
respDTO.setPageIndex(pageSize);
|
respDTO.setPageSize((int) page.getCurrent());
|
respDTO.setDangerManagerId(dangerManageById.getId());
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
|
List<String> reportList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.REPORT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> rectifyList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.RECTIFY.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> acceptList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.ACCEPT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
respDTO.setReportImages(reportList);
|
respDTO.setRectifyImages(rectifyList);
|
respDTO.setAcceptImages(acceptList);
|
list.add(respDTO);
|
resultVO.setCount((int) page.getTotal());
|
}
|
}
|
|
resultVO.setData(list);
|
resultVO.setCount((int) page.getTotal());
|
|
return resultVO;
|
}
|
|
|
/**
|
* 隐患整改清单-查询:待验收与已验收
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> getRectifyOverPage(Long userId, PreventRectifyOverQueryReqDTO rectifyOverQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventDangerRectifyQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = rectifyOverQueryReqDTO.getPageIndex();
|
Integer pageSize = rectifyOverQueryReqDTO.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);
|
}
|
if (ObjectUtils.isEmpty(rectifyOverQueryReqDTO.getDangerStatus())){
|
rectifyOverQueryReqDTO.setStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
}else {
|
rectifyOverQueryReqDTO.setStatus(null);
|
}
|
|
//TODO 后续改为连表查询,现为临时用
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
Page pageInfo = new Page<>(pageIndex, pageSize);
|
pageInfo.setOptimizeCountSql(false);
|
IPage<PreventDangerRectify> page =
|
preventDangerRectifyService.getDangerRectifyPageToOverRectify(pageInfo, rectifyOverQueryReqDTO);
|
for (PreventDangerRectify record : page.getRecords()) {
|
PreventDangerRectifyQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventDangerRectifyQueryRespDTO.class);
|
PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(record.getDangerManagerId());
|
PreventDangerManageTimeout timeoutResult = preventDangerManageTimeoutService.getByRectifyId(record.getId());
|
//添加部门名称
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, respDTO.getRectifyDepId());
|
if (ObjectUtils.isNotEmpty(timeoutResult)){
|
respDTO.setTimeoutStatus(timeoutResult.getTimeoutStatus());
|
}
|
//添加部门名称
|
DepartmentInfo departmentInfo = departmentService.getDepartmentInfoById(respDTO.getRectifyDepId());
|
DepInfoRPCRespDTO data = (DepInfoRPCRespDTO)depInfoByDepId.getData();
|
respDTO.setRectifyDepName(departmentInfo.getDepartment());
|
respDTO.setSerialCode(dangerManageById.getSerialCode());
|
respDTO.setDangerStatus(dangerManageById.getDangerStatus());
|
respDTO.setDangerManagerId(record.getDangerManagerId());
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setPageSize((int) page.getSize());
|
|
List<PreventDangerImage> images = preventDangerImageService.listImagesByParentId(record.getDangerManagerId());
|
List<PreventDangerManageImageRespDTO> imageRespDTOs = new ArrayList<>(images.size());
|
PreventDangerManageImageRespDTO reportImage;
|
if (images.size() > 0) {
|
for (PreventDangerImage image : images) {
|
reportImage = new PreventDangerManageImageRespDTO();
|
reportImage.setId(image.getId());
|
reportImage.setImagePath(image.getImagePath());
|
reportImage.setParentId(image.getParentId());
|
reportImage.setType(image.getType());
|
imageRespDTOs.add(reportImage);
|
}
|
}
|
List<String> reportList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.REPORT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> rectifyList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.RECTIFY.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
List<String> acceptList = imageRespDTOs.stream().filter(item -> item.getType().equals(ImageTypeEnum.ACCEPT.getCode())).map(PreventDangerManageImageRespDTO::getImagePath).collect(Collectors.toList());
|
respDTO.setReportImages(reportList);
|
respDTO.setRectifyImages(rectifyList);
|
respDTO.setAcceptImages(acceptList);
|
|
|
list.add(respDTO);
|
}
|
|
resultVO.setData(list);
|
resultVO.setCount(list.size());
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患整改清单-新增 ---不要了--20220727
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> saveDangerRectify(Long userId, PreventDangerRectifySaveReqDTO rectifySaveReqDTO) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
if (rectifySaveReqDTO.getDangerManagerId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患管理单不能为空");
|
}
|
PreventDangerManage dangerManageById =
|
preventDangerManageService.getDangerManageById(rectifySaveReqDTO.getDangerManagerId());
|
if (ObjectUtils.isEmpty(dangerManageById)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请填写正确的隐患管理单");
|
}
|
//每个隐患管理单,只能有一个整改清单 TODO
|
PreventDangerRectify rectifyByCode =
|
preventDangerRectifyService.getRectifyByCode(dangerManageById.getDangerCode());
|
if (ObjectUtils.isNotEmpty(rectifyByCode)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "每个隐患管理单只能有一个整改任务单");
|
}
|
if (rectifySaveReqDTO.getRectifyTime() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改期限不能为空");
|
}
|
|
if (rectifySaveReqDTO.getLiablePersonId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改责任人不能为空");
|
}
|
//获取责任人信息
|
ResultVO<UserRPCRespDTO> liablePersonResult = accountAuthService.getUserById(rectifySaveReqDTO.getLiablePersonId());
|
UserRPCRespDTO liablePerson = (UserRPCRespDTO)liablePersonResult.getData();
|
if (ObjectUtils.isEmpty(liablePerson)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请正确填写整改责任人");
|
}
|
if (rectifySaveReqDTO.getRectifyDesc() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改内容说明");
|
}
|
if (rectifySaveReqDTO.getRectifyTime() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改类型不能为空");
|
}
|
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long rectifyId = snowFlow.nextId();
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//封装参数
|
PreventDangerRectify dangerRectify = BeanCopyUtils.copyBean(rectifySaveReqDTO, PreventDangerRectify.class);
|
dangerRectify.setId(rectifyId);
|
dangerRectify.setUuid(uuid);
|
dangerRectify.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
|
dangerRectify.setGmtCreate(date);
|
dangerRectify.setCreateByUserName(userById.getRealName());
|
dangerRectify.setGmtModitify(date);
|
dangerRectify.setLastEditUserName(userById.getRealName());
|
dangerRectify.setEnterpriseId((long) 1);
|
dangerRectify.setEnterpriseUuid("1564wq");
|
dangerRectify.setCheckAcceptPerson(userById.getRealName());
|
dangerRectify.setCheckAcceptPersonId(null);
|
dangerRectify.setRectifyDepId(null);
|
|
dangerRectify.setDangerManagerUuid(dangerManageById.getUuid());
|
dangerRectify.setDangerManagerId(rectifySaveReqDTO.getDangerManagerId());
|
dangerRectify.setDangerCode(dangerManageById.getDangerCode());
|
dangerRectify.setLiablePerson(liablePerson.getRealName());
|
|
//设置上报时间为空
|
dangerRectify.setReportTime(null);
|
//设置本条数据上报更新时间
|
dangerRectify.setUpdateReportDataTime(new Date());
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
//本模块是否上报,通过DangerManager表的配置进行管理
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
dangerRectify.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
dangerRectify.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
}
|
//不确定是否需要的字段
|
dangerRectify.setCheckAcceptTime(null);
|
dangerRectify.setCheckAcceptDesc(null);
|
|
int result = preventDangerRectifyService.saveDangerRectify(dangerRectify);
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患整改--延期
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> timeOutRectify(Long userId, PreventDangerRectifyUpdateReqDTO updateReqDTO) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
if (updateReqDTO.getId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "传参非法");
|
}
|
if (updateReqDTO.getDangerManagerId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患管理单不能为空");
|
}
|
if (updateReqDTO.getRectifyTime() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "延期的时间不能为空");
|
}
|
if (updateReqDTO.getTimeOutDesc() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "延期说明不能为空");
|
}
|
PreventDangerRectify rectify = preventDangerRectifyService.getRectifyById(updateReqDTO.getId());
|
if (updateReqDTO.getRectifyTime().getTime() - rectify.getRectifyTime().getTime() <= 0){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "延期时间必须大于整改期限");
|
}
|
PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(rectify.getDangerManagerId());
|
if (ObjectUtils.isEmpty(dangerManageById)){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "传参错误");
|
}
|
if (dangerManageById.getDangerStatus() == StatusEnum.DANGER_MANAGER_NOT_ACCEPT.getCode()){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "超期未整改任务无法延期");
|
}
|
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//封装修改参数
|
PreventDangerRectifyUpdateParams updateParams = new PreventDangerRectifyUpdateParams();
|
updateParams.setId(updateReqDTO.getId());
|
updateParams.setRectifyTime(updateReqDTO.getRectifyTime());
|
updateParams.setLastEditUserName(userById.getRealName());
|
updateParams.setGmtModitify(new Date());
|
updateParams.setTimeOutDesc(updateReqDTO.getTimeOutDesc());
|
|
//设置本条数据上报更新时间 ,上报开关依赖于dangerManager
|
updateParams.setUpdateReportDataTime(new Date());
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
updateParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
updateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
}
|
//整改单延期成功
|
int resultRectify = preventDangerRectifyService.updateRectifyTime(updateParams);
|
if (resultRectify < 1){
|
throw new BusinessException(E.UPDATE_FAIL, "延期操作失败");
|
}
|
//管理单变更状态成功
|
//封装修改参数
|
UpdateRectifyResultParams updateRectifyParams = new UpdateRectifyResultParams();
|
updateRectifyParams.setDangerStatus(StatusEnum.DANGER_MANAGER_TIMEOUT_RECTIFY.getCode());
|
updateRectifyParams.setDangerManagerId(updateReqDTO.getDangerManagerId());
|
updateRectifyParams.setUpdateReportDataTime(new Date());
|
|
int resultManager = preventDangerManageService.updateRectifyResult(updateRectifyParams);
|
if (resultManager < 1){
|
throw new BusinessException(E.UPDATE_FAIL, "隐患管理状态变更失败");
|
}
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患整改清单-修改
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> updateDangerRectify(Long userId, PreventDangerRectifyUpdateReqDTO rectifyUpdateReqDTO) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
|
if (rectifyUpdateReqDTO.getDangerManagerId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "参数非法");
|
}
|
PreventDangerManage dangerManageById =
|
preventDangerManageService.getDangerManageById(rectifyUpdateReqDTO.getDangerManagerId());
|
if (ObjectUtils.isEmpty(dangerManageById)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请填写正确的隐患管理单");
|
}
|
if (rectifyUpdateReqDTO.getRectifyTime() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改期限不能为空");
|
}
|
if (rectifyUpdateReqDTO.getLiablePersonId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改责任人不能为空");
|
}
|
//获取责任人信息
|
ResultVO<UserRPCRespDTO> liablePersonResult = accountAuthService.getUserById(rectifyUpdateReqDTO.getLiablePersonId());
|
UserRPCRespDTO liablePerson = (UserRPCRespDTO)liablePersonResult.getData();
|
if (ObjectUtils.isEmpty(liablePerson)){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请正确填写整改责任人");
|
}
|
if (rectifyUpdateReqDTO.getRectifyDesc() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改内容说明不能为空");
|
}
|
if (rectifyUpdateReqDTO.getRectifyType() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改类型不能为空");
|
}
|
if (rectifyUpdateReqDTO.getCost() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改资金不能为空");
|
}
|
|
//获取需要填充的信息
|
Date date = new Date();
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//封装参数
|
PreventDangerRectifyUpdateParams updateParams
|
= BeanCopyUtils.copyBean(rectifyUpdateReqDTO, PreventDangerRectifyUpdateParams.class);
|
|
updateParams.setGmtModitify(date);
|
updateParams.setLastEditUserName(userById.getRealName());
|
updateParams.setDangerManagerUuid(dangerManageById.getUuid());
|
updateParams.setLiablePerson(liablePerson.getRealName());
|
|
//设置本条数据上报更新时间 ,上报开关依赖于dangerManager
|
updateParams.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
updateParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
updateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
}
|
|
int result = preventDangerRectifyService.updateDangerRectify(updateParams);
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患整改清单-验收情况填报-整改
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> applyReport(Long userId, PreventDangerReportRectifyReqDTO reportRectify) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
if (reportRectify.getId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "参数为空");
|
}
|
if (reportRectify.getRectifyImages() == null || reportRectify.getRectifyImages().size() < 1){
|
throw new BusinessException(E.DATA_PARAM_NULL, "上传图片为空");
|
}
|
// 图片
|
if (reportRectify.getRectifyImages().size() > 3) {
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "图片上传不能超过三张");
|
}
|
for (String path : reportRectify.getRectifyImages()) {
|
if (StringUtils.isBlank(path)) {
|
throw new BusinessException(E.DATA_PARAM_NULL, "图片上传不能为空路径");
|
}
|
}
|
//获取验收责任人信息
|
// ResultVO<UserRPCRespDTO> checkAcceptPersonResult = accountAuthService.getUserById(reportRectify.getCheckAcceptPersonId());
|
// UserRPCRespDTO checkAcceptPerson = (UserRPCRespDTO)checkAcceptPersonResult.getData();
|
|
PreventDangerRectify rectifyById = preventDangerRectifyService.getRectifyById(reportRectify.getId());
|
|
if (!userId.equals(rectifyById.getLiablePersonId())){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "非整改责任人,无法操作");
|
}
|
|
PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(reportRectify.getDangerManagerId());
|
|
if (dangerManageById.getDangerStatus().equals(StatusEnum.DANGER_MANAGER_NOT_ACCEPT.getCode())
|
|| dangerManageById.getDangerStatus().equals(StatusEnum.DANGER_MANAGER_WAIT_ACCEPT.getCode())
|
|| dangerManageById.getDangerStatus().equals(StatusEnum.DANGER_MANAGER_ACCEPT.getCode())){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "该整改单不是整改中状态,只有在整改的单据才可以申请验收");
|
}
|
if (reportRectify.getRectifyInfo() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "整改说明不能为空");
|
}
|
|
if (dangerManageById.getDangerReview() == StatusEnum.DANGER_RECTIFY_REVIEW.getCode()){
|
throw new BusinessException(E.DATA_PARAM_NULL, "隐患已关闭,无法处理");
|
}
|
|
|
|
//获取需要填充的信息
|
Date date = new Date();
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//封装参数
|
PreventDangerReportRectifyUpdayeParams reportParams
|
= BeanCopyUtils.copyBean(reportRectify, PreventDangerReportRectifyUpdayeParams.class);
|
|
reportParams.setGmtModitify(date);
|
reportParams.setLastEditUserName(userById.getRealName());
|
reportParams.setApplyTime(reportRectify.getApplyTime());
|
reportParams.setRectifyInfo(reportRectify.getRectifyInfo());
|
|
//设置本条数据上报更新时间 ,上报开关依赖于dangerManager
|
reportParams.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
reportParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
reportParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
}
|
//提交数据
|
int result = preventDangerRectifyService.applyReport(reportParams);
|
|
if (result < 1) {
|
throw new BusinessException(E.UPDATE_FAIL, "提交验收失败");
|
}
|
//封装修改参数
|
UpdateRectifyResultParams updateParams = new UpdateRectifyResultParams();
|
updateParams.setDangerStatus(StatusEnum.DANGER_MANAGER_WAIT_ACCEPT.getCode());
|
updateParams.setDangerManagerId(reportRectify.getDangerManagerId());
|
updateParams.setUpdateReportDataTime(date);
|
//设置为待验收
|
int manageResult = preventDangerManageService.updateRectifyResult(updateParams);
|
if (manageResult < 1) {
|
throw new BusinessException(E.UPDATE_FAIL, "状态变更失败");
|
}
|
// 图片
|
List<PreventDangerImage> images = new ArrayList<>();
|
PreventDangerImage image;
|
SnowFlow snowFlow = new SnowFlow();
|
for (String path : reportRectify.getRectifyImages()) {
|
image = new PreventDangerImage();
|
image.setId(snowFlow.nextId());
|
image.setImagePath(path);
|
image.setParentId(reportRectify.getDangerManagerId());
|
image.setStatus(DataConvertEnum.DELETE_STATUS_USE.getCode());
|
image.setType(ImageTypeEnum.RECTIFY.getCode());
|
images.add(image);
|
}
|
preventDangerImageService.saveBatch(images);
|
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
/**
|
* 隐患管理-关闭隐患单
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventRiskAnaUnit> closeDanger(Long userId, PreventCloseDangerReqDTO closeDangerReqDTO) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
//TODO 只有没有处理过的隐患,才能关闭
|
//封装参数
|
CloseDangerParams closeDangerParams = BeanCopyUtils.copyBean(closeDangerReqDTO, CloseDangerParams.class);
|
|
closeDangerParams.setDangerReview(StatusEnum.DANGER_RECTIFY_REVIEW.getCode());
|
closeDangerParams.setGmtModitify(new Date());
|
closeDangerParams.setLastEditUserName(userById.getRealName());
|
closeDangerParams.setUpdateReportDataTime(new Date());
|
|
int resultManage = preventDangerManageService.closeDanger(closeDangerParams);
|
if (resultManage < 1){
|
throw new BusinessException(E.UPDATE_FAIL, "关闭隐患管理信息失败");
|
}
|
//当做删除-进行同步
|
int resultRectify = preventDangerRectifyService.closeDanger(closeDangerParams);
|
if (resultRectify < 1){
|
throw new BusinessException(E.UPDATE_FAIL, "关闭隐患整改信息失败");
|
}
|
|
resultVO.setCount(resultManage);
|
|
return resultVO;
|
}
|
|
/**
|
* 隐患整改清单--验收
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> reportRectify(Long userId, PreventDangerReportRectifyReqDTO reportRectify) {
|
|
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);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
if (reportRectify.getId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "参数为空");
|
}
|
if (reportRectify.getDangerManagerId() == null ){
|
throw new BusinessException(E.DATA_PARAM_NULL, "参数为空");
|
}
|
if (reportRectify.getCheckAcceptDesc() == null){
|
throw new BusinessException(E.DATA_PARAM_NULL, "验收意见不能为空");
|
}
|
PreventDangerRectify rectifyById = preventDangerRectifyService.getRectifyById(reportRectify.getId());
|
if(!rectifyById.getCheckAcceptPersonId().equals(userId)){
|
throw new BusinessException(E.DATA_PARAM_NULL, "非验收人,无权操作");
|
}
|
// if (reportRectify.getAcceptImages() == null || reportRectify.getAcceptImages().size() < 1) {
|
// throw new BusinessException(E.DATA_PARAM_NULL, "上传图片为空");
|
// }
|
// 图片
|
// if (reportRectify.getAcceptImages().size() > 3) {
|
// throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "图片上传不能超过三张");
|
// }
|
// for (String path : reportRectify.getAcceptImages()) {
|
// if (StringUtils.isBlank(path)) {
|
// throw new BusinessException(E.DATA_PARAM_NULL, "图片上传不能为空路径");
|
// }
|
// }
|
PreventDangerManage dangerManageById = preventDangerManageService.getDangerManageById(reportRectify.getDangerManagerId());
|
if (dangerManageById.getDangerStatus() != StatusEnum.DANGER_MANAGER_WAIT_ACCEPT.getCode()){
|
throw new BusinessException(E.DATA_PARAM_CHECK_INVALID, "该整改单不是待验收状态,只有待验收的单据才可以同意验收");
|
}
|
|
//获取需要填充的信息
|
Date date = new Date();
|
//读取上报主配置
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_DANGER_INFO.getCode());
|
//封装参数
|
PreventDangerReportRectifyUpdayeParams reportParams = new PreventDangerReportRectifyUpdayeParams();
|
|
reportParams.setId(reportRectify.getId());
|
reportParams.setGmtModitify(date);
|
reportParams.setLastEditUserName(userById.getRealName());
|
reportParams.setCheckAcceptTime(date);
|
reportParams.setCheckAcceptDesc(reportRectify.getCheckAcceptDesc());
|
reportParams.setUpdateReportDataTime(date);
|
|
//设置本条数据上报更新时间 ,上报开关依赖于dangerManager
|
reportParams.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
reportParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
reportParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
}
|
|
int result = preventDangerRectifyService.reportRectify(reportParams);
|
if (result < 1) {
|
throw new BusinessException(E.UPDATE_FAIL, "验收信息提交失败");
|
}
|
//封装修改参数
|
UpdateRectifyResultParams updateParams = new UpdateRectifyResultParams();
|
updateParams.setDangerStatus(StatusEnum.DANGER_MANAGER_ACCEPT.getCode());
|
updateParams.setDangerManagerId(reportRectify.getDangerManagerId());
|
updateParams.setUpdateReportDataTime(date);
|
//设置为待验收
|
int RectifyResult= preventDangerManageService.updateRectifyResult(updateParams);
|
if (result < 1) {
|
throw new BusinessException(E.UPDATE_FAIL, "验收状态变更失败");
|
}
|
// 图片
|
// List<PreventDangerImage> images = new ArrayList<>();
|
// PreventDangerImage image;
|
// SnowFlow snowFlow = new SnowFlow();
|
// for (String path : reportRectify.getAcceptImages()) {
|
// image = new PreventDangerImage();
|
// image.setId(snowFlow.nextId());
|
// image.setImagePath(path);
|
// image.setParentId(reportRectify.getDangerManagerId());
|
// image.setStatus(DataConvertEnum.DELETE_STATUS_USE.getCode());
|
// image.setType(ImageTypeEnum.ACCEPT.getCode());
|
// images.add(image);
|
// }
|
// preventDangerImageService.saveBatch(images);
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 隐患整改清单-删除
|
*/
|
@Override
|
public ResultVO<PreventDangerRectify> deleteDangerRectify(Long userId, PreventDangerRectifyDeleteReqDTO rectifyDeleteReqDTO) {
|
|
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 (rectifyDeleteReqDTO.getId() == null ){
|
throw new BusinessException(E.DATA_DATABASE_NO_EXISTENT, "请选择正确的删除内容");
|
}
|
//获取需要填充的信息
|
Date date = new Date();
|
//封装删除需要的参数
|
deleteParams.setId(rectifyDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(date);
|
|
int result = preventDangerRectifyService.deleteDangerRectify(deleteParams);
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
|
@Override
|
public ResultVO countDangerByDate(LocalDate date) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode(ResultCodes.OK.getCode());
|
LocalDateTime startTime = LocalDateTime.of(date, LocalTime.of(0,0,0));
|
LocalDateTime endTime = LocalDateTime.of(date, LocalTime.of(23,59,59));
|
Date start = Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant());
|
Date end = Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant());
|
resultVO.setData(preventDangerManageService.countByCreateTime(start,end));
|
return resultVO;
|
}
|
|
@Override
|
public ResultVO<PreventDangerManageQueryRespDTO> findByDangerSerialCode(String serialCode) {
|
ResultVO<PreventDangerManageQueryRespDTO> resultVO = new ResultVO<>();
|
resultVO.setCode(ResultCodes.OK.getCode());
|
PreventDangerManage dangerManage = preventDangerManageService.findByDangerSerialCode(serialCode);
|
if(dangerManage != null){
|
PreventDangerManageQueryRespDTO respDTO = new PreventDangerManageQueryRespDTO();
|
BeanUtils.copyProperties(dangerManage,respDTO);
|
resultVO.setData(respDTO);
|
}
|
return resultVO;
|
}
|
|
@Override
|
public SearchResultVO<List<PreventDangerCheckTaskRectifyRespDTO>> listOwnRectifyPage(ContextCacheUser currentUser, PageQuery<OwnRectifyPageQuery> pageQuery) {
|
|
OwnRectifyPageDBQuery dbQuery = new OwnRectifyPageDBQuery();
|
dbQuery.setCurrentUid(currentUser.getUid());
|
Page<PreventDangerCheckTaskRectifyDO> page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize());
|
List<PreventDangerCheckTaskRectifyDO> dbData = preventDangerManageService.listOwnRectifyPage(page, dbQuery);
|
List<PreventDangerCheckTaskRectifyRespDTO> result = new ArrayList<>(dbData.size());
|
if (dbData.size() > 0) {
|
for (PreventDangerCheckTaskRectifyDO rectifyDO : dbData) {
|
PreventDangerCheckTaskRectifyRespDTO respDTO = new PreventDangerCheckTaskRectifyRespDTO();
|
|
respDTO.setManageId(rectifyDO.getManageId());
|
respDTO.setManageUuid(rectifyDO.getManageUuid());
|
respDTO.setRegisterTime(rectifyDO.getRegisterTime());
|
respDTO.setDangerLevel(rectifyDO.getDangerLevel());
|
respDTO.setDangerType(rectifyDO.getDangerType());
|
respDTO.setDangerSource(rectifyDO.getDangerSource());
|
respDTO.setDangerStatus(rectifyDO.getDangerStatus());
|
respDTO.setRegistantId(rectifyDO.getRegistantId());
|
respDTO.setProduceDeviceId(rectifyDO.getProduceDeviceId());
|
respDTO.setDangerCode(rectifyDO.getDangerCode());
|
respDTO.setRegistantName(rectifyDO.getRegistantName());
|
respDTO.setDangerDesc(rectifyDO.getDangerDesc());
|
respDTO.setDangerReason(rectifyDO.getDangerReason());
|
respDTO.setDangerResult(rectifyDO.getDangerResult());
|
respDTO.setDepId(rectifyDO.getDepId());
|
respDTO.setRiskUnitId(rectifyDO.getRiskUnitId());
|
respDTO.setDangerReview(rectifyDO.getDangerReview());
|
respDTO.setDangerCloseReason(rectifyDO.getDangerCloseReason());
|
respDTO.setRectifyId(rectifyDO.getRectifyId());
|
respDTO.setRectifyType(rectifyDO.getRectifyType());
|
respDTO.setRectifyTime(rectifyDO.getRectifyTime());
|
respDTO.setLiablePersonId(rectifyDO.getLiablePersonId());
|
respDTO.setCheckAcceptTime(rectifyDO.getCheckAcceptTime());
|
respDTO.setCheckAcceptPersonId(rectifyDO.getCheckAcceptPersonId());
|
respDTO.setLiablePerson(rectifyDO.getLiablePerson());
|
respDTO.setCheckAcceptPerson(rectifyDO.getCheckAcceptPerson());
|
respDTO.setRectifyDepId(rectifyDO.getRectifyDepId());
|
respDTO.setRectifyDesc(rectifyDO.getRectifyDesc());
|
respDTO.setCost(rectifyDO.getCost());
|
respDTO.setRectifyApplyTime(rectifyDO.getRectifyApplyTime());
|
respDTO.setTimeOutDesc(rectifyDO.getTimeOutDesc());
|
respDTO.setRectifyInfo(rectifyDO.getRectifyInfo());
|
result.add(respDTO);
|
}
|
}
|
|
return new SearchResultVO<>(
|
true,
|
page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
result, ResultCodes.OK);
|
}
|
|
/**
|
* 生成隐患编码
|
* @param time
|
* @param existCount
|
* @return
|
*/
|
private String generateDangerSerialCode(Date time,int existCount){
|
LocalDateTime t = time.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
LocalDate d = t.toLocalDate();
|
StringBuilder stringBuilder = new StringBuilder("");
|
stringBuilder.append(d.getYear());
|
int mon = d.getMonthValue();
|
if(mon < 10){
|
stringBuilder.append("0");
|
stringBuilder.append(mon);
|
}else {
|
stringBuilder.append(mon);
|
}
|
stringBuilder.append(d.getDayOfMonth());
|
stringBuilder.append('-');
|
int nowSerial = 0;
|
if(existCount > 0)
|
nowSerial = existCount + 1;
|
else
|
nowSerial = 1;
|
if(nowSerial < 10000){
|
if(nowSerial<10){
|
stringBuilder.append("000");
|
}else if(nowSerial>=10 && nowSerial<100){
|
stringBuilder.append("00");
|
}else if(nowSerial>=100 && nowSerial<1000){
|
stringBuilder.append("0");
|
}
|
stringBuilder.append(nowSerial);
|
}else {
|
stringBuilder.append(nowSerial);
|
}
|
return stringBuilder.toString();
|
}
|
}
|