提交 d637cf76 authored 作者: 黄夏豪's avatar 黄夏豪

Merge remote-tracking branch 'origin/master'

...@@ -11,12 +11,9 @@ import com.tykj.workflowcore.base.util.ClassUtil; ...@@ -11,12 +11,9 @@ import com.tykj.workflowcore.base.util.ClassUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -40,14 +37,6 @@ public class ApiService { ...@@ -40,14 +37,6 @@ public class ApiService {
* @return 结构化列表数据,内容为带有指定注解的方法列表,也就是列出主项目中可调用的方法。 * @return 结构化列表数据,内容为带有指定注解的方法列表,也就是列出主项目中可调用的方法。
*/ */
public List<ClassInfo> findAll() { public List<ClassInfo> findAll() {
List<ClassInfo> classInfos = load();
for (ClassInfo classInfo : classInfos) {
System.out.println(classInfo);
}
return classInfos;
}
private List<ClassInfo> load() {
//获取所有类 //获取所有类
List<Class<?>> classes = ClassUtil.loadClassByLoader(getClass().getClassLoader()); List<Class<?>> classes = ClassUtil.loadClassByLoader(getClass().getClassLoader());
return classes.stream() return classes.stream()
......
...@@ -29,6 +29,7 @@ import java.util.Map; ...@@ -29,6 +29,7 @@ import java.util.Map;
@RequestMapping("/model") @RequestMapping("/model")
@Api("数据模型层接口") @Api("数据模型层接口")
public class ModelController { public class ModelController {
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
...@@ -61,7 +62,7 @@ public class ModelController { ...@@ -61,7 +62,7 @@ public class ModelController {
* @Description 根据表名得到所有字段名 * @Description 根据表名得到所有字段名
* @Date 16:20 2021/3/4 * @Date 16:20 2021/3/4
**/ **/
@ApiOperation("根据表名获得表所有字段") @ApiOperation("根据表名获查询所有字段")
@GetMapping("/getAllField") @GetMapping("/getAllField")
public ResponseEntity getFields(String tableName) { public ResponseEntity getFields(String tableName) {
if (tableName != null && tableName != "") { if (tableName != null && tableName != "") {
...@@ -90,7 +91,7 @@ public class ModelController { ...@@ -90,7 +91,7 @@ public class ModelController {
} }
modelService.NewTable(tableVO); modelService.NewTable(tableVO);
return ResultUtil.success("新建成功",""); return ResultUtil.success("","新建成功");
} }
...@@ -109,5 +110,22 @@ public class ModelController { ...@@ -109,5 +110,22 @@ public class ModelController {
return ResultUtil.success("数据插入成功",""); return ResultUtil.success("数据插入成功","");
} }
/**
* @Author WWW
* @Description 根据表名查询所有数据
* @Date 9:30 2021/3/11
* @param tableName
* @return org.springframework.http.ResponseEntity
**/
@ApiOperation("根据表名查询所有数据")
@GetMapping("/getAll")
public ResponseEntity getAll(String tableName) {
try {
return ResultUtil.success( modelService.findAllByName(tableName),"");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return ResultUtil.success( null,"获取失败");
}
} }
...@@ -25,7 +25,7 @@ import java.util.Map; ...@@ -25,7 +25,7 @@ import java.util.Map;
@Service @Service
public interface ModelService { public interface ModelService {
List<TableInfo> ListAllEntities() throws SQLException; List<TableInfo> ListAllEntities() throws SQLException;
List<ColumnInfo> showModelFields(String ModelName); List<ColumnInfo> showModelFields(String ModelName);
...@@ -34,7 +34,9 @@ public interface ModelService { ...@@ -34,7 +34,9 @@ public interface ModelService {
TableVO NewTable(TableVO tableVO); TableVO NewTable(TableVO tableVO);
int putValueByEntityName(Map<String ,Object> map ); int putValueByEntityName(Map<String, Object> map);
void swaggerScan(List<Class<?>> classList); void swaggerScan(List<Class<?>> classList);
List findAllByName(String name) throws SQLException;
} }
package com.tykj.workflowcore.model_layer.service.impl; package com.tykj.workflowcore.model_layer.service.impl;
import cn.hutool.db.Db;
import com.fasterxml.jackson.annotation.JsonTypeInfo; 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;
...@@ -37,12 +38,12 @@ import javax.persistence.Id; ...@@ -37,12 +38,12 @@ import javax.persistence.Id;
import javax.persistence.criteria.*; import javax.persistence.criteria.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.sql.SQLException;
import java.text.ParseException; 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.CreatTableUtil.CreatTable; import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.*;
import static com.tykj.workflowcore.model_layer.utils.CreatTableUtil.getClassName;
/** /**
...@@ -136,7 +137,7 @@ public class ModelImpl implements ModelService { ...@@ -136,7 +137,7 @@ public class ModelImpl implements ModelService {
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(XML_MAPPING); tableInfo.setXML(XML_MAPPING);
...@@ -284,7 +285,7 @@ public class ModelImpl implements ModelService { ...@@ -284,7 +285,7 @@ public class ModelImpl implements ModelService {
if (declaredField.isAnnotationPresent(javax.persistence.Id.class)){ if (declaredField.isAnnotationPresent(javax.persistence.Id.class)){
columnVO.setPrimarykey(0); columnVO.setPrimarykey(0);
} }
columnVO.setFiledType(genericType.toString()); columnVO.setFiledType(getTypeName(genericType.toString()));
columnVO.setFieldName(getClassName(declaredField.toString())); columnVO.setFieldName(getClassName(declaredField.toString()));
//获得属性中文描述 //获得属性中文描述
...@@ -321,13 +322,16 @@ public class ModelImpl implements ModelService { ...@@ -321,13 +322,16 @@ public class ModelImpl implements ModelService {
columnInfo.setLength(columnVO.getFiledLength()); columnInfo.setLength(columnVO.getFiledLength());
columnInfo.setCnName(columnVO.getFiledDescription()); columnInfo.setCnName(columnVO.getFiledDescription());
columnInfo.setPrimarykey(columnVO.getPrimarykey()); 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);
} else if (genericType.toString().equals("class java.lang.Integer")&&genericType.toString().equals("int")) { } else if (genericType.toString().equals("class java.lang.Integer")&&genericType.toString().equals("int")) {
columnInfo.setLength(11); columnInfo.setLength(11);
} else { } else if (genericType.toString().equals("class java.lang.Double")) {
columnInfo.setLength(10);
}
else {
columnInfo.setLength(0); columnInfo.setLength(0);
} }
columnInfo.setDbName(className); columnInfo.setDbName(className);
...@@ -344,21 +348,29 @@ public class ModelImpl implements ModelService { ...@@ -344,21 +348,29 @@ public class ModelImpl implements ModelService {
} }
} }
public boolean checkRepeat(String table_name) { 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");
Predicate equal = criteriaBuilder.equal(name, table_name); Predicate equal = criteriaBuilder.equal(name, tableName);
return equal; return equal;
}; };
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 (table_name.equals(name)) {
return false; return false;
} }
} }
return true; return true;
} }
@Override
public List findAllByName(String name) throws SQLException {
if (name!=null&&name != ""){
return Db.use().findAll(name);
}
return null;
}
} }
...@@ -79,10 +79,15 @@ public class CreatTableUtil { ...@@ -79,10 +79,15 @@ 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;
} }
// 处理带空格的class
public static String getTypeName(String aClass){
return aClass.replace("class ", "");
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论