提交 eab4359c authored 作者: ww1xhqc's avatar ww1xhqc

model layer类型和字段主键问题

上级 f2530727
......@@ -23,6 +23,10 @@ public class ColumnInfo {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
//0是,1否
@Column(name = "primary_key")
private Integer primarykey;
@Column(name = "name")
private String name;
@Column(name = "cn_name")
......
package com.tykj.workflowcore.model_layer.model;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import lombok.Data;
/**
......@@ -19,5 +19,6 @@ public class ColumnVO {
private String fieldName;
private String filedDescription;
private int filedLength;
private Integer primarykey=1;
}
package com.tykj.workflowcore.model_layer.service.impl;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -32,6 +33,7 @@ import javax.persistence.Entity;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;
import javax.persistence.criteria.*;
import java.lang.reflect.Field;
......@@ -245,15 +247,16 @@ public class ModelImpl implements ModelService {
@Override
public void swaggerScan(List<Class<?>> classList) {
for (Class<?> aClass : classList) {
//不扫描自己
if (!aClass.isAnnotationPresent(WorkFlowCoreNoScan.class)) {
if (aClass.isAnnotationPresent(Entity.class)) {
TableInfo tableInfo = new TableInfo();
// tableInfo.setId(id);
TableVO tableVO = new TableVO();
String className = getClassName(aClass.toString());
//入表真实名称
String realName=className.toLowerCase() + "_model_test";
tableVO.setModelName(realName);
//获得类中文描述
if (aClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = aClass.getAnnotation(ApiModel.class);
StringBuilder APiModelDocument = new StringBuilder();
......@@ -269,17 +272,22 @@ public class ModelImpl implements ModelService {
} else {
tableVO.setModelTitle("");
}
//获得类所有属性
Field[] declaredFields = aClass.getDeclaredFields();
java.lang.reflect.Type genericType = null;
List<ColumnVO> list = new ArrayList<>();
for (Field declaredField : declaredFields) {
ColumnVO columnVO = new ColumnVO();
//获得类型
genericType = declaredField.getGenericType();
//是否主键
if (declaredField.isAnnotationPresent(javax.persistence.Id.class)){
columnVO.setPrimarykey(0);
}
columnVO.setFiledType(genericType.toString());
columnVO.setFieldName(getClassName(declaredField.toString()));
//获得属性中文描述
if (declaredField.isAnnotationPresent(ApiModelProperty.class)) {
ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
StringBuilder ApiModelPropertyDocument = new StringBuilder();
......@@ -302,7 +310,7 @@ public class ModelImpl implements ModelService {
tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXML(xml);
tableInfo.setType(0);
//判断是否存在
if (checkRepeat(realName)){
tableInfo = tableInfoDao.save(tableInfo);
List<ColumnVO> dataList = tableVO.getDataList();
......@@ -312,6 +320,7 @@ public class ModelImpl implements ModelService {
columnInfo.setType(columnVO.getFiledType());
columnInfo.setLength(columnVO.getFiledLength());
columnInfo.setCnName(columnVO.getFiledDescription());
columnInfo.setPrimarykey(columnVO.getPrimarykey());
if (genericType.toString().equals("class java.lang.String")) {
columnInfo.setLength(255);
......
......@@ -81,7 +81,6 @@ public class CreatTableUtil {
public static String getClassName(String aClass){
int i = aClass.lastIndexOf(".");
String substring = aClass.substring(i+1);
return substring;
......
package com.tykj.workflowcore.model_layer.utils;
import com.tykj.workflowcore.model_layer.model.QueryCondition;
import java.util.List;
import java.util.Objects;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论