定时标准预警
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package com.adc.da.scheduled;
|
||||
|
||||
import com.adc.da.scheduled.dao.SarStandardInfoDao;
|
||||
import com.adc.da.scheduled.dao.SarStandardItemDao;
|
||||
import com.adc.da.scheduled.dao.SarStandardWarningDao;
|
||||
import com.adc.da.scheduled.entity.DataDTO;
|
||||
import com.adc.da.scheduled.entity.WarningEO;
|
||||
import com.adc.da.util.UUIDUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -8,7 +14,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@EnableScheduling
|
||||
@Component
|
||||
@@ -22,17 +30,107 @@ public class ScheduledJob {
|
||||
@Value("${isNotScheduled}")
|
||||
private boolean isNotScheduled; //是否开启定时器
|
||||
|
||||
//
|
||||
// @Scheduled(cron="*/5 * * * * ?")
|
||||
// @Async
|
||||
// public void StandScheduledJob(){
|
||||
// System.out.println("hello");
|
||||
//// if(isNotScheduled){
|
||||
//// System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---START-01");
|
||||
//// System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---End-01");
|
||||
//// try{
|
||||
//// Thread.sleep(2000);
|
||||
//// }catch(Exception e){
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
|
||||
|
||||
@Autowired
|
||||
private SarStandardWarningDao sarStandardWarningDao;
|
||||
|
||||
@Autowired
|
||||
private SarStandardItemDao sarStandardItemDao;
|
||||
|
||||
@Autowired
|
||||
private SarStandardInfoDao sarStandardInfoDao;
|
||||
|
||||
|
||||
// @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
||||
@Scheduled(cron="*/5 * * * * ?")
|
||||
@Async
|
||||
public void StandScheduledJob(){
|
||||
if(isNotScheduled){
|
||||
System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---START-01");
|
||||
System.out.println(Thread.currentThread().getName() + " cron=0 0 1 1 * ? --- " + new Date()+"---End-01");
|
||||
try{
|
||||
Thread.sleep(2000);
|
||||
}catch(Exception e){
|
||||
}
|
||||
public void schedulingTasks() {
|
||||
|
||||
|
||||
/**
|
||||
* 1.查询标准属性字段表(sar_stand_attr_info) XCXSSEQ ZCCSSRQ ZRGCS
|
||||
* 联接标准信息表sar_standards_info表的STAND_NAME
|
||||
* 2.查询分解单(条款表)
|
||||
* 3.查询预警表
|
||||
* 4.去掉预警表中已存在的的数据
|
||||
* 5.插入预警表
|
||||
*/
|
||||
|
||||
/**
|
||||
mark:标识预警的种类
|
||||
3:新车标准预警
|
||||
4:在产车标准预警
|
||||
1:新车条款预警
|
||||
2:在产车条款预警
|
||||
*/
|
||||
System.out.println("开始执行预警!!!");
|
||||
//预警期限
|
||||
DataDTO dataDTO = new DataDTO();
|
||||
dataDTO.setStartDate(LocalDate.now().plusDays(1)) //系统日期的下一天
|
||||
.setEndDate(LocalDate.now().plusMonths(3).plusDays(1));//系统日期3个月后
|
||||
|
||||
LinkedList<WarningEO> warningList = new LinkedList<>();
|
||||
|
||||
//分解单(条款) 新车型 mark=1
|
||||
List<WarningEO> itemForXCXSSRQ = sarStandardItemDao.select(dataDTO, "XCXSSRQ");
|
||||
for (WarningEO warningEO : itemForXCXSSRQ) {
|
||||
warningEO.setId(UUIDUtils.randomUUID20())
|
||||
.setPower("1")
|
||||
.setMark("1")
|
||||
.setPutTime(warningEO.getXCXSSRQ());
|
||||
}
|
||||
warningList.addAll(itemForXCXSSRQ);
|
||||
|
||||
//分解单(条款) 在产车型 mark=2
|
||||
List<WarningEO> itemForZCCSSRQ = sarStandardItemDao.select(dataDTO, "ZCCSSRQ");
|
||||
for (WarningEO warningEO : itemForZCCSSRQ) {
|
||||
warningEO.setId(UUIDUtils.randomUUID20())
|
||||
.setPower("1")
|
||||
.setMark("2")
|
||||
.setPutTime(warningEO.getZCCSSRQ());
|
||||
}
|
||||
warningList.addAll(itemForZCCSSRQ);
|
||||
|
||||
//标准 新车型 预警 mark=3
|
||||
List<WarningEO> standInfoXCXSSRQ = sarStandardInfoDao.select(dataDTO, "XCXSSRQ");
|
||||
for (WarningEO warningEO : standInfoXCXSSRQ) {
|
||||
warningEO.setId(UUIDUtils.randomUUID20())
|
||||
.setPower("1")
|
||||
.setMark("3")
|
||||
.setPutTime(warningEO.getXCXSSRQ());
|
||||
}
|
||||
warningList.addAll(standInfoXCXSSRQ);
|
||||
|
||||
|
||||
//标准 在产车型 mark=4
|
||||
List<WarningEO> standInfoZCCSSRQ = sarStandardInfoDao.select(dataDTO, "ZCCSSRQ");
|
||||
for (WarningEO warningEO : standInfoZCCSSRQ) {
|
||||
warningEO.setId(UUIDUtils.randomUUID20())
|
||||
.setPower("1")
|
||||
.setMark("4")
|
||||
.setPutTime(warningEO.getZCCSSRQ());
|
||||
}
|
||||
warningList.addAll(standInfoZCCSSRQ);
|
||||
|
||||
//持久化至预警表 忽略标准id和标志位都一样的数据
|
||||
if (warningList.size()!=0){
|
||||
int count = sarStandardWarningDao.ignoreInsert(warningList);
|
||||
System.out.println("已预警 " + count + " 条标准或条款!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.adc.da.scheduled.dao;
|
||||
|
||||
|
||||
import com.adc.da.scheduled.entity.DataDTO;
|
||||
import com.adc.da.scheduled.entity.WarningEO;
|
||||
import com.adc.da.slrs.sarStandWarning.entity.EarlyWarningEO;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface SarStandardInfoDao{
|
||||
|
||||
public List<WarningEO> select(DataDTO date, String str);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.adc.da.scheduled.dao;
|
||||
|
||||
import com.adc.da.scheduled.entity.DataDTO;
|
||||
import com.adc.da.scheduled.entity.WarningEO;
|
||||
import com.adc.da.slrs.sarStandWarning.entity.EarlyWarningEO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface SarStandardItemDao extends BaseMapper{
|
||||
|
||||
public List<WarningEO> select(DataDTO date, String str);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.adc.da.scheduled.dao;
|
||||
|
||||
import com.adc.da.scheduled.entity.WarningEO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
@Repository
|
||||
public interface SarStandardWarningDao extends IService<WarningEO> {
|
||||
|
||||
public int ignoreInsert(@Param(value = "warningEOS") LinkedList<WarningEO> warningEOS);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.adc.da.scheduled.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class DataDTO {
|
||||
|
||||
private LocalDate startDate;
|
||||
|
||||
private LocalDate endDate;
|
||||
|
||||
private String str;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.adc.da.scheduled.entity;
|
||||
|
||||
import com.adc.da.base.entity.BaseEntity;
|
||||
import com.adc.da.slrs.sarStandWarning.entity.EarlyWarningEO;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class WarningEO extends EarlyWarningEO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Date XCXSSRQ;
|
||||
|
||||
private Date ZCCSSRQ;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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.scheduled.dao.SarStandardInfoDao">
|
||||
|
||||
<!-- Result Map-->
|
||||
<resultMap id="resultMap" type="com.adc.da.scheduled.entity.WarningEO" >
|
||||
<id column="ID" property="id" />
|
||||
<result column="STAND_NUMBER" property="standCode" />
|
||||
<result column="STAND_NAME" property="standName" />
|
||||
<result column="XCXSSRQ" property="XCXSSRQ"/>
|
||||
<result column="ZCCSSRQ" property="ZCCSSRQ"/>
|
||||
<result column="CLLX" property="applyType" />
|
||||
<result column="STAND_TYPE" property="standType" />
|
||||
<result column="ZRGCS" property="dutyEngineer" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 查询条件 -->
|
||||
<select id="select" resultMap="resultMap" parameterType="com.adc.da.scheduled.entity.DataDTO">
|
||||
SELECT
|
||||
info.ID,
|
||||
info.STAND_NUMBER,
|
||||
info.STAND_NAME,
|
||||
info.STAND_TYPE,
|
||||
attrInfo.CLLX,
|
||||
attrInfo.ZRGCS,
|
||||
attrInfo.${str}
|
||||
FROM
|
||||
sar_standards_info AS info
|
||||
JOIN sar_stand_attr_info AS attrInfo ON info.id = attrinfo.stand_id
|
||||
WHERE
|
||||
attrInfo.${str} BETWEEN #{date.startDate} and #{date.endDate}
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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.scheduled.dao.SarStandardItemDao">
|
||||
|
||||
<!-- Result Map-->
|
||||
<resultMap id="resultMap" type="com.adc.da.scheduled.entity.WarningEO">
|
||||
<id column="ID" property="id"/>
|
||||
<result column="STAND_NUMBER" property="standCode"/>
|
||||
<result column="STAND_NAME" property="standName"/>
|
||||
<result column="XCXSSRQ" property="XCXSSRQ"/>
|
||||
<result column="ZCCSSRQ" property="ZCCSSRQ"/>
|
||||
<result column="CLLX" property="applyType"/>
|
||||
<result column="STAND_TYPE" property="standType"/>
|
||||
<result column="ZRGCS" property="dutyEngineer"/>
|
||||
</resultMap>
|
||||
<!-- 查询条件 -->
|
||||
<select id="select" resultMap="resultMap" parameterType="com.adc.da.scheduled.entity.DataDTO">
|
||||
SELECT
|
||||
STAND_ID,
|
||||
ITEMS_NUM,
|
||||
TERMS_CONDITIONS,
|
||||
DUTY_ENGINEER,
|
||||
APPLY_ARCTIC,
|
||||
info.STAND_TYPE,
|
||||
|
||||
${str}
|
||||
FROM
|
||||
sar_stand_items AS items
|
||||
JOIN sar_standards_info AS info ON items.STAND_ID=info.ID
|
||||
|
||||
WHERE
|
||||
${str} BETWEEN #{date.startDate} and #{date.endDate}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?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.scheduled.dao.SarStandardWarningDao">
|
||||
|
||||
<insert id="ignoreInsert" parameterType="java.util.LinkedList">
|
||||
|
||||
INSERT IGNORE INTO sar_stand_warning (ID, STAND_TYPE, STAND_CODE,STAND_NAME,PUT_TIME,APPLY_TYPE,DUTY_ENGINEER,ITEMS_ID,ITEMS_NAME,POLICY_ID,POLICY_NAME,MARK,POWER)
|
||||
VALUES
|
||||
<if test="warningEOS !=null and warningEOS.size()!=0">
|
||||
<foreach collection="warningEOS" item="item" index="index" separator=",">
|
||||
(
|
||||
#{item.id}
|
||||
,#{item.standType}
|
||||
,#{item.standCode}
|
||||
,#{item.standName}
|
||||
,#{item.putTime}
|
||||
,#{item.applyType}
|
||||
,#{item.dutyEngineer}
|
||||
,#{item.itemsId}
|
||||
,#{item.itemsName}
|
||||
,#{item.policyId}
|
||||
,#{item.policyName}
|
||||
,#{item.mark}
|
||||
,#{item.power}
|
||||
)
|
||||
</foreach>
|
||||
</if>
|
||||
</insert>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user