1、静态规则、动态规则、任务批量删除新增id、auditstatus合法性校验
2、Template新增auditstatus属性,修改query返回auditstatus,新增审批方法
(cherry picked from commit 03042f0aff)
This commit is contained in:
@@ -73,6 +73,11 @@ public class Template {
|
||||
@Schema(description = "防御策略模板创建人处室", example = "xxx", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String createDepart;
|
||||
|
||||
@JsonProperty("audit_status")
|
||||
@Schema(description = "防御策略模板审核状态(0为未审核,1为已退回,2为审核通过)", example = "1", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private String auditStatus;
|
||||
|
||||
|
||||
/**
|
||||
* 设置是否含有日常/应急/紧急防护等级态字段的字段
|
||||
*/
|
||||
|
||||
@@ -129,4 +129,46 @@ public class TemplateController implements TemplateControllerApi {
|
||||
AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState())
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 审批
|
||||
*/
|
||||
@GetMapping("/{id}/audit/{auditStatus}")
|
||||
public ResponseResult updateTemplateAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("template_id", id)
|
||||
.setData("success", false);
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
.addDataMap(templateService.updateAuditStatus(id, auditStatus))
|
||||
.setData("template_id", id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量审批
|
||||
*/
|
||||
/*
|
||||
@PostMapping("/auditbatch")
|
||||
public ResponseResult updateDynamicRuleAuditStatusBatch(@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",dynamicRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -42,4 +42,8 @@ public interface TemplateMapper {
|
||||
Integer queryUsedTemplateTotalNum();
|
||||
|
||||
Integer queryAuditTemplateTotalNum(Integer auditState);
|
||||
|
||||
Integer queryAuditStatusById(Integer id);
|
||||
|
||||
Boolean updateAuditStatusById(Integer id, Integer auditStatus);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.realtime.protection.server.defense.template;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import lombok.SneakyThrows;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class TemplateService {
|
||||
@@ -87,4 +90,66 @@ public class TemplateService {
|
||||
public Integer queryAuditTemplateTotalNum(Integer auditState) {
|
||||
return templateMapper.queryAuditTemplateTotalNum(auditState);
|
||||
}
|
||||
|
||||
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?");
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
}
|
||||
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("success", success);
|
||||
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?");
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
}
|
||||
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 =
|
||||
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(DynamicRuleMapper.class, updateDynamicRuleAuditStatusFunction, idsWithAuditStatusMap);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
public ResponseResult updateDynamicRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("staticRule_id", id)
|
||||
.setData("dynamicRule_id", id)
|
||||
.setData("success", false);
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
|
||||
@@ -58,4 +58,6 @@ public interface DynamicRuleMapper {
|
||||
Boolean updateAuditStatusById(Integer dynamicRuleId, Integer auditStatus);
|
||||
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
|
||||
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -211,6 +212,27 @@ public class DynamicRuleService {
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
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 (originalAuditStatus == null) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new IllegalArgumentException("动态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
|
||||
}
|
||||
|
||||
|
||||
Function<DynamicRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateDynamicRuleAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
if (map == null || map.isEmpty()) {
|
||||
|
||||
@@ -50,4 +50,6 @@ public interface StaticRuleMapper {
|
||||
Integer queryUsedStaticRuleTotalNum();
|
||||
|
||||
Integer queryAuditStaticRuleTotalNum(@Param("auditStatus")Integer auditStatus);
|
||||
|
||||
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
@@ -235,6 +235,25 @@ public class StaticRuleService {
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = staticRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
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 (originalAuditStatus == null) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new IllegalArgumentException("静态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
|
||||
}
|
||||
|
||||
Function<StaticRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateStaticRuleAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
|
||||
@@ -66,4 +66,6 @@ public interface TaskMapper {
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
|
||||
Integer queryAuditTaskTotalNum(Integer auditState);
|
||||
|
||||
List<Integer> queryAuditStatusByIds(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -324,6 +321,26 @@ public class TaskService {
|
||||
}
|
||||
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = taskMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
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 (originalAuditStatus == null) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
errorIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!errorIds.isEmpty()){
|
||||
return new IllegalArgumentException("动态规则id不存在或无法修改为对应审核状态, errorIds: " + errorIds);
|
||||
}
|
||||
|
||||
Function<TaskMapper, Function<Map<Integer, Integer>, Boolean>> updateTaskAuditStatusFunction =
|
||||
mapper -> map -> {
|
||||
if (map == null || map.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user