zbj//1.单位指标告警统计_周统计 (主/配网)算法

This commit is contained in:
zhangbaojian
2023-06-13 10:10:57 +08:00
parent 0d05558e98
commit c37bc9a53f
11 changed files with 522 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package com.njcn.prepare.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName r_stat_pw_alarm_count_w
*/
@Data
@TableName("r_stat_pw_alarm_count_w")
public class RStatPwAlarmCountWPO {
/**
* 单位ID
*/
@MppMultiId(value = "org_no")
private String orgNo;
/**
* 生成数据的时间,每周统计一次
*/
@MppMultiId(value = "data_date")
private Date dataDate;
/**
* 在线监测点数
*/
@TableField(value = "online_monitor_count")
private Integer onlineMonitorCount;
/**
* 告警监测点数
*/
@TableField(value = "alarm_monitor_count")
private Integer alarmMonitorCount;
}

View File

@@ -0,0 +1,49 @@
package com.njcn.prepare.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName r_stat_zw_alarm_count_w
*/
@Data
@TableName("r_stat_zw_alarm_count_w")
public class RStatZwAlarmCountWPO {
/**
* 单位ID
*/
@MppMultiId(value = "org_no")
private String orgNo;
/**
* 生成数据的时间,每周统计一次
*/
@MppMultiId(value = "data_date")
private Date dataDate;
/**
* 有效监测点数量
*/
@TableField(value = "monitor_effective_count")
private Integer monitorEffectiveCount;
/**
* 告警4次及以上监测点数量
*/
@TableField(value = "warn_monitor_count")
private Integer warnMonitorCount;
/**
* 级别较差监测点数量
*/
@TableField(value = "monitor_grade_count")
private Integer monitorGradeCount;
}

View File

@@ -0,0 +1,79 @@
package com.njcn.prepare.harmonic.controller.newalgorithm;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.ServerInfo;
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.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
import com.njcn.prepare.harmonic.pojo.param.OrgParam;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RAlarmCountService;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.po.Dept;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.List;
/**
* Description:
* 接口文档访问地址http://serverIP:port/swagger-ui.html
* Date: 2022/12/28 13:47【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Slf4j
@Api(tags = "指标告警统计")
@RestController
@RequestMapping("/rAlarmCount")
@RequiredArgsConstructor
public class RAlarmCountController extends BaseController {
private final RAlarmCountService rAlarmCountService;
private final CommTerminalGeneralClient commTerminalGeneralClient;
private final DeptFeignClient deptFeignClient;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/rAlarmCount")
@ApiOperation("指标告警统计")
@ApiImplicitParam(name = "orgParam", value = "参数", required = true)
public HttpResult<String> rAlarmCountHandler(@RequestBody @Validated OrgParam orgParam) {
log.info(LocalDateTime.now() + "rAlarmCountHandler开始执行");
String methodDescribe = getMethodDescribe("rAlarmCountHandler");
/**
* 支持补录
*/
DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
if (StringUtils.isEmpty(orgParam.getOrgId())) {
Dept data = deptFeignClient.getRootDept().getData();
deptGetLineParam.setDeptId(data.getId());
} else {
deptGetLineParam.setDeptId(orgParam.getOrgId());
}
deptGetLineParam.setServerName(ServerInfo.PREPARE_BOOT);
List<DeptGetChildrenMoreDTO> data = commTerminalGeneralClient.deptGetLine(deptGetLineParam).getData();
rAlarmCountService.handler(data,orgParam.getDataDate(),orgParam.getType());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,18 @@
package com.njcn.prepare.harmonic.mapper.mysql.newalgorithm;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.prepare.harmonic.pojo.po.RStatPwAlarmCountWPO;
import com.njcn.prepare.harmonic.pojo.po.RStatZwAlarmCountWPO;
import org.apache.ibatis.annotations.Mapper;
/**
* Description:
* 接口文档访问地址http://serverIP:port/swagger-ui.html
* Date: 2022/12/13 15:39【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Mapper
public interface RStatPwAlarmCountWPOMapper extends MppBaseMapper<RStatPwAlarmCountWPO> {
}

View File

@@ -0,0 +1,18 @@
package com.njcn.prepare.harmonic.mapper.mysql.newalgorithm;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.prepare.harmonic.pojo.po.RStatEventYPO;
import com.njcn.prepare.harmonic.pojo.po.RStatZwAlarmCountWPO;
import org.apache.ibatis.annotations.Mapper;
/**
* Description:
* 接口文档访问地址http://serverIP:port/swagger-ui.html
* Date: 2022/12/13 15:39【需求编号】
*
* @author clam
* @version V1.0.0
*/
@Mapper
public interface RStatZwAlarmCountWPOMapper extends MppBaseMapper<RStatZwAlarmCountWPO> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.prepare.harmonic.service.mysql.newalgorithm;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import java.util.List;
/**
* @author zbj
* @since 2023-06-12
*/
public interface RAlarmCountService {
void handler(List<DeptGetChildrenMoreDTO> data, String dataDate, Integer type);
}

