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

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

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