提交 5afab766 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 字段修改和更新方法添加

上级 f980ee6e
...@@ -30,7 +30,7 @@ import java.util.Map; ...@@ -30,7 +30,7 @@ import java.util.Map;
*/ */
@RestController @RestController
@RequestMapping("/model") @RequestMapping("/model")
@Api("数据模型层接口") @Api(tags = "数据模型层接口")
public class ModelController { public class ModelController {
@Autowired @Autowired
...@@ -82,7 +82,7 @@ public class ModelController { ...@@ -82,7 +82,7 @@ public class ModelController {
public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception { public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception {
List<TableInfo> tableInfos = modelService.listAllEntities(); List<TableInfo> tableInfos = modelService.listAllEntities();
for (TableInfo tableInfo : tableInfos) { for (TableInfo tableInfo : tableInfos) {
if (tableVO.getModelName().equals(tableInfo.getName())) { if (tableVO.getModelName().equals(tableInfo.getModelName())) {
return ResultUtil.failed("表已经存在!"); return ResultUtil.failed("表已经存在!");
} }
} }
...@@ -142,7 +142,7 @@ public class ModelController { ...@@ -142,7 +142,7 @@ public class ModelController {
throwables.printStackTrace(); throwables.printStackTrace();
} }
for (TableInfo tableInfo : tableInfos) { for (TableInfo tableInfo : tableInfos) {
if (tableName.equals(tableInfo.getName())) { if (tableName.equals(tableInfo.getModelName())) {
return ResultUtil.failed("表已经存在!"); return ResultUtil.failed("表已经存在!");
} }
} }
......
...@@ -31,13 +31,13 @@ public class ColumnInfo extends BaseEntity { ...@@ -31,13 +31,13 @@ public class ColumnInfo extends BaseEntity {
private Integer primaryKey; private Integer primaryKey;
@ApiModelProperty("列名") @ApiModelProperty("列名")
private String name; private String fieldName;
@ApiModelProperty("列名中文描述") @ApiModelProperty("列名中文描述")
private String cnName; private String fieldTitle;
@ApiModelProperty("列类型") @ApiModelProperty("列类型")
private String type; private String fieldType;
@ApiModelProperty("长度") @ApiModelProperty("长度")
private Integer length; private Integer fieldLength;
@ApiModelProperty("所属表名") @ApiModelProperty("所属表名")
private String dbName; private String dbName;
@ApiModelProperty("所属表id") @ApiModelProperty("所属表id")
......
...@@ -30,10 +30,10 @@ public class TableInfo extends BaseEntity implements Serializable { ...@@ -30,10 +30,10 @@ public class TableInfo extends BaseEntity implements Serializable {
@ApiModelProperty("表名,不能为空") @ApiModelProperty("表名,不能为空")
@Column(nullable = false) @Column(nullable = false)
private String name; private String modelName;
@ApiModelProperty("表中文名,不能为空") @ApiModelProperty("表中文名,不能为空")
@Column(nullable = false) @Column(nullable = false)
private String cnName; private String modelTitle;
@ApiModelProperty("详细描述") @ApiModelProperty("详细描述")
private String description; private String description;
......
...@@ -22,7 +22,7 @@ public class ColumnVO { ...@@ -22,7 +22,7 @@ public class ColumnVO {
@ApiModelProperty("字段名") @ApiModelProperty("字段名")
private String fieldName; private String fieldName;
@ApiModelProperty("中文描述") @ApiModelProperty("中文描述")
private String fieldDescription; private String fieldTitle;
@ApiModelProperty("字段长度,有默认值") @ApiModelProperty("字段长度,有默认值")
private Integer fieldLength; private Integer fieldLength;
......
...@@ -19,9 +19,9 @@ public class SearchTableInfoVo extends JpaCustomPage { ...@@ -19,9 +19,9 @@ public class SearchTableInfoVo extends JpaCustomPage {
private Integer id; private Integer id;
private String tableName; private String modelName;
private String tableCnName; private String modelTitle;
private Integer modelType; private Integer modelType;
} }
...@@ -80,9 +80,9 @@ public class ModelImpl implements ModelService { ...@@ -80,9 +80,9 @@ public class ModelImpl implements ModelService {
@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.like(searchTableInfoVo.getTableName() != null, "name", "%" + searchTableInfoVo.getTableName() + "%"); and.like(searchTableInfoVo.getModelName() != null, "modelName", "%" + searchTableInfoVo.getModelName() + "%");
and.like(searchTableInfoVo.getTableCnName() != null, "cnName", "%" + searchTableInfoVo.getTableCnName() + "%"); and.like(searchTableInfoVo.getModelTitle() != null, "modelTitle", "%" + searchTableInfoVo.getModelTitle() + "%");
and.eq(searchTableInfoVo.getModelType()!=null,"modelType",searchTableInfoVo.getModelType()); and.eq(searchTableInfoVo.getModelType() != null, "modelType", searchTableInfoVo.getModelType());
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable()); return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
} }
...@@ -128,8 +128,8 @@ public class ModelImpl implements ModelService { ...@@ -128,8 +128,8 @@ public class ModelImpl implements ModelService {
List<ColumnVO> dataList = tableVO.getDataList(); List<ColumnVO> dataList = tableVO.getDataList();
TableInfo tableInfo = new TableInfo(); TableInfo tableInfo = new TableInfo();
tableInfo.setName(tableVO.getModelName()); tableInfo.setModelName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle()); tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setXml(xmlMapping); tableInfo.setXml(xmlMapping);
tableInfo.setModelType(tableVO.getModelType()); tableInfo.setModelType(tableVO.getModelType());
tableInfo.setParentTable(parentTable); tableInfo.setParentTable(parentTable);
...@@ -137,11 +137,11 @@ public class ModelImpl implements ModelService { ...@@ -137,11 +137,11 @@ public class ModelImpl implements ModelService {
for (ColumnVO columnVO : dataList) { for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo(); ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(columnVO.getFieldName()); columnInfo.setFieldName(columnVO.getFieldName());
columnInfo.setType(columnVO.getFieldType()); columnInfo.setFieldType(columnVO.getFieldType());
columnInfo.setLength(columnVO.getFieldLength()); columnInfo.setFieldLength(columnVO.getFieldLength());
columnInfo.setCnName(columnVO.getFieldDescription()); columnInfo.setFieldTitle(columnVO.getFieldTitle());
columnInfo.setDbName(tableInfo.getCnName()); columnInfo.setDbName(tableInfo.getModelName());
columnInfo.setDbId(tableInfo.getId()); columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo); columnInfoDao.save(columnInfo);
} }
...@@ -164,7 +164,7 @@ public class ModelImpl implements ModelService { ...@@ -164,7 +164,7 @@ public class ModelImpl implements ModelService {
//查找对应的表 //查找对应的表
Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> { Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Predicate equal = null; Predicate equal = null;
Path name = root.get("Name"); Path name = root.get("modelName");
equal = criteriaBuilder.equal(name, tableName); equal = criteriaBuilder.equal(name, tableName);
return equal; return equal;
}; };
...@@ -177,12 +177,12 @@ public class ModelImpl implements ModelService { ...@@ -177,12 +177,12 @@ public class ModelImpl implements ModelService {
Object values = map.get(tableName); Object values = map.get(tableName);
if (values instanceof Map) { if (values instanceof Map) {
//插入数据 //插入数据
insertValue(tableInfo.getName(), tableInfo.getXml(), (Map) values); insertValue(tableInfo.getModelName(), tableInfo.getXml(), (Map) values);
} else { } else {
//循环插入数据 //循环插入数据
List valuesList = (List) values; List valuesList = (List) values;
for (int i = 0; i < valuesList.size(); i++) { for (int i = 0; i < valuesList.size(); i++) {
insertValue(tableInfo.getName(), tableInfo.getXml(), (Map) valuesList.get(i)); insertValue(tableInfo.getModelName(), tableInfo.getXml(), (Map) valuesList.get(i));
} }
} }
} }
...@@ -262,10 +262,9 @@ public class ModelImpl implements ModelService { ...@@ -262,10 +262,9 @@ public class ModelImpl implements ModelService {
if (annotation.description() != null && !"".equals(annotation.description())) { if (annotation.description() != null && !"".equals(annotation.description())) {
apiModelDocument.append(annotation.description() + "|"); apiModelDocument.append(annotation.description() + "|");
} }
tableVO.setModelTitle(apiModelDocument.toString()); tableVO.setModelTitle(apiModelDocument.toString());
} else { } else {
tableVO.setModelTitle(""); tableVO.setModelTitle("(无描述)");
} }
//获得类所有属性 //获得类所有属性
Field[] declaredFields = aClass.getDeclaredFields(); Field[] declaredFields = aClass.getDeclaredFields();
...@@ -293,16 +292,16 @@ public class ModelImpl implements ModelService { ...@@ -293,16 +292,16 @@ public class ModelImpl implements ModelService {
apiModelPropertyDocument.append(annotation.example() + "|"); apiModelPropertyDocument.append(annotation.example() + "|");
} }
columnVO.setFieldDescription(apiModelPropertyDocument.toString()); columnVO.setFieldTitle(apiModelPropertyDocument.toString());
} else { } else {
columnVO.setFieldDescription("无描述"); columnVO.setFieldTitle("(无描述)");
} }
list.add(columnVO); list.add(columnVO);
} }
tableVO.setDataList(list); tableVO.setDataList(list);
String xml = createTable(tableVO); String xml = createTable(tableVO);
tableInfo.setName(tableVO.getModelName()); tableInfo.setModelName(tableVO.getModelName());
tableInfo.setCnName(tableVO.getModelTitle()); tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setXml(xml); tableInfo.setXml(xml);
tableInfo.setModelType(0); tableInfo.setModelType(0);
//判断是否存在 //判断是否存在
...@@ -311,24 +310,12 @@ public class ModelImpl implements ModelService { ...@@ -311,24 +310,12 @@ public class ModelImpl implements ModelService {
List<ColumnVO> dataList = tableVO.getDataList(); List<ColumnVO> dataList = tableVO.getDataList();
for (ColumnVO columnVO : dataList) { for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo(); ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setName(columnVO.getFieldName()); columnInfo.setFieldName(columnVO.getFieldName());
columnInfo.setType(columnVO.getFieldType()); columnInfo.setFieldType(columnVO.getFieldType());
columnInfo.setLength(columnVO.getFieldLength()); columnInfo.setFieldLength(columnVO.getFieldLength());
columnInfo.setCnName(columnVO.getFieldDescription()); columnInfo.setFieldTitle(columnVO.getFieldTitle());
columnInfo.setPrimaryKey(columnVO.getPrimaryKey()); columnInfo.setPrimaryKey(columnVO.getPrimaryKey());
//暂定 简单类型 setLength(columnInfo, genericType.toString());
// 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.setDbName(className);
columnInfo.setDbId(tableInfo.getId()); columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo); columnInfoDao.save(columnInfo);
...@@ -351,14 +338,14 @@ public class ModelImpl implements ModelService { ...@@ -351,14 +338,14 @@ public class ModelImpl implements ModelService {
**/ **/
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("modelName");
Predicate equal = criteriaBuilder.equal(name, tableName); 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.getModelName();
if (tableName.equals(name)) { if (tableName.equals(name)) {
return false; return false;
} }
...@@ -400,9 +387,101 @@ public class ModelImpl implements ModelService { ...@@ -400,9 +387,101 @@ public class ModelImpl implements ModelService {
} }
return list; return list;
} }
@Override @Override
public List<TableInfo> listAllEntities() { public List<TableInfo> listAllEntities() {
return tableInfoDao.findAll(); return tableInfoDao.findAll();
} }
@Override
public void updateTable(UpdateTableInfoVO updateTableInfoVO) {
// tableInfo和columnInfo变化
//查询到TableInfo和ColumnInfo
Integer dbId = updateTableInfoVO.getDbId();
Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
Predicate predicate = criteriaBuilder.equal(root.get("dbId"), dbId);
return predicate;
};
List<ColumnInfo> all = columnInfoDao.findAll(spec);
//删除columnInfo
columnInfoDao.deleteInBatch(all);
TableInfo tableInfo = tableInfoDao.getOne(dbId);
tableInfo.setUpdatedTime(new Date());
TableVO tableVO = updateTableInfoVO.getTableVO();
List<ColumnVO> dataList = tableVO.getDataList();
String xml = createTable(tableVO);
tableInfo.setXml(xml);
tableInfoDao.save(tableInfo);
//重新存xml
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setFieldName(columnVO.getFieldName());
columnInfo.setFieldType(columnVO.getFieldType());
columnInfo.setFieldLength(columnVO.getFieldLength());
columnInfo.setFieldTitle(columnVO.getFieldTitle());
setLength(columnInfo, columnVO.getFieldType());
columnInfo.setDbName(tableInfo.getModelName());
columnInfo.setDbId(tableInfo.getId());
columnInfoDao.save(columnInfo);
}
// #################### tableInfo和columnInfo变化结束 ###################
// 对应表真实变化
// 遍历新数据和原来数据对比=> 少了加 多了删
}
/**
* 修改列名
*
* @param tableName
* @param oldColumnName
* @param newColumnName
*/
private void UpdateColumnName(String tableName, String oldColumnName, String newColumnName) {
// ALTER TABLE stu rename column name to name2;
try {
Db.use().execute(" ALTER TABLE " + tableName + " rename column " + oldColumnName + " to " + newColumnName + ";");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
/**
* 删除一列
*
* @param tableName
* @param columnName
*/
private void delOneColumn(String tableName, String columnName) {
// ALTER TABLE fab2 DROP test1;
try {
Db.use().execute("ALTER TABLE " + tableName + " DROP " + columnName + ";");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
/**
* 增加一列
*
* @param tableName
* @param columnName
* @param type
*/
private void addOneColumn(String tableName, String columnName, String type) {
// alter table fab2 add test1 varchar(10) not Null;
try {
Db.use().execute(" alter table "+tableName+" add "+columnName+" "+type);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
} }
...@@ -19,15 +19,15 @@ public class ClassTypeLength { ...@@ -19,15 +19,15 @@ public class ClassTypeLength {
if (STRING.equals(genericType)){ if (STRING.equals(genericType)){
columnInfo.setLength(255); columnInfo.setFieldLength(255);
} else if (Integer.equals(genericType)) { } else if (Integer.equals(genericType)) {
columnInfo.setLength(11); columnInfo.setFieldLength(11);
} else if (Double.equals(genericType)) { } else if (Double.equals(genericType)) {
columnInfo.setLength(10); columnInfo.setFieldLength(10);
} }
else { else {
columnInfo.setLength(0); columnInfo.setFieldLength(0);
} }
} }
} }
package com.tykj.workflowcore.workflow_editer.service; package com.tykj.workflowcore.workflow_editer.service;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage; import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo; import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论