package com.gkhy.safePlatform.doublePrevention.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserRPCRespDTO;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
|
import com.gkhy.safePlatform.commons.utils.idService.SnowFlow;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.doublePrevention.entity.*;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.req.*;
|
import com.gkhy.safePlatform.doublePrevention.entity.dto.resp.*;
|
import com.gkhy.safePlatform.doublePrevention.enums.DeviceStatusEnum;
|
import com.gkhy.safePlatform.doublePrevention.enums.StatusEnum;
|
import com.gkhy.safePlatform.doublePrevention.enums.SyncEnum;
|
import com.gkhy.safePlatform.doublePrevention.repository.param.*;
|
import com.gkhy.safePlatform.doublePrevention.service.ReportService;
|
import com.gkhy.safePlatform.doublePrevention.service.RiskService;
|
import com.gkhy.safePlatform.doublePrevention.service.baseService.*;
|
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.util.*;
|
|
@Service
|
public class RiskServiceImpl implements RiskService {
|
|
@DubboReference(check = false)
|
private AccountAuthService accountAuthService;
|
|
@DubboReference(check = false)
|
private AccountDepartmentService accountDepartmentService;
|
|
@Autowired
|
private PreventProduceDeviceService preventProduceDeviceService;
|
@Autowired
|
private PreventRiskMapService preventRiskMapService;
|
@Autowired
|
private PreventRiskAnaUnitService preventRiskUnitService;
|
@Autowired
|
private PreventRiskEventService preventRiskEventService;
|
@Autowired
|
private PreventRiskControlMeasureService preventRiskControlMeasureService;
|
@Autowired
|
private PreventDangerCheckContentService preventDangerCheckContentService;
|
@Autowired
|
private PreventRiskControlTemplateService preventRiskControlTemplateService;
|
@Autowired
|
private PreventReportConfigService preventReportConfigService;
|
//生产装置
|
/**
|
* 生产装置-分页查询
|
* */
|
@Override
|
public ResultVO<PreventProduceDevice> getDevicePage(PreventProduceDeviceQueryReqDTO deviceReqDto) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
List<PreventProduceDeviceQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = deviceReqDto.getPageIndex();
|
Integer pageSize = deviceReqDto.getPageSize();
|
//封装查询参数
|
PreventProduceDeviceQueryParams queryParams = new PreventProduceDeviceQueryParams();
|
if (ObjectUtils.isEmpty(deviceReqDto)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "数据传参为空");
|
}
|
if (deviceReqDto.getRiskLevel() != null ){
|
queryParams.setRiskLevel(deviceReqDto.getRiskLevel());
|
}
|
if (deviceReqDto.getStatus() != null ){
|
queryParams.setStatus(deviceReqDto.getStatus());
|
}
|
if (deviceReqDto.getDepId() != null ){
|
queryParams.setDepId(deviceReqDto.getDepId());
|
}
|
if (deviceReqDto.getLocation() != null ){
|
queryParams.setLocation(deviceReqDto.getLocation());
|
}
|
if (deviceReqDto.getProduceDeviceName() != null ){
|
queryParams.setProduceDeviceName(deviceReqDto.getProduceDeviceName());
|
}
|
|
//分页查询,获取到所有符合条件的数据
|
IPage<PreventProduceDevice> page =
|
preventProduceDeviceService.getDevicePage(new Page<>(pageIndex, pageSize), queryParams);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
for (PreventProduceDevice record : page.getRecords()) {
|
PreventProduceDeviceQueryRespDTO respDto = BeanCopyUtils.copyBean(record, PreventProduceDeviceQueryRespDTO.class);
|
//校验部门是否存在
|
respDto.setPageIndex((int) page.getCurrent());
|
respDto.setPageSize((int) page.getSize());
|
list.add(respDto);
|
}
|
resultVO.setCount((int) page.getTotal());
|
|
resultVO.setMsg("查询成功");
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 生产装置- 查询生产装置列表
|
*/
|
@Override
|
public ResultVO<PreventProduceDevice> getListDevices(Long valueOf) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventProduceDevice> listDevices = preventProduceDeviceService.getListDevices();
|
if (ObjectUtils.isEmpty(listDevices)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
List<PreventProduceDeviceListsQueryRespDTO> respDTOS =
|
BeanCopyUtils.copyBeanList(listDevices, PreventProduceDeviceListsQueryRespDTO.class);
|
|
resultVO.setData(respDTOS);
|
|
return resultVO;
|
}
|
|
/**
|
* 生产装置-根绝风险等级查询
|
* */
|
@Override
|
public ResultVO<PreventProduceDevice> getByLevel(PreventProduceDeviceQueryReqDTO deviceReqDto) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
PreventProduceDevice byLevel = preventProduceDeviceService.getByLevel(deviceReqDto.getRiskLevel());
|
resultVO.setData(byLevel);
|
return resultVO;
|
}
|
/**
|
* 生产装置-新增
|
* */
|
@Override
|
public ResultVO<PreventProduceDevice> saveDevice(Long userId, PreventProduceDeviceSaveReqDTO deviceSaveReqDto) {
|
|
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.getRealName())){
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
if (ObjectUtils.isEmpty(deviceSaveReqDto)){
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (deviceSaveReqDto.getProduceDeviceName() == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"生产装置名称不能为空");
|
}
|
//查找是否存在同名设备
|
PreventProduceDevice deviceByName = preventProduceDeviceService.getDeviceByName(deviceSaveReqDto.getProduceDeviceName());
|
if(!ObjectUtils.isEmpty(deviceByName)){
|
throw new AusinessException(E.DATA_DATABASE_DUPLICATED, "生产装置已存在,请检查装置名称是否正确,或为装置名称添加编号");
|
}
|
if (deviceSaveReqDto.getLocation() == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"生产装置所在位置不能为空");
|
}
|
if (deviceSaveReqDto.getRiskLevel() == null){
|
throw new RuntimeException("生产装置风险等级不能为空");
|
}
|
if (deviceSaveReqDto.getDepId() == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"生产装置责任部门不能为空");
|
}
|
//校验部门是否存在
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, deviceSaveReqDto.getDepId());
|
if(ObjectUtils.isEmpty(depInfoByDepId)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任部门");
|
}
|
//获取填充信息
|
Date date = new Date();
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
//封装参数
|
PreventProduceDevice device = BeanCopyUtils.copyBean(deviceSaveReqDto, PreventProduceDevice.class);
|
device.setId( snowFlow.nextId());
|
device.setUuid(uuid);
|
device.setStatus(DeviceStatusEnum.DEVICE_USE.getCode());
|
device.setEnterpriseId((long) 1);
|
device.setEnterpriseUuid("111");
|
|
device.setDepId(deviceSaveReqDto.getDepId());
|
DepInfoRPCRespDTO data = (DepInfoRPCRespDTO)depInfoByDepId.getData();
|
device.setDepName(data.getDepName());
|
device.setDepUuid(null);
|
|
device.setCreateByUserName(userById.getRealName());
|
device.setGmtCreate(date);
|
device.setLastEditUserName(userById.getRealName());
|
device.setGmtModitify(date);
|
device.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
//执行插入
|
int result = preventProduceDeviceService.saveDevice(device);
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
/**
|
* 生产装置-删除
|
* @param deviceDeleteReqDTO
|
* @return 查询结果
|
*/
|
@Override
|
public ResultVO<PreventProduceDevice> deleteOne(Long userId, PreventProduceDeviceDeleteReqDTO deviceDeleteReqDTO) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
|
PreventProduceDeviceDeleteParams param = new PreventProduceDeviceDeleteParams();
|
Date date = new Date();
|
|
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(deviceDeleteReqDTO)){
|
throw new RuntimeException("请检查是否正确选择删除项");
|
}
|
PreventProduceDevice device = preventProduceDeviceService.getDeviceById(deviceDeleteReqDTO.getId());
|
if (ObjectUtils.isEmpty(device)){
|
throw new RuntimeException("请检查该项是否已经被删除");
|
}
|
//检查生产装置的分析单元是否存在
|
List<PreventRiskAnaUnit> unitList = preventRiskUnitService.getRiskUnitByDeviceId(device.getId());
|
if (unitList.size() > 0){
|
throw new AusinessException(E.NOT_DELETE, "请先删除生产装置对应的分析单元");
|
}
|
//封装删除参数
|
param.setId(deviceDeleteReqDTO.getId());
|
param.setGmtModitify(date);
|
param.setLastEditUserName(userById.getRealName());
|
//执行删除
|
int result = preventProduceDeviceService.deleteById(param);
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 生产装置-修改
|
*/
|
@Override
|
public ResultVO<PreventProduceDevice> updateOneById(Long userId, PreventProduceDeviceUpdateReqDTO deviceUpdateReqDTO) {
|
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();
|
|
Date date = new Date();
|
if (ObjectUtils.isEmpty(deviceUpdateReqDTO)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "修改参数不能为空");
|
}
|
if (deviceUpdateReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请检查生产装置是否存在");
|
}
|
//检查修改信息的装置是否存在
|
PreventProduceDevice deviceById = preventProduceDeviceService.getDeviceById(deviceUpdateReqDTO.getId());
|
if(ObjectUtils.isEmpty(deviceById)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "生产装置不存在或已删除");
|
}
|
//检查要修改的名称,是否被占用
|
PreventProduceDevice deviceByName = preventProduceDeviceService.getDeviceByName(deviceUpdateReqDTO.getProduceDeviceName());
|
//如果查询结果不为空,且修改设备的id与查询到的设备id不同,名称已经被占用
|
if(!ObjectUtils.isNotEmpty(deviceByName) && !deviceByName.getId().equals(deviceUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "生产装置已存在,请检查装置名称是否正确,或为装置名称添加编号");
|
}
|
if (deviceUpdateReqDTO.getRiskLevel() == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "风险等级设置错误,请设置为以下之一:“低风险、一般风险、较大风险、重大风险");
|
}
|
|
if (deviceUpdateReqDTO.getDepId() == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"生产装置责任部门不能为空");
|
}
|
//校验部门是否存在
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, deviceUpdateReqDTO.getDepId());
|
DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO)depInfoByDepId.getData();
|
if(ObjectUtils.isEmpty(depInfoByDepId)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任部门");
|
}
|
|
if (deviceUpdateReqDTO.getProduceDeviceName() == null || deviceUpdateReqDTO.getProduceDeviceName() ==""){
|
throw new AusinessException(E.DATA_PARAM_NULL, "生产装置名称不能设置为空");
|
}
|
if (deviceUpdateReqDTO.getLocation() == null || deviceUpdateReqDTO.getLocation() ==""){
|
throw new AusinessException(E.DATA_PARAM_NULL, "生产装置所在地不能为空");
|
}
|
//封装修改参数
|
PreventProduceDeviceUpdateParams updateParams = new PreventProduceDeviceUpdateParams();
|
|
updateParams.setId(deviceUpdateReqDTO.getId());
|
updateParams.setRiskLevel(deviceUpdateReqDTO.getRiskLevel());
|
updateParams.setStatus(deviceUpdateReqDTO.getStatus());
|
updateParams.setProduceDeviceName(deviceUpdateReqDTO.getProduceDeviceName());
|
updateParams.setLocation(deviceUpdateReqDTO.getLocation());
|
|
updateParams.setDepId(deviceUpdateReqDTO.getDepId());
|
updateParams.setDepName(dep.getDepName());
|
updateParams.setDepUuid(null);
|
|
updateParams.setGmtModitify(date);
|
updateParams.setLastEditUserName(userById.getRealName());
|
//执行修改
|
int result = preventProduceDeviceService.updateProduceDevice(updateParams);
|
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
//风险分布图
|
/**
|
* 风险分布图-分页查询详细信息
|
*/
|
@Override
|
public ResultVO<PreventRiskMap> getMapPage(PreventRiskMapQueryReqDTO riskMapQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
List<PreventRiskMapQueryRespDTO> list = new ArrayList<>();
|
|
//获取流
|
FileInputStream inputStream = null;
|
String base64Str = "";
|
|
|
Integer pageIndex = riskMapQueryReqDTO.getPageIndex();
|
Integer pageSize = riskMapQueryReqDTO.getPageSize();
|
//执行查询
|
IPage<PreventRiskMap> page = preventRiskMapService.getMapPage(new Page<>(pageIndex, pageSize));
|
for (PreventRiskMap record : page.getRecords()) {
|
PreventRiskMapQueryRespDTO reqDto = BeanCopyUtils.copyBean(record, PreventRiskMapQueryRespDTO.class);
|
reqDto.setPageIndex((int) page.getCurrent());
|
reqDto.setPageSize((int) page.getSize());
|
//处理图片
|
try {
|
Base64.Encoder encoder = Base64.getEncoder();
|
String filePath = "F:/img/"+record.getImgPath();
|
inputStream = new FileInputStream(filePath);
|
int available = inputStream.available();
|
byte[] bytes = new byte[available];
|
inputStream.read(bytes);
|
base64Str = encoder.encodeToString(bytes);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
inputStream.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
reqDto.setImg(base64Str);
|
//封装数据
|
list.add(reqDto);
|
}
|
//封装返回数据
|
resultVO.setData(list);
|
resultVO.setCount((int) page.getTotal());
|
|
return resultVO;
|
}
|
|
/**
|
* 风险分布图-新增
|
*/
|
@Override
|
public ResultVO<PreventRiskMap> saveRiskMap(Long userId, PreventRiskMapSaveReqDTO riskMapSaveReqDTO) {
|
|
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();
|
PreventRiskMap riskMap = new PreventRiskMap();
|
MultipartFile image = riskMapSaveReqDTO.getImg();
|
|
//校验参数
|
if (image == null) {
|
resultVO.setCode("300");
|
resultVO.setMsg("请选择要上传的图片");
|
return resultVO;
|
}
|
if (image.getSize() > 1024 * 1024 * 10) {
|
resultVO.setCode("300");
|
resultVO.setMsg("文件大小不能大于10M");
|
return resultVO;
|
}
|
//获取文件后缀
|
String suffix = image.getOriginalFilename().substring(image.getOriginalFilename().lastIndexOf(".") + 1, image.getOriginalFilename().length());
|
if (!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())) {
|
resultVO.setCode("300");
|
resultVO.setMsg("请选择jpg,jpeg,gif,png格式的图片");
|
return resultVO;
|
}
|
//处理图片
|
String savePath = "F:/img/";
|
File savePathFile = new File(savePath);
|
if (!savePathFile.exists()) {
|
//若不存在该目录,则创建目录
|
savePathFile.mkdir();
|
}
|
//通过UUID生成唯一文件名
|
String filename = UUID.randomUUID().toString().replaceAll("-","") + "." + suffix;
|
try {
|
//将文件保存指定目录
|
//file.transferTo(new File(savePath + filename));
|
//File file1 = new File(file.getOriginalFilename());
|
FileUtils.copyInputStreamToFile(image.getInputStream(),new File(savePath + filename));
|
} catch (Exception e) {
|
e.printStackTrace();
|
resultVO.setCode("300");
|
resultVO.setMsg("保存文件异常");
|
return resultVO;
|
}
|
//获取id与uuid
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
//封装数据
|
//TODO
|
riskMap.setId(snowFlow.nextId());
|
riskMap.setUuid(uuid);
|
riskMap.setImgPath(filename);
|
riskMap.setDescInfo(riskMapSaveReqDTO.getDescInfo());
|
riskMap.setEnterpriseId((long) 1);
|
riskMap.setEnterpriseUuid("111");
|
riskMap.setCreateByUserName(userById.getRealName());
|
riskMap.setGmtCreate(date);
|
riskMap.setLastEditUserName(userById.getRealName());
|
riskMap.setGmtModitify(date);
|
riskMap.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
//执行插入
|
int result = preventRiskMapService.saveRiskMap(riskMap);
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 风险分布图-删除
|
*/
|
@Override
|
public ResultVO<PreventRiskMap> deleteRiskMap(Long userId, PreventRiskMapDeleteReqDTO riskMapDeleteReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
//获取用户信息
|
|
if (riskMapDeleteReqDTO.getId() == null){
|
throw new RuntimeException("请选择删除内容");
|
}
|
//执行删除
|
int result = preventRiskMapService.deleteRiskMap(riskMapDeleteReqDTO.getId());
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "删除失败");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 风险分布图-修改
|
*/
|
@Override
|
public ResultVO<PreventRiskMap> updateRiskMap(Long userId, PreventRiskMapUpdateReqDTO riskMapUpdateReqDTO) {
|
|
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();
|
|
PreventRiskMapUpdateParams params = new PreventRiskMapUpdateParams();
|
Date date = new Date();
|
//封装修改参数
|
params.setId(riskMapUpdateReqDTO.getId());
|
params.setDescInfo(riskMapUpdateReqDTO.getDescInfo());
|
params.setGmtModitify(date);
|
params.setLastEditUserName(userById.getRealName());
|
//修改
|
int result = preventRiskMapService.updateRiskMap(params);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "删除失败");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
//风险分析单元
|
/**
|
* 风险分析单元-分页查询
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> getRiskUnitPage(Long userId, PreventRiskAnaUnitQueryReqDTO riskAnaUnitQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
List<PreventRiskAnaUnitQueryRespDTO> list = new ArrayList<>();
|
Integer pageIndex = riskAnaUnitQueryReqDTO.getPageIndex();
|
Integer pageSize = riskAnaUnitQueryReqDTO.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();
|
//校验参数
|
//分页查询
|
IPage<PreventRiskAnaUnit> page = preventRiskUnitService.getRiskUnitPage(new Page<>(pageIndex, pageSize), riskAnaUnitQueryReqDTO);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
for (PreventRiskAnaUnit record : page.getRecords()) {
|
PreventRiskAnaUnitQueryRespDTO respDto = BeanCopyUtils.copyBean(record, PreventRiskAnaUnitQueryRespDTO.class);
|
//封装设备名称
|
PreventProduceDevice deviceById = preventProduceDeviceService.getDeviceById(record.getProduceDeviceId());
|
respDto.setPageIndex((int) page.getCurrent());
|
respDto.setPageSize((int) page.getSize());
|
respDto.setProduceDeviceName(deviceById.getProduceDeviceName());
|
//封装上报配置信息
|
respDto.setReportState(reportConfigById.getReportState());
|
respDto.setReportType(reportConfigById.getReportType());
|
list.add(respDto);
|
}
|
resultVO.setCount((int) page.getTotal());
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 风险分析单元-新增
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> saveRiskAnaUnit(Long userId, PreventRiskAnaUnitSaveReqDTO riskAnaUnitSaveReqDTO) {
|
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();
|
|
PreventRiskMap riskMap = new PreventRiskMap();
|
|
//校验参数
|
if (ObjectUtils.isEmpty(riskAnaUnitSaveReqDTO)){
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (riskAnaUnitSaveReqDTO.getRiskCode() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险分析编码不能为空");
|
}
|
if (riskAnaUnitSaveReqDTO.getRiskUnitName() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险分析单元名称不能为空");
|
}
|
//判断是否存在同名单元
|
PreventRiskAnaUnit riskUnitById = preventRiskUnitService.getRiskUnitByName(riskAnaUnitSaveReqDTO.getRiskUnitName());
|
if (!ObjectUtils.isEmpty(riskUnitById)){
|
throw new AusinessException(E.DATA_DATABASE_DUPLICATED, "存在同名单元,请修改名称,或为单元添加编号");
|
}
|
//判断是否存在同名编码
|
PreventRiskAnaUnit riskUnitByCode = preventRiskUnitService.getRiskUnitByCode(riskAnaUnitSaveReqDTO.getRiskCode());
|
if (!ObjectUtils.isEmpty(riskUnitByCode)){
|
throw new AusinessException(E.DATA_DATABASE_DUPLICATED, "存在同名风险编码,请修改编码");
|
}
|
if (riskAnaUnitSaveReqDTO.getLiableDepId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "责任部门不能为空");
|
}
|
//校验部门是否存在
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, riskAnaUnitSaveReqDTO.getLiableDepId());
|
if(ObjectUtils.isEmpty(depInfoByDepId)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任部门");
|
}
|
DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO)depInfoByDepId.getData();
|
|
if (riskAnaUnitSaveReqDTO.getLiablePersonId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "责任人不能为空");
|
}
|
|
if (riskAnaUnitSaveReqDTO.getProduceDeviceId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "生产装置不能为空");
|
}
|
PreventProduceDevice deviceById = preventProduceDeviceService.getDeviceById(riskAnaUnitSaveReqDTO.getProduceDeviceId());
|
if (ObjectUtils.isEmpty(deviceById)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "未找到对应的生产装置");
|
}
|
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
ResultVO<UserRPCRespDTO> liablePersonResult = accountAuthService.getUserById(riskAnaUnitSaveReqDTO.getLiablePersonId());
|
UserRPCRespDTO liablePerson = (UserRPCRespDTO)liablePersonResult.getData();
|
//封装参数
|
PreventRiskAnaUnit riskAnaUnit = BeanCopyUtils.copyBean(riskAnaUnitSaveReqDTO, PreventRiskAnaUnit.class);
|
|
riskAnaUnit.setId(snowFlow.nextId());
|
riskAnaUnit.setUuid(uuid);
|
riskAnaUnit.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
|
riskAnaUnit.setEnterpriseId((long) 1);
|
riskAnaUnit.setProduceDeviceId(deviceById.getId());
|
riskAnaUnit.setProduceDeviceUuid(deviceById.getUuid());
|
riskAnaUnit.setEnterpriseUuid("111");
|
riskAnaUnit.setLiablePerson(liablePerson.getRealName());
|
riskAnaUnit.setLiablePersonUuid(liablePerson.getUuid());
|
riskAnaUnit.setLiableDep(dep.getDepName());
|
riskAnaUnit.setLiableDepUuid(null);
|
|
riskAnaUnit.setGmtModitify(date);
|
riskAnaUnit.setGmtCreate(date);
|
riskAnaUnit.setCreateByUserName(userById.getRealName());
|
riskAnaUnit.setLastEditUserName(userById.getRealName());
|
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
//设置上报时间为空
|
riskAnaUnit.setReportTime(null);
|
//设置本条数据上报更新时间
|
riskAnaUnit.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
riskAnaUnit.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
riskAnaUnit.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
riskAnaUnit.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
riskAnaUnit.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
}
|
|
int result = preventRiskUnitService.saveRiskAnaUnit(riskAnaUnit);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "删除失败");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 风险分析单元-修改
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateRiskAnaUnitById(Long userId, PreventRiskAnaUnitUpdateReqDTO riskAnaUnitUpdateReqDTO) {
|
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();
|
PreventRiskMap riskMap = new PreventRiskMap();
|
PreventRiskAnaUnitUpdateParams params = new PreventRiskAnaUnitUpdateParams();
|
Date date = new Date();
|
|
//校验参数
|
if (ObjectUtils.isEmpty(riskAnaUnitUpdateReqDTO)){
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
if (riskAnaUnitUpdateReqDTO.getRiskCode() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险分析编码不能为空");
|
}
|
if (riskAnaUnitUpdateReqDTO.getRiskUnitName() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险分析单元名称不能为空");
|
}
|
//判断是否存在同名单元
|
PreventRiskAnaUnit riskUnitById = preventRiskUnitService.getRiskUnitByName(riskAnaUnitUpdateReqDTO.getRiskUnitName());
|
//如果查询结果不为空,且查询到的id与请求的id不同——被占用
|
if (ObjectUtils.isNotEmpty(riskUnitById) && !riskUnitById.getId().equals(riskAnaUnitUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_DATABASE_DUPLICATED, "存在同名单元,请修改名称,或为单元添加编号");
|
}
|
//判断是否存在同名编码
|
PreventRiskAnaUnit riskUnitByCode = preventRiskUnitService.getRiskUnitByCode(riskAnaUnitUpdateReqDTO.getRiskCode());
|
if (ObjectUtils.isNotEmpty(riskUnitByCode) && !riskUnitByCode.getId().equals(riskAnaUnitUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_DATABASE_DUPLICATED, "存在同名风险编码,请修改编码");
|
}
|
if (riskAnaUnitUpdateReqDTO.getLiableDepId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "责任部门不能为空");
|
}
|
if (riskAnaUnitUpdateReqDTO.getLiablePersonId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "责任人不能为空");
|
}
|
//校验人是否存在
|
ResultVO<DepInfoRPCRespDTO> depInfoByDepId = accountDepartmentService.getDepInfoByDepId(userId, riskAnaUnitUpdateReqDTO.getLiableDepId());
|
DepInfoRPCRespDTO liableDep = (DepInfoRPCRespDTO)depInfoByDepId.getData();
|
if(ObjectUtils.isEmpty(depInfoByDepId)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任人");
|
}
|
|
|
//获取责任人信息
|
ResultVO<UserRPCRespDTO> liablePersonResult = accountAuthService.getUserById(riskAnaUnitUpdateReqDTO.getLiablePersonId());
|
UserRPCRespDTO liablePerson = (UserRPCRespDTO)liablePersonResult.getData();
|
if(ObjectUtils.isEmpty(liablePerson)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"请输入正确责任部门");
|
}
|
//TODO 查询责任人,判断是否存在 ?责任人与责任部门是否需要关联--需要方法,getUserByName
|
|
if (riskAnaUnitUpdateReqDTO.getProduceDeviceId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "生产装置不能为空");
|
}
|
PreventProduceDevice deviceByName = preventProduceDeviceService.getDeviceById(riskAnaUnitUpdateReqDTO.getProduceDeviceId());
|
if (ObjectUtils.isEmpty(deviceByName)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "未找到对应的生产装置");
|
}
|
|
//封装修改参数
|
params.setId(riskAnaUnitUpdateReqDTO.getId());
|
params.setRiskUnitName(riskAnaUnitUpdateReqDTO.getRiskUnitName());
|
params.setRiskCode(riskAnaUnitUpdateReqDTO.getRiskCode());
|
params.setProduceDeviceId(deviceByName.getId());
|
params.setProduceDeviceUuid(deviceByName.getUuid());
|
params.setLiableDepId(riskAnaUnitUpdateReqDTO.getLiableDepId());
|
params.setLiablePersonId(riskAnaUnitUpdateReqDTO.getLiablePersonId());
|
params.setLiablePersonUuid(liablePerson.getUuid());
|
params.setLiableDepUuid(null);
|
params.setLiablePerson(liablePerson.getRealName());
|
params.setLiableDep(liableDep.getDepName());
|
params.setLiableDep(liableDep.getDepName());
|
params.setUpdateReportDataTime(date);
|
params.setGmtModitify(date);
|
params.setLastEditUserName(userById.getRealName());
|
params.setUpdateReportDataTime(date);
|
|
//获取上报主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
//设置本条数据上报更新时间
|
params.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
params.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
params.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
params.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
params.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
}
|
|
int result = preventRiskUnitService.updateRiskAnaUnitById(params);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.UPDATE_FAIL, "修改失败");
|
}
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 安全风险分析单元-手工上报-配置
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateRiskAnaUnitReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
int result ;
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
if (preventHandReportConfigReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
if (preventHandReportConfigReqDTO.getReportSwitch() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
//查询当前隐患的配置
|
PreventRiskAnaUnit riskUnitById = preventRiskUnitService.getRiskUnitById(preventHandReportConfigReqDTO.getId());
|
//配置相同
|
if (riskUnitById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同");
|
}
|
//读取主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode());
|
//只有当开启上报,且类型为手动上报时,可以修改
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
result = preventRiskUnitService.updateRiskAnaUnitReport(preventHandReportConfigReqDTO);
|
|
}else {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 风险分析单元-删除
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> deleteRiskAnaUnitById(Long userId, PreventRiskAnaUnitDeleteReqDTO riskAnaUnitDeleteReqDTO) {
|
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();
|
|
PreventRiskMap riskMap = new PreventRiskMap();
|
PreventRiskAnaUnitDeleteParams deleteParams = new PreventRiskAnaUnitDeleteParams();
|
|
Date date = new Date();
|
//校验参数
|
if (ObjectUtils.isEmpty(riskAnaUnitDeleteReqDTO)) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "请选择删除内容");
|
}
|
//检查风险分析单元对应的风险事件是否全部删除
|
List<PreventRiskEvent> eventList = preventRiskEventService.getRiskEventNameByRiskUnitId(riskAnaUnitDeleteReqDTO.getId());
|
if (eventList.size() > 0){
|
throw new AusinessException(E.NOT_DELETE, "请先删除风险分析单元对应的风险事件");
|
}
|
//封装参数
|
deleteParams.setId(riskAnaUnitDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(date);
|
//删除
|
int result = preventRiskUnitService.deleteRiskAnaUnitById(deleteParams);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "删除失败");
|
}
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 风险单元list查询
|
*/
|
@Override
|
public ResultVO<PreventRiskEvent> listRiskUnits(Long userId) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
//List<PreventRiskEventQueryRespDTO> list = new ArrayList<>();
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData();
|
//校验用户信息
|
if (ObjectUtils.isEmpty(userById)) {
|
throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR);
|
}
|
List<PreventRiskAnaUnit> riskAnaUnits = preventRiskUnitService.listRiskUnits();
|
if (ObjectUtils.isEmpty(riskAnaUnits)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//List<PreventRiskEventListRiskUnitsRespDTO> respDTOS = BeanCopyUtils.copyBeanList(riskAnaUnits, PreventRiskEventListRiskUnitsRespDTO.class);
|
List<PreventRiskEventListRiskUnitsRespDTO> list = new ArrayList<>();
|
for (PreventRiskAnaUnit riskAnaUnit : riskAnaUnits) {
|
PreventRiskEventListRiskUnitsRespDTO respDTO = BeanCopyUtils.copyBean(riskAnaUnit, PreventRiskEventListRiskUnitsRespDTO.class);
|
PreventProduceDevice deviceById = preventProduceDeviceService.getDeviceById(respDTO.getProduceDeviceId());
|
respDTO.setProduceDeviceName(deviceById.getProduceDeviceName());
|
list.add(respDTO);
|
}
|
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
//风险事件
|
/**
|
* 风险事件-分页查询
|
*/
|
@Override
|
public ResultVO<PreventRiskEvent> getRiskEventPage(Long userId, PreventRiskEventQueryReqDTO riskEventQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
List<PreventRiskEventQueryRespDTO> list = new ArrayList<>();
|
PreventRiskEventQueryParams queryParams = new PreventRiskEventQueryParams();
|
Integer pageIndex = riskEventQueryReqDTO.getPageIndex();
|
Integer pageSize = riskEventQueryReqDTO.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 (riskEventQueryReqDTO.getRiskUnitId() != null ){
|
queryParams.setRiskUnitId(riskEventQueryReqDTO.getRiskUnitId());
|
}
|
if (riskEventQueryReqDTO.getRiskEventName() != null && riskEventQueryReqDTO.getRiskEventName() != ""){
|
queryParams.setRiskEventName(riskEventQueryReqDTO.getRiskEventName());
|
}
|
//获取事件上报配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_EVENT.getCode());
|
//获取到所有符合条件的事件
|
IPage<PreventRiskEvent> page = preventRiskEventService.getRiskEventPage(new Page<>(pageIndex, pageSize), queryParams);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//遍历集合,为符合条件的事件添加单元名称
|
for (PreventRiskEvent record : page.getRecords()) {
|
PreventRiskAnaUnit riskUnitById = preventRiskUnitService.getRiskUnitById(record.getRiskUnitId());
|
PreventRiskEventQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventRiskEventQueryRespDTO.class);
|
respDTO.setRiskUnitName(riskUnitById.getRiskUnitName());
|
respDTO.setRiskUnitId(riskUnitById.getId());
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setPageSize((int) page.getSize());
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
list.add(respDTO);
|
}
|
resultVO.setCount((int) page.getTotal());
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 风险事件-新增
|
*/
|
@Override
|
public ResultVO<PreventRiskEvent> saveRiskEvent(Long userId, PreventRiskEventSaveReqDTO riskEventSaveReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("新增成功");
|
PreventRiskEvent riskEvent = new PreventRiskEvent();
|
|
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 (riskEventSaveReqDTO.getRiskEventName() == null && riskEventSaveReqDTO.getRiskEventName() != ""){
|
throw new AusinessException(E.DATA_PARAM_NULL, "事件不能为空");
|
}
|
//检查是否已经存在同名参数
|
PreventRiskEvent riskEventByName = preventRiskEventService.getRiskEventByName(riskEventSaveReqDTO.getRiskEventName());
|
if (!ObjectUtils.isEmpty(riskEventByName)){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "存在同名事件,轻为新事件改名或添加编号");
|
}
|
|
if (riskEventSaveReqDTO.getRiskUnitId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险分析单元不能为空");
|
}
|
PreventRiskAnaUnit riskUnitById = preventRiskUnitService.getRiskUnitById(riskEventSaveReqDTO.getRiskUnitId());
|
if (ObjectUtils.isEmpty(riskUnitById)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请选择正确的风险分析单元");
|
}
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
//封装参数
|
riskEvent.setId(snowFlow.nextId());
|
riskEvent.setUuid(uuid);
|
riskEvent.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
riskEvent.setRiskEventName(riskEventSaveReqDTO.getRiskEventName());
|
|
riskEvent.setRiskUnitId(riskUnitById.getId());
|
riskEvent.setRiskUnitUuid(riskUnitById.getUuid());
|
|
riskEvent.setEnterpriseId((long) 1);
|
riskEvent.setEnterpriseUuid("111");
|
riskEvent.setGmtModitify(date);
|
riskEvent.setGmtCreate(date);
|
riskEvent.setCreateByUserName(userById.getRealName());
|
riskEvent.setLastEditUserName(userById.getRealName());
|
riskEvent.setEventResult(riskEventSaveReqDTO.getEventResult());
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_EVENT.getCode());
|
//设置上报时间为空
|
riskEvent.setReportTime(null);
|
//设置本条数据上报更新时间
|
riskEvent.setUpdateReportDataTime(date);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
riskEvent.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
riskEvent.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
riskEvent.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
riskEvent.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
}
|
|
int result = preventRiskEventService.saveRiskEvent(riskEvent);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "新增失败");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 风险事件-修改
|
*/
|
@Override
|
public ResultVO<PreventRiskEvent> updateRiskEvent(Long userId, PreventRiskEventUpdateReqDTO riskEventUpdateReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
PreventRiskEventUpdateParams updateParams = new PreventRiskEventUpdateParams();
|
Date data = new Date();
|
|
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 (riskEventUpdateReqDTO.getRiskEventName() == null && riskEventUpdateReqDTO.getRiskEventName() != ""){
|
throw new AusinessException(E.DATA_PARAM_NULL, "事件不能为空");
|
}
|
//TODO 问题,只修改单元,也会被拦截
|
//检查是否已经存在同名参数
|
PreventRiskEvent riskEventByName = preventRiskEventService.getRiskEventByName(riskEventUpdateReqDTO.getRiskEventName());
|
//如果查询结果不为空,且查询到的id与请求的id不同——被占用
|
if (!ObjectUtils.isEmpty(riskEventByName) && !riskEventByName.getId().equals(riskEventUpdateReqDTO.getId())){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "存在同名事件,轻为新事件改名或添加编号");
|
}
|
|
if (riskEventUpdateReqDTO.getRiskUnitId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险分析单元不能为空");
|
}
|
PreventRiskAnaUnit riskUnitById = preventRiskUnitService.getRiskUnitById(riskEventUpdateReqDTO.getRiskUnitId());
|
if (ObjectUtils.isEmpty(riskUnitById)){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请选择正确的风险分析单元");
|
}
|
|
//获取需要填充的信息
|
updateParams.setId(riskEventUpdateReqDTO.getId());
|
updateParams.setRiskEventName(riskEventUpdateReqDTO.getRiskEventName());
|
updateParams.setRiskUnitId(riskUnitById.getId());
|
updateParams.setRiskUnitUuid(riskUnitById.getUuid());
|
updateParams.setGmtModitify(data);
|
updateParams.setLastEditUserName(userById.getRealName());
|
updateParams.setEventResult(riskEventUpdateReqDTO.getEventResult());
|
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_EVENT.getCode());
|
|
//设置本条数据上报更新时间
|
updateParams.setUpdateReportDataTime(data);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
updateParams.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
updateParams.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作
|
}else {
|
//设置上报状态为-不上报
|
updateParams.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
updateParams.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
}
|
|
int result = preventRiskEventService.updateRiskEvent(updateParams);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "修改失败");
|
}
|
resultVO.setCount(result);
|
|
return resultVO;
|
}
|
|
/**
|
* 安全风险事件-手工上报-配置
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateRiskEventReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
if (preventHandReportConfigReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
if (preventHandReportConfigReqDTO.getReportSwitch() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
//查询当前隐患的配置
|
PreventRiskEvent riskEventNameById = preventRiskEventService.getRiskEventNameById(preventHandReportConfigReqDTO.getId());
|
//配置相同,做处理
|
if (riskEventNameById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同");
|
}
|
int result ;
|
//读取主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_EVENT.getCode());
|
//只有当开启上报,且类型为手动上报时,可以修改
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
result = preventRiskEventService.updateRiskEventReport(preventHandReportConfigReqDTO);
|
|
}else {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 风险事件-事件list
|
*/
|
@Override
|
public ResultVO<PreventRiskEvent> getListEvents(Long userId) {
|
|
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);
|
}
|
List<PreventRiskEvent> preventRiskEvents = preventRiskEventService.getListEvents();
|
if (ObjectUtils.isEmpty(preventRiskEvents)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
List<PreventRiskEventsListQueryRespDTO> respDTOS
|
= BeanCopyUtils.copyBeanList(preventRiskEvents, PreventRiskEventsListQueryRespDTO.class);
|
|
resultVO.setData(respDTOS);
|
resultVO.setCount(respDTOS.size());
|
return resultVO;
|
}
|
|
/**
|
* 风险事件-删除
|
*/
|
@Override
|
public ResultVO<PreventRiskEvent> deleteRiskEvent(Long userId, PreventRiskEventDeleteReqDTO riskEventDeleteReqDTO) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
PreventRiskEvent riskEvent = new PreventRiskEvent();
|
Date data = new Date();
|
|
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();
|
PreventDeleteParams deleteParams = new PreventDeleteParams();
|
//校验参数
|
if (riskEventDeleteReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "请选择要删除的内容");
|
}
|
//检查风险事件对应的管控措施
|
List<PreventRiskControlMeasure> measureList =
|
preventRiskControlMeasureService.getRiskControlMeasureByRiskEventId(riskEventDeleteReqDTO.getId());
|
if (measureList.size() > 0){
|
throw new AusinessException(E.NOT_DELETE, "请先删除风险事件对应的风险管控措施");
|
}
|
//封装参数
|
deleteParams.setId(riskEventDeleteReqDTO.getId());
|
deleteParams.setGmtModitify(data);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(data);
|
int result = preventRiskEventService.deleteRiskEventById(deleteParams);
|
//结果校验
|
if (result == 0){
|
throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "删除失败");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
//管控措施
|
/**
|
* 管控措施-分页查询
|
*/
|
@Override
|
public ResultVO<PreventRiskControlMeasure> getRiskControlMeasurePage(Long userId, PreventRiskControlMeasureQueryReqDTO measureQueryReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
List<PreventRiskControlMeasureQueryRespDTO> list = new ArrayList<>();
|
PreventRiskControlMeasureQueryParams queryParams = new PreventRiskControlMeasureQueryParams();
|
Integer pageIndex = measureQueryReqDTO.getPageIndex();
|
Integer pageSize = measureQueryReqDTO.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 (measureQueryReqDTO.getControlType() != null) {
|
queryParams.setControlType(measureQueryReqDTO.getControlType());
|
}
|
if (measureQueryReqDTO.getRiskEventId() != null) {
|
queryParams.setRiskEventId(measureQueryReqDTO.getRiskEventId());
|
}
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_MEASURE.getCode());
|
//获取到所有符合条件的措施
|
IPage<PreventRiskControlMeasure> page =
|
preventRiskControlMeasureService.getRiskControlMeasurePage(new Page<>(pageIndex, pageSize), queryParams);
|
if (ObjectUtils.isEmpty(page.getRecords())){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
//遍历集合,为符合条件的措施添加事件名称
|
for (PreventRiskControlMeasure record : page.getRecords()) {
|
PreventRiskControlMeasureQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventRiskControlMeasureQueryRespDTO.class);
|
//为措施添加事件名称
|
PreventRiskEvent riskEventNameById = preventRiskEventService.getRiskEventNameById(record.getRiskEventId());
|
respDTO.setRiskEventName(riskEventNameById.getRiskEventName());
|
//为措施添加隐患排查内容
|
PreventDangerCheckContent checkContent = preventDangerCheckContentService.getCheckContentByMeasureId(record.getId());
|
respDTO.setCheckContent(checkContent.getCheckContent());
|
respDTO.setPageSize((int) page.getSize());
|
respDTO.setPageIndex((int) page.getCurrent());
|
respDTO.setReportState(reportConfigById.getReportState());
|
respDTO.setReportType(reportConfigById.getReportType());
|
list.add(respDTO);
|
}
|
resultVO.setData(list);
|
resultVO.setCount((int) page.getTotal());
|
return resultVO;
|
}
|
|
/**
|
* 生产装置ID- 查询单元
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> getRiskAnaUnitByDeviceId(Long uid, Long deviceId) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
|
//获取用户信息
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(uid);
|
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();
|
|
List<PreventRiskAnaUnit> riskUnitByDeviceId = preventRiskUnitService.getRiskUnitByDeviceId(deviceId);
|
if (ObjectUtils.isEmpty(riskUnitByDeviceId)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
PreventProduceDevice deviceById = preventProduceDeviceService.getDeviceById(deviceId);
|
|
List<PreventGetAnaUnitByDeviceIdRespDTO> list = new ArrayList<>();
|
for (PreventRiskAnaUnit preventRiskAnaUnit : riskUnitByDeviceId) {
|
PreventGetAnaUnitByDeviceIdRespDTO respDTO = BeanCopyUtils.copyBean(preventRiskAnaUnit, PreventGetAnaUnitByDeviceIdRespDTO.class);
|
respDTO.setProduceDeviceName(deviceById.getProduceDeviceName());
|
list.add(respDTO);
|
}
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 安全风险事件-手工上报-配置
|
*/
|
@Override
|
public ResultVO<PreventRiskAnaUnit> updateMeasuresReport(Long userId, PreventHandReportConfigReqDTO preventHandReportConfigReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("修改成功");
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(userId);
|
if (rpcResult == null) {
|
throw new BusinessException(ResultCodes.RPC_RESULT_NULL);
|
}
|
if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) {
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
if (rpcResult.getData() == null) {
|
throw new BusinessException(ResultCodes.RPC_DATA_NULL);
|
}
|
if (!(rpcResult.getData() instanceof UserRPCRespDTO)) {
|
throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH);
|
}
|
if (preventHandReportConfigReqDTO.getId() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
if (preventHandReportConfigReqDTO.getReportSwitch() == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "传参非法");
|
}
|
//查询当前隐患的配置
|
PreventRiskControlMeasure controlMeasureById = preventRiskControlMeasureService.getControlMeasureById(preventHandReportConfigReqDTO.getId());
|
//配置相同,做处理
|
if (controlMeasureById.getReportSwitch() == preventHandReportConfigReqDTO.getReportSwitch()){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同");
|
}
|
int result ;
|
//读取主配置信息
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_MEASURE.getCode());
|
//只有当开启上报,且类型为手动上报时,可以修改
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()
|
&& reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
result = preventRiskControlMeasureService.updateMeasuresReport(preventHandReportConfigReqDTO);
|
|
}else {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "当前上报配置,不支持对单条数据操作");
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 管控措施-新增
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventRiskControlMeasure> saveRiskControlMeasure(Long userId, PreventRiskControlMeasureSaveReqDTO measureSaveReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("新增成功");
|
PreventDangerCheckContent checkContent = new PreventDangerCheckContent();
|
|
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 (measureSaveReqDTO.getRiskEventId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险事件不能为空");
|
}
|
PreventRiskEvent riskEventById = preventRiskEventService.getRiskEventNameById(measureSaveReqDTO.getRiskEventId());
|
if (ObjectUtils.isEmpty(riskEventById)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "请检查风险事件是否正确");
|
}
|
if (measureSaveReqDTO.getControlType() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控方式不能为空,或设置有误");
|
}
|
if (measureSaveReqDTO.getClassify1() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控方式分类1不能为空,或设置有误");
|
}
|
if (measureSaveReqDTO.getClassify2() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控方式分类2不能为空,或设置有误");
|
}
|
if (measureSaveReqDTO.getControlMeasureCode() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控措施编码不能为空");
|
}
|
PreventRiskControlMeasure riskControlMeasureByCode =
|
preventRiskControlMeasureService.getRiskControlMeasureByCodeAndEventId(riskEventById.getId(), measureSaveReqDTO.getControlMeasureCode());
|
if (ObjectUtils.isNotEmpty(riskControlMeasureByCode)){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "本事件已经存在同编码的管控措施,请修改名称或添加编号");
|
}
|
if (measureSaveReqDTO.getCheckContent() == null && measureSaveReqDTO.getCheckContent() == ""){
|
throw new AusinessException(E.DATA_PARAM_NULL, "检查内容不能为空");
|
}
|
|
//获取需要填充的信息
|
SnowFlow snowFlow = new SnowFlow();//雪花算法生成器
|
String uuid = UUID.randomUUID().toString();
|
Date date = new Date();
|
long measureId = snowFlow.nextId();
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_MEASURE.getCode());
|
//封装管控措施参数
|
PreventRiskControlMeasure controlMeasure = BeanCopyUtils.copyBean(measureSaveReqDTO, PreventRiskControlMeasure.class);
|
controlMeasure.setId(measureId);
|
controlMeasure.setUuid(uuid);
|
controlMeasure.setControlMeasureCode(measureSaveReqDTO.getControlMeasureCode());
|
controlMeasure.setRiskEventId(riskEventById.getId());
|
controlMeasure.setRiskEventUuid(riskEventById.getUuid());
|
controlMeasure.setEnterpriseId((long) 1);
|
controlMeasure.setEnterpriseUuid("123");
|
controlMeasure.setDeleteStatus(StatusEnum.DELETE_STATUS_USE.getCode());
|
controlMeasure.setGmtModitify(date);
|
controlMeasure.setGmtCreate(date);
|
controlMeasure.setCreateByUserName(userById.getRealName());
|
controlMeasure.setLastEditUserName(userById.getRealName());
|
|
//创建管控措施不需要的字段填充
|
controlMeasure.setCheckTaskUnitId(null);
|
controlMeasure.setCheckTaskUnitUuid(null);
|
controlMeasure.setCheckWorkId(null);
|
controlMeasure.setCheckWorkUuid(null);
|
controlMeasure.setCheckTaskId(null);
|
controlMeasure.setCheckTaskUuid(null);
|
|
controlMeasure.setReportTime(null);
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode()){
|
//自动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){
|
//设置上报状态为-等待上报
|
controlMeasure.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode());
|
//设置本条数据上报开关为-开启
|
controlMeasure.setReportSwitch(SyncEnum.REPORT_ON.getCode());
|
//设置本条数据上报更新时间
|
controlMeasure.setUpdateReportDataTime(date);
|
}
|
//手动上报
|
if (reportConfigById.getReportType() == SyncEnum.REPORT_AUTO_EXEC_CONFIG.getCode()){
|
//设置上报状态为-不上报
|
controlMeasure.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
controlMeasure.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
controlMeasure.setUpdateReportDataTime(date);
|
}
|
}
|
//如果主配置关闭上报功能
|
if (reportConfigById.getReportState() == SyncEnum.REPORT_OFF.getCode()){
|
//设置上报状态为-不上报
|
controlMeasure.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode());
|
//设置本条数据上报开关为-关闭
|
controlMeasure.setReportSwitch(SyncEnum.REPORT_OFF.getCode());
|
//设置本条数据上报更新时间
|
controlMeasure.setUpdateReportDataTime(date);
|
}
|
|
//封装隐患检查内容的参数
|
checkContent.setControlMeasureId(measureId);
|
checkContent.setControlMeasureUuid(uuid);
|
checkContent.setCheckContent(measureSaveReqDTO.getCheckContent());
|
|
|
//执行措施插入
|
int measureResult = preventRiskControlMeasureService.saveRiskControlMeasure(controlMeasure);
|
//执行隐患检查内容插入
|
int checkContentResult = preventDangerCheckContentService.saveDangerCheckContent(checkContent);
|
|
resultVO.setCount(measureResult);
|
return resultVO;
|
}
|
|
/**
|
* 管控措施-修改
|
*/
|
@Transactional
|
@Override
|
public ResultVO<PreventRiskControlMeasure> updateRiskControlMeasure(Long userId, PreventRiskControlMeasureUpdateReqDTO measureUpdateReqDTO) {
|
|
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();
|
|
PreventRiskAnaUnitUpdateParams params = new PreventRiskAnaUnitUpdateParams();
|
PreventDangerCheckContent checkContent = new PreventDangerCheckContent();
|
Date date = new Date();
|
|
//校验参数
|
if (measureUpdateReqDTO.getRiskEventId() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "风险事件不能为空");
|
}
|
//根据事件名称查询信息
|
PreventRiskEvent riskEventById = preventRiskEventService.getRiskEventNameById(measureUpdateReqDTO.getRiskEventId());
|
if (ObjectUtils.isEmpty(riskEventById)){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "请检查风险事件是否正确");
|
}
|
if (measureUpdateReqDTO.getControlType() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控方式不能为空,或设置有误");
|
}
|
if (measureUpdateReqDTO.getClassify1() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控方式分类1不能为空,或设置有误");
|
}
|
if (measureUpdateReqDTO.getClassify2() == null){
|
throw new AusinessException(E.DATA_PARAM_NULL, "管控方式分类2不能为空,或设置有误");
|
}
|
//根据措施编码与事件id查询
|
PreventRiskControlMeasure riskControlMeasureById
|
= preventRiskControlMeasureService.getRiskControlMeasureByCodeAndEventId(riskEventById.getId(), measureUpdateReqDTO.getControlMeasureCode());
|
//如果查询结果不为空,且查询到的id与请求的id不同——被占用
|
if (ObjectUtils.isNotEmpty(riskControlMeasureById) && !measureUpdateReqDTO.getId().equals(riskControlMeasureById.getId())){
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "本事件已经存在同编码的管控措施,请修改名称或添加编号");
|
}
|
if (measureUpdateReqDTO.getCheckContent() == null && measureUpdateReqDTO.getCheckContent() == ""){
|
throw new AusinessException(E.DATA_PARAM_NULL, "检查内容不能为空");
|
}
|
|
//封装修改参数
|
PreventRiskControlMeasureUpdateParams updateParams =
|
BeanCopyUtils.copyBean(measureUpdateReqDTO, PreventRiskControlMeasureUpdateParams.class);
|
|
updateParams.setRiskEventId(riskEventById.getId());
|
updateParams.setRiskEventUuid(riskEventById.getUuid());
|
updateParams.setGmtModitify(date);
|
updateParams.setLastEditUserName(userById.getRealName());
|
PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_MEASURE.getCode());
|
//读取上报主配置,进行任务记录上报配置,如果开启上报功能
|
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);
|
}
|
|
//执行内容修改
|
preventDangerCheckContentService.updateDangerCheckContent(measureUpdateReqDTO.getId(), measureUpdateReqDTO.getCheckContent());
|
//执行措施修改
|
int result = preventRiskControlMeasureService.updateRiskControlMeasure(updateParams);
|
if (result == 0){
|
throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
|
}
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
/**
|
* 管控措施- 管控措施模板
|
*/
|
@Override
|
public ResultVO<PreventRiskControlMeasure> listMeasures(Long userId) {
|
|
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();
|
|
List<PreventRiskControlTemplate> listMeasureTemplates = preventRiskControlTemplateService.listMeasureTemplates();
|
|
List<PreventRiskMeasureTemplatesListQueryRespDTO> respDTOS
|
= BeanCopyUtils.copyBeanList(listMeasureTemplates, PreventRiskMeasureTemplatesListQueryRespDTO.class);
|
|
resultVO.setCount(respDTOS.size());
|
resultVO.setData(respDTOS);
|
return resultVO;
|
}
|
/**
|
* 管控措施- 管控措施列表
|
*/
|
@Override
|
public ResultVO<PreventRiskControlMeasure> listControlMeasure(ContextCacheUser currentUser) {
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("查询成功");
|
//获取用户信息
|
|
ResultVO<UserRPCRespDTO> rpcResult = accountAuthService.getUserById(currentUser.getUid());
|
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();
|
|
List<PreventRiskControlMeasure> listControlMeasures = preventRiskControlMeasureService.listControlMeasure();
|
if (ObjectUtils.isEmpty(listControlMeasures)){
|
resultVO.setMsg("查询成功,无数据");
|
return resultVO;
|
}
|
List<PreventRiskControlMeasureListRespDTO> list = new ArrayList<>();
|
//List<PreventRiskControlMeasureListRespDTO> respDTOS = BeanCopyUtils.copyBeanList(listControlMeasures, PreventRiskControlMeasureListRespDTO.class);
|
for (PreventRiskControlMeasure controlMeasure : listControlMeasures) {
|
PreventDangerCheckContent checkContentByMeasureId = preventDangerCheckContentService.getCheckContentByMeasureId(controlMeasure.getId());
|
PreventRiskControlMeasureListRespDTO respDTO = BeanCopyUtils.copyBean(controlMeasure, PreventRiskControlMeasureListRespDTO.class);
|
respDTO.setCheckContent(checkContentByMeasureId.getCheckContent());
|
list.add(respDTO);
|
}
|
|
resultVO.setCount(list.size());
|
resultVO.setData(list);
|
|
return resultVO;
|
}
|
|
/**
|
* 管控措施-删除
|
*/
|
@Override
|
public ResultVO<PreventRiskControlMeasure> deleteRiskControlMeasure(Long userId, PreventRiskControlMeasureDeleteReqDTO measureDeleteReqDTO) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("删除成功");
|
|
PreventRiskControlMeasureDeleteParams deleteParams = new PreventRiskControlMeasureDeleteParams();
|
Date date = new Date();
|
|
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);
|
}
|
//校验参数,封装id
|
if (measureDeleteReqDTO.getId() != null){
|
deleteParams.setId(measureDeleteReqDTO.getId());
|
}
|
PreventRiskControlMeasure controlMeasure
|
= preventRiskControlMeasureService.getControlMeasureById(measureDeleteReqDTO.getId());
|
/* //如果riskWorkId,checkTaskUnitId不为空,不能删除
|
if (controlMeasure.getRiskWorkId() != null && controlMeasure.getCheckTaskUnitId() != null){
|
throw new AusinessException(E.NOT_DELETE, "需要先把检查作业、检查任务对该措施的使用取消");
|
}*/
|
//封装措施修改参数
|
deleteParams.setGmtModitify(date);
|
deleteParams.setLastEditUserName(userById.getRealName());
|
deleteParams.setUpdateReportDataTime(date);
|
|
int result = preventRiskControlMeasureService.deleteRiskControlMeasure(deleteParams);
|
//校验结果
|
if (result == 0) {
|
throw new AusinessException(E.NOT_DELETE, "删除失败");
|
}
|
|
resultVO.setCount(result);
|
return resultVO;
|
}
|
|
|
|
|
/**
|
* 风险分布图-图
|
*/
|
@Override
|
public ResultVO<PreventRiskMap> getMapImage(Long id) {
|
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode("200");
|
resultVO.setMsg("成功");
|
|
|
FileInputStream inputStream = null;
|
String base64Str = "";
|
try {
|
Base64.Encoder encoder = Base64.getEncoder();
|
|
PreventRiskMap mapById = preventRiskMapService.getById(id);
|
String filePath = "F:/img/"+mapById.getImgPath();
|
|
inputStream = new FileInputStream(filePath);
|
int available = inputStream.available();
|
byte[] bytes = new byte[available];
|
inputStream.read(bytes);
|
base64Str = encoder.encodeToString(bytes);
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
try {
|
inputStream.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
resultVO.setData(base64Str);
|
|
return resultVO;
|
}
|
}
|