Merge branch 'develop_master' into FOTON

This commit is contained in:
super_liu
2022-01-25 20:15:57 +08:00
10 changed files with 440 additions and 29 deletions
@@ -22,6 +22,8 @@ import java.util.List;
@Repository
public interface SarBussionessStandDao extends BaseMapper<SarBussionessStand> {
List<SarBussionessStand> queryByBussStateSync(SarBussionessStand sarBussionessStand);
SarBussionessStand getStandInfoByReviseStatus(String reviseStatus);
SarBussionessStand selectByPrimaryKey(String standId);
@@ -219,6 +219,17 @@ public class SarBussionessStand extends BaseEntity {
@TableField(exist = false)
private List<SarStandAttrDetailsEO> attrInfoList = new ArrayList<>();
/**
* 新增条件字段
* @return
*/
@TableField(exist = false)
private String reviewTime;
@TableField(exist = false)
private String issueTimeStart;
@TableField(exist = false)
private String issueTimeEnd;
public static long getSerialVersionUID() {
return serialVersionUID;
}
@@ -5,7 +5,9 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -30,7 +32,7 @@ public class SarBussionessStandState extends BaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键/企业标准信息主键")
@TableField("ID")
@TableId(value = "ID", type = IdType.UUID)
private String id;
@ApiModelProperty(value = "企标ID")
@@ -47,11 +49,13 @@ public class SarBussionessStandState extends BaseEntity {
@ApiModelProperty(value = "复审时间")
@TableField("REVIEW_TIME")
private Date reviewTime;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
private String reviewTime;
@ApiModelProperty(value = "发布日期")
@TableField("ISSUE_TIME")
private Date issueTime;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
private String issueTime;
@ApiModelProperty(value = "复审结果 1 修订、2 废止、3 继续有效")
@TableField("REVIEW_RESULTS")
@@ -63,11 +67,13 @@ public class SarBussionessStandState extends BaseEntity {
@ApiModelProperty(value = "创建日期")
@TableField("CREATION_TIME")
private Date creationTime;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private String creationTime;
@ApiModelProperty(value = "更新日期")
@TableField("MODIFY_TIME")
private Date modifyTime;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private String modifyTime;
@TableField("VALID_FLAG")
private Integer validFlag;
@@ -0,0 +1,257 @@
package com.adc.da.slrs.sarBussionessStandState.sync;
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.util.DateUtils;
import com.adc.da.utils.util.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: TODO
* @author: super_liu
* @date: 2022年01月25日 3:34
*/
@EnableScheduling
@Component
@Slf4j
public class StateSync {
Logger logger = LoggerFactory.getLogger(StateSync.class);
@Autowired
private SarBussionessStandDao sarBussionessStandDao;
@Autowired
private ISarBussionessStandStateService bussionessStandStateService;
/**
* 根据配置文件设置是否开启定时器
*/
@Value("${isNotScheduled}")
private boolean isNotScheduled; //是否开启定时器
// 月初
@Scheduled(cron="0 0 1 1 * ?")
// @Scheduled(cron="*/5 * * * * ?")
@Async
public void StandScheduledJobMonthBegin(){
if(isNotScheduled){
try{
Thread.sleep(2000);
logger.info("月初:"+Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---START-01");
String nowFirst = DateUtil.firstOneDay(DateUtil.printDate(new Date()));
String nowFin = DateUtil.finOneDay(DateUtil.printDate(new Date()));
String nowFinByQuery = DateUtil.addDay(DateUtil.finOneDay(DateUtil.printDate(new Date())),1);
System.out.println("当前月第一日:"+nowFirst);
System.out.println("当前月最后一日:"+nowFin);
SarBussionessStand stand = new SarBussionessStand();
stand.setIssueTimeStart(nowFirst);
stand.setIssueTimeEnd(nowFin);
List<SarBussionessStand> standList = sarBussionessStandDao.queryByBussStateSync(stand);
if(!standList.isEmpty()){
List<SarBussionessStandState> filterList = new ArrayList<>();
standList.forEach(sarBussionessStand -> {
SarBussionessStandState state = new SarBussionessStandState();
state.setStandId(sarBussionessStand.getId());
state.setStandCode(sarBussionessStand.getStandCode());
state.setStandName(sarBussionessStand.getStandName());
if(DateUtil.printToDate(sarBussionessStand.getIssueTime()) != null){
state.setIssueTime(sarBussionessStand.getIssueTime());
}
if(DateUtil.printToDate(sarBussionessStand.getReviewTime()) != null){
state.setReviewTime(sarBussionessStand.getReviewTime());
}
state.setCreationTime(DateUtil.printDateAll(new Date()));
state.setModifyTime(DateUtil.printDateAll(new Date()));
filterList.add(state);
});
List<SarBussionessStandState> insList = new ArrayList<>();
List<SarBussionessStandState> updList = new ArrayList<>();
QueryWrapper wrapper = new QueryWrapper();
wrapper.isNull("REVIEW_RESULTS");
wrapper.between("REVIEW_TIME",nowFirst,nowFinByQuery);
List<SarBussionessStandState> stateList = bussionessStandStateService.list(wrapper);
if(!stateList.isEmpty()){
// 差集 (list1 - list2) 新增复审表
List<SarBussionessStandState> distinctByUniqueList = filterList.stream()
.filter(item -> !stateList.stream()
.map(SarBussionessStandState::getStandId)
.collect(Collectors.toList())
.contains(item.getStandId()))
.collect(Collectors.toList());
insList.addAll(distinctByUniqueList);
// 交集 更新复审表
List<SarBussionessStandState> intersection = filterList.stream()
.filter(item -> stateList.stream()
.map(SarBussionessStandState::getStandId)
.collect(Collectors.toList())
.contains(item.getStandId()))
.collect(Collectors.toList());
// jdk8 stream 更新集合批量赋值ID
List<SarBussionessStandState> updSetList = intersection.stream()
.map(upObj -> stateList.stream()
.filter(stateQueryObj -> upObj.getStandId().equals(stateQueryObj.getStandId()))
.findFirst()
.map(stateQueryObj -> {
upObj.setId(stateQueryObj.getId());
upObj.setModifyTime(DateUtil.printDateAll(new Date()));
return upObj;
}).orElse(null))
.collect(Collectors.toList());
updList.addAll(updSetList);
}else {
// 新增复审表
insList.addAll(filterList);
}
// 复审表操作逻辑 新增
if(!insList.isEmpty()){
bussionessStandStateService.saveBatch(insList);
}
// 复审表操作逻辑 更新
if(!updList.isEmpty()){
// List<SarBussionessStandState> updListResult = updList.stream().peek(p -> p.setModifyTime(DateUtil.printDateAll(new Date()))).collect(Collectors.toList());
bussionessStandStateService.updateBatchById(updList);
}
}
logger.info("月初:"+Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---End-01");
}catch(Exception e){
logger.info(e.getMessage());
}
}
}
// 月末
@Scheduled(cron="0 0 1 28-31 * ?")
// @Scheduled(cron="*/5 * * * * ?")
@Async
public void StandScheduledJobMonthEnd(){
if(isNotScheduled){
try{
Thread.sleep(2000);
// 判断当前日期是否为月末
Date date = new Date();
if(isLastDayOfMonth(date)){
logger.info("月末:"+Thread.currentThread().getName() + " cron=0 0 1 28-31 * ? --- " + new Date()+"---START-01");
String nextFirst = DateUtil.printDate(DateUtil.nextMonthFirstDate());
String nextFin = DateUtil.finOneDay(DateUtil.printDate(DateUtil.nextMonthFirstDate()));
String nextFinByQuery = DateUtil.addDay(DateUtil.finOneDay(DateUtil.printDate(DateUtil.nextMonthFirstDate())),1);
System.out.println("下个月第一日:"+ nextFirst);
System.out.println("下个月最后一日:"+nextFin);
SarBussionessStand stand = new SarBussionessStand();
stand.setIssueTimeStart(nextFirst);
stand.setIssueTimeEnd(nextFin);
List<SarBussionessStand> standList = sarBussionessStandDao.queryByBussStateSync(stand);
if(!standList.isEmpty()){
List<SarBussionessStandState> filterList = new ArrayList<>();
standList.forEach(sarBussionessStand -> {
SarBussionessStandState state = new SarBussionessStandState();
state.setStandId(sarBussionessStand.getId());
state.setStandCode(sarBussionessStand.getStandCode());
state.setStandName(sarBussionessStand.getStandName());
if(DateUtil.printToDate(sarBussionessStand.getIssueTime()) != null){
state.setIssueTime(sarBussionessStand.getIssueTime());
}
if(DateUtil.printToDate(sarBussionessStand.getReviewTime()) != null){
state.setReviewTime(sarBussionessStand.getReviewTime());
}
state.setCreationTime(DateUtil.printDateAll(new Date()));
state.setModifyTime(DateUtil.printDateAll(new Date()));
filterList.add(state);
});
List<SarBussionessStandState> insList = new ArrayList<>();
List<SarBussionessStandState> updList = new ArrayList<>();
QueryWrapper wrapper = new QueryWrapper();
wrapper.isNull("REVIEW_RESULTS");
wrapper.between("REVIEW_TIME",nextFirst,nextFinByQuery);
List<SarBussionessStandState> stateList = bussionessStandStateService.list(wrapper);
if(!stateList.isEmpty()){
// 差集 (list1 - list2) 新增复审表
List<SarBussionessStandState> distinctByUniqueList = filterList.stream()
.filter(item -> !stateList.stream()
.map(SarBussionessStandState::getStandId)
.collect(Collectors.toList())
.contains(item.getStandId()))
.collect(Collectors.toList());
insList.addAll(distinctByUniqueList);
// 交集 更新复审表
List<SarBussionessStandState> intersection = filterList.stream()
.filter(item -> stateList.stream()
.map(SarBussionessStandState::getStandId)
.collect(Collectors.toList())
.contains(item.getStandId()))
.collect(Collectors.toList());
// jdk8 stream 更新集合批量赋值ID
List<SarBussionessStandState> updSetList = intersection.stream()
.map(upObj -> stateList.stream()
.filter(stateQueryObj -> upObj.getStandId().equals(stateQueryObj.getStandId()))
.findFirst()
.map(stateQueryObj -> {
upObj.setId(stateQueryObj.getId());
upObj.setModifyTime(DateUtil.printDateAll(new Date()));
return upObj;
}).orElse(null))
.collect(Collectors.toList());
updList.addAll(updSetList);
}else {
// 新增复审表
insList.addAll(filterList);
}
// 复审表操作逻辑 新增
if(!insList.isEmpty()){
bussionessStandStateService.saveBatch(insList);
}
// 复审表操作逻辑 更新
if(!updList.isEmpty()){
// List<SarBussionessStandState> updListResult = updList.stream().peek(p -> p.setModifyTime(DateUtil.printDateAll(new Date()))).collect(Collectors.toList());
bussionessStandStateService.updateBatchById(updList);
}
}
logger.info("月末:"+Thread.currentThread().getName() + " cron=0 0 1 28-31 * ? --- " + new Date()+"---End-01");
}else {
logger.info("月末:"+Thread.currentThread().getName() + " cron=0 0 1 28-31 * ? --- " + new Date()+"当前日期不是最后一日---End-01");
}
}catch(Exception e){
logger.info(e.getMessage());
}
}
}
/** * 判断给定日期是否为月末的一天 * * @param date * @return true:是|false:不是 */
public static boolean isLastDayOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1));
if (calendar.get(Calendar.DAY_OF_MONTH) == 1){
return true;
}
return false;
}
}
@@ -325,21 +325,26 @@ public class SarStandProjectLibraryController extends BaseController<SarStandPro
List<String> managementHostList = new ArrayList<>();
List<String> developmentHostList = new ArrayList<>();
List<String> categoryList = new ArrayList<>();
List<String> statusList=new ArrayList<>();
for(SarStandProjectLibrary sarStandProjectLibrary1 : list){
if(!managementHostList.contains(sarStandProjectLibrary1.getManagementHostName())){
if(null!= sarStandProjectLibrary1.getManagementHostName()&& !"".equals(sarStandProjectLibrary1.getManagementHostName()) && !managementHostList.contains(sarStandProjectLibrary1.getManagementHostName())){
managementHostList.add(sarStandProjectLibrary1.getManagementHostName());
}
if(!developmentHostList.contains(sarStandProjectLibrary1.getDevelopmentHostName())){
if(null!= sarStandProjectLibrary1.getDevelopmentHostName()&& !"".equals(sarStandProjectLibrary1.getDevelopmentHostName()) && !developmentHostList.contains(sarStandProjectLibrary1.getDevelopmentHostName())){
developmentHostList.add(sarStandProjectLibrary1.getDevelopmentHostName());
}
if(!categoryList.contains(sarStandProjectLibrary1.getCategoryName())){
if(null!= sarStandProjectLibrary1.getCategoryName()&& !"".equals(sarStandProjectLibrary1.getCategoryName()) && !categoryList.contains(sarStandProjectLibrary1.getCategoryName())){
categoryList.add(sarStandProjectLibrary1.getCategoryName());
}
if (null!= sarStandProjectLibrary1.getProjectStatus()&& !"".equals(sarStandProjectLibrary1.getProjectStatus()) && !statusList.contains(sarStandProjectLibrary1.getProjectStatus())){
statusList.add(sarStandProjectLibrary1.getProjectStatus());
}
}
QuerySelectRspDTO querySelectRspDTO = QuerySelectRspDTO.builder()
.managementHostList(managementHostList)
.developmentHostList(developmentHostList)
.categoryList(categoryList)
.statusList(statusList)
.build();
return Result.success(querySelectRspDTO);
}
@@ -14,4 +14,6 @@ public class QuerySelectRspDTO {
private List<String> developmentHostList;
private List<String> categoryList;
private List<String> statusList;
}
@@ -11,6 +11,93 @@ import java.util.*;
*/
public class DateUtil {
public static String addDay(String date, Integer dayInt) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date today = null;
try {
today = sdf.parse(date);
} catch (ParseException e) {
}
String endDate = sdf.format(today);//当前日期
Calendar theCa = Calendar.getInstance();
theCa.setTime(today);
theCa.add(theCa.DATE, +dayInt);//最后一个数字30可改,30天的意思
Date start = theCa.getTime();
String startDate = sdf.format(start);//三十天之前日期
return startDate;
}
public static Date nextMonthFirstDate() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.MONTH, 1);
return calendar.getTime();
}
public static Date printToDate(String date) {
Date date1 = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
date1 = sdf.parse(date);
}catch (Exception e){
e.getMessage();
}
return date1;
}
public static String printDateAll(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
public static String printDate(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
public static String firstOneDay(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date today = null;
String startDate = "";
try {
today = sdf.parse(date);
String endDate = sdf.format(today);//当前日期
Calendar theCa = Calendar.getInstance();
theCa.setTime(today);
theCa.add(Calendar.MONTH, 0);
theCa.set(Calendar.DAY_OF_MONTH, 1);
Date start = theCa.getTime();
startDate = sdf.format(start);
} catch (ParseException e) {
}
return startDate;
}
public static String finOneDay(String date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date today = null;
String startDate = "";
try {
today = sdf.parse(date);
String endDate = sdf.format(today);//当前日期
Calendar theCa = Calendar.getInstance();
theCa.setTime(today);
theCa.set(Calendar.DAY_OF_MONTH, 1);
theCa.set(Calendar.DATE, theCa.getActualMaximum(Calendar.DATE));
Date start = theCa.getTime();
startDate = sdf.format(start);
} catch (ParseException e) {
}
return startDate;
}
/**
* 取起始时间到结束时间 所有的时间
* @param startTime
@@ -115,6 +202,12 @@ public class DateUtil {
public static void main(String[] args) {
System.out.println(printDate(new Date()));
System.out.println(firstOneDay(printDate(new Date())));
System.out.println(finOneDay(printDate(new Date())));
System.out.println(addDay(finOneDay(printDate(new Date())),2));
System.out.println(printDate(nextMonthFirstDate()));
System.out.println(finOneDay(printDate(nextMonthFirstDate())));
String utcTime = "2021-04-15T01:43:54.296Z";
String time = formatStrUTCToDateStr("2021-04-15T01:43:54.296Z");
System.out.println("utcTime 转换前:" + utcTime);