预警性能 不使用转列改为使用正则
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.dao.SarStandardWarningDao;
|
||||||
import com.adc.da.scheduled.entity.TermDTO;
|
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.dao.SarStandAttrInfoDao;
|
||||||
import com.adc.da.slrs.sarStandAttrInfo.entity.SarStandAttrInfo;
|
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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@@ -28,8 +31,10 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -68,8 +73,9 @@ public class ScheduledJob {
|
|||||||
// @PostConstruct //程序启动时执行一次
|
// @PostConstruct //程序启动时执行一次
|
||||||
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
||||||
// @Scheduled(cron="*/5 * * * * ?")
|
// @Scheduled(cron="*/5 * * * * ?")
|
||||||
|
// @Scheduled(fixedDelay = 120000)
|
||||||
@Async
|
@Async
|
||||||
public void WarningSchedulingTasks() {
|
public void warningSchedulingTasks() {
|
||||||
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
|
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,6 +99,16 @@ public class ScheduledJob {
|
|||||||
mark:标识预警的种类 stand 标准 item 条款
|
mark:标识预警的种类 stand 标准 item 条款
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Runnable runnable = () -> {
|
||||||
|
// try {
|
||||||
|
// Thread.sleep(60000);
|
||||||
|
// } catch (InterruptedException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// runnable.run();
|
||||||
//删除不在预警范围的标准
|
//删除不在预警范围的标准
|
||||||
int remove = sarStandardWarningDao.autoCancelWarning();
|
int remove = sarStandardWarningDao.autoCancelWarning();
|
||||||
|
|
||||||
@@ -100,17 +116,39 @@ public class ScheduledJob {
|
|||||||
logger.info("取消"+remove+"条预警");
|
logger.info("取消"+remove+"条预警");
|
||||||
logger.info("开始执行预警!!!");
|
logger.info("开始执行预警!!!");
|
||||||
logger.info("==========================================================================");
|
logger.info("==========================================================================");
|
||||||
|
//预警期限(当前日期至3个月后)
|
||||||
|
TermDTO term = new TermDTO();
|
||||||
|
//查询符合预警期限的标准 多个
|
||||||
|
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term);
|
||||||
|
|
||||||
TermDTO term = new TermDTO(); //预警期限(当前日期至3个月后)
|
ArrayList<WarningDate> data = new ArrayList<>();
|
||||||
|
|
||||||
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term); //查询符合预警期限的标准 多个
|
|
||||||
|
|
||||||
warningDateList.forEach(item->{
|
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->{
|
warningList.forEach(item->{
|
||||||
item.setId(UUIDUtils.randomUUID20());
|
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 com.sun.org.apache.bcel.internal.generic.NEW;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
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.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@@ -26,11 +30,15 @@ public class TermDTO {
|
|||||||
|
|
||||||
private String endDate;
|
private String endDate;
|
||||||
|
|
||||||
// private String str;
|
private String termStr;
|
||||||
|
|
||||||
|
private List<String> termList;
|
||||||
|
|
||||||
public TermDTO() {
|
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);
|
convertToStr(starDate,endDate);
|
||||||
}
|
}
|
||||||
@@ -49,7 +57,9 @@ public class TermDTO {
|
|||||||
int compareEnd = dateString.compareTo(startDate);
|
int compareEnd = dateString.compareTo(startDate);
|
||||||
if (compareStart >= 0 && compareEnd <=0) {
|
if (compareStart >= 0 && compareEnd <=0) {
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +71,7 @@ public class TermDTO {
|
|||||||
* @param startDate
|
* @param startDate
|
||||||
* @param endDate
|
* @param endDate
|
||||||
*/
|
*/
|
||||||
public void convertToStr(LocalDate startDate,LocalDate endDate){
|
private void convertToStr(LocalDate startDate,LocalDate endDate){
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用DateTimeFormatter线程安全,但不晓得怎么支持Date类型转换为字符串 ¯\_(ツ)_/¯
|
* 使用DateTimeFormatter线程安全,但不晓得怎么支持Date类型转换为字符串 ¯\_(ツ)_/¯
|
||||||
@@ -72,5 +82,38 @@ public class TermDTO {
|
|||||||
|
|
||||||
this.startDate =formatter.format(startDate);
|
this.startDate =formatter.format(startDate);
|
||||||
this.endDate=formatter.format(endDate);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class WarningDate {
|
|||||||
@TableField("law_id")
|
@TableField("law_id")
|
||||||
private String lawId;
|
private String lawId;
|
||||||
|
|
||||||
@TableField("itemId")
|
@TableField("item_id")
|
||||||
private String itemId;
|
private String itemId;
|
||||||
|
|
||||||
@TableField("SSRQ")
|
@TableField("SSRQ")
|
||||||
|
|||||||
+1
-1
@@ -244,8 +244,8 @@
|
|||||||
FROM
|
FROM
|
||||||
sar_stand_warning AS warning
|
sar_stand_warning AS warning
|
||||||
LEFT JOIN sar_standards_info AS sarInfo ON sarInfo.id = warning.STAND_ID
|
LEFT JOIN sar_standards_info AS sarInfo ON sarInfo.id = warning.STAND_ID
|
||||||
LEFT JOIN sar_stand_items AS items ON items.STAND_ID = warning.STAND_ID
|
|
||||||
LEFT JOIN sar_stand_attr_info AS attr ON attr.STAND_ID = warning.STAND_ID
|
LEFT JOIN sar_stand_attr_info AS attr ON attr.STAND_ID = warning.STAND_ID
|
||||||
|
LEFT JOIN sar_stand_items AS items ON items.ID = warning.ITEMS_ID
|
||||||
<where>
|
<where>
|
||||||
POWER = '1'
|
POWER = '1'
|
||||||
AND (MARK = 'item')
|
AND (MARK = 'item')
|
||||||
|
|||||||
+26
-39
@@ -11,7 +11,7 @@
|
|||||||
(
|
(
|
||||||
#{item.id}
|
#{item.id}
|
||||||
,#{item.standId}
|
,#{item.standId}
|
||||||
,#{item.itemsId}
|
,#{item.itemId}
|
||||||
,#{item.policyId}
|
,#{item.policyId}
|
||||||
,#{item.mark}
|
,#{item.mark}
|
||||||
,#{item.power}
|
,#{item.power}
|
||||||
@@ -29,22 +29,17 @@
|
|||||||
FROM
|
FROM
|
||||||
warning_date
|
warning_date
|
||||||
WHERE
|
WHERE
|
||||||
DATE_FORMAT(SSRQ, '%Y-%m-%d') < DATE_FORMAT(now(), '%Y-%m-%d')
|
DATE_FORMAT(SSRQ, '%Y-%m-%d') > DATE_FORMAT(now(), '%Y-%m-%d')
|
||||||
UNION
|
|
||||||
|
)
|
||||||
|
OR
|
||||||
|
ITEMS_ID IN (
|
||||||
SELECT
|
SELECT
|
||||||
ID
|
ITEM_ID
|
||||||
FROM
|
FROM
|
||||||
sar_standards_info
|
warning_date
|
||||||
WHERE
|
WHERE
|
||||||
DATE_FORMAT(PUT_TIME, '%Y-%m-%d') < DATE_FORMAT(now(), '%Y-%m-%d')
|
DATE_FORMAT(SSRQ, '%Y-%m-%d') > DATE_FORMAT(now(), '%Y-%m-%d')
|
||||||
UNION
|
|
||||||
SELECT
|
|
||||||
STAND_ID
|
|
||||||
FROM
|
|
||||||
sar_stand_items
|
|
||||||
WHERE
|
|
||||||
DATE_FORMAT(XCXSSRQ, '%Y-%m-%d') < DATE_FORMAT(now(), '%Y-%m-%d')
|
|
||||||
OR DATE_FORMAT(ZCCSSRQ, '%Y-%m-%d') < DATE_FORMAT(now(), '%Y-%m-%d')
|
|
||||||
)
|
)
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
@@ -85,55 +80,47 @@
|
|||||||
<select id="getWarningDate" resultType="com.adc.da.slrs.sarStandWarning.entity.WarningDate">
|
<select id="getWarningDate" resultType="com.adc.da.slrs.sarStandWarning.entity.WarningDate">
|
||||||
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
lawId,
|
|
||||||
itemId,
|
|
||||||
timeName,
|
|
||||||
DATE_FORMAT(SSRQ, '%Y-%m-%d') AS SSRQ
|
|
||||||
FROM
|
|
||||||
(
|
|
||||||
select attr.STAND_ID as lawId,'-1' as itemId,'SSRQ' as timeName,
|
select attr.STAND_ID as lawId,'-1' as itemId,'SSRQ' as timeName,
|
||||||
substring_index(substring_index(attr.SSRQ,',',b.help_topic_id+1),',',-1) SSRQ
|
SSRQ as SSRQ
|
||||||
from sar_stand_attr_info attr
|
from sar_stand_attr_info attr
|
||||||
join mysql.help_topic b
|
WHERE
|
||||||
on b.help_topic_id > (length(attr.SSRQ) - length(replace(attr.SSRQ,',',''))+1)
|
SSRQ REGEXP #{termStr}
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
select attr.STAND_ID as lawId,'-1' as itemId,'XCXSSRQ' as timeName,
|
select attr.STAND_ID as lawId,'-1' as itemId,'XCXSSRQ' as timeName,
|
||||||
substring_index(substring_index(attr.SSRQ,',',b.help_topic_id+1),',',-1) SSRQ
|
XCXSSRQ as SSRQ
|
||||||
from sar_stand_attr_info attr
|
from sar_stand_attr_info attr
|
||||||
join mysql.help_topic b
|
WHERE
|
||||||
on b.help_topic_id > (length(attr.XCXSSRQ) - length(replace(attr.XCXSSRQ,',',''))+1)
|
XCXSSRQ REGEXP #{termStr}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
select attr.STAND_ID as lawId,'-1' as itemId,'ZCCSSRQ' as timeName,
|
select attr.STAND_ID as lawId,'-1' as itemId,'ZCCSSRQ' as timeName,
|
||||||
substring_index(substring_index(attr.ZCCSSRQ,',',b.help_topic_id+1),',',-1) SSRQ
|
ZCCSSRQ as SSRQ
|
||||||
from sar_stand_attr_info attr
|
from sar_stand_attr_info attr
|
||||||
join mysql.help_topic b
|
WHERE
|
||||||
on b.help_topic_id > (length(attr.SSRQ) - length(replace(attr.ZCCSSRQ,',',''))+1)
|
ZCCSSRQ REGEXP #{termStr}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UNION All
|
UNION All
|
||||||
select item.STAND_ID as lawId,item.ID as itemId,'ZCCSSRQ' as timeName,
|
select item.STAND_ID as lawId,item.ID as itemId,'ZCCSSRQ' as timeName,
|
||||||
substring_index(substring_index(item.ZCCSSRQ,',',b.help_topic_id+1),',',-1) SSRQ
|
ZCCSSRQ as SSRQ
|
||||||
from sar_stand_items item
|
from sar_stand_items item
|
||||||
join mysql.help_topic b
|
WHERE
|
||||||
on b.help_topic_id > (length(item.ZCCSSRQ) - length(replace(item.ZCCSSRQ,',',''))+1)
|
ZCCSSRQ REGEXP #{termStr}
|
||||||
|
|
||||||
UNION All
|
UNION All
|
||||||
select item.STAND_ID as lawId,item.ID as itemId,'XCXSSRQ' as timeName,
|
select item.STAND_ID as lawId,item.ID as itemId,'XCXSSRQ' as timeName,
|
||||||
substring_index(substring_index(item.XCXSSRQ,',',b.help_topic_id+1),',',-1) SSRQ
|
XCXSSRQ as SSRQ
|
||||||
from sar_stand_items item
|
from sar_stand_items item
|
||||||
join mysql.help_topic b
|
WHERE
|
||||||
on b.help_topic_id > (length(item.XCXSSRQ) - length(replace(item.XCXSSRQ,',',''))+1)
|
XCXSSRQ REGEXP #{termStr}
|
||||||
|
|
||||||
|
|
||||||
) as T
|
|
||||||
WHERE
|
|
||||||
DATE_FORMAT(T.SSRQ,'%Y-%m-%d') BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m-%d') AND DATE_FORMAT(#{endDate}, '%Y-%m-%d')
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user