feat: add controlled aggregation task deletion
This commit is contained in:
1 parent
2a85724613
commit
79f829c12e
4 files changed
+54
-4
No files matched your search
+17
-1
@@ -169,8 +169,24 @@ public class UsdtAggregationTaskController extends BaseController {
|
||||
return AjaxResult.success(usdtAggregationTaskService.selectUsdtAggregationTaskById(id, true));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtTask:remove')")
|
||||
@Log(title = "归集任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult remove(@PathVariable("id") Long id) {
|
||||
aggregationWorkflowService.deleteTask(id, false);
|
||||
return AjaxResult.success("删除成功");
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('system:usdtTask:user-remove')")
|
||||
@Log(title = "用户归集任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/user/{id}")
|
||||
public AjaxResult userRemove(@PathVariable("id") Long id) {
|
||||
aggregationWorkflowService.deleteTask(id, true);
|
||||
return AjaxResult.success("删除成功");
|
||||
}
|
||||
|
||||
/*
|
||||
* 归集任务的状态、审核结果、目标地址和执行时间必须由工作流维护。
|
||||
* 不暴露代码生成器的通用新增、编辑和删除接口,防止绕过审核流程。
|
||||
* 不暴露代码生成器的通用新增和编辑接口;删除必须经过受控状态校验。
|
||||
*/
|
||||
}
|
||||
@@ -23,6 +23,9 @@ public interface UsdtAggregationTaskMapper extends BaseMapper<UsdtAggregationTas
|
||||
*/
|
||||
public UsdtAggregationTask selectUsdtAggregationTaskById(Long id);
|
||||
|
||||
/** 锁定任务供审核、删除等状态迁移使用。 */
|
||||
UsdtAggregationTask selectUsdtAggregationTaskByIdForUpdate(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询归集任务列表
|
||||
*
|
||||
|
||||
+26
-1
@@ -131,6 +131,31 @@ public class UsdtAggregationWorkflowService {
|
||||
taskService.updateById(task);
|
||||
}
|
||||
|
||||
/** 仅允许删除尚未执行且处于待审核或审核拒绝状态的任务。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteTask(Long taskId, boolean userMode) {
|
||||
UsdtAggregationTask task = taskMapper.selectUsdtAggregationTaskByIdForUpdate(taskId);
|
||||
if (task == null) throw new CustomException("归集任务不存在或已删除");
|
||||
if (userMode && !SecurityUtils.getUserId().equals(task.getUserId())) {
|
||||
throw new CustomException("无权删除该归集任务");
|
||||
}
|
||||
if (!Integer.valueOf(0).equals(task.getStatus())
|
||||
|| !(Integer.valueOf(0).equals(task.getVerifyStatus())
|
||||
|| Integer.valueOf(2).equals(task.getVerifyStatus()))) {
|
||||
throw new CustomException("只有待审核或审核拒绝且尚未执行的任务可以删除");
|
||||
}
|
||||
Date now = DateUtils.getNowDate();
|
||||
task.setDeletedAt(now);
|
||||
task.setUpdatedAt(now);
|
||||
task.setRemark("任务已删除");
|
||||
taskMapper.updateUsdtAggregationTask(task);
|
||||
itemService.update(new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<UsdtAggregationTaskItemPlus>()
|
||||
.eq(UsdtAggregationTaskItemPlus::getParentId, taskId)
|
||||
.isNull(UsdtAggregationTaskItemPlus::getDeletedAt)
|
||||
.set(UsdtAggregationTaskItemPlus::getDeletedAt, now)
|
||||
.set(UsdtAggregationTaskItemPlus::getUpdatedAt, now));
|
||||
}
|
||||
|
||||
public void executeTask(Long taskId, String password, boolean userMode) {
|
||||
UsdtAggregationTaskPlus task = requireTask(taskId, userMode);
|
||||
if (!Integer.valueOf(1).equals(task.getVerifyStatus())) {
|
||||
@@ -274,7 +299,7 @@ public class UsdtAggregationWorkflowService {
|
||||
|
||||
private UsdtAggregationTaskPlus requireTask(Long taskId, boolean userMode) {
|
||||
UsdtAggregationTaskPlus task = taskService.getById(taskId);
|
||||
if (task == null) {
|
||||
if (task == null || task.getDeletedAt() != null) {
|
||||
throw new CustomException("归集任务不存在");
|
||||
}
|
||||
if (userMode && !SecurityUtils.getUserId().equals(task.getUserId())) {
|
||||
|
||||
@@ -25,7 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectUsdtAggregationTaskList" parameterType="UsdtAggregationTask" resultMap="UsdtAggregationTaskResult">
|
||||
<include refid="selectUsdtAggregationTaskVo"/>
|
||||
<where>
|
||||
<where>
|
||||
and deleted_at is null
|
||||
<if test="taskName != null and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
|
||||
<if test="appId != null "> and app_id = #{appId}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
@@ -37,7 +38,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectUsdtAggregationTaskById" parameterType="Long" resultMap="UsdtAggregationTaskResult">
|
||||
<include refid="selectUsdtAggregationTaskVo"/>
|
||||
where id = #{id}
|
||||
where id = #{id} and deleted_at is null
|
||||
</select>
|
||||
|
||||
<select id="selectUsdtAggregationTaskByIdForUpdate" resultMap="UsdtAggregationTaskResult">
|
||||
<include refid="selectUsdtAggregationTaskVo"/>
|
||||
where id = #{id} and deleted_at is null for update
|
||||
</select>
|
||||
|
||||
<select id="selectPendingTaskByAppId" resultMap="UsdtAggregationTaskResult">
|
||||
|
||||
Reference in new issue
Block a user