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

[数据模型] 修复扫描时多出id字段bug

上级 9b13f021
......@@ -2,6 +2,7 @@ package com.tykj.workflowcore.model_layer.service.impl;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.google.common.base.Strings;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import com.tykj.workflowcore.model_layer.dao.ColumnInfoDao;
......@@ -104,13 +105,13 @@ public class ModelImpl implements ModelService {
return tableInfoDao.findAll(and.build());
}
private PredicateBuilder<TableInfo> createPredicateBySearchTableInfoVo(SearchTableInfoVo searchTableInfoVo){
private PredicateBuilder<TableInfo> createPredicateBySearchTableInfoVo(SearchTableInfoVo searchTableInfoVo) {
PredicateBuilder<TableInfo> and = Specifications.and();
if (searchTableInfoVo!=null){
if (searchTableInfoVo != null) {
and.like(searchTableInfoVo.getModelName() != null && StringUtils.isNotEmpty(searchTableInfoVo.getModelName()), "modelName", "%" + searchTableInfoVo.getModelName() + "%");
and.like(searchTableInfoVo.getModelTitle() != null && StringUtils.isNotEmpty(searchTableInfoVo.getModelTitle()), "modelTitle", "%" + searchTableInfoVo.getModelTitle() + "%");
and.in(searchTableInfoVo.getModelType() != null&&searchTableInfoVo.getModelType().length>0, "modelType", searchTableInfoVo.getModelType());
and.in(searchTableInfoVo.getIds() != null&&searchTableInfoVo.getIds().length>0, "id", searchTableInfoVo.getIds());
and.in(searchTableInfoVo.getModelType() != null && searchTableInfoVo.getModelType().length > 0, "modelType", searchTableInfoVo.getModelType());
and.in(searchTableInfoVo.getIds() != null && searchTableInfoVo.getIds().length > 0, "id", searchTableInfoVo.getIds());
}
return and;
}
......@@ -307,10 +308,10 @@ public class ModelImpl implements ModelService {
if (aClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = aClass.getAnnotation(ApiModel.class);
StringBuilder apiModelDocument = new StringBuilder();
if (annotation.value() != null && !"".equals(annotation.value())) {
if (!Strings.isNullOrEmpty(annotation.value())) {
apiModelDocument.append(annotation.value() + "|");
}
if (annotation.description() != null && !"".equals(annotation.description())) {
if (!Strings.isNullOrEmpty(annotation.description())) {
apiModelDocument.append(annotation.description() + "|");
}
tableVO.setModelTitle(apiModelDocument.toString());
......@@ -322,8 +323,11 @@ public class ModelImpl implements ModelService {
java.lang.reflect.Type genericType;
List<ColumnVO> list = new ArrayList<>();
ColumnVO primaryColumn = new ColumnVO();
;
List<ColumnVO> otherColumns = new ArrayList<>();
for (Field declaredField : declaredFields) {
ColumnVO columnVO = new ColumnVO();
// ColumnVO columnVO = new ColumnVO();
if (declaredField.isAnnotationPresent(Transient.class)) {
continue;
}
......@@ -331,31 +335,58 @@ public class ModelImpl implements ModelService {
genericType = declaredField.getGenericType();
//是否主键
if (declaredField.isAnnotationPresent(javax.persistence.Id.class)) {
columnVO.setPrimaryKey(0);
}
primaryColumn.setPrimaryKey(0);
primaryColumn.setFieldType(getTypeName(genericType.toString()));
primaryColumn.setFieldName(getClassName(declaredField.toString()));
// primaryColumn.setFieldLength(setLength(genericType.toString()));
columnVO.setFieldType(getTypeName(genericType.toString()));
columnVO.setFieldName(getClassName(declaredField.toString()));
columnVO.setFieldLength(setLength(genericType.toString()));
//获得属性中文描述
if (declaredField.isAnnotationPresent(ApiModelProperty.class)) {
ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
StringBuilder apiModelPropertyDocument = new StringBuilder();
if (annotation.value() != null && !"".equals(annotation.value())) {
if (!Strings.isNullOrEmpty(annotation.value())) {
apiModelPropertyDocument.append(annotation.value() + "|");
}
if (annotation.example() != null && !"".equals(annotation.example())) {
if (!Strings.isNullOrEmpty(annotation.example())) {
apiModelPropertyDocument.append(annotation.example() + "|");
}
primaryColumn.setFieldTitle(apiModelPropertyDocument.toString());
} else {
primaryColumn.setFieldTitle("(无描述)");
}
} else {
ColumnVO otherColumn = new ColumnVO();
otherColumn.setFieldType(getTypeName(genericType.toString()));
otherColumn.setFieldName(getClassName(declaredField.toString()));
// otherColumn.setFieldLength(setLength(genericType.toString()));
otherColumns.add(otherColumn);
//获得属性中文描述
if (declaredField.isAnnotationPresent(ApiModelProperty.class)) {
ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
StringBuilder apiModelPropertyDocument = new StringBuilder();
if (!Strings.isNullOrEmpty(annotation.value())) {
apiModelPropertyDocument.append(annotation.value() + "|");
}
if (!Strings.isNullOrEmpty(annotation.example())) {
apiModelPropertyDocument.append(annotation.example() + "|");
}
columnVO.setFieldTitle(apiModelPropertyDocument.toString());
otherColumn.setFieldTitle(apiModelPropertyDocument.toString());
} else {
columnVO.setFieldTitle("(无描述)");
otherColumn.setFieldTitle("(无描述)");
}
}
list.add(columnVO);
// columnVO.setFieldType(getTypeName(genericType.toString()));
// columnVO.setFieldName(getClassName(declaredField.toString()));
// columnVO.setFieldLength(setLength(genericType.toString()));
}
list.add(primaryColumn);
list.addAll(otherColumns);
tableVO.setDataList(list);
String xml = createTable(tableVO);
//扫描的xml
String xml = createTable(tableVO.getModelName(), primaryColumn, otherColumns);
tableInfo.setModelName(tableVO.getModelName());
tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setXml(xml);
......@@ -363,10 +394,6 @@ public class ModelImpl implements ModelService {
//判断是否存在
if (checkRepeat(realName)) {
tableInfo = tableInfoDao.save(tableInfo);
} else {
tableInfo = tableInfoDao.findByModelName(tableInfo.getModelName());
log.info("{}已存在", realName);
}
List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
......@@ -379,6 +406,9 @@ public class ModelImpl implements ModelService {
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
} else {
log.warn("{}已存在", realName);
}
}
}
}
......@@ -493,7 +523,7 @@ public class ModelImpl implements ModelService {
}
}
if(modelType.equals(ModelType.BASICS_EXTENSION)){
if (modelType.equals(ModelType.BASICS_EXTENSION)) {
columnInfoDao.deleteAllByDbId(updateTableInfoVO.getDbId());
List<ColumnInfo> dataList = updateTableInfoVO.getTableVO().getDataList().stream()
.map(columnVO -> columnInfo(tableInfo.getId(), tableInfo.getModelName(), columnVO))
......@@ -599,7 +629,7 @@ public class ModelImpl implements ModelService {
} else {
TableInfo tableInfo = byId.get();
Integer modelType = tableInfo.getModelType();
if (modelType.equals(ModelType.BUSINESS)||modelType.equals(ModelType.BASICS_EXTENSION)) {
if (modelType.equals(ModelType.BUSINESS) || modelType.equals(ModelType.BASICS_EXTENSION)) {
tableInfoDao.deleteById(delTableVO.getId());
List<ColumnInfo> allByDbId = columnInfoDao.findAllByDbId(delTableVO.getId());
columnInfoDao.deleteInBatch(allByDbId);
......
......@@ -23,7 +23,7 @@ public class ClassTypeLength {
} else if (Double.equals(genericType)) {
length = 10;
} else {
length = 0;
length =1;
}
return length;
}
......
......@@ -59,12 +59,13 @@ public class CreateTableUtil {
" <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n";
xmlMapping += " <id name=\"id\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n" +
" <generator class=\"identity\" />\n" +
" </id>";
for (ColumnVO columnVO : dataList) {
xmlMapping +=
" <property type=\"" + columnVO.getFieldType() + "\" name=\"" + columnVO.getFieldName() + "\" length=\"" + columnVO.getFieldLength() +
"\n <property type=\"" + columnVO.getFieldType() + "\" name=\"" + columnVO.getFieldName() + "\" length=\"" + columnVO.getFieldLength() +
"\" column=\"" + columnVO.getFieldName() + "\"/>\n";
}
......@@ -74,6 +75,37 @@ public class CreateTableUtil {
}
public static String createTable(String entityName,ColumnVO primaryColumn,List<ColumnVO> dataList) {
// 1sql-type="text" string 转为text文本,2长度超过会自动转换
// List<ColumnVO> dataList = tableVO.getDataList();
String xmlMapping = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE hibernate-mapping PUBLIC\n" +
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
"<hibernate-mapping>\n" +
" <class entity-name=\"" + entityName + "\" table=\"" + entityName + "\">\n";
xmlMapping += " <id name=\""+primaryColumn.getFieldName()+"\" type=\""+primaryColumn.getFieldType()+"\" unsaved-value=\"null\" >\n" +
" </id>";
for (ColumnVO columnVO : dataList) {
xmlMapping +=
"\n <property type=\"" + columnVO.getFieldType() + "\" name=\"" + columnVO.getFieldName() +
"\" column=\"" + columnVO.getFieldName() + "\"/>\n";
// xmlMapping +=
// "\n <property type=\"" + columnVO.getFieldType() + "\" name=\"" + columnVO.getFieldName() + "\" length=\"" + columnVO.getFieldLength() +
// "\" column=\"" + columnVO.getFieldName() + "\"/>\n";
}
xmlMapping += " </class>\n" +
"</hibernate-mapping>";
return xmlMapping;
}
public static String getClassName(String aClass) {
......
......@@ -517,17 +517,13 @@ class WorkflowCoreApplicationTests {
@Test
public void complex() {
ArrayList<QueryCondition> queryConditions = Lists.newArrayList(
new QueryCondition("id", "=", "1")
new QueryCondition("testId", "=", "1")
// new QueryCondition("type", "=", "'1'")
);
List<Map<String, Object>> list = modelService.complexQuery("nw_history", queryConditions);
List<Map<String, Object>> list = modelService.complexQuery("TestScan", queryConditions);
for (Map<String, Object> map : list) {
System.out.println(map);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论