feat(govern): 添加治理方案功能并重构相关数据模型

- 引入PqGovernPlan实体类及对应的数据库映射
- 实现治理方案的增删改查API接口和服务逻辑
- 集成治理方案与监测点、敏感用户的关联关系
- 更新设备交付数据传输对象和持久化对象结构
- 修改台账服务以支持治理方案数据展示
- 优化治理报告生成功能,基于治理方案进行数据查询
- 移除过时的设备治理类型字段,统一使用治理方案管理
This commit is contained in:
xy
2026-06-16 16:26:43 +08:00
parent d44b4f3576
commit 9438f75c01
23 changed files with 873 additions and 219 deletions

View File

@@ -0,0 +1,117 @@
package com.njcn.csharmonic.controller;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csharmonic.pojo.param.PqGovernPlanParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqGovernPlanVo;
import com.njcn.csharmonic.service.IPqGovernPlanService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author xy
* @since 2026-06-16
*/
@RestController
@RequestMapping("/pqGovernPlan")
@Api(tags = "治理方案管理")
@AllArgsConstructor
public class PqGovernPlanController extends BaseController {
private final IPqGovernPlanService pqGovernPlanService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/save")
@ApiOperation("新增治理方案")
public HttpResult<Boolean> save(@RequestBody @Validated PqGovernPlanParam param) {
String methodDescribe = getMethodDescribe("save");
boolean result = pqGovernPlanService.save(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/update")
@ApiOperation("修改治理方案")
public HttpResult<Boolean> update(@RequestBody @Validated PqGovernPlanParam.UpdatePqGovernPlanParam param) {
String methodDescribe = getMethodDescribe("update");
boolean result = pqGovernPlanService.update(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/delete")
@ApiOperation("删除治理方案")
@ApiImplicitParam(name = "ids", value = "ID集合")
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
boolean result = pqGovernPlanService.delete(ids);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/getById")
@ApiOperation("根据ID查询治理方案")
@ApiImplicitParam(name = "id", value = "ID", required = true)
public HttpResult<PqGovernPlan> getById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getById");
PqGovernPlan plan = pqGovernPlanService.getById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, plan, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/getListByPid")
@ApiOperation("根据pid查询所有治理方案")
@ApiImplicitParam(name = "pid", value = "用户id关联pq_sensitive_user的id", required = true)
public HttpResult<List<PqGovernPlanVo>> getListByPid(@RequestParam("pid") String pid) {
String methodDescribe = getMethodDescribe("getListByPid");
List<PqGovernPlanVo> list = pqGovernPlanService.getListByPid(pid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/getListExcludeNull")
@ApiOperation("查询所有治理方案(剔除治理前后监测点为空的数据)")
public HttpResult<List<PqGovernPlan>> getListExcludeNull() {
String methodDescribe = getMethodDescribe("getListExcludeNull");
List<PqGovernPlan> list = pqGovernPlanService.getListExcludeNull();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/clearGovernPoints")
@ApiOperation("清空治理前后监测点数据")
@ApiImplicitParam(name = "id", value = "治理方案ID", required = true)
public HttpResult<Boolean> clearGovernPoints(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("clearGovernPoints");
boolean result = pqGovernPlanService.clearGovernPoints(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getListByMonitorPoint")
@ApiOperation("清空治理前后监测点数据")
@ApiImplicitParam(name = "ids", value = "监测点id集合", required = true)
public HttpResult<List<PqGovernPlan>> getListByMonitorPoint(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("clearGovernPoints");
List<PqGovernPlan> result = pqGovernPlanService.getListByMonitorPoint(ids);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -1,8 +1,6 @@
package com.njcn.csharmonic.controller;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
@@ -11,17 +9,14 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csharmonic.pojo.param.PqSensitiveUserParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqSensitiveUserVo;
import com.njcn.csharmonic.service.IPqSensitiveUserService;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
@@ -30,11 +25,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* <p>
@@ -52,7 +44,6 @@ import java.util.stream.Collectors;
public class PqSensitiveUserController extends BaseController {
private final IPqSensitiveUserService pqSensitiveUserService;
private final CsLineFeignClient csLineFeignClient;
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
private final EquipmentFeignClient equipmentFeignClient;
@@ -83,27 +74,7 @@ public class PqSensitiveUserController extends BaseController {
@ApiImplicitParam(name = "ids", value = "id集合")
public HttpResult<List<PqSensitiveUser>> getListByIds(@RequestParam(name = "ids", required = false) List<String> ids) {
String methodDescribe = getMethodDescribe("getListByIds");
List<PqSensitiveUser> list;
//获取用户监测点
List<String> keywordsLineIds = new ArrayList<>();
List<String> devIds = csCommTerminalFeignClient.getDevIdsByUser(RequestUtil.getUserIndex()).getData();
if (CollUtil.isNotEmpty(devIds)) {
List<CsEquipmentDeliveryDTO> devList = equipmentFeignClient.queryDeviceById(devIds).getData();
keywordsLineIds = devList.stream().map(CsEquipmentDeliveryDTO::getMonitorUser).filter(Objects::nonNull).distinct().collect(Collectors.toList());
}
if (CollUtil.isEmpty(keywordsLineIds)) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
if (CollUtil.isNotEmpty(ids)) {
keywordsLineIds = ids;
}
}
list = pqSensitiveUserService.list(
new LambdaQueryWrapper<PqSensitiveUser>().in(PqSensitiveUser::getId, keywordsLineIds)
);
if (CollUtil.isEmpty(list)) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
List<PqSensitiveUser> list = pqSensitiveUserService.getListByIds(ids);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@@ -150,12 +121,12 @@ public class PqSensitiveUserController extends BaseController {
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getUserDevTree")
@ApiOperation("治理用户与设备关系树")
@ApiImplicitParam(name = "type", value = "治理类型")
public HttpResult<Map<String,List<CsEquipmentDeliveryPO>>> getUserDevTree(@RequestParam(name = "type") String type) {
@ApiOperation("治理方案树(敏感用户+治理方案)")
@ApiImplicitParam(name = "type", value = "治理类型(apf→稳态harmonic, 其他→暂态event)", required = true)
public HttpResult<Map<String, List<PqGovernPlan>>> getUserDevTree(@RequestParam("type") String type) {
String methodDescribe = getMethodDescribe("getUserDevTree");
Map<String,List<CsEquipmentDeliveryPO>> map = pqSensitiveUserService.getUserDevTree(type);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, map, methodDescribe);
Map<String, List<PqGovernPlan>> tree = pqSensitiveUserService.getUserDevTree(type);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tree, methodDescribe);
}
}

View File

@@ -0,0 +1,18 @@
package com.njcn.csharmonic.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xy
* @since 2026-06-16
*/
@DS("sjzx")
public interface PqGovernPlanMapper extends BaseMapper<PqGovernPlan> {
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.csdevice.mapper.PqGovernPlanMapper">
</mapper>

View File

@@ -0,0 +1,72 @@
package com.njcn.csharmonic.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csharmonic.pojo.param.PqGovernPlanParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqGovernPlanVo;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xy
* @since 2026-06-16
*/
public interface IPqGovernPlanService extends IService<PqGovernPlan> {
/**
* 新增治理方案
*
* @param param 治理方案参数
*/
boolean save(PqGovernPlanParam param);
/**
* 修改治理方案
*
* @param param 治理方案参数
*/
boolean update(PqGovernPlanParam.UpdatePqGovernPlanParam param);
/**
* 删除治理方案
*
* @param ids 治理方案ID集合
*/
boolean delete(List<String> ids);
/**
* 根据pid查询所有治理方案
* @param pid 用户id
* @return 治理方案列表
*/
List<PqGovernPlanVo> getListByPid(String pid);
/**
* 查询所有治理方案(剔除governBefore和governAfter为null的数据,按sort升序)
*
* @return 治理方案列表
*/
List<PqGovernPlan> getListExcludeNull();
/**
* 根据id清空治理前后监测点数据
*
* @param id 治理方案ID
*/
boolean clearGovernPoints(String id);
/**
* 根据监测点id查询所有治理方案(匹配治理前或治理后)
*
* @param ids 监测点id集合
* @return 治理方案列表
*/
List<PqGovernPlan> getListByMonitorPoint(List<String> ids);
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csharmonic.pojo.param.PqSensitiveUserParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqSensitiveUserVo;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.web.pojo.param.BaseParam;
@@ -25,10 +26,20 @@ public interface IPqSensitiveUserService extends IService<PqSensitiveUser> {
List<PqSensitiveUserVo> getListByUser(BaseParam param);
List<PqSensitiveUser> getListByIds(List<String> ids);
boolean save(PqSensitiveUserParam pqSensitiveUserParam);
boolean update(PqSensitiveUserParam.UpdatePqSensitiveUserParam pqSensitiveUserParam);
Map<String,List<CsEquipmentDeliveryPO>> getUserDevTree(String type);
/**
* 根据敏感用户和治理方案形成树结构
*
* @param type 治理类型(apf→harmonic, 其他→event)
* @return 敏感用户名称为key, 治理方案列表为value的树结构
*/
Map<String, List<PqGovernPlan>> getUserDevTree(String type);
}

View File

@@ -29,11 +29,13 @@ import com.njcn.csharmonic.enums.CsHarmonicResponseEnum;
import com.njcn.csharmonic.param.SensitiveUserReportQueryParam;
import com.njcn.csharmonic.pojo.dto.ReportTemplateDTO;
import com.njcn.csharmonic.pojo.param.ReportTemplateParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.ReportTemplateDataVO;
import com.njcn.csharmonic.pojo.vo.ReportTreeVO;
import com.njcn.csharmonic.pojo.vo.SysDeptTempVO;
import com.njcn.csharmonic.service.CustomReportService;
import com.njcn.csharmonic.service.ICsSysExcelRelationService;
import com.njcn.csharmonic.service.IPqGovernPlanService;
import com.njcn.csharmonic.utils.DataChangeUtil;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
@@ -96,25 +98,18 @@ import java.util.stream.Stream;
public class CustomReportServiceImpl implements CustomReportService {
private final ExcelRptTempMapper excelRptTempMapper;
private final EpdFeignClient epdFeignClient;
private final FileStorageUtil fileStorageUtil;
private final DicDataFeignClient dicDataFeignClient;
private final InfluxDbUtils influxDbUtils;
private final CommTerminalGeneralClient commTerminalGeneralClient;
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
private final CustomReportTableService customReportTableService;
private final WlRecordFeignClient wlRecordFeignClient;
private final UserFeignClient userFeignClient;
private final CsLineFeignClient csLineFeignClient;
private final ICsSysExcelRelationService sysExcelService;
private final IPqGovernPlanService pqGovernPlanService;
private final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
private final JdbcTemplate jdbcTemplate;
@@ -279,31 +274,19 @@ public class CustomReportServiceImpl implements CustomReportService {
@Override
public void getSensitiveUserReport(SensitiveUserReportQueryParam queryParam, HttpServletResponse response) {
String devId = queryParam.getSensitiveUserId();
List<CsLinePO> linePOList = csLineFeignClient.getLinesByDevList(Collections.singletonList(devId)).getData();
DictData loadSideDictData = dicDataFeignClient.getDicDataByCode(LOAD_SIDE_DICT_CODE).getData();
DictData gridSideDictData = dicDataFeignClient.getDicDataByCode(GRID_SIDE_DICT_CODE).getData();
CsLinePO gridSideLine = linePOList.stream().filter(linePO -> linePO.getPosition().equals(gridSideDictData.getId())).findFirst().orElse(null);
CsLinePO loadSideLine = linePOList.stream().filter(linePO -> linePO.getPosition().equals(loadSideDictData.getId())).findFirst().orElse(null);
if(Objects.isNull(gridSideLine) || Objects.isNull(loadSideLine)) {
throw new BusinessException("电网侧与负载侧监测点缺失,无法生成报告!");
PqGovernPlan pqGovernPlan = pqGovernPlanService.getById(queryParam.getSensitiveUserId());
if(Objects.isNull(pqGovernPlan.getGovernBefore()) || Objects.isNull(pqGovernPlan.getGovernAfter())) {
throw new BusinessException("治理前后监测点缺失,无法生成报告!");
}
String tempId = getTempId(queryParam.getTempId(), Objects.isNull(gridSideLine)? loadSideLine.getLineId():gridSideLine.getLineId());
CsLinePO po1 = csLineFeignClient.getById(pqGovernPlan.getGovernBefore()).getData();
CsLinePO po2 = csLineFeignClient.getById(pqGovernPlan.getGovernAfter()).getData();
String tempId = getTempId(queryParam.getTempId(), pqGovernPlan.getGovernAfter());
queryParam.setTempId(tempId);
TimeInterval timeInterval = new TimeInterval();
// ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(queryParam.getTempId());
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(tempId);
if (Objects.isNull(excelRptTemp)) {
throw new BusinessException(CsHarmonicResponseEnum.CUSTOM_REPORT_ACTIVE);
}
// String sensitiveUserId = queryParam.getSensitiveUserId();
// List<CsLinePO> linePOList = csLineFeignClient.getLineBySensitiveUser(Collections.singletonList(sensitiveUserId)).getData();
// DictData loadSideDictData = dicDataFeignClient.getDicDataByCode(LOAD_SIDE_DICT_CODE).getData();
// DictData gridSideDictData = dicDataFeignClient.getDicDataByCode(GRID_SIDE_DICT_CODE).getData();
// CsLinePO gridSideLine = linePOList.stream().filter(linePO -> linePO.getPosition().equals(gridSideDictData.getId())).findFirst().orElse(null);
// CsLinePO loadSideLine = linePOList.stream().filter(linePO -> linePO.getPosition().equals(loadSideDictData.getId())).findFirst().orElse(null);
String lineName1 = "";
String lineName2 = "";
// 模版内容数据
@@ -331,14 +314,14 @@ public class CustomReportServiceImpl implements CustomReportService {
indexDataList = new LinkedHashSet<>(indexDataList).stream().sorted(Comparator.comparing(ReportTemplateDataVO::getItemName)).collect(Collectors.toList());
Map<String, List<ReportTemplateDataVO>> classMap = indexDataList.stream().collect(Collectors.groupingBy(ReportTemplateDataVO::getResourceId));
//定义存放指标的map
if (loadSideLine != null) {
lineName1 = loadSideLine.getName();
List<ReportTemplateDataVO> beforeDataList = fetchDataList(loadSideLine, classMap, queryParam);
if (po1 != null) {
lineName1 = po1.getName();
List<ReportTemplateDataVO> beforeDataList = fetchDataList(po1, classMap, queryParam);
beforeFinalDataList.addAll(beforeDataList);
}
if (gridSideLine != null) {
lineName2 = gridSideLine.getName();
List<ReportTemplateDataVO> afterDataList = fetchDataList(gridSideLine, classMap, queryParam);
if (po2 != null) {
lineName2 = po2.getName();
List<ReportTemplateDataVO> afterDataList = fetchDataList(po2, classMap, queryParam);
afterFinalDataList.addAll(afterDataList);
}
}

View File

@@ -0,0 +1,169 @@
package com.njcn.csharmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
import com.njcn.csharmonic.mapper.PqGovernPlanMapper;
import com.njcn.csharmonic.pojo.param.PqGovernPlanParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqGovernPlanVo;
import com.njcn.csharmonic.service.IPqGovernPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* <p>
* 服务实现类
* </p>
*
* @author xy
* @since 2026-06-16
*/
@Service
@RequiredArgsConstructor
@DS("sjzx")
public class PqGovernPlanServiceImpl extends ServiceImpl<PqGovernPlanMapper, PqGovernPlan> implements IPqGovernPlanService {
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean save(PqGovernPlanParam param) {
checkGovernPointConflict(param.getGovernBefore(), param.getGovernAfter(), null);
PqGovernPlan plan = new PqGovernPlan();
plan.setPid(param.getPid());
plan.setGovernName(param.getGovernName());
plan.setGovernType(param.getGovernType());
plan.setGovernMethod(param.getGovernMethod());
plan.setGovernBefore(param.getGovernBefore());
plan.setGovernAfter(param.getGovernAfter());
plan.setSort(param.getSort());
return this.save(plan);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean update(PqGovernPlanParam.UpdatePqGovernPlanParam param) {
PqGovernPlan plan = this.getById(param.getId());
if (plan == null) {
throw new RuntimeException("治理方案不存在");
}
checkGovernPointConflict(param.getGovernBefore(), param.getGovernAfter(), param.getId());
plan.setPid(param.getPid());
plan.setGovernName(param.getGovernName());
plan.setGovernType(param.getGovernType());
plan.setGovernMethod(param.getGovernMethod());
plan.setGovernBefore(param.getGovernBefore());
plan.setGovernAfter(param.getGovernAfter());
plan.setSort(param.getSort());
return this.updateById(plan);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(List<String> ids) {
return this.removeByIds(ids);
}
@Override
public List<PqGovernPlanVo> getListByPid(String pid) {
List<PqGovernPlanVo> data = new java.util.ArrayList<>();
LambdaQueryWrapper<PqGovernPlan> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PqGovernPlan::getPid, pid)
.orderByAsc(PqGovernPlan::getSort);
List<PqGovernPlan> result = this.list(wrapper);
if (CollUtil.isNotEmpty(result)) {
List<String> allLine = result.stream()
.flatMap(plan -> Stream.of(plan.getGovernBefore(), plan.getGovernAfter()))
.filter(StrUtil::isNotBlank)
.collect(Collectors.toList());
List<DevDetailDTO> ledger = csCommTerminalFeignClient.getLedgerByLineId(allLine).getData();
if (CollUtil.isNotEmpty(ledger)) {
Map<String, DevDetailDTO> lineMap = ledger.stream().collect(Collectors.toMap(DevDetailDTO::getLineId, item -> item));
for (PqGovernPlan item : result) {
PqGovernPlanVo vo = new PqGovernPlanVo();
BeanUtils.copyProperties(item, vo);
DevDetailDTO dto1 = lineMap.get(item.getGovernBefore());
DevDetailDTO dto2 = lineMap.get(item.getGovernAfter());
vo.setLedgerBefore(dto1.getEngineeringName() + "-" + dto1.getProjectName() + "-" + dto1.getEquipmentName() + "-" + dto1.getLineName());
vo.setLedgerAfter(dto2.getEngineeringName() + "-" + dto2.getProjectName() + "-" + dto2.getEquipmentName() + "-" + dto2.getLineName());
data.add(vo);
}
}
}
return data;
}
@Override
public List<PqGovernPlan> getListExcludeNull() {
LambdaQueryWrapper<PqGovernPlan> wrapper = new LambdaQueryWrapper<>();
wrapper.isNotNull(PqGovernPlan::getGovernBefore)
.isNotNull(PqGovernPlan::getGovernAfter);
return this.list(wrapper);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean clearGovernPoints(String id) {
PqGovernPlan plan = this.getById(id);
if (plan == null) {
throw new RuntimeException("治理方案不存在");
}
LambdaUpdateWrapper<PqGovernPlan> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(PqGovernPlan::getId, id)
.set(PqGovernPlan::getGovernBefore, null)
.set(PqGovernPlan::getGovernAfter, null);
return this.update(wrapper);
}
@Override
public List<PqGovernPlan> getListByMonitorPoint(List<String> ids) {
LambdaQueryWrapper<PqGovernPlan> wrapper = new LambdaQueryWrapper<>();
wrapper.and(w -> w.in(PqGovernPlan::getGovernBefore, ids)
.or()
.in(PqGovernPlan::getGovernAfter, ids));
return this.list(wrapper);
}
/**
* 校验治理前后监测点的冲突
* 1. 治理前后监测点不能相同
* 2. 监测点已被其他方案绑定则不能再次绑定(无论治理前还是治理后)
*
* @param governBefore 治理前监测点id
* @param governAfter 治理后监测点id
* @param excludeId 排除的方案id修改时排除自身
*/
private void checkGovernPointConflict(String governBefore, String governAfter, String excludeId) {
if (StrUtil.isNotBlank(governBefore) && StrUtil.isNotBlank(governAfter)
&& governBefore.equals(governAfter)) {
throw new BusinessException("治理前后监测点不能相同");
}
LambdaQueryWrapper<PqGovernPlan> wrapper = new LambdaQueryWrapper<>();
wrapper.ne(StrUtil.isNotBlank(excludeId), PqGovernPlan::getId, excludeId);
List<PqGovernPlan> allPlans = this.list(wrapper);
List<String> boundPoints = allPlans.stream()
.flatMap(p -> java.util.stream.Stream.of(p.getGovernBefore(), p.getGovernAfter()))
.filter(StrUtil::isNotBlank)
.collect(Collectors.toList());
if (StrUtil.isNotBlank(governBefore) && boundPoints.contains(governBefore)) {
throw new BusinessException("治理前监测点已被其他方案绑定,不能重复绑定");
}
if (StrUtil.isNotBlank(governAfter) && boundPoints.contains(governAfter)) {
throw new BusinessException("治理后监测点已被其他方案绑定,不能重复绑定");
}
}
}

View File

@@ -2,7 +2,6 @@ package com.njcn.csharmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -11,12 +10,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csharmonic.pojo.param.PqSensitiveUserParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.PqSensitiveUserVo;
import com.njcn.csharmonic.service.IPqGovernPlanService;
import com.njcn.csharmonic.service.IPqSensitiveUserService;
import com.njcn.device.biz.mapper.PqSensitiveUserMapper;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
@@ -45,10 +43,10 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class PqSensitiveUserServiceImpl extends ServiceImpl<PqSensitiveUserMapper, PqSensitiveUser> implements IPqSensitiveUserService {
private final CsLineFeignClient csLineFeignClient;
private final DicDataFeignClient dicDataFeignClient;
private final EquipmentFeignClient equipmentFeignClient;
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
private final IPqGovernPlanService pqGovernPlanService;
@Override
public Page<PqSensitiveUserVo> getList(BaseParam param) {
@@ -61,33 +59,9 @@ public class PqSensitiveUserServiceImpl extends ServiceImpl<PqSensitiveUserMappe
Page<PqSensitiveUser> page = this.page(new Page<>(param.getPageNum(),param.getPageSize()),lambdaQueryWrapper);
if(CollUtil.isNotEmpty(page.getRecords())){
List<PqSensitiveUserVo> dataGroupEventVOList = new ArrayList<>();
Map<String,List<CsEquipmentDeliveryPO>> map = new HashMap<>();
//获取绑定敏感用户的监测点信息
List<String> sensitiveUserIds = page.getRecords().stream().map(PqSensitiveUser::getId).collect(Collectors.toList());
List<CsEquipmentDeliveryPO> devList = csLineFeignClient.getDevBySensitiveUser(sensitiveUserIds).getData();
if (CollUtil.isNotEmpty(devList)) {
map = devList.stream()
.filter(po -> po.getMonitorUser() != null)
.sorted(Comparator.comparing(CsEquipmentDeliveryPO::getMonitorUser))
.collect(Collectors.groupingBy(
CsEquipmentDeliveryPO::getMonitorUser,
LinkedHashMap::new,
Collectors.toList()
));
}
Map<String, List<CsEquipmentDeliveryPO>> finalMap = map;
page.getRecords().forEach(item->{
PqSensitiveUserVo vo = new PqSensitiveUserVo();
BeanUtil.copyProperties(item,vo);
if (finalMap.containsKey(item.getId())) {
vo.setIsMonitor("");
List<CsEquipmentDeliveryPO> list = finalMap.get(item.getId());
boolean hasGoverned = list.stream().anyMatch(item2 -> !Objects.isNull(item2.getGovernMethod()));
vo.setIsGovern(hasGoverned ? "" : "");
} else {
vo.setIsMonitor("");
vo.setIsGovern("");
}
dataGroupEventVOList.add(vo);
});
result.setRecords(dataGroupEventVOList);
@@ -102,28 +76,20 @@ public class PqSensitiveUserServiceImpl extends ServiceImpl<PqSensitiveUserMappe
@Override
public List<PqSensitiveUserVo> getListByUser(BaseParam param) {
List<PqSensitiveUserVo> result = new ArrayList<>();
//根据用户获取设备
List<String> devIds = csCommTerminalFeignClient.getDevIdsByUser(RequestUtil.getUserIndex()).getData();
if (CollUtil.isEmpty(devIds)) {
//根据当前用户获取监测点
List<String> lineIds = csCommTerminalFeignClient.getLineIdsByUser(RequestUtil.getUserIndex()).getData();
if (CollUtil.isEmpty(lineIds)) {
return result;
}
List<CsEquipmentDeliveryDTO> devList = equipmentFeignClient.queryDeviceById(devIds).getData();
//获取敏感用户集合
List<String> monitorUsers = devList.stream()
.map(CsEquipmentDeliveryDTO::getMonitorUser)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(monitorUsers)) {
//根据监测点获取用户
List<PqGovernPlan> governPlans = pqGovernPlanService.getListByMonitorPoint(lineIds);
if (CollUtil.isEmpty(governPlans)) {
return result;
}
//根据敏感用户进行监测点分组
Map<String,List<CsEquipmentDeliveryDTO>> map = devList.stream()
.filter(po -> po.getMonitorUser() != null)
.collect(Collectors.groupingBy(CsEquipmentDeliveryDTO::getMonitorUser));
List<String> governUserIds = governPlans.stream().map(PqGovernPlan::getPid).distinct().collect(Collectors.toList());
//查询敏感用户信息集合
LambdaQueryWrapper<PqSensitiveUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(PqSensitiveUser::getId,monitorUsers).orderByAsc(PqSensitiveUser::getSort);
lambdaQueryWrapper.in(PqSensitiveUser::getId,governUserIds).orderByAsc(PqSensitiveUser::getSort);
if (StrUtil.isNotBlank(param.getSearchValue())) {
lambdaQueryWrapper.like(PqSensitiveUser::getName, param.getSearchValue());
}
@@ -131,20 +97,35 @@ public class PqSensitiveUserServiceImpl extends ServiceImpl<PqSensitiveUserMappe
sensitiveUserList.forEach(item->{
PqSensitiveUserVo vo = new PqSensitiveUserVo();
BeanUtil.copyProperties(item,vo);
if (map.containsKey(item.getId())) {
vo.setIsMonitor("");
List<CsEquipmentDeliveryDTO> list = map.get(item.getId());
boolean hasGoverned = list.stream().anyMatch(item2 -> !Objects.isNull(item2.getGovernMethod()));
vo.setIsGovern(hasGoverned ? "" : "");
} else {
vo.setIsMonitor("");
vo.setIsGovern("");
}
vo.setIsMonitor("");
vo.setIsGovern("");
result.add(vo);
});
return result;
}
@Override
public List<PqSensitiveUser> getListByIds(List<String> ids) {
List<PqSensitiveUser> result = new ArrayList<>();
List<String> governUserIds;
if (CollUtil.isEmpty(ids) || ids.isEmpty()) {
//根据当前用户获取监测点
List<String> lineIds = csCommTerminalFeignClient.getLineIdsByUser(RequestUtil.getUserIndex()).getData();
if (CollUtil.isEmpty(lineIds)) {
return result;
}
//根据监测点获取用户
List<PqGovernPlan> governPlans = pqGovernPlanService.getListByMonitorPoint(lineIds);
if (CollUtil.isEmpty(governPlans)) {
return result;
}
governUserIds = governPlans.stream().map(PqGovernPlan::getPid).distinct().collect(Collectors.toList());
} else {
governUserIds = ids;
}
return this.list(new LambdaQueryWrapper<PqSensitiveUser>().in(PqSensitiveUser::getId, governUserIds));
}
@Override
public boolean save(PqSensitiveUserParam pqSensitiveUserParam) {
checkParam(pqSensitiveUserParam,false);
@@ -163,26 +144,27 @@ public class PqSensitiveUserServiceImpl extends ServiceImpl<PqSensitiveUserMappe
}
@Override
public Map<String, List<CsEquipmentDeliveryPO>> getUserDevTree(String type) {
Map<String, List<CsEquipmentDeliveryPO>> map = new HashMap<>();
List<PqSensitiveUser> list = this.list();
if (CollUtil.isNotEmpty(list)) {
List<CsEquipmentDeliveryPO> devList = equipmentFeignClient.getAll().getData();
Map<String,List<CsEquipmentDeliveryPO>> devMap = new HashMap<>();
if (CollUtil.isNotEmpty(devList)) {
String governType = Objects.equals(type, "apf") ? "harmonic" : "event";
devMap = devList.stream()
.filter(po -> po.getMonitorUser() != null && Objects.equals(po.getGovernType(), governType))
.sorted(Comparator.comparing(CsEquipmentDeliveryPO::getSort))
public Map<String, List<PqGovernPlan>> getUserDevTree(String type) {
Map<String, List<PqGovernPlan>> map = new LinkedHashMap<>();
List<PqSensitiveUser> userList = this.list();
if (CollUtil.isNotEmpty(userList)) {
String governType = Objects.equals(type, "apf") ? "harmonic" : "event";
LambdaQueryWrapper<PqGovernPlan> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PqGovernPlan::getGovernType, governType)
.orderByAsc(PqGovernPlan::getSort);
List<PqGovernPlan> planList = pqGovernPlanService.list(wrapper);
Map<String, List<PqGovernPlan>> planMap = new LinkedHashMap<>();
if (CollUtil.isNotEmpty(planList)) {
planMap = planList.stream()
.collect(Collectors.groupingBy(
CsEquipmentDeliveryPO::getMonitorUser,
PqGovernPlan::getPid,
LinkedHashMap::new,
Collectors.toList()
));
}
Map<String, List<CsEquipmentDeliveryPO>> finalDevMap = devMap;
list.forEach(item->{
map.put(item.getName(), finalDevMap.get(item.getId()));
Map<String, List<PqGovernPlan>> finalPlanMap = planMap;
userList.forEach(item -> {
map.put(item.getName(), finalPlanMap.get(item.getId()));
});
}
return map;

View File

@@ -17,11 +17,13 @@ import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csharmonic.api.PqGovernPlanFeignClient;
import com.njcn.csharmonic.mapper.RStatLimitRateDMapper;
import com.njcn.csharmonic.pojo.param.MainLineQueryParam;
import com.njcn.csharmonic.pojo.param.MainLineStatLimitRateDetailsQueryParam;
import com.njcn.csharmonic.pojo.param.TotalLimitStatisticsDetailsQueryParam;
import com.njcn.csharmonic.pojo.param.TotalLimitStatisticsParam;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.po.RStatLimitRateDPO;
import com.njcn.csharmonic.pojo.vo.*;
import com.njcn.csharmonic.service.IRStatLimitRateDService;
@@ -56,6 +58,7 @@ public class RStatLimitRateDServiceImpl extends ServiceImpl<RStatLimitRateDMappe
private final String GRID_SIDE_DICT_CODE = "Grid_Side";
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
private final CsCommTerminalFeignClient csCommTerminal;
private final PqGovernPlanFeignClient pqGovernPlanFeignClient;
@Override
public List<RStatLimitRateDPO> monitorIdsGetLimitRateInfo(String date, List<String> monitorIds) {
@@ -192,6 +195,15 @@ public class RStatLimitRateDServiceImpl extends ServiceImpl<RStatLimitRateDMappe
MainLineVO mainLineVO;
List<DevDetailDTO> devDetailDTOList = csCommTerminalFeignClient.getLedgerByLineId(keywordsLineIds).getData();
Map<String, DevDetailDTO> devDetailDTOMap = devDetailDTOList.stream().collect(Collectors.toMap(DevDetailDTO::getLineId, item -> item));
//根据监测点获取治理方案
List<PqGovernPlan> pqGovernPlans = pqGovernPlanFeignClient.getListByMonitorPoint(keywordsLineIds).getData();
Map<String, PqGovernPlan> pqGovernPlanMap1 = Collections.emptyMap();
Map<String, PqGovernPlan> pqGovernPlanMap2 = Collections.emptyMap();
if (CollUtil.isNotEmpty(pqGovernPlans)) {
pqGovernPlanMap1 = pqGovernPlans.stream().collect(Collectors.toMap(PqGovernPlan::getGovernBefore, item -> item));
pqGovernPlanMap2 = pqGovernPlans.stream().collect(Collectors.toMap(PqGovernPlan::getGovernAfter, item -> item));
}
for (RStatLimitRateDPO record : records) {
String lineId = record.getLineId();
mainLineVO = new MainLineVO();
@@ -200,7 +212,14 @@ public class RStatLimitRateDServiceImpl extends ServiceImpl<RStatLimitRateDMappe
mainLineVO.setProjectName(devDetailDTOMap.get(lineId).getProjectName());
mainLineVO.setDevName(devDetailDTOMap.get(lineId).getEquipmentName());
mainLineVO.setLineName(devDetailDTOMap.get(lineId).getLineName());
mainLineVO.setGovern(Objects.isNull(devDetailDTOMap.get(lineId).getGovernType()) ? "未治理" : devDetailDTOMap.get(lineId).getGovernType());
PqGovernPlan plan1 = pqGovernPlanMap1.get(lineId);
if (!Objects.isNull(plan1)) {
mainLineVO.setGovern(Objects.isNull(plan1.getGovernMethod()) ? "未治理" : plan1.getGovernMethod());
}
PqGovernPlan plan2 = pqGovernPlanMap2.get(lineId);
if (!Objects.isNull(plan2)) {
mainLineVO.setGovern(Objects.isNull(plan2.getGovernMethod()) ? "未治理" : plan2.getGovernMethod());
}
mainLineVO.setObjType(devDetailDTOMap.get(lineId).getObjType());
if (ObjectUtil.isNotNull(devDetailDTOMap.get(lineId).getObjType())) {
DictData dictData = dicDataFeignClient.getDicDataById(devDetailDTOMap.get(lineId).getObjType()).getData();

View File

@@ -12,7 +12,9 @@ import com.njcn.csdevice.utils.ReflectUtils;
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
import com.njcn.csharmonic.param.FrequencyStatisticalQueryParam;
import com.njcn.csharmonic.param.ThdDataQueryParm;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
import com.njcn.csharmonic.service.IPqGovernPlanService;
import com.njcn.csharmonic.service.StableDataService;
import com.njcn.csharmonic.util.InfluxDbParamUtil;
import com.njcn.influx.constant.InfluxDbSqlConstant;
@@ -28,7 +30,6 @@ import com.njcn.system.api.CsStatisticalSetFeignClient;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd;
import lombok.RequiredArgsConstructor;
import org.influxdb.dto.QueryResult;
@@ -66,6 +67,7 @@ public class StableDataServiceImpl implements StableDataService {
private final EquipmentFeignClient equipmentFeignClient;
private final String GRID_SIDE_DICT_CODE = "Grid_Side";
private final String LOAD_SIDE_DICT_CODE = "Load_Side";
private final IPqGovernPlanService pqGovernPlanService;
@Override
@@ -247,17 +249,16 @@ public class StableDataServiceImpl implements StableDataService {
@Override
public List<ThdDataVO> queryCommonStatisticalByTime(CommonStatisticalQueryParam commonStatisticalQueryParam) {
List<ThdDataVO> result = new ArrayList();
Optional.ofNullable(commonStatisticalQueryParam.getDevId()).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.DEVICE_LOSE));
List<CsEquipmentDeliveryDTO> data1 = equipmentFeignClient.queryDeviceById(Stream.of(commonStatisticalQueryParam.getDevId()).collect(Collectors.toList())).getData();
List<CsLinePO> csLinePOList = csLineFeignClient.queryLineByDevId(commonStatisticalQueryParam.getDevId()).getData();
if(CollectionUtil.isEmpty(csLinePOList)){
throw new BusinessException(AlgorithmResponseEnum.LINE_DATA_ERROR);
List<ThdDataVO> result = new ArrayList<>();
PqGovernPlan pqGovernPlan = pqGovernPlanService.getById(commonStatisticalQueryParam.getDevId());
if(Objects.isNull(pqGovernPlan.getGovernBefore()) || Objects.isNull(pqGovernPlan.getGovernAfter())) {
throw new BusinessException("治理前后监测点缺失,无法分析!");
}
DictData loadSideDictData = dicDataFeignClient.getDicDataByCode(LOAD_SIDE_DICT_CODE).getData();
DictData gridSideDictData = dicDataFeignClient.getDicDataByCode(GRID_SIDE_DICT_CODE).getData();
CsLinePO gridSideLine = csLinePOList.stream().filter(linePO -> linePO.getPosition().equals(gridSideDictData.getId())).findFirst().orElse(null);
CsLinePO loadSideLine = csLinePOList.stream().filter(linePO -> linePO.getPosition().equals(loadSideDictData.getId())).findFirst().orElse(null);
CsLinePO loadSideLine = csLineFeignClient.getById(pqGovernPlan.getGovernBefore()).getData();
CsLinePO gridSideLine = csLineFeignClient.getById(pqGovernPlan.getGovernAfter()).getData();
List<CsEquipmentDeliveryDTO> devs = equipmentFeignClient.queryDeviceById(Arrays.asList(loadSideLine.getDeviceId(),gridSideLine.getDeviceId())).getData();
Map<String,Integer> devMap = devs.stream().collect(Collectors.toMap(CsEquipmentDeliveryDTO::getId, CsEquipmentDeliveryDTO::getProcess));
List<CsLinePO> csLinePOList1 = new ArrayList<>();
csLinePOList1.add(gridSideLine);csLinePOList1.add(loadSideLine);
List<EleEpdPqd> data = csStatisticalSetFeignClient.queryStatisticalSelect(Collections.singletonList(commonStatisticalQueryParam.getStatisticalId())).getData();
@@ -283,7 +284,7 @@ public class StableDataServiceImpl implements StableDataService {
commonQueryParam.setStartTime(commonStatisticalQueryParam.getStartTime() + " 00:00:00");
commonQueryParam.setEndTime(commonStatisticalQueryParam.getEndTime() + " 23:59:59");
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase());
commonQueryParam.setProcess(data1.get(0).getProcess()+"");
commonQueryParam.setProcess(devMap.get(temp.getDeviceId())+"");
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId()));
return commonQueryParam;