Merge remote-tracking branch 'origin/master'

This commit is contained in:
EnderByEndera
2024-04-22 15:08:01 +08:00
11 changed files with 102 additions and 10 deletions

View File

@@ -50,7 +50,7 @@ public class TaskCommandInfo {
@Schema(description = "局点", example = "123456")
@JsonProperty("distribute_point")
private Integer distributePoint;
private String distributePoint;
@Schema(description = "事件类型(策略模板名称)", example = "DDOS")
@JsonProperty("event_type")
@@ -123,6 +123,7 @@ public class TaskCommandInfo {
this.taskType = original.taskType;
this.taskAct = original.taskAct;
this.distributePoint = original.distributePoint;
this.eventType = original.eventType;
this.frequency = original.frequency;
this.startTime = original.startTime;
this.endTime = original.endTime;

View File

@@ -32,7 +32,7 @@ public class AlertMessageService {
public void processAlertMessage(AlertMessage alertMessage) {
//根据告警信息——>生成指令
List<TaskCommandInfo> dynamicTaskCommandInfoList = generateDynamicCommand(alertMessage);
//获取任务状态设置指令的isValid字段且是否生成指令入库除了RUNING\PAUSED状态其他都不入库
//获取任务状态设置指令的isValid字段且是否生成指令入库除了RUNING\PAUSED状态其他都不入command库)。
Integer taskStatus = dynamicTaskCommandInfoList.get(0).getTaskStatus();
//获取任务类型设置指令的isJudged字段。
Integer taskType = dynamicTaskCommandInfoList.get(0).getTaskType();
@@ -89,7 +89,7 @@ public class AlertMessageService {
alertMessage.getProtectIsSrcOrDst(), templateProtectLevel);
//根据fiveTuple生成动态指令信息
List<TaskCommandInfo> dynamicCommandInfoList = new ArrayList<TaskCommandInfo>();
List<TaskCommandInfo> dynamicCommandInfoList = new ArrayList<>();
if (fiveTupleWithMaskNew.size() == 2){
TaskCommandInfo dynamicCommandInfo_bi = new TaskCommandInfo();
dynamicCommandInfo_bi.copyTaskCommandInfo(dynamicCommandInfo);
@@ -203,7 +203,7 @@ public class AlertMessageService {
peer.setPort(null);
peer.setMaskPort(null);
}
List<FiveTupleWithMask> newFiveTupleWithMask = new ArrayList<FiveTupleWithMask>();
List<FiveTupleWithMask> newFiveTupleWithMask = new ArrayList<>();
//生成指令
FiveTupleWithMask command1 = new FiveTupleWithMask();
command1.setSourceIP(peer.getIP());

View File

@@ -14,7 +14,9 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@@ -163,7 +165,7 @@ public class StaticRuleController implements StaticRuleControllerApi {
public ResponseResult updateStaticRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
return new ResponseResult(400, "id or status is invalid")
.setData("whiteobj_id", id)
.setData("staticRule_id", id)
.setData("success", false);
}
return ResponseResult.ok()
@@ -173,4 +175,29 @@ public class StaticRuleController implements StaticRuleControllerApi {
}
/**
* 批量修改审核状态
*/
@PostMapping("/auditbatch")
public ResponseResult updateStaticRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
List<Integer> errorIds = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
Integer auditStatus = entry.getValue();
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
return new ResponseResult(400, "id or status is invalid")
.setData("staticRule_id", errorIds)
.setData("success", false);
}
return ResponseResult.ok()
.setData("success", staticRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
}
}

View File

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface StaticRuleMapper {
@@ -43,4 +44,6 @@ public interface StaticRuleMapper {
String static_rule_create_username, String ip);
List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids);
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch")Map<Integer, Integer> idWithAuditStatusBatch);
}

View File

@@ -155,7 +155,7 @@ public class StaticRuleService {
}
List<StaticRuleObject> StaticRuleBatch = ListUtils.newArrayListWithExpectedSize(100);
for (StaticRuleObject staticRule : staticRuleList) {
for (StaticRuleObject staticRule : list) {
staticRule.setStaticRuleCreateTime(LocalDateTime.now());
StaticRuleBatch.add(staticRule);
if (StaticRuleBatch.size() < 100) {
@@ -215,4 +215,31 @@ public class StaticRuleService {
public List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids) {
return staticRuleMapper.queryStaticRuleByIds(ids);
}
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
Function<StaticRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateStaticRuleAuditStatusFunction =
mapper -> map -> {
if (map == null || map.isEmpty()) {
return false;
}
Map<Integer, Integer> idWithAuditStatusBatch = new HashMap<>();
for (Map.Entry<Integer, Integer> item : map.entrySet()) {
idWithAuditStatusBatch.put(item.getKey(), item.getValue());
if (idWithAuditStatusBatch.size() < 100) {
continue;
}
//mapper指的就是外层函数输入的参数也就是WhiteListMapper
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
}
return true;
};
//实现事务操作
return sqlSessionWrapper.startBatchSession(StaticRuleMapper.class, updateStaticRuleAuditStatusFunction, idsWithAuditStatusMap);
}
}