1、修复动态规则、任务批量审批bug

2、配置新增批量审批
3、规则、任务补全创建人属性
4、删去kafkatest配置文件
This commit is contained in:
PushM
2024-05-09 13:06:21 +08:00
parent 1b7460be64
commit dc70c713b2
32 changed files with 373 additions and 211 deletions

View File

@@ -66,16 +66,16 @@ public class ProtectObject {
@JsonProperty("proobj_create_username")
@ExcelIgnore
@Schema(description = "防护对象创建人", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防护对象创建人", example = "xxx")
private String protectObjectCreateUsername;
@JsonProperty("proobj_create_depart")
@ExcelIgnore
@Schema(description = "防护对象创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防护对象创建人处室", example = "xxx")
private String protectObjectCreateDepart;
@JsonProperty("proobj_create_userid")
@ExcelIgnore
@Schema(description = "防护对象创建人ID", example = "0", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防护对象创建人ID", example = "0")
private Integer protectObjectCreateUserId;
}

View File

@@ -62,15 +62,15 @@ public class Template {
private Integer runningTasks;
@JsonProperty("create_user_id")
@Schema(description = "防御策略模板创建人ID", example = "1", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防御策略模板创建人ID", example = "1")
private Integer createUserId;
@JsonProperty("create_user_name")
@Schema(description = "防御策略模板创建人名称", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防御策略模板创建人名称", example = "xxx")
private String createUsername;
@JsonProperty("create_user_depart")
@Schema(description = "防御策略模板创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "防御策略模板创建人处室", example = "xxx")
private String createDepart;
@JsonProperty("audit_status")

View File

@@ -50,19 +50,19 @@ public class StaticRuleObject {
@JsonProperty("static_rule_create_username")
@ExcelIgnore
@Schema(description = "静态规则创建用户名称", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "静态规则创建用户名称")
private String staticRuleCreateUsername;
@JsonProperty("static_rule_audit_status")
@ExcelIgnore
@Schema(description = "静态规则审核状态0为未审核1为已退回2为审核通过", example = "2", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "静态规则审核状态0为未审核1为已退回2为审核通过", example = "2")
private Integer auditStatus;
@JsonProperty("static_rule_create_depart")
@ExcelIgnore
@Schema(description = "静态规则创建用户所属部门", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "静态规则创建用户所属部门")
private String staticRuleCreateDepart;
@JsonProperty("static_rule_create_user_id")
@ExcelIgnore
@Schema(hidden = true)
@Schema(description = "静态规则创建人ID")
private Integer staticRuleCreateUserId;
@JsonProperty("static_rule_used_task_id")
@ExcelIgnore

View File

@@ -56,15 +56,19 @@ public class Task {
private String taskAct;
@JsonProperty("task_create_username")
@Schema(description = "任务创建人名称", accessMode = Schema.AccessMode.READ_ONLY)
// @Schema(description = "任务创建人名称", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "任务创建人名称")
private String taskCreateUsername;
@JsonProperty("task_create_depart")
@Schema(description = "任务创建人处室", accessMode = Schema.AccessMode.READ_ONLY)
// @Schema(description = "任务创建人处室", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "任务创建人处室")
private String taskCreateDepart;
@JsonProperty("task_create_userid")
@Schema(description = "任务创建人ID", accessMode = Schema.AccessMode.READ_ONLY)
// @Schema(description = "任务创建人ID", accessMode = Schema.AccessMode.READ_ONLY)
@Schema(description = "任务创建人ID")
private Integer taskCreateUserId;
@JsonProperty("static_rule_ids")

View File

@@ -56,7 +56,6 @@ public class WhiteListObject {
@Schema(description = "白名单对象网络协议", example = "TCP", requiredMode = Schema.RequiredMode.REQUIRED)
private String whiteListProtocol;
@JsonProperty("audit_status")
@ExcelIgnore
@Schema(description = "白名单对象审核状态0为未审核1为已退回2为审核通过", example = "2")
@@ -67,4 +66,16 @@ public class WhiteListObject {
@Schema(description = "白名单展示id", example = "BMD-20200101-123456", accessMode = Schema.AccessMode.READ_ONLY)
private String whiteListDisplayId;
@JsonProperty("white_list_create_user_name")
@Schema(description = "白名单对象创建人名称")
private String createUserName;
@JsonProperty("white_list_create_user_id")
@Schema(description = "白名单对象创建人id")
private String createUserId;
@JsonProperty("white_list_create_user_department")
@Schema(description = "白名单对象创建人部门")
private String createUserDepartment;
}

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
@RequestMapping("/proobj")
@@ -168,4 +170,29 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
null, null, null, null, null,
AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState())));
}
/**
* 批量修改审核状态
*/
@Override
@PostMapping("/auditbatch")
public ResponseResult updateWhiteListAuditStatusBatch(@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("id", errorIds)
.setData("success", false);
}
return ResponseResult.ok()
.setData("success", protectObjectService.updateAuditStatusBatch(idsWithAuditStatusMap));
}
}

View File

@@ -18,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Tag(name = "防护对象API", description = "防护对象模块所有接口")
public interface ProtectObjectControllerApi {
@@ -445,4 +446,7 @@ public interface ProtectObjectControllerApi {
)
@GetMapping("/statistics")
ResponseResult statisticsProtectObject();
@PostMapping("/auditbatch")
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> 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 ProtectObjectMapper {
@@ -51,4 +52,8 @@ public interface ProtectObjectMapper {
@Param("page_size") Integer pageSize);
Integer queryUsedProtectObjectsTotalNum();
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
List<Integer> queryAuditStatusByIds(@Param("idsWithAuditStatusMap") Map<Integer, Integer> idsWithAuditStatusMap);
}

View File

@@ -7,11 +7,13 @@ 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;
@@ -166,4 +168,51 @@ public class ProtectObjectService {
public Integer queryUsedProtectObjectsTotalNum() {
return protectObjectMapper.queryUsedProtectObjectsTotalNum();
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = protectObjectMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {
throw new IllegalArgumentException("防护对象部分不存在");
}
int index = 0;
List<Integer> errorIds = new ArrayList<>();
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
Integer auditStatus = entry.getValue();
Integer originalAuditStatus = originalAuditStatusList.get(index);
index++;
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
throw new IllegalArgumentException("防护对象无法修改为对应审核状态, 错误id: " + errorIds);
}
Function<ProtectObjectMapper, Function<Map<Integer, Integer>, Boolean>> updateProtectObjectAuditStatusFunction =
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(ProtectObjectMapper.class, updateProtectObjectAuditStatusFunction, idsWithAuditStatusMap);
}
}

View File

@@ -7,6 +7,7 @@ import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -148,12 +149,13 @@ public class TemplateController implements TemplateControllerApi {
.setData("template_id", id);
}
/**
* 批量审批
* 批量修改审核状态
*/
/*
@Override
@PostMapping("/auditbatch")
public ResponseResult updateDynamicRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
public ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
List<Integer> errorIds = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
@@ -164,13 +166,11 @@ public class TemplateController implements TemplateControllerApi {
}
if (!errorIds.isEmpty()){
return new ResponseResult(400, "id or status is invalid")
.setData("staticRule_id", errorIds)
.setData("id", errorIds)
.setData("success", false);
}
return ResponseResult.ok();
// .setData("success",dynamicRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
return ResponseResult.ok()
.setData("success", templateService.updateAuditStatusBatch(idsWithAuditStatusMap));
}
*/
}

View File

@@ -480,4 +480,7 @@ public interface TemplateControllerApi {
)
@GetMapping("/statistics")
ResponseResult statisticsTemplate();
@PostMapping("/auditbatch")
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
}

View File

@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface TemplateMapper {
@@ -48,4 +49,8 @@ public interface TemplateMapper {
Integer queryAuditStatusById(Integer id);
Boolean updateAuditStatusById(Integer id, Integer auditStatus);
List<Integer> queryAuditStatusByIds(@Param("idsWithAuditStatusMap") Map<Integer, Integer> idsWithAuditStatusMap);
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
}

View File

@@ -2,26 +2,32 @@ package com.realtime.protection.server.defense.template;
import com.realtime.protection.configuration.entity.defense.template.Template;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
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.function.Function;
@Service
public class TemplateService {
private final TemplateMapper templateMapper;
private final Counter counter;
private final SqlSessionWrapper sqlSessionWrapper;
public TemplateService(TemplateMapper templateMapper, Counter counter) {
public TemplateService(TemplateMapper templateMapper, Counter counter, SqlSessionWrapper sqlSessionWrapper) {
this.templateMapper = templateMapper;
this.counter = counter;
this.sqlSessionWrapper = sqlSessionWrapper;
}
@Transactional
@@ -119,26 +125,29 @@ public class TemplateService {
resultMap.put("audit_status", auditStatus);
return resultMap;
}
/*
public Map<String, Object> updateAuditStatus(Integer id, Integer auditStatus) {
Integer originalAuditStatus = templateMapper.queryAuditStatusById(id);
if (originalAuditStatus == null) {
throw new IllegalArgumentException("cannot find audit status of static rule " + id + ", maybe static rule doesn't exist?");
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = templateMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {
throw new IllegalArgumentException("策略模板部分不存在");
}
int index = 0;
List<Integer> errorIds = new ArrayList<>();
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
Integer auditStatus = entry.getValue();
Integer originalAuditStatus = originalAuditStatusList.get(index);
index++;
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
throw new IllegalArgumentException("invalid audit status");
errorIds.add(id);
}
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
resultMap.put("audit_status", auditStatus);
return resultMap;
}
if (!errorIds.isEmpty()){
throw new IllegalArgumentException("策略模板无法修改为对应审核状态, 错误id: " + errorIds);
}
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
Function<DynamicRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateDynamicRuleAuditStatusFunction =
Function<TemplateMapper, Function<Map<Integer, Integer>, Boolean>> updateTemplateAuditStatusFunction =
mapper -> map -> {
if (map == null || map.isEmpty()) {
return false;
@@ -160,9 +169,9 @@ public class TemplateService {
return true;
};
//实现事务操作
return sqlSessionWrapper.startBatchSession(DynamicRuleMapper.class, updateDynamicRuleAuditStatusFunction, idsWithAuditStatusMap);
return sqlSessionWrapper.startBatchSession(TemplateMapper.class, updateTemplateAuditStatusFunction, idsWithAuditStatusMap);
}
*/
}

View File

@@ -61,5 +61,5 @@ public interface DynamicRuleMapper {
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusMap);
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusMap") Map<Integer, Integer> idWithAuditStatusMap);
}

View File

@@ -232,6 +232,9 @@ public class DynamicRuleService {
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {
return new IllegalArgumentException("部分动态规则id不存在");
}
int index = 0;
List<Integer> errorIds = new ArrayList<>();
@@ -240,15 +243,13 @@ public class DynamicRuleService {
Integer auditStatus = entry.getValue();
Integer originalAuditStatus = originalAuditStatusList.get(index);
index++;
if (originalAuditStatus == null) {
errorIds.add(id);
}
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
return new IllegalArgumentException("动态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
return new IllegalArgumentException("动态规则id无法修改为对应审核状态, 错误id: " + errorIds);
}
@@ -277,4 +278,8 @@ public class DynamicRuleService {
return sqlSessionWrapper.startBatchSession(DynamicRuleMapper.class, updateDynamicRuleAuditStatusFunction, idsWithAuditStatusMap);
}
public List<Integer> queryAuditStatusByIds(Map<Integer, Integer> idsWithAuditStatusMap) {
return dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
}
}

View File

@@ -266,9 +266,12 @@ public class StaticRuleService {
return staticRuleMapper.queryStaticRuleByIds(ids);
}
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = staticRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {
throw new IllegalArgumentException("部分静态规则id不存在");
}
int index = 0;
List<Integer> errorIds = new ArrayList<>();
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
@@ -276,15 +279,12 @@ public class StaticRuleService {
Integer auditStatus = entry.getValue();
Integer originalAuditStatus = originalAuditStatusList.get(index);
index++;
if (originalAuditStatus == null) {
errorIds.add(id);
}
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
return new IllegalArgumentException("静态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
throw new IllegalArgumentException("静态规则id无法修改为对应审核状态, 错误id: " + errorIds);
}
Function<StaticRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateStaticRuleAuditStatusFunction =
@@ -316,6 +316,11 @@ public class StaticRuleService {
return staticRuleMapper.queryUsedStaticRuleTotalNum();
}
public List<Integer> queryAuditStatusByIds(Map<Integer, Integer> idsWithAuditStatusMap) {
List<Integer> originalAuditStatusList = staticRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
return originalAuditStatusList;
}
public Integer queryAuditStaticRuleTotalNum(Integer auditStatus) {
return staticRuleMapper.queryAuditStaticRuleTotalNum(auditStatus);
}

View File

@@ -53,9 +53,9 @@ public class TaskService {
@Transactional
public Long newTask(Task task) {
// todo: 目前获取方式还不确定,以后再确定
task.setTaskCreateUserId(1);
task.setTaskCreateUsername("xxx");
task.setTaskCreateDepart("xxx");
// task.setTaskCreateUserId(1);
// task.setTaskCreateUsername("xxx");
// task.setTaskCreateDepart("xxx");
task.setTaskDisplayId(
"RW-"
@@ -312,7 +312,7 @@ public class TaskService {
staticCommandInfos.forEach(taskCommandInfo -> {
taskCommandInfo.setProtocolNum();
taskCommandInfo.setMask();
// taskCommandInfo.setMask();
});
return staticCommandInfos;
@@ -345,9 +345,13 @@ public class TaskService {
taskAct, taskAuditor, taskSource, ruleName,null);
}
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = taskMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {
throw new IllegalArgumentException("任务id部分不存在");
}
int index = 0;
List<Integer> errorIds = new ArrayList<>();
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
@@ -355,15 +359,13 @@ public class TaskService {
Integer auditStatus = entry.getValue();
Integer originalAuditStatus = originalAuditStatusList.get(index);
index++;
if (originalAuditStatus == null) {
errorIds.add(id);
}
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
return new IllegalArgumentException("动态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
throw new IllegalArgumentException("动态规则id无法修改为对应审核状态, errorIds: " + errorIds);
}
Function<TaskMapper, Function<Map<Integer, Integer>, Boolean>> updateTaskAuditStatusFunction =

View File

@@ -12,7 +12,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
@RequestMapping("/whiteobj")
@@ -163,12 +165,11 @@ public class WhiteListController implements WhiteListControllerApi {
@GetMapping("/{id}/audit/{auditStatus}")
public ResponseResult updateWhiteListObjectAuditStatus(@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("success", false);
// }
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
return new ResponseResult(400, "id or status is invalid")
.setData("whiteobj_id", id)
.setData("success", false);
}
return ResponseResult.ok()
.addDataMap(whiteListService.updateWhiteListObjectAuditStatus(id, auditStatus))
.setData("whiteobj_id", id);
@@ -214,5 +215,29 @@ public class WhiteListController implements WhiteListControllerApi {
));
}
/**
* 批量修改审核状态
*/
@Override
@PostMapping("/auditbatch")
public ResponseResult updateWhiteListAuditStatusBatch(@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("id", errorIds)
.setData("success", false);
}
return ResponseResult.ok()
.setData("success", whiteListService.updateAuditStatusBatch(idsWithAuditStatusMap));
}
}

View File

@@ -10,14 +10,12 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Tag(name = "白名单API", description = "白名单模块所有接口")
public interface WhiteListControllerApi {
@@ -297,4 +295,7 @@ public interface WhiteListControllerApi {
)
@GetMapping("/statistics")
ResponseResult getWhiteListStatisticsData();
@PostMapping("/auditbatch")
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
}

View File

@@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface WhiteListMapper {
@@ -50,4 +51,8 @@ public interface WhiteListMapper {
List<WhiteListObject> whiteListCStaticRulesCheck(@Param("staticRuleObjects") List<StaticRuleObject> staticRuleObjects);
Integer queryAuditWhiteListTotalNum(@Param("auditStatus") Integer auditStatus);
void updateAuditStatusByIdBatch(@Param("idsWithAuditStatusMap") Map<Integer, Integer> idsWithAuditStatusMap);
List<Integer> queryAuditStatusByIds(@Param("idsWithAuditStatusMap") Map<Integer, Integer> idsWithAuditStatusMap);
}

View File

@@ -14,6 +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;
@@ -216,4 +217,51 @@ public class WhiteListService {
public Integer queryAuditWhiteListTotalNum(Integer auditStatus) {
return whiteListMapper.queryAuditWhiteListTotalNum(auditStatus);
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = whiteListMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {
throw new IllegalArgumentException("白名单id部分不存在");
}
int index = 0;
List<Integer> errorIds = new ArrayList<>();
for(Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
Integer auditStatus = entry.getValue();
Integer originalAuditStatus = originalAuditStatusList.get(index);
index++;
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
throw new IllegalArgumentException("白名单id无法修改为对应审核状态, 错误id: " + errorIds);
}
Function<WhiteListMapper, Function<Map<Integer, Integer>, Boolean>> updateWhiteListAuditStatusFunction =
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(WhiteListMapper.class, updateWhiteListAuditStatusFunction, idsWithAuditStatusMap);
}
}

View File

@@ -1,134 +0,0 @@
server:
port: 8081
logging:
level:
com.realtime.protection: info
file:
name: classpath:log/realtime_protection.log
spring:
datasource:
dynamic:
datasource:
mysql:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: aiihhbfcsy123!@#
url: jdbc:mysql://192.168.107.89:3306/realtime_protection?serverTimezone=Asia/Shanghai
hikari:
is-auto-commit: false
doris:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
url: jdbc:mysql://10.26.22.133:9030/command
hikari:
is-auto-commit: false
aop:
enabled: true
primary: mysql
strict: false
grace-destroy: true
mvc:
servlet:
path: /api/v1
jackson:
default-property-inclusion: non_null
kafka:
# kafka集群信息多个用逗号间隔
bootstrap-servers: 192.168.107.49:9092
consumer:
topic-name: topic-test
# 消费者组
group-id: TestObjectGroup
# 是否自动提交偏移量默认值是true为了避免出现重复数据和数据丢失可以把它设置为false然后手动提交偏移量
enable-auto-commit: false
# 该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
# earliest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时从头开始消费分区的记录
# latest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时消费新产生的该分区下的数据在消费者启动之后生成的记录
# none当各分区都存在已提交的offset时从提交的offset开始消费只要有一个分区不存在已提交的offset则抛出异常
auto-offset-reset: latest
# 键的反序列化方式
key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
# 值的反序列化方式建议使用Json这种序列化方式可以无需额外配置传输实体类
value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
# 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
properties:
spring.json.trusted.packages: com.realtime.protection.configuration.entity.*
# 这个参数定义了poll方法最多可以拉取多少条消息默认值为500。如果在拉取消息的时候新消息不足500条那有多少返回多少如果超过500条每次只返回500。
# 这个默认值在有些场景下太大有些场景很难保证能够在5min内处理完500条消息
# 如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
# 然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
# 要避免出现上述问题提前评估好处理一条消息最长需要多少时间然后覆盖默认的max.poll.records参数
# 注需要开启BatchListener批量监听才会生效如果不开启BatchListener则不会出现reBalance情况
#max-poll-records: 3
spring.deserializer.key.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer
spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer
# properties:
# # 两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
# max:
# poll:
# interval:
# ms: 600000
# # 当broker多久没有收到consumer的心跳请求后就触发reBalance默认值是10s
# session:
# timeout:
# ms: 10000
producer:
# 重试次数设置大于0的值则客户端会将发送失败的记录重新发送
retries: 3
#批量处理大小16K
batch-size: 16384
#缓冲存储大32M
buffer-memory: 33554432
acks: 1
# 指定消息key和消息体的编码方式字符串序列化
key-serializer: org.springframework.kafka.support.serializer.JsonSerializer
#值序列化使用Json
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
# 监听
listener:
# record当每一条记录被消费者监听器ListenerConsumer处理之后提交
# batch当每一批poll()的数据被ListenerConsumer处理之后提交
# time当每一批poll()的数据被ListenerConsumer处理之后距离上次提交时间大于TIME时提交
# count当每一批poll()的数据被ListenerConsumer处理之后被处理record数量大于等于COUNT时提交
# count_timeTIME或COUNT中有一个条件满足时提交
# manual当每一批poll()的数据被ListenerConsumer处理之后, 手动调用Acknowledgment.acknowledge()后提交
# manual_immediate手动调用Acknowledgment.acknowledge()后立即提交,一般推荐使用这种
ack-mode: manual_immediate
# # 在侦听器容器中运行的线程数,一般设置为 机器数*分区数
# concurrency: 4
# # 自动提交关闭,需要设置手动消息确认
# ack-mode: manual_immediate
# # 消费监听接口监听的主题不存在时默认会报错所以设置为false忽略错误
# missing-topics-fatal: false
# # 两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
# poll-timeout: 600000
mybatis:
mapper-locations: classpath:mappers/*
task:
pool:
core-pool-size: 20
max-pool-size: 100
queue-capacity: 100
keep-alive-seconds: 120
springdoc:
api-docs:
enabled: true
path: /api-docs
swagger-ui:
path: /swagger
packages-to-scan: com.realtime.protection.server
management:
endpoint:
shutdown:
enabled: true

View File

@@ -35,7 +35,7 @@ spring:
default-property-inclusion: non_null
kafka:
# kafka集群信息多个用逗号间隔
bootstrap-servers: ${KAFKA_SERVERS}
bootstrap-servers: 192.168.107.49:9092
consumer:
topic-name: topic-alert
# 消费者组

View File

@@ -1,3 +1,3 @@
spring:
profiles:
active: kafkatest
active: test

View File

@@ -307,7 +307,7 @@
select audit_status
from t_dynamic_rule
where dynamic_rule_id in
<foreach collection="idWithAuditStatusBatch" item="id" open="(" separator="," close=")">
<foreach collection="idWithAuditStatusMap" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>

View File

@@ -141,6 +141,15 @@
FROM t_protect_object_dynamic_rule_conn
</select>
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
select protect_object_audit_status
from t_protect_object
where protect_object_id in
<foreach collection="idsWithAuditStatusMap" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<update id="updateProtectObject">
UPDATE t_protect_object
<set>
@@ -179,4 +188,17 @@
SET protect_object_audit_status = #{proobj_audit_status}
WHERE protect_object_id = #{proobj_id}
</update>
<update id="updateAuditStatusByIdBatch">
update t_protect_object
set protect_object_audit_status = CASE protect_object_id
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
WHEN #{id} THEN #{auditStatus}
</foreach>
END
WHERE protect_object_id IN
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>

View File

@@ -387,7 +387,7 @@
SELECT task_audit_status
FROM t_task
WHERE task_id IN
<foreach collection="idWithAuditStatusBatch" item="taskId" open="(" separator="," close=")">
<foreach collection="idWithAuditStatusBatch" index="taskId" open="(" separator="," close=")">
#{taskId}
</foreach>
</select>

View File

@@ -172,6 +172,15 @@
WHERE strategy_template_id = #{id}
</select>
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
select audit_status
from t_strategy_template
where strategy_template_id in
<foreach collection="idsWithAuditStatusMap" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<update id="updateTemplateInformation">
UPDATE t_strategy_template
<set>
@@ -189,4 +198,17 @@
SET audit_status = #{auditStatus}
WHERE strategy_template_id = #{id}
</update>
<update id="updateAuditStatusByIdBatch">
update t_strategy_template
set audit_status = CASE strategy_template_id
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
WHEN #{id} THEN #{auditStatus}
</foreach>
END
WHERE strategy_template_id IN
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>

View File

@@ -8,11 +8,15 @@
insert into t_white_list(white_list_name, white_list_system_name,
white_list_ip, white_list_port,
white_list_url, white_list_protocol,
white_list_audit_status, create_time, white_list_display_id)
white_list_audit_status, create_time, white_list_display_id,
white_list_create_username, white_list_create_depart,
white_list_create_user_id)
values (#{object.whiteListName}, #{object.whiteListSystemName},
INET_ATON(#{object.whiteListIP}), #{object.whiteListPort},
#{object.whiteListUrl}, #{object.whiteListProtocol},
0, NOW(), #{object.whiteListDisplayId})
0, NOW(), #{object.whiteListDisplayId},
#{object.createUsername}, #{object.createDepart},
#{object.createUserId})
</insert>
<insert id="newWhiteListObjects">
@@ -114,6 +118,19 @@
where white_list_id = #{id}
</update>
<update id="updateAuditStatusByIdBatch">
update t_white_list
set white_list_audit_status = CASE white_list_id
<foreach collection="idsWithAuditStatusMap" index="id" item="auditStatus" separator=" ">
WHEN #{id} THEN #{auditStatus}
</foreach>
END
WHERE white_list_id IN
<foreach collection="idsWithAuditStatusMap" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<select id="existWhiteListObject" resultType="java.lang.String">
select CONCAT(INET_NTOA(white_list_ip)," ", CAST(white_list_port)," ", white_list_url)
from t_white_list
@@ -310,4 +327,13 @@
where white_list_audit_status = #{auditStatus}
</select>
<select id="queryAuditStatusByIds" resultType="java.lang.Integer">
select white_list_audit_status
from t_white_list
where white_list_id in
<foreach collection="idsWithAuditStatusMap" index="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@@ -147,7 +147,8 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
map.put(112, 2);
// System.out.println(dynamicRuleMapper.queryAuditStatusByIds(map));
System.out.println(dynamicRuleService.updateAuditStatusBatch(map));
System.out.println(dynamicRuleService.queryAuditStatusByIds(map));
}
}

View File

@@ -112,6 +112,15 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
System.out.println(staticRuleService.updateAuditStatusBatch(map));
}
@Test
void testQueryAuditStatusByIds(){
Map<Integer, Integer> map = new HashMap<>();
map.put(1300, 0);
map.put(1326, 1);
map.put(1328, 1);
System.out.println(staticRuleService.queryAuditStatusByIds(map));
}

View File

@@ -14,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -134,4 +135,11 @@ class WhiteListServiceTest extends ProtectionApplicationTests {
List<WhiteListObject> whiteListObjects = whiteListService.queryWhiteListObject(null, null, null, null, null, 1, 2);
System.out.println(whiteListObjects);
}
@Test
void testUpdateAuditStatusByIdBatch() {
Map<Integer, Integer> idsWithAuditStatusMap = Map.of(7189, 2, 7192, 2);
whiteListService.updateAuditStatusBatch(idsWithAuditStatusMap);
}
}