473 lines
20 KiB
Java
473 lines
20 KiB
Java
package com.adc.da.scheduled;
|
|
|
|
import com.adc.da.mq.CreateStandardMQService;
|
|
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.processModel.utils.TrainFormDate;
|
|
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.DSarStandardDTO;
|
|
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
|
import com.adc.da.slrs.sarUpdLog.service.ISarUpdLogService;
|
|
import com.adc.da.sys.service.IDicTypeEOService;
|
|
import com.adc.da.util.UUIDUtils;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import net.sf.json.JSONObject;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
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 java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@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;// 预警日期
|
|
|
|
@Autowired
|
|
CreateStandardMQService createStandardMQService;
|
|
|
|
@Autowired
|
|
private IDicTypeEOService dicTypeEOService;
|
|
|
|
// @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();
|
|
|
|
logger.info("=========================================================================================================");
|
|
logger.info("=========================================================================================================");
|
|
|
|
logger.info("开始执行预警!!!");
|
|
logger.info("========================================================================================================");
|
|
logger.info("========================================================================================================");
|
|
//删除不在预警范围的标准
|
|
int remove = sarStandardWarningDao.autoCancelWarning();
|
|
log.info("开始修整"+new Date()+"!");
|
|
try {
|
|
Thread.sleep(20000);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
log.info("结束修整"+new Date()+"!");
|
|
logger.info("取消" + remove + "条预警");
|
|
|
|
//预警期限(当前日期至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 = term.getTermStr();
|
|
|
|
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("==================================预警结束======================================");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Autowired
|
|
private ISarUpdLogService sarUpdLogEOService;
|
|
|
|
|
|
/**
|
|
* 定时更新文本状态
|
|
*/
|
|
// @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
|
// @Scheduled(cron="*/5 * * * * ?")
|
|
@Async
|
|
public void TextStatusSchedulingTasks() {
|
|
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
|
|
|
|
|
|
logger.info("=========================================================================================================");
|
|
logger.info("=========================================================================================================");
|
|
logger.info("开始更新文本状态!!!");
|
|
logger.info("=========================================================================================================");
|
|
logger.info("=========================================================================================================");
|
|
// 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")
|
|
.eq("VALID_FLAG", "0")
|
|
.ne("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<String> standId = sarStandardsInfoDao.selectIdFormDTBZH(DTBJH);
|
|
if (standId.size() > 0) {
|
|
boolean b = replaceIdCountMap.containsKey(standId.get(0));
|
|
//如果代替标准id已存在则映射为2不存在则添加并映射为1
|
|
if (b) {
|
|
replaceIdCountMap.replace(standId.get(0), 2);
|
|
} else {
|
|
replaceIdCountMap.put(standId.get(0), 1);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
|
|
//一个被代替标准号时,文本状态更新为废止状态,两个及以上时更新为被代替状态
|
|
for (String key : replaceIdCountMap.keySet()) {
|
|
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
|
|
String reasonMsg = "";
|
|
switch (replaceIdCountMap.get(key)) {
|
|
case 1:
|
|
//废止状态
|
|
sarStandardsInfo.setTextStatus("chblaarg77");
|
|
sarStandardsInfo.setId(key);
|
|
reasonMsg = "该标准被一个标准代替";
|
|
break;
|
|
case 2:
|
|
//被代替状态
|
|
sarStandardsInfo.setTextStatus("qke0ckro2p");
|
|
sarStandardsInfo.setId(key);
|
|
reasonMsg = "该标准被一个以上标准代替";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
|
|
try {
|
|
//更新日志
|
|
SarStandardsInfo beforeSarStandardsInfoEO = sarStandardsInfoDao.selectById(sarStandardsInfo.getId());
|
|
sarStandardsInfo.setStandType(beforeSarStandardsInfoEO.getStandType());
|
|
sarStandardsInfo.setStandSort(beforeSarStandardsInfoEO.getStandSort());
|
|
sarStandardsInfo.setStandNumber(beforeSarStandardsInfoEO.getStandNumber());
|
|
sarStandardsInfo.setStandYear(beforeSarStandardsInfoEO.getStandYear());
|
|
sarStandardsInfo.setStandName(beforeSarStandardsInfoEO.getStandName());
|
|
saveUpdateLog(sarStandardsInfo, beforeSarStandardsInfoEO, reasonMsg);
|
|
//更新日志
|
|
sarStandardsInfoDao.updateById(sarStandardsInfo);
|
|
} catch (Exception e) {
|
|
System.out.println("代替标准状态更新:id为" + key + "文本状态更新失败");
|
|
}
|
|
}
|
|
logger.info("==================================更新文本状态结束======================================");
|
|
logger.info("==================================更新文本状态结束======================================");
|
|
|
|
}
|
|
|
|
|
|
public void saveUpdateLog(SarStandardsInfo sarStandardsInfoEO, SarStandardsInfo beforeSarStandardsInfo, String reasonMsg) throws Exception {
|
|
Map<String, Object> newMap = new HashMap<>();
|
|
Map<String, Object> oldMap = new HashMap<>();
|
|
String attrStr = sarStandardsInfoEO.getSarStandAttrEOStr();
|
|
if (StringUtils.isNotBlank(attrStr)) {
|
|
newMap = JSONObject.fromObject(attrStr);
|
|
}
|
|
newMap.put("textStatus", sarStandardsInfoEO.getTextStatus());
|
|
oldMap.put("textStatus", beforeSarStandardsInfo.getTextStatus());
|
|
// 增加关联事件
|
|
String number = sarStandardsInfoEO.getStandSort() + " " + sarStandardsInfoEO.getStandNumber();
|
|
if (StringUtils.isNotBlank(sarStandardsInfoEO.getStandYear())) {
|
|
number += "-" + sarStandardsInfoEO.getStandYear();
|
|
}
|
|
String content = "==定时任务执行修改==:" + number + " 《" + sarStandardsInfoEO.getStandName() + "》" + reasonMsg;
|
|
sarUpdLogEOService.createUpdateLog(sarStandardsInfoEO.getStandType() + "_STAND", sarStandardsInfoEO.getId(), oldMap, newMap, content);
|
|
}
|
|
|
|
|
|
// @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
|
// @Scheduled(cron = "*/30 * * * * ?")
|
|
@Async
|
|
public void TextStatusUpdateStandard() {
|
|
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
|
|
logger.info("=======================================开始更新文本状态======================================");
|
|
//第一步 查询满足条件的数据 第一步只能查询 需要的标准id和日期
|
|
//查询出两组数据
|
|
Map<String, String> map = new HashMap<>();
|
|
List<String> types = new ArrayList<>();
|
|
types.add("WBZTCLASS");
|
|
Map<String, Object> dicTypeEO = dicTypeEOService.getDicTypeListCodeByType(types);
|
|
List<Map<String, String>> arr = (List<Map<String, String>>) dicTypeEO.get("WBZTCLASS");
|
|
arr.forEach(stringStringMap -> {
|
|
stringStringMap.keySet().forEach(s -> {
|
|
map.put(stringStringMap.get("label"), stringStringMap.get("value"));
|
|
});
|
|
});
|
|
//只针对国内标准 INLAND
|
|
|
|
// 查询国标 实施日期 晚于现在
|
|
// 标准状态属于发布
|
|
// 标准状态改为即将实施
|
|
List<DSarStandardDTO> changeJJSS = new ArrayList<>();
|
|
List<String> strings = new ArrayList<>();
|
|
strings.add(map.get("发布"));
|
|
List<DSarStandardDTO> sarStandardsInfos = sarStandardsInfoDao.dealWithDS("INLAND", strings);
|
|
//判定时间
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
if (null != sarStandardsInfos && sarStandardsInfos.size() > 0) {
|
|
for (DSarStandardDTO s : sarStandardsInfos) {
|
|
if (null != s.getSSRQ()) {
|
|
if (s.getSSRQ().contains(",")) {
|
|
//多个日期拆分 一个满足就都满足
|
|
if (findFirstTime(s.getSSRQ()).compareTo(new Date()) >= 0 && !changeJJSS.contains(s)) {
|
|
changeJJSS.add(s);
|
|
}
|
|
} else {
|
|
Date date = null;
|
|
try {
|
|
date = dateFormat.parse(TrainFormDate.dealWithTimeZoneyyyy(s.getSSRQ(), "yyyy-MM-dd"));
|
|
} catch (ParseException e) {
|
|
e.printStackTrace();
|
|
}
|
|
logger.info("时间为:" + date);
|
|
//与现在时间进行比较
|
|
if (date.compareTo(new Date()) >= 0 && !changeJJSS.contains(s)) {
|
|
changeJJSS.add(s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 标桩状态 属于即将实施 或 发布
|
|
// 实施日期 在今天之前
|
|
// 标准状态 改为现行有效
|
|
List<DSarStandardDTO> changeXXYX = new ArrayList<>();
|
|
List<String> strings2 = new ArrayList<>();
|
|
strings2.add(map.get("即将实施"));
|
|
strings2.add(map.get("发布"));
|
|
List<DSarStandardDTO> sarStandardsInfos1 = sarStandardsInfoDao.dealWithDS("INLAND", strings2);
|
|
if (null != sarStandardsInfos1 && sarStandardsInfos1.size() > 0) {
|
|
for (DSarStandardDTO s : sarStandardsInfos1) {
|
|
if (null != s.getSSRQ()) {
|
|
if (s.getSSRQ().contains(",")) {
|
|
//多个日期拆分 一个满足就都满足
|
|
if (findFirstTime(s.getSSRQ()).compareTo(new Date()) < 0 && !changeXXYX.contains(s)) {
|
|
changeXXYX.add(s);
|
|
}
|
|
} else {
|
|
Date date = null;
|
|
try {
|
|
date = dateFormat.parse(TrainFormDate.dealWithTimeZoneyyyy(s.getSSRQ(), "yyyy-MM-dd"));
|
|
} catch (ParseException e) {
|
|
e.printStackTrace();
|
|
}
|
|
logger.info("时间为:" + date);
|
|
//与现在时间进行比较
|
|
if (date.compareTo(new Date()) < 0 && !changeXXYX.contains(s)) {
|
|
changeXXYX.add(s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
logger.info("改为即将实施的有" + changeJJSS.size() + "条");
|
|
logger.info("改为现行有效的有" + changeXXYX.size() + "条");
|
|
logger.info("=============================");
|
|
createStandardMQService.sendMQ(changeJJSS,changeXXYX);
|
|
}
|
|
}
|
|
|
|
private Date findFirstTime(String ssrq) {
|
|
String[] as = ssrq.split(",");
|
|
List<Date> dates = new ArrayList<>();
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
for (String s : as) {
|
|
Date date = null;
|
|
try {
|
|
date = dateFormat.parse(TrainFormDate.dealWithTimeZoneyyyy(s, "yyyy-MM-dd"));
|
|
} catch (ParseException e) {
|
|
e.printStackTrace();
|
|
}
|
|
dates.add(date);
|
|
}
|
|
dates.sort(Comparator.comparing(date -> date));
|
|
return dates.get(0);
|
|
}
|
|
|
|
|
|
}
|