Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
8a3081aa
提交
8a3081aa
authored
4月 08, 2021
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型]修改为多层嵌套数据 增加了根据聚合对象id查询所有相关字段信息的方法
上级
62c2ba5f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
128 行增加
和
13 行删除
+128
-13
AggregationDao.java
...com/tykj/workflowcore/model_layer/dao/AggregationDao.java
+1
-1
ColumnEXVO.java
...m/tykj/workflowcore/model_layer/entity/vo/ColumnEXVO.java
+36
-0
ModelHelper.java
...kj/workflowcore/model_layer/service/impl/ModelHelper.java
+91
-12
没有找到文件。
src/main/java/com/tykj/workflowcore/model_layer/dao/AggregationDao.java
浏览文件 @
8a3081aa
...
@@ -15,6 +15,6 @@ import java.util.List;
...
@@ -15,6 +15,6 @@ import java.util.List;
*/
*/
public
interface
AggregationDao
extends
JpaRepository
<
Aggregation
,
Integer
>,
JpaSpecificationExecutor
<
Aggregation
>
{
public
interface
AggregationDao
extends
JpaRepository
<
Aggregation
,
Integer
>,
JpaSpecificationExecutor
<
Aggregation
>
{
List
<
Aggregation
>
findAllByTableInfoExId
(
Integer
tableEx
Id
);
List
<
Aggregation
>
findAllByTableInfoExId
AAndParentId
(
Integer
tableExId
,
Integer
parent
Id
);
}
}
src/main/java/com/tykj/workflowcore/model_layer/entity/vo/ColumnEXVO.java
0 → 100644
浏览文件 @
8a3081aa
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
;
@ApiModel
(
"字段信息(聚合对象用)"
)
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
ColumnEXVO
{
@ApiModelProperty
(
"id"
)
private
Integer
id
;
@ApiModelProperty
(
"是否主键"
)
private
Integer
primaryKey
;
@ApiModelProperty
(
"字段类型"
)
private
String
fieldType
;
@ApiModelProperty
(
"字段名"
)
private
String
fieldName
;
@ApiModelProperty
(
"中文描述"
)
private
String
fieldTitle
;
@ApiModelProperty
(
"字段长度,有默认值"
)
private
Integer
fieldLength
;
@ApiModelProperty
(
"详细描述"
)
private
String
description
;
@ApiModelProperty
(
"聚合类型: -1无 0一对一 1一对多 2多对多"
)
private
Integer
aggregationType
;
@ApiModelProperty
(
"如果类型是个对象 该对象下的字段信息"
)
private
List
<
ColumnEXVO
>
columns
;
}
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelHelper.java
浏览文件 @
8a3081aa
...
@@ -9,14 +9,14 @@ import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
...
@@ -9,14 +9,14 @@ 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.Aggregation
;
import
com.tykj.workflowcore.model_layer.entity.Aggregation
;
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.TableInfoEx
;
import
com.tykj.workflowcore.model_layer.entity.TableInfoEx
;
import
com.tykj.workflowcore.model_layer.entity.vo.ColumnEXVO
;
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.ArrayList
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.stream.Collectors
;
import
java.util.List
;
import
java.util.Map
;
import
static
java
.
lang
.
String
.
format
;
import
static
java
.
lang
.
String
.
format
;
...
@@ -73,7 +73,18 @@ public class ModelHelper {
...
@@ -73,7 +73,18 @@ public class ModelHelper {
result
.
put
(
columnInfo
.
getFieldName
(),
null
);
result
.
put
(
columnInfo
.
getFieldName
(),
null
);
}
}
//查出相关聚合信息并做处理
//查出相关聚合信息并做处理
List
<
Aggregation
>
aggregations
=
aggregationDao
.
findAllByTableInfoExId
(
tableInfoExId
);
List
<
Aggregation
>
aggregations
=
aggregationDao
.
findAllByTableInfoExIdAAndParentId
(
tableInfoExId
,
null
);
getSubResult
(
result
,
aggregations
);
//做json转换并返回
try
{
return
new
ObjectMapper
().
writeValueAsString
(
result
);
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
throw
new
ApiException
(
"json转换时出现异常"
);
}
}
private
void
getSubResult
(
Map
<
String
,
Object
>
result
,
List
<
Aggregation
>
aggregations
)
{
for
(
Aggregation
aggregation
:
aggregations
)
{
for
(
Aggregation
aggregation
:
aggregations
)
{
List
<
ColumnInfo
>
subColumnInfos
=
columnInfoDao
.
findAllByDbId
(
aggregation
.
getSideTableId
());
List
<
ColumnInfo
>
subColumnInfos
=
columnInfoDao
.
findAllByDbId
(
aggregation
.
getSideTableId
());
Map
<
String
,
Object
>
subResult
=
new
HashMap
<>();
Map
<
String
,
Object
>
subResult
=
new
HashMap
<>();
...
@@ -83,6 +94,11 @@ public class ModelHelper {
...
@@ -83,6 +94,11 @@ public class ModelHelper {
String
subTableName
=
tableInfoDao
.
findById
(
aggregation
.
getSideTableId
())
String
subTableName
=
tableInfoDao
.
findById
(
aggregation
.
getSideTableId
())
.
orElseThrow
(()
->
new
RuntimeException
(
format
(
"未找到该id的数据:%s"
,
aggregation
.
getSideTableId
())))
.
orElseThrow
(()
->
new
RuntimeException
(
format
(
"未找到该id的数据:%s"
,
aggregation
.
getSideTableId
())))
.
getModelName
();
.
getModelName
();
//如果聚合信息下还有子聚合信息 则往下递归处理
boolean
hasSub
=
Objects
.
nonNull
(
aggregation
.
getAggregations
())
&&
!
aggregation
.
getAggregations
().
isEmpty
();
if
(
hasSub
)
{
getSubResult
(
subResult
,
aggregation
.
getAggregations
());
}
//判断关联类型 根据关联类型做不同处理 0:一对一 1:一对多 2:多对多
//判断关联类型 根据关联类型做不同处理 0:一对一 1:一对多 2:多对多
Integer
relationshipType
=
aggregation
.
getRelationship
();
Integer
relationshipType
=
aggregation
.
getRelationship
();
switch
(
relationshipType
)
{
switch
(
relationshipType
)
{
...
@@ -98,15 +114,78 @@ public class ModelHelper {
...
@@ -98,15 +114,78 @@ public class ModelHelper {
default
:
default
:
throw
new
ApiException
(
format
(
"未识别的聚合类型:%s"
,
relationshipType
));
throw
new
ApiException
(
format
(
"未识别的聚合类型:%s"
,
relationshipType
));
}
}
}
//做json转换并返回
try
{
return
new
ObjectMapper
().
writeValueAsString
(
result
);
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
throw
new
ApiException
(
"json转换时出现异常"
);
}
}
}
}
/**
* 根据聚合对象id 查询出其相关所有字段信息(包含对象嵌套字段)
*
* @param tableInfoExId 聚合对象id
* @return 聚合对象字段信息
*/
public
List
<
ColumnEXVO
>
getColumnEXVOs
(
Integer
tableInfoExId
)
{
List
<
ColumnEXVO
>
result
=
new
ArrayList
<>();
TableInfoEx
tableInfoEX
=
tableInfoExDao
.
findById
(
tableInfoExId
)
.
orElseThrow
(()
->
new
ApiException
(
format
(
"未找到该id的数据:%s"
,
tableInfoExId
)));
//根据主表id查出主表部分字段信息 并加入Map结果
List
<
ColumnInfo
>
columnInfos
=
columnInfoDao
.
findAllByDbId
(
tableInfoEX
.
getMainTableId
());
//普通字段部分
List
<
ColumnEXVO
>
part1
=
columnInfos
.
stream
()
.
map
(
this
::
columnEXVO
)
.
collect
(
Collectors
.
toList
());
//对象字段部分
List
<
Aggregation
>
aggregations
=
aggregationDao
.
findAllByTableInfoExIdAAndParentId
(
tableInfoExId
,
null
);
List
<
ColumnEXVO
>
part2
=
columnEXVOs
(
aggregations
);
result
.
addAll
(
part1
);
result
.
addAll
(
part2
);
return
result
;
}
private
ColumnEXVO
columnEXVO
(
ColumnInfo
columnInfo
)
{
return
new
ColumnEXVO
(
columnInfo
.
getId
(),
columnInfo
.
getPrimaryKey
(),
columnInfo
.
getFieldType
(),
columnInfo
.
getFieldName
(),
columnInfo
.
getFieldTitle
(),
columnInfo
.
getFieldLength
(),
columnInfo
.
getDescription
(),
-
1
,
new
ArrayList
<>()
);
}
private
List
<
ColumnEXVO
>
columnEXVOs
(
List
<
Aggregation
>
aggregations
)
{
List
<
ColumnEXVO
>
result
=
new
ArrayList
<>();
for
(
Aggregation
aggregation
:
aggregations
)
{
List
<
ColumnInfo
>
columnInfos
=
columnInfoDao
.
findAllByDbId
(
aggregation
.
getSideTableId
());
List
<
ColumnEXVO
>
columns
=
columnInfos
.
stream
()
.
map
(
this
::
columnEXVO
)
.
collect
(
Collectors
.
toList
());
TableInfo
tableInfo
=
tableInfoDao
.
findById
(
aggregation
.
getSideTableId
())
.
orElseThrow
(()
->
new
RuntimeException
(
format
(
"未找到该id的数据:%s"
,
aggregation
.
getSideTableId
())));
//如果聚合信息下还有子聚合信息 则往下递归获取字段信息
boolean
hasSub
=
Objects
.
nonNull
(
aggregation
.
getAggregations
())
&&
!
aggregation
.
getAggregations
().
isEmpty
();
if
(
hasSub
)
{
List
<
ColumnEXVO
>
objColumns
=
columnEXVOs
(
aggregation
.
getAggregations
());
columns
.
addAll
(
objColumns
);
}
ColumnEXVO
columnEXVO
=
new
ColumnEXVO
(
null
,
0
,
Object
.
class
.
getTypeName
(),
tableInfo
.
getModelName
(),
tableInfo
.
getModelTitle
(),
-
1
,
tableInfo
.
getDescription
(),
aggregation
.
getRelationship
(),
columns
);
result
.
add
(
columnEXVO
);
}
return
result
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论