6-10 - fix - 更新定时任务逻辑

master
tianxinlei 2026-06-10 09:38:08 +08:00
parent 71bbd603f7
commit a4e65972ab
13 changed files with 129 additions and 45 deletions

View File

@ -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 = { const APP_ENV = {
antd: { antd: {
'ant-prefix': 'micro-temp', 'ant-prefix': 'micro-temp',
@ -20,4 +20,4 @@
redirect: '', redirect: '',
FRAMEWORK: APP_ENV.antd 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

View File

@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */

View File

@ -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.TaskDetailE;
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskExecutionE; import com.zcloud.safetyDutyList.domain.model.tasklist.TaskExecutionE;
import com.zcloud.safetyDutyList.domain.model.tasklist.TaskListIssueE; import com.zcloud.safetyDutyList.domain.model.tasklist.TaskListIssueE;
import com.zcloud.safetyDutyList.domain.util.FeedbackCycleUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.List; import java.util.List;
/** /**
* 2 * 2
* <p> * <p>
* * 10
* * <p>
*
* 1. task_status=1 feedback_cycle_type
* 2.
*
* feedback_cycle_type=1
* feedback_cycle_type=2
* feedback_cycle_type=36
* feedback_cycle_type=4
*/ */
@Slf4j @Slf4j
@Component @Component
@ -40,7 +45,7 @@ public class FeedbackExceptionCheckExe {
private final FeedbackGateway feedbackGateway; private final FeedbackGateway feedbackGateway;
private final FeedbackExceptionGateway feedbackExceptionGateway; private final FeedbackExceptionGateway feedbackExceptionGateway;
@Scheduled(cron = "0 10 1 * * ?") @Scheduled(cron = "0 0 0 1 * ?")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void execute() { public void execute() {
log.info("【定时任务2】开始反馈异常检测..."); log.info("【定时任务2】开始反馈异常检测...");
@ -50,70 +55,77 @@ public class FeedbackExceptionCheckExe {
return; return;
} }
LocalDate today = LocalDate.now();
String currentPeriodFlag = today.format(DateTimeFormatter.ofPattern("yyyy-MM"));
for (TaskListIssueE issueE : issuedList) { for (TaskListIssueE issueE : issuedList) {
List<TaskExecutionE> executionList = taskExecutionGateway.listByTaskIssueId(issueE.getTaskIssueId()); List<TaskExecutionE> executionList = taskExecutionGateway.listByTaskIssueId(issueE.getTaskIssueId());
if (executionList == null) continue; if (executionList == null) continue;
for (TaskExecutionE executionE : executionList) { for (TaskExecutionE executionE : executionList) {
// 不是进行中就返回
if (!TaskStatusEnum.IN_PROGRESS.getCode().equals(executionE.getTaskStatus())) continue; if (!TaskStatusEnum.IN_PROGRESS.getCode().equals(executionE.getTaskStatus())) continue;
// 获取任务详情
TaskDetailE detailE = taskDetailGateway.getByTaskDetailId(executionE.getTaskDetailId()); 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( List<FeedbackE> feedbackList = feedbackGateway.listByTaskExecutionIdAndPeriodFlag(
executionE.getTaskExecutionId(), currentPeriodFlag); executionE.getTaskExecutionId(), previousPeriodFlag);
if (feedbackList == null || feedbackList.isEmpty()) { if (feedbackList == null || feedbackList.isEmpty()) {
// 标记任务执行记录为异常 // 标记任务执行记录为异常
executionE.setFeedbackStatus(2); executionE.setFeedbackStatus(2);
taskExecutionGateway.update(executionE); taskExecutionGateway.update(executionE);
// 创建异常记录 // 创建异常记录
createExceptionRecord(executionE, detailE, issueE, currentPeriodFlag, today); createExceptionRecord(executionE, detailE, issueE, previousPeriodFlag);
log.info("【定时任务2】任务执行[{}]周期[{}]未反馈,已标记异常", log.info("【定时任务2】任务执行[{}]上一周期[{}]未反馈,已标记异常",
executionE.getTaskExecutionId(), currentPeriodFlag); executionE.getTaskExecutionId(), previousPeriodFlag);
} }
} }
} }
log.info("【定时任务2】反馈异常检测完成"); 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, 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(); FeedbackExceptionE exceptionE = new FeedbackExceptionE();
exceptionE.init(); exceptionE.init();
exceptionE.setTaskDetailId(executionE.getTaskDetailId()); exceptionE.setTaskDetailId(executionE.getTaskDetailId());
exceptionE.setTaskExecutionId(executionE.getTaskExecutionId()); exceptionE.setTaskExecutionId(executionE.getTaskExecutionId());
exceptionE.setTaskListId(executionE.getTaskListId()); exceptionE.setTaskListId(executionE.getTaskListId());
exceptionE.setTaskIssueId(executionE.getTaskIssueId()); exceptionE.setTaskIssueId(executionE.getTaskIssueId());
exceptionE.setExceptionPeriodFlag(periodFlag); exceptionE.setExceptionPeriodFlag(previousPeriodFlag);
exceptionE.setExceptionPeriodStartTime(today.withDayOfMonth(1).atStartOfDay()); exceptionE.setExceptionPeriodStartTime(periodTime != null ? periodTime[0] : null);
exceptionE.setExceptionPeriodEndTime(today.with(TemporalAdjusters.lastDayOfMonth()).atTime(LocalTime.MAX)); exceptionE.setExceptionPeriodEndTime(periodTime != null ? periodTime[1] : null);
exceptionE.setExceptionType(1); exceptionE.setExceptionType(1);
exceptionE.setExceptionTime(LocalDateTime.now());
feedbackExceptionGateway.add(exceptionE); feedbackExceptionGateway.add(exceptionE);
} }
} }

View File

@ -39,7 +39,6 @@ public class TaskListStatusUpdateExe {
for (TaskListIssueE issueE : expiredList) { for (TaskListIssueE issueE : expiredList) {
log.info("【定时任务1】下发记录[{}]周期已结束,更新为已完成", issueE.getTaskIssueId()); log.info("【定时任务1】下发记录[{}]周期已结束,更新为已完成", issueE.getTaskIssueId());
issueE.setStatus(TaskStatusEnum.COMPLETED.getCode()); issueE.setStatus(TaskStatusEnum.COMPLETED.getCode());
issueE.setCloseTime(LocalDateTime.now());
taskListIssueGateway.update(issueE); taskListIssueGateway.update(issueE);
// 同时关闭该下发记录下所有进行中的任务执行记录 // 同时关闭该下发记录下所有进行中的任务执行记录

View File

@ -17,6 +17,5 @@ public class FeedbackListQry extends PageQuery {
@NotEmpty(message = "任务执行ID不能为空") @NotEmpty(message = "任务执行ID不能为空")
private String taskExecutionId; private String taskExecutionId;
@ApiModelProperty(value = "周期标识", required = true) @ApiModelProperty(value = "周期标识", required = true)
@NotEmpty(message = "周期标识不能为空")
private String feedbackPeriodFlag; private String feedbackPeriodFlag;
} }

View File

@ -61,4 +61,15 @@ public interface FeedbackExceptionGateway {
* @return * @return
*/ */
List<FeedbackExceptionE> listByTaskDetailId(String taskDetailId); List<FeedbackExceptionE> listByTaskDetailId(String taskDetailId);
/**
* ID
* <p>
* 2
*
* @param taskExecutionId ID
* @param exceptionPeriodFlag
* @return
*/
List<FeedbackExceptionE> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag);
} }

View File

@ -134,4 +134,27 @@ public class FeedbackExceptionGatewayImpl implements FeedbackExceptionGateway {
} }
return eList; 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;
}
} }