View File

@@ -0,0 +1,13 @@
package com.njcn.prepare.harmonic.service.mysql.newalgorithm;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.prepare.harmonic.pojo.po.RStatPwAlarmCountWPO;
/**
* @author zbj
* @since 2023-06-13
*/
public interface RStatPwAlarmCountWPOService extends IMppService<RStatPwAlarmCountWPO> {
}

View File

@@ -0,0 +1,15 @@
package com.njcn.prepare.harmonic.service.mysql.newalgorithm;
import com.github.jeffreyning.mybatisplus.service.IMppService;
import com.njcn.prepare.harmonic.pojo.po.RStatEventVoltageMPO;
import com.njcn.prepare.harmonic.pojo.po.RStatZwAlarmCountWPO;
/**
* @author zbj
* @since 2023-06-12
*/
public interface RStatZwAlarmCountWPOService extends IMppService<RStatZwAlarmCountWPO> {
}

View File

@@ -0,0 +1,222 @@
package com.njcn.prepare.harmonic.service.mysql.newalgorithm.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
import com.njcn.harmonic.pojo.po.*;
import com.njcn.prepare.harmonic.mapper.mysql.area.RMpTargetWarnDMapper;
import com.njcn.prepare.harmonic.pojo.po.RMpEventDetailDNewPO;
import com.njcn.prepare.harmonic.pojo.po.RStatPwAlarmCountWPO;
import com.njcn.prepare.harmonic.pojo.po.RStatZwAlarmCountWPO;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RAlarmCountService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatEventVoltageService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatPwAlarmCountWPOService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatZwAlarmCountWPOService;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 指标告警统计
* </p>
*
* @author zbj
* @since 2023-06-12
*/
@Service
@RequiredArgsConstructor
public class RAlarmCountServiceImpl implements RAlarmCountService {
private final RMpTargetWarnDMapper rMpTargetWarnDMapper;
private final RStatZwAlarmCountWPOService rStatZwAlarmCountWPOService;
private final RStatPwAlarmCountWPOService rStatPwAlarmCountWPOService;
@Override
public void handler(List<DeptGetChildrenMoreDTO> data, String dataDate, Integer type) {
switch (type) {
case 3:
this.rAlarmCountMHandler(data, dataDate, type);
break;
case 4:
this.rAlarmCountWHandler(data, dataDate, type);
break;
default:
break;
}
}
//周表
public void rAlarmCountWHandler(List<DeptGetChildrenMoreDTO> data, String dataDate, Integer type) {
List<RStatZwAlarmCountWPO> rStatZwAlarmCountWPOS = new ArrayList<>();
List<RStatPwAlarmCountWPO> rStatPwAlarmCountWPOS = new ArrayList<>();
//获取日期
Date localDate = DateUtil.parse(dataDate);
//获取当前周的起始与结束日期
LocalDate date = LocalDate.parse(dataDate, DateTimeFormatter.ISO_DATE);
LocalDate startOfWeek = date.with(DayOfWeek.MONDAY);
LocalDate endOfWeek = date.with(DayOfWeek.SUNDAY);
QueryWrapper<RMpTargetWarnDPO> rMpTargetWarnDPOQueryWrapper = new QueryWrapper<>();
data.forEach(deptGetChildrenMoreDTO -> {
/*主网*/
if (!CollectionUtils.isEmpty(deptGetChildrenMoreDTO.getLineBaseList())) {
List<LineDevGetDTO> lineBaseList = deptGetChildrenMoreDTO.getLineBaseList();
List<String> collect1 = lineBaseList.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList());
rMpTargetWarnDPOQueryWrapper.clear();
rMpTargetWarnDPOQueryWrapper.
in("measurement_point_id", collect1).
eq("is_effective", "1").
between("data_date", startOfWeek, endOfWeek);
List<RMpTargetWarnDPO> rMpTargetWarnDPOList = rMpTargetWarnDMapper.selectList(rMpTargetWarnDPOQueryWrapper);
//告警4次及以上监测点数量
long count = rMpTargetWarnDPOList.stream()
.filter(obj -> obj.getIsWarn() == 1)
.collect(Collectors.groupingBy(RMpTargetWarnDPO::getMeasurementPointId, Collectors.counting()))
.entrySet().stream()
.filter(e -> e.getValue() >= 4)
.count();
// 使用 Stream API 进行流式处理,选择 status 为 1 的告警,按照 id 进行分组并统计个数
Map<String, Double> avgStatusOneCountByAlarmId = rMpTargetWarnDPOList.stream()
.filter(alarm -> alarm.getIsWarn() == 1)
.collect(Collectors.groupingBy(RMpTargetWarnDPO::getMeasurementPointId, Collectors.counting()))
.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() / 7.0));
// 对 map 中的 value 进行从大到小的排序,并且排除 value 为 0 的元素
Map<String, Double> sortedAvgStatusOneCountByAlarmId = avgStatusOneCountByAlarmId.entrySet().stream()
.filter(e -> e.getValue() != 0)
.sorted(Map.Entry.<String, Double>comparingByValue(Comparator.reverseOrder()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));
// 获取前 30% 的告警 id 数量
int top30PercentCount = (int) (sortedAvgStatusOneCountByAlarmId.size() * 0.3) + 1;
RStatZwAlarmCountWPO rStatZwAlarmCountWPO = new RStatZwAlarmCountWPO();
rStatZwAlarmCountWPO.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
rStatZwAlarmCountWPO.setDataDate(localDate);
rStatZwAlarmCountWPO.setMonitorEffectiveCount(rMpTargetWarnDPOList.size());
rStatZwAlarmCountWPO.setWarnMonitorCount(Integer.valueOf(count + ""));
rStatZwAlarmCountWPO.setMonitorGradeCount(top30PercentCount);
rStatZwAlarmCountWPOS.add(rStatZwAlarmCountWPO);
}
/*配网*/
if (!CollectionUtils.isEmpty(deptGetChildrenMoreDTO.getPwMonitorIds())) {
List<LineDevGetDTO> pwMonitorIds = deptGetChildrenMoreDTO.getPwMonitorIds();
List<String> collect1 = pwMonitorIds.stream().map(LineDevGetDTO::getPointId).collect(Collectors.toList());
rMpTargetWarnDPOQueryWrapper.clear();
rMpTargetWarnDPOQueryWrapper.
in("measurement_point_id", collect1).
between("data_date", startOfWeek, endOfWeek);
List<RMpTargetWarnDPO> rMpTargetWarnDPOList = rMpTargetWarnDMapper.selectList(rMpTargetWarnDPOQueryWrapper);
long count = rMpTargetWarnDPOList.stream().filter(alarm -> alarm.getIsWarn() == 1).count();
RStatPwAlarmCountWPO rStatPwAlarmCountWPO = new RStatPwAlarmCountWPO();
rStatPwAlarmCountWPO.setOrgNo(deptGetChildrenMoreDTO.getUnitId());
rStatPwAlarmCountWPO.setDataDate(localDate);
rStatPwAlarmCountWPO.setOnlineMonitorCount(rMpTargetWarnDPOList.size());
rStatPwAlarmCountWPO.setAlarmMonitorCount(Integer.valueOf(count + ""));
rStatPwAlarmCountWPOS.add(rStatPwAlarmCountWPO);
}
});
if (!CollectionUtils.isEmpty(rStatZwAlarmCountWPOS)) {
rStatZwAlarmCountWPOService.saveOrUpdateBatchByMultiId(rStatZwAlarmCountWPOS, 500);
}
if (!CollectionUtils.isEmpty(rStatZwAlarmCountWPOS)) {
rStatPwAlarmCountWPOService.saveOrUpdateBatchByMultiId(rStatPwAlarmCountWPOS, 500);
}
}
//月表
public void rAlarmCountMHandler(List<DeptGetChildrenMoreDTO> data, String dataDate, Integer type) {
}
//获取监测点类型 1/2/3类字典id
private String getmeasurementType(Integer k, Map<String, DictData> lineSortMap) {
String value = "";
switch (k) {
case 1:
value = lineSortMap.get(DicDataEnum.ONE_LINE.getCode()).getId();
break;
case 2:
value = lineSortMap.get(DicDataEnum.TWO_LINE.getCode()).getId();
break;
case 3:
value = lineSortMap.get(DicDataEnum.THREE_LINE.getCode()).getId();
break;
default:
break;
}
return value;
}
//获取暂态各个类型发生的监测点数量及发生次数
private List<Integer> getTransientStatisData(DictData dictData, List<RMpEventDetailDNewPO> list) {
List<Integer> result = new ArrayList<>(2);
Integer value = 0;
Integer count = 0;
if (Objects.equals(dictData.getCode(), DicDataEnum.VOLTAGE_DIP.getCode())) {
value = Integer.valueOf(list.stream().filter(temp -> temp.getSagTimes() > 0).count() + "");
count = Integer.valueOf(list.stream().mapToInt(RMpEventDetailDNewPO::getSagTimes).sum() + "");
}
if (Objects.equals(dictData.getCode(), DicDataEnum.VOLTAGE_RISE.getCode())) {
value = Integer.valueOf(list.stream().filter(temp -> temp.getSwellTimes() > 0).count() + "");
count = Integer.valueOf(list.stream().mapToInt(RMpEventDetailDNewPO::getSwellTimes).sum() + "");
}
if (Objects.equals(dictData.getCode(), DicDataEnum.SHORT_INTERRUPTIONS.getCode())) {
value = Integer.valueOf(list.stream().filter(temp -> temp.getInterruptTimes() > 0).count() + "");
count = Integer.valueOf(list.stream().mapToInt(RMpEventDetailDNewPO::getInterruptTimes).sum() + "");
}
result.add(value);
result.add(count);
return result;
}
//获取暂态各个类型发生的监测点数量
private Integer getStatisData(DictData dictData, String voltage, List<RMpEventDetailMNewPO> list) {
Integer value = 0;
if (Objects.equals(dictData.getCode(), DicDataEnum.VOLTAGE_DIP.getCode())) {
value = Integer.valueOf(list.stream().filter(temp -> temp.getSagTimes() > 0 && Objects.equals(temp.getVoltage(), voltage)).count() + "");
}
if (Objects.equals(dictData.getCode(), DicDataEnum.VOLTAGE_RISE.getCode())) {
value = Integer.valueOf(list.stream().filter(temp -> temp.getSwellTimes() > 0 && Objects.equals(temp.getVoltage(), voltage)).count() + "");
}
if (Objects.equals(dictData.getCode(), DicDataEnum.SHORT_INTERRUPTIONS.getCode())) {
value = Integer.valueOf(list.stream().filter(temp -> temp.getInterruptTimes() > 0 && Objects.equals(temp.getVoltage(), voltage)).count() + "");
}
return value;
}
}

