Merge branch 'develop_3' into 'FOTON'

Develop 3

See merge request LiuChao/foton-slrs-system-rest!321
This commit is contained in:
王夏晖
2021-12-25 09:33:08 +08:00
7 changed files with 159 additions and 68 deletions
@@ -5,6 +5,7 @@ import com.adc.da.scheduled.dao.SarStandardItemDao;
import com.adc.da.scheduled.dao.SarStandardWarningDao;
import com.adc.da.scheduled.entity.TermDTO;
import com.adc.da.slrs.ActivityDatas.entity.DataList;
import com.adc.da.slrs.sarStandAttrInfo.dao.SarStandAttrInfoDao;
import com.adc.da.slrs.sarStandAttrInfo.entity.SarStandAttrInfo;
@@ -17,8 +18,10 @@ import com.adc.da.util.UUIDUtils;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
@@ -28,8 +31,10 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -68,8 +73,9 @@ public class ScheduledJob {
// @PostConstruct //程序启动时执行一次
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
// @Scheduled(cron="*/5 * * * * ?")
// @Scheduled(fixedDelay = 120000)
@Async
public void WarningSchedulingTasks() {
public void warningSchedulingTasks() {
Logger logger = LoggerFactory.getLogger(ScheduledJob.class);
/**
@@ -93,6 +99,16 @@ public class ScheduledJob {
mark:标识预警的种类 stand 标准 item 条款
*/
// Runnable runnable = () -> {
// try {
// Thread.sleep(60000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// };
//
// runnable.run();
//删除不在预警范围的标准
int remove = sarStandardWarningDao.autoCancelWarning();
@@ -100,17 +116,39 @@ public class ScheduledJob {
logger.info("取消"+remove+"条预警");
logger.info("开始执行预警!!!");
logger.info("==========================================================================");
//预警期限(当前日期至3个月后)
TermDTO term = new TermDTO();
//查询符合预警期限的标准 多个
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term);
TermDTO term = new TermDTO(); //预警期限(当前日期至3个月后)
List<WarningDate> warningDateList = sarStandardWarningDao.getWarningDate(term); //查询符合预警期限的标准 多个
ArrayList<WarningDate> data = new ArrayList<>();
warningDateList.forEach(item->{
item.setId(UUIDUtils.randomUUID20());
for (String s : item.getSSRQ().split(",")) {
String pattern = "^\\d{4}-\\d{1,2}-\\d{1,2}";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(s);
//判断是否是日期格式
if (m.matches()) {
WarningDate warningDate = new WarningDate();
BeanUtils.copyProperties(item, warningDate);
warningDate.setId(UUIDUtils.randomUUID20());
warningDate.setSSRQ(s);
data.add(warningDate);
}
}
});
iWarningDateService.remove(null); //清空标准的日期子表
iWarningDateService.saveBatch(warningDateList); // 保存进入标准的日期子表 保存标准的实施日期 新车型实施日期 在产车实施日期 多个
List<EarlyWarningEO> warningList = sarStandardWarningDao.getWarningId(term); //联接标准的日期子表 和分解单表 查询符合预警期限的标准和分解项
//清空标准的日期子表
iWarningDateService.remove(null);
// 保存进入标准的日期子表 保存标准的实施日期 新车型实施日期 在产车实施日期 多个
iWarningDateService.saveBatch(data);
//联接标准的日期子表 和分解单表 查询符合预警期限的标准和分解项
List<EarlyWarningEO> warningList = sarStandardWarningDao.getWarningId(term);
warningList.forEach(item->{
item.setId(UUIDUtils.randomUUID20());
@@ -0,0 +1,23 @@
package com.adc.da.scheduled.controller;
import com.adc.da.scheduled.ScheduledJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/${restPath}/scheduled")
public class Controller {
@Autowired
ScheduledJob scheduledJob;
@PostMapping
public void run(){
scheduledJob.warningSchedulingTasks();
}
}
@@ -4,15 +4,19 @@ import com.alibaba.druid.sql.visitor.functions.Char;
import com.sun.org.apache.bcel.internal.generic.NEW;
import lombok.Data;
import lombok.experimental.Accessors;
import net.bytebuddy.asm.Advice;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.format.annotation.DateTimeFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.*;
@Data
@Accessors(chain = true)
@@ -26,11 +30,15 @@ public class TermDTO {
private String endDate;
// private String str;
private String termStr;
private List<String> termList;
public TermDTO() {
LocalDate starDate = LocalDate.now();//系统当前日期
LocalDate endDate = LocalDate.now().plusMonths(3);//系统当前日期3个月后
//系统当前日期
LocalDate starDate = LocalDate.now();
//系统当前日期3个月后
LocalDate endDate = LocalDate.now().plusMonths(3);
convertToStr(starDate,endDate);
}
@@ -49,7 +57,9 @@ public class TermDTO {
int compareEnd = dateString.compareTo(startDate);
if (compareStart >= 0 && compareEnd <=0) {
return true;
} else return false;
} else {
return false;
}
}
@@ -61,7 +71,7 @@ public class TermDTO {
* @param startDate
* @param endDate
*/
public void convertToStr(LocalDate startDate,LocalDate endDate){
private void convertToStr(LocalDate startDate,LocalDate endDate){
/**
* 使用DateTimeFormatter线程安全,但不晓得怎么支持Date类型转换为字符串 ¯\_(ツ)_/¯
@@ -72,5 +82,38 @@ public class TermDTO {
this.startDate =formatter.format(startDate);
this.endDate=formatter.format(endDate);
this.termList= forDate();
this.termStr= StringUtils.join(this.termList,"|");
}
private List<String> forDate() {
// 日期格式化
LinkedList<String> termList = new LinkedList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
// 起始日期
Date d1 = sdf.parse(this.startDate);
// 结束日期
Date d2 = sdf.parse(this.endDate);
Date tmp = d1;
Calendar dd = Calendar.getInstance();
dd.setTime(d1);
// 循环之间的每一天
while (tmp.getTime() < d2.getTime()) {
tmp = dd.getTime();
termList.add(sdf.format(tmp));
// 天数加上1
dd.add(Calendar.DAY_OF_MONTH, 1);
}
} catch (ParseException e) {
e.printStackTrace();
}
return termList;
}
}
@@ -14,7 +14,7 @@ public class WarningDate {
@TableField("law_id")
private String lawId;
@TableField("itemId")
@TableField("item_id")
private String itemId;
@TableField("SSRQ")
@@ -66,30 +66,30 @@
<select id="getSarStandUnqualifiedCount" resultType="java.lang.Integer">
SELECT
count(c.ID)
count(*)
FROM
(
SELECT b.*,sar_standards_info.STAND_TYPE as standType FROM (
SELECT (@i:=@i+1) as rows,sar_stand_unqualified.* FROM
sar_stand_unqualified,(SELECT @i:=0)j
SELECT (@i:=@i+1) as rows,sar_stand_unqualified.* ,sar_standards_info.STAND_TYPE as standType , concat(ts_user.UNAME,concat('(',concat(ts_user.USID,')'))) as dutyEngineerName , ts_institution.name as responsibleUnit FROM
(sar_stand_unqualified,(SELECT @i:=0)j)
left join sar_standards_info on sar_stand_unqualified.STAND_ID = sar_standards_info.id
left join ts_user on ts_user.USID = sar_stand_unqualified.DUTY_ENGINEER
left join ts_institution on ts_institution.id=ts_user.INSTITUTION_ID
WHERE
close_state = #{sar.closeState}
sar_stand_unqualified.close_state = #{sar.closeState}
<if test="sar.standId != null and sar.standId != '' ">
and STAND_ID = #{sar.standId}
and sar_stand_unqualified.STAND_ID = #{sar.standId}
</if>
<if test="sar.productName != null and sar.productName != '' ">
and PRODUCT_NAME like concat(concat('%',#{sar.productName}),'%')
and sar_stand_unqualified.PRODUCT_NAME like concat(concat('%',#{sar.productName}),'%')
</if>
<if test="sar.responsibleUnit != null and sar.responsibleUnit != '' ">
and RESPONSIBLE_UNIT = #{sar.responsibleUnit}
and ts_institution.name like concat('%',#{sar.responsibleUnit},'%')
</if>
<if test="sar.standSerialNumber != null and sar.standSerialNumber != '' ">
and (REPLACE(STAND_SERIAL_NUMBER,' ','') like concat(concat('%',REPLACE(#{sar.standSerialNumber},' ','')),'%')
and (REPLACE(sar_stand_unqualified.STAND_SERIAL_NUMBER,' ','') like concat(concat('%',REPLACE(#{sar.standSerialNumber},' ','')),'%')
or sar_stand_unqualified.STAND_NAME like concat(concat('%',#{sar.standSerialNumber}),'%'))
</if>
order by sar_stand_unqualified.STAND_ID ,sar_stand_unqualified.ITEMS_NUM asc
)b
left join sar_standards_info on b.STAND_ID = sar_standards_info.id
order by sar_stand_unqualified.ID,sar_stand_unqualified.STAND_ID ,sar_stand_unqualified.ITEMS_NUM asc
)c
ORDER BY c.STAND_ID, CONVERT(SUBSTRING(c.ITEMS_NUM,1,(SELECT LOCATE('.',CONCAT(c.ITEMS_NUM,'.')))),SIGNED) ,c.rows
</select>
@@ -244,8 +244,8 @@
FROM
sar_stand_warning AS warning
LEFT JOIN sar_standards_info AS sarInfo ON sarInfo.id = warning.STAND_ID
LEFT JOIN sar_stand_items AS items ON items.STAND_ID = warning.STAND_ID
LEFT JOIN sar_stand_attr_info AS attr ON attr.STAND_ID = warning.STAND_ID
LEFT JOIN sar_stand_items AS items ON items.ID = warning.ITEMS_ID
<where>
POWER = '1'
AND (MARK = 'item')
@@ -11,7 +11,7 @@
(
#{item.id}
,#{item.standId}
,#{item.itemsId}
,#{item.itemId}
,#{item.policyId}
,#{item.mark}
,#{item.power}
@@ -29,22 +29,17 @@
FROM
warning_date
WHERE
DATE_FORMAT(SSRQ, '%Y-%m-%d') &lt; DATE_FORMAT(now(), '%Y-%m-%d')
UNION
DATE_FORMAT(SSRQ, '%Y-%m-%d') &gt; DATE_FORMAT(now(), '%Y-%m-%d')
)
OR
ITEMS_ID IN (
SELECT
ID
ITEM_ID
FROM
sar_standards_info
warning_date
WHERE
DATE_FORMAT(PUT_TIME, '%Y-%m-%d') &lt; DATE_FORMAT(now(), '%Y-%m-%d')
UNION
SELECT
STAND_ID
FROM
sar_stand_items
WHERE
DATE_FORMAT(XCXSSRQ, '%Y-%m-%d') &lt; DATE_FORMAT(now(), '%Y-%m-%d')
OR DATE_FORMAT(ZCCSSRQ, '%Y-%m-%d') &lt; DATE_FORMAT(now(), '%Y-%m-%d')
DATE_FORMAT(SSRQ, '%Y-%m-%d') &gt; DATE_FORMAT(now(), '%Y-%m-%d')
)
</delete>
@@ -85,55 +80,47 @@
<select id="getWarningDate" resultType="com.adc.da.slrs.sarStandWarning.entity.WarningDate">
SELECT
lawId,
itemId,
timeName,
DATE_FORMAT(SSRQ, '%Y-%m-%d') AS SSRQ
FROM
(
select attr.STAND_ID as lawId,'-1' as itemId,'SSRQ' as timeName,
substring_index(substring_index(attr.SSRQ,',',b.help_topic_id+1),',',-1) SSRQ
SSRQ as SSRQ
from sar_stand_attr_info attr
join mysql.help_topic b
on b.help_topic_id &gt; (length(attr.SSRQ) - length(replace(attr.SSRQ,',',''))+1)
WHERE
SSRQ REGEXP #{termStr}
UNION ALL
select attr.STAND_ID as lawId,'-1' as itemId,'XCXSSRQ' as timeName,
substring_index(substring_index(attr.SSRQ,',',b.help_topic_id+1),',',-1) SSRQ
XCXSSRQ as SSRQ
from sar_stand_attr_info attr
join mysql.help_topic b
on b.help_topic_id &gt; (length(attr.XCXSSRQ) - length(replace(attr.XCXSSRQ,',',''))+1)
WHERE
XCXSSRQ REGEXP #{termStr}
UNION ALL
select attr.STAND_ID as lawId,'-1' as itemId,'ZCCSSRQ' as timeName,
substring_index(substring_index(attr.ZCCSSRQ,',',b.help_topic_id+1),',',-1) SSRQ
ZCCSSRQ as SSRQ
from sar_stand_attr_info attr
join mysql.help_topic b
on b.help_topic_id &gt; (length(attr.SSRQ) - length(replace(attr.ZCCSSRQ,',',''))+1)
WHERE
ZCCSSRQ REGEXP #{termStr}
UNION All
select item.STAND_ID as lawId,item.ID as itemId,'ZCCSSRQ' as timeName,
substring_index(substring_index(item.ZCCSSRQ,',',b.help_topic_id+1),',',-1) SSRQ
ZCCSSRQ as SSRQ
from sar_stand_items item
join mysql.help_topic b
on b.help_topic_id &gt; (length(item.ZCCSSRQ) - length(replace(item.ZCCSSRQ,',',''))+1)
WHERE
ZCCSSRQ REGEXP #{termStr}
UNION All
select item.STAND_ID as lawId,item.ID as itemId,'XCXSSRQ' as timeName,
substring_index(substring_index(item.XCXSSRQ,',',b.help_topic_id+1),',',-1) SSRQ
XCXSSRQ as SSRQ
from sar_stand_items item
join mysql.help_topic b
on b.help_topic_id &gt; (length(item.XCXSSRQ) - length(replace(item.XCXSSRQ,',',''))+1)
WHERE
XCXSSRQ REGEXP #{termStr}
) as T
WHERE
DATE_FORMAT(T.SSRQ,'%Y-%m-%d') BETWEEN DATE_FORMAT(#{startDate}, '%Y-%m-%d') AND DATE_FORMAT(#{endDate}, '%Y-%m-%d')
</select>