提交 9f5cb8f2 authored 作者: ww1xhqc's avatar ww1xhqc

model layer 扫描重复bug

上级 bb9a9db9
......@@ -14,6 +14,7 @@ import com.tykj.workflowcore.model_layer.service.ModelService;
import com.tykj.workflowcore.model_layer.utils.CreatTableUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.Session;
import org.hibernate.internal.SessionImpl;
......@@ -51,6 +52,7 @@ import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.getClassNam
*/
@Transactional
@Service
@Slf4j
public class ModelImpl implements ModelService {
......@@ -249,7 +251,8 @@ public class ModelImpl implements ModelService {
// tableInfo.setId(id);
TableVO tableVO = new TableVO();
String className = getClassName(aClass.toString());
tableVO.setModelName(className.toLowerCase() + "_model_test");
String realName=className.toLowerCase() + "_model_test";
tableVO.setModelName(realName);
if (aClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = aClass.getAnnotation(ApiModel.class);
......@@ -298,33 +301,54 @@ public class ModelImpl implements ModelService {
tableInfo.setName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXML(xml);
tableInfo= tableInfoDao.save(tableInfo);
List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(columnVO.getFieldName());
columnInfo.setType(columnVO.getFiledType());
columnInfo.setLength(columnVO.getFiledLength());
columnInfo.setCnName(columnVO.getFiledDescription());
if (genericType.toString().equals("class java.lang.String")){
columnInfo.setLength(65535);
}
else if (genericType.toString().equals("class java.lang.Integer")){
columnInfo.setLength(11);
}else {
columnInfo.setLength(0);
if (checkRepeat(realName)){
tableInfo = tableInfoDao.save(tableInfo);
List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(columnVO.getFieldName());
columnInfo.setType(columnVO.getFiledType());
columnInfo.setLength(columnVO.getFiledLength());
columnInfo.setCnName(columnVO.getFiledDescription());
if (genericType.toString().equals("class java.lang.String")) {
columnInfo.setLength(255);
} else if (genericType.toString().equals("class java.lang.Integer")&&genericType.toString().equals("int")) {
columnInfo.setLength(11);
} else {
columnInfo.setLength(0);
}
columnInfo.setDbName(className);
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
columnInfo.setDbName(className);
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
else {
log.info("{}已存在",className);
}
}
}
}
}
public boolean checkRepeat(String table_name) {
Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Path name = root.get("name");
Predicate equal = criteriaBuilder.equal(name, table_name);
return equal;
};
List<TableInfo> all = tableInfoDao.findAll(spec);
for (TableInfo tableInfo : all) {
String name = tableInfo.getName();
if (table_name.equals(name)) {
return false;
}
}
return true;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论