View File

@ -61,4 +61,15 @@ public interface FeedbackExceptionMapper extends BaseMapper<FeedbackExceptionDO>
* @return * @return
*/ */
FeedbackExceptionDO getByExceptionId(String exceptionId); FeedbackExceptionDO getByExceptionId(String exceptionId);
/**
* ID
* <p>
* 2
*
* @param taskExecutionId ID
* @param exceptionPeriodFlag
* @return
*/
List<FeedbackExceptionDO> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag);
} }

View File

@ -72,4 +72,12 @@ public class FeedbackExceptionRepositoryImpl extends BaseRepositoryImpl<Feedback
public FeedbackExceptionDO getByExceptionId(String exceptionId) { public FeedbackExceptionDO getByExceptionId(String exceptionId) {
return feedbackExceptionMapper.getByExceptionId(exceptionId); return feedbackExceptionMapper.getByExceptionId(exceptionId);
} }
/**
* ID
*/
@Override
public List<FeedbackExceptionDO> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag) {
return feedbackExceptionMapper.listByTaskExecutionIdAndPeriodFlag(taskExecutionId, exceptionPeriodFlag);
}
} }

View File

@ -56,4 +56,15 @@ public interface FeedbackExceptionRepository extends BaseRepository<FeedbackExce
* @return * @return
*/ */
FeedbackExceptionDO getByExceptionId(String exceptionId); FeedbackExceptionDO getByExceptionId(String exceptionId);
/**
* ID
* <p>
* 2
*
* @param taskExecutionId ID
* @param exceptionPeriodFlag
* @return
*/
List<FeedbackExceptionDO> listByTaskExecutionIdAndPeriodFlag(String taskExecutionId, String exceptionPeriodFlag);
} }

View File

@ -53,4 +53,11 @@
SELECT * FROM safety_accountability_feedback_exception WHERE feedback_exception_id = #{exceptionId} SELECT * FROM safety_accountability_feedback_exception WHERE feedback_exception_id = #{exceptionId}
</select> </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> </mapper>

View File

@ -172,7 +172,7 @@
<select id="listIssuedWithPeriod" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskListIssueDO"> <select id="listIssuedWithPeriod" resultType="com.zcloud.safetyDutyList.persistence.dataobject.tasklist.TaskListIssueDO">
SELECT * FROM safety_accountability_task_list_issue 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' AND period_end_time > DATE_SUB(NOW(), INTERVAL 1 MONTH) AND delete_enum = 'FALSE'
</select> </select>