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.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.vo.ResultVO; import com.gkhy.safePlatform.doublePrevention.entity.*; import com.gkhy.safePlatform.doublePrevention.entity.dto.report.req.*; import com.gkhy.safePlatform.doublePrevention.entity.dto.report.resp.*; import com.gkhy.safePlatform.doublePrevention.entity.dto.req.PreventReportConfigLogQueryReqDTO; import com.gkhy.safePlatform.doublePrevention.entity.dto.req.PreventReportConfigUpdateReqDTO; import com.gkhy.safePlatform.doublePrevention.entity.dto.resp.PreventReportConfigLogQueryRespDTO; import com.gkhy.safePlatform.doublePrevention.entity.dto.resp.PreventReportConfigQueryRespDTO; import com.gkhy.safePlatform.doublePrevention.repository.param.PreventReportConfigUpdateParams; import com.gkhy.safePlatform.doublePrevention.service.ReportService; import com.gkhy.safePlatform.doublePrevention.service.baseService.*; 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 java.util.ArrayList; import java.util.Date; import java.util.List; @Service public class ReportServiceImpl implements ReportService { @DubboReference(check = false) private AccountAuthService accountAuthService; @Autowired private PreventReportConfigService preventReportConfigService; @Autowired private PreventReportConfigLogService preventReportConfigLogService; @Autowired private PreventReportRiskAnaUnitService riskAnaUnitService; @Autowired private PreventReportRiskEventService eventService; @Autowired private PreventReportRiskControlMeasureService measureService; @Autowired private PreventReportCheckTaskFromWorkService taskFromWorkService; @Autowired private PreventReportCheckRecordFromTaskService taskService; @Autowired private PreventReportDangerInfoService dangerInfoService; /** * 数据上报配置-查询 */ @Override public ResultVO getReportConfig(Long userId) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); //获取用户信息,校验 ResultVO rpcResult = accountAuthService.getUserById(userId); if (rpcResult == null) { throw new BusinessException(ResultCodes.RPC_RESULT_NULL); } if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) { throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg()); } if (rpcResult.getData() == null) { throw new BusinessException(ResultCodes.RPC_DATA_NULL); } if (!(rpcResult.getData() instanceof UserRPCRespDTO)) { throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH); } UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } //查询配置 List configList= preventReportConfigService.ListReportConfigs(); //封装DTO List respDTO = BeanCopyUtils.copyBeanList(configList, PreventReportConfigQueryRespDTO.class); //封装返回数据 resultVO.setCount(respDTO.size()); resultVO.setData(respDTO); return resultVO; } /** * 数据上报配置-修改 */ @Transactional @Override public ResultVO updateReportConfig(Long userId, PreventReportConfigUpdateReqDTO updateReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("修改成功"); int step = 1; //获取用户信息,校验 ResultVO rpcResult = accountAuthService.getUserById(userId); if (rpcResult == null) { throw new BusinessException(ResultCodes.RPC_RESULT_NULL); } if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) { throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg()); } if (rpcResult.getData() == null) { throw new BusinessException(ResultCodes.RPC_DATA_NULL); } if (!(rpcResult.getData() instanceof UserRPCRespDTO)) { throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH); } UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } //封装修改参数 PreventReportConfigUpdateParams updateParams = BeanCopyUtils.copyBean(updateReqDTO, PreventReportConfigUpdateParams.class); updateParams.setGmtModitify(new Date()); updateParams.setLastEditUserName(userById.getRealName()); //按照id查询配置,并保存历史记录 String updateInfo = null; if (step ==1){ PreventReportConfig oldReportConfigById = preventReportConfigService.getReportConfigById(updateReqDTO.getId()); if (oldReportConfigById.getReportState().equals(updateReqDTO.getReportState()) && oldReportConfigById.getReportType().equals(updateReqDTO.getReportType()) ){ throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "与当前配置相同,无需修改"); } //取出数据,存入log表 PreventReportConfigLog preventReportConfigLog = new PreventReportConfigLog(); //封装log表参数 preventReportConfigLog.setReportState(oldReportConfigById.getReportState()); preventReportConfigLog.setReportType(oldReportConfigById.getReportType()); preventReportConfigLog.setReportData(oldReportConfigById.getReportData()); preventReportConfigLog.setReportDataName(oldReportConfigById.getReportDataName()); preventReportConfigLog.setLastEditUserName(oldReportConfigById.getLastEditUserName()); preventReportConfigLog.setGmtModitify(oldReportConfigById.getGmtModitify()); //插入数据进log表 int i = preventReportConfigLogService.insertOldReportConfig(preventReportConfigLog); if (i < 1){ throw new AusinessException(E.UPDATE_FAIL, "历史记录保存失败"); } step = 2; } //修改配置信息 if (step == 2){ int result = preventReportConfigService.updateReportConfig(updateParams); if (result < 1){ throw new AusinessException(E.UPDATE_FAIL, "修改配置失败"); } resultVO.setCount(result); } return resultVO; } /** * 数据上报配置历史记录-查询 */ @Override public ResultVO getReportConfigLogPage(Long userId, PreventReportConfigLogQueryReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); int step = 1; //获取用户信息,校验 ResultVO rpcResult = accountAuthService.getUserById(userId); if (rpcResult == null) { throw new BusinessException(ResultCodes.RPC_RESULT_NULL); } if (!ResultCodes.OK.getCode().equals(rpcResult.getCode())) { throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg()); } if (rpcResult.getData() == null) { throw new BusinessException(ResultCodes.RPC_DATA_NULL); } if (!(rpcResult.getData() instanceof UserRPCRespDTO)) { throw new BusinessException(ResultCodes.RPC_DATA_TYPE_NOT_MATCH); } UserRPCRespDTO userById = (UserRPCRespDTO)rpcResult.getData(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } //获取到所有符合条件任务 IPage page = preventReportConfigLogService.getReportConfigLogPage(new Page<>(queryReqDTO.getPageIndex(), queryReqDTO.getPageSize()), queryReqDTO); //获取返回前端对象集合,封装DTO数据 List list = new ArrayList<>(); for (PreventReportConfigLog record : page.getRecords()) { PreventReportConfigLogQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventReportConfigLogQueryRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } /** * 上报数据-风险分析单元-分页查询 */ @Override public ResultVO getReportRiskUnitPage(ContextCacheUser currentUser, PreReportRiskUnitQueryReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = queryReqDTO.getPageIndex(); Integer pageSize = queryReqDTO.getPageSize(); int step = 1; //获取用户信息,校验 ResultVO 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(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } List list = new ArrayList<>(); //分页查询 IPage page = riskAnaUnitService.getReportRiskUnitPage(new Page<>(pageIndex, pageSize), queryReqDTO); for (PreventReportRiskAnaUnit record : page.getRecords()) { PreReportRiskUnitQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreReportRiskUnitQueryRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } /** * 上报数据-事件-分页查询 */ @Override public ResultVO getReportEventPage(ContextCacheUser currentUser, PreReportRiskEventQueryReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = queryReqDTO.getPageIndex(); Integer pageSize = queryReqDTO.getPageSize(); int step = 1; //获取用户信息,校验 ResultVO 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(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } List list = new ArrayList<>(); //分页查询 IPage page = eventService.getReportRiskEventPage(new Page<>(pageIndex, pageSize), queryReqDTO); for (PreventReportRiskEvent record : page.getRecords()) { PreReportRiskEventQueryRespDTO respDTO = BeanCopyUtils.copyBean(record, PreReportRiskEventQueryRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } /** * 上报数据-管控措施-分页查询 */ @Override public ResultVO getReportMeasurePage(ContextCacheUser currentUser, PreventReportRiskControlMeasureReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = queryReqDTO.getPageIndex(); Integer pageSize = queryReqDTO.getPageSize(); int step = 1; //获取用户信息,校验 ResultVO 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(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } List list = new ArrayList<>(); //分页查询 IPage page = measureService.getReportMeasurePage(new Page<>(pageIndex, pageSize), queryReqDTO); for (PreventReportRiskControlMeasure record : page.getRecords()) { PreventReportRiskControlMeasureRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventReportRiskControlMeasureRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } /** * 上报数据-任务配置-分页查询 */ @Override public ResultVO getReportTaskFromWorkPage(ContextCacheUser currentUser, PreventReportCheckTaskFromWorkReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = queryReqDTO.getPageIndex(); Integer pageSize = queryReqDTO.getPageSize(); int step = 1; //获取用户信息,校验 ResultVO 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(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } List list = new ArrayList<>(); //分页查询 IPage page = taskFromWorkService.getReportTaskFromWorkPage(new Page<>(pageIndex, pageSize), queryReqDTO); for (PreventReportCheckTaskFromWork record : page.getRecords()) { PreventReportCheckTaskFromWorkRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventReportCheckTaskFromWorkRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } /** * 上报数据-任务记录-分页查询 */ @Override public ResultVO getRecordFromTaskPage(ContextCacheUser currentUser, PreventReportCheckRecordFromTaskReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = queryReqDTO.getPageIndex(); Integer pageSize = queryReqDTO.getPageSize(); int step = 1; //获取用户信息,校验 ResultVO 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(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } List list = new ArrayList<>(); //分页查询 IPage page = taskService.getReportTaskFromWorkPage(new Page<>(pageIndex, pageSize), queryReqDTO); for (PreventReportCheckRecordFromTask record : page.getRecords()) { PreventReportCheckRecordFromTaskRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventReportCheckRecordFromTaskRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } /** * 上报数据-隐患信息-分页查询 */ @Override public ResultVO getReportDangerInfoPage(ContextCacheUser currentUser, PreventReportDangerInfoReqDTO queryReqDTO) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); Integer pageIndex = queryReqDTO.getPageIndex(); Integer pageSize = queryReqDTO.getPageSize(); int step = 1; //获取用户信息,校验 ResultVO 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(); if (ObjectUtils.isEmpty(userById)) { throw new BusinessException(ResultCodes.CLIENT_IDENTITY_CHECK_ERROR); } List list = new ArrayList<>(); //分页查询 IPage page = dangerInfoService.getReportDangerInfoPage(new Page<>(pageIndex, pageSize), queryReqDTO); for (PreventReportDangerInfo record : page.getRecords()) { PreventReportDangerInfoRespDTO respDTO = BeanCopyUtils.copyBean(record, PreventReportDangerInfoRespDTO.class); respDTO.setPageIndex((int) page.getCurrent()); respDTO.setPageSize((int) page.getSize()); list.add(respDTO); } resultVO.setCount((int) page.getTotal()); resultVO.setData(list); return resultVO; } }