预警性能 不使用转列改为使用正则
This commit is contained in:
@@ -5,6 +5,7 @@ import com.adc.da.scheduled.dao.SarStandardItemDao;
|
||||
import com.adc.da.scheduled.dao.SarStandardWarningDao;
|
||||
import com.adc.da.scheduled.entity.TermDTO;
|
||||
|
||||
import com.adc.da.slrs.ActivityDatas.entity.DataList;
|
||||
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
|
||||
import com.adc.da.slrs.sarStandAttrInfo.entity.SarStandAttrInfo;
|
||||
|
||||
@@ -17,8 +18,10 @@ import com.adc.da.util.UUIDUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -28,8 +31,10 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -68,8 +73,9 @@ public class ScheduledJob {
|
||||
// @PostConstruct //程序启动时执行一次
|
||||
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
||||
// @Scheduled(cron="*/5 * * * * ?")
|
||||
// @Scheduled(fixedDelay = 120000)
|
||||
@Async
|
||||
public void WarningSchedulingTasks() {
|
||||
public void warningSchedulingTasks() {
|
||||
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
|
||||
|
||||
/**
|
||||
@@ -93,6 +99,16 @@ public class ScheduledJob {
|
||||
mark:标识预警的种类 stand 标准 item 条款
|
||||
*/
|
||||
|
||||
|
||||
// Runnable runnable = () -> {
|
||||
// try {
|
||||
// Thread.sleep(60000);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// runnable.run();
|
||||
//删除不在预警范围的标准
|
||||
int remove = sarStandardWarningDao.autoCancelWarning();
|
||||
|
||||
@@ -100,17 +116,39 @@ public class ScheduledJob {
|
||||
logger.info("取消"+remove+"条预警");
|
||||
logger.info("开始执行预警!!!");
|
||||
logger.info("==========================================================================");
|
||||
//预警期限(当前日期至3个月后)
|
||||
TermDTO term = new TermDTO();
|
||||
//查询符合预警期限的标准 多个
|
||||
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term);
|
||||
|
||||
TermDTO term = new TermDTO(); //预警期限(当前日期至3个月后)
|
||||
|
||||
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term); //查询符合预警期限的标准 多个
|
||||
|
||||
ArrayList<WarningDate> data = new ArrayList<>();
|
||||
warningDateList.forEach(item->{
|
||||
item.setId(UUIDUtils.randomUUID20());
|
||||
|
||||
for (String s : item.getSSRQ().split(",")) {
|
||||
|
||||
String pattern = "^\\d{4}-\\d{1,2}-\\d{1,2}";
|
||||
|
||||
Pattern r = Pattern.compile(pattern);
|
||||
Matcher m = r.matcher(s);
|
||||
//判断是否是日期格式
|
||||
if (m.matches()) {
|
||||
WarningDate warningDate = new WarningDate();
|
||||
BeanUtils.copyProperties(item, warningDate);
|
||||
|
||||
warningDate.setId(UUIDUtils.randomUUID20());
|
||||
warningDate.setSSRQ(s);
|
||||
data.add(warningDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
iWarningDateService.remove(null); //清空标准的日期子表
|
||||
iWarningDateService.saveBatch(warningDateList); // 保存进入标准的日期子表 保存标准的实施日期 新车型实施日期 在产车实施日期 多个
|
||||
List<EarlyWarningEO> warningList = sarStandardWarningDao.getWarningId(term); //联接标准的日期子表 和分解单表 查询符合预警期限的标准和分解项
|
||||
|
||||
|
||||
//清空标准的日期子表
|
||||
iWarningDateService.remove(null);
|
||||
// 保存进入标准的日期子表 保存标准的实施日期 新车型实施日期 在产车实施日期 多个
|
||||
iWarningDateService.saveBatch(data);
|
||||
//联接标准的日期子表 和分解单表 查询符合预警期限的标准和分解项
|
||||
List<EarlyWarningEO> warningList = sarStandardWarningDao.getWarningId(term);
|
||||
|
||||
warningList.forEach(item->{
|
||||
item.setId(UUIDUtils.randomUUID20());
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.adc.da.scheduled.controller;
|
||||
|
||||
|
||||
import com.adc.da.scheduled.ScheduledJob;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/${restPath}/scheduled")
|
||||
public class Controller {
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
ScheduledJob scheduledJob;
|
||||
|
||||
@PostMapping
|
||||
public void run(){
|
||||
scheduledJob.warningSchedulingTasks();
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,19 @@ import com.alibaba.druid.sql.visitor.functions.Char;
|
||||
import com.sun.org.apache.bcel.internal.generic.NEW;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@@ -26,11 +30,15 @@ public class TermDTO {
|
||||
|
||||
private String endDate;
|
||||
|
||||
// private String str;
|
||||
private String termStr;
|
||||
|
||||
private List<String> termList;
|
||||
|
||||
public TermDTO() {
|
||||
LocalDate starDate = LocalDate.now();//系统当前日期
|
||||
LocalDate endDate = LocalDate.now().plusMonths(3);//系统当前日期3个月后
|
||||
//系统当前日期
|
||||
LocalDate starDate = LocalDate.now();
|
||||
//系统当前日期3个月后
|
||||
LocalDate endDate = LocalDate.now().plusMonths(3);
|
||||
|
||||
convertToStr(starDate,endDate);
|
||||
}
|
||||
@@ -49,7 +57,9 @@ public class TermDTO {
|
||||
int compareEnd = dateString.compareTo(startDate);
|
||||
if (compareStart >= 0 && compareEnd <=0) {
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +71,7 @@ public class TermDTO {
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
*/
|
||||
public void convertToStr(LocalDate startDate,LocalDate endDate){
|
||||
private void convertToStr(LocalDate startDate,LocalDate endDate){
|
||||
|
||||
/**
|
||||
* 使用DateTimeFormatter线程安全,但不晓得怎么支持Date类型转换为字符串 ¯\_(ツ)_/¯
|
||||
@@ -72,5 +82,38 @@ public class TermDTO {
|
||||
|
||||
this.startDate =formatter.format(startDate);
|
||||
this.endDate=formatter.format(endDate);
|
||||
|
||||
this.termList= forDate();
|
||||
this.termStr= StringUtils.join(this.termList,"|");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<String> forDate() {
|
||||
// 日期格式化
|
||||
LinkedList<String> termList = new LinkedList<>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
// 起始日期
|
||||
Date d1 = sdf.parse(this.startDate);
|
||||
// 结束日期
|
||||
Date d2 = sdf.parse(this.endDate);
|
||||
Date tmp = d1;
|
||||
Calendar dd = Calendar.getInstance();
|
||||
dd.setTime(d1);
|
||||
// 循环之间的每一天
|
||||
while (tmp.getTime() < d2.getTime()) {
|
||||
tmp = dd.getTime();
|
||||
termList.add(sdf.format(tmp));
|
||||
// 天数加上1
|
||||
dd.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return termList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user