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

@@ -1,14 +1,8 @@
package com.njcn.csdevice.pojo.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
*
* Description:
@@ -76,8 +70,6 @@ public class CsEquipmentDeliveryDTO {
*/
private String debugPerson;
/**
* 合同号
*/
@@ -121,18 +113,4 @@ public class CsEquipmentDeliveryDTO {
*/
private String softinfoId;
/**
* 治理方法
*/
private String governMethod;
/**
* 敏感用户id
*/
private String monitorUser;
/**
* 治理类型(稳态:harmonic 暂态:event)
*/
private String governType;
}

View File

@@ -52,8 +52,8 @@ public class DevDetailDTO {
@ApiModelProperty(value = "监测对象")
private String objType;
@ApiModelProperty(value = "设备治理方案")
private String governType;
// @ApiModelProperty(value = "设备治理方案")
// private String governType;
@ApiModelProperty(value = "监测点id集合")
private List<String> lineList;

View File

@@ -158,22 +158,4 @@ public class CsEquipmentDeliveryPO extends BaseEntity {
* 是否支持升级(0:否 1:是)
*/
private Integer upgrade;
/**
* 治理方法
*/
@TableField(value = "govern_method")
private String governMethod;
/**
* 敏感用户id
*/
@TableField(value = "monitor_user")
private String monitorUser;
/**
* 治理类型(稳态:harmonic 暂态:event)
*/
@TableField(value = "govern_type")
private String governType;
}

View File

@@ -75,6 +75,15 @@ public class CsLedgerVO implements Serializable {
@ApiModelProperty(name = "devConType",value = "设备连接方式 MQTT || CLD")
private String devConType;
@ApiModelProperty(name = "监测点关联用户id")
private String sensitiveUserId;
@ApiModelProperty(name = "监测点关联用户名称")
private String sensitiveUserName;
@ApiModelProperty(name = "治理方案名称")
private String governPlanName;
@ApiModelProperty(name = "children",value = "子节点")
private List<CsLedgerVO> children = new ArrayList<>();

View File

@@ -13,6 +13,8 @@ import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.CsMarketDataVO;
import com.njcn.csdevice.pojo.vo.CsTouristDataParmVO;
import com.njcn.csdevice.service.*;
import com.njcn.csharmonic.api.PqGovernPlanFeignClient;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.enums.AppRoleEnum;
@@ -42,6 +44,7 @@ public class CsCommTerminalServiceImpl implements CsCommTerminalService {
private final CsMarketDataService csMarketDataService;
private final ICsLedgerService csLedgerService;
private final CsTouristDataPOService csTouristDataPOService;
private final PqGovernPlanFeignClient pqGovernPlanFeignClient;
@Override
@@ -65,15 +68,15 @@ public class CsCommTerminalServiceImpl implements CsCommTerminalService {
@Override
public List<String> getPqUserIdsByUser(String userId) {
List<String> result = new ArrayList<>();
List<String> devIds = commGetDevIds(userId);
if (CollUtil.isEmpty(devIds)) {
List<String> lineIds = getLineIdsByUser(userId);
if (CollUtil.isEmpty(lineIds)) {
return result;
}
List<CsEquipmentDeliveryPO> po = csEquipmentDeliveryService.listByIds(devIds);
if (CollUtil.isEmpty(po)) {
result = po.stream().map(CsEquipmentDeliveryPO::getMonitorUser).distinct().collect(Collectors.toList());
List<PqGovernPlan> governPlans = pqGovernPlanFeignClient.getListByMonitorPoint(lineIds).getData();
if (CollUtil.isEmpty(governPlans)) {
return result;
}
return result;
return governPlans.stream().map(PqGovernPlan::getPid).distinct().collect(Collectors.toList());
}
@Override
@@ -188,6 +191,7 @@ public class CsCommTerminalServiceImpl implements CsCommTerminalService {
dto.setEquipmentName(equipmentLedger.getName());
dto.setLineId(item.getId());
dto.setLineName(item.getName());
dto.setObjType(csLinePoMap.get(item.getId()).getMonitorObj());
if (Objects.isNull(csLinePoMap.get(item.getId()).getRunStatus())) {
CsEquipmentDeliveryPO delivery = equipmentDeliveryMap.get(equipmentId);
@@ -202,8 +206,6 @@ public class CsCommTerminalServiceImpl implements CsCommTerminalService {
} else {
dto.setRunStatus(csLinePoMap.get(item.getId()).getRunStatus());
}
dto.setObjType(csLinePoMap.get(item.getId()).getMonitorObj());
dto.setGovernType(equipmentDeliveryMap.get(equipmentId).getGovernType());
result.add(dto);
}
return result;

View File

@@ -5,12 +5,10 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.csdevice.constant.DataParam;
import com.njcn.csdevice.enums.LineBaseEnum;
@@ -21,7 +19,9 @@ import com.njcn.csdevice.pojo.param.CsLedgerParam;
import com.njcn.csdevice.pojo.po.*;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.service.*;
import com.njcn.csharmonic.api.PqGovernPlanFeignClient;
import com.njcn.csharmonic.api.PqSensitiveUserFeignClient;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.AreaFeignClient;
@@ -29,14 +29,12 @@ import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.Area;
import com.njcn.system.pojo.vo.DictTreeVO;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.enums.AppRoleEnum;
import com.njcn.user.pojo.constant.UserType;
import com.njcn.user.pojo.vo.UserVO;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.function.Function;
@@ -66,8 +64,8 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
private final ICsDataSetService csDataSetService;
private final DictTreeFeignClient dictTreeFeignClient;
private final CsDeviceUserPOMapper csDeviceUserPOMapper;
private final PqGovernPlanFeignClient pqGovernPlanFeignClient;
private final PqSensitiveUserFeignClient pqSensitiveUserFeignClient;
private final UserFeignClient userFeignClient;
private final ICsUserPinsService csUserPinsService;
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
@@ -164,12 +162,74 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
.filter(item -> Objects.equals(poMap.get(item.getId()).getUsageStatus(), 1))
.sorted(Comparator.comparing(CsLedgerVO::getSort))
.collect(Collectors.toList());
//获取治理方案
List<PqGovernPlan> governPlan = pqGovernPlanFeignClient.getListExcludeNull().getData();
Map<String, PqGovernPlan> beforeMap = Optional.ofNullable(governPlan)
.orElse(Collections.emptyList())
.stream()
.filter(p -> p.getGovernBefore() != null)
.collect(Collectors.toMap(
PqGovernPlan::getGovernBefore,
Function.identity(),
(v1, v2) -> v1
));
Map<String, PqGovernPlan> afterMap = Optional.ofNullable(governPlan)
.orElse(Collections.emptyList())
.stream()
.filter(p -> p.getGovernAfter() != null)
.collect(Collectors.toMap(
PqGovernPlan::getGovernAfter,
Function.identity(),
(v1, v2) -> v1
));
//获取治理用户
// 1. governPlan 防 null + 过滤掉 pid 为 null 的数据
List<String> sensitiveUser = Optional.ofNullable(governPlan)
.orElse(Collections.emptyList())
.stream()
.map(PqGovernPlan::getPid)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
// 2. 没有 id 就不调用远程接口,直接返回空 Map
Map<String, PqSensitiveUser> sensitiveUserMap;
if (CollectionUtils.isEmpty(sensitiveUser)) {
sensitiveUserMap = Collections.emptyMap();
} else {
List<PqSensitiveUser> sensitiveUserList = pqSensitiveUserFeignClient
.getListByIds(sensitiveUser)
.getData();
// 3. sensitiveUserList 防 null
sensitiveUserMap = Optional.ofNullable(sensitiveUserList)
.orElse(Collections.emptyList())
.stream()
.filter(u -> u != null && u.getId() != null)
.collect(Collectors.toMap(
PqSensitiveUser::getId,
Function.identity(),
(v1, v2) -> v1
));
}
List<CsLedgerVO> finalLineList = allList.stream()
.filter(item -> item.getLevel().equals(LineBaseEnum.LINE_LEVEL.getCode()))
.sorted(Comparator.comparing(CsLedgerVO::getSort))
.peek(
item -> {
PqGovernPlan beforePlan = beforeMap.get(item.getId());
PqGovernPlan afterPlan = afterMap.get(item.getId());
if (beforePlan != null) {
PqSensitiveUser user = sensitiveUserMap.get(beforePlan.getPid());
item.setSensitiveUserId(beforePlan.getPid());
item.setSensitiveUserName(Objects.isNull(user) ? null : user.getName());
item.setGovernPlanName(beforePlan.getGovernName());
}
if (afterPlan != null) {
PqSensitiveUser user = sensitiveUserMap.get(afterPlan.getPid());
item.setSensitiveUserId(afterPlan.getPid());
item.setSensitiveUserName(Objects.isNull(user) ? null : user.getName());
item.setGovernPlanName(afterPlan.getGovernName());
}
item.setType("line");
String index = item.getId().substring(item.getId().length() - 1);
if (Objects.equals(index, "0")) {

View File

@@ -29,9 +29,11 @@ import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.csdevice.service.ICsDataSetService;
import com.njcn.csharmonic.api.CsHarmonicPlanFeignClient;
import com.njcn.csharmonic.api.CsHarmonicPlanLineFeignClient;
import com.njcn.csharmonic.api.PqGovernPlanFeignClient;
import com.njcn.csharmonic.api.PqSensitiveUserFeignClient;
import com.njcn.csharmonic.param.CsHarmonicPlanLineParam;
import com.njcn.csharmonic.pojo.po.CsHarmonicPlan;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
@@ -72,6 +74,7 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
private final DicDataFeignClient dicDataFeignClient;
private final CsTerminalLogsMapper csTerminalLogsMapper;
private final PqSensitiveUserFeignClient pqSensitiveUserFeignClient;
private final PqGovernPlanFeignClient pqGovernPlanFeignClient;
private final FileStorageUtil fileStorageUtil;
private final UserFeignClient userFeignClient;
@@ -328,7 +331,8 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
@Override
public List<CsEquipmentDeliveryPO> getDevBySensitiveUser(List<String> list) {
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.in(CsEquipmentDeliveryPO::getMonitorUser,list)
lambdaQueryWrapper
// .in(CsEquipmentDeliveryPO::getMonitorUser,list)
.ne(CsEquipmentDeliveryPO::getRunStatus, DataStateEnum.DELETED.getCode());
return csEquipmentDeliveryMapper.selectList(lambdaQueryWrapper);
}
@@ -358,13 +362,16 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
if (CollUtil.isEmpty(records)) {
return result;
}
List<String> devIds = records.stream().map(CsLinePO::getDeviceId).distinct().collect(Collectors.toList());
List<CsEquipmentDeliveryPO> devList = csEquipmentDeliveryMapper.selectBatchIds(devIds);
Map<String, CsEquipmentDeliveryPO> devMap = devList.stream().collect(Collectors.toMap(CsEquipmentDeliveryPO::getId, item -> item));
List<PqSensitiveUserLineVO> list = new ArrayList<>();
List<String> sensitiveUserIds = list.stream().map(PqSensitiveUserLineVO::getSensitiveUser).distinct().collect(Collectors.toList());
//获取用户id
List<String> ids = records.stream().map(CsLinePO::getLineId).distinct().collect(Collectors.toList());
List<PqGovernPlan> governPlans = pqGovernPlanFeignClient.getListByMonitorPoint(ids).getData();
if (CollUtil.isEmpty(governPlans)) {
return result;
}
Map<String, PqGovernPlan> lineMap1 = governPlans.stream().collect(Collectors.toMap(PqGovernPlan::getGovernBefore, item -> item));
Map<String, PqGovernPlan> lineMap2 = governPlans.stream().collect(Collectors.toMap(PqGovernPlan::getGovernAfter, item -> item));
List<String> sensitiveUserIds = governPlans.stream().map(PqGovernPlan::getPid).distinct().collect(Collectors.toList());
Map<String, String> sensitiveUserNameMap = new HashMap<>();
List<PqSensitiveUser> pqSensitiveUserList = pqSensitiveUserFeignClient.getListByIds(sensitiveUserIds).getData();
if (CollUtil.isNotEmpty(pqSensitiveUserList)) {
@@ -383,19 +390,26 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
List<DevDetailDTO> devDetailDTOList = csCommTerminal.getLedgerByLineId(lineIds).getData();
Map<String, DevDetailDTO> devDetailDTOMap = devDetailDTOList.stream().collect(Collectors.toMap(DevDetailDTO::getLineId, item -> item));
List<PqSensitiveUserLineVO> list = new ArrayList<>();
for (CsLinePO record : records) {
sensitiveUserLineVO = new PqSensitiveUserLineVO();
sensitiveUserLineVO.setEngineeringName(devDetailDTOMap.get(record.getLineId()).getEngineeringName());
sensitiveUserLineVO.setProjectName(devDetailDTOMap.get(record.getLineId()).getProjectName());
sensitiveUserLineVO.setDevName(devDetailDTOMap.get(record.getLineId()).getEquipmentName());
// 治理对象
sensitiveUserLineVO.setSensitiveUser(sensitiveUserNameMap.getOrDefault(devMap.get(record.getDeviceId()).getMonitorUser(), null));
// 治理对象 && 是否治理
PqGovernPlan plan1 = lineMap1.get(record.getLineId());
if (!Objects.isNull(plan1)) {
sensitiveUserLineVO.setSensitiveUser(sensitiveUserNameMap.getOrDefault(plan1.getPid(), null));
sensitiveUserLineVO.setGovern(Objects.isNull(plan1.getGovernMethod()) ? "未治理" : plan1.getGovernMethod());
}
PqGovernPlan plan2 = lineMap2.get(record.getLineId());
if (!Objects.isNull(plan2)) {
sensitiveUserLineVO.setSensitiveUser(sensitiveUserNameMap.getOrDefault(plan2.getPid(), null));
sensitiveUserLineVO.setGovern(Objects.isNull(plan2.getGovernMethod()) ? "未治理" : plan2.getGovernMethod());
}
// 测点名称
sensitiveUserLineVO.setLineId(record.getLineId());
sensitiveUserLineVO.setLineName(record.getName());
// 是否治理
String governMethod = devMap.get(record.getDeviceId()).getGovernMethod();
sensitiveUserLineVO.setGovern(Objects.isNull(governMethod) ? "未治理" : governMethod);
// 监测类型
if (ObjectUtil.isNotNull(record.getPosition())) {
sensitiveUserLineVO.setPosition(record.getPosition());

View File

@@ -0,0 +1,30 @@
package com.njcn.csharmonic.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csharmonic.api.fallback.PqGovernPlanClientFallbackFactory;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.CS_HARMONIC_BOOT, path = "/pqGovernPlan", fallbackFactory = PqGovernPlanClientFallbackFactory.class,contextId = "pqGovernPlan")
public interface PqGovernPlanFeignClient {
@GetMapping("/getListExcludeNull")
@ApiOperation("查询所有治理方案(剔除治理前后监测点为空的数据)")
HttpResult<List<PqGovernPlan>> getListExcludeNull();
@PostMapping("/getListByMonitorPoint")
@ApiOperation("清空治理前后监测点数据")
HttpResult<List<PqGovernPlan>> getListByMonitorPoint(@RequestBody List<String> ids);
}

View File

@@ -0,0 +1,42 @@
package com.njcn.csharmonic.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csharmonic.api.PqGovernPlanFeignClient;
import com.njcn.csharmonic.pojo.po.PqGovernPlan;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author xy
*/
@Slf4j
@Component
public class PqGovernPlanClientFallbackFactory implements FallbackFactory<PqGovernPlanFeignClient> {
@Override
public PqGovernPlanFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new PqGovernPlanFeignClient() {
@Override
public HttpResult<List<PqGovernPlan>> getListExcludeNull() {
log.error("{}异常,降级处理,异常为:{}","查询所有治理方案异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<PqGovernPlan>> getListByMonitorPoint(List<String> ids) {
log.error("{}异常,降级处理,异常为:{}","清空治理前后监测点数据异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,69 @@
package com.njcn.csharmonic.pojo.param;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
/**
* 治理方案参数类
*
* @author xy
* @since 2026-06-16
*/
@Data
public class PqGovernPlanParam {
@ApiModelProperty(value = "用户id关联pq_sensitive_user的id")
@NotBlank(message = "用户id不能为空")
private String pid;
@ApiModelProperty(value = "治理点名称")
@NotBlank(message = "治理点名称不能为空")
private String governName;
@ApiModelProperty(value = "治理类型(稳态:harmonic 暂态:event)")
@NotBlank(message = "治理类型不能为空")
private String governType;
@ApiModelProperty(value = "治理方法")
private String governMethod;
@ApiModelProperty(value = "治理前-监测点id")
private String governBefore;
@ApiModelProperty(value = "治理后-监测点id")
private String governAfter;
@ApiModelProperty(value = "排序")
private Integer sort;
/**
* 修改参数类
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class UpdatePqGovernPlanParam extends PqGovernPlanParam {
@ApiModelProperty("ID")
@NotBlank(message = "ID不能为空")
private String id;
}
/**
* 分页查询参数类
*/
@Data
@EqualsAndHashCode(callSuper = true)
public static class QueryParam extends BaseParam {
@ApiModelProperty(value = "治理点名称")
private String governName;
@ApiModelProperty(value = "治理类型(稳态:harmonic 暂态:event)")
private String governType;
@ApiModelProperty(value = "用户id关联pq_sensitive_user的id")
private String pid;
}
}

View File

@@ -0,0 +1,64 @@
package com.njcn.csharmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author xy
* @since 2026-06-16
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("pq_govern_plan")
public class PqGovernPlan extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 用户id关联pq_sensitive_user的id
*/
private String pid;
/**
* 治理点名称
*/
private String governName;
/**
* 治理类型(稳态:harmonic 暂态:event)
*/
private String governType;
/**
* 治理方法
*/
private String governMethod;
/**
* 治理前-监测点id
*/
private String governBefore;
/**
* 治理后-监测点id
*/
private String governAfter;
/**
* 排序
*/
private Integer sort;
}

View File

@@ -0,0 +1,56 @@
package com.njcn.csharmonic.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class PqGovernPlanVo implements Serializable {
/**
* id
*/
private String id;
/**
* 用户id关联pq_sensitive_user的id
*/
private String pid;
/**
* 治理点名称
*/
private String governName;
/**
* 治理类型(稳态:harmonic 暂态:event)
*/
private String governType;
/**
* 治理方法
*/
private String governMethod;
/**
* 治理前-监测点id
*/
private String governBefore;
@ApiModelProperty("治理前台账")
private String ledgerBefore;
/**
* 治理后-监测点id
*/
private String governAfter;
@ApiModelProperty("治理后台账")
private String ledgerAfter;
/**
* 排序
*/
private Integer sort;
}

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;