296 lines
11 KiB
Java
296 lines
11 KiB
Java
package com.adc.da.scheduled;
|
|
|
|
import com.adc.da.scheduled.dao.SarStandardInfoDao;
|
|
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;
|
|
|
|
import com.adc.da.slrs.sarStandWarning.entity.EarlyWarningEO;
|
|
import com.adc.da.slrs.sarStandWarning.entity.WarningDate;
|
|
import com.adc.da.slrs.sarStandWarning.service.IWarningDateService;
|
|
import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao;
|
|
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
|
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;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
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;
|
|
|
|
|
|
@EnableScheduling
|
|
@Component
|
|
@Slf4j
|
|
public class ScheduledJob {
|
|
|
|
/**
|
|
* 根据配置文件设置是否开启定时器
|
|
*/
|
|
|
|
@Value("${isNotScheduled}")
|
|
private boolean isNotScheduled; //是否开启定时器
|
|
|
|
|
|
@Autowired
|
|
private SarStandardInfoDao sarStandardInfoDao; //标准信息表
|
|
|
|
@Autowired
|
|
private SarStandardsInfoDao sarStandardsInfoDao;//标准信息表
|
|
|
|
@Autowired
|
|
private SarStandardWarningDao sarStandardWarningDao;//预警表
|
|
|
|
@Autowired
|
|
private SarStandardItemDao sarStandardItemDao; //分解单表
|
|
|
|
@Autowired
|
|
private SarStandAttrInfoDao sarStandAttrInfoDao; //属性字段表
|
|
|
|
@Autowired
|
|
private IWarningDateService iWarningDateService;// 预警日期
|
|
|
|
// @PostConstruct //程序启动时执行一次
|
|
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
|
// @Scheduled(cron="*/5 * * * * ?")
|
|
// @Scheduled(fixedDelay = 120000)
|
|
@Async
|
|
public void warningSchedulingTasks() {
|
|
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
|
|
|
|
/**
|
|
* 1.查询标准属性字段表(sar_stand_attr_info) XCXSSEQ ZCCSSRQ ZRGCS
|
|
* 联接标准信息表sar_standards_info表的STAND_NAME
|
|
* 2.查询分解单(条款表)
|
|
* 3.查询预警表
|
|
* 4.去掉预警表中已存在的的数据
|
|
* 5.插入预警表
|
|
*/
|
|
|
|
/**
|
|
mark:标识预警的种类
|
|
3:新车标准预警
|
|
4:在产车标准预警
|
|
1:新车条款预警
|
|
2:在产车条款预警
|
|
|
|
2021/12/1 日需求修改
|
|
分为标准预警与条款预警
|
|
mark:标识预警的种类 stand 标准 item 条款
|
|
*/
|
|
|
|
|
|
// Runnable runnable = () -> {
|
|
// try {
|
|
// Thread.sleep(60000);
|
|
// } catch (InterruptedException e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
// };
|
|
//
|
|
// runnable.run();
|
|
//删除不在预警范围的标准
|
|
int remove = sarStandardWarningDao.autoCancelWarning();
|
|
|
|
logger.info("==========================================================================");
|
|
logger.info("取消"+remove+"条预警");
|
|
logger.info("开始执行预警!!!");
|
|
logger.info("==========================================================================");
|
|
//预警期限(当前日期至3个月后)
|
|
TermDTO term = new TermDTO();
|
|
//查询符合预警期限的标准 多个
|
|
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term);
|
|
|
|
ArrayList<WarningDate> data = new ArrayList<>();
|
|
warningDateList.forEach(item->{
|
|
|
|
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(data);
|
|
//联接标准的日期子表 和分解单表 查询符合预警期限的标准和分解项
|
|
List<EarlyWarningEO> warningList = sarStandardWarningDao.getWarningId(term);
|
|
|
|
warningList.forEach(item->{
|
|
item.setId(UUIDUtils.randomUUID20());
|
|
});
|
|
//持久化至预警表 忽略标准id和标志位都一样的数据
|
|
if (warningList.size()!=0){
|
|
//此表的STAND_ID和MARK字段以及ITEMS_ID字段需个建立唯一性约束
|
|
int count = sarStandardWarningDao.ignoreInsert(warningList);
|
|
logger.info("==================================预警结束======================================");
|
|
logger.info("==================================预警结束======================================");
|
|
logger.info("已预警"+ count+"条标准或条款!!");
|
|
logger.info("==================================预警结束======================================");
|
|
logger.info("==================================预警结束======================================");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 定时更新文本状态
|
|
*/
|
|
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
|
// @Scheduled(cron="*/5 * * * * ?")
|
|
@Async
|
|
public void TextStatusSchedulingTasks() {
|
|
QueryWrapper<SarStandardsInfo> wrapper = new QueryWrapper<>();
|
|
|
|
TermDTO data = new TermDTO(LocalDate.now(), LocalDate.now());
|
|
|
|
/**
|
|
*实施日期是当前系统时间的标准文本状态变为'现行有效'
|
|
*/
|
|
QueryWrapper<SarStandAttrInfo> columnsAndCondition = new QueryWrapper<>();
|
|
columnsAndCondition.select("STAND_ID").like("SSRQ",LocalDate.now());
|
|
List<Map<String, Object>> effectiveList=sarStandAttrInfoDao.selectMaps(columnsAndCondition);
|
|
// List<ScheduledDTO> effectiveList = sarStandardInfoDao.selectWithinTerm(data, "SSRQ");
|
|
|
|
effectiveList.forEach(item->{
|
|
try {
|
|
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
|
|
sarStandardsInfo.setId(item.get("STAND_ID").toString());
|
|
sarStandardsInfo.setTextStatus("vsaga7nwub");
|
|
|
|
sarStandardsInfoDao.updateById(sarStandardsInfo);
|
|
// sarStandardInfoDao.updateStandardInfo(item.getStandId(),"vsaga7nwub");
|
|
|
|
}catch (Exception e){
|
|
System.out.println("标准id为=="+item.get("STAND_ID").toString()+"==文本状态更新失败");
|
|
}
|
|
});
|
|
|
|
|
|
/**
|
|
* 被多个标准代替的标准变为“被代替”,只被一个标准代替的自动变为“废止”
|
|
*/
|
|
QueryWrapper<SarStandAttrInfo> columnForDTBJH = new QueryWrapper<>();
|
|
|
|
columnForDTBJH.select("DTBJH");
|
|
//查询代替标准字段得到一个 被代替了的标准的id的键值对列表
|
|
List<Map<String, Object>> replaceStandIdMaps = sarStandAttrInfoDao.selectMaps(columnForDTBJH);
|
|
HashMap<String, Integer> replaceIdCountMap = new HashMap<>();
|
|
// 格式为 T/CSAE 175-2021
|
|
Pattern pattern = Pattern.compile("^\\S*\\s\\S*[\\u2014\\u002d\\s]\\d{4}$");
|
|
replaceStandIdMaps.forEach(item->{
|
|
if (item!=null){
|
|
//此标准代替的标准的标准号的数组
|
|
String DTBJHStr = item.get("DTBJH").toString();
|
|
|
|
//数据格式: (GB 123-2000,GB 4233434-2021,GB 423423423-2021)
|
|
if (!DTBJHStr.equals("")) {
|
|
String[] DTBJHArray = DTBJHStr.split(",");
|
|
for (String DTBJH : DTBJHArray) {
|
|
|
|
if (!pattern.matcher(DTBJH).matches()){
|
|
continue;
|
|
}
|
|
|
|
String[] split = DTBJH.split("[\\u2014\\u002d\\s]");//以空格或'-'或'—'分割
|
|
String sort = split[0];
|
|
String number = split[1];
|
|
String year = split[2];
|
|
|
|
QueryWrapper<SarStandardsInfo> infoWrapper = new QueryWrapper<>();
|
|
infoWrapper.select("ID")
|
|
.eq("STAND_SORT", sort)
|
|
.eq("STAND_NUMBER", number)
|
|
.eq("STAND_YEAR", year);
|
|
|
|
|
|
List<Map<String, Object>> idMaps = sarStandardsInfoDao.selectMaps(infoWrapper);
|
|
if (idMaps.size() > 0) {
|
|
String standId = idMaps.get(0).get("ID").toString();
|
|
//如果代替标准id已存在则映射为2不存在则添加并映射为1
|
|
if (replaceIdCountMap.containsKey(standId)) {
|
|
replaceIdCountMap.replace(standId, 2);
|
|
} else {
|
|
replaceIdCountMap.put(standId, 1);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//一个被代替标准号时,文本状态更新为废止状态,两个及以上时更新为被代替状态
|
|
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
|
|
for (String key : replaceIdCountMap.keySet()) {
|
|
switch (replaceIdCountMap.get(key)){
|
|
case 1 :
|
|
sarStandardsInfo.setTextStatus("chblaarg77");//废止状态
|
|
sarStandardsInfo.setId(key);
|
|
break;
|
|
default :
|
|
sarStandardsInfo.setTextStatus("qke0ckro2p");//被代替状态
|
|
sarStandardsInfo.setId(key);
|
|
break;
|
|
}
|
|
|
|
|
|
try {
|
|
sarStandardsInfoDao.updateById(sarStandardsInfo);
|
|
}catch (Exception e){
|
|
System.out.println("代替标准状态更新:id为"+key+"文本状态更新失败");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|