新增待办过期和历史归档任务

This commit is contained in:
jsowell
2026-07-17 18:06:21 +08:00
parent 09d98eb18d
commit b6b052b9df
9 changed files with 229 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package com.jsowell.system.domain.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 待办维护任务执行结果。
*/
@Data
@AllArgsConstructor
public class TodoTaskMaintenanceResult implements Serializable {
private static final long serialVersionUID = 1L;
private int expiredCount;
private int archivedCount;
private Date archiveBefore;
}

View File

@@ -6,6 +6,7 @@ import com.jsowell.system.domain.dto.TodoTaskQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Date;
/**
* 待办任务数据层。
@@ -73,4 +74,9 @@ public interface SysTodoTaskMapper {
@Param("updateBy") String updateBy);
int hideTodo(@Param("todoId") Long todoId, @Param("updateBy") String updateBy);
int expireDueTasks(@Param("now") Date now, @Param("updateBy") String updateBy);
int archiveTerminalTasks(@Param("archiveBefore") Date archiveBefore,
@Param("updateBy") String updateBy);
}

View File

@@ -0,0 +1,10 @@
package com.jsowell.system.service;
import com.jsowell.system.domain.dto.TodoTaskMaintenanceResult;
/**
* 待办过期和历史归档维护服务。
*/
public interface TodoTaskMaintenanceService {
TodoTaskMaintenanceResult maintain();
}

View File

@@ -0,0 +1,38 @@
package com.jsowell.system.service.impl;
import com.jsowell.common.util.DateUtils;
import com.jsowell.system.domain.dto.TodoTaskMaintenanceResult;
import com.jsowell.system.mapper.SysTodoTaskMapper;
import com.jsowell.system.service.TodoTaskMaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
* 待办过期和历史归档维护服务实现。
*/
@Service
public class TodoTaskMaintenanceServiceImpl implements TodoTaskMaintenanceService {
private static final int DEFAULT_RETENTION_DAYS = 180;
@Value("${todo.retention-days:180}")
private Integer retentionDays;
@Autowired
private SysTodoTaskMapper todoTaskMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public TodoTaskMaintenanceResult maintain() {
Date now = DateUtils.getNowDate();
int safeRetentionDays = retentionDays == null || retentionDays < DEFAULT_RETENTION_DAYS
? DEFAULT_RETENTION_DAYS : retentionDays;
int expiredCount = todoTaskMapper.expireDueTasks(now, "todo-maintenance");
Date archiveBefore = DateUtils.addDays(now, -safeRetentionDays);
int archivedCount = todoTaskMapper.archiveTerminalTasks(archiveBefore, "todo-maintenance");
return new TodoTaskMaintenanceResult(expiredCount, archivedCount, archiveBefore);
}
}

View File

@@ -287,4 +287,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and del_flag = '0'
</update>
<update id="expireDueTasks">
update sys_todo_task
set task_status = 'EXPIRED',
completed_time = #{now},
active_idempotent_key = null,
update_by = #{updateBy},
update_time = #{now}
where task_status in ('PENDING', 'PROCESSING')
and due_time is not null
and due_time &lt;= #{now}
and del_flag = '0'
</update>
<update id="archiveTerminalTasks">
update sys_todo_task
set del_flag = '2',
active_idempotent_key = null,
update_by = #{updateBy},
update_time = sysdate()
where task_status in ('COMPLETED', 'CANCELLED', 'EXPIRED')
and coalesce(completed_time, update_time, create_time) &lt; #{archiveBefore}
and del_flag = '0'
</update>
</mapper>