文本状态更新被代替,废止

This commit is contained in:
zhaokaiyao@91isoft.com
2021-09-04 15:07:15 +08:00
parent 28e8ba6c88
commit 2e83db6d98
@@ -13,6 +13,7 @@ import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
import com.adc.da.util.UUIDUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
@@ -21,9 +22,9 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@EnableScheduling
@Component
@@ -173,8 +174,8 @@ public class ScheduledJob {
/**
* 定时更新文本状态
*/
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
// @Scheduled(cron="*/5 * * * * ?")
// @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
@Scheduled(cron="*/5 * * * * ?")
@Async
public void TextStatusSchedulingTasks() {
QueryWrapper<SarStandardsInfo> wrapper = new QueryWrapper<>();
@@ -205,37 +206,56 @@ public class ScheduledJob {
/**
* 被多个标准代替的标准变为“被代替”,只一个代替的自动变为“废止”
* 被多个标准代替的标准变为“被代替”,只一个标准代替的自动变为“废止”
*/
QueryWrapper<SarStandAttrInfo> columns = new QueryWrapper<>();
columns.select("DTBJH","STAND_ID");
List<Map<String, Object>> mapsDTBZH = sarStandAttrInfoDao.selectMaps(columns);
QueryWrapper<SarStandardsInfo> columns = new QueryWrapper<>();
mapsDTBZH.forEach(item->{
if (item.get("DTBJH")!=null && !item.get("DTBJH").toString().equals("")){
String dtbzh = item.get("DTBJH").toString();
String[] split = dtbzh.split(",");
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
sarStandardsInfo.setId(item.get("STAND_ID").toString());
columns.select("REPLACE_STAND_NUM");
//查询代替标准字段得到一个 被代替了的标准的id的键值对列表
List<Map<String, Object>> replaceStandIdMaps = sarStandardsInfoDao.selectMaps(columns);
HashMap<String, Integer> replaceIdCountMap = new HashMap<>();
//一个被代替标准号时,文本状态更新为废止状态,两个及以上时更新为被代替状态
switch (split.length){
case 0 :
break;
case 1 :
sarStandardsInfo.setTextStatus("chblaarg77");//废止状态
break;
default:
sarStandardsInfo.setTextStatus("qke0ckro2p");//被代替状态
}
try {
sarStandardsInfoDao.updateById(sarStandardsInfo);
}catch (Exception e){
System.out.println("代替标准状态更新:id为"+item.get("STAND_ID").toString()+"文本状态更新失败");
}
replaceStandIdMaps.forEach(item->{
if (item!=null){
//此标准代替的标准的id数组
String[] standIds = item.get("REPLACE_STAND_NUM").toString().split(",");
for (String standId : standIds) {
//如果代替标准id已存在则映射为2不存在则添加并映射为1
if (replaceIdCountMap.containsKey(standId)) {
replaceIdCountMap.replace(standId,2);
}else {
replaceIdCountMap.put(standId, 1);
}
}
}
});
//一个被代替标准号时,文本状态更新为废止状态,两个及以上时更新为被代替状态
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
for (String key : replaceIdCountMap.keySet()) {
switch (replaceIdCountMap.get(key)){
case 1 :
sarStandardsInfo.setTextStatus("chblaarg77");//废止状态
sarStandardsInfo.setId(key);
break;
default :
sarStandardsInfo.setTextStatus("qke0ckro2p");//被代替状态
sarStandardsInfo.setId(key);
break;
}
});
try {
sarStandardsInfoDao.updateById(sarStandardsInfo);
}catch (Exception e){
System.out.println("代替标准状态更新:id为"+key+"文本状态更新失败");
}
}
}
}