提交 4a54f0a7 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 补全类的全参、无参构造,聚合对象修改

上级 da3be51d
......@@ -5,16 +5,16 @@ import com.tykj.workflowcore.model_layer.dao.AggregationDao;
import com.tykj.workflowcore.model_layer.entity.Aggregation;
import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO;
import com.tykj.workflowcore.model_layer.service.AggregationService;
import com.tykj.workflowcore.model_layer.service.impl.ModelHelper;
import io.swagger.annotations.Api;
import liquibase.pro.packaged.A;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
......@@ -26,7 +26,7 @@ import java.util.List;
* @Date 2021/4/2 11:19
* @Version 1.0
*/
@Api(tags = "聚合对象")
@RestController
@RequestMapping("/aggregation")
public class AggregationController {
......@@ -36,6 +36,8 @@ public class AggregationController {
@Autowired
AggregationDao aggregationDao;
@Autowired
ModelHelper modelHelper;
@PostMapping("/add")
public ResponseEntity add(@RequestBody AggregationVO aggregationVO) {
......@@ -85,4 +87,8 @@ public class AggregationController {
return elementCLass;
}
}
......@@ -128,7 +128,7 @@ public class ModelController {
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return ResultUtil.success(null, "获取失败!");
return ResultUtil.failed(null, "获取失败!");
}
/**
......@@ -147,7 +147,7 @@ public class ModelController {
if (list != null) {
return ResultUtil.success(list, "查询成功!");
}
return ResultUtil.success(null, "没有数据!");
return ResultUtil.failed(null, "没有数据!");
}
@ApiOperation("编辑操作")
......@@ -158,7 +158,7 @@ public class ModelController {
if (i == 1) {
return ResultUtil.success("", "修改成功!");
}
return ResultUtil.success("业务类型不支持修改!");
return ResultUtil.failed("业务类型不支持修改!");
}
@ApiOperation("删除操作")
......@@ -169,7 +169,7 @@ public class ModelController {
if (i == 1) {
return ResultUtil.success("", "删除成功!");
}
return ResultUtil.success("业务类型不支持删除!");
return ResultUtil.failed("业务类型不支持删除!");
}
......
package com.tykj.workflowcore.model_layer.dao;
import com.tykj.workflowcore.model_layer.entity.Aggregation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
......
......@@ -3,8 +3,10 @@ package com.tykj.workflowcore.model_layer.entity;
import com.tykj.workflowcore.base.entity.BaseEntity;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
......@@ -18,12 +20,14 @@ import java.util.List;
* @Date 2021/4/2 9:49
* @Version 1.0
*/
@Accessors(chain = true)
@WorkFlowCoreNoScan
@Data
@Table(name = "workflow_aggregation")
@Table(name = "aggregation")
@NoArgsConstructor
@AllArgsConstructor
@Entity
@SQLDelete(sql = "update column_info set deleted = 1 where id = ?")
@SQLDelete(sql = "update aggregation set deleted = 1 where id = ?")
@Where(clause = "deleted = 0")
public class Aggregation extends BaseEntity {
......
......@@ -4,7 +4,9 @@ package com.tykj.workflowcore.model_layer.entity;
import com.tykj.workflowcore.base.entity.BaseEntity;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.*;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
......@@ -25,6 +27,8 @@ import java.io.Serializable;
@Table
@EntityListeners(AuditingEntityListener.class)
@Data
@AllArgsConstructor
@NoArgsConstructor
@SQLDelete(sql = "update table_info set deleted = 1 where id = ?")
@Where(clause = "deleted = 0")
public class TableInfo extends BaseEntity {
......
......@@ -7,7 +7,10 @@ import com.tykj.workflowcore.model_layer.entity.TableInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import java.util.List;
......@@ -19,6 +22,9 @@ import java.util.List;
* @Date 2021/4/2 9:51
* @Version 1.0
*/
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel("聚合信息")
@Data
public class AggregationVO {
......
......@@ -2,7 +2,9 @@ package com.tykj.workflowcore.model_layer.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName ColumnVO
......@@ -13,6 +15,8 @@ import lombok.Data;
*/
@ApiModel("列信息")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ColumnVO {
@ApiModelProperty("id")
......
......@@ -2,7 +2,9 @@ package com.tykj.workflowcore.model_layer.entity.vo;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
import com.tykj.workflowcore.model_layer.entity.TableInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
......@@ -13,6 +15,8 @@ import java.util.List;
* @Date 2021/3/29 9:59
* @Version 1.0
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class TableAndColumnInfoVO {
......
......@@ -2,7 +2,9 @@ package com.tykj.workflowcore.model_layer.entity.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
......@@ -15,6 +17,8 @@ import java.util.List;
*/
@ApiModel("表信息")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TableVO {
@ApiModelProperty("中文描述")
......
package com.tykj.workflowcore.model_layer.myEnum;
/**
* @ClassName ModelType
* @Description TODO 模型的3种类型
......@@ -9,6 +10,11 @@ package com.tykj.workflowcore.model_layer.myEnum;
*/
public class ModelType {
/**
* 聚合对象
*/
// public static final Integer AGGREGATION = -1;
/**
* 基础扫描对象
*/
......@@ -16,11 +22,20 @@ public class ModelType {
/**
* 业务对象
*/
public static final Integer BUSINESS = 1;
// public static final Integer BUSINESS = 1;
/**
* 基础对象延伸
*/
public static final Integer BASICS_EXTENSION = 2;
// public static final Integer BASICS_EXTENSION = 2;
/**
* 数据源对象
*/
public static final Integer DATA_SOURCE = 3;
/**
*虚拟对象,业务对象加聚合对象
*/
public static final Integer VIRTUAL = 4;
}
......@@ -8,8 +8,10 @@ import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.entity.Aggregation;
import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO;
import com.tykj.workflowcore.model_layer.myEnum.AggregationType;
import com.tykj.workflowcore.model_layer.myEnum.ModelType;
import com.tykj.workflowcore.model_layer.service.AggregationService;
import com.tykj.workflowcore.model_layer.utils.AggregationUtil;
import com.tykj.workflowcore.model_layer.utils.SessionUtil;
......@@ -26,6 +28,7 @@ import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* @ClassName AggregationImpl
......@@ -41,46 +44,37 @@ public class AggregationImpl implements AggregationService {
TableInfoDao tableInfoDao;
@Autowired
AggregationDao aggregationRelationshipDao;
AggregationDao aggregationDao;
@Autowired
SessionUtil sessionUtil;
@Override
@Transactional(rollbackOn = Exception.class)
public void addAggregation(AggregationVO aggregationVO) {
Document mainTableDocument;
//获取主表XML
Integer mainTableId = aggregationVO.getMainTableId();
Optional<TableInfo> mainTableById = tableInfoDao.findById(mainTableId);
if (mainTableById.isPresent()){
mainTableDocument = AggregationUtil.getDocument(mainTableById.get().getXml());
}else {
throw new ApiException("主表不存在");
throw new ApiException("主表不存在!");
}
//改CLASS名字
AggregationUtil.changeClassName(aggregationVO.getModelName(),mainTableDocument );
// save TableInfoEx (name des mainTableId)
List<TableInfo> all = tableInfoDao.findAll();
for (TableInfo tableInfo : all) {
if (aggregationVO.getModelName().equals(tableInfo.getModelName())){
throw new ApiException("名称已存在!");
}
}
TableInfo tableInfoEx = tableInfoDao.save(aggregationVO.getTableInfo());
try {
createAggregationObjectXml(aggregationVO.getAggregations(), null, tableInfoEx.getId(), mainTableById.get(), mainTableDocument.getRootElement());
tableInfoEx.setXml(mainTableDocument.asXML());
createAggregationObjectXml(aggregationVO.getAggregations(), null, tableInfoEx.getId(), mainTableById.get());
} catch (DocumentException e) {
e.printStackTrace();
}
tableInfoDao.save(tableInfoEx);
}
//假设获得的是一份XML
public Element createAggregationObjectXml(List<Aggregation> aggregations, Aggregation parentAggregation, Integer tableInfoExId, TableInfo mainTableInfo, Element rootElement) throws DocumentException {
// 假设获得的是一份XML
public void createAggregationObjectXml(List<Aggregation> aggregations,
Aggregation parentAggregation,
Integer tableInfoExId,
TableInfo mainTableInfo) throws DocumentException {
//这里需要一个class标签,
Boolean isFirst = false;
Element elementClass ;
String parentModeName;
if (parentAggregation!=null){
//如果不是第一层,则通过parentAggregation,查出副表的XML字符串
......@@ -88,7 +82,6 @@ public class AggregationImpl implements AggregationService {
//取出Class标签,将Class标签赋值给elementClass
Optional<TableInfo> sideTableInfoOptional = tableInfoDao.findById(parentAggregation.getSideTableId());
if (sideTableInfoOptional.isPresent()){
elementClass = (Element) DocumentHelper.parseText(sideTableInfoOptional.get().getXml()).getRootElement().element("class").clone();
}else {
throw new ApiException("id为:"+parentAggregation.getSideTableId()+"的副表不存在");
}
......@@ -96,35 +89,26 @@ public class AggregationImpl implements AggregationService {
}else {
//如果是第一层 则通过rootElement 查出副表的XML字符串
//取出Class标签,将Class标签赋值给elementClass
elementClass = (Element) rootElement.element("class");
parentModeName = mainTableInfo.getModelName();
isFirst = true;
}
//循环
for (int i = 0; i < aggregations.size(); i++) {
Aggregation aggregationChild = aggregations.get(i);
if (aggregationChild.getAggregations()!=null&&aggregationChild.getAggregations().size()>0){
String uuid ="tykj"+UUID.randomUUID().toString().replaceAll("-","");
Element elementClassChild = createAggregationObjectXml(aggregationChild.getAggregations(), aggregationChild, tableInfoExId, mainTableInfo,rootElement);
//为element给一个UUID的entity_name
aggregationChild.setUuidTableName(uuid);
elementClassChild.attribute("entity-name").setValue(uuid);
Element elementSet = aggregationToXmlElement(aggregationChild, tableInfoExId, parentModeName);
elementClass.add(elementSet);
createAggregationObjectXml(aggregationChild.getAggregations(), aggregationChild, tableInfoExId, mainTableInfo);
aggregationToXmlElement(aggregationChild, tableInfoExId, parentModeName);
}else {
//addSet
Element elementSet = aggregationToXmlElement(aggregationChild, tableInfoExId, parentModeName);
elementClass.add(elementSet);
aggregationToXmlElement(aggregationChild, tableInfoExId, parentModeName);
}
aggregationRelationshipDao.save(aggregationChild);
}
if (!isFirst){
rootElement.add(elementClass);
aggregationDao.save(aggregationChild);
}
return elementClass;
return;
}
public Element aggregationToXmlElement(Aggregation aggregation,Integer tableInfoExId,String parentModelName){
public void aggregationToXmlElement(Aggregation aggregation,Integer tableInfoExId,String parentModelName){
//设置tableInfoExId
aggregation.setTableInfoExId(tableInfoExId);
......@@ -133,17 +117,10 @@ public class AggregationImpl implements AggregationService {
throw new ApiException("id为:"+aggregation.getSideTableId()+"的副表不存在");
}
if (aggregation.getRelationship().equals(AggregationType.ONE_TO_ONE)){
return AggregationUtil.createOneToOneElement(
sideTableById.get().getModelName(),
aggregation.getSideTableConnectionKey(),
StringUtils.isEmpty(aggregation.getUuidTableName())?sideTableById.get().getModelName():aggregation.getUuidTableName()
);
return;
}
if (aggregation.getRelationship().equals(AggregationType.ONE_TO_MANY)){
return AggregationUtil.createOneToManyElement(
sideTableById.get().getModelName(),
StringUtils.isEmpty(aggregation.getUuidTableName())?sideTableById.get().getModelName():aggregation.getUuidTableName(),
aggregation.getSideTableConnectionKey());
return;
}
if (aggregation.getRelationship().equals(AggregationType.MANY_TO_MANY)){
//如果是多对多需要 为 aggregationRelationship 生成连接的KEY
......@@ -155,9 +132,46 @@ public class AggregationImpl implements AggregationService {
String connectionTableName = parentModelName+"_"+sideTableById.get().getModelName()+"_"+ (UUID.randomUUID().toString().substring(0,8));
aggregation.setConnectionTableName(connectionTableName);
//Util.addManyToMany
return AggregationUtil.createManyToManyElement(sideTableById.get().getModelName(),aggregation.getUuidTableName(),connectionTableName,mainTableConnectionKey,sideTableConnectionKey);
return;
}
return null;
return ;
}
//
// @Override
// public void addAggregation(AggregationVO aggregationVO) {
// Integer mainTableId = aggregationVO.getMainTableId();
// Optional<TableInfo> byId = tableInfoDao.findById(mainTableId);
// TableInfo tableInfo = new TableInfo();
// List<String> modelNames = tableInfoDao.findAll()
// .stream()
// .map(TableInfo::getModelName)
// .collect(Collectors.toList());
// if (byId.isPresent()){
// if (modelNames.contains(aggregationVO.getModelName())){
// throw new ApiException("表名已经存在!");
// }
// else {
// tableInfo.setModelType(ModelType.VIRTUAL);
// tableInfo = tableInfoDao.save(aggregationVO.getTableInfo());
// }
// }else {
// throw new ApiException("主表不存在!");
// }
// saveAggregation(aggregationVO,tableInfo.getId());
//
//
//
// }
//
// public void saveAggregation(AggregationVO aggregationVO,Integer tableInfoId){
// Aggregation aggregation=new Aggregation();
// aggregation.setConnectionTableName(aggregationVO.getModelName())
// .setRelationship(aggregationVO.getAggregations().get(0).getRelationship())
// .setMainTableConnectionKey(aggregationVO.getAggregations().get(0).getMainTableConnectionKey())
// .setSideTableId(aggregationVO.getAggregations().get(0).getSideTableId())
// .setTableInfoExId(tableInfoId)
// .setSideTableConnectionKey(aggregationVO.getAggregations().get(0).getSideTableConnectionKey());
// aggregationDao.save(aggregation);
// }
}
......@@ -146,15 +146,22 @@ public class ModelImpl implements ModelService {
Integer modelType = tableVO.getModelType();
String parentTable = null;
//扫描新建类型
if (modelType.equals(ModelType.BASICS_EXTENSION)) {
if (modelType.equals(ModelType.VIRTUAL)) {
parentTable = tableVO.getParentTable();
tableVO.setModelType(ModelType.BASICS_EXTENSION);
tableVO.setModelType(ModelType.VIRTUAL);
} else {
tableVO.setModelType(ModelType.BUSINESS);
tableVO.setModelType(ModelType.VIRTUAL);
}
// sessionUtil.addXml(xmlMapping);
Session session = sessionUtil.getSession();
List<ColumnVO> dataList = tableVO.getDataList();
List<String> collect = tableInfoDao.findAll()
.stream()
.map(TableInfo::getModelName)
.collect(Collectors.toList());
if (collect.contains(tableVO.getModelName())){
throw new ApiException("表名已经存在!");
}
TableInfo tableInfo = new TableInfo();
tableInfo.setModelName(tableVO.getModelName());
tableInfo.setModelTitle(tableVO.getModelTitle());
......@@ -164,8 +171,10 @@ public class ModelImpl implements ModelService {
tableInfo.setParentTable(parentTable);
tableInfoDao.save(tableInfo);
//默认存储ID字段
ColumnInfo cId = new ColumnInfo(0, "id", "主键", "java.lang.Integer", 11, tableInfo.getModelName(), tableInfo.getId(), "主键");
columnInfoDao.save(cId);
if (tableInfo.getModelType().equals(ModelType.VIRTUAL)){
ColumnInfo cId = new ColumnInfo(0, "id", "主键", "java.lang.Integer", 11, tableInfo.getModelName(), tableInfo.getId(), "主键");
columnInfoDao.save(cId);
}
for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo();
columnInfo.setFieldName(columnVO.getFieldName());
......@@ -208,7 +217,7 @@ public class ModelImpl implements ModelService {
tableInfo = (TableInfo) one.get();
}
Integer modelType = tableInfo.getModelType();
if (modelType.equals(ModelType.BUSINESS)) {
if (modelType.equals(ModelType.VIRTUAL)) {
Object values = map.get(tableName);
if (values instanceof Map) {
//插入数据
......@@ -476,9 +485,8 @@ public class ModelImpl implements ModelService {
Integer dbId = updateTableInfoVO.getDbId();
TableInfo tableInfo = tableInfoDao.findById(dbId).orElseThrow(() -> new RuntimeException("未找到该id的表信息"));
Integer modelType = tableInfo.getModelType();
if (modelType.equals(ModelType.BUSINESS)) {
if (modelType.equals(ModelType.VIRTUAL)) {
tableInfo.setUpdatedTime(new Date());
tableInfo.setDescription(tableVO.getDescription());
tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setModelType(tableVO.getModelType());
......@@ -524,7 +532,7 @@ public class ModelImpl implements ModelService {
return 1;
}
if (modelType.equals(ModelType.BASICS_EXTENSION)) {
if (modelType.equals(ModelType.VIRTUAL)) {
columnInfoDao.deleteAllByDbId(updateTableInfoVO.getDbId());
......@@ -642,7 +650,7 @@ public class ModelImpl implements ModelService {
} else {
TableInfo tableInfo = byId.get();
Integer modelType = tableInfo.getModelType();
if (modelType.equals(ModelType.BUSINESS) || modelType.equals(ModelType.BASICS_EXTENSION)) {
if (modelType.equals(ModelType.VIRTUAL) || modelType.equals(ModelType.VIRTUAL)) {
tableInfoDao.deleteById(delTableVO.getId());
List<ColumnInfo> allByDbId = columnInfoDao.findAllByDbId(delTableVO.getId());
columnInfoDao.deleteInBatch(allByDbId);
......
......@@ -3,7 +3,7 @@ package com.tykj.workflowcore.model_layer.utils;
import com.google.common.base.Strings;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.entity.TableInfo;
import org.checkerframework.checker.units.qual.A;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论