|
@@ -1,5 +1,6 @@
|
|
|
package com.bizmatics.mhfire.service.job;
|
|
|
|
|
|
+import com.bizmatics.common.core.util.DateUtils;
|
|
|
import com.bizmatics.common.core.util.StringUtils;
|
|
|
import com.bizmatics.mhfire.model.Alert;
|
|
|
import com.bizmatics.mhfire.service.AlertService;
|
|
@@ -9,7 +10,9 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author yq
|
|
@@ -17,25 +20,54 @@ import java.util.List;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
-public class AlertJob {
|
|
|
+public class AlertJob{
|
|
|
|
|
|
@Autowired
|
|
|
private AlertService alertService;
|
|
|
|
|
|
public void execute(){
|
|
|
- String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
|
|
|
+ try {
|
|
|
+ String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
|
|
|
+ int page = 1;
|
|
|
+ int size = 200;
|
|
|
+ executeCore(page,size,null,null,token);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("alertJob--all--异常"+e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void executeToday(){
|
|
|
+ try {
|
|
|
+ String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
|
|
|
+ int page = 1;
|
|
|
+ int size = 200;
|
|
|
+ Date date = new Date();
|
|
|
+ Date dayStartTime = DateUtils.getDayStartTime(date);
|
|
|
+ Date dayEndTime = DateUtils.getDayEndTime(date);
|
|
|
+ executeCore(page,size,dayStartTime,dayEndTime,token);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("alertJob--today--异常"+e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void executeCore(Integer page,Integer size,Date startTime,Date endTime,String token){
|
|
|
boolean nextFlag = true;
|
|
|
- Integer page = 1;
|
|
|
- Integer size = 500;
|
|
|
- Integer count = 0;
|
|
|
+ int count = 0;
|
|
|
while (StringUtils.isNotBlank(token) && nextFlag){
|
|
|
- List<Alert> alerts = AlertAndSiteApi.alertPage(null, null, page, size, token);
|
|
|
- count+=alerts.size();
|
|
|
- if (CollectionUtils.isNotEmpty(alerts)){
|
|
|
- alerts.forEach(alert -> alertService.saveOrUpdate(alert));
|
|
|
- page++;
|
|
|
- }else {
|
|
|
- nextFlag = false;
|
|
|
+ try {
|
|
|
+ List<Alert> alerts = AlertAndSiteApi.alertPage(null, null, page, size, token);
|
|
|
+ if (null != startTime && null != endTime){
|
|
|
+ alerts = alerts.stream().filter(alert -> DateUtils.isEffectiveDate(alert.getDcsj(), startTime, endTime)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ count+=alerts.size();
|
|
|
+ if (CollectionUtils.isNotEmpty(alerts)){
|
|
|
+ alerts.forEach(alert -> alertService.saveOrUpdate(alert));
|
|
|
+ page++;
|
|
|
+ }else {
|
|
|
+ nextFlag = false;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("alertJob----异常"+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
log.info("alertJob----完成,获取警情记录:"+ count);
|