#1971 建表clear,BO字段调整

parent 5cc73854
Pipeline #4710 canceled with stages
......@@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
......@@ -32,6 +33,7 @@ import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@Component
public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> implements JavaModelBeanLoader {
@Autowired
......@@ -97,9 +99,20 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
model.setIncludeAuditFields(true);
model.setIncludeVersionField(true);
model.setIncludeDomainField(true);
initField(clazz, model, consumer);
//todo 补充子类和拓展字段
//字段名去重
Set<String> fieldNames = new HashSet<>();
//是否没有大文本字段,当一个表有多个大文本字段,只需要建一次表,将多个大文本字段的值放在一张表中
Boolean isFirstText = true;
//根据字段建表
isFirstText = initField(clazz, model, fieldNames,isFirstText, consumer);
//补充子类
for (Class childClazz:beanDefinition.getChildrenBo()) {
isFirstText = initField(childClazz, model, fieldNames,isFirstText, consumer);
}
//补充拓展字段
for (Class expandoClazz:beanDefinition.getExpando()) {
isFirstText = initField(expandoClazz, model, fieldNames,isFirstText, consumer);
}
consumer.accept(model);
}
}
......@@ -110,12 +123,17 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
* @param model model
* @param consumer
*/
private void initField(Class<?> clazz, Model model, Consumer<IQuery> consumer) {
Field[] fields = clazz.getDeclaredFields();
//当一个表有多个大文本字段,只需要建一次表,将多个大文本字段的值放在一张表中
boolean isFirstText = true;
private Boolean initField(Class<?> clazz, Model model,Set<String> fieldNames,Boolean isFirstText, Consumer<IQuery> consumer) {
List<Field> fieldList = new ArrayList<>();
while (clazz != null){
fieldList.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass();
}
//遍历所有字段
for (Field f : fields) {
for (Field f : fieldList) {
//如果已经加过此字段,则跳过
if (!fieldNames.add(f.getName()))
continue;
if (f.getAnnotation(Column.class) != null) {
//带有Column注解的字段
FieldParser parser = FieldParserUtil.getParser(f);
......@@ -145,6 +163,7 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
newManyModel(model, f, consumer);
}
}
return isFirstText;
}
......@@ -310,7 +329,7 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
Class<?> childClazz = classLoader.loadClass(e.getBeanClassName());
boModel_relation.entrySet()
.stream()
.filter(f->childClazz.isAssignableFrom(f.getKey()))
.filter(f->childClazz.isAssignableFrom(f.getKey())||f.getKey().isAssignableFrom(childClazz))
.forEach(f->f.getValue().addChildBo(childClazz));
} catch (ClassNotFoundException classNotFoundException) {
}
......@@ -325,7 +344,7 @@ public class BoModelBeanLoader extends BeanLoader<IQuery, TenantProject> impleme
if (type instanceof ParameterizedType){
ParameterizedType paramterizedType = (ParameterizedType) type;
//找到BizExpando接口
if (paramterizedType.getRawType().equals("logwire.core.bo.field.BizExpando")){
if (paramterizedType.getRawType()==BizExpando.class){
//找到泛型
Class clazz = (Class)paramterizedType.getActualTypeArguments()[0];
//通过泛型去找对应的boRelation
......
......@@ -68,11 +68,11 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
*/
@Override
public void load(TenantProject project, TenantProject input, Consumer<BoRelationDefinition> consumer) throws Exception {
Map<String, BoRelationDefinition> boRelationBeanDefinitions = loadBeanDefinition(project);
/*Map<String, BoRelationDefinition> boRelationBeanDefinitions = loadBeanDefinition(project, input);
boRelationBeanDefinitions.values().forEach(boRelationDefinition -> {
initializeService(boRelationDefinition, boRelationBeanDefinitions);
consumer.accept(boRelationDefinition);
});
});*/
}
/**
......@@ -107,7 +107,9 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
* @return
* @throws Exception
*/
private Map<String, BoRelationDefinition> loadBeanDefinition(TenantProject project) throws Exception {
private Map<String, BoRelationDefinition> loadBeanDefinition(TenantProject project, TenantProject input) throws Exception {
input.getBeansOfType(BizObject.class);
//加载bo类
Map<String, BoRelationDefinition> boRelationBeanDefinitions = Maps.newHashMap();
TenantClassLoader classLoader = project.getTenantBeanContext().getTenantClassLoader();
ClassPathScanningCandidateComponentProvider provider = loaderUtil.getScanningBeanProvider();
......@@ -159,11 +161,14 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
}
private void registerBeanDefinition(Map<String, BoRelationDefinition> boRelationBeanDefinitions, Map<String, List<Class<?>>> beanClassMap) {
//如果没有使用bo,则不会报错
if(beanClassMap.get(BIZ_OBJECT)!=null) {
beanClassMap.get(BIZ_OBJECT).forEach(clazz -> {
BoRelationDefinition boRelationDefinition = doRegisterBeanDefinition((Class<? extends BizObject>) clazz);
boRelationBeanDefinitions.put(boRelationDefinition.getId(), boRelationDefinition);
});
}
}
private void addOperationProvider(Map<String, BoRelationDefinition> boRelationBeanDefinitions, Map<String, List<Class<?>>> beanClassMap) {
beanClassMap.get(TYPE_OPERATION_PROVIDER).forEach(clazz -> {
......@@ -262,7 +267,10 @@ public class BoRelationBeanDefinitionLoader extends BeanLoader<BoRelationDefinit
return boRelationDefinition;
}
/**
* 扫描bo相关类
* @param provider
*/
private void addIncludeFilters(ClassPathScanningCandidateComponentProvider provider) {
provider.addIncludeFilter(loaderUtil.getAbstractTypeFilter(BizObject.class));
provider.addIncludeFilter(new AssignableTypeFilter(OperationHandler.class));
......
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