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

[数据模型] 新增聚合对象接口。

上级 1eeae3cc
...@@ -115,6 +115,12 @@ ...@@ -115,6 +115,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId> <artifactId>spring-boot-starter-cache</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.tykj.workflowcore.model_layer.controller;
import com.tykj.workflowcore.model_layer.service.TableInfoExService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName TableInfoExController
* @Description TODO
* @Author WWW
* @Date 2021/4/6 10:37
* @Version 1.0
*/
@RestController
public class TableInfoExController {
@Autowired
TableInfoExService tableInfoExService;
}
package com.tykj.workflowcore.model_layer.dao; package com.tykj.workflowcore.model_layer.dao;
import com.tykj.workflowcore.model_layer.entity.AggregationRelationship; import com.tykj.workflowcore.model_layer.entity.Aggregation;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
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;
...@@ -12,6 +13,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; ...@@ -12,6 +13,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @Date 2021/4/2 10:34 * @Date 2021/4/2 10:34
* @Version 1.0 * @Version 1.0
*/ */
public interface AggregationRelationshipDao extends JpaRepository<AggregationRelationship, Integer>, JpaSpecificationExecutor<AggregationRelationship> { public interface AggregationRelationshipDao extends JpaRepository<Aggregation, Integer>, JpaSpecificationExecutor<Aggregation> {
} }
...@@ -23,12 +23,12 @@ import javax.persistence.Entity; ...@@ -23,12 +23,12 @@ import javax.persistence.Entity;
@Entity @Entity
@SQLDelete(sql = "update column_info set deleted = 1 where id = ?") @SQLDelete(sql = "update column_info set deleted = 1 where id = ?")
@Where(clause = "deleted = 0") @Where(clause = "deleted = 0")
public class AggregationRelationship extends BaseEntity { public class Aggregation extends BaseEntity {
@ApiModelProperty("聚合对象ID") @ApiModelProperty("聚合对象ID")
private Integer tableInfoExId; private Integer tableInfoExId;
@ApiModelProperty("表id") @ApiModelProperty("表id")
private Integer sideTableId; private Integer sideTableId;
@ApiModelProperty("聚合对象关系") @ApiModelProperty("聚合对象关系")
......
package com.tykj.workflowcore.model_layer.entity.vo; package com.tykj.workflowcore.model_layer.entity.vo;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.tykj.workflowcore.model_layer.entity.AggregationRelationship; import com.tykj.workflowcore.model_layer.entity.Aggregation;
import com.tykj.workflowcore.model_layer.entity.TableInfoEx; import com.tykj.workflowcore.model_layer.entity.TableInfoEx;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -30,7 +31,7 @@ public class AggregationVO { ...@@ -30,7 +31,7 @@ public class AggregationVO {
private Integer mainTableId; private Integer mainTableId;
@ApiModelProperty("关系集合") @ApiModelProperty("关系集合")
private List<AggregationRelationship> lists; private List<Aggregation> lists;
public TableInfoEx getTableInfoEx(){ public TableInfoEx getTableInfoEx(){
TableInfoEx tableInfoEx = new TableInfoEx(); TableInfoEx tableInfoEx = new TableInfoEx();
......
...@@ -4,6 +4,8 @@ import com.tykj.workflowcore.model_layer.entity.TableInfoEx; ...@@ -4,6 +4,8 @@ import com.tykj.workflowcore.model_layer.entity.TableInfoEx;
import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO; import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @ClassName Aggregation * @ClassName Aggregation
* @Description TODO * @Description TODO
......
package com.tykj.workflowcore.model_layer.service;
import com.tykj.workflowcore.model_layer.entity.TableInfoEx;
import java.util.List;
/**
* @Author WWW
* @Description
* @Date 14:06 2021/4/6
* @return
**/
public interface TableInfoExService {
/**
* 查询所有
* @return
*/
List<TableInfoEx> findAll();
/**
* 根据id获取tableInfoExXML
* @param id
* @return
*/
String findXml(Integer id);
}
...@@ -4,7 +4,8 @@ import com.tykj.workflowcore.base.result.ApiException; ...@@ -4,7 +4,8 @@ import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.dao.AggregationRelationshipDao; import com.tykj.workflowcore.model_layer.dao.AggregationRelationshipDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoDao; import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.dao.TableInfoExDao; import com.tykj.workflowcore.model_layer.dao.TableInfoExDao;
import com.tykj.workflowcore.model_layer.entity.AggregationRelationship;
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.TableInfoEx; import com.tykj.workflowcore.model_layer.entity.TableInfoEx;
import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO; import com.tykj.workflowcore.model_layer.entity.vo.AggregationVO;
...@@ -15,7 +16,7 @@ import org.dom4j.Document; ...@@ -15,7 +16,7 @@ import org.dom4j.Document;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
...@@ -28,6 +29,7 @@ import java.util.UUID; ...@@ -28,6 +29,7 @@ import java.util.UUID;
*/ */
@Service @Service
public class AggregationImpl implements AggregationService { public class AggregationImpl implements AggregationService {
@Autowired @Autowired
TableInfoDao tableInfoDao; TableInfoDao tableInfoDao;
@Autowired @Autowired
...@@ -51,22 +53,23 @@ public class AggregationImpl implements AggregationService { ...@@ -51,22 +53,23 @@ public class AggregationImpl implements AggregationService {
// save TableInfoEx (name des mainTableId) // save TableInfoEx (name des mainTableId)
TableInfoEx tableInfoEx = tableInfoExDao.save(aggregationVO.getTableInfoEx()); TableInfoEx tableInfoEx = tableInfoExDao.save(aggregationVO.getTableInfoEx());
// 遍历VO 根据聚合类型 生成对应的 XML 节点 并添加到DOCUMENT中 // 遍历VO 根据聚合类型 生成对应的 XML 节点 并添加到DOCUMENT中
for (AggregationRelationship aggregationRelationship : aggregationVO.getLists()) { for (Aggregation aggregationRelationship : aggregationVO.getLists()) {
//取出副表的tableinfo //取出副表的tableInfo
Optional<TableInfo> sideTableById = tableInfoDao.findById(aggregationRelationship.getSideTableId()); Optional<TableInfo> sideTableById = tableInfoDao.findById(aggregationRelationship.getSideTableId());
aggregationRelationship.setTableInfoExId(tableInfoEx.getId()); aggregationRelationship.setTableInfoExId(tableInfoEx.getId());
if (!sideTableById.isPresent()){ if (!sideTableById.isPresent()){
throw new ApiException("id为:"+aggregationRelationship.getSideTableId()+"的副表不存在"); throw new ApiException("id为:"+aggregationRelationship.getSideTableId()+"的副表不存在");
} }
if (aggregationRelationship.getRelationship().equals(AggregationType.ONE_TO_ONE)){ if (aggregationRelationship.getRelationship().equals(AggregationType.ONE_TO_ONE)){
AggregationUtil.addOneToOne(aggregationRelationship.getSideTableConnectionKey(), sideTableById.get().getModelName(), mainTableDocument); Document document = AggregationUtil.addOneToOne(aggregationRelationship.getSideTableConnectionKey(), sideTableById.get().getModelName(), mainTableDocument);
tableInfoEx.setXml(document.asXML());
} }
if (aggregationRelationship.getRelationship().equals(AggregationType.ONE_TO_MANY)){ if (aggregationRelationship.getRelationship().equals(AggregationType.ONE_TO_MANY)){
//如果是一对多需要 为 aggregationRelationship 生成连接的KEY //如果是一对多需要 为 aggregationRelationship 生成连接的KEY
String mainTableConnectionKey = sideTableById.get().getModelName()+"List"; String mainTableConnectionKey = sideTableById.get().getModelName()+"_list";
AggregationUtil.addOneToMany(sideTableById.get().getModelName(), mainTableConnectionKey, aggregationRelationship.getSideTableConnectionKey(), mainTableDocument); Document document = AggregationUtil.addOneToMany(sideTableById.get().getModelName(), mainTableConnectionKey, aggregationRelationship.getSideTableConnectionKey(), mainTableDocument);
tableInfoEx.setXml(document.asXML());
} }
if (aggregationRelationship.getRelationship().equals(AggregationType.MANY_TO_MANY)){ if (aggregationRelationship.getRelationship().equals(AggregationType.MANY_TO_MANY)){
//如果是多对多需要 为 aggregationRelationship 生成连接的KEY //如果是多对多需要 为 aggregationRelationship 生成连接的KEY
...@@ -75,16 +78,13 @@ public class AggregationImpl implements AggregationService { ...@@ -75,16 +78,13 @@ public class AggregationImpl implements AggregationService {
aggregationRelationship.setMainTableConnectionKey(mainTableConnectionKey); aggregationRelationship.setMainTableConnectionKey(mainTableConnectionKey);
aggregationRelationship.setSideTableConnectionKey(sideTableConnectionKey); aggregationRelationship.setSideTableConnectionKey(sideTableConnectionKey);
//如果是多对多需要 为 aggregationRelationship 生成连接的中间表名 //如果是多对多需要 为 aggregationRelationship 生成连接的中间表名
String ConnectionTableName = mainTableById.get().getModelName()+"_"+sideTableById.get().getModelName()+"_"+ (UUID.randomUUID().toString().substring(0,8)); String connectionTableName = mainTableById.get().getModelName()+"_"+sideTableById.get().getModelName()+"_"+ (UUID.randomUUID().toString().substring(0,8));
aggregationRelationship.setConnectionTableName(ConnectionTableName); aggregationRelationship.setConnectionTableName(connectionTableName);
//Util.addManyToMany //Util.addManyToMany
AggregationUtil.addManyToMany(sideTableById.get().getModelName(),ConnectionTableName,mainTableConnectionKey,sideTableConnectionKey,mainTableDocument); Document document = AggregationUtil.addManyToMany(sideTableById.get().getModelName(),connectionTableName,mainTableConnectionKey,sideTableConnectionKey,mainTableDocument);
tableInfoEx.setXml(document.asXML());
} }
aggregationRelationshipDao.save(aggregationRelationship); aggregationRelationshipDao.save(aggregationRelationship);
} }
} }
} }
...@@ -222,8 +222,10 @@ public class ModelImpl implements ModelService { ...@@ -222,8 +222,10 @@ public class ModelImpl implements ModelService {
* @Date 16:17 2021/3/5 * @Date 16:17 2021/3/5
**/ **/
public void insertValue(String tableName, Map map) { public void insertValue(String tableName, Map map) {
// CreateTableUtil createTableUtil = new CreateTableUtil(); /*
// Session newSession = createTableUtil.getSession(entityManagerFactory, xml); CreateTableUtil createTableUtil = new CreateTableUtil();
Session newSession = createTableUtil.getSession(entityManagerFactory, xml);
*/
Session newSession = sessionUtil.getSession(); Session newSession = sessionUtil.getSession();
......
package com.tykj.workflowcore.model_layer.service.impl;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.dao.TableInfoExDao;
import com.tykj.workflowcore.model_layer.entity.TableInfoEx;
import com.tykj.workflowcore.model_layer.service.TableInfoExService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.rmi.runtime.NewThreadAction;
import java.util.List;
import java.util.Optional;
/**
* @ClassName TableInfoExImpl
* @Description TODO
* @Author WWW
* @Date 2021/4/6 9:58
* @Version 1.0
*/
@Service
public class TableInfoExImpl implements TableInfoExService {
@Autowired
TableInfoExDao tableInfoExDao;
@Override
public List<TableInfoEx> findAll() {
return tableInfoExDao.findAll() ;
}
@Override
public String findXml(Integer id) {
Optional<TableInfoEx> byId = tableInfoExDao.findById(id);
if (byId.isPresent()){
return byId.get().getXml();
}
throw new ApiException("id错误!");
}
}
...@@ -2,14 +2,13 @@ package com.tykj.workflowcore.model_layer.utils; ...@@ -2,14 +2,13 @@ package com.tykj.workflowcore.model_layer.utils;
import com.tykj.workflowcore.base.result.ApiException; import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.model_layer.myEnum.AggregationType; import com.tykj.workflowcore.model_layer.myEnum.AggregationType;
import liquibase.pro.packaged.E;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.springframework.util.StringUtils;
import java.util.List;
/** /**
* @ClassName AggregationUtil * @ClassName AggregationUtil
...@@ -19,6 +18,7 @@ import java.util.List; ...@@ -19,6 +18,7 @@ import java.util.List;
* @Version 1.0 * @Version 1.0
*/ */
public class AggregationUtil { public class AggregationUtil {
//xml工具
public static Document getDocument(String xml){ public static Document getDocument(String xml){
try { try {
...@@ -45,7 +45,7 @@ public class AggregationUtil { ...@@ -45,7 +45,7 @@ public class AggregationUtil {
} }
public static Document addOneToMany(String sideTableName,String mainTableConnectionKey, String sideTableConnectionKey,Document document) { public static Document addOneToMany(String sideTableName,String mainTableConnectionKey, String sideTableConnectionKey,Document document) {
//创建ELEMTN //创建ELEMETN
Element setElement = createSetElement(mainTableConnectionKey,sideTableName, "", mainTableConnectionKey, sideTableConnectionKey, AggregationType.ONE_TO_MANY); Element setElement = createSetElement(mainTableConnectionKey,sideTableName, "", mainTableConnectionKey, sideTableConnectionKey, AggregationType.ONE_TO_MANY);
//创建结束 //创建结束
Element classElement = getNode(document); Element classElement = getNode(document);
...@@ -92,6 +92,7 @@ public class AggregationUtil { ...@@ -92,6 +92,7 @@ public class AggregationUtil {
return elementSet; return elementSet;
} }
// 字符串拼接
// private static String xmlStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + // private static String xmlStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
// "<!DOCTYPE hibernate-mapping PUBLIC\n" + // "<!DOCTYPE hibernate-mapping PUBLIC\n" +
// " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" + // " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
......
...@@ -431,6 +431,7 @@ class WorkflowCoreApplicationTests { ...@@ -431,6 +431,7 @@ class WorkflowCoreApplicationTests {
@Test @Test
public void testOldProperty() throws DocumentException { public void testOldProperty() throws DocumentException {
TableInfo stus = tableInfoDao.findByModelName("stus"); TableInfo stus = tableInfoDao.findByModelName("stus");
String xml = stus.getXml(); String xml = stus.getXml();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论