Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
478a97d1
提交
478a97d1
编写于
12月 22, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
规则执行结果动态存储
上级
f4d7bd11
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
66 行删除
+24
-66
ExecResultExService.java
.../ibizlab/core/extensions/service/ExecResultExService.java
+18
-45
DbEntityService.java
...ibizlab/core/lite/extensions/service/DbEntityService.java
+6
-21
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/ExecResultExService.java
浏览文件 @
478a97d1
...
@@ -2,11 +2,8 @@ package cn.ibizlab.core.extensions.service;
...
@@ -2,11 +2,8 @@ package cn.ibizlab.core.extensions.service;
import
cn.ibizlab.core.lite.extensions.service.DbEntityService
;
import
cn.ibizlab.core.lite.extensions.service.DbEntityService
;
import
cn.ibizlab.core.rule.domain.ExecResult
;
import
cn.ibizlab.core.rule.domain.ExecResult
;
import
cn.ibizlab.core.rule.domain.RuleEngine
;
import
cn.ibizlab.core.rule.service.IRuleEngineService
;
import
cn.ibizlab.core.rule.service.IRuleEngineService
;
import
cn.ibizlab.core.rule.service.impl.ExecResultServiceImpl
;
import
cn.ibizlab.core.rule.service.impl.ExecResultServiceImpl
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
...
@@ -14,8 +11,6 @@ import org.springframework.context.annotation.Primary;
...
@@ -14,8 +11,6 @@ import org.springframework.context.annotation.Primary;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
import
java.util.*
;
/**
/**
...
@@ -70,23 +65,23 @@ public class ExecResultExService extends ExecResultServiceImpl {
...
@@ -70,23 +65,23 @@ public class ExecResultExService extends ExecResultServiceImpl {
synchronized
(
objResultSaveAsyncLock
)
{
synchronized
(
objResultSaveAsyncLock
)
{
if
(
resultsSaveAsync
.
size
()
>
0
)
{
if
(
resultsSaveAsync
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
List
<
ExecResult
>>
entry
:
resultsSaveAsync
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
ExecResult
>>
entry
:
resultsSaveAsync
.
entrySet
())
{
String
e
ngine
Id
=
entry
.
getKey
();
String
e
xecResult
Id
=
entry
.
getKey
();
String
dsName
=
getDSNameByEngineId
(
engineId
);
String
[]
idArray
=
execResultId
.
split
(
"\\|"
);
List
<
ExecResult
>
execResults
=
entry
.
getValue
();
List
<
ExecResult
>
execResults
=
entry
.
getValue
();
List
<
ExecResult
>
tempExecResults
=
new
ArrayList
<>();
List
<
ExecResult
>
tempExecResults
=
new
ArrayList
<>();
if
(
execResults
.
size
()
>
0
)
{
if
(
execResults
.
size
()
>
0
&&
idArray
.
length
==
3
)
{
for
(
ExecResult
execResult
:
execResults
)
{
for
(
ExecResult
execResult
:
execResults
)
{
tempExecResults
.
add
(
execResult
);
tempExecResults
.
add
(
execResult
);
if
(
tempExecResults
.
size
()
>=
500
)
{
if
(
tempExecResults
.
size
()
>=
500
)
{
dbEntityService
.
saveResultBatch
(
tempExecResults
,
dsName
);
dbEntityService
.
saveResultBatch
(
tempExecResults
,
idArray
[
1
]
,
idArray
[
2
]
);
tempExecResults
.
clear
();
tempExecResults
.
clear
();
}
}
}
}
if
(
tempExecResults
.
size
()
>
0
)
{
if
(
tempExecResults
.
size
()
>
0
)
{
dbEntityService
.
saveResultBatch
(
tempExecResults
,
dsName
);
dbEntityService
.
saveResultBatch
(
tempExecResults
,
idArray
[
1
]
,
idArray
[
2
]
);
tempExecResults
.
clear
();
tempExecResults
.
clear
();
}
}
resultsSaveAsync
.
remove
(
e
ngine
Id
);
resultsSaveAsync
.
remove
(
e
xecResult
Id
);
}
}
}
}
}
}
...
@@ -124,23 +119,23 @@ public class ExecResultExService extends ExecResultServiceImpl {
...
@@ -124,23 +119,23 @@ public class ExecResultExService extends ExecResultServiceImpl {
synchronized
(
objResultDeleteAsyncLock
)
{
synchronized
(
objResultDeleteAsyncLock
)
{
if
(
resultsDeleteAsync
.
size
()
>
0
)
{
if
(
resultsDeleteAsync
.
size
()
>
0
)
{
for
(
Map
.
Entry
<
String
,
List
<
ExecResult
>>
entry
:
resultsDeleteAsync
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
List
<
ExecResult
>>
entry
:
resultsDeleteAsync
.
entrySet
())
{
String
engineId
=
entry
.
getKey
();
String
execResultId
=
entry
.
getKey
();
String
dsName
=
getDSNameByEngineId
(
engineId
);
List
<
ExecResult
>
execResults
=
entry
.
getValue
();
List
<
ExecResult
>
execResults
=
entry
.
getValue
();
List
<
ExecResult
>
tempExecResults
=
new
ArrayList
<>();
List
<
ExecResult
>
tempExecResults
=
new
ArrayList
<>();
if
(
execResults
.
size
()
>
0
)
{
String
[]
idArray
=
execResultId
.
split
(
"|"
);
if
(
execResults
.
size
()
>
0
&&
idArray
.
length
==
3
)
{
for
(
ExecResult
execResult
:
execResults
)
{
for
(
ExecResult
execResult
:
execResults
)
{
tempExecResults
.
add
(
execResult
);
tempExecResults
.
add
(
execResult
);
if
(
tempExecResults
.
size
()
>=
500
)
{
if
(
tempExecResults
.
size
()
>=
500
)
{
dbEntityService
.
clearResultBatch
(
tempExecResults
,
dsName
);
dbEntityService
.
clearResultBatch
(
tempExecResults
,
idArray
[
1
]
,
idArray
[
2
]
);
tempExecResults
.
clear
();
tempExecResults
.
clear
();
}
}
}
}
if
(
tempExecResults
.
size
()
>
0
)
{
if
(
tempExecResults
.
size
()
>
0
)
{
dbEntityService
.
clearResultBatch
(
tempExecResults
,
dsName
);
dbEntityService
.
clearResultBatch
(
tempExecResults
,
idArray
[
1
]
,
idArray
[
2
]
);
tempExecResults
.
clear
();
tempExecResults
.
clear
();
}
}
resultsDeleteAsync
.
remove
(
e
ngine
Id
);
resultsDeleteAsync
.
remove
(
e
xecResult
Id
);
}
}
}
}
}
}
...
@@ -154,30 +149,6 @@ public class ExecResultExService extends ExecResultServiceImpl {
...
@@ -154,30 +149,6 @@ public class ExecResultExService extends ExecResultServiceImpl {
return
et
;
return
et
;
}
}
/**
* 通过引擎获取数据源信息
*
* @param engineId
* @return
*/
private
String
getDSNameByEngineId
(
String
engineId
)
{
String
dsName
=
""
;
RuleEngine
engine
=
engineService
.
get
(
engineId
);
if
(!
ObjectUtils
.
isEmpty
(
engine
.
getExtParams
()))
{
JSONArray
array
=
JSONArray
.
parseArray
(
engine
.
getExtParams
());
for
(
int
a
=
0
;
a
<
array
.
size
();
a
++)
{
JSONObject
engineParam
=
array
.
getJSONObject
(
a
);
String
property
=
engineParam
.
getString
(
"property"
);
String
value
=
engineParam
.
getString
(
"value"
);
if
(!
StringUtils
.
isEmpty
(
property
)
&&
RuleEngineExService
.
Setting_ResultDataSource
.
equalsIgnoreCase
(
property
)
&&
!
StringUtils
.
isEmpty
(
value
))
{
return
value
;
}
}
}
return
dsName
;
}
/**
/**
* 将规则执行结果添加到待保存集合中
* 将规则执行结果添加到待保存集合中
*
*
...
@@ -186,15 +157,17 @@ public class ExecResultExService extends ExecResultServiceImpl {
...
@@ -186,15 +157,17 @@ public class ExecResultExService extends ExecResultServiceImpl {
*/
*/
private
void
addExecResult
(
Map
<
String
,
List
<
ExecResult
>>
execResultMap
,
ExecResult
execResult
)
{
private
void
addExecResult
(
Map
<
String
,
List
<
ExecResult
>>
execResultMap
,
ExecResult
execResult
)
{
Object
engineId
=
execResult
.
get
(
BaseEntityServiceImpl
.
Tag_EngineId
);
Object
engineId
=
execResult
.
get
(
BaseEntityServiceImpl
.
Tag_EngineId
);
Object
dsName
=
execResult
.
get
(
RuleEngineExService
.
Setting_ResultDataSource
);
Object
tabName
=
execResult
.
get
(
RuleEngineExService
.
Setting_ResultTableName
);
String
id
=
String
.
format
(
"%s|%s|%s"
,
engineId
,
dsName
,
tabName
);
if
(
ObjectUtils
.
isEmpty
(
engineId
))
{
if
(
ObjectUtils
.
isEmpty
(
engineId
))
{
log
.
error
(
"存储规则结果失败,无法数据[{}]的引擎标识!"
,
execResult
.
getId
());
log
.
error
(
"存储规则结果失败,无法数据[{}]的引擎标识!"
,
execResult
.
getId
());
return
;
return
;
}
}
String
strEngine
=
String
.
valueOf
(
engineId
);
if
(
execResultMap
.
containsKey
(
id
))
{
if
(
execResultMap
.
containsKey
(
engineId
))
{
execResultMap
.
get
(
id
).
add
(
execResult
);
execResultMap
.
get
(
engineId
).
add
(
execResult
);
}
else
{
}
else
{
execResultMap
.
put
(
strEngine
,
new
ArrayList
()
{{
execResultMap
.
put
(
id
,
new
ArrayList
()
{{
add
(
execResult
);
add
(
execResult
);
}});
}});
}
}
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/service/DbEntityService.java
浏览文件 @
478a97d1
...
@@ -2,7 +2,6 @@ package cn.ibizlab.core.lite.extensions.service;
...
@@ -2,7 +2,6 @@ package cn.ibizlab.core.lite.extensions.service;
import
cn.ibizlab.core.extensions.mapper.DbEntityMapper
;
import
cn.ibizlab.core.extensions.mapper.DbEntityMapper
;
import
cn.ibizlab.core.extensions.service.DstDataSourceExService
;
import
cn.ibizlab.core.extensions.service.DstDataSourceExService
;
import
cn.ibizlab.core.extensions.service.RuleEngineExService
;
import
cn.ibizlab.core.lite.extensions.domain.EntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.EntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.EntityObj
;
import
cn.ibizlab.core.lite.extensions.domain.EntityObj
;
import
cn.ibizlab.core.lite.extensions.domain.FieldModel
;
import
cn.ibizlab.core.lite.extensions.domain.FieldModel
;
...
@@ -170,15 +169,17 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
...
@@ -170,15 +169,17 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
@Autowired
@Autowired
private
DbEntityMapper
dbEntityMapper
;
private
DbEntityMapper
dbEntityMapper
;
public
int
saveResultBatch
(
List
<
ExecResult
>
execResults
,
String
dsName
)
{
public
int
saveResultBatch
(
List
<
ExecResult
>
execResults
,
String
dsName
,
String
tableName
)
{
int
result
=
0
;
int
result
=
0
;
try
{
try
{
if
(!
ObjectUtils
.
isEmpty
(
dsName
)){
if
(!
ObjectUtils
.
isEmpty
(
dsName
)
&&
!
dsName
.
equalsIgnoreCase
(
"null"
)
){
dstDataSourceService
.
initDataSource
(
dsName
);
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
}
if
(
StringUtils
.
isEmpty
(
tableName
)
||
tableName
.
equalsIgnoreCase
(
"null"
)){
tableName
=
Default_ResultTableName
;
}
Map
<
String
,
DataSource
>
dynamicDSMap
=
dynamicRoutingDataSource
.
getCurrentDataSources
();
Map
<
String
,
DataSource
>
dynamicDSMap
=
dynamicRoutingDataSource
.
getCurrentDataSources
();
String
tableName
=
getTableName
(
execResults
);
if
(!
ObjectUtils
.
isEmpty
(
dynamicDSMap
)
&&
dynamicDSMap
.
containsKey
(
dsName
))
{
if
(!
ObjectUtils
.
isEmpty
(
dynamicDSMap
)
&&
dynamicDSMap
.
containsKey
(
dsName
))
{
DataSource
ds
=
dynamicDSMap
.
get
(
dsName
);
DataSource
ds
=
dynamicDSMap
.
get
(
dsName
);
if
(
ds
instanceof
DruidDataSource
)
{
if
(
ds
instanceof
DruidDataSource
)
{
...
@@ -197,25 +198,9 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
...
@@ -197,25 +198,9 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
return
result
;
return
result
;
}
}
/**
public
int
clearResultBatch
(
List
<
ExecResult
>
execResults
,
String
dsName
,
String
tableName
)
{
* 获取规则结果表名
* @param execResults
* @return
*/
private
String
getTableName
(
List
<
ExecResult
>
execResults
)
{
String
tableName
=
Default_ResultTableName
;
for
(
ExecResult
execResult
:
execResults
){
if
(!
ObjectUtils
.
isEmpty
(
execResult
.
get
(
RuleEngineExService
.
Setting_ResultTableName
))){
return
String
.
valueOf
(
execResult
.
get
(
RuleEngineExService
.
Setting_ResultTableName
));
}
}
return
tableName
;
}
public
int
clearResultBatch
(
List
<
ExecResult
>
execResults
,
String
dsName
)
{
int
result
=
0
;
int
result
=
0
;
try
{
try
{
String
tableName
=
getTableName
(
execResults
);
dstDataSourceService
.
initDataSource
(
dsName
);
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
result
=
dbEntityMapper
.
clearBatch
(
execResults
,
tableName
);
result
=
dbEntityMapper
.
clearBatch
(
execResults
,
tableName
);
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录