问题单修复

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> 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); 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); Boolean insertTopMsg(@Param("list") List<TopMsgPO> topMsgPOS);
List<AlarmStrategyVO> selectAlarmStrategy(); 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 pld.Line_Grade is NOT NULL
</select> </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 id="getIntegrityByLineIds" resultType="com.njcn.prepare.harmonic.pojo.mysql.po.line.AlarmPO">
SELECT SELECT
device.id AS deviceId, device.id AS deviceId,
IFNULL(SUM(integrity.due_time),0) AS due, 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 FROM r_stat_integrity_d integrity
INNER JOIN pq_line line ON integrity.line_index = line.id INNER JOIN pq_line line ON integrity.line_index = line.id
INNER JOIN pq_line vol ON line.pid=vol.id INNER JOIN pq_line vol ON line.pid=vol.id
@@ -95,28 +74,26 @@
GROUP BY device.Id GROUP BY device.Id
</select> </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.*, SELECT t.*,
(t.actualValue)/(t.flowMeal) flowProportion (t.actualValue)/(t.flowMeal) flowProportion
FROM FROM
( (
SELECT 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(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, IFNULL(cmf.Actual_Value/1024/1024,0) actualValue
rsod.online_min/(rsod.online_min+rsod.offline_min) onlineRate FROM cld_month_flow cmf
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_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 d ON c.Base_Meal_Id = d.id
LEFT JOIN cld_flow_meal d1 ON c.Ream_Meal_Id = d1.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 cmf.Dev_Id IN
WHERE device.id IN
<foreach collection="list" index="index" item="item" open="(" separator="," close=")"> <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item} #{item}
</foreach> </foreach>
AND AND
cmf.Time_Id BETWEEN #{startTime} AND #{endTime} DATE_FORMAT(cmf.Time_Id,'%Y-%m') =#{time}
) t ) t
ORDER BY flowProportion DESC ORDER BY flowProportion DESC
</select> </select>
@@ -171,4 +148,17 @@
WHERE A.State = 1 WHERE A.State = 1
</select> </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> </mapper>

View File

