Commit dbf34e6e by s_guodong

update

parent b15e4155
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/10
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoListVo implements Serializable {
@JsonIgnore
private static final long serialVersionUID = 1L;
@Length(max = 20, message = "最大长度为20")
@RelPath("cur")
private String aa;
@Need
@RelPath("act")
private String bb;
}
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
import java.util.List;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/10
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoVo implements Serializable {
@JsonIgnore
private static final long serialVersionUID = 1L;
@Length(max = 2, message = "最大长度为20")
@RelPath("acdgrp_rec_account") // 映射到对应交易vo的字段
private String a;
@Length(max = 2, message = "最大长度为2")
@Need
private String b;
@RelPath("src")
private String src;
@RelPath("dataList")
@Need
private List<DemoListVo> list;
@RelPath("acd")
@Need
private DemoVo_2 demoVo_2;
@RelPath("addrs")
@Need
private List<String> addrList;
}
package com.ceb.gjjs.mda.special.vo;
import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/10
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DemoVo_2 implements Serializable {
@JsonIgnore
private static final long serialVersionUID = 1L;
@Length(max = 20, message = "最大长度为20")
@RelPath("entname")
private String name;
@Length(max = 2, message = "最大长度为2")
@RelPath("inr")
private String addr;
}
package com.ceb.gjjs.mda.util;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.brilliance.mda.runtime.mda.impl.ModuleList;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* @Description
* @Author s_guodong
* @Date 2023/8/8
*/
public class ReflectUtil {
private static Logger log = LoggerFactory.getLogger(ReflectUtil.class);
public static String setObjValue(Object specialVoValue, Class specialVoClass, Object req, Class reqClass) {
Field[] declaredFields = specialVoClass.getDeclaredFields();
for (Field f : declaredFields) {
f.setAccessible(true);
if (f.isAnnotationPresent(RelPath.class)) {
RelPath annotation = f.getAnnotation(RelPath.class);
String path = annotation.value();
try {
Object o = f.get(specialVoValue);
Field declaredField = reqClass.getDeclaredField(path);
declaredField.setAccessible(true);
Class<?> type = declaredField.getType();
// 基本数据类型
if (isPrimate(type)) {
declaredField.set(req, o);
}
// ModuleList类型
else if ("com.brilliance.mda.runtime.mda.impl.ModuleList".equals(type.getName())) {
// moduleList中的泛型
Class moduleT = getTType(declaredField);
// list中的泛型
Class listT = getTType(f);
List list = (List) o;
ModuleList moduleList = new ModuleList();
for (Object data : list) {
Object dataObj = moduleT.newInstance();
String s = setObjValue(data, listT, dataObj, moduleT);
if (!StringUtils.isBlank(s)) {
return s;
}
moduleList.add(dataObj);
}
declaredField.set(req, moduleList);
} else if ("java.util.List".equals(type.getName())) {
// list数据类型
declaredField.set(req, o);
} else {
// 对象类型
Object typeO = type.newInstance();
String s = setObjValue(o, f.getType(), typeO, type);
if (!StringUtils.isBlank(s)) {
return s;
}
declaredField.set(req, typeO);
}
} catch (Exception e) {
Class<?> superclass = reqClass.getSuperclass();
try {
Field superclassDeclaredField = superclass.getDeclaredField(path);
superclassDeclaredField.setAccessible(true);
superclassDeclaredField.set(req, f.get(specialVoValue));
} catch (Exception ex) {
String errMsg = specialVoClass.getName() + "中字段" + f.getName() + "反射错误";
log.error(errMsg);
return errMsg;
}
}
}
}
return "";
}
/**
* 获取List的泛型
*
* @param f
* @return
*/
public static Class getTType(Field f) {
Type genericType = f.getGenericType();
if (genericType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) genericType;
//得到泛型里的class类型对象
Class<?> genericClazz = (Class<?>) pt.getActualTypeArguments()[0];
return genericClazz;
}
return null;
}
/**
* 是否是基本类型
*
* @param aclass
* @return
*/
public static boolean isPrimate(Class aclass) {
return aclass.isAssignableFrom(String.class)
|| aclass.isAssignableFrom(BigDecimal.class)
|| aclass.isAssignableFrom(Date.class)
|| aclass.isPrimitive();
}
}
......@@ -7,6 +7,7 @@ import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.lang.reflect.Field;
import java.util.List;
/**
* @Description
......@@ -14,6 +15,7 @@ import java.lang.reflect.Field;
* @Date 2023/8/8
*/
public class ValidatorUtil {
public static String check(Object obj) {
Class<?> aClass = obj.getClass();
Field[] fields = aClass.getDeclaredFields();
......@@ -54,8 +56,33 @@ public class ValidatorUtil {
if (type.isAssignableFrom(String.class) && StringUtils.isBlank((String) o)) {
return "参数校验错误[" + f.getName() + ":为必需参数,不能为空]";
}
if (ReflectUtil.isPrimate(type)) {
} else if ("java.util.List".equals(type.getName())) {
List list = (List) o;
if (list.size() == 0) {
return "参数校验错误[" + f.getName() + ":元素个数不能为0]";
}
// 获取list的泛型
Class tType = ReflectUtil.getTType(f);
if (!ReflectUtil.isPrimate(tType)) {
for (Object data : list) {
String s = check(data);
if (!StringUtils.isBlank(s)) {
return s;
}
}
}
} else {
String s = check(o);
if (!StringUtils.isBlank(s)) {
return s;
}
}
}
}
return "";
}
}
......@@ -17,7 +17,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
@JsonFilter("fieldFilter")
//@JsonFilter("fieldFilter")
@Module
public abstract class AbstractModule implements IModule, IModuleRoot {
......
......@@ -7,7 +7,7 @@ public class BaseVO {
protected String src;
protected String pageId;
protected Map<String, Object> params;
protected Map<String, Object> special_vo;
protected Map<String, Object> root;
protected List<Map<String, Object>> changes;
......@@ -64,11 +64,11 @@ public class BaseVO {
this.src = src;
}
public Map<String, Object> getSpecial_vo() {
return special_vo;
public Map<String, Object> getRoot() {
return root;
}
public void setSpecial_vo(Map<String, Object> special_vo) {
this.special_vo = special_vo;
public void setRoot(Map<String, Object> root) {
this.root = root;
}
}
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