hotfix:
修改部分API注释bug
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
# SSFY系统 README
|
# SSFY系统 README
|
||||||
|
|
||||||
## 项目文件夹结构说明:
|
## 项目文件夹结构说明:
|
||||||
|
|
||||||
目前整体分为两大板块:**configuration**和**server**
|
目前整体分为两大板块:**configuration**和**server**
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
所有业务的配置,包括切面、拦截器、中间件、消息处理等配置全部放置于此处。
|
所有业务的配置,包括切面、拦截器、中间件、消息处理等配置全部放置于此处。
|
||||||
任何带@Configuration注解的配置均放置于此
|
任何带@Configuration注解的配置均放置于此
|
||||||
|
|
||||||
### server
|
### server
|
||||||
|
|
||||||
server主要存放所有的业务逻辑以及Mapper接口。业务逻辑和Mapper需要按照业务进行划分进行分开放置
|
server主要存放所有的业务逻辑以及Mapper接口。业务逻辑和Mapper需要按照业务进行划分进行分开放置
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class ProtectObject {
|
|||||||
private Integer protectObjectId;
|
private Integer protectObjectId;
|
||||||
|
|
||||||
@JsonProperty("proobj_name")
|
@JsonProperty("proobj_name")
|
||||||
@NotNull(message = "proobj_name should not be empty.")
|
@NotNull(message = "proobj_name字段不能为空。")
|
||||||
@ExcelProperty("名称")
|
@ExcelProperty("名称")
|
||||||
@Schema(description = "防护对象名称", example = "静态对象测试")
|
@Schema(description = "防护对象名称", example = "静态对象测试")
|
||||||
private String protectObjectName;
|
private String protectObjectName;
|
||||||
@@ -35,21 +35,21 @@ public class ProtectObject {
|
|||||||
private String protectObjectIPAddress;
|
private String protectObjectIPAddress;
|
||||||
|
|
||||||
@JsonProperty("proobj_port")
|
@JsonProperty("proobj_port")
|
||||||
@NotNull(message = "proobj_port should not be empty.")
|
@NotNull(message = "proobj_port字段不能为空。")
|
||||||
@Max(value = 65535, message = "port should not be more than 65535")
|
@Max(value = 65535, message = "端口号不能大于65535。")
|
||||||
@Min(value = 1, message = "port should not be less than 1")
|
@Min(value = 1, message = "端口号不能小于1。")
|
||||||
@ExcelProperty("端口")
|
@ExcelProperty("端口")
|
||||||
@Schema(description = "防护对象端口", maximum = "65535", minimum = "1", example = "8080")
|
@Schema(description = "防护对象端口", maximum = "65535", minimum = "1", example = "8080")
|
||||||
private Integer protectObjectPort;
|
private Integer protectObjectPort;
|
||||||
|
|
||||||
@JsonProperty("proobj_url")
|
@JsonProperty("proobj_url")
|
||||||
@NotNull(message = "proobj_url should not be empty.")
|
@NotNull(message = "proobj_url字段不能为空。")
|
||||||
@ExcelProperty("URL")
|
@ExcelProperty("URL")
|
||||||
@Schema(description = "防护对象URL", example = "alice.bob.com")
|
@Schema(description = "防护对象URL", example = "alice.bob.com")
|
||||||
private String protectObjectURL;
|
private String protectObjectURL;
|
||||||
|
|
||||||
@JsonProperty("proobj_protocol")
|
@JsonProperty("proobj_protocol")
|
||||||
@NotNull(message = "proobj_protocol should not be empty.")
|
@NotNull(message = "proobj_protocol字段不能为空")
|
||||||
@ExcelProperty("协议")
|
@ExcelProperty("协议")
|
||||||
@Schema(description = "防护对象网络协议(目前仅可以填写TCP或UDP)", example = "TCP")
|
@Schema(description = "防护对象网络协议(目前仅可以填写TCP或UDP)", example = "TCP")
|
||||||
private String protectObjectProtocol;
|
private String protectObjectProtocol;
|
||||||
|
|||||||
@@ -12,27 +12,27 @@ public class Template {
|
|||||||
private Integer templateId;
|
private Integer templateId;
|
||||||
|
|
||||||
@JsonProperty("template_name")
|
@JsonProperty("template_name")
|
||||||
@NotNull(message = "template name should not be empty.")
|
@NotNull(message = "template_name字段不能为空。")
|
||||||
@Schema(description = "防御策略模板名称", example = "自定义模板")
|
@Schema(description = "防御策略模板名称", example = "自定义模板")
|
||||||
private String templateName;
|
private String templateName;
|
||||||
|
|
||||||
@JsonProperty("source_system")
|
@JsonProperty("source_system")
|
||||||
@NotNull(message = "source_system should not be empty. ")
|
@NotNull(message = "source_system字段不能为空。")
|
||||||
@Schema(description = "防御策略模板数据来源系统", example = "BW系统")
|
@Schema(description = "防御策略模板数据来源系统", example = "BW系统")
|
||||||
private String sourceSystem;
|
private String sourceSystem;
|
||||||
|
|
||||||
@JsonProperty("protect_level_low")
|
@JsonProperty("protect_level_low")
|
||||||
@NotNull(message = "protect_level_low should not be empty. ")
|
@NotNull(message = "protect_level_low字段不能为空。")
|
||||||
@Schema(description = "防御策略模板日常态字段提取选项")
|
@Schema(description = "防御策略模板日常态字段提取选项")
|
||||||
private ProtectLevel protectLevelLow;
|
private ProtectLevel protectLevelLow;
|
||||||
|
|
||||||
@JsonProperty("protect_level_medium")
|
@JsonProperty("protect_level_medium")
|
||||||
@NotNull(message = "protect_level_medium should not be empty. ")
|
@NotNull(message = "protect_level_medium字段不能为空。")
|
||||||
@Schema(description = "防御策略模板应急态字段提取选项")
|
@Schema(description = "防御策略模板应急态字段提取选项")
|
||||||
private ProtectLevel protectLevelMedium;
|
private ProtectLevel protectLevelMedium;
|
||||||
|
|
||||||
@JsonProperty("protect_level_high")
|
@JsonProperty("protect_level_high")
|
||||||
@NotNull(message = "protect_level_high should not be empty. ")
|
@NotNull(message = "protect_level_high字段不能为空。")
|
||||||
@Schema(description = "防御策略模板紧急态字段提取选项")
|
@Schema(description = "防御策略模板紧急态字段提取选项")
|
||||||
private ProtectLevel protectLevelHigh;
|
private ProtectLevel protectLevelHigh;
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,19 @@ public class Task {
|
|||||||
private Long taskId;
|
private Long taskId;
|
||||||
|
|
||||||
@JsonProperty("task_name")
|
@JsonProperty("task_name")
|
||||||
@NotNull(message = "task_name should not be empty. ")
|
@NotNull(message = "task_name字段不能为空。")
|
||||||
@Schema(description = "任务名称", example = "静态任务")
|
@Schema(description = "任务名称", example = "静态任务")
|
||||||
private String taskName;
|
private String taskName;
|
||||||
|
|
||||||
@JsonProperty("task_start_time")
|
@JsonProperty("task_start_time")
|
||||||
@NotNull(message = "task_start_time should not be empty. ")
|
@NotNull(message = "task_start_time字段不能为空。")
|
||||||
@Future(message = "task_start_time should be a future time")
|
@Future(message = "task_start_time必须晚于当前时间。")
|
||||||
@Schema(description = "任务开始时间,必须晚于当前时间", example = "2024-10-23T00:00:00")
|
@Schema(description = "任务开始时间,必须晚于当前时间", example = "2024-10-23T00:00:00")
|
||||||
private LocalDateTime taskStartTime;
|
private LocalDateTime taskStartTime;
|
||||||
|
|
||||||
@JsonProperty("task_end_time")
|
@JsonProperty("task_end_time")
|
||||||
@NotNull(message = "task_end_time should not be empty. ")
|
@NotNull(message = "task_end_time字段不能为空。")
|
||||||
@Future(message = "task_end_time should be a future time. ")
|
@Future(message = "task_end_time必须晚于当前时间。")
|
||||||
@Schema(description = "任务结束时间,必须晚于开始时间", example = "2024-10-24T00:00:00")
|
@Schema(description = "任务结束时间,必须晚于开始时间", example = "2024-10-24T00:00:00")
|
||||||
private LocalDateTime taskEndTime;
|
private LocalDateTime taskEndTime;
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ public class Task {
|
|||||||
private LocalDateTime taskModifyTime;
|
private LocalDateTime taskModifyTime;
|
||||||
|
|
||||||
@JsonProperty("task_type")
|
@JsonProperty("task_type")
|
||||||
@NotNull(message = "task_type should not be empty. ")
|
@NotNull(message = "task_type字段不能为空。")
|
||||||
@Schema(description = "任务类型,1为静态任务,2为实时任务,3为研判后任务", example = "1")
|
@Schema(description = "任务类型,1为静态任务,2为实时任务,3为研判后任务", example = "1")
|
||||||
private Integer taskType;
|
private Integer taskType;
|
||||||
|
|
||||||
@JsonProperty("task_act")
|
@JsonProperty("task_act")
|
||||||
@NotNull(message = "task_act should not be empty. ")
|
@NotNull(message = "task_act字段不能为空。")
|
||||||
@Schema(description = "任务行为,目前只能为【阻断】", example = "阻断")
|
@Schema(description = "任务行为,目前只能为【阻断】", example = "阻断")
|
||||||
private String taskAct;
|
private String taskAct;
|
||||||
|
|
||||||
|
|||||||
@@ -30,30 +30,23 @@ public class GlobalExceptionHandler {
|
|||||||
@Order(3)
|
@Order(3)
|
||||||
@ExceptionHandler(value = {Exception.class})
|
@ExceptionHandler(value = {Exception.class})
|
||||||
public ResponseResult handleGlobalException(Exception e) {
|
public ResponseResult handleGlobalException(Exception e) {
|
||||||
log.error("meets global exception: " + e.getMessage());
|
log.error("遭遇全局异常:" + e.getMessage());
|
||||||
return ResponseResult.error().setMessage(e.getMessage());
|
return ResponseResult.error().setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = {PersistenceException.class})
|
@ExceptionHandler(value = {PersistenceException.class, DuplicateKeyException.class})
|
||||||
public ResponseResult handleSQLException(PersistenceException e) {
|
public ResponseResult handleSQLException(Exception e) {
|
||||||
log.error("meets database exception: " + e.getMessage());
|
log.info("遭遇数据库异常:" + e.getMessage());
|
||||||
return ResponseResult.invalid().setMessage(
|
return ResponseResult.invalid().setMessage(
|
||||||
"please check the integrity of the data. check if the json data exists in the database");
|
"请检查json字段的完整性,确保json字段按照文档中要求填写。");
|
||||||
}
|
|
||||||
|
|
||||||
@Order(2)
|
|
||||||
@ExceptionHandler(value = DuplicateKeyException.class)
|
|
||||||
public ResponseResult handleDuplicateKeyException(DuplicateKeyException e) {
|
|
||||||
log.debug("meets duplicate key exception: " + e.getMessage());
|
|
||||||
return ResponseResult.invalid().setMessage("duplicate key in json data");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||||
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
|
public ResponseResult handleBindException(MethodArgumentNotValidException e) {
|
||||||
log.debug("meets data bind exception: " + e.getMessage());
|
log.debug("遭遇数据绑定异常:" + e.getMessage());
|
||||||
return ResponseResult.invalid().setMessage(
|
return ResponseResult.invalid().setMessage(
|
||||||
e.getBindingResult().getAllErrors().stream()
|
e.getBindingResult().getAllErrors().stream()
|
||||||
.map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining())
|
.map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining())
|
||||||
@@ -67,14 +60,14 @@ public class GlobalExceptionHandler {
|
|||||||
IllegalStateException.class
|
IllegalStateException.class
|
||||||
})
|
})
|
||||||
public ResponseResult handleHandlerMethodValidationException(Exception e) {
|
public ResponseResult handleHandlerMethodValidationException(Exception e) {
|
||||||
log.debug("meets illegal argument exception: " + e.getMessage());
|
log.debug("遭遇非法参数异常:" + e.getMessage());
|
||||||
return ResponseResult.invalid().setMessage(e.getMessage());
|
return ResponseResult.invalid().setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = NotLoginException.class)
|
@ExceptionHandler(value = NotLoginException.class)
|
||||||
public ResponseResult handleNotLoginException(NotLoginException e) {
|
public ResponseResult handleNotLoginException(NotLoginException e) {
|
||||||
log.debug("meets not login exception, login type: " + e.getLoginType());
|
log.debug("遭遇Sa-Token登录异常,登录类型为:" + e.getLoginType());
|
||||||
return new ResponseResult(
|
return new ResponseResult(
|
||||||
401,
|
401,
|
||||||
e.getMessage()
|
e.getMessage()
|
||||||
@@ -84,16 +77,16 @@ public class GlobalExceptionHandler {
|
|||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = SaTokenException.class)
|
@ExceptionHandler(value = SaTokenException.class)
|
||||||
public ResponseResult handleSaTokenException(SaTokenException e) {
|
public ResponseResult handleSaTokenException(SaTokenException e) {
|
||||||
log.debug("sa-token meets exception: " + e.getMessage());
|
log.debug("Sa-token模块遭遇异常:" + e.getMessage());
|
||||||
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
return ResponseResult.unAuthorized().setMessage(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@ExceptionHandler(value = DorisStartException.class)
|
@ExceptionHandler(value = DorisStartException.class)
|
||||||
public ResponseResult handleDorisStartException(DorisStartException e) {
|
public ResponseResult handleDorisStartException(DorisStartException e) {
|
||||||
log.warn("doris database meets exception: " + e.getMessage());
|
log.warn("Doris数据库遭遇异常:" + e.getMessage());
|
||||||
ResponseResult responseResult = ResponseResult.error()
|
ResponseResult responseResult = ResponseResult.error()
|
||||||
.setMessage("Doris command creation meets error: " + e.getMessage());
|
.setMessage("Doris数据库指令生成遭遇异常:" + e.getMessage());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stateChangeService.changeState(StateEnum.FAILED.getStateNum(), e.taskId);
|
stateChangeService.changeState(StateEnum.FAILED.getStateNum(), e.taskId);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class CommandService {
|
|||||||
commandBatch.clear();
|
commandBatch.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(String.format("create all the commands from task(%d), rule(%d)",
|
log.debug(String.format("在task(%d)和rule(%d)中构建了全部指令",
|
||||||
info.getTaskId(), info.getRuleId()));
|
info.getTaskId(), info.getRuleId()));
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@@ -68,6 +68,7 @@ public class CommandService {
|
|||||||
public void createCommand(TaskCommandInfo commandInfo) throws DorisStartException {
|
public void createCommand(TaskCommandInfo commandInfo) throws DorisStartException {
|
||||||
try {
|
try {
|
||||||
sqlSessionWrapper.startBatchSession(CommandMapper.class, createCommandBatchFunction, commandInfo);
|
sqlSessionWrapper.startBatchSession(CommandMapper.class, createCommandBatchFunction, commandInfo);
|
||||||
|
taskService.changeTaskStatus(commandInfo.getTaskId(), StateEnum.RUNNING.getStateNum());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DorisStartException(e, commandInfo.getTaskId());
|
throw new DorisStartException(e, commandInfo.getTaskId());
|
||||||
}
|
}
|
||||||
@@ -92,7 +93,10 @@ public class CommandService {
|
|||||||
try {
|
try {
|
||||||
sqlSessionWrapper.startBatchSession(CommandMapper.class, function, taskCommandInfos);
|
sqlSessionWrapper.startBatchSession(CommandMapper.class, function, taskCommandInfos);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TaskCommandInfo info = taskCommandInfos.get(0);
|
TaskCommandInfo info = null;
|
||||||
|
if (taskCommandInfos != null) {
|
||||||
|
info = taskCommandInfos.get(0);
|
||||||
|
}
|
||||||
Long taskId = null;
|
Long taskId = null;
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
taskId = info.getTaskId();
|
taskId = info.getTaskId();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class ProjectObjectDataListener implements ReadListener<ProtectObject> {
|
|||||||
private void saveData() {
|
private void saveData() {
|
||||||
Boolean success = protectObjectService.newProtectObjects(cachedDataList);
|
Boolean success = protectObjectService.newProtectObjects(cachedDataList);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new RuntimeException("Error reading data in /proobj/new");
|
throw new RuntimeException("在/proobj/upload中读取数据时出现了错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
|
|||||||
@Override
|
@Override
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public ResponseResult uploadFile(
|
public ResponseResult uploadFile(
|
||||||
@NotNull(message = "uploadFile cannot be null. ") MultipartFile uploadFile
|
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
EasyExcel.read(uploadFile.getInputStream(), ProtectObject.class,
|
EasyExcel.read(uploadFile.getInputStream(), ProtectObject.class,
|
||||||
new ProjectObjectDataListener(protectObjectService)).sheet().doRead();
|
new ProjectObjectDataListener(protectObjectService)).sheet().doRead();
|
||||||
@@ -85,6 +85,10 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
|
|||||||
@GetMapping("/{protectObjectId}/query")
|
@GetMapping("/{protectObjectId}/query")
|
||||||
public ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException {
|
public ResponseResult queryProtectObject(@PathVariable Integer protectObjectId) throws IllegalAccessException {
|
||||||
ProtectObject protectObject = protectObjectService.queryProtectObject(protectObjectId);
|
ProtectObject protectObject = protectObjectService.queryProtectObject(protectObjectId);
|
||||||
|
if (protectObject == null) {
|
||||||
|
return ResponseResult.invalid()
|
||||||
|
.setMessage("无效的防护对象ID,也许该ID指定的防护对象不存在?");
|
||||||
|
}
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setDataMap(EntityUtils.entityToMap(protectObject));
|
.setDataMap(EntityUtils.entityToMap(protectObject));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public interface ProtectObjectControllerApi {
|
|||||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "上传文件")
|
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "上传文件")
|
||||||
)
|
)
|
||||||
ResponseResult uploadFile(
|
ResponseResult uploadFile(
|
||||||
@NotNull(message = "uploadFile cannot be null. ") MultipartFile uploadFile
|
@NotNull(message = "uploadFile字段不能为空") MultipartFile uploadFile
|
||||||
) throws IOException;
|
) throws IOException;
|
||||||
|
|
||||||
@GetMapping("/download")
|
@GetMapping("/download")
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class ProtectObjectService {
|
|||||||
public Map<String, Object> changeProtectObjectAuditStatus(Integer protectObjectId, Integer auditStatus) {
|
public Map<String, Object> changeProtectObjectAuditStatus(Integer protectObjectId, Integer auditStatus) {
|
||||||
Integer originalAuditStatus = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
|
Integer originalAuditStatus = protectObjectMapper.queryProtectObject(protectObjectId).getProtectObjectAuditStatus();
|
||||||
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
if (!AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(auditStatus)) {
|
||||||
throw new IllegalArgumentException("invalid audit status");
|
throw new IllegalArgumentException("无效的审核状态");
|
||||||
}
|
}
|
||||||
Boolean success = protectObjectMapper.changeProtectObjectAuditStatus(protectObjectId, auditStatus);
|
Boolean success = protectObjectMapper.changeProtectObjectAuditStatus(protectObjectId, auditStatus);
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class TemplateController implements TemplateControllerApi {
|
|||||||
Template template = templateService.queryTemplate(templateId);
|
Template template = templateService.queryTemplate(templateId);
|
||||||
if (template == null) {
|
if (template == null) {
|
||||||
return ResponseResult.invalid()
|
return ResponseResult.invalid()
|
||||||
.setMessage("invalid templateId, maybe this template doesn't exist?");
|
.setMessage("无效的策略模板ID,也许该模板不存在?");
|
||||||
}
|
}
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setDataMap(EntityUtils.entityToMap(template));
|
.setDataMap(EntityUtils.entityToMap(template));
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class TaskController implements TaskControllerApi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@GetMapping("/{taskId}/running/{stateNum}")
|
@GetMapping("/{taskId}/running/{stateNum}")
|
||||||
public ResponseResult changeTaskStatus(@PathVariable @NotNull Integer stateNum,
|
public ResponseResult changeTaskStatus(@PathVariable @NotNull @Min(0) @Max(6) Integer stateNum,
|
||||||
@PathVariable @NotNull Long taskId) throws DorisStartException {
|
@PathVariable @NotNull Long taskId) throws DorisStartException {
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
.setData("task_id", taskId)
|
.setData("task_id", taskId)
|
||||||
|
|||||||
@@ -160,6 +160,6 @@ public interface TaskControllerApi {
|
|||||||
@Parameter(name = "stateNum", description = "任务状态编号任务状态(0为未启动,1为生成中,2为运行中,3为暂停中,4为已停止,5为已结束,6为失败)")
|
@Parameter(name = "stateNum", description = "任务状态编号任务状态(0为未启动,1为生成中,2为运行中,3为暂停中,4为已停止,5为已结束,6为失败)")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
ResponseResult changeTaskStatus(@PathVariable @NotNull Integer stateNum,
|
ResponseResult changeTaskStatus(@PathVariable @NotNull @Min(0) @Max(6) Integer stateNum,
|
||||||
@PathVariable @NotNull Long taskId) throws DorisStartException;
|
@PathVariable @NotNull Long taskId) throws DorisStartException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class TaskService {
|
|||||||
public Boolean changeTaskAuditStatus(Long taskId, Integer taskAuditStatus) {
|
public Boolean changeTaskAuditStatus(Long taskId, Integer taskAuditStatus) {
|
||||||
Integer originalAuditStatus = taskMapper.queryTaskAuditStatus(taskId);
|
Integer originalAuditStatus = taskMapper.queryTaskAuditStatus(taskId);
|
||||||
if (originalAuditStatus == null) {
|
if (originalAuditStatus == null) {
|
||||||
throw new IllegalArgumentException("cannot find audit status of task " + taskId + ", maybe task doesn't exist?");
|
throw new IllegalArgumentException("无法找到任务ID为" + taskId + "的任务,也许任务不存在?");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
|
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import com.realtime.protection.server.task.TaskService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class StateChangeService {
|
public class StateChangeService {
|
||||||
@@ -22,9 +24,14 @@ public class StateChangeService {
|
|||||||
|
|
||||||
@DSTransactional
|
@DSTransactional
|
||||||
public Boolean changeState(Integer stateNum, Long taskId) throws DorisStartException {
|
public Boolean changeState(Integer stateNum, Long taskId) throws DorisStartException {
|
||||||
|
if (Objects.equals(stateNum, StateEnum.GENERATING.getStateNum()) ||
|
||||||
|
Objects.equals(stateNum, StateEnum.FAILED.getStateNum())) {
|
||||||
|
throw new IllegalArgumentException("非法任务状态:" + StateEnum.getStateByNum(stateNum));
|
||||||
|
}
|
||||||
|
|
||||||
Integer originalStateNum = taskService.queryTaskStatus(taskId);
|
Integer originalStateNum = taskService.queryTaskStatus(taskId);
|
||||||
if (originalStateNum == null) {
|
if (originalStateNum == null) {
|
||||||
throw new IllegalArgumentException("cannot find status of task " + taskId + ", maybe task doesn't exist?");
|
throw new IllegalArgumentException("无法找到" + taskId + "的任务状态,也许任务ID不存在?");
|
||||||
}
|
}
|
||||||
|
|
||||||
State originalState = StateEnum.getStateByNum(originalStateNum);
|
State originalState = StateEnum.getStateByNum(originalStateNum);
|
||||||
@@ -39,7 +46,7 @@ public class StateChangeService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(String.format("successfully let task(%d) change state from %s to %s",
|
log.debug(String.format("成功使得task(%d)从%s切换为%s",
|
||||||
taskId,
|
taskId,
|
||||||
originalState.getClass().getSimpleName(),
|
originalState.getClass().getSimpleName(),
|
||||||
newState.getClass().getSimpleName()));
|
newState.getClass().getSimpleName()));
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ public class StateHandler {
|
|||||||
Task task = taskService.queryTask(taskId);
|
Task task = taskService.queryTask(taskId);
|
||||||
|
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
throw new IllegalArgumentException("invalid task id");
|
throw new IllegalArgumentException("无效task_id,因为无法找到对应任务");
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer taskAuditStatus = task.getTaskAuditStatus();
|
Integer taskAuditStatus = task.getTaskAuditStatus();
|
||||||
|
|
||||||
if (taskAuditStatus == null) {
|
if (taskAuditStatus == null) {
|
||||||
throw new IllegalArgumentException("invalid task id, because task_audit_status is null");
|
throw new IllegalArgumentException("无效的task_id,因为task_audit_status为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果审核状态不为已通过审核,则无效
|
// 如果审核状态不为已通过审核,则无效
|
||||||
@@ -74,7 +74,7 @@ public class StateHandler {
|
|||||||
// 如果未能获取staticTaskCommandInfos,需要报错
|
// 如果未能获取staticTaskCommandInfos,需要报错
|
||||||
List<TaskCommandInfo> staticTaskCommandInfos = taskService.getStaticCommandInfos(taskId);
|
List<TaskCommandInfo> staticTaskCommandInfos = taskService.getStaticCommandInfos(taskId);
|
||||||
if (staticTaskCommandInfos == null || staticTaskCommandInfos.isEmpty()) {
|
if (staticTaskCommandInfos == null || staticTaskCommandInfos.isEmpty()) {
|
||||||
throw new IllegalArgumentException("static rules are empty, need to choose at least one static rule");
|
throw new IllegalArgumentException("静态规则列表为空,请至少选择一个静态规则以启动任务");
|
||||||
}
|
}
|
||||||
|
|
||||||
commandService.createCommands(staticTaskCommandInfos);
|
commandService.createCommands(staticTaskCommandInfos);
|
||||||
|
|||||||
@@ -189,6 +189,4 @@ public interface WhiteListControllerApi {
|
|||||||
@PathVariable Integer auditStatus);
|
@PathVariable Integer auditStatus);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,3 +52,8 @@ springdoc:
|
|||||||
swagger-ui:
|
swagger-ui:
|
||||||
path: /swagger
|
path: /swagger
|
||||||
packages-to-scan: com.realtime.protection.server
|
packages-to-scan: com.realtime.protection.server
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoint:
|
||||||
|
shutdown:
|
||||||
|
enabled: true
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
dynamic_rule_create_depart, template_id, dynamic_rule_protect_level,
|
dynamic_rule_create_depart, template_id, dynamic_rule_protect_level,
|
||||||
dynamic_rule_priority, dynamic_rule_range,
|
dynamic_rule_priority, dynamic_rule_range,
|
||||||
dynamic_rule_frequency, dynamic_rule_create_user_id)
|
dynamic_rule_frequency, dynamic_rule_create_user_id)
|
||||||
values
|
values (#{object.dynamicRuleName},
|
||||||
(#{object.dynamicRuleName},
|
|
||||||
#{object.dynamicRuleCreateTime}, #{object.dynamicRuleModifyTime},
|
#{object.dynamicRuleCreateTime}, #{object.dynamicRuleModifyTime},
|
||||||
#{object.dynamicRuleCreateUsername}, #{object.dynamicRuleCreateDepart},
|
#{object.dynamicRuleCreateUsername}, #{object.dynamicRuleCreateDepart},
|
||||||
#{object.templateId}, #{object.dynamicRuleProtectLevel},
|
#{object.templateId}, #{object.dynamicRuleProtectLevel},
|
||||||
@@ -26,8 +25,7 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<insert id="newDynamicRulProtectObjectConcat">
|
<insert id="newDynamicRulProtectObjectConcat">
|
||||||
insert into
|
insert into t_protect_object_dynamic_rule_conn(dynamic_rule_id, protect_object_id)
|
||||||
t_protect_object_dynamic_rule_conn(dynamic_rule_id, protect_object_id)
|
|
||||||
values (#{dynamicRuleId}, #{protectObjectId})
|
values (#{dynamicRuleId}, #{protectObjectId})
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="newDynamicRules">
|
<insert id="newDynamicRules">
|
||||||
@@ -58,12 +56,14 @@
|
|||||||
<!-- # on t_dynamic_rule.dynamic_rule_id = t_protect_object_dynamic_rule_conn.dynamic_rule_id-->
|
<!-- # on t_dynamic_rule.dynamic_rule_id = t_protect_object_dynamic_rule_conn.dynamic_rule_id-->
|
||||||
<!-- # where t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}-->
|
<!-- # where t_dynamic_rule.dynamic_rule_id = #{dynamicRuleId}-->
|
||||||
<delete id="deleteDynamicRuleObject">
|
<delete id="deleteDynamicRuleObject">
|
||||||
delete from t_dynamic_rule
|
delete
|
||||||
|
from t_dynamic_rule
|
||||||
where dynamic_rule_id = #{dynamicRuleId}
|
where dynamic_rule_id = #{dynamicRuleId}
|
||||||
</delete>
|
</delete>
|
||||||
<!-- 用于update时删去之前的关联-->
|
<!-- 用于update时删去之前的关联-->
|
||||||
<delete id="deleteDynamicRuleProtectObjectConcat">
|
<delete id="deleteDynamicRuleProtectObjectConcat">
|
||||||
delete from t_protect_object_dynamic_rule_conn
|
delete
|
||||||
|
from t_protect_object_dynamic_rule_conn
|
||||||
where dynamic_rule_id = #{dynamicRuleId}
|
where dynamic_rule_id = #{dynamicRuleId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
@@ -82,7 +82,9 @@
|
|||||||
<if test="object.dynamicRuleName != null">dynamic_rule_name = #{object.dynamicRuleName},</if>
|
<if test="object.dynamicRuleName != null">dynamic_rule_name = #{object.dynamicRuleName},</if>
|
||||||
<if test="object.dynamicRuleModifyTime != null">modify_time = #{object.dynamicRuleModifyTime},</if>
|
<if test="object.dynamicRuleModifyTime != null">modify_time = #{object.dynamicRuleModifyTime},</if>
|
||||||
<if test="object.templateId != null">template_id = #{object.templateId},</if>
|
<if test="object.templateId != null">template_id = #{object.templateId},</if>
|
||||||
<if test="object.dynamicRuleProtectLevel != null"> dynamic_rule_protect_level = #{object.dynamicRuleProtectLevel},</if>
|
<if test="object.dynamicRuleProtectLevel != null">dynamic_rule_protect_level =
|
||||||
|
#{object.dynamicRuleProtectLevel},
|
||||||
|
</if>
|
||||||
<if test="object.dynamicRulePriority != null">dynamic_rule_priority = #{object.dynamicRulePriority},</if>
|
<if test="object.dynamicRulePriority != null">dynamic_rule_priority = #{object.dynamicRulePriority},</if>
|
||||||
<if test="object.dynamicRuleRange != null">dynamic_rule_range = #{object.dynamicRuleRange},</if>
|
<if test="object.dynamicRuleRange != null">dynamic_rule_range = #{object.dynamicRuleRange},</if>
|
||||||
<if test="object.dynamicRuleFrequency != null">dynamic_rule_frequency = #{object.dynamicRuleFrequency}</if>
|
<if test="object.dynamicRuleFrequency != null">dynamic_rule_frequency = #{object.dynamicRuleFrequency}</if>
|
||||||
@@ -91,7 +93,8 @@
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
<resultMap id="dynamicRuleMap" type="com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject">
|
<resultMap id="dynamicRuleMap"
|
||||||
|
type="com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject">
|
||||||
<id column="dynamic_rule_id" property="dynamicRuleId"/>
|
<id column="dynamic_rule_id" property="dynamicRuleId"/>
|
||||||
<result column="dynamic_rule_name" property="dynamicRuleName"/>
|
<result column="dynamic_rule_name" property="dynamicRuleName"/>
|
||||||
<result column="create_time" property="dynamicRuleCreateTime"/>
|
<result column="create_time" property="dynamicRuleCreateTime"/>
|
||||||
|
|||||||
@@ -121,11 +121,13 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="queryStaticRuleById" resultMap="staticRuleMap">
|
<select id="queryStaticRuleById" resultMap="staticRuleMap">
|
||||||
SELECT * FROM t_static_rule
|
SELECT *
|
||||||
|
FROM t_static_rule
|
||||||
WHERE static_rule_id = #{static_rule_id}
|
WHERE static_rule_id = #{static_rule_id}
|
||||||
</select>
|
</select>
|
||||||
<select id="queryAuditStatusById" resultType="java.lang.Integer">
|
<select id="queryAuditStatusById" resultType="java.lang.Integer">
|
||||||
SELECT static_rule_audit_status FROM t_static_rule
|
SELECT static_rule_audit_status
|
||||||
|
FROM t_static_rule
|
||||||
WHERE static_rule_id = #{id}
|
WHERE static_rule_id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class DynamicRuleServiceTest {
|
public class DynamicRuleServiceTest {
|
||||||
private final DynamicRuleService dynamicRuleService;
|
private final DynamicRuleService dynamicRuleService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DynamicRuleServiceTest(DynamicRuleService dynamicRuleService) {
|
public DynamicRuleServiceTest(DynamicRuleService dynamicRuleService) {
|
||||||
this.dynamicRuleService = dynamicRuleService;
|
this.dynamicRuleService = dynamicRuleService;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
public class StaticRuleServiceTest {
|
public class StaticRuleServiceTest {
|
||||||
private final StaticRuleService staticRuleService;
|
private final StaticRuleService staticRuleService;
|
||||||
private StaticRuleObject staticRuleTest;
|
private StaticRuleObject staticRuleTest;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public StaticRuleServiceTest(StaticRuleService staticRuleService) {
|
public StaticRuleServiceTest(StaticRuleService staticRuleService) {
|
||||||
this.staticRuleService = staticRuleService;
|
this.staticRuleService = staticRuleService;
|
||||||
@@ -63,6 +64,7 @@ public class StaticRuleServiceTest {
|
|||||||
}
|
}
|
||||||
//assertTrue(id>0);
|
//assertTrue(id>0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNewStaticRules() {
|
void testNewStaticRules() {
|
||||||
List<StaticRuleObject> staticRuleObjects = new ArrayList<>();
|
List<StaticRuleObject> staticRuleObjects = new ArrayList<>();
|
||||||
@@ -83,6 +85,7 @@ public class StaticRuleServiceTest {
|
|||||||
staticRuleService.deleteStaticRules(list);
|
staticRuleService.deleteStaticRules(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testUpdateStaticRule() {
|
void testUpdateStaticRule() {
|
||||||
|
|
||||||
@@ -104,6 +107,7 @@ public class StaticRuleServiceTest {
|
|||||||
|
|
||||||
staticRuleService.updateStaticRule(5, object);
|
staticRuleService.updateStaticRule(5, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testQueryStaticRule() {
|
void testQueryStaticRule() {
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,10 @@ class TaskServiceTest {
|
|||||||
LocalDateTime taskEndTime = LocalDateTime.now().plusDays(i + 10);
|
LocalDateTime taskEndTime = LocalDateTime.now().plusDays(i + 10);
|
||||||
task.setTaskStartTime(taskStartTime);
|
task.setTaskStartTime(taskStartTime);
|
||||||
task.setTaskEndTime(taskEndTime);
|
task.setTaskEndTime(taskEndTime);
|
||||||
assertDoesNotThrow(() -> {Long taskId = taskService.newTask(task); assertTrue(taskId > 0);});
|
assertDoesNotThrow(() -> {
|
||||||
|
Long taskId = taskService.newTask(task);
|
||||||
|
assertTrue(taskId > 0);
|
||||||
|
});
|
||||||
assertTrue(task.getTaskId() > 0);
|
assertTrue(task.getTaskId() > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class WhiteListServiceTest {
|
class WhiteListServiceTest {
|
||||||
|
|
||||||
private final WhiteListService whiteListService;
|
private final WhiteListService whiteListService;
|
||||||
private WhiteListObject whiteListObject;
|
private WhiteListObject whiteListObject;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WhiteListServiceTest(WhiteListService whiteListService) {
|
WhiteListServiceTest(WhiteListService whiteListService) {
|
||||||
this.whiteListService = whiteListService;
|
this.whiteListService = whiteListService;
|
||||||
|
|||||||
Reference in New Issue
Block a user