Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
ab4aa54d
提交
ab4aa54d
编写于
7月 27, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交
上级
46ca7a2a
变更
6
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
178 行增加
和
83 行删除
+178
-83
ExecResultRepository.java
.../cn/ibizlab/core/extensions/cql/ExecResultRepository.java
+15
-1
FetchParam.java
.../main/java/cn/ibizlab/core/extensions/dto/FetchParam.java
+2
-1
ExecResultExMapper.java
...cn/ibizlab/core/extensions/mapper/ExecResultExMapper.java
+7
-0
BuildResultService.java
...n/ibizlab/core/extensions/service/BuildResultService.java
+40
-81
ExecResultExService.java
.../ibizlab/core/extensions/service/ExecResultExService.java
+76
-0
ExecResultExMapper.xml
...n/resources/mapper/rule/execresult/ExecResultExMapper.xml
+38
-0
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/cql/ExecResultRepository.java
浏览文件 @
ab4aa54d
...
...
@@ -174,6 +174,20 @@ public class ExecResultRepository {
*/
public
ResultSet
getPageData
(
String
ruleid
,
PagingState
pagingState
,
Integer
retValue
,
String
dims
,
Timestamp
start
,
Timestamp
end
)
{
final
int
RESULTS_PER_PAGE
=
1000
;
return
getPageData
(
ruleid
,
pagingState
,
RESULTS_PER_PAGE
,
retValue
,
dims
,
start
,
end
);
}
/**
* 根据规则ID、单位和时间查询相应的规则结果数据
*
* @param ruleid
* @param retValue
* @param dims
* @param start
* @param end
* @return
*/
public
ResultSet
getPageData
(
String
ruleid
,
PagingState
pagingState
,
int
pageSize
,
Integer
retValue
,
String
dims
,
Timestamp
start
,
Timestamp
end
)
{
LocalDate
st
=
ExecResult
.
time2LocalDate
(
start
);
LocalDate
ed
=
ExecResult
.
time2LocalDate
(
end
);
Statement
statement
=
select
().
column
(
"keyvaluefield"
).
...
...
@@ -182,7 +196,7 @@ public class ExecResultRepository {
and
(
eq
(
"retvalue"
,
retValue
)).
and
(
eq
(
"dimfield"
,
dims
)).
and
(
gte
(
"timefield"
,
st
)).
and
(
lte
(
"timefield"
,
ed
)).
setReadTimeoutMillis
(
200000
);
statement
.
setFetchSize
(
RESULTS_PER_PAGE
);
statement
.
setFetchSize
(
pageSize
);
if
(
pagingState
!=
null
)
{
statement
.
setPagingState
(
pagingState
);
}
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/dto/FetchParam.java
浏览文件 @
ab4aa54d
...
...
@@ -53,7 +53,8 @@ public class FetchParam {
private
Timestamp
endTime
;
private
int
page
=
0
;
private
int
size
=
100
;
private
int
size
=
1000
;
private
int
total
=
0
;
private
boolean
filled
=
false
;
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/mapper/ExecResultExMapper.java
浏览文件 @
ab4aa54d
...
...
@@ -3,8 +3,11 @@ package cn.ibizlab.core.extensions.mapper;
import
cn.ibizlab.core.lite.extensions.domain.EntityObj
;
import
cn.ibizlab.core.rule.domain.ExecResult
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
org.apache.ibatis.annotations.Param
;
import
java.sql.Timestamp
;
import
java.util.List
;
public
interface
ExecResultExMapper
extends
BaseMapper
<
EntityObj
>{
...
...
@@ -14,5 +17,9 @@ public interface ExecResultExMapper extends BaseMapper<EntityObj>{
int
replaceBatchByPG
(
@Param
(
"list"
)
List
<
ExecResult
>
var1
,
@Param
(
"resultTableName"
)
String
tableName
);
int
clearBatch
(
@Param
(
"list"
)
List
<
ExecResult
>
var1
,
@Param
(
"resultTableName"
)
String
tableName
);
List
<
ExecResult
>
sumResult
(
@Param
(
"resultTableName"
)
String
tableName
,
@Param
(
"ruleids"
)
List
<
String
>
ruleids
,
@Param
(
"dimfields"
)
List
<
String
>
dimfields
,
@Param
(
"from"
)
Timestamp
from
,
@Param
(
"to"
)
Timestamp
to
);
List
<
ExecResult
>
avgResult
(
@Param
(
"resultTableName"
)
String
tableName
,
@Param
(
"ruleids"
)
List
<
String
>
ruleids
,
@Param
(
"dimfields"
)
List
<
String
>
dimfields
,
@Param
(
"from"
)
Timestamp
from
,
@Param
(
"to"
)
Timestamp
to
);
Page
<
ExecResult
>
lookupResult
(
IPage
page
,
@Param
(
"resultTableName"
)
String
tableName
,
@Param
(
"columns"
)
String
columns
,
@Param
(
"ruleid"
)
String
ruleid
,
@Param
(
"dimfield"
)
String
dimfield
,
@Param
(
"from"
)
Timestamp
from
,
@Param
(
"to"
)
Timestamp
to
);
}
\ No newline at end of file
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/BuildResultService.java
浏览文件 @
ab4aa54d
...
...
@@ -21,7 +21,6 @@ import cn.ibizlab.util.helper.Setting;
import
com.alibaba.fastjson.JSONArray
;
import
com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.datastax.driver.core.PagingState
;
import
com.datastax.driver.core.ResultSet
;
import
com.datastax.driver.core.Row
;
...
...
@@ -30,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.domain.Page
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -78,9 +78,13 @@ public class BuildResultService {
@Autowired
@Lazy
private
IExecResultService
execResult
Service
;
private
ExecResultExService
execResultEx
Service
;
@Value
(
"${defaultResultDataSource:default}"
)
private
String
Default_ResultDataSource
;
@Value
(
"${defaultResultTableName:IBZRULERESULT}"
)
private
String
Default_ResultTableName
;
private
void
prepareFetchParam
(
FetchParam
fetchParam
)
...
...
@@ -194,9 +198,9 @@ public class BuildResultService {
String
resultDataSource
=
Setting
.
getValue
(
daBuild
.
getExtParams
(),
"resultDataSource"
);
String
resultTableName
=
Setting
.
getValue
(
daBuild
.
getExtParams
(),
"resultTableName"
);
if
(
StringUtils
.
isEmpty
(
resultDataSource
))
resultDataSource
=
"default"
;
resultDataSource
=
Default_ResultDataSource
;
if
(
StringUtils
.
isEmpty
(
resultTableName
))
resultTableName
=
"IBZRULERESULT"
;
resultTableName
=
Default_ResultTableName
;
String
table
=
resultDataSource
+
"|"
+
resultTableName
;
if
(!
fetchParam
.
getDimTables
().
containsKey
(
table
))
fetchParam
.
getDimTables
().
put
(
table
,
builds
.
get
(
key
));
...
...
@@ -246,11 +250,6 @@ public class BuildResultService {
String
dsName
=
args
[
0
];
String
tableName
=
args
[
1
];
try
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
Set
<
String
>
tmpSet
=
new
LinkedHashSet
<>();
for
(
String
id:
tab
.
get
(
key
))
{
...
...
@@ -259,22 +258,11 @@ public class BuildResultService {
}
if
(
tmpSet
.
size
()>
0
)
{
List
<
ExecResult
>
list
=
execResultService
.
list
(
Wrappers
.<
ExecResult
>
query
()
.
select
(
"ruleid"
,
"1 as retvalue"
,
"dimfield"
,
"sum(metricfield) as metricfield"
)
.
in
(
"ruleid"
,
tmpSet
).
eq
(
"retvalue"
,
1
).
in
(
"dimfield"
,
fetchParam
.
getDimValues
())
.
ge
(
"timefield"
,
startTime
).
le
(
"timefield"
,
endTime
)
.
groupBy
(
"ruleid"
,
"dimfield"
));
List
<
ExecResult
>
list
=
execResultExService
.
avgResult
(
dsName
,
tableName
,
new
ArrayList
<>(
tmpSet
),
fetchParam
.
getDimValues
(),
startTime
,
endTime
);
list
.
forEach
(
item
->{
ret
.
add
(
new
BuildResult
().
setSqlResult
(
item
));
});
}
}
catch
(
Exception
ex
)
{
log
.
error
(
"汇总分析结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
}
...
...
@@ -318,11 +306,7 @@ public class BuildResultService {
String
dsName
=
args
[
0
];
String
tableName
=
args
[
1
];
try
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
Set
<
String
>
tmpSet
=
new
LinkedHashSet
<>();
for
(
String
id:
tab
.
get
(
key
))
{
...
...
@@ -331,22 +315,12 @@ public class BuildResultService {
}
if
(
tmpSet
.
size
()>
0
)
{
List
<
ExecResult
>
list
=
execResultService
.
list
(
Wrappers
.<
ExecResult
>
query
()
.
select
(
"ruleid"
,
"1 as retvalue"
,
"dimfield"
,
"avg(metricfield) as metricfield"
)
.
in
(
"ruleid"
,
tab
.
get
(
key
)).
eq
(
"retvalue"
,
1
).
in
(
"dimfield"
,
fetchParam
.
getDimValues
())
.
ge
(
"timefield"
,
startTime
).
le
(
"timefield"
,
endTime
)
.
groupBy
(
"ruleid"
,
"dimfield"
));
List
<
ExecResult
>
list
=
execResultExService
.
sumResult
(
dsName
,
tableName
,
new
ArrayList
<>(
tmpSet
),
fetchParam
.
getDimValues
(),
startTime
,
endTime
);
list
.
forEach
(
item
->{
ret
.
add
(
new
BuildResult
().
setSqlResult
(
item
));
});
}
}
catch
(
Exception
ex
)
{
log
.
error
(
"汇总分析结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
}
...
...
@@ -363,7 +337,7 @@ public class BuildResultService {
PagingState
pagingState
=
null
;
for
(
int
i
=
0
;
i
<=
fetchParam
.
getPage
();
i
++)
{
if
(
fetchParam
.
getPage
()
==
i
)
{
ResultSet
rs
=
execResultRepository
.
getPageData
(
fetchParam
.
getMetricId
(),
pagingState
,
1
,
fetchParam
.
getDimValue
(),
fetchParam
.
getStartTime
(),
fetchParam
.
getEndTime
());
ResultSet
rs
=
execResultRepository
.
getPageData
(
fetchParam
.
getMetricId
(),
pagingState
,
fetchParam
.
getSize
(),
1
,
fetchParam
.
getDimValue
(),
fetchParam
.
getStartTime
(),
fetchParam
.
getEndTime
());
int
remaining
=
rs
.
getAvailableWithoutFetching
();
for
(
Row
row
:
rs
)
{
ret
.
add
(
row
.
getString
(
"keyvaluefield"
));
...
...
@@ -373,7 +347,7 @@ public class BuildResultService {
}
break
;
}
else
{
ResultSet
rs
=
execResultRepository
.
getPageData
(
fetchParam
.
getMetricId
(),
pagingState
,
1
,
fetchParam
.
getDimValue
(),
fetchParam
.
getStartTime
(),
fetchParam
.
getEndTime
());
ResultSet
rs
=
execResultRepository
.
getPageData
(
fetchParam
.
getMetricId
(),
pagingState
,
fetchParam
.
getSize
(),
1
,
fetchParam
.
getDimValue
(),
fetchParam
.
getStartTime
(),
fetchParam
.
getEndTime
());
pagingState
=
rs
.
getExecutionInfo
().
getPagingState
();
}
}
...
...
@@ -388,25 +362,10 @@ public class BuildResultService {
String
dsName
=
args
[
0
];
String
tableName
=
args
[
1
];
try
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
Page
<
ExecResult
>
page
=
execResultService
.
page
(
new
Page
(
fetchParam
.
getPage
()+
1
,
fetchParam
.
getSize
()),
Wrappers
.<
ExecResult
>
query
()
.
select
(
"keyvaluefield"
)
.
eq
(
"ruleid"
,
fetchParam
.
getMetricId
()).
eq
(
"retvalue"
,
1
).
eq
(
"dimfield"
,
fetchParam
.
getDimValue
())
.
ge
(
"timefield"
,
fetchParam
.
getStartTime
()).
le
(
"timefield"
,
fetchParam
.
getEndTime
()));
page
.
getRecords
().
forEach
(
item
->{
Page
<
ExecResult
>
page
=
execResultExService
.
lookupResult
(
fetchParam
.
getPage
(),
fetchParam
.
getSize
(),
dsName
,
tableName
,
"keyvaluefield"
,
fetchParam
.
getMetricId
(),
fetchParam
.
getDimValue
(),
fetchParam
.
getStartTime
(),
fetchParam
.
getEndTime
());
page
.
getContent
().
forEach
(
item
->{
ret
.
add
(
item
.
getKeyValueField
());
});
}
catch
(
Exception
ex
)
{
log
.
error
(
"反查分析结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
});
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/ExecResultExService.java
浏览文件 @
ab4aa54d
...
...
@@ -7,17 +7,23 @@ import cn.ibizlab.core.rule.service.impl.ExecResultServiceImpl;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.baomidou.dynamic.datasource.DynamicRoutingDataSource
;
import
com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
javax.sql.DataSource
;
import
java.sql.Timestamp
;
import
java.util.*
;
/**
...
...
@@ -246,5 +252,75 @@ public class ExecResultExService extends ExecResultServiceImpl {
return
result
;
}
public
List
<
ExecResult
>
sumResult
(
String
dsName
,
String
tableName
,
List
<
String
>
ruleids
,
List
<
String
>
dimfields
,
Timestamp
from
,
Timestamp
to
)
{
List
<
ExecResult
>
result
=
null
;
try
{
if
(!
Default_ResultDataSource
.
equalsIgnoreCase
(
dsName
)){
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
result
=
execResultExMapper
.
sumResult
(
tableName
,
ruleids
,
dimfields
,
from
,
to
);
}
catch
(
Exception
ex
)
{
result
=
new
ArrayList
<>();
log
.
error
(
"存储规则结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
Default_ResultDataSource
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
return
result
;
}
public
List
<
ExecResult
>
avgResult
(
String
dsName
,
String
tableName
,
List
<
String
>
ruleids
,
List
<
String
>
dimfields
,
Timestamp
from
,
Timestamp
to
)
{
List
<
ExecResult
>
result
=
null
;
try
{
if
(!
Default_ResultDataSource
.
equalsIgnoreCase
(
dsName
)){
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
result
=
execResultExMapper
.
avgResult
(
tableName
,
ruleids
,
dimfields
,
from
,
to
);
}
catch
(
Exception
ex
)
{
result
=
new
ArrayList
<>();
log
.
error
(
"存储规则结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
Default_ResultDataSource
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
return
result
;
}
public
Page
<
ExecResult
>
lookupResult
(
int
current
,
int
size
,
String
dsName
,
String
tableName
,
String
columns
,
String
ruleid
,
String
dimfield
,
Timestamp
from
,
Timestamp
to
)
{
if
(
StringUtils
.
isEmpty
(
columns
))
columns
=
"*"
;
List
<
ExecResult
>
result
=
null
;
long
total
=
0
;
try
{
if
(!
Default_ResultDataSource
.
equalsIgnoreCase
(
dsName
)){
dstDataSourceService
.
initDataSource
(
dsName
);
DynamicDataSourceContextHolder
.
push
(
dsName
);
}
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
ExecResult
>
pages
=
execResultExMapper
.
lookupResult
(
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
(
current
+
1
,
size
),
tableName
,
columns
,
ruleid
,
dimfield
,
from
,
to
);
result
=
pages
.
getRecords
();
total
=
pages
.
getTotal
();
}
catch
(
Exception
ex
)
{
result
=
new
ArrayList
<>();
log
.
error
(
"存储规则结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
Default_ResultDataSource
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
return
new
PageImpl
<
ExecResult
>(
result
,
PageRequest
.
of
(
current
,
size
),
total
);
}
}
ibzdst-core/src/main/resources/mapper/rule/execresult/ExecResultExMapper.xml
浏览文件 @
ab4aa54d
...
...
@@ -86,5 +86,43 @@
</delete>
<select
id=
"sumResult"
>
select ruleid, 1 as retvalue,dimfield,sum(metricfield) as metricfield from ${resultTableName} where ruleid in
<foreach
item=
"id"
index=
"index"
collection=
"ruleids"
open=
"("
separator=
","
close=
")"
>
#{id}
</foreach>
and RETVALUE=1 and DIMFIELD in
<foreach
item=
"id"
index=
"index"
collection=
"dimfields"
open=
"("
separator=
","
close=
")"
>
#{id}
</foreach>
and TIMEFIELD
<![CDATA[ >= ]]>
#{from} and TIMEFIELD
<![CDATA[ <= ]]>
#{to}
group by ruleid,dimfield
</select>
<select
id=
"avgResult"
>
select ruleid, 1 as retvalue,dimfield,avg(metricfield) as metricfield from ${resultTableName} where ruleid in
<foreach
item=
"id"
index=
"index"
collection=
"ruleids"
open=
"("
separator=
","
close=
")"
>
#{id}
</foreach>
and RETVALUE=1 and DIMFIELD in
<foreach
item=
"id"
index=
"index"
collection=
"dimfields"
open=
"("
separator=
","
close=
")"
>
#{id}
</foreach>
and TIMEFIELD
<![CDATA[ >= ]]>
#{from} and TIMEFIELD
<![CDATA[ <= ]]>
#{to}
group by ruleid,dimfield
</select>
<select
id=
"lookupResult"
>
select ${columns} from ${resultTableName} where ruleid = #{ruleid}
and RETVALUE=1 and DIMFIELD = #{dimfield}
and TIMEFIELD
<![CDATA[ >= ]]>
#{from} and TIMEFIELD
<![CDATA[ <= ]]>
#{to}
</select>
</mapper>
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录