1. 新增AuditStatusValidator类,用以作为审核状态机
2. 新建DataListener,用以读取excel文件 3. 完成防护对象配置所有接口 4. 添加SqlSessionWrapper类用以进行批处理 5. ProtectObject类添加更多校验(IP、大小等)
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package com.realtime.protection.configuration.entity.defense.object;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -17,10 +20,13 @@ public class ProtectObject {
|
||||
private String protectObjectSystemName;
|
||||
|
||||
@JsonProperty("proobj_ip_address")
|
||||
@Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "Invalid IPv4 Address")
|
||||
private String protectObjectIPAddress;
|
||||
|
||||
@JsonProperty("proobj_port")
|
||||
@NotNull(message = "proobj_port should not be empty.")
|
||||
@Max(value = 65535, message = "port should not be more than 65535")
|
||||
@Min(value = 1, message = "port should not be less than 1")
|
||||
private Integer protectObjectPort;
|
||||
|
||||
@JsonProperty("proobj_url")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.realtime.protection.configuration.entity.task;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.Future;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -13,15 +14,16 @@ public class Task {
|
||||
private Integer taskId;
|
||||
|
||||
@JsonProperty("task_name")
|
||||
@NotNull(message = "task_name should not be empty.")
|
||||
@NotNull(message = "task_name should not be empty. ")
|
||||
private String taskName;
|
||||
|
||||
@JsonProperty("task_start_time")
|
||||
@NotNull(message = "task_start_time should not be empty.")
|
||||
@NotNull(message = "task_start_time should not be empty. ")
|
||||
private LocalDateTime taskStartTime;
|
||||
|
||||
@JsonProperty("task_end_time")
|
||||
@NotNull(message = "task_end_time should not be empty.")
|
||||
@NotNull(message = "task_end_time should not be empty. ")
|
||||
@Future(message = "task_end_time should be a future time. ")
|
||||
private LocalDateTime taskEndTime;
|
||||
|
||||
@JsonProperty("task_create_time")
|
||||
@@ -31,11 +33,11 @@ public class Task {
|
||||
private LocalDateTime taskModifyTime;
|
||||
|
||||
@JsonProperty("task_type")
|
||||
@NotNull(message = "task_type should not be empty.")
|
||||
@NotNull(message = "task_type should not be empty. ")
|
||||
private String taskType;
|
||||
|
||||
@JsonProperty("task_act")
|
||||
@NotNull(message = "task_act should not be empty.")
|
||||
@NotNull(message = "task_act should not be empty. ")
|
||||
private String taskAct;
|
||||
|
||||
@JsonProperty("task_create_username")
|
||||
|
||||
@@ -48,7 +48,7 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
@Order(2)
|
||||
@ExceptionHandler(value = HandlerMethodValidationException.class)
|
||||
@ExceptionHandler(value = {HandlerMethodValidationException.class, IllegalArgumentException.class})
|
||||
public ResponseResult handleHandlerMethodValidationException(HandlerMethodValidationException e) {
|
||||
return ResponseResult.invalid().setMessage(e.getMessage());
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ResponseResult implements Serializable {
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
private LinkedHashMap<String, Object> data;
|
||||
private Map<String, Object> data;
|
||||
|
||||
public ResponseResult(int code, String message, LinkedHashMap<String, Object> data) {
|
||||
this.code = code;
|
||||
@@ -45,6 +46,10 @@ public class ResponseResult implements Serializable {
|
||||
return new ResponseResult(400, "invalid request");
|
||||
}
|
||||
|
||||
public static ResponseResult invalid(String message) {
|
||||
return new ResponseResult(400, message);
|
||||
}
|
||||
|
||||
public static ResponseResult unAuthorized() {
|
||||
return new ResponseResult(401, "UnAuthorized User");
|
||||
}
|
||||
@@ -68,7 +73,7 @@ public class ResponseResult implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponseResult setDataMap(LinkedHashMap<String, Object> data) {
|
||||
public ResponseResult setDataMap(Map<String, Object> data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.realtime.protection.configuration.utils;
|
||||
|
||||
public class AuditStatusValidator {
|
||||
|
||||
private final Integer auditStatusOriginal;
|
||||
|
||||
public AuditStatusValidator(Integer auditStatusOriginal) {
|
||||
this.auditStatusOriginal = auditStatusOriginal;
|
||||
}
|
||||
|
||||
public static AuditStatusValidator setOriginal(Integer auditStatusOriginal) {
|
||||
return new AuditStatusValidator(auditStatusOriginal);
|
||||
}
|
||||
|
||||
public Boolean checkValidate(Integer auditStatusNow) {
|
||||
switch (auditStatusNow) {
|
||||
case 0, 1 -> {return auditStatusOriginal != 2;}
|
||||
case 2 -> {return auditStatusOriginal != 1;}
|
||||
default -> {return false;}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.realtime.protection.configuration.utils;
|
||||
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Component
|
||||
public class SqlSessionWrapper {
|
||||
|
||||
private final SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public SqlSessionWrapper(SqlSessionFactory sqlSessionFactory) {
|
||||
this.sqlSessionFactory = sqlSessionFactory;
|
||||
}
|
||||
|
||||
public <M, I, O> O startBatchSession(Class<M> mapperClass,
|
||||
Function<M, Function<I, O>> wrappedFunction,
|
||||
I arguments) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
M mapper = sqlSession.getMapper(mapperClass);
|
||||
try {
|
||||
O result = wrappedFunction.apply(mapper).apply(arguments);
|
||||
sqlSession.commit();
|
||||
sqlSession.clearCache();
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
sqlSession.rollback();
|
||||
throw e;
|
||||
} finally {
|
||||
sqlSession.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user