@@ -1,6 +1,7 @@
package com.njcn.prepare.harmonic.service.mysql.Impl.device; package com.njcn.prepare.harmonic.service.mysql.Impl.device;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.njcn.influxdb.param.InfluxDBPublicParam; import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils; import com.njcn.influxdb.utils.InfluxDbUtils;
@@ -38,9 +39,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
private final InfluxDbUtils influxDbUtils; private final InfluxDbUtils influxDbUtils;
@Override @Override
public boolean dailyDeviceAbnormaStatistics(DeviceAbnormaStatisticsParam param) { public boolean dailyDeviceAbnormaStatistics (DeviceAbnormaStatisticsParam param) {
Map<String, List<TopMsgPO>> comMap = new HashMap<>(); 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(); List<AlarmPO> lines = deviceAbnormaStatisticsMapper.getLines();
// 根据装置id分组 // 根据装置id分组
@@ -58,36 +59,37 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
DateUtil.beginOfDay(DateUtil.parse(param.getTime())), DateUtil.beginOfDay(DateUtil.parse(param.getTime())),
DateUtil.endOfDay(DateUtil.parse(param.getTime()))); DateUtil.endOfDay(DateUtil.parse(param.getTime())));
Map<String, List<AlarmPO>> lineIntegrityMap = lineIntegritys.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); Map<String, List<AlarmPO>> lineIntegrityMap = lineIntegritys.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
// 告警信息统计
List<AlarmPO> lineAlarms = deviceAbnormaStatisticsMapper.getAlarmByLines( List<AlarmPO> lineAlarms = deviceAbnormaStatisticsMapper.getAlarmByLines(
monotorIds, monotorIds,
devIds, devIds,
DateUtil.beginOfDay(DateUtil.parse(param.getTime())), DateUtil.beginOfDay(DateUtil.parse(param.getTime())),
DateUtil.endOfDay(DateUtil.parse(param.getTime()))); DateUtil.endOfDay(DateUtil.parse(param.getTime())));
Map<String, List<AlarmPO>> lineAlarmsMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId)); Map<String, List<AlarmPO>> lineAlarmsMap = lineAlarms.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
// 获取设备流量 // 获取终端在线率
List<AlarmPO> deviceFlowAndOnlineRate = deviceAbnormaStatisticsMapper.getFlowAndOnlineRateByDevice( List<AlarmPO> deviceOnlineRate = deviceAbnormaStatisticsMapper.getOnlineRateByDevice(
devIds, devIds,
DateUtil.beginOfDay(DateUtil.parse(param.getTime())), DateUtil.beginOfDay(DateUtil.parse(param.getTime())),
DateUtil.endOfDay(DateUtil.parse(param.getTime()))); DateUtil.endOfDay(DateUtil.parse(param.getTime())));
if (CollectionUtil.isNotEmpty(deviceFlowAndOnlineRate)) { Map<String, List<AlarmPO>> deviceOnlineMap = deviceOnlineRate.stream().collect(Collectors.groupingBy(AlarmPO::getDeviceId));
deviceFlowAndOnlineRateMap = deviceFlowAndOnlineRate.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<String> list = Arrays.asList("025fa0e4c91f72ad7f1c1bd29026f20a");
List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime()); List<TopMsgPO> comMsgs = getCommunicate(devIds, param.getTime());
if (CollectionUtil.isNotEmpty(comMsgs)) { if (CollectionUtil.isNotEmpty(comMsgs)) {
comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId)); comMap = comMsgs.stream().collect(Collectors.groupingBy(TopMsgPO::getDevId));
} }
// 整合装置信息 // 整合装置信息
List<TopMsgPO> topMsgPOS = new ArrayList<>(); List<TopMsgPO> topMsgPOS = new ArrayList<>();
for (Map.Entry<String, List<AlarmPO>> devEntry : devMap.entrySet()) { for (Map.Entry<String, List<AlarmPO>> devEntry : devMap.entrySet()) {
if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey()) // if (!lineIntegrityMap.containsKey(devEntry.getKey()) && !lineAlarmsMap.containsKey(devEntry.getKey())
&& !deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey())) { // && !deviceFlowMap.containsKey(devEntry.getKey()) && !comMap.containsKey(devEntry.getKey()) && !deviceOnlineMap.containsKey(devEntry.getKey())) {
continue; // continue;
} // }
TopMsgPO topMsg = new TopMsgPO(); TopMsgPO topMsg = new TopMsgPO();
topMsg.setDevId(devEntry.getKey()); topMsg.setDevId(devEntry.getKey());
topMsg.setIntegrityFlag(1); topMsg.setIntegrityFlag(1);
@@ -95,12 +97,6 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
topMsg.setFlowFlag(1); topMsg.setFlowFlag(1);
topMsg.setOnlineRateFlag(1); topMsg.setOnlineRateFlag(1);
topMsg.setAlarmCountFlag(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); int deviceLevel = devEntry.getValue().stream().mapToInt(AlarmPO::getLevel).min().orElse(-1);
// 装置等级 // 装置等级
topMsg.setDeviceLevel(deviceLevel); topMsg.setDeviceLevel(deviceLevel);
@@ -108,11 +104,10 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
AlarmStrategyVO alarmStrategyVO = levMap.get(deviceLevel).get(0); AlarmStrategyVO alarmStrategyVO = levMap.get(deviceLevel).get(0);
// 数据完整性 // 数据完整性
if (lineIntegrityMap.containsKey(devEntry.getKey())) { if (lineIntegrityMap.containsKey(devEntry.getKey())) {
Integer due = lineIntegrityMap.get(devEntry.getKey()).get(0).getDue(); topMsg.setIntegrityFlag(lineIntegrityMap.get(devEntry.getKey()).get(0).getIntegrity() < alarmStrategyVO.getIntegrityValue() ? 0 : 1);
Integer real = lineIntegrityMap.get(devEntry.getKey()).get(0).getReal(); topMsg.setIntegrityValue(lineIntegrityMap.get(devEntry.getKey()).get(0).getIntegrity());
float integrity = BigDecimal.valueOf((float) real *100 / due).setScale(2, RoundingMode.HALF_UP).floatValue(); } else {
topMsg.setIntegrityFlag(integrity < alarmStrategyVO.getIntegrityValue() ? 0 : 1); topMsg.setIntegrityFlag(-1);
topMsg.setIntegrityValue(integrity);
} }
// 装置告警 // 装置告警
if (lineAlarmsMap.containsKey(devEntry.getKey())) { if (lineAlarmsMap.containsKey(devEntry.getKey())) {
@@ -125,17 +120,22 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
} else { } else {
topMsg.setAlarmCount(0); topMsg.setAlarmCount(0);
} }
// 流量和在线率 // 在线率
if (deviceFlowAndOnlineRateMap.containsKey(devEntry.getKey())) { if (deviceOnlineMap.containsKey(devEntry.getKey())) {
AlarmPO alarmPO = deviceFlowAndOnlineRateMap.get(devEntry.getKey()).get(0); AlarmPO alarmPO = deviceOnlineMap.get(devEntry.getKey()).get(0);
topMsg.setFlowFlag(alarmPO.getActualValue() > alarmPO.getFlowMeal() ? 0 : 1); topMsg.setOnlineRateFlag(alarmPO.getOnlineRate() * 100 < alarmStrategyVO.getOnlineValue() ? 0 : 1);
topMsg.setOnlineRateFlag(alarmPO.getOnlineRate() *100 < alarmStrategyVO.getOnlineValue() ? 0 : 1);
topMsg.setFlowValue(alarmPO.getFlowProportion());
topMsg.setOnlineRateValue(alarmPO.getOnlineRate() *100); topMsg.setOnlineRateValue(alarmPO.getOnlineRate() *100);
} else { } else {
topMsg.setFlowFlag(-1);
topMsg.setOnlineRateFlag(-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())) { if (comMap.containsKey(devEntry.getKey())) {
TopMsgPO comOutPO = comMap.get(devEntry.getKey()).get(0); TopMsgPO comOutPO = comMap.get(devEntry.getKey()).get(0);
@@ -167,14 +167,6 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS); 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) { public List<TopMsgPO> getCommunicate(List<String> devs, String time) {
// 组装sql语句 // 组装sql语句
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();