diff --git a/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/DynamicRuleObject.java b/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/DynamicRuleObject.java index 9f3b60d..1c77011 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/DynamicRuleObject.java +++ b/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/DynamicRuleObject.java @@ -3,6 +3,8 @@ package com.realtime.protection.configuration.entity.rule.dynamicrule; import com.alibaba.excel.annotation.ExcelIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.realtime.protection.configuration.entity.defense.object.ProtectObject; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; @@ -101,5 +103,17 @@ public class DynamicRuleObject { @JsonProperty("dynamic_rule_audit_status") @ExcelIgnore @Schema(description = "动态规则审核状态(0为未审核,1为已退回,2为审核通过)", example = "2", accessMode = Schema.AccessMode.READ_ONLY) - private Integer dynamicRuleAuditStatus; + private Integer auditStatus; + + public void checkAuditStatusValidate(AuditStatusEnum newAuditStatus) { + if (!List.of(AuditStatusEnum.AUDITED.getNum(), AuditStatusEnum.USING.getNum()).contains(this.getAuditStatus())) { + throw new IllegalArgumentException("规则《" + this.getDynamicRuleName() + "》原审批状态非法"); + } + + if (!AuditStatusValidator + .setOriginal(this.getAuditStatus()) + .checkValidate(newAuditStatus.getNum())) { + throw new IllegalArgumentException("规则《" + this.getDynamicRuleName() + "》审核状态错误"); + } + } } diff --git a/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java b/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java index e61b1eb..5dc8cda 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java +++ b/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java @@ -3,6 +3,8 @@ package com.realtime.protection.configuration.entity.rule.staticrule; import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonProperty; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; @@ -14,6 +16,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDateTime; +import java.util.List; @Data @Builder @@ -47,7 +50,7 @@ public class StaticRuleObject { @JsonProperty("static_rule_audit_status") @ExcelIgnore @Schema(description = "静态规则审核状态(0为未审核,1为已退回,2为审核通过)", example = "2", accessMode = Schema.AccessMode.READ_ONLY) - private Integer staticRuleAuditStatus; + private Integer auditStatus; @JsonProperty("static_rule_create_depart") @ExcelIgnore @Schema(description = "静态规则创建用户所属部门", accessMode = Schema.AccessMode.READ_ONLY) @@ -142,4 +145,15 @@ public class StaticRuleObject { @Schema(description = "频率,最低为1", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) private Integer staticRuleFrequency; + public void checkAuditStatusValidate(AuditStatusEnum newAuditStatus) { + if (!List.of(AuditStatusEnum.AUDITED.getNum(), AuditStatusEnum.USING.getNum()).contains(this.getAuditStatus())) { + throw new IllegalArgumentException("规则《" + this.getStaticRuleName() + "》原审批状态非法"); + } + + if (!AuditStatusValidator + .setOriginal(this.getAuditStatus()) + .checkValidate(newAuditStatus.getNum())) { + throw new IllegalArgumentException("规则《" + this.getStaticRuleName() + "》审核状态错误"); + } + } } diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java b/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java index cb8f844..b07c3cb 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java @@ -87,7 +87,9 @@ public class FiveTupleWithMask { public void setProtocolNum() { ProtocolEnum protocol = ProtocolEnum.getProtocolEnumByProtocol(this.protocol); - assert protocol != null; + if (protocol == null) { + return; + } this.protocolNum = protocol.getNumber(); } diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java index d6b060e..a84807d 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java @@ -140,10 +140,16 @@ public class TaskCommandInfo { } public void setProtocolNum() { + if (this.fiveTupleWithMask == null) { + return; + } this.fiveTupleWithMask.setProtocolNum(); } public void setMask() { + if (this.fiveTupleWithMask == null) { + return; + } this.fiveTupleWithMask.setMask(); } } diff --git a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java index 2d51188..35801fc 100644 --- a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java +++ b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java @@ -57,7 +57,7 @@ public class StaticRuleService { public Integer newStaticRuleObject(StaticRuleObject object) { object.setStaticRuleCreateTime(LocalDateTime.now()); - object.setStaticRuleAuditStatus(0); + object.setAuditStatus(0); /* 待开发:设置静态规则对象的创建用户、用户所属部门等属性 */ @@ -114,7 +114,7 @@ public class StaticRuleService { throw new IllegalArgumentException("未知的静态规则ID"); } - if (!staticRuleObject.getStaticRuleAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) { + if (!staticRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) { throw new IllegalStateException("无法修改该静态规则,因为其审核状态未处于" + AuditStatusEnum.AUDITED); } @@ -125,7 +125,7 @@ public class StaticRuleService { //判断当前静态规则是否能够修改---是否存在任务选择的静态规则?? //按id查询该静态规则的used_task_id字段,如果不为空,则不能修改 object.setStaticRuleModifyTime(LocalDateTime.now()); - object.setStaticRuleAuditStatus(AuditStatusEnum.PENDING.getNum()); + object.setAuditStatus(AuditStatusEnum.PENDING.getNum()); //修改静态规则 return staticRuleMapper.updateStaticRule(id, object); } @@ -200,7 +200,7 @@ public class StaticRuleService { return; } - if (Objects.equals(staticRuleObject.getStaticRuleAuditStatus(), AuditStatusEnum.USING.getNum())) { + if (Objects.equals(staticRuleObject.getAuditStatus(), AuditStatusEnum.USING.getNum())) { throw new IllegalArgumentException("当前静态规则正在使用,无法删除"); } staticRuleMapper.deleteStaticRuleById(id); diff --git a/src/main/java/com/realtime/protection/server/task/TaskService.java b/src/main/java/com/realtime/protection/server/task/TaskService.java index 860a15e..93afd23 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskService.java +++ b/src/main/java/com/realtime/protection/server/task/TaskService.java @@ -1,6 +1,9 @@ package com.realtime.protection.server.task; +import com.alibaba.excel.util.MapUtils; import com.baomidou.dynamic.datasource.annotation.DS; +import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject; +import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject; import com.realtime.protection.configuration.entity.task.DynamicTaskInfo; import com.realtime.protection.configuration.entity.task.Task; import com.realtime.protection.configuration.entity.task.TaskCommandInfo; @@ -8,6 +11,8 @@ import com.realtime.protection.configuration.utils.SqlSessionWrapper; import com.realtime.protection.configuration.utils.enums.StateEnum; import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator; +import com.realtime.protection.server.rule.dynamicrule.DynamicRuleMapper; +import com.realtime.protection.server.rule.staticrule.StaticRuleMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,17 +22,23 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Function; +import java.util.stream.Collectors; @Service @Slf4j @DS("mysql") public class TaskService { private final TaskMapper taskMapper; + private final StaticRuleMapper staticRuleMapper; private final SqlSessionWrapper sqlSessionWrapper; + private static final int BATCH_SIZE = 100; + private final DynamicRuleMapper dynamicRuleMapper; - public TaskService(TaskMapper taskMapper,SqlSessionWrapper sqlSessionWrapper) { + public TaskService(TaskMapper taskMapper, StaticRuleMapper staticRuleMapper, SqlSessionWrapper sqlSessionWrapper, DynamicRuleMapper dynamicRuleMapper) { this.taskMapper = taskMapper; + this.staticRuleMapper = staticRuleMapper; this.sqlSessionWrapper = sqlSessionWrapper; + this.dynamicRuleMapper = dynamicRuleMapper; } @Transactional @@ -36,19 +47,146 @@ public class TaskService { task.setTaskCreateUsername("xxx"); task.setTaskCreateDepart("xxx"); - // todo: 添加新建任务时,将动态/静态规则从“已审核”修改为“使用中” - taskMapper.newTask(task); - if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty()) + if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty()) { + staticRuleMapper.queryStaticRuleByIds(task.getStaticRuleIds()).forEach(staticRuleObject -> { + if (!staticRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) { + throw new IllegalArgumentException("部分规则审批状态错误"); + } + if (staticRuleObject.getStaticRuleUsedTaskId() != null) { + throw new IllegalArgumentException("部分静态规则已被其他任务使用"); + } + }); taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds()); + } - if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty()) + if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty()) { + dynamicRuleMapper.queryDynamicRuleByIds(task.getDynamicRuleIds()).forEach(dynamicRuleObject -> { + if (!dynamicRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) { + throw new IllegalArgumentException("部分规则审批状态错误"); + } + + if (dynamicRuleObject.getDynamicRuleUsedTaskId() != null) { + throw new IllegalArgumentException("部分动态规则已被其他任务使用"); + } + }); taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds()); + } return task.getTaskId(); } + /** + * 更新任务关联的静态规则审批状态,用于任务新建/停止时候,修改审批状态为已使用/已审批,不能用于其他审批状态修改 + * @param task 与静态规则关联的任务 + * @param newAuditStatus 需要修改的审批状态 + */ + public void updateStaticRuleAuditStatusInTask(Task task, AuditStatusEnum newAuditStatus) { + if (task == null) { + return; + } + + // 限制该函数仅能用于将规则修改为已审批/使用中 + if (!List.of(AuditStatusEnum.AUDITED, AuditStatusEnum.USING).contains(newAuditStatus)) { + return; + } + + List staticRuleObjects = staticRuleMapper.queryStaticRuleByIds(task.getStaticRuleIds()); + if (staticRuleObjects == null || staticRuleObjects.isEmpty()) { + throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在"); + } + + // 检查所有的静态规则审批状态是否正确,如果不正确则报错 + staticRuleObjects.forEach(staticRuleObject -> staticRuleObject.checkAuditStatusValidate(newAuditStatus)); + + Map staticRuleAuditStatusBatch = staticRuleObjects + .stream() + .collect(Collectors.toMap( + StaticRuleObject::getStaticRuleId, + k -> newAuditStatus.getNum(), // 将审核状态全部修改为使用中状态 + (existing, replacement) -> existing)); // 如果有重复字段,默认使用先前值 + + sqlSessionWrapper.startBatchSession( + StaticRuleMapper.class, + + (Function, Void>>) mapper -> staticRuleBatch -> { + Map batchMap = MapUtils.newHashMapWithExpectedSize(BATCH_SIZE); + for (Map.Entry auditStatusEntry : staticRuleBatch.entrySet()) { + batchMap.put(auditStatusEntry.getKey(), auditStatusEntry.getValue()); + if (batchMap.size() < BATCH_SIZE) { + continue; + } + + mapper.updateAuditStatusByIdBatch(batchMap); + batchMap.clear(); + } + + mapper.updateAuditStatusByIdBatch(batchMap); + batchMap.clear(); + + return null; + }, + + staticRuleAuditStatusBatch + ); + } + + /** + * 更新任务关联的动态规则审批状态,用于任务新建/停止时候,修改审批状态为已使用/已审批,不能用于其他审批状态修改 + * @param task 与动态规则关联的任务 + * @param newAuditStatus 需要修改的审批状态 + */ + public void updateDynamicRuleAuditStatusInTask(Task task, AuditStatusEnum newAuditStatus) { + if (task == null) { + return; + } + + // 限制该函数仅能用于将规则修改为已审批/使用中 + if (!List.of(AuditStatusEnum.AUDITED, AuditStatusEnum.USING).contains(newAuditStatus)) { + return; + } + + List dynamicRuleObjects = dynamicRuleMapper.queryDynamicRuleByIds(task.getDynamicRuleIds()); + if (dynamicRuleObjects == null || dynamicRuleObjects.isEmpty()) { + throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在"); + } + + // 检查所有的动态规则列表的审批状态是否正确,如不正确则报错 + dynamicRuleObjects.forEach(dynamicRuleObject -> dynamicRuleObject.checkAuditStatusValidate(newAuditStatus)); + + Map dynamicRuleAuditStatusBatch = dynamicRuleObjects + .stream() + .collect(Collectors.toMap( + DynamicRuleObject::getDynamicRuleId, + k -> newAuditStatus.getNum(), + (existing, replacement) -> existing)); + + sqlSessionWrapper.startBatchSession( + DynamicRuleMapper.class, + + (Function, Void>>) mapper -> batch -> { + Map batchMap = MapUtils.newHashMapWithExpectedSize(BATCH_SIZE); + for (Map.Entry auditStatusEntry : batch.entrySet()) { + batchMap.put(auditStatusEntry.getKey(), auditStatusEntry.getValue()); + if (batchMap.size() < BATCH_SIZE) { + continue; + } + + mapper.updateAuditStatusByIdBatch(batchMap); + batchMap.clear(); + } + + mapper.updateAuditStatusByIdBatch(batchMap); + batchMap.clear(); + + return null; + }, + + dynamicRuleAuditStatusBatch + ); + } + @Transactional public List queryTasks(Integer taskStatus, Integer taskType, String taskName, String taskCreator, @@ -116,6 +254,12 @@ public class TaskService { } public Boolean deleteTask(Long taskId) { + Task task = taskMapper.queryTask(taskId); + if (task == null) { + return true; + } + + updateStaticRuleAuditStatusInTask(task, AuditStatusEnum.AUDITED); return taskMapper.deleteTask(taskId); } diff --git a/src/main/java/com/realtime/protection/server/task/status/StateHandler.java b/src/main/java/com/realtime/protection/server/task/status/StateHandler.java index 07780a8..90ee668 100644 --- a/src/main/java/com/realtime/protection/server/task/status/StateHandler.java +++ b/src/main/java/com/realtime/protection/server/task/status/StateHandler.java @@ -36,14 +36,14 @@ public class StateHandler { } // 如果审核状态不为已通过审核,则报错 - if (taskAuditStatus != AuditStatusEnum.AUDITED.getNum()) { + if (!taskAuditStatus.equals(AuditStatusEnum.AUDITED.getNum())) { throw new IllegalArgumentException("无效的task_id,因为未通过审核"); } return switch (TaskTypeEnum.getTaskTypeByNum(task.getTaskType())) { - case STATIC -> handleStaticTaskStart(commandService, taskService, taskId); - case DYNAMIC -> handleDynamicTaskStart(taskService, taskId); - case JUDGED -> handleJudgedTaskStart(taskService, taskId); + case STATIC -> handleStaticTaskStart(commandService, taskService, task); + case DYNAMIC -> handleDynamicTaskStart(taskService, task); + case JUDGED -> handleJudgedTaskStart(taskService, task); }; } @@ -57,49 +57,60 @@ public class StateHandler { return true; } - protected Boolean handleStop(CommandService commandService, Long taskId) { + protected Boolean handleStop(CommandService commandService, TaskService taskService, Long taskId) { commandService.removeCommandsByTaskId(taskId); + taskService.updateDynamicRuleAuditStatusInTask(taskService.queryTask(taskId), AuditStatusEnum.AUDITED); + taskService.updateStaticRuleAuditStatusInTask(taskService.queryTask(taskId), AuditStatusEnum.AUDITED); return true; } - protected Boolean handleFinish(CommandService commandService, Long taskId) { + protected Boolean handleFinish(CommandService commandService, TaskService taskService, Long taskId) { commandService.removeCommandsByTaskId(taskId); + taskService.updateDynamicRuleAuditStatusInTask(taskService.queryTask(taskId), AuditStatusEnum.AUDITED); + taskService.updateStaticRuleAuditStatusInTask(taskService.queryTask(taskId), AuditStatusEnum.AUDITED); return true; } - protected Boolean handleFailed(CommandService commandService, Long taskId) { + protected Boolean handleFailed(CommandService commandService, TaskService taskService, Long taskId) { commandService.removeCommandsByTaskId(taskId); + taskService.updateDynamicRuleAuditStatusInTask(taskService.queryTask(taskId), AuditStatusEnum.AUDITED); + taskService.updateStaticRuleAuditStatusInTask(taskService.queryTask(taskId), AuditStatusEnum.AUDITED); return true; } // todo: 如果是实时任务或者研判后处置任务,那么就需要在任务启动之后,立刻向动态规则中指定的系统发送日志筛选请求。 // 筛选完成后,系统返回日志,需要由接收端点提取字段,并且合成一条静态规则,再按照任务开始时间、结束时间和任务类型进行指令创建 - private Boolean handleJudgedTaskStart(TaskService taskService, Long taskId) { - return sendFilters(taskService, taskId); + private Boolean handleJudgedTaskStart(TaskService taskService, Task task) { + return sendFilters(taskService, task); } - private Boolean handleDynamicTaskStart(TaskService taskService, Long taskId) { - return sendFilters(taskService, taskId); + private Boolean handleDynamicTaskStart(TaskService taskService, Task task) { + return sendFilters(taskService, task); } - private Boolean handleStaticTaskStart(CommandService commandService, TaskService taskService, Long taskId) { + private Boolean handleStaticTaskStart(CommandService commandService, TaskService taskService, Task task) { // 如果未能获取staticTaskCommandInfos,需要报错 - List staticTaskCommandInfos = taskService.getStaticCommandInfos(taskId); + List staticTaskCommandInfos = taskService.getStaticCommandInfos(task.getTaskId()); if (staticTaskCommandInfos == null || staticTaskCommandInfos.isEmpty()) { throw new IllegalArgumentException("静态规则列表为空,请至少选择一个静态规则以启动任务"); } + // 将所有关联的静态规则全部设置为已使用状态 + taskService.updateStaticRuleAuditStatusInTask(task, AuditStatusEnum.USING); + commandService.createCommands(staticTaskCommandInfos); return true; } - private Boolean sendFilters(TaskService taskService, Long taskId) { - List dynamicTaskInfos = taskService.getDynamicTaskInfos(taskId); + private Boolean sendFilters(TaskService taskService, Task task) { + List dynamicTaskInfos = taskService.getDynamicTaskInfos(task.getTaskId()); if (dynamicTaskInfos == null || dynamicTaskInfos.isEmpty()) { throw new IllegalArgumentException("动态规则列表为空,请至少选择一个动态规则以启动动态/研判后类型任务"); } + taskService.updateDynamicRuleAuditStatusInTask(task, AuditStatusEnum.AUDITED); + AtomicReference success = new AtomicReference<>(false); Mono mono = client.post() diff --git a/src/main/java/com/realtime/protection/server/task/status/states/FailedState.java b/src/main/java/com/realtime/protection/server/task/status/states/FailedState.java index 3eab4fa..251b0bb 100644 --- a/src/main/java/com/realtime/protection/server/task/status/states/FailedState.java +++ b/src/main/java/com/realtime/protection/server/task/status/states/FailedState.java @@ -11,8 +11,8 @@ public class FailedState extends StateHandler implements State { public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException { return switch (StateEnum.getStateEnumByState(newState)) { case RUNNING -> handleStart(taskService, commandService, taskId); - case STOP -> handleStop(commandService, taskId); - case FINISHED -> handleFinish(commandService, taskId); + case STOP -> handleStop(commandService, taskService, taskId); + case FINISHED -> handleFinish(commandService, taskService, taskId); default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState)); }; } diff --git a/src/main/java/com/realtime/protection/server/task/status/states/GeneratingState.java b/src/main/java/com/realtime/protection/server/task/status/states/GeneratingState.java index 98dd397..47af68d 100644 --- a/src/main/java/com/realtime/protection/server/task/status/states/GeneratingState.java +++ b/src/main/java/com/realtime/protection/server/task/status/states/GeneratingState.java @@ -10,8 +10,8 @@ public class GeneratingState extends StateHandler implements State { public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) { return switch (StateEnum.getStateEnumByState(newState)) { case RUNNING -> true; - case FAILED -> handleFailed(commandService, taskId); - case FINISHED -> handleFinish(commandService, taskId); + case FAILED -> handleFailed(commandService, taskService, taskId); + case FINISHED -> handleFinish(commandService, taskService, taskId); default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState)); }; } diff --git a/src/main/java/com/realtime/protection/server/task/status/states/PauseState.java b/src/main/java/com/realtime/protection/server/task/status/states/PauseState.java index 137b034..3382565 100644 --- a/src/main/java/com/realtime/protection/server/task/status/states/PauseState.java +++ b/src/main/java/com/realtime/protection/server/task/status/states/PauseState.java @@ -10,9 +10,9 @@ public class PauseState extends StateHandler implements State { public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) { return switch (StateEnum.getStateEnumByState(newState)) { case RUNNING -> handleResume(commandService, taskId); - case STOP -> handleStop(commandService, taskId); - case FINISHED -> handleFinish(commandService, taskId); - case FAILED -> handleFailed(commandService, taskId); + case STOP -> handleStop(commandService, taskService, taskId); + case FINISHED -> handleFinish(commandService, taskService, taskId); + case FAILED -> handleFailed(commandService, taskService, taskId); default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState)); }; } diff --git a/src/main/java/com/realtime/protection/server/task/status/states/PendingState.java b/src/main/java/com/realtime/protection/server/task/status/states/PendingState.java index b7f6ec1..6973e63 100644 --- a/src/main/java/com/realtime/protection/server/task/status/states/PendingState.java +++ b/src/main/java/com/realtime/protection/server/task/status/states/PendingState.java @@ -10,9 +10,9 @@ public class PendingState extends StateHandler implements State { @Override public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException { return switch (StateEnum.getStateEnumByState(newState)) { - case FAILED -> handleFailed(commandService, taskId); + case FAILED -> handleFailed(commandService, taskService, taskId); case RUNNING -> handleStart(taskService, commandService, taskId); - case FINISHED -> handleFinish(commandService, taskId); + case FINISHED -> handleFinish(commandService, taskService, taskId); default -> throw new IllegalStateException(taskId + " meets unexpected value: " + StateEnum.getStateEnumByState(newState)); }; diff --git a/src/main/java/com/realtime/protection/server/task/status/states/RunningState.java b/src/main/java/com/realtime/protection/server/task/status/states/RunningState.java index e875d6b..e36ad9a 100644 --- a/src/main/java/com/realtime/protection/server/task/status/states/RunningState.java +++ b/src/main/java/com/realtime/protection/server/task/status/states/RunningState.java @@ -10,9 +10,9 @@ public class RunningState extends StateHandler implements State { public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) { return switch (StateEnum.getStateEnumByState(newState)) { case PAUSED -> handlePause(commandService, taskId); - case STOP -> handleStop(commandService, taskId); - case FINISHED -> handleFinish(commandService, taskId); - case FAILED -> handleFailed(commandService, taskId); + case STOP -> handleStop(commandService, taskService, taskId); + case FINISHED -> handleFinish(commandService, taskService, taskId); + case FAILED -> handleFailed(commandService, taskService, taskId); default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState)); }; } diff --git a/src/main/java/com/realtime/protection/server/task/status/states/StopState.java b/src/main/java/com/realtime/protection/server/task/status/states/StopState.java index 46ef965..f301cba 100644 --- a/src/main/java/com/realtime/protection/server/task/status/states/StopState.java +++ b/src/main/java/com/realtime/protection/server/task/status/states/StopState.java @@ -12,8 +12,8 @@ public class StopState extends StateHandler implements State { public Boolean handle(State newState, CommandService commandService, TaskService taskService, Long taskId) throws DorisStartException { return switch (StateEnum.getStateEnumByState(newState)) { case RUNNING -> handleStart(taskService, commandService, taskId); - case FAILED -> handleFailed(commandService, taskId); - case FINISHED -> handleFinish(commandService, taskId); + case FAILED -> handleFailed(commandService, taskService, taskId); + case FINISHED -> handleFinish(commandService, taskService, taskId); default -> throw new IllegalStateException("Unexpected value: " + StateEnum.getStateEnumByState(newState)); }; } diff --git a/src/main/resources/mappers/StaticRuleMapper.xml b/src/main/resources/mappers/StaticRuleMapper.xml index 2025944..dd2c0a3 100644 --- a/src/main/resources/mappers/StaticRuleMapper.xml +++ b/src/main/resources/mappers/StaticRuleMapper.xml @@ -86,7 +86,8 @@ update t_static_rule - set static_rule_audit_status = CASE static_rule_id + set static_rule_modify_time = NOW(), + static_rule_audit_status = CASE static_rule_id WHEN #{id} THEN #{auditStatus} diff --git a/src/main/resources/mappers/TaskMapper.xml b/src/main/resources/mappers/TaskMapper.xml index 4c98aed..a3bc326 100644 --- a/src/main/resources/mappers/TaskMapper.xml +++ b/src/main/resources/mappers/TaskMapper.xml @@ -81,13 +81,13 @@