问题单修复

This commit is contained in:
zhuxinyu
2023-04-23 11:29:04 +08:00
parent 3f4a1254bf
commit 87f08d8558
9 changed files with 109 additions and 85 deletions

View File

@@ -12,7 +12,7 @@ import java.util.List;
public interface RStatLimitTargetMapper extends BaseMapper<RStatLimitTargetDPO> {
Page<MonitorOverLimitVO> getSumLimitTargetPage(Page<RStatLimitRateDPO> p,
Page<MonitorOverLimitVO> getSumLimitTargetPage(Page<MonitorOverLimitVO>p,
@Param("ids") List<String> lineIndexes,
@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
}

View File

@@ -295,13 +295,10 @@ public class AnalyzeServiceImpl implements IAnalyzeService {
lineList.addAll(item.getLineIndexes());
});
}
Page<RStatLimitRateDPO> p = new Page<>();
p.setSize(param.getPageSize());
p.setCurrent(param.getPageNum());
if (CollectionUtil.isNotEmpty(lineList)) {
Page<MonitorOverLimitVO> sumLimitRatePage = targetMapper.getSumLimitTargetPage(p, lineList, DateUtil.beginOfDay(DateUtil.parse(param.getSearchBeginTime())),
page = targetMapper.getSumLimitTargetPage(page, lineList, DateUtil.beginOfDay(DateUtil.parse(param.getSearchBeginTime())),
DateUtil.endOfDay(DateUtil.parse(param.getSearchEndTime())));
List<MonitorOverLimitVO> pageRecords = sumLimitRatePage.getRecords();
List<MonitorOverLimitVO> pageRecords = page.getRecords();
if (CollectionUtils.isEmpty(pageRecords)) {
return page;
}
@@ -360,9 +357,8 @@ public class AnalyzeServiceImpl implements IAnalyzeService {
}
if (!CollectionUtils.isEmpty(result)){
List<MonitorOverLimitVO> recordList = new ArrayList<>();
//默认 根据在线监测点个数 倒叙排序
recordList = result.stream().sorted(Comparator.comparing(MonitorOverLimitVO::getOverDay).reversed()).collect(Collectors.toList());
List<MonitorOverLimitVO> recordList = result.stream().sorted(Comparator.comparing(MonitorOverLimitVO::getOverDay).reversed()).collect(Collectors.toList());
page.setRecords(recordList);
return page;
}

View File

@@ -50,5 +50,9 @@ public class Communicate {
@Column(name = "description")
private String remark;
private Integer duration;
private String desc;
}

View File

@@ -1,5 +1,6 @@
package com.njcn.prepare.harmonic.pojo.mysql.po.line;
import cn.hutool.core.date.DateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.njcn.db.bo.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
@@ -46,8 +47,7 @@ public class AlarmPO implements Serializable {
*/
private Integer alarmCount;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone ="GMT+8")
private LocalDateTime updateTime;
private String updateTime;
/**
* 1.装置 2.监测点

View File

@@ -1,6 +1,7 @@
package com.njcn.prepare.harmonic.pojo.mysql.po.line;
import com.njcn.db.bo.BaseEntity;
import com.njcn.prepare.harmonic.pojo.influxdb.po.Communicate;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -31,11 +32,10 @@ public class TopMsgPO extends BaseEntity {
*/
private Integer comOutCount;
/**
* 通信中断时间段描述
*/
private List<String> comOutDesc;
private String comOutDescription;
/**
@@ -74,10 +74,10 @@ public class TopMsgPO extends BaseEntity {
private float onlineRateValue;
private Integer offtimeValue;
private Integer offtimeFlag;
private List<Communicate> communicates;
/**
* 状态 0.删除 1.正常
*/

View File

@@ -40,7 +40,7 @@
SELECT line.Id AS id,
device.Id AS deviceId,
sdd.Algo_Describe AS level,
device.Update_Time AS updateTime
DATE_FORMAT(pd.Update_Time, "%Y-%m-%d %H:%i:%s") AS updateTime
FROM pq_line line
INNER JOIN pq_line vol ON line.pid=vol.id
INNER JOIN pq_line device ON vol.pid=device.id
@@ -101,16 +101,17 @@
FROM
(
SELECT
cmf.Dev_Id deviceId,
device.id deviceId,
IFNULL(d.flow, (select flow from cld_flow_meal where type = 0 and flag = 1)) + IFNULL(d1.flow, 0) flowMeal,
IFNULL(cmf.Actual_Value,0) actualValue,
rsod.online_min/1440 onlineRate
FROM cld_month_flow cmf
IFNULL(cmf.Actual_Value/1024/1024,0) actualValue,
rsod.online_min/(rsod.online_min+rsod.offline_min) onlineRate
FROM pq_line device
LEFT JOIN cld_month_flow cmf ON cmf.Dev_Id = device.id
LEFT JOIN cld_dev_meal c ON cmf.Dev_Id = c.Line_Id
LEFT JOIN cld_flow_meal d ON c.Base_Meal_Id = d.id
LEFT JOIN cld_flow_meal d1 ON c.Ream_Meal_Id = d1.id
LEFT JOIN r_stat_onlinerate_d rsod ON rsod.dev_index = cmf.Dev_Id
WHERE cmf.Dev_Id IN
LEFT JOIN r_stat_onlinerate_d rsod ON rsod.dev_index = device.id
WHERE device.id IN
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>

View File

@@ -22,6 +22,7 @@ import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -48,6 +49,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
List<String> monotorIds = lines.stream().map(AlarmPO::getId).collect(Collectors.toList());
// 装置id集合
List<String> devIds = new ArrayList<>(devMap.keySet());
// 获取异常告警策略
List<AlarmStrategyVO> alarmStrategyVOS = deviceAbnormaStatisticsMapper.selectAlarmStrategy();
Map<Integer, List<AlarmStrategyVO>> levMap = alarmStrategyVOS.stream().collect(Collectors.groupingBy(AlarmStrategyVO::getAlgoDesc));
// 获取监测点数据完整性
List<AlarmPO> lineIntegritys = deviceAbnormaStatisticsMapper.getIntegrityByLineIds(
monotorIds,
@@ -68,41 +72,45 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
if (CollectionUtil.isNotEmpty(deviceFlowAndOnlineRate)) {
deviceFlowAndOnlineRateMap = deviceFlowAndOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
}
// 获取通信中断信息
// List<String> list = Arrays.asList("025fa0e4c91f72ad7f1c1bd29026f20a");
List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime(), param.getTime());
List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime());
if (CollectionUtil.isNotEmpty(comMsgs)) {
comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId));
}
// 比对告警策略并落表
List<AlarmStrategyVO> alarmStrategyVOS = deviceAbnormaStatisticsMapper.selectAlarmStrategy();
Map<Integer, List<AlarmStrategyVO>> levMap = alarmStrategyVOS.stream().collect(Collectors.groupingBy(AlarmStrategyVO::getAlgoDesc));
// 整合装置信息
List<TopMsgPO> topMsgPOS = new ArrayList<>();
for (Map.Entry<String, List<AlarmPO>> alarmEntry : devMap.entrySet()) {
if (!lineIntegrityMap.containsKey(alarmEntry.getKey()) && !lineAlarmsMap.containsKey(alarmEntry.getKey())
&& !deviceFlowAndOnlineRateMap.containsKey(alarmEntry.getKey()) && !comMap.containsKey(alarmEntry.getKey())) {
for (Map.Entry<String, List<AlarmPO>> devEntry : devMap.entrySet()) {
if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey())
&& !deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey())) {
continue;
}
TopMsgPO topMsg = new TopMsgPO();
topMsg.setDevId(alarmEntry.getKey());
int deviceLevel = alarmEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1);
topMsg.setDevId(devEntry.getKey());
topMsg.setIntegrityFlag(1);
topMsg.setOfftimeFlag(1);
topMsg.setFlowFlag(1);
topMsg.setOnlineRateFlag(1);
topMsg.setAlarmCountFlag(1);
int deviceLevel = devEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1);
// 装置等级
topMsg.setDeviceLevel(deviceLevel);
// 等级对应的告警策略
AlarmStrategyVO alarmStrategyVO = levMap.get(deviceLevel).get(0);
// 数据完整性
if (lineIntegrityMap.containsKey(alarmEntry.getKey())) {
Integer due = lineIntegrityMap.get(alarmEntry.getKey()).get(0).getDue();
Integer real = lineIntegrityMap.get(alarmEntry.getKey()).get(0).getReal();
if (lineIntegrityMap.containsKey(devEntry.getKey())) {
Integer due = lineIntegrityMap.get(devEntry.getKey()).get(0).getDue();
Integer real = lineIntegrityMap.get(devEntry.getKey()).get(0).getReal();
float integrity = BigDecimal.valueOf((float) real *100 / due).setScale(2, RoundingMode.HALF_UP).floatValue();
topMsg.setIntegrityFlag(integrity < alarmStrategyVO.getIntegrityValue() ? 0 : 1);
topMsg.setIntegrityValue(integrity);
} else {
topMsg.setIntegrityFlag(-1);
}
// 装置告警
if (lineAlarmsMap.containsKey(alarmEntry.getKey())) {
List<AlarmPO> lineAlarmPOS = lineAlarmsMap.get(alarmEntry.getKey());
if (lineAlarmsMap.containsKey(devEntry.getKey())) {
List<AlarmPO> lineAlarmPOS = lineAlarmsMap.get(devEntry.getKey());
int alarmCount = lineAlarmPOS.stream().mapToInt(AlarmPO::getAlarmCount).sum();
String alarmDesc = String.join(",", lineAlarmPOS.stream().map(AlarmPO::getAlarmDesc).collect(Collectors.toList()));
topMsg.setAlarmCountFlag(alarmCount > alarmStrategyVO.getWarnValue() ? 0 : 1);
@@ -112,8 +120,8 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
topMsg.setAlarmCount(0);
}
// 流量和在线率
if (deviceFlowAndOnlineRateMap.containsKey(alarmEntry.getKey())) {
AlarmPO alarmPO = deviceFlowAndOnlineRateMap.get(alarmEntry.getKey()).get(0);
if (deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey())) {
AlarmPO alarmPO = deviceFlowAndOnlineRateMap.get(devEntry.getKey()).get(0);
topMsg.setFlowFlag(alarmPO.getActualValue() > alarmPO.getFlowMeal() ? 0 : 1);
topMsg.setOnlineRateFlag(alarmPO.getOnlineRate() *100 < alarmStrategyVO.getOnlineValue() ? 0 : 1);
topMsg.setFlowValue(alarmPO.getFlowProportion());
@@ -123,29 +131,34 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
topMsg.setOnlineRateFlag(-1);
}
if (comMap.containsKey(alarmEntry.getKey())) {
TopMsgPO comOutPO = comMap.get(alarmEntry.getKey()).get(0);
topMsg.setOfftimeFlag(comOutPO.getOfftimeValue() > alarmStrategyVO.getOffTimeValue() ? 0 :1);
topMsg.setComOutCount(comOutPO.getComOutCount());
topMsg.setComOutDescription(String.join(",",comOutPO.getComOutDesc()));
if (comMap.containsKey(devEntry.getKey())) {
TopMsgPO comOutPO = comMap.get(devEntry.getKey()).get(0);
List<Communicate> abnormals = comOutPO.getCommunicates().stream().filter(t -> t.getDuration() > alarmStrategyVO.getOffTimeValue()).collect(Collectors.toList());
topMsg.setOfftimeFlag(abnormals.size() > 0 ? 0 :1);
topMsg.setComOutCount(abnormals.size());
List<String> abnormalDesc = abnormals.stream().map(Communicate::getDesc).collect(Collectors.toList());
topMsg.setComOutDescription(String.join(",",abnormalDesc));
} else {
try {
if (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(devEntry.getValue().get(0).getUpdateTime()).after(DateUtil.endOfDay(DateUtil.parse(param.getTime())))) {
topMsg.setOfftimeFlag(0);
String updateTime = localDateTimeFormat(alarmEntry.getValue().get(0).getUpdateTime());
long time = DateUtil.endOfDay(DateUtil.parse(param.getTime())).getTime() -
alarmEntry.getValue().get(0).getUpdateTime().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
topMsg.setOfftimeValue((int)(time/1000/60));
topMsg.setComOutCount(1);
topMsg.setComOutDescription(updateTime+""+DateUtil.endOfDay(DateUtil.parse(param.getTime())));
topMsg.setComOutDescription(DateUtil.beginOfDay(DateUtil.parse(param.getTime()))+""+devEntry.getValue().get(0).getUpdateTime());
} else if (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(devEntry.getValue().get(0).getUpdateTime()).before(DateUtil.beginOfDay(DateUtil.parse(param.getTime())))) {
topMsg.setOfftimeFlag(1);
topMsg.setComOutCount(0);
}
if (topMsg.getFlowFlag() != 1 || topMsg.getIntegrityFlag() != 1 || topMsg.getOfftimeFlag() != 0
} catch (ParseException e) {
log.error("ParseException "+e);
}
}
if (topMsg.getFlowFlag() !=1 || topMsg.getIntegrityFlag() !=1 || topMsg.getOfftimeFlag() != 1
|| topMsg.getAlarmCountFlag() !=1 || topMsg.getOnlineRateFlag() !=1) {
topMsgPOS.add(topMsg);
}
}
return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS);
}
public String localDateTimeFormat(LocalDateTime localDateTime) {
@@ -156,12 +169,10 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(instant.toEpochMilli());
return format;
}
public List<TopMsgPO> getCommunicate(List<String> devs, String startTime, String endTime) {
// startTime ="2023-04-02";
// endTime = "2023-04-02";
public List<TopMsgPO> getCommunicate(List<String> devs, String time) {
// 组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(time))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(time))).append("' and ");
for (int i = 0; i < devs.size(); i++) {
if (devs.size() - i != 1) {
stringBuilder.append("dev_id ='").append(devs.get(i)).append("' or ");
@@ -180,34 +191,39 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Map<String, List<Communicate>> comMap = communicates.stream().collect(Collectors.groupingBy(Communicate::getDevId));
for (Map.Entry<String, List<Communicate>> comEntry : comMap.entrySet()) {
TopMsgPO topMsgPO = new TopMsgPO(); List<String> comOutDesc = new ArrayList<>();
topMsgPO.setDevId(comEntry.getKey());
for (Map.Entry<String, List<Communicate>> entry : comMap.entrySet()) {
String key = entry.getKey();
List<Communicate> value = entry.getValue();
TopMsgPO topMsgPO = new TopMsgPO();
List<Communicate> comOuts = new ArrayList<>();
topMsgPO.setDevId(key);
// 根据日期排序
List<Communicate> sortedList = comEntry.getValue().stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList());
Long mills = 0l;
List<Communicate> sortedList = value.stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList());
if (sortedList.get(0).getType() == 1) {
long time = Date.from(sortedList.get(0).getUpdateTime()).getTime() - DateUtil.beginOfDay(DateUtil.parse(startTime)).getTime();
mills += time;
comOutDesc.add((DateUtil.beginOfDay(DateUtil.parse(startTime)))+""+formatter.format(Date.from(sortedList.get(0).getUpdateTime())));
Communicate communicate = new Communicate();
int durationTime = (int) (Date.from(sortedList.get(0).getUpdateTime()).getTime() - DateUtil.beginOfDay(DateUtil.parse(time)).getTime())/1000/60;
communicate.setDuration(durationTime);
communicate.setDesc((DateUtil.beginOfDay(DateUtil.parse(time))) + "" + formatter.format(Date.from(sortedList.get(0).getUpdateTime())));
comOuts.add(communicate);
}
for (int i = 0; i < sortedList.size(); i++) {
if (sortedList.get(i).getType() == 0 && i < sortedList.size() - 1) {
long time = Date.from(sortedList.get(i+1).getUpdateTime()).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime();
mills += time;
String comOutTime =formatter.format(Date.from(sortedList.get(i).getUpdateTime()))+""+ formatter.format(Date.from(sortedList.get(i+1).getUpdateTime()));
comOutDesc.add(comOutTime);
Communicate communicate = new Communicate();
int durationTime = (int) (Date.from(sortedList.get(i + 1).getUpdateTime()).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime())/1000/60;
communicate.setDuration(durationTime);
String comOut = formatter.format(Date.from(sortedList.get(i).getUpdateTime())) + "" + formatter.format(Date.from(sortedList.get(i + 1).getUpdateTime()));
communicate.setDesc(comOut);
comOuts.add(communicate);
} else if (sortedList.get(i).getType() == 0 && i == sortedList.size() - 1) {
long time = DateUtil.endOfDay(DateUtil.parse(endTime)).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime();
mills += time;
String comOutTime = formatter.format(Date.from(sortedList.get(i).getUpdateTime())) +""+ DateUtil.endOfDay(DateUtil.parse(endTime));
comOutDesc.add(comOutTime);
Communicate communicate = new Communicate();
int durationTime = (int) (DateUtil.endOfDay(DateUtil.parse(time)).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime()) / 1000 / 60;
communicate.setDuration(durationTime);
String comOut = formatter.format(Date.from(sortedList.get(i).getUpdateTime())) + "" + DateUtil.endOfDay(DateUtil.parse(time));
communicate.setDesc(comOut);
comOuts.add(communicate);
}
}
topMsgPO.setOfftimeValue( (int)(mills / 1000 / 60));
topMsgPO.setComOutDesc(comOutDesc);
// 通信中断次数
topMsgPO.setComOutCount(comOutDesc.size());
topMsgPO.setCommunicates(comOuts);
comMsgs.add(topMsgPO);
}
return comMsgs;

View File

@@ -37,12 +37,15 @@ public class ConfigParam {
*/
@ApiModelProperty("审计日志大小MB")
@NotNull(message = "审计日志大小不可为空")
@Min(value = 0,message = "审计日志大小不能小于0")
private BigDecimal logSize;
/**
* 审计日志大小
*/
@ApiModelProperty("审计日志存储时间1-6个月默认3个月")
@Min(value = 1,message = "审计日志保留时间不能小于1")
@Max(value = 6,message = "审计日志保留时间不能大于6")
private Integer logTime;
/**

View File

@@ -13,9 +13,11 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* <p>
@@ -81,7 +83,9 @@ public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> impleme
@Override
public List<Config> getList() {
return this.baseMapper.getList();
List<Config> list = this.baseMapper.getList();
List<Config> filterList = list.stream().filter(t -> t.getLogTime() > 0 && t.getLogSize().compareTo(new BigDecimal(0))==1).collect(Collectors.toList());
return filterList;
}