问题单修复

This commit is contained in:
zhuxinyu
2023-05-04 13:34:54 +08:00
parent 46179beb54
commit 886bec3def
3 changed files with 65 additions and 75 deletions

View File

@@ -18,15 +18,23 @@ public interface DeviceAbnormaStatisticsMapper {
*/
List<AlarmPO> getLines();
List<AlarmPO> getFlowAndOnlineRateByDevice(@Param("list") List<String> list,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
List<AlarmPO> getFlowByDevice(@Param("list") List<String> list, @Param("time") String startTime);
List<AlarmPO> getIntegrityByLines(@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
List<AlarmPO> getIntegrityByLineIds(@Param("list") List<String> list,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
List<AlarmPO> getIntegrityByLineIds(@Param("list") List<String> list, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
/**
* 告警信息
* @param monitorIds
* @param devIds
* @param startTime
* @param endTime
* @return
*/
List<AlarmPO> getAlarmByLines(@Param("monitorIds") List<String> monitorIds,@Param("devIds") List<String> devIds,@Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
Boolean insertTopMsg(@Param("list") List<TopMsgPO> topMsgPOS);
List<AlarmStrategyVO> selectAlarmStrategy();
List<AlarmPO> getOnlineRateByDevice(@Param("list") List<String> devIds, @Param("startTime") DateTime beginOfDay, @Param("endTime") DateTime endOfDay);
}

View File

@@ -55,33 +55,12 @@
pld.Line_Grade is NOT NULL
</select>
<select id="getIntegrityByLines" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
SELECT line.Id AS Id,
device.id AS deviceId,
IFNULL(SUM(integrity.due_time),0) AS due,
IFNULL(SUM(integrity.real_time),0) AS `real`
FROM pq_line line
INNER JOIN pq_line vol ON line.pid=vol.id
INNER JOIN pq_line device ON vol.pid=device.id
LEFT JOIN pq_device pd ON device.id=pd.id
LEFT JOIN pq_line_detail pld ON pld.id=line.id
LEFT JOIN r_stat_integrity_d integrity ON integrity.line_index = line.id
WHERE
pd.Dev_Model=1
AND
pd.Run_Flag=0
AND
pld.Line_Grade is NOT NULL
AND
integrity.time_id BETWEEN #{startTime} AND #{endTime}
GROUP BY device.Id
</select>
<select id="getIntegrityByLineIds" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
SELECT
device.id AS deviceId,
IFNULL(SUM(integrity.due_time),0) AS due,
IFNULL(SUM(integrity.real_time),0) AS `real`
IFNULL(SUM(integrity.real_time),0) AS `real`,
CONVERT(SUM(integrity.real_time)*100/SUM(integrity.due_time),DECIMAL(15,2)) AS integrity
FROM r_stat_integrity_d integrity
INNER JOIN pq_line line ON integrity.line_index = line.id
INNER JOIN pq_line vol ON line.pid=vol.id
@@ -95,28 +74,26 @@
GROUP BY device.Id
</select>
<select id="getFlowAndOnlineRateByDevice" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
<select id="getFlowByDevice" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
SELECT t.*,
(t.actualValue)/(t.flowMeal) flowProportion
FROM
(
SELECT
device.id deviceId,
cmf.Dev_Id deviceId,
DATE_FORMAT(cmf.Time_Id,'%Y-%m') updateTime,
IFNULL(d.flow, (select flow from cld_flow_meal where type = 0 and flag = 1)) + IFNULL(d1.flow, 0) flowMeal,
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
IFNULL(cmf.Actual_Value/1024/1024,0) actualValue
FROM cld_month_flow cmf
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 = device.id
WHERE device.id IN
WHERE cmf.Dev_Id IN
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
AND
cmf.Time_Id BETWEEN #{startTime} AND #{endTime}
DATE_FORMAT(cmf.Time_Id,'%Y-%m') =#{time}
) t
ORDER BY flowProportion DESC
</select>
@@ -171,4 +148,17 @@
WHERE A.State = 1
</select>
<select id="getOnlineRateByDevice" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
SELECT
rsod.dev_index,
rsod.online_min/(rsod.online_min+rsod.offline_min) onlineRate
FROM r_stat_onlinerate_d rsod
WHERE rsod.dev_index IN
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
AND
rsod.time_id BETWEEN #{startTime} AND #{endTime}
</select>
</mapper>

View File

@@ -1,6 +1,7 @@
package com.njcn.prepare.harmonic.service.mysql.Impl.device;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
@@ -38,9 +39,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
private final InfluxDbUtils influxDbUtils;
@Override
public boolean dailyDeviceAbnormaStatistics(DeviceAbnormaStatisticsParam param) {
public boolean dailyDeviceAbnormaStatistics (DeviceAbnormaStatisticsParam param) {
Map<String, List<TopMsgPO>> comMap = new HashMap<>();
Map<String, List<AlarmPO>> deviceFlowAndOnlineRateMap = new HashMap<>();
Map<String, List<AlarmPO>> deviceFlowMap = new HashMap<>();
// 获取所有装置以及下属监测点
List<AlarmPO> lines = deviceAbnormaStatisticsMapper.getLines();
// 根据装置id分组
@@ -58,36 +59,37 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
DateUtil.beginOfDay(DateUtil.parse(param.getTime())),
DateUtil.endOfDay(DateUtil.parse(param.getTime())));
Map<String, List<AlarmPO>> lineIntegrityMap = lineIntegritys.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
// 告警信息统计
List<AlarmPO> lineAlarms = deviceAbnormaStatisticsMapper.getAlarmByLines(
monotorIds,
devIds,
DateUtil.beginOfDay(DateUtil.parse(param.getTime())),
DateUtil.endOfDay(DateUtil.parse(param.getTime())));
Map<String, List<AlarmPO>> lineAlarmsMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
// 获取设备流量
List<AlarmPO> deviceFlowAndOnlineRate = deviceAbnormaStatisticsMapper.getFlowAndOnlineRateByDevice(
// 获取终端在线率
List<AlarmPO> deviceOnlineRate = deviceAbnormaStatisticsMapper.getOnlineRateByDevice(
devIds,
DateUtil.beginOfDay(DateUtil.parse(param.getTime())),
DateUtil.endOfDay(DateUtil.parse(param.getTime())));
if (CollectionUtil.isNotEmpty(deviceFlowAndOnlineRate)) {
deviceFlowAndOnlineRateMap = deviceFlowAndOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
Map<String, List<AlarmPO>> deviceOnlineMap = deviceOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
// 获取设备流量
List<AlarmPO> deviceFlow = deviceAbnormaStatisticsMapper.getFlowByDevice(devIds,param.getTime().substring(0,6));
if (CollectionUtil.isNotEmpty(deviceFlow)) {
deviceFlowMap = deviceFlow.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
}
// 获取通信中断信息
// List<String> list = Arrays.asList("025fa0e4c91f72ad7f1c1bd29026f20a");
List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime());
if (CollectionUtil.isNotEmpty(comMsgs)) {
comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId));
}
// 整合装置信息
List<TopMsgPO> topMsgPOS = new ArrayList<>();
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;
}
// if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey())
// && !deviceFlowMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey()) && !deviceOnlineMap.containsKey(devEntry.getKey())) {
// continue;
// }
TopMsgPO topMsg = new TopMsgPO();
topMsg.setDevId(devEntry.getKey());
topMsg.setIntegrityFlag(1);
@@ -95,12 +97,6 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
topMsg.setFlowFlag(1);
topMsg.setOnlineRateFlag(1);
topMsg.setAlarmCountFlag(1);
try {
topMsg.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(param.getTime()));
} catch (ParseException e) {
log.error("ParseException: "+e);
e.printStackTrace();
}
int deviceLevel = devEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1);
// 装置等级
topMsg.setDeviceLevel(deviceLevel);
@@ -108,11 +104,10 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
AlarmStrategyVO alarmStrategyVO = levMap.get(deviceLevel).get(0);
// 数据完整性
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);
topMsg.setIntegrityFlag(lineIntegrityMap.get(devEntry.getKey()).get(0).getIntegrity() < alarmStrategyVO.getIntegrityValue() ? 0 : 1);
topMsg.setIntegrityValue(lineIntegrityMap.get(devEntry.getKey()).get(0).getIntegrity());
} else {
topMsg.setIntegrityFlag(-1);
}
// 装置告警
if (lineAlarmsMap.containsKey(devEntry.getKey())) {
@@ -125,17 +120,22 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
} else {
topMsg.setAlarmCount(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());
// 在线率
if (deviceOnlineMap.containsKey(devEntry.getKey())) {
AlarmPO alarmPO = deviceOnlineMap.get(devEntry.getKey()).get(0);
topMsg.setOnlineRateFlag(alarmPO.getOnlineRate() * 100 < alarmStrategyVO.getOnlineValue() ? 0 : 1);
topMsg.setOnlineRateValue(alarmPO.getOnlineRate() *100);
} else {
topMsg.setFlowFlag(-1);
topMsg.setOnlineRateFlag(-1);
}
// 流量
if (deviceFlowMap.containsKey(devEntry.getKey()) && Objects.nonNull(deviceFlowMap.get(devEntry.getKey()).get(0).getFlowProportion())) {
AlarmPO alarmPO = deviceFlowMap.get(devEntry.getKey()).get(0);
topMsg.setFlowFlag(alarmPO.getActualValue() > alarmPO.getFlowMeal() ? 0 : 1);
topMsg.setFlowValue(alarmPO.getFlowProportion());
} else {
topMsg.setFlowFlag(-1);
}
if (comMap.containsKey(devEntry.getKey())) {
TopMsgPO comOutPO = comMap.get(devEntry.getKey()).get(0);
@@ -167,14 +167,6 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS);
}
public String localDateTimeFormat(LocalDateTime localDateTime) {
// 通过LocalDateTime.atZone方法使用系统默认时区ZonId.systemDefault()获取Instant实例
ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.systemDefault());
Instant instant = zonedDateTime.toInstant();
// 日期格式化
String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(instant.toEpochMilli());
return format;
}
public List<TopMsgPO> getCommunicate(List<String> devs, String time) {
// 组装sql语句
StringBuilder stringBuilder = new StringBuilder();