Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
0be29099
提交
0be29099
authored
4月 08, 2021
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型] 更新了聚合对象生成的方法,现在支持多层嵌套的聚合对象了
上级
1c97e5f0
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
114 行增加
和
77 行删除
+114
-77
AggregationController.java
...lowcore/model_layer/controller/AggregationController.java
+52
-2
Aggregation.java
...com/tykj/workflowcore/model_layer/entity/Aggregation.java
+11
-1
AggregationVO.java
...ykj/workflowcore/model_layer/entity/vo/AggregationVO.java
+4
-1
AggregationImpl.java
...orkflowcore/model_layer/service/impl/AggregationImpl.java
+0
-0
ModelImpl.java
...tykj/workflowcore/model_layer/service/impl/ModelImpl.java
+3
-3
AggregationUtil.java
.../tykj/workflowcore/model_layer/utils/AggregationUtil.java
+44
-68
CreateTableUtil.java
.../tykj/workflowcore/model_layer/utils/CreateTableUtil.java
+0
-2
没有找到文件。
src/main/java/com/tykj/workflowcore/model_layer/controller/AggregationController.java
浏览文件 @
0be29099
package
com
.
tykj
.
workflowcore
.
model_layer
.
controller
;
package
com
.
tykj
.
workflowcore
.
model_layer
.
controller
;
import
com.tykj.workflowcore.base.result.ResultObj
;
import
com.tykj.workflowcore.base.result.ResultUtil
;
import
com.tykj.workflowcore.base.result.ResultUtil
;
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.entity.vo.AggregationVO
;
import
com.tykj.workflowcore.model_layer.service.AggregationService
;
import
com.tykj.workflowcore.model_layer.service.AggregationService
;
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.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.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
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.RestController
;
import
java.util.HashMap
;
import
java.util.List
;
/**
/**
* @ClassName AggregationController
* @ClassName AggregationController
* @Description TODO
* @Description TODO
...
@@ -19,14 +28,55 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -19,14 +28,55 @@ import org.springframework.web.bind.annotation.RestController;
*/
*/
@RestController
@RestController
@RequestMapping
(
"/aggregation"
)
public
class
AggregationController
{
public
class
AggregationController
{
@Autowired
@Autowired
AggregationService
aggregationService
;
AggregationService
aggregationService
;
@PostMapping
(
"aggregation/add"
)
@Autowired
AggregationDao
aggregationDao
;
@PostMapping
(
"/add"
)
public
ResponseEntity
add
(
@RequestBody
AggregationVO
aggregationVO
)
{
public
ResponseEntity
add
(
@RequestBody
AggregationVO
aggregationVO
)
{
aggregationService
.
addAggregation
(
aggregationVO
);
aggregationService
.
addAggregation
(
aggregationVO
);
return
ResultUtil
.
success
(
""
,
"保存成功!"
);
return
ResultUtil
.
success
(
""
,
"保存成功!"
);
}
}
@PostMapping
(
"/test"
)
public
ResponseEntity
test
(
@RequestBody
AggregationVO
AggregationVO
)
{
String
result
=
""
;
Document
document
=
DocumentHelper
.
createDocument
();
Element
rootElement
=
DocumentHelper
.
createElement
(
"rootElement"
);
String
s
=
testDG
(
AggregationVO
.
getAggregations
(),
null
,
1
,
rootElement
).
asXML
();
document
.
add
(
rootElement
);
return
ResultUtil
.
success
(
aggregationDao
.
findById
(
3
),
"保存成功!"
);
}
//假设获得的是一份XML
public
Element
testDG
(
List
<
Aggregation
>
aggregations
,
Aggregation
parentAggregation
,
Integer
mainId
,
Element
element
){
//循环
Element
elementCLass
=
DocumentHelper
.
createElement
(
"class"
);
if
(
parentAggregation
!=
null
){
elementCLass
.
addAttribute
(
"name"
,
parentAggregation
.
getSideTableId
()+
"_"
);
}
else
{
elementCLass
.
addAttribute
(
"name"
,
mainId
+
"_"
);
}
for
(
int
i
=
0
;
i
<
aggregations
.
size
();
i
++)
{
Aggregation
aggregationChild
=
aggregations
.
get
(
i
);
if
(
aggregationChild
.
getAggregations
()!=
null
&&
aggregationChild
.
getAggregations
().
size
()>
0
){
Element
elementClassChild
=
testDG
(
aggregationChild
.
getAggregations
(),
aggregationChild
,
mainId
,
element
);
Element
elementSet
=
DocumentHelper
.
createElement
(
"set"
);
elementSet
.
addAttribute
(
"setName"
,
"c"
+
elementClassChild
.
attribute
(
"name"
).
getValue
());
elementCLass
.
add
(
elementSet
);
}
else
{
Element
elementSet
=
DocumentHelper
.
createElement
(
"set"
);
elementSet
.
addAttribute
(
"setName"
,
"c"
+
aggregationChild
.
getSideTableId
());
elementCLass
.
add
(
elementSet
);
}
}
element
.
add
(
elementCLass
);
return
elementCLass
;
}
}
}
src/main/java/com/tykj/workflowcore/model_layer/entity/Aggregation.java
浏览文件 @
0be29099
...
@@ -8,7 +8,8 @@ import lombok.NoArgsConstructor;
...
@@ -8,7 +8,8 @@ import lombok.NoArgsConstructor;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
import
org.hibernate.annotations.Where
;
import
javax.persistence.Entity
;
import
javax.persistence.*
;
import
java.util.List
;
/**
/**
* @ClassName AggregationRelationship
* @ClassName AggregationRelationship
...
@@ -42,4 +43,13 @@ public class Aggregation extends BaseEntity {
...
@@ -42,4 +43,13 @@ public class Aggregation extends BaseEntity {
@ApiModelProperty
(
"中间表名称"
)
@ApiModelProperty
(
"中间表名称"
)
private
String
connectionTableName
;
private
String
connectionTableName
;
@ApiModelProperty
(
"多层嵌套时会生成虚拟对象class 该class为了不影响其他真实对象所以用uuid命名"
)
private
String
uuidTableName
;
private
Integer
parentId
;
@OneToMany
(
cascade
=
CascadeType
.
ALL
)
//表示级练操作
@JoinColumn
(
name
=
"parentId"
)
List
<
Aggregation
>
aggregations
;
}
}
src/main/java/com/tykj/workflowcore/model_layer/entity/vo/AggregationVO.java
浏览文件 @
0be29099
...
@@ -24,6 +24,9 @@ public class AggregationVO {
...
@@ -24,6 +24,9 @@ public class AggregationVO {
@ApiModelProperty
(
"名称"
)
@ApiModelProperty
(
"名称"
)
private
String
name
;
private
String
name
;
@ApiModelProperty
(
"描述"
)
private
String
chineseName
;
@ApiModelProperty
(
"描述"
)
@ApiModelProperty
(
"描述"
)
private
String
description
;
private
String
description
;
...
@@ -31,7 +34,7 @@ public class AggregationVO {
...
@@ -31,7 +34,7 @@ public class AggregationVO {
private
Integer
mainTableId
;
private
Integer
mainTableId
;
@ApiModelProperty
(
"关系集合"
)
@ApiModelProperty
(
"关系集合"
)
private
List
<
Aggregation
>
list
s
;
private
List
<
Aggregation
>
aggregation
s
;
public
TableInfoEx
getTableInfoEx
(){
public
TableInfoEx
getTableInfoEx
(){
TableInfoEx
tableInfoEx
=
new
TableInfoEx
();
TableInfoEx
tableInfoEx
=
new
TableInfoEx
();
...
...
src/main/java/com/tykj/workflowcore/model_layer/service/impl/AggregationImpl.java
浏览文件 @
0be29099
差异被折叠。
点击展开。
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelImpl.java
浏览文件 @
0be29099
...
@@ -256,7 +256,7 @@ public class ModelImpl implements ModelService {
...
@@ -256,7 +256,7 @@ public class ModelImpl implements ModelService {
map
.
put
(
propertyNames
[
i
],
value
);
map
.
put
(
propertyNames
[
i
],
value
);
}
}
}
}
newSession
.
save
(
tableName
,
map
);
newSession
.
save
OrUpdate
(
tableName
,
map
);
newSession
.
getTransaction
().
begin
();
newSession
.
getTransaction
().
begin
();
newSession
.
getTransaction
().
commit
();
newSession
.
getTransaction
().
commit
();
newSession
.
close
();
newSession
.
close
();
...
@@ -307,8 +307,8 @@ public class ModelImpl implements ModelService {
...
@@ -307,8 +307,8 @@ public class ModelImpl implements ModelService {
columnVO
.
setPrimaryKey
(
0
);
columnVO
.
setPrimaryKey
(
0
);
}
}
columnVO
.
setFieldType
(
getTypeName
(
genericType
.
toString
()));
columnVO
.
setFieldType
(
getTypeName
(
genericType
.
toString
()));
columnVO
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
columnVO
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
columnVO
.
setFieldLength
(
setLength
(
genericType
.
toString
()));
//获得属性中文描述
//获得属性中文描述
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
...
@@ -340,7 +340,7 @@ public class ModelImpl implements ModelService {
...
@@ -340,7 +340,7 @@ public class ModelImpl implements ModelService {
ColumnInfo
columnInfo
=
new
ColumnInfo
();
ColumnInfo
columnInfo
=
new
ColumnInfo
();
columnInfo
.
setFieldName
(
columnVO
.
getFieldName
());
columnInfo
.
setFieldName
(
columnVO
.
getFieldName
());
columnInfo
.
setFieldType
(
columnVO
.
getFieldType
());
columnInfo
.
setFieldType
(
columnVO
.
getFieldType
());
columnInfo
.
setFieldLength
(
setLength
(
genericType
.
toString
()
));
columnInfo
.
setFieldLength
(
columnVO
.
getFieldLength
(
));
columnInfo
.
setFieldTitle
(
columnVO
.
getFieldTitle
());
columnInfo
.
setFieldTitle
(
columnVO
.
getFieldTitle
());
columnInfo
.
setPrimaryKey
(
columnVO
.
getPrimaryKey
());
columnInfo
.
setPrimaryKey
(
columnVO
.
getPrimaryKey
());
...
...
src/main/java/com/tykj/workflowcore/model_layer/utils/AggregationUtil.java
浏览文件 @
0be29099
...
@@ -6,8 +6,7 @@ import org.dom4j.Document;
...
@@ -6,8 +6,7 @@ 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
;
/**
/**
...
@@ -63,14 +62,54 @@ public class AggregationUtil {
...
@@ -63,14 +62,54 @@ public class AggregationUtil {
return
document
;
return
document
;
}
}
public
static
Element
createOneToOneElement
(
String
name
,
String
connectionKey
,
String
sideTableName
)
{
Element
element
=
DocumentHelper
.
createElement
(
"one-to-one"
);
element
.
addAttribute
(
"name"
,
name
);
element
.
addAttribute
(
"property-ref"
,
connectionKey
);
element
.
addAttribute
(
"class"
,
sideTableName
);
element
.
addAttribute
(
"cascade"
,
"save-update"
);
return
element
;
}
public
static
Element
createOneToManyElement
(
String
name
,
String
sideTableName
,
String
sideTableConnectionKey
)
{
//创建ELEMETN
Element
setElement
=
createSetElement
(
name
,
sideTableName
,
""
,
""
,
sideTableConnectionKey
,
AggregationType
.
ONE_TO_MANY
);
return
setElement
;
}
public
static
Element
createManyToManyElement
(
String
sideTableName
,
String
uuidTableName
,
String
connectionTableName
,
String
mainTableConnectionKey
,
String
sideTableConnectionKey
)
{
Element
setElement
=
createSetElement
(
sideTableName
,
StringUtils
.
isEmpty
(
uuidTableName
)?
sideTableName:
uuidTableName
,
connectionTableName
,
mainTableConnectionKey
,
sideTableConnectionKey
,
AggregationType
.
MANY_TO_MANY
);
return
setElement
;
}
public
static
Element
getNode
(
Document
document
)
{
public
static
Element
getNode
(
Document
document
)
{
return
document
.
getRootElement
().
element
(
"class"
);
return
document
.
getRootElement
().
element
(
"class"
);
}
}
public
static
Element
createSetElement
(
String
setName
,
String
sideTableName
,
String
connectionTableName
,
String
mainTableConnectionKey
,
String
sideTableConnectionKey
,
Integer
type
){
public
static
Element
createSetElement
(
String
name
,
//创建ELEMTN
String
sideTableName
,
String
connectionTableName
,
String
mainTableConnectionKey
,
String
sideTableConnectionKey
,
Integer
type
){
//创建element
Element
elementSet
=
DocumentHelper
.
createElement
(
"set"
);
Element
elementSet
=
DocumentHelper
.
createElement
(
"set"
);
elementSet
.
addAttribute
(
"name"
,
setN
ame
);
elementSet
.
addAttribute
(
"name"
,
n
ame
);
elementSet
.
addAttribute
(
"cascade"
,
"save-update"
);
elementSet
.
addAttribute
(
"cascade"
,
"save-update"
);
Element
elementKey
=
DocumentHelper
.
createElement
(
"key"
);
Element
elementKey
=
DocumentHelper
.
createElement
(
"key"
);
if
(
type
.
equals
(
AggregationType
.
MANY_TO_MANY
)){
if
(
type
.
equals
(
AggregationType
.
MANY_TO_MANY
)){
...
@@ -92,69 +131,6 @@ public class AggregationUtil {
...
@@ -92,69 +131,6 @@ public class AggregationUtil {
return
elementSet
;
return
elementSet
;
}
}
// 字符串拼接
// private static String xmlStart = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
// "<!DOCTYPE hibernate-mapping PUBLIC\n" +
// " \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
// " \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n" +
// "<hibernate-mapping>";
//
// private static String xmlEnd = "</hibernate-mapping>";
//
//
// public static String getOldProperty(String xml) {
// String property = "";
// Document document = null;
// try {
// document = DocumentHelper.parseText(xml);
// } catch (DocumentException e) {
// e.printStackTrace();
// }
// List<Element> elements = document.getRootElement().elements().get(0).elements();
// for (Element element : elements) {
// property = property + element.asXML();
// }
// return property;
// }
//
//
//
//
// public static String addOneToMany(String mainTable, String sideTable, String mainField, String xml) {
//
//
// String addStr =
// "<class entity-name= \"" +mainTable + "_" + sideTable + "\""+" table=\"" + mainTable +"\""+ ">\n" +
// getOldProperty(xml) +
// " <set name=\"" + sideTable + "_list" + "\""+" inverse=\"true\" lazy=\"true\">\n" +
// " <key column=\"" + mainField + "\""+"/>\n" +
// " <one-to-many class=\"" + sideTable +"\""+ "/>\n" +
// "</set>\n" +
// " </class>";
//
//
// return xmlStart+ addStr+xmlEnd;
// }
//
//
// public static String addManyToMany(String mainTable, String sideTable, String xml) {
//
// String entityName = mainTable + "_" + sideTable + "_ref";
//
// String addStr = "<class entity-name=\"" + entityName +"\""+ " table=\"" + mainTable +"\""+ ">\n" +
// " \n"
// +
// getOldProperty(xml)
// +
// " <set name=\"" + sideTable+"\"" + " table=\"" + entityName+"\"" + ">\n" +
// " \t<key column=\"" + mainTable + "_id" +"\""+ "/>\n" +
// " \t<many-to-many class=\"" + sideTable +"\""+ " column=\"" + sideTable +"\""+ "_id" + "/>\n" +
// " </set>" +
// "</class>";
// return xmlStart+ addStr+xmlEnd;
// }
//
...
...
src/main/java/com/tykj/workflowcore/model_layer/utils/CreateTableUtil.java
浏览文件 @
0be29099
...
@@ -37,9 +37,7 @@ public class CreateTableUtil {
...
@@ -37,9 +37,7 @@ public class CreateTableUtil {
}
}
xmlMapping
+=
" </class>\n"
+
xmlMapping
+=
" </class>\n"
+
"</hibernate-mapping>"
;
"</hibernate-mapping>"
;
return
xmlMapping
;
return
xmlMapping
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论