1、指令新增白名单判断,命中白名单后加入到t_whitelist_hit表中,不加到t_command

2、指令新增时,记录到t_command_log表中
3、配置增加创建人、审核人
4、任务停止、结束时,规则的used_task_id也变为空
5、规则update后更新审核状态bug修复
This commit is contained in:
PushM
2024-06-06 03:28:50 +08:00
parent 62772955d2
commit 366e89ae47
28 changed files with 1033 additions and 107 deletions

View File

@@ -164,6 +164,7 @@ public class StaticRuleObject {
private String auditUserDepart;
@JsonProperty("event_type")
@ExcelProperty("事件类型")
@Schema(description = "事件类型", example = "DDos")
private String eventType;

View File

@@ -1,6 +1,9 @@
package com.realtime.protection.server.command;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -38,4 +41,20 @@ public interface CommandMapper {
@Param("src_port") String sourcePort,
@Param("dst_ip") String destinationIP,
@Param("dst_port") String destinationPort);
void createCommandInWhiteListHit(@Param("info") TaskCommandInfo commandInfo);
void updateCommandHistoryExpireTime(@Param("command_id") String commandUUID);
void insertCommandHistory(@Param("command_id") String commandUUID);
void updateCommandHistoryExpireTimeBatch(@Param("commandIds")List<String> commandIds);
void insertCommandHistoryBatch(@Param("commandIds")List<String> commandIds);
@DS("mysql")
List<WhiteListObject> whiteListCommandCheck(@Param("command") FiveTupleWithMask fiveTupleWithMask);
@DS("mysql")
void createCommandWhiteListConnect(@Param("command_id") String uuid, @Param("whiteLists") List<WhiteListObject> whiteListsHit);
}

View File

@@ -4,8 +4,10 @@ import com.alibaba.excel.util.ListUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.server.whitelist.WhiteListMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -23,12 +25,14 @@ public class CommandService {
private final CommandMapper commandMapper;
private final SqlSessionWrapper sqlSessionWrapper;
private final Counter counter;
private final WhiteListMapper whiteListMapper;
private static final int BatchSize = 100;
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter) {
public CommandService(CommandMapper commandMapper, SqlSessionWrapper sqlSessionWrapper, Counter counter, WhiteListMapper whiteListMapper) {
this.commandMapper = commandMapper;
this.sqlSessionWrapper = sqlSessionWrapper;
this.counter = counter;
this.whiteListMapper = whiteListMapper;
}
@DSTransactional
@@ -44,8 +48,21 @@ public class CommandService {
+ String.format("%06d", counter.generateId("command"))
);
//指令:白名单检查
List<WhiteListObject> whiteListsHit = commandMapper.whiteListCommandCheck(commandInfo.getFiveTupleWithMask());
if (!whiteListsHit.isEmpty()) {
commandInfo.setUUID(UUID.randomUUID().toString());
commandMapper.createCommandInWhiteListHit(commandInfo);
commandMapper.createCommandWhiteListConnect(commandInfo.getUUID(), whiteListsHit);
//写入历史表
insertCommandHistory(commandInfo.getUUID());
return commandInfo.getUUID();
}
commandInfo.setUUID(UUID.randomUUID().toString());
commandMapper.createCommand(commandInfo);
//写入历史表
insertCommandHistory(commandInfo.getUUID());
return commandInfo.getUUID();
}
@@ -58,13 +75,15 @@ public class CommandService {
if (taskCommandInfoBatch.size() < BatchSize) {
continue;
}
//因为createCommands只用于静态规则生成command静态规则已经检查了白名单所以不检查了
commandMapper.createCommands(taskCommandInfoBatch);
insertCommandHistoryBatch(taskCommandInfoBatch);
taskCommandInfoBatch.clear();
}
if (!taskCommandInfoBatch.isEmpty()) {
commandMapper.createCommands(taskCommandInfoBatch);
insertCommandHistoryBatch(taskCommandInfoBatch);
taskCommandInfoBatch.clear();
}
@@ -108,4 +127,17 @@ public class CommandService {
String destinationIP, String destinationPort){
return commandMapper.queryCommandTotalNum(taskId, sourceIP, sourcePort, destinationIP, destinationPort);
}
public void insertCommandHistory(String commandUUID) {
commandMapper.updateCommandHistoryExpireTime(commandUUID);
commandMapper.insertCommandHistory(commandUUID);
}
public void insertCommandHistoryBatch(List<TaskCommandInfo> commandIdList) {
List<String> commandIds = ListUtils.newArrayListWithExpectedSize(commandIdList.size());
commandIdList.forEach(item -> commandIds.add(item.getUUID()));
commandMapper.updateCommandHistoryExpireTimeBatch(commandIds);
commandMapper.insertCommandHistoryBatch(commandIds);
}
}

