6-10 - fix - 更新定时任务逻辑
parent
71bbd603f7
commit
a4e65972ab
|
|
@ -1,4 +1,4 @@
|
|||
<!doctype html><html lang="zh"><head data-built-info="@cqsjjb/scripts@2.0.0 Env/production (2026/6/1 09:40:32) App/safetyDutyList"><meta charset="UTF-8"/><meta name="renderer" content="webkit"/><meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1"/><meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"><title>--</title><script>(function () {
|
||||
<!doctype html><html lang="zh"><head data-built-info="@cqsjjb/scripts@2.0.0 Env/production (2026/6/9 17:57:56) App/safetyDutyList"><meta charset="UTF-8"/><meta name="renderer" content="webkit"/><meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1"/><meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"><title>--</title><script>(function () {
|
||||
const APP_ENV = {
|
||||
antd: {
|
||||
'ant-prefix': 'micro-temp',
|
||||
|
|
@ -20,4 +20,4 @@
|
|||
redirect: '',
|
||||
FRAMEWORK: APP_ENV.antd
|
||||
};
|
||||
})();</script><script defer="defer" src="/safetyDutyList/static/js/185.46e52d05996ddef5e7f4.js"></script><script defer="defer" src="/safetyDutyList/static/js/26.7e37655f7b2954f97c50.js"></script><script defer="defer" src="/safetyDutyList/static/js/main.5854b5653e32685ed8d6.js"></script><link href="/safetyDutyList/static/css/main.c74fbb90829596498e3a.css" rel="stylesheet"></head><body><noscript>此网页需要开启JavaScript功能。</noscript><div id="root" style="width: 100%; height: 100%; position: relative;overflow-y: auto"></div><script type="text/javascript">/* @cqsjjb/script 输出当前应用基本信息、构建时间 */console.log("%c@cqsjjb/scripts@2.0.0 Env/production (2026/6/1 09:40:32) App/safetyDutyList Version/main Java/<branch-name>", "color: #1890ff; border-radius: 2px; padding: 0 4px; border: 1px solid #1890ff; background: #f9fcff")</script></body></html>
|
||||
})();</script><script defer="defer" src="/safetyDutyList/static/js/185.46e52d05996ddef5e7f4.js"></script><script defer="defer" src="/safetyDutyList/static/js/26.7e37655f7b2954f97c50.js"></script><script defer="defer" src="/safetyDutyList/static/js/main.cd9beec701b863d55554.js"></script><link href="/safetyDutyList/static/css/main.c74fbb90829596498e3a.css" rel="stylesheet"></head><body><noscript>此网页需要开启JavaScript功能。</noscript><div id="root" style="width: 100%; height: 100%; position: relative;overflow-y: auto"></div><script type="text/javascript">/* @cqsjjb/script 输出当前应用基本信息、构建时间 */console.log("%c@cqsjjb/scripts@2.0.0 Env/production (2026/6/9 17:57:56) App/safetyDutyList Version/main Java/<branch-name>", "color: #1890ff; border-radius: 2px; padding: 0 4px; border: 1px solid #1890ff; background: #f9fcff")</script></body></html>
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1 @@
|
|||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
||||
|
|
@ -11,24 +11,29 @@ import com.zcloud.safetyDutyList.domain.model.tasklist.FeedbackExceptionE;
|
|||
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskDetailE;
|
||||
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskExecutionE;
|
||||
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskListIssueE;
|
||||
import com.zcloud.safetyDutyList.domain.util.FeedbackCycleUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务2:反馈异常检测
|
||||
* <p>
|
||||
* 定时扫描已下发且有周期的下发记录下的任务执行记录,
|
||||
* 检查当前周期是否已反馈,未反馈则标记为异常并创建异常记录。
|
||||
* 执行周期:每月1日0时
|
||||
* <p>
|
||||
* 实现逻辑:
|
||||
* 1. 获取所有 task_status=1 的任务执行记录,获取其反馈周期类型 feedback_cycle_type
|
||||
* 2. 根据反馈周期类型判断上一阶段是否有反馈记录,无记录则判定为异常
|
||||
* 判定规则:
|
||||
* feedback_cycle_type=1(每月):每个月都需要反馈至少一次
|
||||
* feedback_cycle_type=2(每季度):每个季度(自然月划分)都需要反馈至少一次
|
||||
* feedback_cycle_type=3(每半年):每半年(以自然月6月划分)都需要反馈至少一次
|
||||
* feedback_cycle_type=4(年):一年内必须反馈至少一次
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
|
|
@ -40,7 +45,7 @@ public class FeedbackExceptionCheckExe {
|
|||
private final FeedbackGateway feedbackGateway;
|
||||
private final FeedbackExceptionGateway feedbackExceptionGateway;
|
||||
|
||||
@Scheduled(cron = "0 10 1 * * ?")
|
||||
@Scheduled(cron = "0 0 0 1 * ?")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void execute() {
|
||||
log.info("【定时任务2】开始反馈异常检测...");
|
||||
|
|
@ -50,70 +55,77 @@ public class FeedbackExceptionCheckExe {
|
|||
return;
|
||||
}
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
String currentPeriodFlag = today.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||
|
||||
for (TaskListIssueE issueE : issuedList) {
|
||||
List<TaskExecutionE> executionList = taskExecutionGateway.listByTaskIssueId(issueE.getTaskIssueId());
|
||||
if (executionList == null) continue;
|
||||
|
||||
for (TaskExecutionE executionE : executionList) {
|
||||
|
||||
// 不是进行中就返回
|
||||
if (!TaskStatusEnum.IN_PROGRESS.getCode().equals(executionE.getTaskStatus())) continue;
|
||||
|
||||
|
||||
// 获取任务详情
|
||||
TaskDetailE detailE = taskDetailGateway.getByTaskDetailId(executionE.getTaskDetailId());
|
||||
if (detailE == null) continue;
|
||||
if (detailE == null || detailE.getFeedbackCycleType() == null) continue;
|
||||
|
||||
if (!shouldCheckThisPeriod(detailE.getFeedbackCycleType(), today)) continue;
|
||||
// 反馈周期枚举: 1(每月) 2(每季度) 3(每半年) 4(年)
|
||||
Integer feedbackCycleType = detailE.getFeedbackCycleType();
|
||||
|
||||
// 检查当前周期是否已反馈
|
||||
// 首周期判断:如果当前仍处于清单的首个反馈周期内,跳过检测
|
||||
if (FeedbackCycleUtil.isFirstCycle(feedbackCycleType, issueE.getPeriodStartTime())) {
|
||||
log.info("【定时任务2】任务执行[{}]仍处于首周期内,跳过检测", executionE.getTaskExecutionId());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 生成上一阶段周期标识
|
||||
String previousPeriodFlag = FeedbackCycleUtil.generatePreviousPeriodFlag(feedbackCycleType);
|
||||
if (previousPeriodFlag == null) continue;
|
||||
|
||||
// 防重:检查上一阶段是否已存在异常记录
|
||||
List<FeedbackExceptionE> existingExceptions = feedbackExceptionGateway
|
||||
.listByTaskExecutionIdAndPeriodFlag(executionE.getTaskExecutionId(), previousPeriodFlag);
|
||||
if (existingExceptions != null && !existingExceptions.isEmpty()) {
|
||||
log.debug("【定时任务2】任务执行[{}]周期[{}]已存在异常记录,跳过",
|
||||
executionE.getTaskExecutionId(), previousPeriodFlag);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查上一阶段是否有反馈记录
|
||||
List<FeedbackE> feedbackList = feedbackGateway.listByTaskExecutionIdAndPeriodFlag(
|
||||
executionE.getTaskExecutionId(), currentPeriodFlag);
|
||||
executionE.getTaskExecutionId(), previousPeriodFlag);
|
||||
if (feedbackList == null || feedbackList.isEmpty()) {
|
||||
// 标记任务执行记录为异常
|
||||
executionE.setFeedbackStatus(2);
|
||||
taskExecutionGateway.update(executionE);
|
||||
|
||||
// 创建异常记录
|
||||
createExceptionRecord(executionE, detailE, issueE, currentPeriodFlag, today);
|
||||
log.info("【定时任务2】任务执行[{}]周期[{}]未反馈,已标记异常",
|
||||
executionE.getTaskExecutionId(), currentPeriodFlag);
|
||||
createExceptionRecord(executionE, detailE, issueE, previousPeriodFlag);
|
||||
log.info("【定时任务2】任务执行[{}]上一周期[{}]未反馈,已标记异常",
|
||||
executionE.getTaskExecutionId(), previousPeriodFlag);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("【定时任务2】反馈异常检测完成");
|
||||
}
|
||||
|
||||
private boolean shouldCheckThisPeriod(Integer feedbackCycleType, LocalDate today) {
|
||||
if (feedbackCycleType == null) return false;
|
||||
// 1-每月 2-季度 3-半年 4-年
|
||||
switch (feedbackCycleType) {
|
||||
case 1: // 每月
|
||||
return today.getDayOfMonth() > 1;
|
||||
case 2: // 季度
|
||||
int month = today.getMonthValue();
|
||||
int quarterEndMonth = ((month - 1) / 3 + 1) * 3;
|
||||
return month == quarterEndMonth && today.getDayOfMonth() > 1;
|
||||
case 3: // 半年
|
||||
return (today.getMonthValue() == 6 || today.getMonthValue() == 12) && today.getDayOfMonth() > 1;
|
||||
case 4: // 年
|
||||
return today.getMonthValue() == 12 && today.getDayOfMonth() > 1;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void createExceptionRecord(TaskExecutionE executionE, TaskDetailE detailE,
|
||||
TaskListIssueE issueE, String periodFlag, LocalDate today) {
|
||||
TaskListIssueE issueE, String previousPeriodFlag) {
|
||||
|
||||
// 根据上一阶段周期标识计算起止时间
|
||||
LocalDateTime[] periodTime = FeedbackCycleUtil.getPeriodTime(previousPeriodFlag);
|
||||
|
||||
FeedbackExceptionE exceptionE = new FeedbackExceptionE();
|
||||
exceptionE.init();
|
||||
exceptionE.setTaskDetailId(executionE.getTaskDetailId());
|
||||
exceptionE.setTaskExecutionId(executionE.getTaskExecutionId());
|
||||
exceptionE.setTaskListId(executionE.getTaskListId());
|
||||
exceptionE.setTaskIssueId(executionE.getTaskIssueId());
|
||||
exceptionE.setExceptionPeriodFlag(periodFlag);
|
||||
exceptionE.setExceptionPeriodStartTime(today.withDayOfMonth(1).atStartOfDay());
|
||||
exceptionE.setExceptionPeriodEndTime(today.with(TemporalAdjusters.lastDayOfMonth()).atTime(LocalTime.MAX));
|
||||
exceptionE.setExceptionPeriodFlag(previousPeriodFlag);
|
||||
exceptionE.setExceptionPeriodStartTime(periodTime != null ? periodTime[0] : null);
|
||||
exceptionE.setExceptionPeriodEndTime(periodTime != null ? periodTime[1] : null);
|
||||
exceptionE.setExceptionType(1);
|
||||
exceptionE.setExceptionTime(LocalDateTime.now());
|
||||
feedbackExceptionGateway.add(exceptionE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ public class TaskListStatusUpdateExe {
|
|||
for (TaskListIssueE issueE : expiredList) {
|
||||
log.info("【定时任务1】下发记录[{}]周期已结束,更新为已完成", issueE.getTaskIssueId());
|
||||
issueE.setStatus(TaskStatusEnum.COMPLETED.getCode());
|
||||
issueE.setCloseTime(LocalDateTime.now());
|
||||
taskListIssueGateway.update(issueE);
|
||||
|
||||
// 同时关闭该下发记录下所有进行中的任务执行记录
|
||||
|
|
|
|||
|
|
@ -17,6 +17,5 @@ public class FeedbackListQry extends PageQuery {
|
|||
@NotEmpty(message = "任务执行ID不能为空")
|
||||
private String taskExecutionId;
|
||||
@ApiModelProperty(value = "周期标识", required = true)
|
||||
@NotEmpty(message = "周期标识不能为空")
|
||||
private String feedbackPeriodFlag;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,15 @@ public interface FeedbackExceptionGateway {
|
|||
* @return 反馈异常记录列表
|
||||
*/
|
||||
List<FeedbackExceptionE> listByTaskDetailId(String taskDetailId);
|
||||
|
||||
/**
|
||||
* 根据任务执行ID和周期标识查询反馈异常记录
|
||||
* <p>
|
||||
* 用于定时任务2:反馈异常检测时,检查某个任务在指定周期是否已存在异常记录,避免重复添加
|
||||
*
|
||||
* @param taskExecutionId 任务执行业务ID
|
||||
* @param exceptionPeriodFlag 异常周期标识
|
||||
* @return 反馈异常记录列表
|
||||
*/
|
||||
List<FeedbackExceptionE> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,4 +134,27 @@ public class FeedbackExceptionGatewayImpl implements FeedbackExceptionGateway {
|
|||
}
|
||||
return eList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据任务执行ID和周期标识查询反馈异常记录
|
||||
* <p>
|
||||
* 用于定时任务2:反馈异常检测时,检查某个任务在指定周期是否已存在异常记录,避免重复添加
|
||||
*
|
||||
* @param taskExecutionId 任务执行业务ID
|
||||
* @param exceptionPeriodFlag 异常周期标识
|
||||
* @return 反馈异常记录列表
|
||||
*/
|
||||
@Override
|
||||
public List<FeedbackExceptionE> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag) {
|
||||
List<FeedbackExceptionDO> doList = feedbackExceptionRepository.listByTaskExecutionIdAndPeriodFlag(taskExecutionId, exceptionPeriodFlag);
|
||||
List<FeedbackExceptionE> eList = new ArrayList<>();
|
||||
if (doList != null) {
|
||||
for (FeedbackExceptionDO d : doList) {
|
||||
FeedbackExceptionE e = new FeedbackExceptionE();
|
||||
BeanUtils.copyProperties(d, e);
|
||||
eList.add(e);
|
||||
}
|
||||
}
|
||||
return eList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,15 @@ public interface FeedbackExceptionMapper extends BaseMapper<FeedbackExceptionDO>
|
|||
* @return 反馈异常数据对象
|
||||
*/
|
||||
FeedbackExceptionDO getByExceptionId(String exceptionId);
|
||||
|
||||
/**
|
||||
* 根据任务执行ID和周期标识查询反馈异常记录
|
||||
* <p>
|
||||
* 用于定时任务2:反馈异常检测时,检查某个任务在指定周期是否已存在异常记录,避免重复添加
|
||||
*
|
||||
* @param taskExecutionId 任务执行业务ID
|
||||
* @param exceptionPeriodFlag 异常周期标识
|
||||
* @return 反馈异常数据对象列表
|
||||
*/
|
||||
List<FeedbackExceptionDO> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,4 +72,12 @@ public class FeedbackExceptionRepositoryImpl extends BaseRepositoryImpl<Feedback
|
|||
public FeedbackExceptionDO getByExceptionId(String exceptionId) {
|
||||
return feedbackExceptionMapper.getByExceptionId(exceptionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据任务执行ID和周期标识查询反馈异常记录
|
||||
*/
|
||||
@Override
|
||||
public List<FeedbackExceptionDO> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag) {
|
||||
return feedbackExceptionMapper.listByTaskExecutionIdAndPeriodFlag(taskExecutionId, exceptionPeriodFlag);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,4 +56,15 @@ public interface FeedbackExceptionRepository extends BaseRepository<FeedbackExce
|
|||
* @return 反馈异常数据对象
|
||||
*/
|
||||
FeedbackExceptionDO getByExceptionId(String exceptionId);
|
||||
|
||||
/**
|
||||
* 根据任务执行ID和周期标识查询反馈异常记录
|
||||
* <p>
|
||||
* 用于定时任务2:反馈异常检测时,检查某个任务在指定周期是否已存在异常记录,避免重复添加
|
||||
*
|
||||
* @param taskExecutionId 任务执行业务ID
|
||||
* @param exceptionPeriodFlag 异常周期标识
|
||||
* @return 反馈异常数据对象列表
|
||||
*/
|
||||
List<FeedbackExceptionDO> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,4 +53,11 @@
|
|||
SELECT * FROM safety_accountability_feedback_exception WHERE feedback_exception_id = #{exceptionId}
|
||||
</select>
|
||||
|
||||
<select id="listByTaskExecutionIdAndPeriodFlag" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.FeedbackExceptionDO">
|
||||
SELECT * FROM safety_accountability_feedback_exception
|
||||
WHERE task_execution_id = #{taskExecutionId}
|
||||
AND exception_period_flag = #{exceptionPeriodFlag}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@
|
|||
|
||||
<select id="listIssuedWithPeriod" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskListIssueDO">
|
||||
SELECT * FROM safety_accountability_task_list_issue
|
||||
WHERE issue_status = 1 AND period_start_time IS NOT NULL AND period_end_time IS NOT NULL
|
||||
WHERE issue_status = 1 AND status = 1 AND period_start_time IS NOT NULL AND period_end_time IS NOT NULL
|
||||
AND period_end_time > DATE_SUB(NOW(), INTERVAL 1 MONTH) AND delete_enum = 'FALSE'
|
||||
</select>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue