定时任务优化
This commit is contained in:
@@ -136,18 +136,8 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
||||
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);
|
||||
topMsg.setComOutCount(1);
|
||||
topMsg.setComOutDescription(DateUtil.beginOfDay(DateUtil.parse(param.getTime()))+"至"+devEntry.getValue().get(0).getUpdateTime());
|
||||
} else {
|
||||
topMsg.setOfftimeFlag(1);
|
||||
topMsg.setComOutCount(0);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
log.error("ParseException "+e);
|
||||
}
|
||||
topMsg.setOfftimeFlag(1);
|
||||
topMsg.setComOutCount(0);
|
||||
}
|
||||
if (topMsg.getFlowFlag() ==0 || topMsg.getIntegrityFlag() ==0 || topMsg.getOfftimeFlag() == 0
|
||||
|| topMsg.getAlarmCountFlag() ==0 || topMsg.getOnlineRateFlag() ==0) {
|
||||
@@ -155,6 +145,9 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
||||
}
|
||||
|
||||
}
|
||||
for (TopMsgPO topMsgPO : topMsgPOS) {
|
||||
System.out.println(topMsgPO);
|
||||
}
|
||||
return deviceAbnormaStatisticsMapper.insertTopMsg(topMsgPOS);
|
||||
}
|
||||
|
||||
@@ -174,46 +167,76 @@ public class DeviceAbnormaStatisticsServiceImpl implements DeviceAbnormalStatist
|
||||
QueryResult result = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
|
||||
List<Communicate> communicates = influxDBResultMapper.toPOJO(result, Communicate.class);
|
||||
// 通讯状态统计结果集
|
||||
List<TopMsgPO> comMsgs = new ArrayList<>();
|
||||
if (CollectionUtil.isEmpty(communicates)) {
|
||||
return comMsgs;
|
||||
}
|
||||
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>> 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 = value.stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList());
|
||||
if (sortedList.get(0).getType() == 1) {
|
||||
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) {
|
||||
if (CollectionUtil.isNotEmpty(communicates)) {
|
||||
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 = value.stream().sorted(Comparator.comparing(Communicate::getUpdateTime)).collect(Collectors.toList());
|
||||
if (sortedList.get(0).getType() == 1) {
|
||||
Communicate communicate = new Communicate();
|
||||
int durationTime = (int) (Date.from(sortedList.get(i + 1).getUpdateTime()).getTime() - Date.from(sortedList.get(i).getUpdateTime()).getTime())/1000/60;
|
||||
int durationTime = (int) (Date.from(sortedList.get(0).getUpdateTime()).getTime() - DateUtil.beginOfDay(DateUtil.parse(time)).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) {
|
||||
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);
|
||||
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) {
|
||||
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) {
|
||||
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.setCommunicates(comOuts);
|
||||
comMsgs.add(topMsgPO);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> coms = new ArrayList<>(comMap.keySet());
|
||||
// 计算influxdb中当天无记录装置id
|
||||
List<String> extraComs = devs.stream().filter(t -> !coms.contains(t)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(extraComs)) {
|
||||
for (String devId : extraComs) {
|
||||
TopMsgPO topMsgPO = new TopMsgPO();
|
||||
List<Communicate> comOuts = new ArrayList<>();
|
||||
topMsgPO.setDevId(devId);
|
||||
// 组装sql语句
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("dev_id ='").append(devId).append("'");
|
||||
builder.append(" AND time <= '").append(DateUtil.beginOfDay(DateUtil.parse(time))).append("'").append(" order by time DESC ").append("limit 1 ");
|
||||
String sql1 = "select * from " + InfluxDBPublicParam.PQS_COMMUNICATE + " where "+builder.toString() + InfluxDBPublicParam.TIME_ZONE;
|
||||
// 获取暂降事件
|
||||
QueryResult result1 = influxDbUtils.query(sql1);
|
||||
InfluxDBResultMapper influxDBResultMapper1 = new InfluxDBResultMapper();
|
||||
List<Communicate> earlyData = influxDBResultMapper1.toPOJO(result1, Communicate.class);
|
||||
Communicate early = earlyData.get(0);
|
||||
Communicate communicate = new Communicate();
|
||||
if (early.getType() == 0) {
|
||||
int durationTime = (int) (DateUtil.endOfDay(DateUtil.parse(time)).getTime() - Date.from(early.getUpdateTime()).getTime()) / 1000 / 60;
|
||||
communicate.setDuration(durationTime);
|
||||
communicate.setDesc(formatter.format(Date.from(early.getUpdateTime())) + "至" + DateUtil.endOfDay(DateUtil.parse(time)));
|
||||
comOuts.add(communicate);
|
||||
}
|
||||
topMsgPO.setCommunicates(comOuts);
|
||||
comMsgs.add(topMsgPO);
|
||||
}
|
||||
topMsgPO.setCommunicates(comOuts);
|
||||
comMsgs.add(topMsgPO);
|
||||
}
|
||||
return comMsgs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user