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

model layer

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