Commit 921b3994 by s_guodong

去掉needInit,增加渠道缓存,增加参数校验方法

parent 65c8cebc
......@@ -80,6 +80,10 @@
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.brilliance</groupId>
<artifactId>jrxx-bean</artifactId>
<version>0.0.1</version>
......
package com.ceb.gjjs.mda.resource.base;
import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess;
import com.brilliance.mda.runtime.request.BaseVO;
import com.brilliance.mda.runtime.response.ResponseSet;
import com.brilliance.mda.support.service.ICommonService;
......@@ -22,7 +21,6 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
@Path("/init")
@POST
public ResponseSet<V> init(@RequestBody V req) {
req.setNeedInit(true);
return getCommonService().init(req);
}
......@@ -55,7 +53,6 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
@POST
public ResponseSet<V> executeCheck(@PathParam("rule") String rule, @RequestBody V req) {
String[] ruleArr = rule.split(",");
setInitFlag(req, ModuleAnnotationProcess.needInitCheck, ruleArr);
return getCommonService().executeCheck(req, ruleArr);
}
......@@ -63,7 +60,6 @@ public abstract class AbstractCommonResource<V extends BaseVO> {
@POST
public ResponseSet<V> executeRule(@PathParam("rule") String rule, @RequestBody V req) {
String[] ruleArr = rule.split(",");
setInitFlag(req, ModuleAnnotationProcess.needInitRule, ruleArr);
ResponseSet<V> res = getCommonService().executeRule(req, ruleArr);
return res;
}
......
package com.ceb.gjjs.mda.util;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.lang.reflect.Field;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/8
*/
public class ValidatorUtil {
public static String check(Object obj) {
Class<?> aClass = obj.getClass();
Field[] fields = aClass.getDeclaredFields();
for (Field f : fields) {
f.setAccessible(true);
Class<?> type = f.getType();
Object o = null;
try {
o = f.get(obj);
} catch (IllegalAccessException e) {
}
if (f.isAnnotationPresent(Length.class) && type.isAssignableFrom(String.class)) {
Length length = f.getAnnotation(Length.class);
int min = length.min();
int max = length.max();
String message = length.message();
if (o != null) {
String stringValue = (String) o;
if (stringValue.length() > max || stringValue.length() < min) {
return f.getName() + ":" + message;
}
}
}
if (f.isAnnotationPresent(NotEmpty.class) && type.isAssignableFrom(String.class)) {
if (o == null || StringUtils.isBlank((String) o)) {
return f.getName() + ":不能为空";
}
}
if (f.isAnnotationPresent(NotNull.class) && !type.isAssignableFrom(String.class)) {
if (o == null) {
return f.getName() + ":不能为null";
}
}
}
return "";
}
}
......@@ -332,11 +332,11 @@ public abstract class AbstractRouteService<V extends BaseVO> {
if (req != null) {
ctx.setVo(req);
}
if (!req.isNeedInit()) {
logger.info("不需要初始化");
return;
}
logger.info("开始初始化...");
// if (!req.isNeedInit()) {
// logger.info("不需要初始化");
// return;
// }
// logger.info("开始初始化...");
StopWatch watch = new StopWatch("initTrans");
IRuleEmitter emitter = getEmitter();
//将认证信息(usr、usg、ety)放入sysStream
......@@ -461,12 +461,14 @@ public abstract class AbstractRouteService<V extends BaseVO> {
public boolean enterTransaction(V req) {
if (req != null) {
IContext ctx = MdaEnv.getContext();
String src = req.getSrc();
ctx.storeData(IContext.APP_KEY, src);
Map<String, Object> params = req.getParams();
chain(params);
initTrans(req);
IContext ctx = MdaEnv.getContext();
String src = req.getSrc();
if (!StringUtils.isBlank(src)) {
ctx.storeData(IContext.APP_KEY, src);
}
ctx.storeData(IContext.DISPLAY_KEY, req);
}
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment