1、AlertMessage入库修复字段和库表不匹配问题,增加display_id

2、command增加display_id
3、规则、任务、配置增加新建时(批量导入除外)、任务运行状态、审核状态改变时的历史记录
This commit is contained in:
PushM
2024-06-04 20:07:29 +08:00
parent 25ade2ef06
commit a756f9aedb
27 changed files with 1063 additions and 59 deletions

View File

@@ -55,7 +55,7 @@ public class AlertMessage {
@JsonProperty("c_priority")
private Integer c_priority;
@JsonProperty("c_time")
private LocalDateTime c_time;
private Long c_time;
@JsonProperty("c_flowid")
private String c_flowid;
@JsonProperty("c_src_ipv4")
@@ -80,8 +80,8 @@ public class AlertMessage {
private Integer c_d_tunnel_port;
@JsonProperty("c_proto_type")
private Integer c_proto_type;
@JsonProperty("c_return_info")
private String c_return_info;
@JsonProperty("c_s_boundary")
private Long c_s_boundary;
@JsonProperty("c_s_region")
@@ -108,8 +108,8 @@ public class AlertMessage {
private String c_d_owner;
@JsonProperty("c_ret_file_type")
private Integer c_ret_file_type;
@JsonProperty("c_ret_filename")
private String c_ret_filename;
@JsonProperty("c_ret_file_name")
private String c_ret_file_name;
@JsonProperty("c_ret_file")
private String c_ret_file;
@JsonProperty("c_url")
@@ -134,6 +134,15 @@ public class AlertMessage {
private Long c_d_mark4;
@JsonProperty("c_d_mark5")
private Long c_d_mark5;
@JsonProperty("display_id")
private String display_id;
@JsonProperty("c_return_info")
private String c_return_info;
// "c_priority": 0,
// "c_time": 1714528212,
// "c_flowid": "ca0c192021",

View File

@@ -115,6 +115,9 @@ public class TaskCommandInfo {
@Schema(description = "指令所属任务的运行状态", accessMode = Schema.AccessMode.READ_ONLY)
private Integer taskStatus;
@Schema(description = "指令展示id", accessMode = Schema.AccessMode.READ_ONLY)
private String displayId;
// 复制构造函数
public void copyTaskCommandInfo(TaskCommandInfo original) {
this.UUID = original.UUID;

View File

@@ -5,12 +5,15 @@ import com.realtime.protection.configuration.entity.alert.AlertMessage;
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.enums.StateEnum;
import com.realtime.protection.configuration.utils.enums.TaskTypeEnum;
import com.realtime.protection.server.command.CommandService;
import lombok.Data;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -20,11 +23,13 @@ import java.util.UUID;
public class AlertMessageService {
private final CommandService commandService;
private final AlertMessageMapper alertMessageMapper;
private final Counter counter;
public AlertMessageService(
CommandService commandService, AlertMessageMapper alertMessageMapper) {
CommandService commandService, AlertMessageMapper alertMessageMapper, Counter counter) {
this.commandService = commandService;
this.alertMessageMapper = alertMessageMapper;
this.counter = counter;
}
@DSTransactional
@@ -119,9 +124,17 @@ public class AlertMessageService {
String commandUUID = commandService.createCommand(dynamicTaskCommandInfo);
//alertmessage入库
alertMessage.setCommandUUID(commandUUID);
String alertMessageUUID = UUID.randomUUID().toString();
alertMessage.setAlertMessageUUID(alertMessageUUID);
alertMessage.setDisplay_id(
"GJ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("alert_message"))
);
alertMessageMapper.insertAlertMessage(alertMessage);
}
@@ -131,6 +144,13 @@ public class AlertMessageService {
alertMessage.setCommandUUID(null);
String alertMessageUUID = UUID.randomUUID().toString();
alertMessage.setAlertMessageUUID(alertMessageUUID);
alertMessage.setDisplay_id(
"GJ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("alert_message"))
);
alertMessageMapper.insertAlertMessage(alertMessage);
return alertMessageUUID;

View File

@@ -4,10 +4,13 @@ import com.alibaba.excel.util.ListUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
@@ -19,11 +22,13 @@ public class CommandService {
private final CommandMapper commandMapper;
private final SqlSessionWrapper sqlSessionWrapper;
private final Counter counter;
private static final int BatchSize = 100;
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper) {
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter) {
this.commandMapper = commandMapper;
this.sqlSessionWrapper = sqlSessionWrapper;
this.counter = counter;
}
@DSTransactional
@@ -32,6 +37,12 @@ public class CommandService {
if (uuid != null) {
return uuid;
}
commandInfo.setDisplayId(
"ZL-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("command"))
);
commandInfo.setUUID(UUID.randomUUID().toString());
commandMapper.createCommand(commandInfo);

View File

@@ -5,6 +5,7 @@ import com.realtime.protection.configuration.response.ResponseResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -60,4 +61,12 @@ public interface ProtectObjectMapper {
Boolean updateAuditInfo(@Param("ids")List<Integer> ids, @Param("auditInfo")String auditInfo);
String queryProtectObjectAuditInfo(Integer id);
void insertStaticRuleStatusLog(Integer id);
void updateStaticRuleStatusLogExpireTime(Integer id);
void insertStaticRuleStatusLogBatch(List<Integer> ids);
void updateStaticRuleStatusLogExpireTimeBatch(List<Integer> ids);
}

View File

@@ -2,21 +2,17 @@ package com.realtime.protection.server.defense.object;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import com.realtime.protection.configuration.response.ResponseResult;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import com.realtime.protection.server.whitelist.WhiteListMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
@Service
@@ -45,6 +41,7 @@ public class ProtectObjectService {
if (protectObject.getProtectObjectId() == null) {
return 0;
}
insertStaticRuleStatusLog(protectObject.getProtectObjectId());
return protectObject.getProtectObjectId();
}
@@ -145,6 +142,7 @@ public class ProtectObjectService {
}
Boolean success = protectObjectMapper.changeProtectObjectAuditStatus(protectObjectId, auditStatus);
insertStaticRuleStatusLog(protectObjectId);
Integer auditStatusNow = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
@@ -204,10 +202,12 @@ public class ProtectObjectService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -223,4 +223,27 @@ public class ProtectObjectService {
public String queryAuditInfo(Integer id) {
return protectObjectMapper.queryProtectObjectAuditInfo(id);
}
public void insertStaticRuleStatusLog(Integer id) {
//先把之前的状态日志过期,再插入新的状态日志
protectObjectMapper.updateStaticRuleStatusLogExpireTime(id);
protectObjectMapper.insertStaticRuleStatusLog(id);
}
public void insertStaticRuleStatusLog(Map<Integer, Integer> idWithAuditStatusBatch) {
Set<Integer> keys = idWithAuditStatusBatch.keySet();
ArrayList<Integer> ids = new ArrayList<>(keys);
protectObjectMapper.updateStaticRuleStatusLogExpireTimeBatch(ids);
protectObjectMapper.insertStaticRuleStatusLogBatch(ids);
}
public void insertStaticRuleStatusLog(List<StaticRuleObject> objects) {
List<Integer> ids = new ArrayList<>();
for (StaticRuleObject staticRuleObject : objects) {
ids.add(staticRuleObject.getStaticRuleId());
}
protectObjectMapper.updateStaticRuleStatusLogExpireTimeBatch(ids);
protectObjectMapper.insertStaticRuleStatusLogBatch(ids);
}
}

View File

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -61,4 +62,11 @@ public interface TemplateMapper {
String queryAuditInfo(Integer id);
void updateStatusLogExpireTime(Integer id);
void insertStatusLog(Integer id);
void updateStatusLogExpireTimeBatch(List<Integer> ids);
void insertStatusLogBatch(List<Integer> ids);
}

View File

@@ -1,6 +1,7 @@
package com.realtime.protection.server.defense.templatenew;
import com.realtime.protection.configuration.entity.defense.template.TemplateNew;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
@@ -8,10 +9,7 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
@Service
@@ -41,6 +39,7 @@ public class TemplateService {
if (template.getTemplateId() == null) {
return 0;
}
insertStatusLog(template.getTemplateId());
return template.getTemplateId();
}
@@ -103,7 +102,7 @@ public class TemplateService {
throw new IllegalArgumentException("invalid audit status");
}
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
insertStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
resultMap.put("audit_status", auditStatus);
@@ -145,10 +144,12 @@ public class TemplateService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -165,4 +166,26 @@ public class TemplateService {
public String queryAuditInfo(Integer id) {
return templateMapper.queryAuditInfo(id);
}
public void insertStatusLog(Integer id) {
templateMapper.updateStatusLogExpireTime(id);
templateMapper.insertStatusLog(id);
}
public void insertStatusLog(Map<Integer, Integer> idWithAuditStatusBatch) {
Set<Integer> keys = idWithAuditStatusBatch.keySet();
ArrayList<Integer> ids = new ArrayList<>(keys);
templateMapper.updateStatusLogExpireTimeBatch(ids);
templateMapper.insertStatusLogBatch(ids);
}
public void insertStatusLog(List<StaticRuleObject> objects) {
List<Integer> ids = new ArrayList<>();
for (StaticRuleObject staticRuleObject : objects) {
ids.add(staticRuleObject.getStaticRuleId());
}
templateMapper.updateStatusLogExpireTimeBatch(ids);
templateMapper.insertStatusLogBatch(ids);
}
}

View File

@@ -6,6 +6,7 @@ import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRule
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -64,4 +65,12 @@ public interface DynamicRuleMapper {
@Param("auditUserName")String auditUserName,
@Param("auditUserId")String auditUserId,
@Param("auditUserDepart")String auditUserDepart);
void insertStatusLog(Integer id);
void updateStatusLogExpireTime(Integer id);
void insertStatusLogBatch(List<Integer> ids);
void updateStatusLogExpireTimeBatch(List<Integer> ids);
}

View File

@@ -2,6 +2,7 @@ package com.realtime.protection.server.rule.dynamicrule;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.StateEnum;
@@ -11,10 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
@Service
@@ -40,7 +38,7 @@ public class DynamicRuleService {
);
dynamicRuleMapper.newDynamicRule(dynamicRule);
insertStatusLog(dynamicRule.getDynamicRuleId());
return dynamicRule.getDynamicRuleId();
}
@@ -205,6 +203,8 @@ public class DynamicRuleService {
}
Boolean success = dynamicRuleMapper.updateAuditStatusById(id, auditStatus ,auditUserName, auditUserId, auditUserDepart);
insertStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
resultMap.put("audit_status", auditStatus);
@@ -250,10 +250,12 @@ public class DynamicRuleService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -309,10 +311,13 @@ public class DynamicRuleService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusWithAuditorByIdBatch(idWithAuditStatusBatch, auditUserName, auditUserId, auditUserDepart);
insertStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusWithAuditorByIdBatch(idWithAuditStatusBatch, auditUserName, auditUserId, auditUserDepart);
insertStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -331,4 +336,30 @@ public class DynamicRuleService {
public String queryAuditInfo(Integer id) {
return dynamicRuleMapper.queryAuditInfo(id);
}
public void insertStatusLog(Integer id) {
dynamicRuleMapper.updateStatusLogExpireTime(id);
dynamicRuleMapper.insertStatusLog(id);
}
public void insertStatusLog(Map<Integer, Integer> idWithAuditStatusBatch) {
Set<Integer> keys = idWithAuditStatusBatch.keySet();
ArrayList<Integer> ids = new ArrayList<>(keys);
dynamicRuleMapper.updateStatusLogExpireTimeBatch(ids);
dynamicRuleMapper.insertStatusLogBatch(ids);
}
public void insertSStatusLog(List<StaticRuleObject> objects) {
List<Integer> ids = new ArrayList<>();
for (StaticRuleObject staticRuleObject : objects) {
ids.add(staticRuleObject.getStaticRuleId());
}
dynamicRuleMapper.updateStatusLogExpireTimeBatch(ids);
dynamicRuleMapper.insertStatusLogBatch(ids);
}
}

View File

@@ -52,6 +52,7 @@ public class StaticRuleController implements StaticRuleControllerApi {
object.setStaticRuleCreateUserId(Integer.valueOf(user.uid));
object.setStaticRuleCreateDepart(user.getOrgName());
}
//调用service新增
staticRuleService.newStaticRuleObject(object);
return ResponseResult.ok()

View File

@@ -5,7 +5,6 @@ import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@@ -37,7 +36,7 @@ public interface StaticRuleMapper {
void deleteStaticRules(@Param("staticRuleIds") List<Integer> staticRuleBatch);
void newStaticRules(List<StaticRuleObject> staticRuleBatch);
void newStaticRules(List<StaticRuleObject> list);
Integer queryAuditStatusById(Integer id);
@@ -69,4 +68,12 @@ public interface StaticRuleMapper {
Boolean updateAuditInfo(@Param("ids") List<Integer> ids, @Param("auditInfo") String auditInfo);
String queryAuditInfo(Integer id);
void insertStaticRuleStatusLog(Integer id);
void updateStaticRuleStatusLogExpireTime(Integer id);
void insertStaticRuleStatusLogBatch(List<Integer> ids);
void updateStaticRuleStatusLogExpireTimeBatch(List<Integer> ids);
}

View File

@@ -99,6 +99,8 @@ public class StaticRuleService {
staticRuleMapper.newStaticRuleObject(object);
insertStaticRuleStatusLog(object.getStaticRuleId());
return object.getStaticRuleId();
}
@@ -210,10 +212,13 @@ public class StaticRuleService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.newStaticRules(StaticRuleBatch);
//todo: 批量插入静态规则mybatis未返回主键id待解决
// insertStaticRuleStatusLog(StaticRuleBatch);
StaticRuleBatch.clear();
}
if (!StaticRuleBatch.isEmpty()) {
mapper.newStaticRules(StaticRuleBatch);
// insertStaticRuleStatusLog(StaticRuleBatch);
}
return true;
};
@@ -237,7 +242,8 @@ public class StaticRuleService {
throw new IllegalArgumentException("invalid audit status");
}
Boolean success = staticRuleMapper.updateAuditStatusById(id, auditStatus, auditUserName, auditUserId, auditUserDepart);
//记录状态历史
insertStaticRuleStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
resultMap.put("audit_status", auditStatus);
@@ -309,11 +315,13 @@ public class StaticRuleService {
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusWithAuditorByIdBatch(idWithAuditStatusBatch,
auditUserName, auditUserId, auditUserDepart);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusWithAuditorByIdBatch(idWithAuditStatusBatch,
auditUserName, auditUserId, auditUserDepart);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -358,10 +366,12 @@ public class StaticRuleService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -388,4 +398,26 @@ public class StaticRuleService {
public String queryAuditInfo(Integer id) {
return staticRuleMapper.queryAuditInfo(id);
}
public void insertStaticRuleStatusLog(Integer id) {
staticRuleMapper.updateStaticRuleStatusLogExpireTime(id);
staticRuleMapper.insertStaticRuleStatusLog(id);
}
public void insertStaticRuleStatusLog(Map<Integer, Integer> idWithAuditStatusBatch) {
Set<Integer> keys = idWithAuditStatusBatch.keySet();
ArrayList<Integer> ids = new ArrayList<>(keys);
staticRuleMapper.updateStaticRuleStatusLogExpireTimeBatch(ids);
staticRuleMapper.insertStaticRuleStatusLogBatch(ids);
}
public void insertStaticRuleStatusLog(List<StaticRuleObject> objects) {
List<Integer> ids = new ArrayList<>();
for (StaticRuleObject staticRuleObject : objects) {
ids.add(staticRuleObject.getStaticRuleId());
}
staticRuleMapper.updateStaticRuleStatusLogExpireTimeBatch(ids);
staticRuleMapper.insertStaticRuleStatusLogBatch(ids);
}
}

View File

@@ -104,4 +104,12 @@ public interface TaskMapper {
void deleteTaskProtectObjectConcat(Long taskId);
List<ProtectObject> queryProtectObjectsByTaskId(Long id);
void insertTaskStatusLog(Long taskId);
void updateTaskStatusLogExpireTime(Long taskId);
void insertTaskStatusLogBatch(List<Integer> idWithAuditStatusBatch);
void updateTaskStatusLogExpireTimeBatch(List<Integer> taskIds);
}

View File

@@ -101,7 +101,7 @@ public class TaskService {
}
}
insertTaskStatusLog(task.getTaskId());
return task.getTaskId();
}
@@ -316,7 +316,7 @@ public class TaskService {
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
taskMapper.changeTaskAuditStatusWithAudior(taskId, taskAuditStatus, auditUserName, auditUserId, auditUserDepart);
else return false;
insertTaskStatusLog(taskId);
return true;
}
@Transactional
@@ -329,6 +329,7 @@ public class TaskService {
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
taskMapper.changeTaskAuditStatus(taskId, taskAuditStatus);
else return false;
insertTaskStatusLog(taskId);
return true;
}
@@ -427,10 +428,13 @@ public class TaskService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
//记录状态日志
insertTaskStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertTaskStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -507,4 +511,16 @@ public class TaskService {
public String queryAuditInfo(Integer id) {
return taskMapper.queryAuditInfo(id);
}
public void insertTaskStatusLog(Long taskId) {
taskMapper.updateTaskStatusLogExpireTime(taskId);
taskMapper.insertTaskStatusLog(taskId);
}
public void insertTaskStatusLog(Map<Integer, Integer> idWithAuditStatusBatch) {
Set<Integer> keys = idWithAuditStatusBatch.keySet();
ArrayList<Integer> taskIds = new ArrayList<>(keys);
taskMapper.updateTaskStatusLogExpireTimeBatch(taskIds);
taskMapper.insertTaskStatusLogBatch(taskIds);
}
}

View File

@@ -70,8 +70,15 @@ public class StateChangeService {
originalState.getClass().getSimpleName(),
newState.getClass().getSimpleName()));
// 这里一定是handle成功的状态我们再进行task status的修改如果handle失败要么返回false要么抛出异常不会进入此处
return taskService.changeTaskStatus(taskId, stateNum);
Boolean isChanged = taskService.changeTaskStatus(taskId, stateNum);
//记录状态日志
if (isChanged) {
taskService.insertTaskStatusLog(taskId);
}
return isChanged;
}
private Boolean checkState(State originalState, State newState) {

View File

@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -59,4 +60,12 @@ public interface WhiteListMapper {
Boolean updateAuditInfo(@Param("ids")List<Integer> ids, @Param("auditInfo")String auditInfo);
String queryWhiteListObjectAuditInfo(Integer id);
void updateStatusLogExpireTime(Integer id);
void insertStatusLog(Integer id);
void updateStatusLogExpireTimeBatch(List<Integer> ids);
void insertStatusLogBatch(List<Integer> ids);
}

View File

@@ -14,10 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
@Service
@@ -50,6 +47,7 @@ public class WhiteListService {
);
whiteListMapper.newWhiteListObject(object);
insertStatusLog(object.getWhiteListId());
return object.getWhiteListId();
}
@@ -200,7 +198,7 @@ public class WhiteListService {
}
Boolean success = whiteListMapper.updateWhiteListObjectAuditStatus(id, auditStatus);
insertStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
resultMap.put("audit_status", auditStatus);
@@ -253,10 +251,12 @@ public class WhiteListService {
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
insertStatusLog(idWithAuditStatusBatch);
}
return true;
};
@@ -272,4 +272,26 @@ public class WhiteListService {
public String queryAuditInfo(Integer id) {
return whiteListMapper.queryWhiteListObjectAuditInfo(id);
}
public void insertStatusLog(Integer id) {
whiteListMapper.updateStatusLogExpireTime(id);
whiteListMapper.insertStatusLog(id);
}
public void insertStatusLog(Map<Integer, Integer> idWithAuditStatusBatch) {
Set<Integer> keys = idWithAuditStatusBatch.keySet();
List<Integer> ids = new ArrayList<>(keys);
whiteListMapper.updateStatusLogExpireTimeBatch(ids);
whiteListMapper.insertStatusLogBatch(ids);
}
public void insertStatusLog(List<StaticRuleObject> objects) {
List<Integer> ids = new ArrayList<>();
for (StaticRuleObject staticRuleObject : objects) {
ids.add(staticRuleObject.getStaticRuleId());
}
whiteListMapper.updateStatusLogExpireTimeBatch(ids);
whiteListMapper.insertStatusLogBatch(ids);
}
}