Merge branch 'develop_migration' into 'develop_master'

Develop migration

See merge request LiuChao/foton-slrs-system-rest!506
This commit is contained in:
super_liu
2022-05-27 15:12:41 +08:00
15 changed files with 2144 additions and 744 deletions
@@ -0,0 +1,28 @@
package com.adc.da.common;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年05月27日 14:26
*/
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class GetBeanUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext context) {
GetBeanUtil.applicationContext = context;
}
public static Object getBean(String name) {
return applicationContext.getBean(name);
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}
@@ -1,301 +1,301 @@
package com.adc.da.scheduledState.server; //package com.adc.da.scheduledState.server;
//
import com.adc.da.mq.CreateStandMQService; //import com.adc.da.mq.CreateStandMQService;
import com.adc.da.person.service.IPersonCollectEOService; //import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.scheduledState.utils.Util; //import com.adc.da.scheduledState.utils.Util;
import com.adc.da.slrs.sarBussStandAttrInfo.dao.SarBussStandAttrInfoDao; //import com.adc.da.slrs.sarBussStandAttrInfo.dao.SarBussStandAttrInfoDao;
import com.adc.da.slrs.sarBussStandAttrInfo.service.ISarBussStandAttrInfoService; //import com.adc.da.slrs.sarBussStandAttrInfo.service.ISarBussStandAttrInfoService;
import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao; //import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao;
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand; //import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService; //import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao; //import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao;
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo; //import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.sys.dao.DicTypeEODao; //import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.utils.util.FieldConvertUtil; //import com.adc.da.utils.util.FieldConvertUtil;
import com.adc.da.utils.util.InitStandAttrUtil; //import com.adc.da.utils.util.InitStandAttrUtil;
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
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.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.json.JSONTokener; //import org.json.JSONTokener;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
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;
import org.springframework.scheduling.annotation.EnableScheduling; //import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.sql.Clob; //import java.sql.Clob;
import java.time.LocalDate; //import java.time.LocalDate;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.*; //import java.util.*;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @Description: TODO // * @Description: TODO
* @author: super_liu // * @author: super_liu
* @date: 2022年01月25日 3:34 // * @date: 2022年01月25日 3:34
*/ // */
@EnableScheduling //@EnableScheduling
@Component //@Component
@Slf4j //@Slf4j
public class UpdateStateBussSync { //public class UpdateStateBussSync {
Logger logger = LoggerFactory.getLogger(UpdateStateBussSync.class); // Logger logger = LoggerFactory.getLogger(UpdateStateBussSync.class);
//
@Autowired // @Autowired
private DicTypeEODao dicTypeEODao; // private DicTypeEODao dicTypeEODao;
//
@Autowired // @Autowired
private SarStandItemsDao standItemsDao; // private SarStandItemsDao standItemsDao;
//
@Autowired // @Autowired
private CreateStandMQService createStandMQService; // private CreateStandMQService createStandMQService;
//
@Autowired // @Autowired
private IPersonCollectEOService personCollectEOService; // private IPersonCollectEOService personCollectEOService;
//
@Autowired // @Autowired
private SarBussionessStandDao sarBussionessStandDao; // private SarBussionessStandDao sarBussionessStandDao;
//
@Autowired // @Autowired
private ISarBussionessStandService iSarBussionessStandService; // private ISarBussionessStandService iSarBussionessStandService;
//
@Autowired // @Autowired
private ISarBussStandAttrInfoService sarBussStandAttrInfoService; // private ISarBussStandAttrInfoService sarBussStandAttrInfoService;
//
@Autowired // @Autowired
private SarBussStandAttrInfoDao sarBussStandAttrInfoEODao; // private SarBussStandAttrInfoDao sarBussStandAttrInfoEODao;
//
/** // /**
* 根据配置文件设置是否开启定时器 // * 根据配置文件设置是否开启定时器
*/ // */
//
@Value("${isNotScheduled}") // @Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器 // private boolean isNotScheduled; //是否开启定时器
//
//
// 每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑 // // 每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑
// @Scheduled(cron="0 0 1 1 * ?") //// @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="*/60 * * * * ?") //// @Scheduled(cron="*/60 * * * * ?")
// @Scheduled(cron = "0 1 0 * * ?") //// @Scheduled(cron = "0 1 0 * * ?")
@Async // @Async
public void BussScheduled(){ // public void BussScheduled(){
if(isNotScheduled){ // if(isNotScheduled){
try{ // try{
Thread.sleep(2000); // Thread.sleep(2000);
logger.info("每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01"); // logger.info("每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
//
// 发布、即将实施 // // 发布、即将实施
List<String> list = new ArrayList<>(); // List<String> list = new ArrayList<>();
// 发布 // // 发布
list.add("6jnqba2mby"); // list.add("6jnqba2mby");
// 即将实施 // // 即将实施
list.add("rpvoxsvr60"); // list.add("rpvoxsvr60");
QueryWrapper wrapper = new QueryWrapper(); // QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0"); // wrapper.eq("A.VALID_FLAG","0");
wrapper.in("A.TEXT_STATUS_BUSS",list); // wrapper.in("A.TEXT_STATUS_BUSS",list);
List<SarBussionessStand> getStateScheduledList = sarBussionessStandDao.getStateScheduledList(wrapper); // List<SarBussionessStand> getStateScheduledList = sarBussionessStandDao.getStateScheduledList(wrapper);
if(!getStateScheduledList.isEmpty()){ // if(!getStateScheduledList.isEmpty()){
// N个实施日期中大于当前日期 // // N个实施日期中大于当前日期
List<SarBussionessStand> getStateScheduledListToIsAfter = getStateScheduledList.stream().filter(info -> { // List<SarBussionessStand> getStateScheduledListToIsAfter = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getPutTime())){ // if(StringUtils.isNotBlank(info.getPutTime())){
List<String> dateList = Arrays.stream(info.getPutTime().split(",")).map(String::trim).collect(Collectors.toList()); // List<String> dateList = Arrays.stream(info.getPutTime().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsAfterList = dateList.stream().filter(s -> { // List<String> dateIsAfterList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){ // if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now(); // LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay(); // LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否大于当前日期 // // 实施日期是否大于当前日期
return parse.isAfter(now); // return parse.isAfter(now);
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
return !dateIsAfterList.isEmpty(); // return !dateIsAfterList.isEmpty();
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
//
// N个实施日期中小于当前时间 // // N个实施日期中小于当前时间
List<SarBussionessStand> getStateScheduledListToIsBefore = getStateScheduledList.stream().filter(info -> { // List<SarBussionessStand> getStateScheduledListToIsBefore = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getPutTime())){ // if(StringUtils.isNotBlank(info.getPutTime())){
List<String> dateList = Arrays.stream(info.getPutTime().split(",")).map(String::trim).collect(Collectors.toList()); // List<String> dateList = Arrays.stream(info.getPutTime().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsBeforeList = dateList.stream().filter(s -> { // List<String> dateIsBeforeList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){ // if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now(); // LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay(); // LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否小于当前时间 // // 实施日期是否小于当前时间
return parse.isBefore(now); // return parse.isBefore(now);
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
return !dateIsBeforeList.isEmpty(); // return !dateIsBeforeList.isEmpty();
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
// N个实施日期中大于当前日期 执行逻辑 更为即将实施 // // N个实施日期中大于当前日期 执行逻辑 更为即将实施
if(!getStateScheduledListToIsAfter.isEmpty()){ // if(!getStateScheduledListToIsAfter.isEmpty()){
execStandDate(getStateScheduledListToIsAfter,"rpvoxsvr60"); // execStandDate(getStateScheduledListToIsAfter,"rpvoxsvr60");
} // }
//
// N个实施日期中小于当前时间 执行逻辑 更为现行有效 // // N个实施日期中小于当前时间 执行逻辑 更为现行有效
if(!getStateScheduledListToIsBefore.isEmpty()){ // if(!getStateScheduledListToIsBefore.isEmpty()){
execStandDate(getStateScheduledListToIsBefore,"9z741h2m3j"); // execStandDate(getStateScheduledListToIsBefore,"9z741h2m3j");
} // }
//
} // }
//
logger.info("每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01"); // logger.info("每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){ // }catch(Exception e){
logger.info(e.getMessage()); // logger.info(e.getMessage());
} // }
} // }
} // }
//
// 每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态 // // 每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态
// @Scheduled(cron="0 0 1 1 * ?") //// @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="*/60 * * * * ?") //// @Scheduled(cron="*/60 * * * * ?")
// @Scheduled(cron = "0 1 0 * * ?") //// @Scheduled(cron = "0 1 0 * * ?")
@Async // @Async
public void BussScheduledToAbolish(){ // public void BussScheduledToAbolish(){
if(isNotScheduled){ // if(isNotScheduled){
try{ // try{
Thread.sleep(2000); // Thread.sleep(2000);
logger.info("每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01"); // logger.info("每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
//
// 现行有效、即将实施 // // 现行有效、即将实施
List<String> list = new ArrayList<>(); // List<String> list = new ArrayList<>();
// 现行有效 // // 现行有效
list.add("9z741h2m3j"); // list.add("9z741h2m3j");
// 即将实施 // // 即将实施
list.add("rpvoxsvr60"); // list.add("rpvoxsvr60");
QueryWrapper wrapper = new QueryWrapper(); // QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0"); // wrapper.eq("A.VALID_FLAG","0");
wrapper.in("A.TEXT_STATUS_BUSS",list); // wrapper.in("A.TEXT_STATUS_BUSS",list);
List<SarBussionessStand> getStateScheduledList = sarBussionessStandDao.getStateScheduledList(wrapper); // List<SarBussionessStand> getStateScheduledList = sarBussionessStandDao.getStateScheduledList(wrapper);
if(!getStateScheduledList.isEmpty()){ // if(!getStateScheduledList.isEmpty()){
//
// 需要更新为作废状态的集合 // // 需要更新为作废状态的集合
List<SarBussionessStand> invalidList = getStateScheduledList.stream().filter(info -> { // List<SarBussionessStand> invalidList = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getBDTQBBHBUSS())){ // if(StringUtils.isNotBlank(info.getBDTQBBHBUSS())){
List<String> bdtList = Arrays.stream(info.getBDTQBBHBUSS().split(",")).map(String::trim).collect(Collectors.toList()); // List<String> bdtList = Arrays.stream(info.getBDTQBBHBUSS().split(",")).map(String::trim).collect(Collectors.toList());
// 现行有效、作废 // // 现行有效、作废
List<String> bdtStateList = new ArrayList<>(); // List<String> bdtStateList = new ArrayList<>();
// 现行有效 // // 现行有效
bdtStateList.add("9z741h2m3j"); // bdtStateList.add("9z741h2m3j");
// 作废 // // 作废
bdtStateList.add("3lqnlgmgcn"); // bdtStateList.add("3lqnlgmgcn");
QueryWrapper wrapperBdt = new QueryWrapper(); // QueryWrapper wrapperBdt = new QueryWrapper();
wrapperBdt.eq("VALID_FLAG","0"); // wrapperBdt.eq("VALID_FLAG","0");
wrapperBdt.in("STAND_CODE",bdtList); // wrapperBdt.in("STAND_CODE",bdtList);
wrapperBdt.in("TEXT_STATUS_BUSS",bdtStateList); // wrapperBdt.in("TEXT_STATUS_BUSS",bdtStateList);
List<SarBussionessStand> queryBDTBussList = sarBussionessStandDao.selectList(wrapperBdt); // List<SarBussionessStand> queryBDTBussList = sarBussionessStandDao.selectList(wrapperBdt);
// 所有的被代替标准号中的有效标准中有一个标准标准状态是现行有效、作废 // // 所有的被代替标准号中的有效标准中有一个标准标准状态是现行有效、作废
return !queryBDTBussList.isEmpty(); // return !queryBDTBussList.isEmpty();
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
//
// 作废状态的集合 执行逻辑 更为作废 // // 作废状态的集合 执行逻辑 更为作废
if(!invalidList.isEmpty()){ // if(!invalidList.isEmpty()){
execStandDate(invalidList,"3lqnlgmgcn"); // execStandDate(invalidList,"3lqnlgmgcn");
} // }
//
} // }
//
logger.info("每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01"); // logger.info("每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){ // }catch(Exception e){
logger.info(e.getMessage()); // logger.info(e.getMessage());
} // }
} // }
} // }
//
//
@Async // @Async
public void execStandDate(List<SarBussionessStand> infoList, String textStatusStand) throws Exception { // public void execStandDate(List<SarBussionessStand> infoList, String textStatusStand) throws Exception {
List<SarBussionessStand> list = new ArrayList<>(); // List<SarBussionessStand> list = new ArrayList<>();
for (SarBussionessStand info : infoList) { // for (SarBussionessStand info : infoList) {
info.setTextStatusBuss(textStatusStand); // info.setTextStatusBuss(textStatusStand);
bussAttrInfoShowSearchDetails(info); // bussAttrInfoShowSearchDetails(info);
if (info.getAttrInfoMap() != null) { // if (info.getAttrInfoMap() != null) {
info.setSarStandAttrEOStr(JSONObject.toJSONString(info.getAttrInfoMap())); // info.setSarStandAttrEOStr(JSONObject.toJSONString(info.getAttrInfoMap()));
} // }
createStandMQService.sendBussStandMQ(info,"update"); // createStandMQService.sendBussStandMQ(info,"update");
//
// 只批量更新文本字段 // // 只批量更新文本字段
SarBussionessStand newInfo = new SarBussionessStand(); // SarBussionessStand newInfo = new SarBussionessStand();
newInfo.setTextStatusBuss(textStatusStand); // newInfo.setTextStatusBuss(textStatusStand);
newInfo.setId(info.getId()); // newInfo.setId(info.getId());
newInfo.setModifyTime(new Date()); // newInfo.setModifyTime(new Date());
list.add(newInfo); // list.add(newInfo);
} // }
//
if(!list.isEmpty()){ // if(!list.isEmpty()){
iSarBussionessStandService.updateBatchById(list); // iSarBussionessStandService.updateBatchById(list);
} // }
} // }
//
//
/** // /**
* 获取属性字段 // * 获取属性字段
* @param row // * @param row
*/ // */
//
public void bussAttrInfoShowSearchDetails(SarBussionessStand row) throws Exception { // public void bussAttrInfoShowSearchDetails(SarBussionessStand row) throws Exception {
if (row != null) { // if (row != null) {
bussAttrInfoSearchDetails(row); // bussAttrInfoSearchDetails(row);
Map<String, Object> getAttrMap = row.getAttrInfoCaseMap(); // Map<String, Object> getAttrMap = row.getAttrInfoCaseMap();
if (getAttrMap != null && getAttrMap.size() > 0) { // if (getAttrMap != null && getAttrMap.size() > 0) {
for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) { // for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) {
String name = entry.getKey().toUpperCase(); // String name = entry.getKey().toUpperCase();
String value = ""; // String value = "";
List<String> valArr = new ArrayList<>(); // List<String> valArr = new ArrayList<>();
if (entry.getValue() != null && InitStandAttrUtil.selectionFieldListBuss != null && InitStandAttrUtil.selectionFieldListBuss.size() > 0 && InitStandAttrUtil.selectionFieldListBuss.contains(name)) { // if (entry.getValue() != null && InitStandAttrUtil.selectionFieldListBuss != null && InitStandAttrUtil.selectionFieldListBuss.size() > 0 && InitStandAttrUtil.selectionFieldListBuss.contains(name)) {
if(org.apache.commons.lang.StringUtils.isNotBlank(entry.getValue().toString())){ // if(org.apache.commons.lang.StringUtils.isNotBlank(entry.getValue().toString())){
Object json= new JSONTokener(entry.getValue().toString()).nextValue(); // Object json= new JSONTokener(entry.getValue().toString()).nextValue();
if(json instanceof org.json.JSONArray){ // if(json instanceof org.json.JSONArray){
valArr = com.alibaba.fastjson.JSONObject.parseArray(entry.getValue().toString(),String.class); // valArr = com.alibaba.fastjson.JSONObject.parseArray(entry.getValue().toString(),String.class);
}else { // }else {
value = entry.getValue().toString(); // value = entry.getValue().toString();
valArr = Arrays.asList(value.split(",")); // valArr = Arrays.asList(value.split(","));
} // }
if(!valArr.isEmpty()){ // if(!valArr.isEmpty()){
value = dicTypeEODao.getDicNamesByCodes(valArr,""); // value = dicTypeEODao.getDicNamesByCodes(valArr,"");
} // }
} // }
entry.setValue(value); // entry.setValue(value);
} // }
} // }
} // }
} // }
} // }
//
public void bussAttrInfoSearchDetails(SarBussionessStand row) throws Exception { // public void bussAttrInfoSearchDetails(SarBussionessStand row) throws Exception {
String fieldInfo = InitStandAttrUtil.queryFieldBuss; // String fieldInfo = InitStandAttrUtil.queryFieldBuss;
String collectId = personCollectEOService.queryCollectByUserAndId(row.getId()); // String collectId = personCollectEOService.queryCollectByUserAndId(row.getId());
row.setCollectId(collectId); // row.setCollectId(collectId);
// 查询属性表数据 // // 查询属性表数据
if (org.apache.commons.lang.StringUtils.isNotBlank(fieldInfo)) { // if (org.apache.commons.lang.StringUtils.isNotBlank(fieldInfo)) {
Map<String, Object> getAttrMap = sarBussStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId()); // Map<String, Object> getAttrMap = sarBussStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId());
if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) { // if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) {
// 遍历修改所有clob类型的值 // // 遍历修改所有clob类型的值
for (String clobField : InitStandAttrUtil.clobFieldList) { // for (String clobField : InitStandAttrUtil.clobFieldList) {
Clob clobValue = (Clob) getAttrMap.get(clobField); // Clob clobValue = (Clob) getAttrMap.get(clobField);
String fieldValue = FieldConvertUtil.ClobToString(clobValue); // String fieldValue = FieldConvertUtil.ClobToString(clobValue);
getAttrMap.put(clobField, fieldValue); // getAttrMap.put(clobField, fieldValue);
} // }
} // }
//
row.setAttrInfoMap(getAttrMap); // row.setAttrInfoMap(getAttrMap);
} // }
} // }
//
} //}
@@ -0,0 +1,220 @@
package com.adc.da.scheduledState.server;
import com.adc.da.common.GetBeanUtil;
import com.adc.da.mq.CreateStandMQService;
import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.search.bean.SearchCenter;
import com.adc.da.search.server.ResetSearchCenterService;
import com.adc.da.slrs.sarBussStandAttrInfo.dao.SarBussStandAttrInfoDao;
import com.adc.da.slrs.sarBussStandAttrInfo.service.ISarBussStandAttrInfoService;
import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao;
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao;
import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.utils.util.FieldConvertUtil;
import com.adc.da.utils.util.InitStandAttrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import java.sql.Clob;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年01月25日 3:34
*/
@Slf4j
public class UpdateStateBussSyncFz implements Runnable {
Logger logger = LoggerFactory.getLogger(UpdateStateBussSyncFz.class);
private DicTypeEODao dicTypeEODao;
private SarStandItemsDao standItemsDao;
private CreateStandMQService createStandMQService;
private IPersonCollectEOService personCollectEOService;
private SarBussionessStandDao sarBussionessStandDao;
private ISarBussionessStandService iSarBussionessStandService;
private ISarBussStandAttrInfoService sarBussStandAttrInfoService;
private SarBussStandAttrInfoDao sarBussStandAttrInfoEODao;
/**
* 根据配置文件设置是否开启定时器
*/
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
public UpdateStateBussSyncFz(){
sarBussionessStandDao = GetBeanUtil.getApplicationContext().getBean(SarBussionessStandDao.class);
createStandMQService = GetBeanUtil.getApplicationContext().getBean(CreateStandMQService.class);
iSarBussionessStandService = GetBeanUtil.getApplicationContext().getBean(ISarBussionessStandService.class);
dicTypeEODao = GetBeanUtil.getApplicationContext().getBean(DicTypeEODao.class);
personCollectEOService = GetBeanUtil.getApplicationContext().getBean(IPersonCollectEOService.class);
sarBussStandAttrInfoEODao = GetBeanUtil.getApplicationContext().getBean(SarBussStandAttrInfoDao.class);
}
/**
* 每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态
*/
@Override
public void run() {
try{
Thread.sleep(2000);
logger.info("每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
// 现行有效、即将实施
List<String> list = new ArrayList<>();
// 现行有效
list.add("9z741h2m3j");
// 即将实施
list.add("rpvoxsvr60");
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0");
wrapper.in("A.TEXT_STATUS_BUSS",list);
List<SarBussionessStand> getStateScheduledList = sarBussionessStandDao.getStateScheduledList(wrapper);
if(!getStateScheduledList.isEmpty()){
// 需要更新为作废状态的集合
List<SarBussionessStand> invalidList = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getBDTQBBHBUSS())){
List<String> bdtList = Arrays.stream(info.getBDTQBBHBUSS().split(",")).map(String::trim).collect(Collectors.toList());
// 现行有效、作废
List<String> bdtStateList = new ArrayList<>();
// 现行有效
bdtStateList.add("9z741h2m3j");
// 作废
bdtStateList.add("3lqnlgmgcn");
QueryWrapper wrapperBdt = new QueryWrapper();
wrapperBdt.eq("VALID_FLAG","0");
wrapperBdt.in("STAND_CODE",bdtList);
wrapperBdt.in("TEXT_STATUS_BUSS",bdtStateList);
List<SarBussionessStand> queryBDTBussList = sarBussionessStandDao.selectList(wrapperBdt);
// 所有的被代替标准号中的有效标准中有一个标准标准状态是现行有效、作废
return !queryBDTBussList.isEmpty();
}
return false;
}).collect(Collectors.toList());
// 作废状态的集合 执行逻辑 更为作废
if(!invalidList.isEmpty()){
execStandDate(invalidList,"3lqnlgmgcn");
}
}
logger.info("每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){
logger.info(e.getMessage());
}
}
// 每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态
// @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="*/60 * * * * ?")
// @Scheduled(cron = "0 1 0 * * ?")
// @Async
// public void BussScheduledToAbolish(){
// if(isNotScheduled){
//
// }
// }
@Async
public void execStandDate(List<SarBussionessStand> infoList, String textStatusStand) throws Exception {
List<SarBussionessStand> list = new ArrayList<>();
for (SarBussionessStand info : infoList) {
info.setTextStatusBuss(textStatusStand);
bussAttrInfoShowSearchDetails(info);
if (info.getAttrInfoMap() != null) {
info.setSarStandAttrEOStr(JSONObject.toJSONString(info.getAttrInfoMap()));
}
createStandMQService.sendBussStandMQ(info,"update");
// 只批量更新文本字段
SarBussionessStand newInfo = new SarBussionessStand();
newInfo.setTextStatusBuss(textStatusStand);
newInfo.setId(info.getId());
newInfo.setModifyTime(new Date());
list.add(newInfo);
}
if(!list.isEmpty()){
iSarBussionessStandService.updateBatchById(list);
}
}
/**
* 获取属性字段
* @param row
*/
public void bussAttrInfoShowSearchDetails(SarBussionessStand row) throws Exception {
if (row != null) {
bussAttrInfoSearchDetails(row);
Map<String, Object> getAttrMap = row.getAttrInfoCaseMap();
if (getAttrMap != null && getAttrMap.size() > 0) {
for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) {
String name = entry.getKey().toUpperCase();
String value = "";
List<String> valArr = new ArrayList<>();
if (entry.getValue() != null && InitStandAttrUtil.selectionFieldListBuss != null && InitStandAttrUtil.selectionFieldListBuss.size() > 0 && InitStandAttrUtil.selectionFieldListBuss.contains(name)) {
if(org.apache.commons.lang.StringUtils.isNotBlank(entry.getValue().toString())){
Object json= new JSONTokener(entry.getValue().toString()).nextValue();
if(json instanceof org.json.JSONArray){
valArr = com.alibaba.fastjson.JSONObject.parseArray(entry.getValue().toString(),String.class);
}else {
value = entry.getValue().toString();
valArr = Arrays.asList(value.split(","));
}
if(!valArr.isEmpty()){
value = dicTypeEODao.getDicNamesByCodes(valArr,"");
}
}
entry.setValue(value);
}
}
}
}
}
public void bussAttrInfoSearchDetails(SarBussionessStand row) throws Exception {
String fieldInfo = InitStandAttrUtil.queryFieldBuss;
String collectId = personCollectEOService.queryCollectByUserAndId(row.getId());
row.setCollectId(collectId);
// 查询属性表数据
if (org.apache.commons.lang.StringUtils.isNotBlank(fieldInfo)) {
Map<String, Object> getAttrMap = sarBussStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId());
if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) {
// 遍历修改所有clob类型的值
for (String clobField : InitStandAttrUtil.clobFieldList) {
Clob clobValue = (Clob) getAttrMap.get(clobField);
String fieldValue = FieldConvertUtil.ClobToString(clobValue);
getAttrMap.put(clobField, fieldValue);
}
}
row.setAttrInfoMap(getAttrMap);
}
}
}
@@ -0,0 +1,245 @@
package com.adc.da.scheduledState.server;
import com.adc.da.common.GetBeanUtil;
import com.adc.da.mq.CreateStandMQService;
import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.scheduledState.utils.Util;
import com.adc.da.search.server.ResetSearchCenterService;
import com.adc.da.slrs.sarBussStandAttrInfo.dao.SarBussStandAttrInfoDao;
import com.adc.da.slrs.sarBussStandAttrInfo.service.ISarBussStandAttrInfoService;
import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao;
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao;
import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.utils.util.FieldConvertUtil;
import com.adc.da.utils.util.InitStandAttrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import java.sql.Clob;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年01月25日 3:34
*/
@Slf4j
public class UpdateStateBussSyncSsAndYx implements Runnable {
Logger logger = LoggerFactory.getLogger(UpdateStateBussSyncSsAndYx.class);
private DicTypeEODao dicTypeEODao;
private SarStandItemsDao standItemsDao;
private CreateStandMQService createStandMQService;
private IPersonCollectEOService personCollectEOService;
private SarBussionessStandDao sarBussionessStandDao;
private ISarBussionessStandService iSarBussionessStandService;
private SarBussStandAttrInfoDao sarBussStandAttrInfoEODao;
/**
* 根据配置文件设置是否开启定时器
*/
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
public UpdateStateBussSyncSsAndYx(){
sarBussionessStandDao = GetBeanUtil.getApplicationContext().getBean(SarBussionessStandDao.class);
createStandMQService = GetBeanUtil.getApplicationContext().getBean(CreateStandMQService.class);
iSarBussionessStandService = GetBeanUtil.getApplicationContext().getBean(ISarBussionessStandService.class);
dicTypeEODao = GetBeanUtil.getApplicationContext().getBean(DicTypeEODao.class);
personCollectEOService = GetBeanUtil.getApplicationContext().getBean(IPersonCollectEOService.class);
sarBussStandAttrInfoEODao = GetBeanUtil.getApplicationContext().getBean(SarBussStandAttrInfoDao.class);
}
/**
* 每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑
*/
@Override
public void run() {
try{
Thread.sleep(2000);
logger.info("每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
// 发布、即将实施
List<String> list = new ArrayList<>();
// 发布
list.add("6jnqba2mby");
// 即将实施
list.add("rpvoxsvr60");
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0");
wrapper.in("A.TEXT_STATUS_BUSS",list);
List<SarBussionessStand> getStateScheduledList = sarBussionessStandDao.getStateScheduledList(wrapper);
if(!getStateScheduledList.isEmpty()){
// N个实施日期中大于当前日期
List<SarBussionessStand> getStateScheduledListToIsAfter = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getPutTime())){
List<String> dateList = Arrays.stream(info.getPutTime().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsAfterList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否大于当前日期
return parse.isAfter(now);
}
return false;
}).collect(Collectors.toList());
return !dateIsAfterList.isEmpty();
}
return false;
}).collect(Collectors.toList());
// N个实施日期中小于当前时间
List<SarBussionessStand> getStateScheduledListToIsBefore = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getPutTime())){
List<String> dateList = Arrays.stream(info.getPutTime().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsBeforeList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否小于当前时间
return parse.isBefore(now);
}
return false;
}).collect(Collectors.toList());
return !dateIsBeforeList.isEmpty();
}
return false;
}).collect(Collectors.toList());
// N个实施日期中大于当前日期 执行逻辑 更为即将实施
if(!getStateScheduledListToIsAfter.isEmpty()){
execStandDate(getStateScheduledListToIsAfter,"rpvoxsvr60");
}
// N个实施日期中小于当前时间 执行逻辑 更为现行有效
if(!getStateScheduledListToIsBefore.isEmpty()){
execStandDate(getStateScheduledListToIsBefore,"9z741h2m3j");
}
}
logger.info("每天0点1分执行 企标标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){
logger.info(e.getMessage());
}
}
// 每天0点1分执行 企标标准文本状态被代替逻辑 自动变更作废状态
// @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="*/60 * * * * ?")
// @Scheduled(cron = "0 1 0 * * ?")
// @Async
// public void BussScheduledToAbolish(){
// if(isNotScheduled){
//
// }
// }
@Async
public void execStandDate(List<SarBussionessStand> infoList, String textStatusStand) throws Exception {
List<SarBussionessStand> list = new ArrayList<>();
for (SarBussionessStand info : infoList) {
info.setTextStatusBuss(textStatusStand);
bussAttrInfoShowSearchDetails(info);
if (info.getAttrInfoMap() != null) {
info.setSarStandAttrEOStr(JSONObject.toJSONString(info.getAttrInfoMap()));
}
createStandMQService.sendBussStandMQ(info,"update");
// 只批量更新文本字段
SarBussionessStand newInfo = new SarBussionessStand();
newInfo.setTextStatusBuss(textStatusStand);
newInfo.setId(info.getId());
newInfo.setModifyTime(new Date());
list.add(newInfo);
}
if(!list.isEmpty()){
iSarBussionessStandService.updateBatchById(list);
}
}
/**
* 获取属性字段
* @param row
*/
public void bussAttrInfoShowSearchDetails(SarBussionessStand row) throws Exception {
if (row != null) {
bussAttrInfoSearchDetails(row);
Map<String, Object> getAttrMap = row.getAttrInfoCaseMap();
if (getAttrMap != null && getAttrMap.size() > 0) {
for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) {
String name = entry.getKey().toUpperCase();
String value = "";
List<String> valArr = new ArrayList<>();
if (entry.getValue() != null && InitStandAttrUtil.selectionFieldListBuss != null && InitStandAttrUtil.selectionFieldListBuss.size() > 0 && InitStandAttrUtil.selectionFieldListBuss.contains(name)) {
if(org.apache.commons.lang.StringUtils.isNotBlank(entry.getValue().toString())){
Object json= new JSONTokener(entry.getValue().toString()).nextValue();
if(json instanceof org.json.JSONArray){
valArr = JSONObject.parseArray(entry.getValue().toString(),String.class);
}else {
value = entry.getValue().toString();
valArr = Arrays.asList(value.split(","));
}
if(!valArr.isEmpty()){
value = dicTypeEODao.getDicNamesByCodes(valArr,"");
}
}
entry.setValue(value);
}
}
}
}
}
public void bussAttrInfoSearchDetails(SarBussionessStand row) throws Exception {
String fieldInfo = InitStandAttrUtil.queryFieldBuss;
String collectId = personCollectEOService.queryCollectByUserAndId(row.getId());
row.setCollectId(collectId);
// 查询属性表数据
if (org.apache.commons.lang.StringUtils.isNotBlank(fieldInfo)) {
Map<String, Object> getAttrMap = sarBussStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId());
if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) {
// 遍历修改所有clob类型的值
for (String clobField : InitStandAttrUtil.clobFieldList) {
Clob clobValue = (Clob) getAttrMap.get(clobField);
String fieldValue = FieldConvertUtil.ClobToString(clobValue);
getAttrMap.put(clobField, fieldValue);
}
}
row.setAttrInfoMap(getAttrMap);
}
}
}
@@ -1,405 +1,405 @@
package com.adc.da.scheduledState.server; //package com.adc.da.scheduledState.server;
//
import com.adc.da.mq.CreateStandMQService; //import com.adc.da.mq.CreateStandMQService;
import com.adc.da.person.service.IPersonCollectEOService; //import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.scheduledState.utils.Util; //import com.adc.da.scheduledState.utils.Util;
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao; //import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
import com.adc.da.slrs.sarStandAttrInfo.service.ISarStandAttrInfoService; //import com.adc.da.slrs.sarStandAttrInfo.service.ISarStandAttrInfoService;
import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao; //import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao;
import com.adc.da.slrs.sarStandItems.entity.FindSarItemsPageReqDTO; //import com.adc.da.slrs.sarStandItems.entity.FindSarItemsPageReqDTO;
import com.adc.da.slrs.sarStandItems.entity.SarStandItems; //import com.adc.da.slrs.sarStandItems.entity.SarStandItems;
import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao; //import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao;
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo; //import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService; //import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
import com.adc.da.sys.dao.DicTypeEODao; //import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.utils.util.FieldConvertUtil; //import com.adc.da.utils.util.FieldConvertUtil;
import com.adc.da.utils.util.InitStandAttrUtil; //import com.adc.da.utils.util.InitStandAttrUtil;
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
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.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.json.JSONTokener; //import org.json.JSONTokener;
import org.slf4j.Logger; //import org.slf4j.Logger;
import org.slf4j.LoggerFactory; //import org.slf4j.LoggerFactory;
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;
import org.springframework.scheduling.annotation.EnableScheduling; //import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.sql.Clob; //import java.sql.Clob;
import java.time.LocalDate; //import java.time.LocalDate;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.*; //import java.util.*;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @Description: TODO // * @Description: TODO
* @author: super_liu // * @author: super_liu
* @date: 2022年01月25日 3:34 // * @date: 2022年01月25日 3:34
*/ // */
@EnableScheduling //@EnableScheduling
@Component //@Component
@Slf4j //@Slf4j
public class UpdateStateStandSync { //public class UpdateStateStandSync {
Logger logger = LoggerFactory.getLogger(UpdateStateStandSync.class); // Logger logger = LoggerFactory.getLogger(UpdateStateStandSync.class);
//
@Autowired // @Autowired
private DicTypeEODao dicTypeEODao; // private DicTypeEODao dicTypeEODao;
//
@Autowired // @Autowired
private SarStandItemsDao standItemsDao; // private SarStandItemsDao standItemsDao;
//
@Autowired // @Autowired
private CreateStandMQService createStandMQService; // private CreateStandMQService createStandMQService;
//
@Autowired // @Autowired
private IPersonCollectEOService personCollectEOService; // private IPersonCollectEOService personCollectEOService;
//
@Autowired // @Autowired
private SarStandAttrInfoDao sarStandAttrInfoEODao; // private SarStandAttrInfoDao sarStandAttrInfoEODao;
//
@Autowired // @Autowired
private SarStandardsInfoDao sarStandardsInfoDao; // private SarStandardsInfoDao sarStandardsInfoDao;
//
@Autowired // @Autowired
private ISarStandardsInfoService iSarStandardsInfoService; // private ISarStandardsInfoService iSarStandardsInfoService;
//
@Autowired // @Autowired
private ISarStandAttrInfoService sarStandAttrInfoEOService; // private ISarStandAttrInfoService sarStandAttrInfoEOService;
//
/** // /**
* 根据配置文件设置是否开启定时器 // * 根据配置文件设置是否开启定时器
*/ // */
//
@Value("${isNotScheduled}") // @Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器 // private boolean isNotScheduled; //是否开启定时器
//
//
// 每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑 // // 每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑
// @Scheduled(cron="0 0 1 1 * ?") //// @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="0 37 9 * * ?") //// @Scheduled(cron="0 37 9 * * ?")
// @Scheduled(cron = "0 1 0 * * ?") //// @Scheduled(cron = "0 1 0 * * ?")
@Async // @Async
public void StandScheduled(){ // public void StandScheduled(){
if(isNotScheduled){ // if(isNotScheduled){
try{ // try{
Thread.sleep(2000); // Thread.sleep(2000);
logger.info("每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01"); // logger.info("每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
//
// 发布、即将实施 只查询国内标准 // // 发布、即将实施 只查询国内标准
List<String> list = new ArrayList<>(); // List<String> list = new ArrayList<>();
// 发布 // // 发布
list.add("hc99551723c"); // list.add("hc99551723c");
// 即将实施 // // 即将实施
list.add("hb0iy9z23c"); // list.add("hb0iy9z23c");
QueryWrapper wrapper = new QueryWrapper(); // QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0"); // wrapper.eq("A.VALID_FLAG","0");
wrapper.eq("STAND_TYPE","INLAND"); // wrapper.eq("STAND_TYPE","INLAND");
wrapper.in("A.TEXT_STATUS",list); // wrapper.in("A.TEXT_STATUS",list);
List<SarStandardsInfo> getStateScheduledList = sarStandardsInfoDao.getStateScheduledList(wrapper); // List<SarStandardsInfo> getStateScheduledList = sarStandardsInfoDao.getStateScheduledList(wrapper);
if(!getStateScheduledList.isEmpty()){ // if(!getStateScheduledList.isEmpty()){
// N个实施日期中大于当前日期 // // N个实施日期中大于当前日期
List<SarStandardsInfo> getStateScheduledListToIsAfter = getStateScheduledList.stream().filter(info -> { // List<SarStandardsInfo> getStateScheduledListToIsAfter = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getSSRQ())){ // if(StringUtils.isNotBlank(info.getSSRQ())){
List<String> dateList = Arrays.stream(info.getSSRQ().split(",")).map(String::trim).collect(Collectors.toList()); // List<String> dateList = Arrays.stream(info.getSSRQ().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsAfterList = dateList.stream().filter(s -> { // List<String> dateIsAfterList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){ // if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now(); // LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay(); // LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否大于当前日期 // // 实施日期是否大于当前日期
return parse.isAfter(now); // return parse.isAfter(now);
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
return !dateIsAfterList.isEmpty(); // return !dateIsAfterList.isEmpty();
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
//
// N个实施日期中小于当前时间 // // N个实施日期中小于当前时间
List<SarStandardsInfo> getStateScheduledListToIsBefore = getStateScheduledList.stream().filter(info -> { // List<SarStandardsInfo> getStateScheduledListToIsBefore = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getSSRQ())){ // if(StringUtils.isNotBlank(info.getSSRQ())){
List<String> dateList = Arrays.stream(info.getSSRQ().split(",")).map(String::trim).collect(Collectors.toList()); // List<String> dateList = Arrays.stream(info.getSSRQ().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsBeforeList = dateList.stream().filter(s -> { // List<String> dateIsBeforeList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){ // if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now(); // LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay(); // LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否小于当前时间 // // 实施日期是否小于当前时间
return parse.isBefore(now); // return parse.isBefore(now);
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
return !dateIsBeforeList.isEmpty(); // return !dateIsBeforeList.isEmpty();
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
// N个实施日期中大于当前日期 执行逻辑 更为即将实施 // // N个实施日期中大于当前日期 执行逻辑 更为即将实施
if(!getStateScheduledListToIsAfter.isEmpty()){ // if(!getStateScheduledListToIsAfter.isEmpty()){
logger.info("=============N个实施日期中大于当前日期 执行============"); // logger.info("=============N个实施日期中大于当前日期 执行============");
// 文本状态更为即将实施 // // 文本状态更为即将实施
execStandDate(getStateScheduledListToIsAfter,"hb0iy9z23c"); // execStandDate(getStateScheduledListToIsAfter,"hb0iy9z23c");
} // }
//
// N个实施日期中小于当前时间 执行逻辑 更为现行有效 // // N个实施日期中小于当前时间 执行逻辑 更为现行有效
if(!getStateScheduledListToIsBefore.isEmpty()){ // if(!getStateScheduledListToIsBefore.isEmpty()){
logger.info("=============N个实施日期中小于当前时间 执行============"); // logger.info("=============N个实施日期中小于当前时间 执行============");
// 文本状态更为现行有效 // // 文本状态更为现行有效
execStandDate(getStateScheduledListToIsBefore,"vsaga7nwub"); // execStandDate(getStateScheduledListToIsBefore,"vsaga7nwub");
} // }
//
} // }
//
//
logger.info("每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01"); // logger.info("每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){ // }catch(Exception e){
logger.info(e.getMessage()); // logger.info(e.getMessage());
} // }
} // }
} // }
//
// 每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止 // // 每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止
// @Scheduled(cron="0 0 1 1 * ?") //// @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="*/60 * * * * ?") //// @Scheduled(cron="*/60 * * * * ?")
// @Scheduled(cron = "0 1 0 * * ?") //// @Scheduled(cron = "0 1 0 * * ?")
@Async // @Async
public void StandScheduledToAbolish(){ // public void StandScheduledToAbolish(){
if(isNotScheduled){ // if(isNotScheduled){
try{ // try{
Thread.sleep(2000); // Thread.sleep(2000);
logger.info("每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01"); // logger.info("每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
//
// 现行有效、即将实施、被代替 只查询国内标准 // // 现行有效、即将实施、被代替 只查询国内标准
List<String> list = new ArrayList<>(); // List<String> list = new ArrayList<>();
// 现行有效 // // 现行有效
list.add("vsaga7nwub"); // list.add("vsaga7nwub");
// 即将实施 // // 即将实施
list.add("hb0iy9z23c"); // list.add("hb0iy9z23c");
// 被代替 // // 被代替
list.add("qke0ckro2p"); // list.add("qke0ckro2p");
QueryWrapper wrapper = new QueryWrapper(); // QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0"); // wrapper.eq("A.VALID_FLAG","0");
wrapper.eq("STAND_TYPE","INLAND"); // wrapper.eq("STAND_TYPE","INLAND");
wrapper.in("A.TEXT_STATUS",list); // wrapper.in("A.TEXT_STATUS",list);
List<SarStandardsInfo> getStateStandScheduledList = sarStandardsInfoDao.getStateScheduledList(wrapper); // List<SarStandardsInfo> getStateStandScheduledList = sarStandardsInfoDao.getStateScheduledList(wrapper);
//
if(!getStateStandScheduledList.isEmpty()){ // if(!getStateStandScheduledList.isEmpty()){
//
List<SarStandardsInfo> invalidStandToGBList = new ArrayList<>(); // List<SarStandardsInfo> invalidStandToGBList = new ArrayList<>();
List<SarStandardsInfo> bdtStandToGBList = new ArrayList<>(); // List<SarStandardsInfo> bdtStandToGBList = new ArrayList<>();
//
// 当前标准的标准类别是否是GB类 GB集合逻辑 // // 当前标准的标准类别是否是GB类 GB集合逻辑
getStateStandScheduledList.forEach(info -> { // getStateStandScheduledList.forEach(info -> {
if(StringUtils.isNotBlank(info.getBDTBZH())){ // if(StringUtils.isNotBlank(info.getBDTBZH())){
List<String> bdtList = Arrays.stream(info.getBDTBZH().split(",")).map( // List<String> bdtList = Arrays.stream(info.getBDTBZH().split(",")).map(
s -> s.replace(" ","").trim()).collect(Collectors.toList()); // s -> s.replace(" ","").trim()).collect(Collectors.toList());
// 查询等于GB的国内标准 // // 查询等于GB的国内标准
QueryWrapper wrapperGB = new QueryWrapper(); // QueryWrapper wrapperGB = new QueryWrapper();
wrapperGB.eq("SAR_STANDARDS_INFO.VALID_FLAG","0"); // wrapperGB.eq("SAR_STANDARDS_INFO.VALID_FLAG","0");
wrapperGB.eq("SAR_STANDARDS_INFO.STAND_SORT","GB"); // wrapperGB.eq("SAR_STANDARDS_INFO.STAND_SORT","GB");
wrapperGB.in("trim(replace(concat(SAR_STANDARDS_INFO.STAND_SORT,' ',SAR_STANDARDS_INFO.STAND_NUMBER,'-'," + // wrapperGB.in("trim(replace(concat(SAR_STANDARDS_INFO.STAND_SORT,' ',SAR_STANDARDS_INFO.STAND_NUMBER,'-'," +
"SAR_STANDARDS_INFO.STAND_YEAR),' ',''))",bdtList); // "SAR_STANDARDS_INFO.STAND_YEAR),' ',''))",bdtList);
List<SarStandardsInfo> queryGBList = sarStandardsInfoDao.selectList(wrapperGB); // List<SarStandardsInfo> queryGBList = sarStandardsInfoDao.selectList(wrapperGB);
//
if(!queryGBList.isEmpty()){ // if(!queryGBList.isEmpty()){
int queryGbCount = queryGBList.size(); // int queryGbCount = queryGBList.size();
//
//被代替标准号中所有有效标准的状态都是现行有效状态 // //被代替标准号中所有有效标准的状态都是现行有效状态
List<SarStandardsInfo> yxList = queryGBList.stream().filter(info1 -> // List<SarStandardsInfo> yxList = queryGBList.stream().filter(info1 ->
"vsaga7nwub".equals(info1.getTextStatus())).collect(Collectors.toList()); // "vsaga7nwub".equals(info1.getTextStatus())).collect(Collectors.toList());
//
//被代替标准号中所有有效标准的状态都是被代替状态 // //被代替标准号中所有有效标准的状态都是被代替状态
List<SarStandardsInfo> bdtStateList = queryGBList.stream().filter(info1 -> // List<SarStandardsInfo> bdtStateList = queryGBList.stream().filter(info1 ->
"qke0ckro2p".equals(info1.getTextStatus())).collect(Collectors.toList()); // "qke0ckro2p".equals(info1.getTextStatus())).collect(Collectors.toList());
//
//被代替标准号中所有有效标准的状态都是废止状态 // //被代替标准号中所有有效标准的状态都是废止状态
List<SarStandardsInfo> fzList = queryGBList.stream().filter(info1 -> // List<SarStandardsInfo> fzList = queryGBList.stream().filter(info1 ->
"chblaarg77".equals(info1.getTextStatus())).collect(Collectors.toList()); // "chblaarg77".equals(info1.getTextStatus())).collect(Collectors.toList());
//
// 满足其上存入更新废止逻辑 如果只有一个被代替标准 优先更新废止状态 // // 满足其上存入更新废止逻辑 如果只有一个被代替标准 优先更新废止状态
if(yxList.size() == queryGbCount || bdtStateList.size() == queryGbCount || fzList.size() == queryGbCount){ // if(yxList.size() == queryGbCount || bdtStateList.size() == queryGbCount || fzList.size() == queryGbCount){
invalidStandToGBList.add(info); // invalidStandToGBList.add(info);
}else { // }else {
// 被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 // // 被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的
List<SarStandardsInfo> singleList = queryGBList.stream().filter(info1 -> { // List<SarStandardsInfo> singleList = queryGBList.stream().filter(info1 -> {
if("hc99551723c".equals(info1.getTextStatus()) || "hb0iy9z23c".equals(info1.getTextStatus()) // if("hc99551723c".equals(info1.getTextStatus()) || "hb0iy9z23c".equals(info1.getTextStatus())
|| "vsaga7nwub".equals(info1.getTextStatus()) || "qke0ckro2p".equals(info1.getTextStatus())){ // || "vsaga7nwub".equals(info1.getTextStatus()) || "qke0ckro2p".equals(info1.getTextStatus())){
return true; // return true;
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
// 满足其上存入更新被代替逻辑 // // 满足其上存入更新被代替逻辑
if(!singleList.isEmpty()){ // if(!singleList.isEmpty()){
bdtStandToGBList.add(info); // bdtStandToGBList.add(info);
} // }
} // }
} // }
} // }
}); // });
//
//
// 当前标准的标准类别是否是GB类 NOT GB集合逻辑 // // 当前标准的标准类别是否是GB类 NOT GB集合逻辑
List<SarStandardsInfo> bdtStandToNotGBList = getStateStandScheduledList.stream().filter(info -> { // List<SarStandardsInfo> bdtStandToNotGBList = getStateStandScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getBDTBZH())){ // if(StringUtils.isNotBlank(info.getBDTBZH())){
List<String> bdtList = Arrays.stream(info.getBDTBZH().split(",")).map( // List<String> bdtList = Arrays.stream(info.getBDTBZH().split(",")).map(
s -> s.replace(" ","").trim()).collect(Collectors.toList()); // s -> s.replace(" ","").trim()).collect(Collectors.toList());
//
//发布、即将实施、现行有效、被代替 // //发布、即将实施、现行有效、被代替
List<String> bdtStateList = new ArrayList<>(); // List<String> bdtStateList = new ArrayList<>();
// 发布 // // 发布
bdtStateList.add("hc99551723c"); // bdtStateList.add("hc99551723c");
// 作废 // // 作废
bdtStateList.add("hb0iy9z23c"); // bdtStateList.add("hb0iy9z23c");
// 即将实施 // // 即将实施
bdtStateList.add("vsaga7nwub"); // bdtStateList.add("vsaga7nwub");
// 被代替 // // 被代替
bdtStateList.add("qke0ckro2p"); // bdtStateList.add("qke0ckro2p");
//
// 查询不等于GB的国内标准 且 有效的被代替标准 // // 查询不等于GB的国内标准 且 有效的被代替标准
QueryWrapper wrapperNotGB = new QueryWrapper(); // QueryWrapper wrapperNotGB = new QueryWrapper();
wrapperNotGB.eq("VALID_FLAG","0"); // wrapperNotGB.eq("VALID_FLAG","0");
wrapperNotGB.ne("STAND_SORT","GB"); // wrapperNotGB.ne("STAND_SORT","GB");
wrapperNotGB.in("TEXT_STATUS",wrapperNotGB); // wrapperNotGB.in("TEXT_STATUS",wrapperNotGB);
wrapperNotGB.in("trim(replace(concat(SAR_STANDARDS_INFO.STAND_SORT,' ',SAR_STANDARDS_INFO.STAND_NUMBER,'-'," + // wrapperNotGB.in("trim(replace(concat(SAR_STANDARDS_INFO.STAND_SORT,' ',SAR_STANDARDS_INFO.STAND_NUMBER,'-'," +
"SAR_STANDARDS_INFO.STAND_YEAR),' ',''))",bdtList); // "SAR_STANDARDS_INFO.STAND_YEAR),' ',''))",bdtList);
List<SarStandardsInfo> queryNotGBList = sarStandardsInfoDao.selectList(wrapperNotGB); // List<SarStandardsInfo> queryNotGBList = sarStandardsInfoDao.selectList(wrapperNotGB);
//
// 被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 // // 被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的
// 满足其上过滤更新被代替数据 // // 满足其上过滤更新被代替数据
return !queryNotGBList.isEmpty(); // return !queryNotGBList.isEmpty();
} // }
return false; // return false;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
if(!invalidStandToGBList.isEmpty()){ // if(!invalidStandToGBList.isEmpty()){
logger.info("=============被代替标准号中所有有效标准的状态都是现行有效、被代替、废止状态 执行============"); // logger.info("=============被代替标准号中所有有效标准的状态都是现行有效、被代替、废止状态 执行============");
// 文本状态更为废止状态 // // 文本状态更为废止状态
execStandDate(invalidStandToGBList,"chblaarg77"); // execStandDate(invalidStandToGBList,"chblaarg77");
} // }
//
if(!bdtStandToGBList.isEmpty()){ // if(!bdtStandToGBList.isEmpty()){
logger.info("=============GB=======被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 执行============"); // logger.info("=============GB=======被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 执行============");
// 文本状态更为被代替 // // 文本状态更为被代替
execStandDate(bdtStandToGBList,"qke0ckro2p"); // execStandDate(bdtStandToGBList,"qke0ckro2p");
} // }
//
if(!bdtStandToNotGBList.isEmpty()){ // if(!bdtStandToNotGBList.isEmpty()){
logger.info("=============NOT GB ===被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 执行============"); // logger.info("=============NOT GB ===被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 执行============");
// 文本状态更为被代替 // // 文本状态更为被代替
execStandDate(bdtStandToNotGBList,"qke0ckro2p"); // execStandDate(bdtStandToNotGBList,"qke0ckro2p");
} // }
//
//
//
} // }
//
logger.info("每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01"); // logger.info("每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){ // }catch(Exception e){
logger.info(e.getMessage()); // logger.info(e.getMessage());
} // }
} // }
} // }
//
//
//
@Async // @Async
public void execStandDate(List<SarStandardsInfo> infoList, String textStatusStand) throws Exception { // public void execStandDate(List<SarStandardsInfo> infoList, String textStatusStand) throws Exception {
List<SarStandardsInfo> list = new ArrayList<>(); // List<SarStandardsInfo> list = new ArrayList<>();
for (SarStandardsInfo info : infoList) { // for (SarStandardsInfo info : infoList) {
info.setTextStatus(textStatusStand); // info.setTextStatus(textStatusStand);
standFunc(info); // standFunc(info);
createStandMQService.sendStandMQ(info,"update"); // createStandMQService.sendStandMQ(info,"update");
//
// 只批量更新文本字段 // // 只批量更新文本字段
SarStandardsInfo newInfo = new SarStandardsInfo(); // SarStandardsInfo newInfo = new SarStandardsInfo();
newInfo.setTextStatus(textStatusStand); // newInfo.setTextStatus(textStatusStand);
newInfo.setId(info.getId()); // newInfo.setId(info.getId());
newInfo.setModifyTime(new Date()); // newInfo.setModifyTime(new Date());
list.add(newInfo); // list.add(newInfo);
} // }
//
if(!list.isEmpty()){ // if(!list.isEmpty()){
iSarStandardsInfoService.updateBatchById(list); // iSarStandardsInfoService.updateBatchById(list);
} // }
} // }
//
private void standFunc(SarStandardsInfo sarStandardsInfoEO) throws Exception { // private void standFunc(SarStandardsInfo sarStandardsInfoEO) throws Exception {
attrInfoSearchDetails(sarStandardsInfoEO); // attrInfoSearchDetails(sarStandardsInfoEO);
FindSarItemsPageReqDTO pageInfo = new FindSarItemsPageReqDTO(); // FindSarItemsPageReqDTO pageInfo = new FindSarItemsPageReqDTO();
pageInfo.setStandId(sarStandardsInfoEO.getId()); // pageInfo.setStandId(sarStandardsInfoEO.getId());
pageInfo.setFileType("FBGBJBD"); // pageInfo.setFileType("FBGBJBD");
//
/** // /**
* SarItemVO换为sarItemVOS // * SarItemVO换为sarItemVOS
* List<SarItemVO> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo); // * List<SarItemVO> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo);
* .collect(Collectors.toMap(SarItemVO::getItemsNum, SarItemVO::getItemsName)); // * .collect(Collectors.toMap(SarItemVO::getItemsNum, SarItemVO::getItemsName));
*/ // */
//
List<SarStandItems> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo); // List<SarStandItems> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo);
if (!sarItemVOS.isEmpty()) { // if (!sarItemVOS.isEmpty()) {
Map<String, String> collectMap = sarItemVOS.stream().filter((e) -> e.getItemsNum() != null && e.getItemsName() != null) // Map<String, String> collectMap = sarItemVOS.stream().filter((e) -> e.getItemsNum() != null && e.getItemsName() != null)
.collect(Collectors.toMap(SarStandItems::getItemsNum, SarStandItems::getTermsConditions)); // .collect(Collectors.toMap(SarStandItems::getItemsNum, SarStandItems::getTermsConditions));
sarStandardsInfoEO.setMapItems(collectMap); // sarStandardsInfoEO.setMapItems(collectMap);
} // }
if (sarStandardsInfoEO.getAttrInfoMap() != null) { // if (sarStandardsInfoEO.getAttrInfoMap() != null) {
sarStandardsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarStandardsInfoEO.getAttrInfoMap())); // sarStandardsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarStandardsInfoEO.getAttrInfoMap()));
} // }
} // }
//
public void attrInfoSearchDetails(SarStandardsInfo row) throws Exception { // public void attrInfoSearchDetails(SarStandardsInfo row) throws Exception {
if (row != null) { // if (row != null) {
String fieldInfo = InitStandAttrUtil.queryField; // String fieldInfo = InitStandAttrUtil.queryField;
String collectId = personCollectEOService.queryCollectByUserAndId(row.getId()); // String collectId = personCollectEOService.queryCollectByUserAndId(row.getId());
row.setCollectId(collectId); // row.setCollectId(collectId);
// 查询属性表数据 // // 查询属性表数据
if (StringUtils.isNotBlank(fieldInfo)) { // if (StringUtils.isNotBlank(fieldInfo)) {
Map<String, Object> getAttrMap = sarStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId()); // Map<String, Object> getAttrMap = sarStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId());
if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) { // if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) {
// 遍历修改所有clob类型的值 // // 遍历修改所有clob类型的值
for (String clobField : InitStandAttrUtil.clobFieldList) { // for (String clobField : InitStandAttrUtil.clobFieldList) {
Clob clobValue = (Clob) getAttrMap.get(clobField); // Clob clobValue = (Clob) getAttrMap.get(clobField);
String fieldValue = FieldConvertUtil.ClobToString(clobValue); // String fieldValue = FieldConvertUtil.ClobToString(clobValue);
getAttrMap.put(clobField, fieldValue); // getAttrMap.put(clobField, fieldValue);
} // }
} // }
//
row.setAttrInfoMap(getAttrMap); // row.setAttrInfoMap(getAttrMap);
} // }
//
Map<String, Object> getAttrMap = row.getAttrInfoMap(); // Map<String, Object> getAttrMap = row.getAttrInfoMap();
if (getAttrMap != null && getAttrMap.size() > 0) { // if (getAttrMap != null && getAttrMap.size() > 0) {
for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) { // for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) {
String name = entry.getKey(); // String name = entry.getKey();
String value = ""; // String value = "";
List<String> valArr = new ArrayList<>(); // List<String> valArr = new ArrayList<>();
if (entry.getValue() != null && InitStandAttrUtil.selectionFieldList != null && InitStandAttrUtil.selectionFieldList.size() > 0 && InitStandAttrUtil.selectionFieldList.contains(name)) { // if (entry.getValue() != null && InitStandAttrUtil.selectionFieldList != null && InitStandAttrUtil.selectionFieldList.size() > 0 && InitStandAttrUtil.selectionFieldList.contains(name)) {
if (StringUtils.isNotBlank(entry.getValue().toString())) { // if (StringUtils.isNotBlank(entry.getValue().toString())) {
Object json = new JSONTokener(entry.getValue().toString()).nextValue(); // Object json = new JSONTokener(entry.getValue().toString()).nextValue();
if (json instanceof org.json.JSONArray) { // if (json instanceof org.json.JSONArray) {
valArr = com.alibaba.fastjson.JSONObject.parseArray(entry.getValue().toString(), String.class); // valArr = com.alibaba.fastjson.JSONObject.parseArray(entry.getValue().toString(), String.class);
} else { // } else {
value = entry.getValue().toString(); // value = entry.getValue().toString();
valArr = Arrays.asList(value.split(",")); // valArr = Arrays.asList(value.split(","));
} // }
if (!valArr.isEmpty()) { // if (!valArr.isEmpty()) {
value = dicTypeEODao.getDicNamesByCodes(valArr, ""); // value = dicTypeEODao.getDicNamesByCodes(valArr, "");
} // }
} // }
entry.setValue(value); // entry.setValue(value);
} // }
} // }
} // }
} // }
} // }
//
//
} //}
@@ -0,0 +1,310 @@
package com.adc.da.scheduledState.server;
import com.adc.da.common.GetBeanUtil;
import com.adc.da.mq.CreateStandMQService;
import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.search.bean.SearchCenter;
import com.adc.da.search.server.ResetSearchCenterService;
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
import com.adc.da.slrs.sarStandAttrInfo.service.ISarStandAttrInfoService;
import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao;
import com.adc.da.slrs.sarStandItems.entity.FindSarItemsPageReqDTO;
import com.adc.da.slrs.sarStandItems.entity.SarStandItems;
import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao;
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.utils.util.FieldConvertUtil;
import com.adc.da.utils.util.InitStandAttrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import java.sql.Clob;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年01月25日 3:34
*/
@Slf4j
public class UpdateStateStandSyncFz implements Runnable {
Logger logger = LoggerFactory.getLogger(UpdateStateStandSyncFz.class);
private DicTypeEODao dicTypeEODao;
private SarStandItemsDao standItemsDao;
private CreateStandMQService createStandMQService;
private IPersonCollectEOService personCollectEOService;
private SarStandAttrInfoDao sarStandAttrInfoEODao;
private SarStandardsInfoDao sarStandardsInfoDao;
private ISarStandardsInfoService iSarStandardsInfoService;
private ISarStandAttrInfoService sarStandAttrInfoEOService;
/**
* 根据配置文件设置是否开启定时器
*/
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
public UpdateStateStandSyncFz(){
dicTypeEODao = GetBeanUtil.getApplicationContext().getBean(DicTypeEODao.class);
standItemsDao = GetBeanUtil.getApplicationContext().getBean(SarStandItemsDao.class);
createStandMQService = GetBeanUtil.getApplicationContext().getBean(CreateStandMQService.class);
personCollectEOService = GetBeanUtil.getApplicationContext().getBean(IPersonCollectEOService.class);
sarStandAttrInfoEODao = GetBeanUtil.getApplicationContext().getBean(SarStandAttrInfoDao.class);
sarStandardsInfoDao = GetBeanUtil.getApplicationContext().getBean(SarStandardsInfoDao.class);
iSarStandardsInfoService = GetBeanUtil.getApplicationContext().getBean(ISarStandardsInfoService.class);
sarStandAttrInfoEOService = GetBeanUtil.getApplicationContext().getBean(ISarStandAttrInfoService.class);
}
/**
* 每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止
*/
@Override
public void run() {
try{
Thread.sleep(2000);
logger.info("每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
// 现行有效、即将实施、被代替 只查询国内标准
List<String> list = new ArrayList<>();
// 现行有效
list.add("vsaga7nwub");
// 即将实施
list.add("hb0iy9z23c");
// 被代替
list.add("qke0ckro2p");
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0");
wrapper.eq("STAND_TYPE","INLAND");
wrapper.in("A.TEXT_STATUS",list);
List<SarStandardsInfo> getStateStandScheduledList = sarStandardsInfoDao.getStateScheduledList(wrapper);
if(!getStateStandScheduledList.isEmpty()){
List<SarStandardsInfo> invalidStandToGBList = new ArrayList<>();
List<SarStandardsInfo> bdtStandToGBList = new ArrayList<>();
// 当前标准的标准类别是否是GB类 GB集合逻辑
getStateStandScheduledList.forEach(info -> {
if(StringUtils.isNotBlank(info.getBDTBZH())){
List<String> bdtList = Arrays.stream(info.getBDTBZH().split(",")).map(
s -> s.replace(" ","").trim()).collect(Collectors.toList());
// 查询等于GB的国内标准
QueryWrapper wrapperGB = new QueryWrapper();
wrapperGB.eq("SAR_STANDARDS_INFO.VALID_FLAG","0");
wrapperGB.eq("SAR_STANDARDS_INFO.STAND_SORT","GB");
wrapperGB.in("trim(replace(concat(SAR_STANDARDS_INFO.STAND_SORT,' ',SAR_STANDARDS_INFO.STAND_NUMBER,'-'," +
"SAR_STANDARDS_INFO.STAND_YEAR),' ',''))",bdtList);
List<SarStandardsInfo> queryGBList = sarStandardsInfoDao.selectList(wrapperGB);
if(!queryGBList.isEmpty()){
int queryGbCount = queryGBList.size();
//被代替标准号中所有有效标准的状态都是现行有效状态
List<SarStandardsInfo> yxList = queryGBList.stream().filter(info1 ->
"vsaga7nwub".equals(info1.getTextStatus())).collect(Collectors.toList());
//被代替标准号中所有有效标准的状态都是被代替状态
List<SarStandardsInfo> bdtStateList = queryGBList.stream().filter(info1 ->
"qke0ckro2p".equals(info1.getTextStatus())).collect(Collectors.toList());
//被代替标准号中所有有效标准的状态都是废止状态
List<SarStandardsInfo> fzList = queryGBList.stream().filter(info1 ->
"chblaarg77".equals(info1.getTextStatus())).collect(Collectors.toList());
// 满足其上存入更新废止逻辑 如果只有一个被代替标准 优先更新废止状态
if(yxList.size() == queryGbCount || bdtStateList.size() == queryGbCount || fzList.size() == queryGbCount){
invalidStandToGBList.add(info);
}else {
// 被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的
List<SarStandardsInfo> singleList = queryGBList.stream().filter(info1 -> {
if("hc99551723c".equals(info1.getTextStatus()) || "hb0iy9z23c".equals(info1.getTextStatus())
|| "vsaga7nwub".equals(info1.getTextStatus()) || "qke0ckro2p".equals(info1.getTextStatus())){
return true;
}
return false;
}).collect(Collectors.toList());
// 满足其上存入更新被代替逻辑
if(!singleList.isEmpty()){
bdtStandToGBList.add(info);
}
}
}
}
});
// 当前标准的标准类别是否是GB类 NOT GB集合逻辑
List<SarStandardsInfo> bdtStandToNotGBList = getStateStandScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getBDTBZH())){
List<String> bdtList = Arrays.stream(info.getBDTBZH().split(",")).map(
s -> s.replace(" ","").trim()).collect(Collectors.toList());
//发布、即将实施、现行有效、被代替
List<String> bdtStateList = new ArrayList<>();
// 发布
bdtStateList.add("hc99551723c");
// 作废
bdtStateList.add("hb0iy9z23c");
// 即将实施
bdtStateList.add("vsaga7nwub");
// 被代替
bdtStateList.add("qke0ckro2p");
// 查询不等于GB的国内标准 且 有效的被代替标准
QueryWrapper wrapperNotGB = new QueryWrapper();
wrapperNotGB.eq("VALID_FLAG","0");
wrapperNotGB.ne("STAND_SORT","GB");
wrapperNotGB.in("TEXT_STATUS",wrapperNotGB);
wrapperNotGB.in("trim(replace(concat(SAR_STANDARDS_INFO.STAND_SORT,' ',SAR_STANDARDS_INFO.STAND_NUMBER,'-'," +
"SAR_STANDARDS_INFO.STAND_YEAR),' ',''))",bdtList);
List<SarStandardsInfo> queryNotGBList = sarStandardsInfoDao.selectList(wrapperNotGB);
// 被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的
// 满足其上过滤更新被代替数据
return !queryNotGBList.isEmpty();
}
return false;
}).collect(Collectors.toList());
if(!invalidStandToGBList.isEmpty()){
logger.info("=============被代替标准号中所有有效标准的状态都是现行有效、被代替、废止状态 执行============");
// 文本状态更为废止状态
execStandDate(invalidStandToGBList,"chblaarg77");
}
if(!bdtStandToGBList.isEmpty()){
logger.info("=============GB=======被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 执行============");
// 文本状态更为被代替
execStandDate(bdtStandToGBList,"qke0ckro2p");
}
if(!bdtStandToNotGBList.isEmpty()){
logger.info("=============NOT GB ===被代替标准号中的有效标准的标准状态中有一个是发布、即将实施、现行有效、被代替状态的 执行============");
// 文本状态更为被代替
execStandDate(bdtStandToNotGBList,"qke0ckro2p");
}
}
logger.info("每天0点1分执行 国内标准文本状态被代替逻辑 标准自动变更废止:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){
logger.info(e.getMessage());
}
}
@Async
public void execStandDate(List<SarStandardsInfo> infoList, String textStatusStand) throws Exception {
List<SarStandardsInfo> list = new ArrayList<>();
for (SarStandardsInfo info : infoList) {
info.setTextStatus(textStatusStand);
standFunc(info);
createStandMQService.sendStandMQ(info,"update");
// 只批量更新文本字段
SarStandardsInfo newInfo = new SarStandardsInfo();
newInfo.setTextStatus(textStatusStand);
newInfo.setId(info.getId());
newInfo.setModifyTime(new Date());
list.add(newInfo);
}
if(!list.isEmpty()){
iSarStandardsInfoService.updateBatchById(list);
}
}
private void standFunc(SarStandardsInfo sarStandardsInfoEO) throws Exception {
attrInfoSearchDetails(sarStandardsInfoEO);
FindSarItemsPageReqDTO pageInfo = new FindSarItemsPageReqDTO();
pageInfo.setStandId(sarStandardsInfoEO.getId());
pageInfo.setFileType("FBGBJBD");
/**
* SarItemVO换为sarItemVOS
* List<SarItemVO> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo);
* .collect(Collectors.toMap(SarItemVO::getItemsNum, SarItemVO::getItemsName));
*/
List<SarStandItems> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo);
if (!sarItemVOS.isEmpty()) {
Map<String, String> collectMap = sarItemVOS.stream().filter((e) -> e.getItemsNum() != null && e.getItemsName() != null)
.collect(Collectors.toMap(SarStandItems::getItemsNum, SarStandItems::getTermsConditions));
sarStandardsInfoEO.setMapItems(collectMap);
}
if (sarStandardsInfoEO.getAttrInfoMap() != null) {
sarStandardsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarStandardsInfoEO.getAttrInfoMap()));
}
}
public void attrInfoSearchDetails(SarStandardsInfo row) throws Exception {
if (row != null) {
String fieldInfo = InitStandAttrUtil.queryField;
String collectId = personCollectEOService.queryCollectByUserAndId(row.getId());
row.setCollectId(collectId);
// 查询属性表数据
if (StringUtils.isNotBlank(fieldInfo)) {
Map<String, Object> getAttrMap = sarStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId());
if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) {
// 遍历修改所有clob类型的值
for (String clobField : InitStandAttrUtil.clobFieldList) {
Clob clobValue = (Clob) getAttrMap.get(clobField);
String fieldValue = FieldConvertUtil.ClobToString(clobValue);
getAttrMap.put(clobField, fieldValue);
}
}
row.setAttrInfoMap(getAttrMap);
}
Map<String, Object> getAttrMap = row.getAttrInfoMap();
if (getAttrMap != null && getAttrMap.size() > 0) {
for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) {
String name = entry.getKey();
String value = "";
List<String> valArr = new ArrayList<>();
if (entry.getValue() != null && InitStandAttrUtil.selectionFieldList != null && InitStandAttrUtil.selectionFieldList.size() > 0 && InitStandAttrUtil.selectionFieldList.contains(name)) {
if (StringUtils.isNotBlank(entry.getValue().toString())) {
Object json = new JSONTokener(entry.getValue().toString()).nextValue();
if (json instanceof org.json.JSONArray) {
valArr = com.alibaba.fastjson.JSONObject.parseArray(entry.getValue().toString(), String.class);
} else {
value = entry.getValue().toString();
valArr = Arrays.asList(value.split(","));
}
if (!valArr.isEmpty()) {
value = dicTypeEODao.getDicNamesByCodes(valArr, "");
}
}
entry.setValue(value);
}
}
}
}
}
}
@@ -0,0 +1,259 @@
package com.adc.da.scheduledState.server;
import com.adc.da.common.GetBeanUtil;
import com.adc.da.mq.CreateStandMQService;
import com.adc.da.person.service.IPersonCollectEOService;
import com.adc.da.scheduledState.utils.Util;
import com.adc.da.search.server.ResetSearchCenterService;
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
import com.adc.da.slrs.sarStandAttrInfo.service.ISarStandAttrInfoService;
import com.adc.da.slrs.sarStandItems.dao.SarStandItemsDao;
import com.adc.da.slrs.sarStandItems.entity.FindSarItemsPageReqDTO;
import com.adc.da.slrs.sarStandItems.entity.SarStandItems;
import com.adc.da.slrs.sarStandardsInfo.dao.SarStandardsInfoDao;
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
import com.adc.da.sys.dao.DicTypeEODao;
import com.adc.da.utils.util.FieldConvertUtil;
import com.adc.da.utils.util.InitStandAttrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import java.sql.Clob;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年01月25日 3:34
*/
@Slf4j
public class UpdateStateStandSyncSsAndYx implements Runnable {
Logger logger = LoggerFactory.getLogger(UpdateStateStandSyncSsAndYx.class);
private ResetSearchCenterService resetSearchCenterService;
private DicTypeEODao dicTypeEODao;
private SarStandItemsDao standItemsDao;
private CreateStandMQService createStandMQService;
private IPersonCollectEOService personCollectEOService;
private SarStandAttrInfoDao sarStandAttrInfoEODao;
private SarStandardsInfoDao sarStandardsInfoDao;
private ISarStandardsInfoService iSarStandardsInfoService;
private ISarStandAttrInfoService sarStandAttrInfoEOService;
/**
* 根据配置文件设置是否开启定时器
*/
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
public UpdateStateStandSyncSsAndYx(){
dicTypeEODao = GetBeanUtil.getApplicationContext().getBean(DicTypeEODao.class);
standItemsDao = GetBeanUtil.getApplicationContext().getBean(SarStandItemsDao.class);
createStandMQService = GetBeanUtil.getApplicationContext().getBean(CreateStandMQService.class);
personCollectEOService = GetBeanUtil.getApplicationContext().getBean(IPersonCollectEOService.class);
sarStandAttrInfoEODao = GetBeanUtil.getApplicationContext().getBean(SarStandAttrInfoDao.class);
sarStandardsInfoDao = GetBeanUtil.getApplicationContext().getBean(SarStandardsInfoDao.class);
iSarStandardsInfoService = GetBeanUtil.getApplicationContext().getBean(ISarStandardsInfoService.class);
sarStandAttrInfoEOService = GetBeanUtil.getApplicationContext().getBean(ISarStandAttrInfoService.class);
}
/**
* 每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑
*/
@Override
public void run() {
try{
Thread.sleep(2000);
logger.info("每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
// 发布、即将实施 只查询国内标准
List<String> list = new ArrayList<>();
// 发布
list.add("hc99551723c");
// 即将实施
list.add("hb0iy9z23c");
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("A.VALID_FLAG","0");
wrapper.eq("STAND_TYPE","INLAND");
wrapper.in("A.TEXT_STATUS",list);
List<SarStandardsInfo> getStateScheduledList = sarStandardsInfoDao.getStateScheduledList(wrapper);
if(!getStateScheduledList.isEmpty()){
// N个实施日期中大于当前日期
List<SarStandardsInfo> getStateScheduledListToIsAfter = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getSSRQ())){
List<String> dateList = Arrays.stream(info.getSSRQ().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsAfterList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否大于当前日期
return parse.isAfter(now);
}
return false;
}).collect(Collectors.toList());
return !dateIsAfterList.isEmpty();
}
return false;
}).collect(Collectors.toList());
// N个实施日期中小于当前时间
List<SarStandardsInfo> getStateScheduledListToIsBefore = getStateScheduledList.stream().filter(info -> {
if(StringUtils.isNotBlank(info.getSSRQ())){
List<String> dateList = Arrays.stream(info.getSSRQ().split(",")).map(String::trim).collect(Collectors.toList());
List<String> dateIsBeforeList = dateList.stream().filter(s -> {
if(Util.isValidDate(s)){
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDateTime parse = LocalDate.parse(s, dateTimeFormatter).atStartOfDay();
// 实施日期是否小于当前时间
return parse.isBefore(now);
}
return false;
}).collect(Collectors.toList());
return !dateIsBeforeList.isEmpty();
}
return false;
}).collect(Collectors.toList());
// N个实施日期中大于当前日期 执行逻辑 更为即将实施
if(!getStateScheduledListToIsAfter.isEmpty()){
logger.info("=============N个实施日期中大于当前日期 执行============");
// 文本状态更为即将实施
execStandDate(getStateScheduledListToIsAfter,"hb0iy9z23c");
}
// N个实施日期中小于当前时间 执行逻辑 更为现行有效
if(!getStateScheduledListToIsBefore.isEmpty()){
logger.info("=============N个实施日期中小于当前时间 执行============");
// 文本状态更为现行有效
execStandDate(getStateScheduledListToIsBefore,"vsaga7nwub");
}
}
logger.info("每天0点1分执行 国内标准文本状态 即将实施和现行有效状态自动变更逻辑:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){
logger.info(e.getMessage());
}
}
@Async
public void execStandDate(List<SarStandardsInfo> infoList, String textStatusStand) throws Exception {
List<SarStandardsInfo> list = new ArrayList<>();
for (SarStandardsInfo info : infoList) {
info.setTextStatus(textStatusStand);
standFunc(info);
createStandMQService.sendStandMQ(info,"update");
// 只批量更新文本字段
SarStandardsInfo newInfo = new SarStandardsInfo();
newInfo.setTextStatus(textStatusStand);
newInfo.setId(info.getId());
newInfo.setModifyTime(new Date());
list.add(newInfo);
}
if(!list.isEmpty()){
iSarStandardsInfoService.updateBatchById(list);
}
}
private void standFunc(SarStandardsInfo sarStandardsInfoEO) throws Exception {
attrInfoSearchDetails(sarStandardsInfoEO);
FindSarItemsPageReqDTO pageInfo = new FindSarItemsPageReqDTO();
pageInfo.setStandId(sarStandardsInfoEO.getId());
pageInfo.setFileType("FBGBJBD");
/**
* SarItemVO换为sarItemVOS
* List<SarItemVO> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo);
* .collect(Collectors.toMap(SarItemVO::getItemsNum, SarItemVO::getItemsName));
*/
List<SarStandItems> sarItemVOS = standItemsDao.querySarItemAndInterpretation(pageInfo);
if (!sarItemVOS.isEmpty()) {
Map<String, String> collectMap = sarItemVOS.stream().filter((e) -> e.getItemsNum() != null && e.getItemsName() != null)
.collect(Collectors.toMap(SarStandItems::getItemsNum, SarStandItems::getTermsConditions));
sarStandardsInfoEO.setMapItems(collectMap);
}
if (sarStandardsInfoEO.getAttrInfoMap() != null) {
sarStandardsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarStandardsInfoEO.getAttrInfoMap()));
}
}
public void attrInfoSearchDetails(SarStandardsInfo row) throws Exception {
if (row != null) {
String fieldInfo = InitStandAttrUtil.queryField;
String collectId = personCollectEOService.queryCollectByUserAndId(row.getId());
row.setCollectId(collectId);
// 查询属性表数据
if (StringUtils.isNotBlank(fieldInfo)) {
Map<String, Object> getAttrMap = sarStandAttrInfoEODao.selectStandFieldAndData(fieldInfo, row.getId());
if (InitStandAttrUtil.clobFieldList != null && !InitStandAttrUtil.clobFieldList.isEmpty()) {
// 遍历修改所有clob类型的值
for (String clobField : InitStandAttrUtil.clobFieldList) {
Clob clobValue = (Clob) getAttrMap.get(clobField);
String fieldValue = FieldConvertUtil.ClobToString(clobValue);
getAttrMap.put(clobField, fieldValue);
}
}
row.setAttrInfoMap(getAttrMap);
}
Map<String, Object> getAttrMap = row.getAttrInfoMap();
if (getAttrMap != null && getAttrMap.size() > 0) {
for (Map.Entry<String, Object> entry : getAttrMap.entrySet()) {
String name = entry.getKey();
String value = "";
List<String> valArr = new ArrayList<>();
if (entry.getValue() != null && InitStandAttrUtil.selectionFieldList != null && InitStandAttrUtil.selectionFieldList.size() > 0 && InitStandAttrUtil.selectionFieldList.contains(name)) {
if (StringUtils.isNotBlank(entry.getValue().toString())) {
Object json = new JSONTokener(entry.getValue().toString()).nextValue();
if (json instanceof org.json.JSONArray) {
valArr = JSONObject.parseArray(entry.getValue().toString(), String.class);
} else {
value = entry.getValue().toString();
valArr = Arrays.asList(value.split(","));
}
if (!valArr.isEmpty()) {
value = dicTypeEODao.getDicNamesByCodes(valArr, "");
}
}
entry.setValue(value);
}
}
}
}
}
}
@@ -0,0 +1,119 @@
package com.adc.da.search.conf;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年05月27日 10:17
*/
import com.adc.da.slrs.tsTask.dao.TbTaskDao;
import com.adc.da.slrs.tsTask.entity.TbTask;
import com.adc.da.slrs.tsTask.service.ITbTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
/**
* 动态定时器
*/
@Slf4j
@Component
public class SchedulerConf {
//数据库的任务
public static ConcurrentHashMap<String, TbTask> tasks = new ConcurrentHashMap<>(50);
//正在运行的任务
public static ConcurrentHashMap<String, ScheduledFuture> runTasks = new ConcurrentHashMap<>(50);
//线程池任务调度
private ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
@Autowired
TbTaskDao tbTaskDao;
@Autowired
ITbTaskService iTbTaskService;
/**
* 初始化线程池任务调度
*/
@Autowired
public SchedulerConf(){
this.threadPoolTaskScheduler.setPoolSize(50);
this.threadPoolTaskScheduler.setThreadNamePrefix("task-thread-");
this.threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.threadPoolTaskScheduler.initialize();
}
/**
* 获取所有数据库里的定时任务
*/
private void getAllTbTask(){
//查询所有,并put到tasks
SchedulerConf.tasks.clear();
List<TbTask> list = iTbTaskService.list();
list.forEach((task)-> SchedulerConf.tasks.put(task.getId(),task));
}
/**
* 根据定时任务id,启动定时任务
*/
public void start(String taskId){
try {
//重新获取最新执行任务周期
this.getAllTbTask();
TbTask tbTask = SchedulerConf.tasks.get(taskId);
//获取并实例化Runnable任务类
Class<?> clazz = Class.forName(tbTask.getTaskClass());
Runnable runnable = (Runnable)clazz.newInstance();
//Cron表达式
CronTrigger cron = new CronTrigger(tbTask.getTaskExp());
//执行,并put到runTasks
SchedulerConf.runTasks.put(taskId, Objects.requireNonNull(this.threadPoolTaskScheduler.schedule(runnable, cron)));
this.updateTaskStatus(taskId,1);
log.info("{},任务启动!",taskId);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
log.error("{},任务启动失败...",taskId);
e.printStackTrace();
}
}
/**
* 根据定时任务id,停止定时任务
*/
public void stop(String taskId){
SchedulerConf.runTasks.get(taskId).cancel(true);
SchedulerConf.runTasks.remove(taskId);
this.updateTaskStatus(taskId,0);
log.info("{},任务停止...",taskId);
}
/**
* 更新数据库动态定时任务状态
*/
private void updateTaskStatus(String taskId,int status){
TbTask task = iTbTaskService.getById(taskId);
task.setTaskStatus(status);
task.setUpdateTime(new Date());
iTbTaskService.updateById(task);
}
}
@@ -1,71 +1,78 @@
package com.adc.da.search.sync; package com.adc.da.search.sync;
import com.adc.da.common.GetBeanUtil;
import com.adc.da.search.bean.SearchCenter; import com.adc.da.search.bean.SearchCenter;
import com.adc.da.search.server.ResetSearchCenterService; import com.adc.da.search.server.ResetSearchCenterService;
import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao;
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
import com.adc.da.slrs.sarBussionessStandState.entity.SarBussionessStandState;
import com.adc.da.slrs.sarBussionessStandState.service.ISarBussionessStandStateService;
import com.adc.da.utils.util.DateUtil;
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.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.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @Description: TODO * @Description: TODO
* @author: super_liu * @author: super_liu
* @date: 2022年01月25日 3:34 * @date: 2022年01月25日 3:34
*/ */
@EnableScheduling
@Component
@Slf4j @Slf4j
public class restSearchSync { public class restSearchSync implements Runnable {
Logger logger = LoggerFactory.getLogger(restSearchSync.class); Logger logger = LoggerFactory.getLogger(restSearchSync.class);
@Autowired
private ResetSearchCenterService resetSearchCenterService; private ResetSearchCenterService resetSearchCenterService;
/** /**
* 根据配置文件设置是否开启定时器 * 根据配置文件设置是否开启定时器
*/ */
@Value("${isNotScheduled}") @Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器 private boolean isNotScheduled; //是否开启定时器
public restSearchSync(){
resetSearchCenterService = GetBeanUtil.getApplicationContext().getBean(ResetSearchCenterService.class);
}
/**
* 动态调用重置ES7天内标准数据
*/
@Override
public void run() {
try{
Thread.sleep(2000);
logger.info("每天0点1分执行 重置ES 自动更新、新增:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
SearchCenter searchCenter = new SearchCenter();
// ALL 执行全部
searchCenter.setExecType("ALL");
resetSearchCenterService.syncResetALLSearchCenter(searchCenter);
logger.info("每天0点1分执行 重置ES 自动更新、新增:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){
logger.info(e.getMessage());
}
}
// 每天0点1分执行 重置ES 自动更新、新增 // 每天0点1分执行 重置ES 自动更新、新增
// @Scheduled(cron="0 0 1 1 * ?") // @Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron = "0 1 0 * * ?") // @Scheduled(cron = "0 1 0 * * ?")
@Async // @Async
public void StandScheduledJobMonthBegin(){ // public void StandScheduledJobMonthBegin(){
if(isNotScheduled){ // if(isNotScheduled){
try{ // try{
Thread.sleep(2000); // Thread.sleep(2000);
logger.info("每天0点1分执行 重置ES 自动更新、新增:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01"); // logger.info("每天0点1分执行 重置ES 自动更新、新增:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01");
//
SearchCenter searchCenter = new SearchCenter(); // SearchCenter searchCenter = new SearchCenter();
// ALL 执行全部 // // ALL 执行全部
searchCenter.setExecType("ALL"); // searchCenter.setExecType("ALL");
resetSearchCenterService.syncResetALLSearchCenter(searchCenter); // resetSearchCenterService.syncResetALLSearchCenter(searchCenter);
//
logger.info("每天0点1分执行 重置ES 自动更新、新增:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01"); // logger.info("每天0点1分执行 重置ES 自动更新、新增:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01");
}catch(Exception e){ // }catch(Exception e){
logger.info(e.getMessage()); // logger.info(e.getMessage());
} // }
} // }
} // }
} }
@@ -0,0 +1,96 @@
package com.adc.da.slrs.tsTask.controller;
import com.adc.da.search.conf.SchedulerConf;
import com.adc.da.slrs.tsTask.service.ITbTaskService;
import oracle.ucp.proxy.annotation.Post;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.adc.da.slrs.tsTask.entity.TbTask;
import io.swagger.annotations.Api;
import com.adc.da.base.web.BaseController;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 动态定时任务表 前端控制器
* </p>
*
* @author super_liu
* @since 2022-05-27
*/
@RestController
@Api(tags = "动态定时任务表")
@RequestMapping("/tsTask/tb-task")
public class TbTaskController extends BaseController<TbTask> {
@Autowired
private SchedulerConf schedulerConf;
@Autowired
private ITbTaskService iTbTaskService;
/**
* 启动一个动态定时任务
* http://localhost:10085/tbTask/start/2
*/
@GetMapping("start/{taskId}")
public String start(@PathVariable("taskId") String taskId){
schedulerConf.start(taskId);
return "操作成功";
}
/**
* 停止一个动态定时任务
* http://localhost:10085/tbTask/stop/2
*/
@GetMapping("stop/{taskId}")
public String stop(@PathVariable("taskId") String taskId){
schedulerConf.stop(taskId);
return "操作成功";
}
/**
* 更新一个动态定时任务
* http://localhost:10085/tbTask/save?taskId=2&taskExp=0/2 * * * * ?&taskClass=cn.huanzi.qch.springboottimer.task.MyRunnable3
*/
@PostMapping("save")
public String save(TbTask task) throws IllegalAccessException {
//先更新表数据
TbTask tbTask = iTbTaskService.getById(task.getId());
//null值忽略
List<String> ignoreProperties = new ArrayList<>(7);
//反射获取Class的属性(Field表示类中的成员变量)
for (Field field : task.getClass().getDeclaredFields()) {
//获取授权
field.setAccessible(true);
//属性名称
String fieldName = field.getName();
//属性的值
Object fieldValue = field.get(task);
//找出值为空的属性,我们复制的时候不进行赋值
if(null == fieldValue){
ignoreProperties.add(fieldName);
}
}
//org.springframework.beans BeanUtils.copyProperties(A,B)A中的值付给B
BeanUtils.copyProperties(task, tbTask,ignoreProperties.toArray(new String[0]));
iTbTaskService.updateById(tbTask);
schedulerConf.tasks.clear();
//停止旧任务
schedulerConf.stop(tbTask.getId());
//重新启动
schedulerConf.start(tbTask.getId());
return "操作成功";
}
}
@@ -0,0 +1,18 @@
package com.adc.da.slrs.tsTask.dao;
import com.adc.da.slrs.tsTask.entity.TbTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* <p>
* 动态定时任务表 Mapper 接口
* </p>
*
* @author super_liu
* @since 2022-05-27
*/
@Repository
public interface TbTaskDao extends BaseMapper<TbTask> {
}
@@ -0,0 +1,57 @@
package com.adc.da.slrs.tsTask.entity;
import com.adc.da.base.entity.BaseEntity;
import java.time.LocalDateTime;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
/**
* <p>
* 动态定时任务表
* </p>
*
* @author super_liu
* @since 2022-05-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value="TbTask对象", description="动态定时任务表")
public class TbTask extends BaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "定时任务id")
@TableId("ID")
private String id;
@ApiModelProperty(value = "定时任务名称")
private String taskName;
@ApiModelProperty(value = "定时任务描述")
private String taskDesc;
@ApiModelProperty(value = "定时任务Cron表达式")
private String taskExp;
@ApiModelProperty(value = "定时任务状态,0停用 1启用")
private Integer taskStatus;
@ApiModelProperty(value = "定时任务的Runnable任务类完整路径")
private String taskClass;
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "创建时间")
private Date createTime;
}
@@ -0,0 +1,16 @@
package com.adc.da.slrs.tsTask.service;
import com.adc.da.slrs.tsTask.entity.TbTask;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 动态定时任务表 服务类
* </p>
*
* @author super_liu
* @since 2022-05-27
*/
public interface ITbTaskService extends IService<TbTask> {
}
@@ -0,0 +1,20 @@
package com.adc.da.slrs.tsTask.service.impl;
import com.adc.da.slrs.tsTask.entity.TbTask;
import com.adc.da.slrs.tsTask.dao.TbTaskDao;
import com.adc.da.slrs.tsTask.service.ITbTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 动态定时任务表 服务实现类
* </p>
*
* @author super_liu
* @since 2022-05-27
*/
@Service
public class TbTaskServiceImpl extends ServiceImpl<TbTaskDao, TbTask> implements ITbTaskService {
}
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.adc.da.slrs.tsTask.dao.TbTaskDao">
</mapper>