feat: 增加db引用注解
This commit is contained in:
parent
b5b8611b6c
commit
69d4c62f35
@ -1,7 +1,7 @@
|
|||||||
package com.flyfish.framework.beans.meta;
|
package com.flyfish.framework.beans.meta;
|
||||||
|
|
||||||
import com.flyfish.framework.annotations.*;
|
|
||||||
import com.flyfish.framework.annotations.Properties;
|
import com.flyfish.framework.annotations.Properties;
|
||||||
|
import com.flyfish.framework.annotations.*;
|
||||||
import com.flyfish.framework.domain.base.Qo;
|
import com.flyfish.framework.domain.base.Qo;
|
||||||
import com.flyfish.framework.domain.base.Vo;
|
import com.flyfish.framework.domain.base.Vo;
|
||||||
import com.flyfish.framework.utils.DataUtils;
|
import com.flyfish.framework.utils.DataUtils;
|
||||||
@ -13,6 +13,7 @@ import org.apache.commons.lang3.ClassUtils;
|
|||||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
@ -106,11 +107,11 @@ public class BeanProperty {
|
|||||||
property.prop("code", name);
|
property.prop("code", name);
|
||||||
} else if (field.isAnnotationPresent(DBRefValue.class)) {
|
} else if (field.isAnnotationPresent(DBRefValue.class)) {
|
||||||
// 添加了数据库引用注解,自动注入类型给前端使用
|
// 添加了数据库引用注解,自动注入类型给前端使用
|
||||||
property.setType(BeanPropertyType.DB_REF);
|
|
||||||
DBRefValue dbRefValue = field.getAnnotation(DBRefValue.class);
|
DBRefValue dbRefValue = field.getAnnotation(DBRefValue.class);
|
||||||
Document document = AnnotationUtils.findAnnotation(dbRefValue.value(), Document.class);
|
Optional<String> optional = processDbRef(dbRefValue.value());
|
||||||
if (null != document) {
|
if (optional.isPresent()) {
|
||||||
property.prop("uri", document.collection());
|
property.setType(BeanPropertyType.DB_REF);
|
||||||
|
property.prop("uri", optional.get());
|
||||||
} else {
|
} else {
|
||||||
property.setType(BeanPropertyType.STRING);
|
property.setType(BeanPropertyType.STRING);
|
||||||
}
|
}
|
||||||
@ -131,9 +132,9 @@ public class BeanProperty {
|
|||||||
break;
|
break;
|
||||||
case DB_REF:
|
case DB_REF:
|
||||||
// 当存在db-ref时,解析为动态数据源
|
// 当存在db-ref时,解析为动态数据源
|
||||||
Document document = AnnotationUtils.findAnnotation(clazz, Document.class);
|
Optional<String> optional = processDbRef(clazz);
|
||||||
if (null != document) {
|
if (optional.isPresent()) {
|
||||||
property.prop("uri", document.collection());
|
property.prop("uri", optional.get());
|
||||||
} else {
|
} else {
|
||||||
property.setType(BeanPropertyType.STRING);
|
property.setType(BeanPropertyType.STRING);
|
||||||
}
|
}
|
||||||
@ -162,6 +163,17 @@ public class BeanProperty {
|
|||||||
return ListUtils.union(parseExtras(clazz), properties);
|
return ListUtils.union(parseExtras(clazz), properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析db引用的参数
|
||||||
|
*
|
||||||
|
* @param clazz 类
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
private static Optional<String> processDbRef(Class<?> clazz) {
|
||||||
|
return Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(clazz, Document.class))
|
||||||
|
.map(Document::value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析额外的注解
|
* 解析额外的注解
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user