diff --git a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectController.java b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectController.java index 2ac1fa1..5221d55 100644 --- a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectController.java +++ b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectController.java @@ -3,6 +3,7 @@ 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.response.ResponseResult; + import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.Min; @@ -149,4 +150,22 @@ public class ProtectObjectController implements ProtectObjectControllerApi { .addDataMap(protectObjectService.changeProtectObjectAuditStatus(protectObjectId, auditStatus)) .setData("proobj_id", protectObjectId); } + + /* + 防护对象数据统计 + */ + @Override + @GetMapping("/statistics") + public ResponseResult statisticsProtectObject() { + return ResponseResult.ok() + .setData("proobj_num", protectObjectService.queryProtectObjectsTotalNum(null, null, null, null, + null, null, null, null, null, null)) + .setData("proobj_used_num", protectObjectService.queryUsedProtectObjectsTotalNum()) + .setData("proobj_audit_num", protectObjectService.queryProtectObjectsTotalNum(null, null, null, null, + null, null, null, null, null, + AuditStatusEnum.getNumByState(AuditStatusEnum.AUDITED.getState()))) + .setData("proobj_undit_num", protectObjectService.queryProtectObjectsTotalNum(null, null, null, null, + null, null, null, null, null, + AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState()))); + } } diff --git a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectControllerApi.java b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectControllerApi.java index 387a94b..c830746 100644 --- a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectControllerApi.java +++ b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectControllerApi.java @@ -408,4 +408,41 @@ public interface ProtectObjectControllerApi { ) ResponseResult changeProtectObjectAuditStatus(@PathVariable Integer protectObjectId, @PathVariable Integer auditStatus); + + /* + 防护对象数据统计 + */ + @Operation( + summary = "数据统计", + description = "数据统计", + responses = { + @ApiResponse( + description = "返回数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "proobj_num": 2, + "proobj_used_num": 2, + "proobj_audit_num": 1, + "proobj_undit_num": 0 + } + } + """ + ) + ) + ) + }, + parameters = { + + } + ) + @GetMapping("/statistics") + ResponseResult statisticsProtectObject(); } diff --git a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectMapper.java b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectMapper.java index 5b8c7f1..2203732 100644 --- a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectMapper.java +++ b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectMapper.java @@ -1,6 +1,7 @@ package com.realtime.protection.server.defense.object; import com.realtime.protection.configuration.entity.defense.object.ProtectObject; +import com.realtime.protection.configuration.response.ResponseResult; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -48,4 +49,6 @@ public interface ProtectObjectMapper { @Param("proobj_audit_status") Integer protectObjectAuditStatus, @Param("page") Integer page, @Param("page_size") Integer pageSize); + + Integer queryUsedProtectObjectsTotalNum(); } diff --git a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectService.java b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectService.java index 1740012..12d35f9 100644 --- a/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectService.java +++ b/src/main/java/com/realtime/protection/server/defense/object/ProtectObjectService.java @@ -2,6 +2,7 @@ package com.realtime.protection.server.defense.object; import com.alibaba.excel.util.ListUtils; import com.realtime.protection.configuration.entity.defense.object.ProtectObject; +import com.realtime.protection.configuration.response.ResponseResult; 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; @@ -142,4 +143,8 @@ public class ProtectObjectService { protectObjectCreateUsername, protectObjectAuditStatus ); } + + public Integer queryUsedProtectObjectsTotalNum() { + return protectObjectMapper.queryUsedProtectObjectsTotalNum(); + } } diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java index f06cb4d..399b61a 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateController.java @@ -2,6 +2,7 @@ package com.realtime.protection.server.defense.template; import com.realtime.protection.configuration.entity.defense.template.Template; import com.realtime.protection.configuration.response.ResponseResult; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import jakarta.validation.Valid; import jakarta.validation.constraints.Min; import org.springframework.web.bind.annotation.*; @@ -112,5 +113,20 @@ public class TemplateController implements TemplateControllerApi { .setData("template_id", templateService.queryTemplateId(sourceSystem, eventName)); } - + /* + 策略模板数据统计 + */ + @Override + @GetMapping("/statistics") + public ResponseResult statisticsTemplate() { + return ResponseResult.ok() + .setData("template_num", templateService.queryTemplateTotalNum(null, null, null)) + .setData("template_used_num", templateService.queryUsedTemplateTotalNum()) + .setData("template_audit_num", templateService.queryAuditTemplateTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.AUDITED.getState()) + )) + .setData("template_unaudit_num", templateService.queryAuditTemplateTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState()) + )); + } } diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java index 9ee5fc2..3a34dda 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateControllerApi.java @@ -438,4 +438,41 @@ public interface TemplateControllerApi { } ) ResponseResult queryTemplateId(@RequestBody Map map); + + /* + 策略模板数据统计 + */ + @Operation( + summary = "数据统计", + description = "数据统计", + responses = { + @ApiResponse( + description = "返回数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "template_num": 1, + "template_used_num": 1, + "template_audit_num": 0, + "template_unaudit_num": 1 + } + } + """ + ) + ) + ) + }, + parameters = { + + } + ) + @GetMapping("/statistics") + ResponseResult statisticsTemplate(); } \ No newline at end of file diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java index baa3542..7c036ad 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateMapper.java @@ -38,4 +38,8 @@ public interface TemplateMapper { List queryEventName(String sourceSystem); Integer queryTemplateId(String sourceSystem, String eventName); + + Integer queryUsedTemplateTotalNum(); + + Integer queryAuditTemplateTotalNum(Integer auditState); } diff --git a/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java b/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java index 69b2094..ffdad26 100644 --- a/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java +++ b/src/main/java/com/realtime/protection/server/defense/template/TemplateService.java @@ -79,4 +79,12 @@ public class TemplateService { public Integer queryTemplateId(String sourceSystem, String eventName) { return templateMapper.queryTemplateId(sourceSystem, eventName); } + + public Integer queryUsedTemplateTotalNum() { + return templateMapper.queryUsedTemplateTotalNum(); + } + + public Integer queryAuditTemplateTotalNum(Integer auditState) { + return templateMapper.queryAuditTemplateTotalNum(auditState); + } } diff --git a/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleController.java b/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleController.java index 73990c8..83ef29a 100644 --- a/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleController.java +++ b/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleController.java @@ -2,6 +2,7 @@ package com.realtime.protection.server.rule.dynamicrule; import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject; import com.realtime.protection.configuration.response.ResponseResult; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -164,15 +165,22 @@ public class DynamicRuleController implements DynamicRuleControllerApi { /** * 获取统计数据 */ + @Override @GetMapping("/statistics") public ResponseResult getStaticRuleStatisticsData(){ return ResponseResult.ok() .setData("dynamic_rule_num", dynamicRuleService.queryDynamicRuleTotalNum(null, null, null, null)) - .setData("dynamic_rule_used_num", dynamicRuleService.queryUsedDynamicRuleTotalNum()) - .setData("dynamic_rule_audit_num", dynamicRuleService.queryAuditDynamicRuleTotalNum(1)) - .setData("dynamic_rule_unaudit_num", dynamicRuleService.queryAuditDynamicRuleTotalNum(0)); + .setData("dynamic_rule_used_num", dynamicRuleService.queryAuditDynamicRuleTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.USING.getState()) + )) + .setData("dynamic_rule_audit_num", dynamicRuleService.queryAuditDynamicRuleTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.AUDITED.getState()) + )) + .setData("dynamic_rule_unaudit_num", dynamicRuleService.queryAuditDynamicRuleTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState()) + )); } diff --git a/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleControllerApi.java b/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleControllerApi.java index dcfc227..29a55e7 100644 --- a/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleControllerApi.java +++ b/src/main/java/com/realtime/protection/server/rule/dynamicrule/DynamicRuleControllerApi.java @@ -358,5 +358,37 @@ public interface DynamicRuleControllerApi { @RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page_size", defaultValue = "10") Integer pageSize); + @Operation( + summary = "数据统计", + description = "数据统计", + responses = { + @ApiResponse( + description = "返回数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "dynamic_rule_num": 3, + "dynamic_rule_used_num": 0, + "dynamic_rule_audit_num": 2, + "dynamic_rule_unaudit_num": 0 + } + } + """ + ) + ) + ) + }, + parameters = { + } + ) + @GetMapping("/statistics") + ResponseResult getStaticRuleStatisticsData(); } \ No newline at end of file diff --git a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleController.java b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleController.java index 0a95937..ccdf690 100644 --- a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleController.java +++ b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleController.java @@ -4,6 +4,7 @@ package com.realtime.protection.server.rule.staticrule; import com.alibaba.excel.EasyExcel; import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject; import com.realtime.protection.configuration.response.ResponseResult; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -178,6 +179,7 @@ public class StaticRuleController implements StaticRuleControllerApi { /** * 批量修改审核状态 */ + @Override @PostMapping("/auditbatch") public ResponseResult updateStaticRuleAuditStatusBatch(@RequestBody Map idsWithAuditStatusMap) { List errorIds = new ArrayList<>(); @@ -198,6 +200,26 @@ public class StaticRuleController implements StaticRuleControllerApi { .setData("success", staticRuleService.updateAuditStatusBatch(idsWithAuditStatusMap)); } + /** + * 获取统计数据 + */ + @Override + @GetMapping("/statistics") + public ResponseResult getStaticRuleStatisticsData(){ + + return ResponseResult.ok() + .setData("static_rule_num", staticRuleService.queryStaticRuleTotalNum(null, null, null, null)) + .setData("static_rule_used_num", staticRuleService.queryAuditStaticRuleTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.USING.getState()) + )) + .setData("static_rule_audit_num", staticRuleService.queryAuditStaticRuleTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.AUDITED.getState()) + )) + .setData("static_rule_unaudit_num", staticRuleService.queryAuditStaticRuleTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState()))); + } + + } diff --git a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleControllerApi.java b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleControllerApi.java index 590b9a1..905ae9a 100644 --- a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleControllerApi.java +++ b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleControllerApi.java @@ -7,18 +7,17 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; 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.HttpServletResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; -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 StaticRuleControllerApi { @@ -281,4 +280,62 @@ public interface StaticRuleControllerApi { } ) ResponseResult updateStaticRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus); + + @PostMapping("/auditbatch") + @Operation( + summary = "批量更新静态规则审批状态", + description = "批量更新静态规则审批状态,0未审核、1审核不通过、2审核通过", + responses = { + @io.swagger.v3.oas.annotations.responses.ApiResponse( + description = "返回静态规则审核结果", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "字典,key是静态规则id,value是静态规则审核状态id", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Map.class) + + ) + ) + ) + ResponseResult updateStaticRuleAuditStatusBatch(@RequestBody Map idsWithAuditStatusMap); + + @Operation( + summary = "数据统计", + description = "数据统计", + responses = { + @ApiResponse( + description = "返回数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "static_rule_num": 7, + "static_rule_used_num": 2, + "static_rule_audit_num": 3, + "static_rule_unaudit_num": 1 + } + } + """ + ) + ) + ) + }, + parameters = { + + } + ) + @GetMapping("/statistics") + ResponseResult getStaticRuleStatisticsData(); } diff --git a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleMapper.java b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleMapper.java index 8cdc9e1..6b6207d 100644 --- a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleMapper.java +++ b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleMapper.java @@ -46,4 +46,8 @@ public interface StaticRuleMapper { List queryStaticRuleByIds(List ids); void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch")Map idWithAuditStatusBatch); + + Integer queryUsedStaticRuleTotalNum(); + + Integer queryAuditStaticRuleTotalNum(@Param("auditStatus")Integer auditStatus); } diff --git a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java index 35801fc..8e3f832 100644 --- a/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java +++ b/src/main/java/com/realtime/protection/server/rule/staticrule/StaticRuleService.java @@ -193,13 +193,13 @@ public class StaticRuleService { return resultMap; } + @Transactional public void deleteStaticRuleById(Integer id) { StaticRuleObject staticRuleObject = staticRuleMapper.queryStaticRuleById(id); if (staticRuleObject == null) { return; } - if (Objects.equals(staticRuleObject.getAuditStatus(), AuditStatusEnum.USING.getNum())) { throw new IllegalArgumentException("当前静态规则正在使用,无法删除"); } @@ -242,4 +242,12 @@ public class StaticRuleService { //实现事务操作 return sqlSessionWrapper.startBatchSession(StaticRuleMapper.class, updateStaticRuleAuditStatusFunction, idsWithAuditStatusMap); } + + public Integer queryUsedStaticRuleTotalNum() { + return staticRuleMapper.queryUsedStaticRuleTotalNum(); + } + + public Integer queryAuditStaticRuleTotalNum(Integer auditStatus) { + return staticRuleMapper.queryAuditStaticRuleTotalNum(auditStatus); + } } diff --git a/src/main/java/com/realtime/protection/server/task/TaskController.java b/src/main/java/com/realtime/protection/server/task/TaskController.java index cbbeff4..c06adf4 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskController.java +++ b/src/main/java/com/realtime/protection/server/task/TaskController.java @@ -4,6 +4,8 @@ import com.realtime.protection.configuration.entity.task.Task; import com.realtime.protection.configuration.entity.task.TaskCommandInfo; import com.realtime.protection.configuration.exception.DorisStartException; import com.realtime.protection.configuration.response.ResponseResult; +import com.realtime.protection.configuration.utils.enums.StateEnum; +import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import com.realtime.protection.server.command.CommandService; import com.realtime.protection.server.task.status.StateChangeService; import jakarta.validation.Valid; @@ -162,6 +164,7 @@ public class TaskController implements TaskControllerApi { /** * 批量修改审核状态 */ + @Override @PostMapping("/auditbatch") public ResponseResult updateTaskAuditStatusBatch(@RequestBody Map idsWithAuditStatusMap) { List errorIds = new ArrayList<>(); @@ -172,7 +175,7 @@ public class TaskController implements TaskControllerApi { errorIds.add(id); } } - if (!errorIds.isEmpty()){ + if (!errorIds.isEmpty()) { return new ResponseResult(400, "id or status is invalid") .setData("tasks_id", errorIds) .setData("success", false); @@ -181,4 +184,20 @@ public class TaskController implements TaskControllerApi { return ResponseResult.ok() .setData("success", taskService.updateAuditStatusBatch(idsWithAuditStatusMap)); } -} + + /** + * 统计 + */ + @Override + @GetMapping("/statistics") + public ResponseResult statistics() { + return ResponseResult.ok() + .setData("total_num", taskService.queryTaskTotalNum(null, null, null, null)) + .setData("running_num", taskService.queryTaskTotalNum(StateEnum.RUNNING.getStateNum(), null, null, null)) + .setData("finished_num", taskService.queryTaskTotalNum(StateEnum.FINISHED.getStateNum(), null, null, null)) + .setData("unaudit_num", taskService.queryAuditTaskTotalNum( + AuditStatusEnum.PENDING.getNum() + )); + } + +} \ No newline at end of file diff --git a/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java b/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java index 4524f46..fd39664 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java +++ b/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java @@ -17,6 +17,8 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import org.springframework.web.bind.annotation.*; +import java.util.Map; + @Tag(name = "任务控制器API", description = "任务管理模块相关的所有接口") public interface TaskControllerApi { @PostMapping("/new") @@ -521,4 +523,71 @@ public interface TaskControllerApi { @GetMapping("/{commandId}/valid/{isJudged}") ResponseResult setCommandJudged(@PathVariable Boolean isJudged, @PathVariable String commandId); + + @Operation( + summary = "批量更新任务审批状态", + description = "批量更新任务审批状态,0未审核、1审核不通过、2审核通过", + responses = { + @io.swagger.v3.oas.annotations.responses.ApiResponse( + description = "返回任务审核结果", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( + description = "字典,key是任务id,value是任务审核状态id", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Map.class) + + ) + ) + ) + @PostMapping("/auditbatch") + ResponseResult updateTaskAuditStatusBatch(@RequestBody Map idsWithAuditStatusMap); + + @Operation( + summary = "数据统计", + description = "数据统计", + responses = { + @ApiResponse( + description = "返回数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "total_num": 11, + "running_num": 2, + "finished_num": 5, + "unaudit_num": 5 + } + } + """, + description = """ + "total_num": 总数 + + "running_num": 运行任务数 + + "finished_num": 结束任务数 + + "unaudit_num": 未审核数 + """ + ) + ) + ) + }, + parameters = { + + } + ) + @GetMapping("/statistics") + ResponseResult statistics(); } diff --git a/src/main/java/com/realtime/protection/server/task/TaskMapper.java b/src/main/java/com/realtime/protection/server/task/TaskMapper.java index d70237f..73d451b 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskMapper.java +++ b/src/main/java/com/realtime/protection/server/task/TaskMapper.java @@ -61,4 +61,6 @@ public interface TaskMapper { @Param("task_name") String taskName, @Param("task_creator") String taskCreator); void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch") Map idWithAuditStatusBatch); + + Integer queryAuditTaskTotalNum(Integer auditState); } diff --git a/src/main/java/com/realtime/protection/server/task/TaskService.java b/src/main/java/com/realtime/protection/server/task/TaskService.java index df25f1b..307ed53 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskService.java +++ b/src/main/java/com/realtime/protection/server/task/TaskService.java @@ -334,4 +334,8 @@ public class TaskService { } + + public Integer queryAuditTaskTotalNum(Integer auditState) { + return taskMapper.queryAuditTaskTotalNum(auditState); + } } diff --git a/src/main/java/com/realtime/protection/server/whitelist/WhiteListController.java b/src/main/java/com/realtime/protection/server/whitelist/WhiteListController.java index 44fda73..9ba2128 100644 --- a/src/main/java/com/realtime/protection/server/whitelist/WhiteListController.java +++ b/src/main/java/com/realtime/protection/server/whitelist/WhiteListController.java @@ -3,6 +3,7 @@ package com.realtime.protection.server.whitelist; import com.alibaba.excel.EasyExcel; 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.HttpServletResponse; import jakarta.validation.Valid; import org.springframework.web.bind.annotation.*; @@ -194,5 +195,21 @@ public class WhiteListController implements WhiteListControllerApi { .setData("whiteobj_list", whiteListService.whiteListStaticRulesCheck(staticRuleIds)); } + /* + 白名单数据统计 + */ + @Override + @GetMapping("/statistics") + public ResponseResult getWhiteListStatisticsData() { + return ResponseResult.ok() + .setData("whiteobj_num", whiteListService.queryWhiteListTotalNum(null, null)) + .setData("whiteobj_audit_num", whiteListService.queryAuditWhiteListTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.AUDITED.getState()) + )) + .setData("whiteobj_unaudit_num", whiteListService.queryAuditWhiteListTotalNum( + AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState()) + )); + } + } diff --git a/src/main/java/com/realtime/protection/server/whitelist/WhiteListControllerApi.java b/src/main/java/com/realtime/protection/server/whitelist/WhiteListControllerApi.java index fb31c4b..96aa50a 100644 --- a/src/main/java/com/realtime/protection/server/whitelist/WhiteListControllerApi.java +++ b/src/main/java/com/realtime/protection/server/whitelist/WhiteListControllerApi.java @@ -7,8 +7,10 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; 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.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; @@ -240,4 +242,51 @@ public interface WhiteListControllerApi { } ) ResponseResult whiteListStaticRulesCheck(@PathVariable List staticRuleIds); + + /* + 白名单数据统计 + */ + + @Operation( + summary = "白名单数据统计", + description = "白名单数据统计", + responses = { + @ApiResponse( + description = "返回白名单数据统计", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class), + examples = @ExampleObject( + name = "example", + value = """ + { + "code": 200, + "message": "request succeed", + "data": { + "proobj_num": 2, + "proobj_used_num": 2, + "proobj_audit_num": 1, + "proobj_undit_num": 0 + } + } + """, + description = """ + "proobj_num": 白名单总数 + + "template_name": 白名单使用数 + + "proobj_audit_num": 审核通过数 + + "proobj_undit_num": 未审核数 + """ + ) + ) + ) + }, + parameters = { + + } + ) + @GetMapping("/statistics") + ResponseResult getWhiteListStatisticsData(); } diff --git a/src/main/java/com/realtime/protection/server/whitelist/WhiteListMapper.java b/src/main/java/com/realtime/protection/server/whitelist/WhiteListMapper.java index 8f7ce67..3535c66 100644 --- a/src/main/java/com/realtime/protection/server/whitelist/WhiteListMapper.java +++ b/src/main/java/com/realtime/protection/server/whitelist/WhiteListMapper.java @@ -45,4 +45,6 @@ public interface WhiteListMapper { List whiteListCommandsCheck(List taskCommandInfos); List whiteListCStaticRulesCheck(@Param("staticRuleObjects") List staticRuleObjects); + + Integer queryAuditWhiteListTotalNum(@Param("auditStatus") Integer auditStatus); } diff --git a/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java b/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java index 0c80a1e..2cc4005 100644 --- a/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java +++ b/src/main/java/com/realtime/protection/server/whitelist/WhiteListService.java @@ -185,4 +185,7 @@ public class WhiteListService { } + public Integer queryAuditWhiteListTotalNum(Integer auditStatus) { + return whiteListMapper.queryAuditWhiteListTotalNum(auditStatus); + } } diff --git a/src/main/resources/mappers/DynamicRuleMapper.xml b/src/main/resources/mappers/DynamicRuleMapper.xml index ec6e2ec..b65b933 100644 --- a/src/main/resources/mappers/DynamicRuleMapper.xml +++ b/src/main/resources/mappers/DynamicRuleMapper.xml @@ -153,6 +153,7 @@ + + UPDATE t_protect_object diff --git a/src/main/resources/mappers/StaticRuleMapper.xml b/src/main/resources/mappers/StaticRuleMapper.xml index dd2c0a3..5270807 100644 --- a/src/main/resources/mappers/StaticRuleMapper.xml +++ b/src/main/resources/mappers/StaticRuleMapper.xml @@ -22,7 +22,7 @@ #{object.staticRuleMdport}, #{object.staticRuleProtocol}, #{object.staticRuleMprotocol}, #{object.staticRuleDns}, #{object.staticRuleURL}, #{object.staticRulePriority}, #{object.staticRuleRange}, #{object.staticRuleFrequency}, - #{object.staticRuleAuditStatus}) + #{object.auditStatus}) insert into t_static_rule(static_rule_name, static_rule_create_time, @@ -115,7 +115,7 @@ - + @@ -206,5 +206,15 @@ #{id} + + \ No newline at end of file diff --git a/src/main/resources/mappers/TaskMapper.xml b/src/main/resources/mappers/TaskMapper.xml index a3bc326..46a1677 100644 --- a/src/main/resources/mappers/TaskMapper.xml +++ b/src/main/resources/mappers/TaskMapper.xml @@ -257,7 +257,7 @@ - + @@ -266,7 +266,7 @@ + + \ No newline at end of file diff --git a/src/main/resources/mappers/TemplateMapper.xml b/src/main/resources/mappers/TemplateMapper.xml index cb36121..68c83b9 100644 --- a/src/main/resources/mappers/TemplateMapper.xml +++ b/src/main/resources/mappers/TemplateMapper.xml @@ -146,6 +146,17 @@ WHERE strategy_template_name = #{eventName} AND strategy_template_source_system = #{sourceSystem} + + + + UPDATE t_strategy_template diff --git a/src/main/resources/mappers/WhiteListMapper.xml b/src/main/resources/mappers/WhiteListMapper.xml index 05a5dc8..2acecd2 100644 --- a/src/main/resources/mappers/WhiteListMapper.xml +++ b/src/main/resources/mappers/WhiteListMapper.xml @@ -284,5 +284,10 @@ + \ No newline at end of file diff --git a/src/test/java/com/realtime/protection/server/rule/staticrule/StaticRuleServiceTest.java b/src/test/java/com/realtime/protection/server/rule/staticrule/StaticRuleServiceTest.java index 4aa7345..23466c6 100644 --- a/src/test/java/com/realtime/protection/server/rule/staticrule/StaticRuleServiceTest.java +++ b/src/test/java/com/realtime/protection/server/rule/staticrule/StaticRuleServiceTest.java @@ -114,4 +114,6 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests { System.out.println(staticRuleService.updateAuditStatusBatch(map)); } + + } diff --git a/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java b/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java index 5ce7305..63c0aa8 100644 --- a/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java +++ b/src/test/java/com/realtime/protection/server/task/TaskServiceTest.java @@ -3,8 +3,10 @@ package com.realtime.protection.server.task; import com.realtime.protection.ProtectionApplicationTests; import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject; import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject; +import com.realtime.protection.configuration.entity.task.DynamicTaskInfo; import com.realtime.protection.configuration.entity.task.Task; import com.realtime.protection.configuration.entity.task.TaskCommandInfo; +import com.realtime.protection.configuration.exception.DorisStartException; import com.realtime.protection.server.rule.dynamicrule.DynamicRuleService; import com.realtime.protection.server.rule.staticrule.StaticRuleService; import com.realtime.protection.server.task.status.StateChangeService; @@ -27,13 +29,15 @@ class TaskServiceTest extends ProtectionApplicationTests { private final TaskService taskService; private final StaticRuleService staticRuleService; private final DynamicRuleService dynamicRuleService; + private final StateChangeService stateChangeService; private Task task; @Autowired - TaskServiceTest(TaskService taskService, StaticRuleService staticRuleService, DynamicRuleService dynamicRuleService) { + TaskServiceTest(TaskService taskService, StaticRuleService staticRuleService, DynamicRuleService dynamicRuleService, StateChangeService stateChangeService) { this.taskService = taskService; this.staticRuleService = staticRuleService; this.dynamicRuleService = dynamicRuleService; + this.stateChangeService = stateChangeService; } @BeforeEach @@ -189,4 +193,15 @@ class TaskServiceTest extends ProtectionApplicationTests { System.out.println(taskService.updateAuditStatusBatch(map)); } + @Test + void testGetDynamicTaskInfos(){ + List dynamicTaskInfos = taskService.getDynamicTaskInfos(43844L); + System.out.println(dynamicTaskInfos); + } + + @Test + void changeTaskstatus() throws DorisStartException { + stateChangeService.changeState(2, 43844L, false); + + } } \ No newline at end of file