1、规则、任务在新建、批量导入、审核、批量审核时增加通过sessionid获取内存中的用户信息,并写入数据库表相应字段
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.realtime.protection.server.rule.dynamicrule;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import com.realtime.protection.configuration.entity.user.UserFull;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -25,8 +29,17 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
//
|
||||
@Override
|
||||
@PostMapping("/new")
|
||||
public ResponseResult newDynamicRuleObject(@RequestBody @Valid DynamicRuleObject dynamicRuleObject) {
|
||||
log.info("新增动态规则: {}", dynamicRuleObject);
|
||||
public ResponseResult newDynamicRuleObject(@RequestBody @Valid DynamicRuleObject dynamicRuleObject,
|
||||
@Autowired HttpServletRequest request) {
|
||||
// log.info("新增动态规则: {}", dynamicRuleObject);
|
||||
//从http首部session字段获取用户信息
|
||||
HttpSession session = request.getSession();
|
||||
UserFull user = (UserFull) session.getAttribute("user");
|
||||
if (user != null) {
|
||||
dynamicRuleObject.setAuditUserName(user.name);
|
||||
dynamicRuleObject.setAuditUserId(user.uid);
|
||||
dynamicRuleObject.setAuditUserDepart(user.getOrgName());
|
||||
}
|
||||
//调用service新增
|
||||
Integer dynamicRuleObjectId = dynamicRuleService.newDynamicRuleObject(dynamicRuleObject);
|
||||
return ResponseResult.ok().
|
||||
@@ -121,7 +134,7 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
.setData("success", true)
|
||||
.setData("dynamic_rule_list", dynamicRuleService.queryDynamicRuleObject(dynamicRuleName, dynamicRuleId,
|
||||
protectObjectSourceSystem, creator, auditStatus, eventType, protectLevel, templateName, page, pageSize))
|
||||
.setData("total_num",dynamicRuleService.queryDynamicRuleTotalNum(dynamicRuleName, dynamicRuleId,
|
||||
.setData("total_num", dynamicRuleService.queryDynamicRuleTotalNum(dynamicRuleName, dynamicRuleId,
|
||||
protectObjectSourceSystem, creator, auditStatus, eventType, protectLevel, templateName));
|
||||
}
|
||||
|
||||
@@ -133,14 +146,27 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
*/
|
||||
@Override
|
||||
@GetMapping("/{id}/audit/{auditStatus}")
|
||||
public ResponseResult updateDynamicRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||
public ResponseResult updateDynamicRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus,
|
||||
@Autowired HttpServletRequest request) {
|
||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("dynamicRule_id", id)
|
||||
.setData("success", false);
|
||||
}
|
||||
//从http首部session字段获取用户信息
|
||||
HttpSession session = request.getSession();
|
||||
UserFull user = (UserFull) session.getAttribute("user");
|
||||
String auditUserName = null;
|
||||
Integer auditUserId = null;
|
||||
String auditUserDepart = null;
|
||||
if (user != null) {
|
||||
auditUserName= user.name;
|
||||
auditUserId = Integer.valueOf(user.uid);
|
||||
auditUserDepart = user.getOrgName();
|
||||
}
|
||||
return ResponseResult.ok()
|
||||
.addDataMap(dynamicRuleService.updateAuditStatus(id, auditStatus))
|
||||
.addDataMap(dynamicRuleService.updateAuditStatus(id, auditStatus
|
||||
,auditUserName, auditUserId, auditUserDepart))
|
||||
.setData("dynamicRule_id", id);
|
||||
}
|
||||
|
||||
@@ -149,23 +175,36 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
*/
|
||||
@Override
|
||||
@PostMapping("/auditbatch")
|
||||
public ResponseResult updateDynamicRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
public ResponseResult updateDynamicRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
|
||||
@Autowired HttpServletRequest request) {
|
||||
List<Integer> errorIds = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||
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()){
|
||||
if (!errorIds.isEmpty()) {
|
||||
return new ResponseResult(400, "id or status is invalid")
|
||||
.setData("staticRule_id", errorIds)
|
||||
.setData("success", false);
|
||||
}
|
||||
//从http首部session字段获取用户信息
|
||||
HttpSession session = request.getSession();
|
||||
UserFull user = (UserFull) session.getAttribute("user");
|
||||
String auditUserName = null;
|
||||
String auditUserId = null;
|
||||
String auditUserDepart = null;
|
||||
if (user != null) {
|
||||
auditUserName= user.name;
|
||||
auditUserId = user.uid;
|
||||
auditUserDepart = user.getOrgName();
|
||||
}
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("success", dynamicRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||
.setData("success", dynamicRuleService.updateAuditStatusBatch(idsWithAuditStatusMap,
|
||||
auditUserName, auditUserId, auditUserDepart));
|
||||
}
|
||||
|
||||
|
||||
@@ -174,10 +213,10 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
*/
|
||||
@Override
|
||||
@GetMapping("/statistics")
|
||||
public ResponseResult getStaticRuleStatisticsData(){
|
||||
public ResponseResult getStaticRuleStatisticsData() {
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("dynamic_rule_num", dynamicRuleService.queryDynamicRuleTotalNum(null,null, null,
|
||||
.setData("dynamic_rule_num", dynamicRuleService.queryDynamicRuleTotalNum(null, null, null,
|
||||
null, null, null, null, null))
|
||||
.setData("dynamic_rule_used_num", dynamicRuleService.queryAuditDynamicRuleTotalNum(
|
||||
AuditStatusEnum.getNumByState(AuditStatusEnum.USING.getState())
|
||||
@@ -189,6 +228,7 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/auditInfo/{ids}")
|
||||
public ResponseResult updateAuditInfo(@PathVariable List<Integer> ids,
|
||||
|
||||
@@ -9,7 +9,9 @@ import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
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.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -38,7 +40,8 @@ public interface DynamicRuleControllerApi {
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "动态规则信息")
|
||||
)
|
||||
ResponseResult newDynamicRuleObject(@RequestBody @Valid DynamicRuleObject dynamicRuleObject) ;
|
||||
ResponseResult newDynamicRuleObject(@RequestBody @Valid DynamicRuleObject dynamicRuleObject,
|
||||
@Autowired HttpServletRequest request) ;
|
||||
|
||||
@Operation(
|
||||
summary = "删除动态规则",
|
||||
@@ -380,7 +383,8 @@ public interface DynamicRuleControllerApi {
|
||||
@Parameter(name = "auditStatus", description = "要修改为的审核状态")
|
||||
}
|
||||
)
|
||||
ResponseResult updateDynamicRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus);
|
||||
ResponseResult updateDynamicRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus,
|
||||
@Autowired HttpServletRequest request);
|
||||
|
||||
@Operation(
|
||||
summary = "批量更新审批状态",
|
||||
@@ -403,7 +407,8 @@ public interface DynamicRuleControllerApi {
|
||||
)
|
||||
)
|
||||
)
|
||||
ResponseResult updateDynamicRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
|
||||
ResponseResult updateDynamicRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
|
||||
@Autowired HttpServletRequest request);
|
||||
|
||||
@Operation(
|
||||
summary = "数据统计",
|
||||
|
||||
@@ -57,7 +57,8 @@ public interface DynamicRuleMapper {
|
||||
|
||||
Integer queryAuditStatusById(Integer dynamicRuleId);
|
||||
|
||||
Boolean updateAuditStatusById(Integer dynamicRuleId, Integer auditStatus);
|
||||
Boolean updateAuditStatusById(Integer dynamicRuleId, Integer auditStatus,
|
||||
String auditUserName, Integer auditUserId, String auditUserDepart);
|
||||
|
||||
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch);
|
||||
|
||||
@@ -66,4 +67,9 @@ public interface DynamicRuleMapper {
|
||||
Boolean updateAuditInfo(@Param("ids")List<Integer> ids, @Param("auditInfo")String auditInfo);
|
||||
|
||||
String queryAuditInfo(Integer id);
|
||||
|
||||
void updateAuditStatusWithAuditorByIdBatch(@Param("idWithAuditStatusBatch")Map<Integer, Integer> idWithAuditStatusBatch,
|
||||
@Param("auditUserName")String auditUserName,
|
||||
@Param("auditUserId")String auditUserId,
|
||||
@Param("auditUserDepart")String auditUserDepart);
|
||||
}
|
||||
|
||||
@@ -213,7 +213,8 @@ public class DynamicRuleService {
|
||||
return dynamicRuleMapper.queryAuditDynamicRuleTotalNum(auditStatus);
|
||||
}
|
||||
|
||||
public Map<String, Object> updateAuditStatus(Integer id, Integer auditStatus) {
|
||||
public Map<String, Object> updateAuditStatus(Integer id, Integer auditStatus,
|
||||
String auditUserName, Integer auditUserId, String auditUserDepart) {
|
||||
Integer originalAuditStatus = dynamicRuleMapper.queryAuditStatusById(id);
|
||||
if (originalAuditStatus == null) {
|
||||
throw new IllegalArgumentException("cannot find audit status of static rule " + id + ", maybe static rule doesn't exist?");
|
||||
@@ -221,7 +222,7 @@ public class DynamicRuleService {
|
||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||
throw new IllegalArgumentException("invalid audit status");
|
||||
}
|
||||
Boolean success = dynamicRuleMapper.updateAuditStatusById(id, auditStatus);
|
||||
Boolean success = dynamicRuleMapper.updateAuditStatusById(id, auditStatus ,auditUserName, auditUserId, auditUserDepart);
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("success", success);
|
||||
@@ -229,6 +230,11 @@ public class DynamicRuleService {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于任务状态修改时,内部批量更新任务所属动态规则的状态,不需要修改审批人信息
|
||||
* @param idsWithAuditStatusMap
|
||||
* @return
|
||||
*/
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
//校验id和status是否合法
|
||||
List<Integer> originalAuditStatusList = dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
@@ -279,6 +285,64 @@ public class DynamicRuleService {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于外部调用,更新审批用户信息
|
||||
* @param idsWithAuditStatusMap
|
||||
* @param auditUserName
|
||||
* @param auditUserId
|
||||
* @param auditUserDepart
|
||||
* @return
|
||||
*/
|
||||
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap,
|
||||
String auditUserName, String auditUserId, String auditUserDepart) {
|
||||
//校验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<>();
|
||||
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()){
|
||||
return new IllegalArgumentException("动态规则id无法修改为对应审核状态, 错误id: " + errorIds);
|
||||
}
|
||||
|
||||
|
||||
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.updateAuditStatusWithAuditorByIdBatch(idWithAuditStatusBatch, auditUserName, auditUserId, auditUserDepart);
|
||||
idWithAuditStatusBatch.clear();
|
||||
}
|
||||
if (!idWithAuditStatusBatch.isEmpty()) {
|
||||
mapper.updateAuditStatusWithAuditorByIdBatch(idWithAuditStatusBatch, auditUserName, auditUserId, auditUserDepart);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
//实现事务操作
|
||||
return sqlSessionWrapper.startBatchSession(DynamicRuleMapper.class, updateDynamicRuleAuditStatusFunction, idsWithAuditStatusMap);
|
||||
|
||||
}
|
||||
public List<Integer> queryAuditStatusByIds(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||
return dynamicRuleMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user