View File

@@ -0,0 +1,24 @@
package com.njcn.prepare.harmonic.service.mysql.newalgorithm.impl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RStatPwAlarmCountWPOMapper;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RStatZwAlarmCountWPOMapper;
import com.njcn.prepare.harmonic.pojo.po.RStatPwAlarmCountWPO;
import com.njcn.prepare.harmonic.pojo.po.RStatZwAlarmCountWPO;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatPwAlarmCountWPOService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatZwAlarmCountWPOService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
/**
* <p>
* 终端检测监督
* </p>
*
* @author zbj
* @since 2023-06-13
*/
@Service
@RequiredArgsConstructor
public class RStatPwAlarmCountWPOServiceImpl extends MppServiceImpl<RStatPwAlarmCountWPOMapper, RStatPwAlarmCountWPO> implements RStatPwAlarmCountWPOService {
}

View File

@@ -0,0 +1,24 @@
package com.njcn.prepare.harmonic.service.mysql.newalgorithm.impl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RStatEventYPOMapper;
import com.njcn.prepare.harmonic.mapper.mysql.newalgorithm.RStatZwAlarmCountWPOMapper;
import com.njcn.prepare.harmonic.pojo.po.RStatEventYPO;
import com.njcn.prepare.harmonic.pojo.po.RStatZwAlarmCountWPO;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatEventYPOService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatZwAlarmCountWPOService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
/**
* <p>
* 终端检测监督
* </p>
*
* @author zbj
* @since 2023-06-12
*/
@Service
@RequiredArgsConstructor
public class RStatZwAlarmCountWPOServiceImpl extends MppServiceImpl<RStatZwAlarmCountWPOMapper, RStatZwAlarmCountWPO> implements RStatZwAlarmCountWPOService {
}