|
@@ -3,7 +3,9 @@ package com.gyee.impala.service.custom.diagnose;
|
|
|
|
|
|
import com.gyee.impala.common.cache.InfoCache;
|
|
|
import com.gyee.impala.common.feign.RemoteServiceBuilder;
|
|
|
+import com.gyee.impala.common.util.DateUtil;
|
|
|
import com.gyee.impala.model.custom.diagnose.FaultInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.ApplicationArguments;
|
|
|
import org.springframework.boot.ApplicationRunner;
|
|
|
import org.springframework.core.annotation.Order;
|
|
@@ -23,6 +25,7 @@ import java.util.stream.Collectors;
|
|
|
*
|
|
|
* @author xysn
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
@Order(1)
|
|
|
public class FaultRefreshService implements ApplicationRunner {
|
|
@@ -32,22 +35,6 @@ public class FaultRefreshService implements ApplicationRunner {
|
|
|
|
|
|
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
private Calendar calendar;
|
|
|
- /**
|
|
|
- * FaultInfo上次缓存
|
|
|
- */
|
|
|
- private List<FaultInfo> faultRecentold;
|
|
|
- /**
|
|
|
- * FaultInfo当前值
|
|
|
- */
|
|
|
- private List<FaultInfo> faultRecent;
|
|
|
- /**
|
|
|
- * FaultInfo当前值
|
|
|
- */
|
|
|
- private Map<Long, FaultInfo> faultRecentMap;
|
|
|
- /**
|
|
|
- * FaultInfo上次缓存
|
|
|
- */
|
|
|
- private Map<Long, FaultInfo> faultRecentMapold;
|
|
|
|
|
|
@Resource
|
|
|
private RemoteServiceBuilder shardingBuilder;
|
|
@@ -72,7 +59,7 @@ public class FaultRefreshService implements ApplicationRunner {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
try {
|
|
|
- Thread.sleep(5000);
|
|
|
+ Thread.sleep(10 * 1000);
|
|
|
} catch (Exception e) {
|
|
|
}
|
|
|
}
|
|
@@ -83,24 +70,26 @@ public class FaultRefreshService implements ApplicationRunner {
|
|
|
*/
|
|
|
private void toRefresh() {
|
|
|
calendar = Calendar.getInstance();
|
|
|
- calendar.add(Calendar.HOUR_OF_DAY, -2);
|
|
|
+ calendar.add(Calendar.MINUTE, -10);
|
|
|
String s = dateFormat.format(calendar.getTime());
|
|
|
- if (faultRecentold == null || faultRecent == null) {
|
|
|
- faultRecentold = shardingBuilder.sharding().getFaultRecent(s);
|
|
|
- faultRecentold = faultRecentold.stream().filter(f -> f.getCategory1().equals("FJ")).collect(Collectors.toList());
|
|
|
- faultRecentMapold = faultRecentold.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
|
|
|
- infoCache.setFaultRecent(faultRecentMapold);
|
|
|
- } else {
|
|
|
- faultRecentMapold = faultRecentMap;
|
|
|
- infoCache.setFaultRecent(faultRecentMap);
|
|
|
- }
|
|
|
- faultRecent = shardingBuilder.sharding().getFaultRecent(s);
|
|
|
- faultRecent = faultRecent.stream().filter(f -> f.getCategory1().equals("FJ")).collect(Collectors.toList());
|
|
|
- faultRecentMap = faultRecent.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
|
|
|
- for (FaultInfo fi : faultRecentMap.values()) {
|
|
|
- if (!faultRecentMapold.containsKey(fi.getId())) {
|
|
|
+
|
|
|
+ List<FaultInfo> faultRecent = shardingBuilder.sharding().getFaultRecent(s);
|
|
|
+ List<FaultInfo> collect = faultRecent.stream().filter(f -> f.getCategory1().equals("FJ") && f.getCategory2().equals("GZ")).collect(Collectors.toList());
|
|
|
+ Map<Long, FaultInfo> map = collect.stream().collect(Collectors.toMap(FaultInfo::getId, Function.identity(), (key1, key2) -> key2));
|
|
|
+ for (FaultInfo fi : map.values()) {
|
|
|
+ if (!infoCache.faultMap.containsKey(fi.getId()+fi.getFaultTime()+fi.getSnapID())) {
|
|
|
autoCmdService.exec(fi);
|
|
|
+ infoCache.faultMap.put(fi.getId()+fi.getFaultTime()+fi.getSnapID(), fi);
|
|
|
+ log.info(fi.toString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args){
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ System.out.println(dateFormat.format(calendar.getTime()));
|
|
|
+ calendar.add(Calendar.MINUTE, -5);
|
|
|
+ System.out.println(dateFormat.format(calendar.getTime()));
|
|
|
+ }
|
|
|
}
|