|
@@ -10,6 +10,7 @@ import com.gyee.wisdom.alarm.schedule.service.TableNameService;
|
|
|
import com.gyee.wisdom.alarm.schedule.util.SnowflakeGenerator;
|
|
|
import com.gyee.wisdom.common.utils.DateUtil;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -17,8 +18,10 @@ import org.springframework.stereotype.Component;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @description: 报警统计,每天计算后写入alarmcount表 sharding-mysql2中AlarmCountService中startCount方法移植
|
|
@@ -26,6 +29,7 @@ import java.util.List;
|
|
|
* @date: 2022-03-16
|
|
|
*/
|
|
|
@Component
|
|
|
+@Slf4j
|
|
|
public class AlarmCountHandler {
|
|
|
|
|
|
@Autowired
|
|
@@ -40,7 +44,7 @@ public class AlarmCountHandler {
|
|
|
@Autowired
|
|
|
private TableNameService tableNameService;
|
|
|
|
|
|
- // @Scheduled(cron = "0 30 0 ? * *")
|
|
|
+ // @Scheduled(cron = "0 30 0 ? * *")
|
|
|
@XxlJob("alarmCountStat")
|
|
|
public boolean alarmCountStat() {
|
|
|
|
|
@@ -48,7 +52,7 @@ public class AlarmCountHandler {
|
|
|
try {
|
|
|
List<AlarmSnap> snapList = alarmSnapService.queryAll(null, null, "custom", null, null, null, null, null, null, null);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
|
|
|
+ String strDate = sdf.format(DateUtil.addDays(new Date(), -1));
|
|
|
Date dtStart = sdf.parse(strDate);
|
|
|
Date dtEnd = DateUtil.addDays(dtStart, 1);
|
|
|
Date dtNow = new Date();
|
|
@@ -71,24 +75,24 @@ public class AlarmCountHandler {
|
|
|
Date alertTimebegin = null;
|
|
|
Date alertTimeend = null;
|
|
|
Double minall = 0.0;
|
|
|
- for(AlarmHistory alarmHistory:alarmHistories){
|
|
|
+ for (AlarmHistory alarmHistory : alarmHistories) {
|
|
|
int messageType = alarmHistory.getMessageType();
|
|
|
- if(!(messageType==1^bool)){
|
|
|
- if(bool) {
|
|
|
+ if (!(messageType == 1 ^ bool)) {
|
|
|
+ if (bool) {
|
|
|
alertTimebegin = alarmHistory.getAlertTime();
|
|
|
}
|
|
|
- if(!bool){
|
|
|
+ if (!bool) {
|
|
|
alertTimeend = alarmHistory.getAlertTime();
|
|
|
- Double min = Double.parseDouble((alertTimeend.getTime()-alertTimebegin.getTime())+"")/1000/60;
|
|
|
+ Double min = Double.parseDouble((alertTimeend.getTime() - alertTimebegin.getTime()) + "") / 1000 / 60;
|
|
|
minall = minall + min;
|
|
|
bool = true;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
bool = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
DecimalFormat df = new DecimalFormat("0.000");
|
|
|
- ac.setTime(Double.parseDouble(df.format(minall+1)));
|
|
|
+ ac.setTime(Double.parseDouble(df.format(minall + 1)));
|
|
|
acList.add(ac);
|
|
|
}
|
|
|
}
|
|
@@ -99,9 +103,9 @@ public class AlarmCountHandler {
|
|
|
dtEnd = DateUtil.addDays(dtStart, 1);
|
|
|
}
|
|
|
|
|
|
- } catch(Exception ex){
|
|
|
- // log.error(ex.getMessage());
|
|
|
- // log.error(ex.getStackTrace().toString());
|
|
|
+ } catch (Exception ex) {
|
|
|
+ log.error(ex.getMessage());
|
|
|
+ log.error("执行调度任务失败{}",ex.getStackTrace());
|
|
|
return false;
|
|
|
}
|
|
|
|