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

model layer

上级 84ac5a5c
......@@ -16,5 +16,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@Data
public class SearchTableInfoVo extends JpaCustomPage {
private String tableName;
private String tableCnName;
}
......@@ -46,7 +46,7 @@ public class TableInfo extends BaseEntity implements Serializable {
*0是扫描,1是自建
*/
@ApiModelProperty("建表类型")
private Integer type;
private Integer modelType;
@ApiModelProperty("执行人(保留字段)")
private String reviser;
......
......@@ -23,6 +23,9 @@ public class TableVO {
private String modelTitle;
@ApiModelProperty("表名")
private String modelName;
/**
* 0扫描,1自建,2扫描后自选
*/
@ApiModelProperty("模型类型")
private Integer modelType;
@ApiModelProperty("父表名称")
......
......@@ -40,6 +40,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.tykj.workflowcore.model_layer.utils.ClassTypeLength.setLength;
import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.*;
import static com.tykj.workflowcore.model_layer.utils.HqlUtil.createQuery;
......@@ -74,11 +75,11 @@ public class ModelImpl implements ModelService {
* @Date 16:14 2021/3/5
**/
@Override
public Page<TableInfo> listAllEntities( SearchTableInfoVo searchTableInfoVo) {
public Page<TableInfo> listAllEntities(SearchTableInfoVo searchTableInfoVo) {
PredicateBuilder<TableInfo> and = Specifications.and();
and.eq(searchTableInfoVo.getTableName()!=null,"name",searchTableInfoVo.getTableName());
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
and.like(searchTableInfoVo.getTableName() != null, "name", "%" + searchTableInfoVo.getTableName() + "%");
and.like(searchTableInfoVo.getTableCnName() != null, "cnName", "%" + searchTableInfoVo.getTableCnName() + "%");
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
}
......@@ -102,27 +103,36 @@ public class ModelImpl implements ModelService {
}
/**
* @param tableVO
* @return com.tykj.workflowcore.model_layer.model.TableVO
* @Author WWW
* @Description 新建一张表
* @Description 完全新建一张表
* @Date 16:16 2021/3/5
**/
@Override
public TableVO newTable(TableVO tableVO) {
String xmlMapping = creatTable(tableVO);
Integer modelType = tableVO.getModelType();
String parentTable = null;
//扫描新建类型
if (modelType == 2) {
parentTable = tableVO.getParentTable();
tableVO.setModelType(2);
} else {
tableVO.setModelType(1);
}
CreatTableUtil creatTableUtil = new CreatTableUtil();
Session session = creatTableUtil.getSession(entityManagerFactory, xmlMapping);
List<ColumnVO> dataList = tableVO.getDataList();
TableInfo tableInfo = new TableInfo();
tableInfo.setName(tableVO.getModelName()+"_");
tableInfo.setName(tableVO.getModelName() + "_");
tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXml(xmlMapping);
tableInfo.setType(2);
tableInfo.setModelType(tableVO.getModelType());
tableInfo.setParentTable(parentTable);
tableInfoDao.save(tableInfo);
for (ColumnVO columnVO : dataList) {
......@@ -224,6 +234,11 @@ public class ModelImpl implements ModelService {
newSession.close();
}
/**
* 扫描表
*
* @param classList
*/
@Override
public void swaggerScan(List<Class<?>> classList) {
for (Class<?> aClass : classList) {
......@@ -234,7 +249,7 @@ public class ModelImpl implements ModelService {
TableVO tableVO = new TableVO();
String className = getClassName(aClass.toString());
//入表真实名称
String realName=className.toLowerCase() + "_model_test";
String realName = className.toLowerCase() + "_model_test";
tableVO.setModelName(realName);
//获得类中文描述
if (aClass.isAnnotationPresent(ApiModel.class)) {
......@@ -260,8 +275,8 @@ public class ModelImpl implements ModelService {
ColumnVO columnVO = new ColumnVO();
//获得类型
genericType = declaredField.getGenericType();
//是否主键
if (declaredField.isAnnotationPresent(javax.persistence.Id.class)){
//是否主键
if (declaredField.isAnnotationPresent(javax.persistence.Id.class)) {
columnVO.setPrimaryKey(0);
}
columnVO.setFieldType(getTypeName(genericType.toString()));
......@@ -289,9 +304,9 @@ public class ModelImpl implements ModelService {
tableInfo.setName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle());
tableInfo.setXml(xml);
tableInfo.setType(0);
tableInfo.setModelType(0);
//判断是否存在
if (checkRepeat(realName)){
if (checkRepeat(realName)) {
tableInfo = tableInfoDao.save(tableInfo);
List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) {
......@@ -302,37 +317,38 @@ public class ModelImpl implements ModelService {
columnInfo.setCnName(columnVO.getFieldDescription());
columnInfo.setPrimaryKey(columnVO.getPrimaryKey());
//暂定 简单类型
if ("class java.lang.String".equals(genericType.toString())){
columnInfo.setLength(255);
} else if ("class java.lang.Integer".equals(genericType.toString())) {
columnInfo.setLength(11);
} else if ("class java.lang.Double".equals(genericType.toString())) {
columnInfo.setLength(10);
}
else {
columnInfo.setLength(0);
}
// if ("class java.lang.String".equals(genericType.toString())){
// columnInfo.setLength(255);
// } else if ("class java.lang.Integer".equals(genericType.toString())) {
// columnInfo.setLength(11);
//
// } else if ("class java.lang.Double".equals(genericType.toString())) {
// columnInfo.setLength(10);
// }
// else {
// columnInfo.setLength(0);
// }
setLength(columnInfo, genericType);
columnInfo.setDbName(className);
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
}
else {
log.info("{}已存在",className);
} else {
log.info("{}已存在", className);
}
}
}
}
}
/**
* @Author WWW
* @Description 判重
* @Date 10:50 2021/3/11
* @param tableName
* @return boolean
**/
/**
* @param tableName
* @return boolean
* @Author WWW
* @Description 判重
* @Date 10:50 2021/3/11
**/
public boolean checkRepeat(String tableName) {
Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Path name = root.get("name");
......@@ -342,7 +358,7 @@ public class ModelImpl implements ModelService {
List<TableInfo> all = tableInfoDao.findAll(spec);
for (TableInfo tableInfo : all) {
String name = tableInfo.getName();
String name = tableInfo.getName();
if (tableName.equals(name)) {
return false;
}
......@@ -350,40 +366,39 @@ public class ModelImpl implements ModelService {
return true;
}
/**
* @Author WWW
* @Description 通过表名查询所有信息
* @Date 10:51 2021/3/11
* @param name
* @return java.util.List
**/
/**
* @param name
* @return java.util.List
* @Author WWW
* @Description 通过表名查询所有信息
* @Date 10:51 2021/3/11
**/
@Override
public List findAllByName(String name) {
if (name!=null&&name != ""){
if (name != null && name != "") {
try {
return Db.use().findAll(name);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
return null;
return null;
}
@Override
public List complexQuery(String tableName, List<QueryCondition> queryConditions) {
List<cn.hutool.db.Entity> list=null;
if (!"".equals(tableName)){
List<cn.hutool.db.Entity> list = null;
if (!"".equals(tableName)) {
String query = createQuery(tableName, queryConditions);
try {
list = Db.use().query(query);
list = Db.use().query(query);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
else {
} else {
return null;
}
return list ;
return list;
}
@Override
......
package com.tykj.workflowcore.model_layer.utils;
import com.tykj.workflowcore.model_layer.model.ColumnInfo;
/**
* @ClassName ClassTypeLength
* @Description TODO
* @Author WWW
* @Date 2021/3/15 9:53
* @Version 1.0
*/
public class ClassTypeLength {
private static String STRING="class java.lang.String";
private static String Integer="class java.lang.Integer";
private static String Double="class java.lang.Double";
public static void setLength(ColumnInfo columnInfo ,java.lang.reflect.Type genericType){
if (STRING.equals(genericType.toString())){
columnInfo.setLength(255);
} else if (Integer.equals(genericType.toString())) {
columnInfo.setLength(11);
} else if (Double.equals(genericType.toString())) {
columnInfo.setLength(10);
}
else {
columnInfo.setLength(0);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论