View File

@@ -5,6 +5,7 @@ import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import com.realtime.protection.configuration.entity.user.UserFull;
import java.util.List;
@@ -13,13 +14,20 @@ public class ProjectObjectDataListener implements ReadListener<ProtectObject> {
private final ProtectObjectService protectObjectService;
private final List<ProtectObject> cachedDataList = ListUtils.newArrayListWithExpectedSize(batchCount);
private static final int batchCount = 100;
private UserFull user;
public ProjectObjectDataListener(ProtectObjectService protectObjectService) {
public ProjectObjectDataListener(ProtectObjectService protectObjectService, UserFull user) {
this.protectObjectService = protectObjectService;
this.user = user;
}
@Override
public void invoke(ProtectObject protectObject, AnalysisContext analysisContext) {
if (user != null) {
protectObject.setProtectObjectCreateUsername(user.name);
protectObject.setProtectObjectCreateUserId(Integer.valueOf(user.uid));
protectObject.setProtectObjectCreateDepart(user.getOrgName());
}
cachedDataList.add(protectObject);
if (cachedDataList.size() > 1000) {
saveData();

View File

@@ -2,12 +2,16 @@ package com.realtime.protection.server.defense.object;
import com.alibaba.excel.EasyExcel;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
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.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -30,7 +34,16 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
@Override
@PostMapping("/new")
public ResponseResult newProtectObject(@RequestBody @Valid ProtectObject protectObject) {
public ResponseResult newProtectObject(@RequestBody @Valid ProtectObject protectObject,
@Autowired HttpServletRequest request) {
//从http首部session字段获取用户信息
HttpSession session = request.getSession();
UserFull user = (UserFull) session.getAttribute("user");
if (user != null) {
protectObject.setProtectObjectCreateUsername(user.name);
protectObject.setProtectObjectCreateUserId(Integer.valueOf(user.uid));
protectObject.setProtectObjectCreateDepart(user.getOrgName());
}
Integer protectObjectId = protectObjectService.newProtectObject(protectObject);
if (protectObjectId == 0) {
return ResponseResult.error().setMessage("failed to create a protect object")
@@ -48,10 +61,13 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
@Override
@PostMapping("/upload")
public ResponseResult uploadFile(
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile,
@Autowired HttpServletRequest request
) throws IOException {
HttpSession session = request.getSession();
UserFull user = (UserFull) session.getAttribute("user");
EasyExcel.read(uploadFile.getInputStream(), ProtectObject.class,
new ProjectObjectDataListener(protectObjectService)).sheet().doRead();
new ProjectObjectDataListener(protectObjectService, user)).sheet().doRead();
return ResponseResult.ok();
}
@@ -158,9 +174,22 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
@Override
@GetMapping("/{protectObjectId}/audit/{auditStatus}")
public ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
@PathVariable Integer auditStatus) {
@PathVariable Integer auditStatus,
@Autowired HttpServletRequest request) {
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(protectObjectService.changeProtectObjectAuditStatus(protectObjectId, auditStatus))
.addDataMap(protectObjectService.changeProtectObjectAuditStatus(
protectObjectId, auditStatus, auditUserName, auditUserId, auditUserDepart))
.setData("proobj_id", protectObjectId);
}
@@ -191,7 +220,9 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
*/
@Override
@PostMapping("/auditbatch")
public ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
public ResponseResult updateWhiteListAuditStatusBatch(
@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
@Autowired HttpServletRequest request) {
List<Integer> errorIds = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
@@ -205,9 +236,20 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
.setData("id", errorIds)
.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()
.setData("success", protectObjectService.updateAuditStatusBatch(idsWithAuditStatusMap));
.setData("success", protectObjectService.updateAuditStatusBatch(
idsWithAuditStatusMap, auditUserName, auditUserId, auditUserDepart));
}
@Override

View File

@@ -9,10 +9,12 @@ 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.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -58,7 +60,8 @@ public interface ProtectObjectControllerApi {
},
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "防护对象信息")
)
ResponseResult newProtectObject(@RequestBody @Valid ProtectObject protectObject);
ResponseResult newProtectObject(@RequestBody @Valid ProtectObject protectObject,
@Autowired HttpServletRequest request);
@PostMapping("/upload")
@Operation(
@@ -76,7 +79,8 @@ public interface ProtectObjectControllerApi {
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "上传文件")
)
ResponseResult uploadFile(
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile,
@Autowired HttpServletRequest request
) throws IOException;
@GetMapping("/download")
@@ -427,7 +431,8 @@ public interface ProtectObjectControllerApi {
}
)
ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId,
@PathVariable Integer auditStatus);
@PathVariable Integer auditStatus,
@Autowired HttpServletRequest request);
/*
防护对象数据统计
@@ -488,7 +493,9 @@ public interface ProtectObjectControllerApi {
)
)
@PostMapping("/auditbatch")
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
ResponseResult updateWhiteListAuditStatusBatch(
@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
@Autowired HttpServletRequest request);
@Operation(
summary = "更新审批意见",

View File

@@ -24,8 +24,7 @@ public interface ProtectObjectMapper {
void deleteProtectObjects(@Param("proobj_ids") List<Integer> protectObjectIds);
Boolean changeProtectObjectAuditStatus(@Param("proobj_id") Integer protectObjectId,
@Param("proobj_audit_status") Integer protectObjectAuditStatus);
Integer queryProtectObjectsTotalNum(@Param("proobj_name") String protectObjectName,
@@ -73,4 +72,19 @@ public interface ProtectObjectMapper {
List<ProtectObject> queryHistory(Integer id, Integer page, Integer pageSize);
List<ProtectObject> queryProtectObjectByIds(List<Integer> protectObjectIds);
Boolean changeProtectObjectAuditStatus(@Param("proobj_id") Integer protectObjectId,
@Param("proobj_audit_status") Integer auditStatus
);
Boolean changeProtectObjectAuditStatusWithUser(@Param("proobj_id") Integer protectObjectId,
@Param("proobj_audit_status") Integer protectObjectAuditStatus,
@Param("auditUserName")String auditUserName,
@Param("auditUserId")Integer auditUserId,
@Param("auditUserDepart")String auditUserDepart);
void updateAuditStatusByIdBatchWithUser(@Param("idWithAuditStatusBatch")Map<Integer, Integer> idWithAuditStatusBatch,
@Param("auditUserName") String auditUserName,
@Param("auditUserId")Integer auditUserId,
@Param("auditUserDepart")String auditUserDepart);
}

View File

@@ -135,12 +135,35 @@ public class ProtectObjectService {
}
@Transactional
public Map<String, Object> changeProtectObjectAuditStatus(Integer protectObjectId, Integer auditStatus) {
public Map<String, Object> changeProtectObjectAuditStatus(
Integer protectObjectId, Integer auditStatus,String auditUserName,
Integer auditUserId,
String auditUserDepart) {
Integer originalAuditStatus = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
throw new IllegalArgumentException("无效的审核状态");
}
Boolean success = protectObjectMapper.changeProtectObjectAuditStatus(protectObjectId, auditStatus);
Boolean success = protectObjectMapper.changeProtectObjectAuditStatusWithUser(
protectObjectId, auditStatus, auditUserName, auditUserId, auditUserDepart);
insertStaticRuleStatusLog(protectObjectId);
Integer auditStatusNow = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
resultMap.put("audit_status", auditStatusNow);
return resultMap;
}
@Transactional
public Map<String, Object> changeProtectObjectAuditStatus(
Integer protectObjectId, Integer auditStatus) {
Integer originalAuditStatus = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
throw new IllegalArgumentException("无效的审核状态");
}
Boolean success = protectObjectMapper.changeProtectObjectAuditStatus(
protectObjectId, auditStatus);
insertStaticRuleStatusLog(protectObjectId);
Integer auditStatusNow = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
@@ -214,6 +237,59 @@ public class ProtectObjectService {
//实现事务操作
return sqlSessionWrapper.startBatchSession(ProtectObjectMapper.class, updateProtectObjectAuditStatusFunction, idsWithAuditStatusMap);
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap,
String auditUserName,
Integer auditUserId,
String auditUserDepart) {
//校验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.updateAuditStatusByIdBatchWithUser(idWithAuditStatusBatch,
auditUserName, auditUserId, auditUserDepart);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatchWithUser(idWithAuditStatusBatch,
auditUserName, auditUserId, auditUserDepart);
insertStaticRuleStatusLog(idWithAuditStatusBatch);
}
return true;
};
//实现事务操作
return sqlSessionWrapper.startBatchSession(ProtectObjectMapper.class, updateProtectObjectAuditStatusFunction, idsWithAuditStatusMap);
}
public Boolean updateAuditInfo(List<Integer> ids, String auditInfo) {

View File

@@ -1,10 +1,14 @@
package com.realtime.protection.server.defense.templatenew;
import com.realtime.protection.configuration.entity.defense.template.TemplateNew;
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 jakarta.validation.constraints.Min;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
@@ -23,15 +27,16 @@ public class TemplateController implements TemplateNewCpntrollerApi{
@Override
@PostMapping("/new")
public ResponseResult newTemplate(@RequestBody @Valid TemplateNew template) {
public ResponseResult newTemplate(@RequestBody @Valid TemplateNew template,
@Autowired HttpServletRequest request) {
//从http首部session字段获取用户信息
// HttpSession session = request.getSession();
// UserFull user = (UserFull) session.getAttribute("user");
// if (user != null) {
// object.setStaticRuleCreateUsername(user.name);
// object.setStaticRuleCreateUserId(Integer.valueOf(user.uid));
// object.setStaticRuleCreateDepart(user.getOrgName());
// }
HttpSession session = request.getSession();
UserFull user = (UserFull) session.getAttribute("user");
if (user != null) {
template.setCreateUsername(user.name);
template.setCreateUserId(Integer.valueOf(user.uid));
template.setCreateDepart(user.getOrgName());
}
Integer templateId = templateService.newTemplate(template);
if (templateId > 0) {
@@ -161,14 +166,28 @@ public class TemplateController implements TemplateNewCpntrollerApi{
*/
@Override
@GetMapping("/{id}/audit/{auditStatus}")
public ResponseResult updateTemplateAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
public ResponseResult updateTemplateAuditStatus(@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("template_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(templateService.updateAuditStatus(id, auditStatus))
.addDataMap(templateService.updateAuditStatus(id, auditStatus,
auditUserName, auditUserId, auditUserDepart))
.setData("template_id", id);
}
@@ -178,7 +197,8 @@ public class TemplateController implements TemplateNewCpntrollerApi{
*/
@Override
@PostMapping("/auditbatch")
public ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
public ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
@Autowired HttpServletRequest request) {
List<Integer> errorIds = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
@@ -192,9 +212,20 @@ public class TemplateController implements TemplateNewCpntrollerApi{
.setData("id", errorIds)
.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()
.setData("success", templateService.updateAuditStatusBatch(idsWithAuditStatusMap));
.setData("success", templateService.updateAuditStatusBatch(idsWithAuditStatusMap,
auditUserName, auditUserId, auditUserDepart));
}
/*

View File

@@ -52,7 +52,10 @@ public interface TemplateMapper {
Integer queryAuditStatusById(Integer id);
Boolean updateAuditStatusById(Integer id, Integer auditStatus);
Boolean updateAuditStatusById(Integer id, Integer auditStatus,
String auditUserName,
Integer auditUserId,
String auditUserDepart);
List<Integer> queryAuditStatusByIds(@Param("idsWithAuditStatusMap") Map<Integer, Integer> idsWithAuditStatusMap);
@@ -71,4 +74,9 @@ public interface TemplateMapper {
void insertStatusLogBatch(List<Integer> ids);
List<TemplateNew> queryHistory(Integer id, Integer page, Integer pageSize);
void updateAuditStatusByIdBatchWithUser(@Param("idWithAuditStatusBatch")Map<Integer, Integer> idWithAuditStatusBatch,
@Param("auditUserName")String auditUserName,
@Param("auditUserId")Integer auditUserId,
@Param("auditUserDepart")String auditUserDepart);
}

View File

@@ -11,8 +11,10 @@ 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 jakarta.validation.constraints.Min;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -59,7 +61,8 @@ public interface TemplateNewCpntrollerApi {
description = "防御策略模板信息")
)
ResponseResult newTemplate(@RequestBody @Valid TemplateNew template);
ResponseResult newTemplate(@RequestBody @Valid TemplateNew template,
@Autowired HttpServletRequest request);
@GetMapping("/query")
@Operation(
@@ -274,7 +277,8 @@ public interface TemplateNewCpntrollerApi {
}
)
@GetMapping("/{id}/audit/{auditStatus}")
ResponseResult updateTemplateAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus);
ResponseResult updateTemplateAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus,
@Autowired HttpServletRequest request);
@Operation(
summary = "批量更新审批状态",
description = "批量更新审批状态0未审核、1审核不通过、2审核通过",
@@ -297,7 +301,8 @@ public interface TemplateNewCpntrollerApi {
)
)
@PostMapping("/auditbatch")
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap,
@Autowired HttpServletRequest request);
/*
修改审批信息

View File

@@ -5,6 +5,7 @@ import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleOb
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@@ -93,7 +94,10 @@ public class TemplateService {
return templateMapper.queryAuditTemplateTotalNum(auditState);
}
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 = templateMapper.queryAuditStatusById(id);
if (originalAuditStatus == null) {
throw new IllegalArgumentException("cannot find audit status of static rule " + id + ", maybe static rule doesn't exist?");
@@ -101,7 +105,8 @@ public class TemplateService {
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
throw new IllegalArgumentException("invalid audit status");
}
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus);
Boolean success = templateMapper.updateAuditStatusById(id, auditStatus,
auditUserName, auditUserId, auditUserDepart);
insertStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
@@ -158,6 +163,57 @@ public class TemplateService {
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap,
String auditUserName,
Integer auditUserId,
String auditUserDepart) {
//校验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)) {
errorIds.add(id);
}
}
if (!errorIds.isEmpty()){
throw new IllegalArgumentException("策略模板无法修改为对应审核状态, 错误id: " + errorIds);
}
Function<TemplateMapper, Function<Map<Integer, Integer>, Boolean>> updateTemplateAuditStatusFunction =
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.updateAuditStatusByIdBatchWithUser(idWithAuditStatusBatch, auditUserName, auditUserId, auditUserDepart);
insertStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatchWithUser(idWithAuditStatusBatch, auditUserName, auditUserId, auditUserDepart);
insertStatusLog(idWithAuditStatusBatch);
}
return true;
};
//实现事务操作
return sqlSessionWrapper.startBatchSession(TemplateMapper.class, updateTemplateAuditStatusFunction, idsWithAuditStatusMap);
}
public Boolean updateAuditInfo(List<Integer> ids, String auditInfo) {
return templateMapper.updateAuditInfo(ids, auditInfo);

View File

@@ -40,7 +40,7 @@ public interface StaticRuleMapper {
Integer queryAuditStatusById(Integer id);
Boolean updateAuditStatusById(Integer id, Integer auditStatus,
Boolean updateAuditStatusByIdWithUser(Integer id, Integer auditStatus,
String auditUserName,
Integer auditUserId,
String auditUserDepart);
@@ -80,4 +80,6 @@ public interface StaticRuleMapper {
List<StaticRuleObject> queryHistory(Integer id, Integer page, Integer pageSize);
void removeUsedTaskId(Long taskId);
// boolean queryStaticRuleRepeat(StaticRuleObject object);
}

View File

@@ -63,13 +63,12 @@ public class StaticRuleService {
新建静态规则
*/
@SneakyThrows
@Transactional
public Integer newStaticRuleObject(StaticRuleObject object) {
object.setStaticRuleCreateTime(LocalDateTime.now());
object.setAuditStatus(0);
/*
待开发:设置静态规则对象的创建用户、用户所属部门等属性
*/
if (!isIpMaskValid(object.getStaticRuleSip(),object.getStaticRuleMsip()) ||
!isIpMaskValid(object.getStaticRuleDip(),object.getStaticRuleMdip())
){
@@ -78,6 +77,10 @@ public class StaticRuleService {
if (!RuleEnum.checkValidate(object)) {
throw new IllegalArgumentException("静态规则不符合指定的配置方法,请参考规则模板以配置静态规则");
}
// if(!staticRuleMapper.queryStaticRuleRepeat(object)){
// throw new IllegalArgumentException("静态规则重复");
// }
/*
新建静态规则,过一下白名单审核
*/
@@ -103,7 +106,7 @@ public class StaticRuleService {
return object.getStaticRuleId();
}
@Transactional
public Object deleteStaticRules(List<Integer> staticRuleIds) {
//判断当前静态规则是否能够删除---是否存在任务选择的静态规则??
@@ -144,8 +147,8 @@ public class StaticRuleService {
throw new IllegalArgumentException("未知的静态规则ID");
}
if (!staticRuleObject.getAuditStatus().equals(AuditStatusEnum.AUDITED.getNum())) {
throw new IllegalStateException("无法修改该静态规则,因为其审核状态处于" + AuditStatusEnum.AUDITED);
if (staticRuleObject.getAuditStatus().equals(AuditStatusEnum.USING.getNum())) {
throw new IllegalStateException("无法修改该静态规则,因为其状态处于" + AuditStatusEnum.USING);
}
if (!RuleEnum.checkValidate(object)) {
@@ -241,7 +244,7 @@ public class StaticRuleService {
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
throw new IllegalArgumentException("invalid audit status");
}
Boolean success = staticRuleMapper.updateAuditStatusById(id, auditStatus, auditUserName, auditUserId, auditUserDepart);
Boolean success = staticRuleMapper.updateAuditStatusByIdWithUser(id, auditStatus, auditUserName, auditUserId, auditUserDepart);
//记录状态历史
insertStaticRuleStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();

View File

@@ -63,7 +63,12 @@ public class StateHandler {
protected Boolean handleStop(CommandService commandService, TaskService taskService, Long taskId) {
commandService.removeCommandsByTaskId(taskId);
taskService.updateDynamicRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
// 要删去规则的used_task_id,因为在新建时检查了是否有重复使用的规则
taskService.removeDynamicRuleUsedTaskIdInTask(taskId);
taskService.updateStaticRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
taskService.removeStaticRuleUsedTaskIdInTask(taskId);
return true;
}
@@ -84,7 +89,10 @@ public class StateHandler {
protected Boolean handleFailed(CommandService commandService, TaskService taskService, Long taskId) {
commandService.removeCommandsByTaskId(taskId);
taskService.updateDynamicRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
// 要删去规则的used_task_id,因为在新建时检查了是否有重复使用的规则
taskService.removeDynamicRuleUsedTaskIdInTask(taskId);
taskService.updateStaticRuleAuditStatusInTask(taskId, AuditStatusEnum.AUDITED);
taskService.removeStaticRuleUsedTaskIdInTask(taskId);
return true;
}
@@ -95,7 +103,11 @@ public class StateHandler {
}
private Boolean handleDynamicTaskStart(TaskService taskService, Task task) {
// 将所有关联的动态规则审批状态修改为“已使用”
taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.USING);
return sendFilters(taskService, task);
// return true;
}
private Boolean handleStaticTaskStart(CommandService commandService, TaskService taskService, Task task) {
@@ -124,8 +136,8 @@ public class StateHandler {
dynamicTaskInfo.parseSql();
});
// 将所有关联的动态规则审批状态修改为“已使用”
taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.USING);
// // 将所有关联的动态规则审批状态修改为“已使用”
// taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.USING);
AtomicReference<Boolean> success = new AtomicReference<>(false);

View File

@@ -1,11 +1,15 @@
package com.realtime.protection.server.whitelist;
import com.alibaba.excel.EasyExcel;
import com.realtime.protection.configuration.entity.user.UserFull;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
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.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -28,7 +32,17 @@ public class WhiteListController implements WhiteListControllerApi {
@Override
@PostMapping("/new")
public ResponseResult newWhitelistObject(@RequestBody @Valid WhiteListObject object) {
public ResponseResult newWhitelistObject(@RequestBody @Valid WhiteListObject object,
@Autowired HttpServletRequest request) {
HttpSession session = request.getSession();
UserFull user = (UserFull) session.getAttribute("user");
if (user != null) {
object.setCreateUserName(user.name);
object.setAuditUserId(user.uid);
object.setCreateUserDepartment(user.getOrgName());
}
Integer whiteListObjectId = whiteListService.newWhiteListObject(object);
return ResponseResult.ok()
@@ -41,9 +55,12 @@ public class WhiteListController implements WhiteListControllerApi {
//post
@Override
@PostMapping("/upload")
public ResponseResult uploadFile(MultipartFile uploadFile) throws IOException {
public ResponseResult uploadFile(MultipartFile uploadFile,
@Autowired HttpServletRequest request) throws IOException {
HttpSession session = request.getSession();
UserFull user = (UserFull) session.getAttribute("user");
EasyExcel.read(uploadFile.getInputStream(), WhiteListObject.class,
new WhiteListDataListener(whiteListService)).sheet().doRead();
new WhiteListDataListener(whiteListService, user)).sheet().doRead();
return ResponseResult.ok();
}
@@ -164,14 +181,27 @@ public class WhiteListController implements WhiteListControllerApi {
//修改审核状态
@GetMapping("/{id}/audit/{auditStatus}")
public ResponseResult updateWhiteListObjectAuditStatus(@PathVariable Integer id,
@PathVariable Integer auditStatus) {
@PathVariable Integer auditStatus,
@Autowired HttpServletRequest request) {
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
return new ResponseResult(400, "id or status is invalid")
.setData("whiteobj_id", id)
.setData("success", false);
}
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(whiteListService.updateWhiteListObjectAuditStatus(id, auditStatus))
.addDataMap(whiteListService.updateWhiteListObjectAuditStatus(id, auditStatus,
auditUserName, auditUserId, auditUserDepart))
.setData("whiteobj_id", id);
}
@@ -223,7 +253,8 @@ public class WhiteListController implements WhiteListControllerApi {
*/
@Override
@PostMapping("/auditbatch")
public ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
public ResponseResult updateWhiteListAuditStatusBatch(@Autowired HttpServletRequest request,
@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
List<Integer> errorIds = new ArrayList<>();
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
Integer id = entry.getKey();
@@ -237,9 +268,21 @@ public class WhiteListController implements WhiteListControllerApi {
.setData("id", errorIds)
.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()
.setData("success", whiteListService.updateAuditStatusBatch(idsWithAuditStatusMap));
.setData("success", whiteListService.updateAuditStatusBatch(idsWithAuditStatusMap,
auditUserName, auditUserId, auditUserDepart));
}
@Override

View File

@@ -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.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -47,7 +49,8 @@ public interface WhiteListControllerApi {
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "白名单信息")
)
ResponseResult newWhitelistObject(@RequestBody WhiteListObject object);
ResponseResult newWhitelistObject(@RequestBody WhiteListObject object,
@Autowired HttpServletRequest request);
@Operation(
summary = "批量导入白名单",
@@ -64,7 +67,8 @@ public interface WhiteListControllerApi {
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "Excel文件")
)
ResponseResult uploadFile(MultipartFile uploadFile) throws IOException;
ResponseResult uploadFile(MultipartFile uploadFile,
@Autowired HttpServletRequest request) throws IOException;
@Operation(
summary = "下载白名单模板",
@@ -211,7 +215,8 @@ public interface WhiteListControllerApi {
}
)
ResponseResult updateWhiteListObjectAuditStatus(@PathVariable Integer id,
@PathVariable Integer auditStatus);
@PathVariable Integer auditStatus,
@Autowired HttpServletRequest request);
/*
@@ -318,7 +323,8 @@ public interface WhiteListControllerApi {
)
)
@PostMapping("/auditbatch")
ResponseResult updateWhiteListAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
ResponseResult updateWhiteListAuditStatusBatch(@Autowired HttpServletRequest request,
@RequestBody Map<Integer, Integer> idsWithAuditStatusMap);
@Operation(
summary = "更新审批意见",
description = "批量更新审批意见接收多个id",

View File

@@ -3,6 +3,7 @@ package com.realtime.protection.server.whitelist;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.user.UserFull;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import lombok.extern.slf4j.Slf4j;
@@ -15,14 +16,22 @@ public class WhiteListDataListener implements ReadListener<WhiteListObject> {
private final List<WhiteListObject> cachedDataList = ListUtils.newArrayListWithExpectedSize(batchCount);
private final WhiteListService whiteListService;
private UserFull user;
public WhiteListDataListener(WhiteListService whiteListService) {
public WhiteListDataListener(WhiteListService whiteListService, UserFull user) {
this.whiteListService = whiteListService;
this.user = user;
}
@Override
public void invoke(WhiteListObject object, AnalysisContext analysisContext) {
log.info("解析到一条数据:{}", object.toString());
if (user != null) {
object.setCreateUserName(user.name);
object.setCreateUserId(user.uid);
object.setCreateUserDepartment(user.getOrgName());
}
cachedDataList.add(object);
if (cachedDataList.size() > batchCount) {
saveData();

View File

@@ -36,6 +36,8 @@ public interface WhiteListMapper {
Integer queryWhiteListObjectAuditStuatusById(Integer id);
Boolean updateWhiteListObjectAuditStatusWithUser(Integer id, Integer status, String auditUserName, Integer auditUserId, String auditUserDepart);
Boolean updateWhiteListObjectAuditStatus(Integer id, Integer status);
void newWhiteListObjects(@Param("whiteListObjects") List<WhiteListObject> whiteListBatch);
@@ -45,7 +47,7 @@ public interface WhiteListMapper {
List<WhiteListObject> whiteListCommandCheck(@Param("command") FiveTupleWithMask fiveTupleWithMaskInCommand);
Integer queryWhiteListTotalNum(String whiteListName, Integer whiteListId
, String systemName, Integer auditStatus, String creator);
, String systemName, Integer auditStatus, String creator);
List<WhiteListObject> whiteListCommandsCheck(List<TaskCommandInfo> taskCommandInfos);
@@ -57,7 +59,7 @@ public interface WhiteListMapper {
List<Integer> queryAuditStatusByIds(@Param("idsWithAuditStatusMap") Map<Integer, Integer> idsWithAuditStatusMap);
Boolean updateAuditInfo(@Param("ids")List<Integer> ids, @Param("auditInfo")String auditInfo);
Boolean updateAuditInfo(@Param("ids") List<Integer> ids, @Param("auditInfo") String auditInfo);
String queryWhiteListObjectAuditInfo(Integer id);
@@ -70,4 +72,12 @@ public interface WhiteListMapper {
void insertStatusLogBatch(List<Integer> ids);
List<WhiteListObject> queryHistory(Integer id, Integer page, Integer pageSize);
}
void createCommandWhiteListConnect(@Param("command_id") String commandId, @Param("whiteLists") List<WhiteListObject> whiteListsHit);
void updateAuditStatusByIdBatchWithUser(@Param("idWithAuditStatusBatch") Map<Integer, Integer> idWithAuditStatusBatch,
@Param("auditUserName") String auditUserName,
@Param("auditUserId") Integer auditUserId,
@Param("auditUserDepart") String auditUserDepart);
}

View File

@@ -186,7 +186,10 @@ public class WhiteListService {
}
@Transactional
public Map<String, Object> updateWhiteListObjectAuditStatus(Integer id, Integer auditStatus) {
public Map<String, Object> updateWhiteListObjectAuditStatus(Integer id, Integer auditStatus,
String auditUserName,
Integer auditUserId,
String auditUserDepart) {
//查询目前curStatus
Integer originalAuditStatus = whiteListMapper.queryWhiteListObjectAuditStuatusById(id);
if (originalAuditStatus == null){
@@ -197,7 +200,8 @@ public class WhiteListService {
throw new IllegalArgumentException("审核状态修改违规");
}
Boolean success = whiteListMapper.updateWhiteListObjectAuditStatus(id, auditStatus);
Boolean success = whiteListMapper.updateWhiteListObjectAuditStatusWithUser(id, auditStatus,
auditUserName, auditUserId, auditUserDepart);
insertStatusLog(id);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", success);
@@ -216,7 +220,61 @@ public class WhiteListService {
return whiteListMapper.queryAuditWhiteListTotalNum(auditStatus);
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap,
String auditUserName, Integer auditUserId, String auditUserDepart ) {
//校验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.updateAuditStatusByIdBatchWithUser(idWithAuditStatusBatch,
auditUserName, auditUserId, auditUserDepart);
insertStatusLog(idWithAuditStatusBatch);
idWithAuditStatusBatch.clear();
}
if (!idWithAuditStatusBatch.isEmpty()) {
mapper.updateAuditStatusByIdBatchWithUser(idWithAuditStatusBatch,
auditUserName, auditUserId, auditUserDepart);
insertStatusLog(idWithAuditStatusBatch);
}
return true;
};
//实现事务操作
return sqlSessionWrapper.startBatchSession(WhiteListMapper.class, updateWhiteListAuditStatusFunction, idsWithAuditStatusMap);
}
public Boolean updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap ) {
//校验id和status是否合法
List<Integer> originalAuditStatusList = whiteListMapper.queryAuditStatusByIds(idsWithAuditStatusMap);
if (originalAuditStatusList == null || originalAuditStatusList.size() != idsWithAuditStatusMap.size()) {