feat: There is no way the, buss state scheduled

This commit is contained in:
super_liu
2022-01-25 18:42:46 +08:00
parent 01a0a31d15
commit ccaf7d5b86
7 changed files with 403 additions and 13 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);
@@ -214,6 +214,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;
}
}
@@ -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);
@@ -366,6 +366,27 @@
</if>
</select>
<select id="queryByBussStateSync" resultMap="BaseResultMap"
parameterType="com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand">
SELECT
<include refid="Base_Column_List"/>,
DATE_SUB(DATE_ADD(ISSUE_TIME, INTERVAL 5 YEAR),INTERVAL 1 MONTH) AS reviewTime
FROM sar_bussioness_stand
WHERE stand_sort = 'Q/QCBFC'
AND ISSUE_TIME IS NOT NULL
AND DATE_FORMAT(DATE_SUB(DATE_ADD(ISSUE_TIME, INTERVAL 5 YEAR),INTERVAL 1 MONTH),'%Y-%m-%d')
BETWEEN DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d') AND DATE_ADD(DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d'),INTERVAL 1 DAY)
UNION
SELECT
<include refid="Base_Column_List"/>,
DATE_SUB(DATE_ADD(ISSUE_TIME, INTERVAL 3 YEAR),INTERVAL 1 MONTH) AS reviewTime
FROM sar_bussioness_stand
WHERE stand_sort != 'Q/QCBFC'
AND ISSUE_TIME IS NOT NULL
AND DATE_FORMAT(DATE_SUB(DATE_ADD(ISSUE_TIME, INTERVAL 3 YEAR),INTERVAL 1 MONTH),'%Y-%m-%d')
BETWEEN DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d') AND DATE_ADD(DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d'),INTERVAL 1 DAY)
</select>
<!-- 分页查询条件 -->
<sql id="standSort_in">
@@ -32,19 +32,19 @@
and DATE_FORMAT(REVIEW_TIME, '%Y-%m-%d') between DATE_FORMAT(#{reviewTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{reviewTimeEnd}, '%Y-%m-%d')
</if>
<if test="reviewTimeStart != null and reviewTimeStart != '' and reviewTimeEnd == null and reviewTimeEnd == ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &gt;= DATE_FORMAT(#{reviewTimeStart}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &gt;= DATE_FORMAT(#{reviewTimeStart}, '%Y-%m-%d')
</if>
<if test="reviewTimeStart == null and reviewTimeStart == '' and reviewTimeEnd != null and reviewTimeEnd != ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &lt;= DATE_FORMAT(#{reviewTimeEnd}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &lt;= DATE_FORMAT(#{reviewTimeEnd}, '%Y-%m-%d')
</if>
<if test="issueTimeStart != null and issueTimeStart != '' and issueTimeEnd != null and issueTimeEnd != ''">
and DATE_FORMAT(REVIEW_TIME, '%Y-%m-%d') between DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d')
</if>
<if test="issueTimeStart != null and issueTimeStart != '' and issueTimeEnd == null and issueTimeEnd == ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &gt;= DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &gt;= DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d')
</if>
<if test="issueTimeStart == null and issueTimeStart == '' and issueTimeEnd != null and issueTimeEnd != ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &lt;= DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &lt;= DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d')
</if>
</trim>
</sql>
@@ -58,19 +58,19 @@
and DATE_FORMAT(REVIEW_TIME, '%Y-%m-%d') between DATE_FORMAT(#{reviewTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{reviewTimeEnd}, '%Y-%m-%d')
</if>
<if test="reviewTimeStart != null and reviewTimeStart != '' and reviewTimeEnd == null and reviewTimeEnd == ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &gt;= DATE_FORMAT(#{reviewTimeStart}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &gt;= DATE_FORMAT(#{reviewTimeStart}, '%Y-%m-%d')
</if>
<if test="reviewTimeStart == null and reviewTimeStart == '' and reviewTimeEnd != null and reviewTimeEnd != ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &lt;= DATE_FORMAT(#{reviewTimeEnd}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &lt;= DATE_FORMAT(#{reviewTimeEnd}, '%Y-%m-%d')
</if>
<if test="issueTimeStart != null and issueTimeStart != '' and issueTimeEnd != null and issueTimeEnd != ''">
and DATE_FORMAT(REVIEW_TIME, '%Y-%m-%d') between DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d')
</if>
<if test="issueTimeStart != null and issueTimeStart != '' and issueTimeEnd == null and issueTimeEnd == ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &gt;= DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &gt;= DATE_FORMAT(#{issueTimeStart}, '%Y-%m-%d')
</if>
<if test="issueTimeStart == null and issueTimeStart == '' and issueTimeEnd != null and issueTimeEnd != ''">
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%D') &lt;= DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d')
and DATE_FORMAT(REVIEW_TIME,'%Y-%m-%d') &lt;= DATE_FORMAT(#{issueTimeEnd}, '%Y-%m-%d')
</if>
</trim>
</sql>