1. 新增AuditStatusValidator类,用以作为审核状态机
2. 新建DataListener,用以读取excel文件 3. 完成防护对象配置所有接口 4. 添加SqlSessionWrapper类用以进行批处理 5. ProtectObject类添加更多校验(IP、大小等)
This commit is contained in:
@@ -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