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

model layer类型和字段主键问题

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