1、修复动态规则、任务批量审批bug
2、配置新增批量审批 3、规则、任务补全创建人属性 4、删去kafkatest配置文件
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -480,4 +480,7 @@ public interface TemplateControllerApi {
|
||||
)
|
||||
@GetMapping("/statistics")
|
||||
ResponseResult statisticsTemplate();
|
||||
|
||||
@PostMapping("/auditbatch")
|
||||
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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("策略模板部分不存在");
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
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);
|
||||
}
|
||||
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("success", success);
|
||||
resultMap.put("audit_status", auditStatus);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user