Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
9616956e
提交
9616956e
编写于
6月 20, 2023
作者:
xuhui961310148
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update:报表查询支持忽略时间范围,使用默认时间查询结果,报表导出支持计算表达式列导出
上级
aa3c45d6
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
91 行增加
和
12 行删除
+91
-12
BuildResultService.java
...n/ibizlab/core/extensions/service/BuildResultService.java
+91
-12
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/BuildResultService.java
浏览文件 @
9616956e
...
...
@@ -40,6 +40,8 @@ import org.springframework.util.Assert;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
javax.script.ScriptEngine
;
import
javax.script.ScriptEngineManager
;
import
java.io.File
;
import
java.math.BigDecimal
;
import
java.nio.file.Files
;
...
...
@@ -263,6 +265,15 @@ public class BuildResultService {
fetchParam
.
getDimTables
().
put
(
table
,
builds
.
get
(
key
));
else
fetchParam
.
getDimTables
().
get
(
table
).
addAll
(
builds
.
get
(
key
));
String
ignoreTime
=
Setting
.
getValue
(
daBuild
.
getExtParams
(),
"ignoreTime"
);
if
(
"Y"
.
equals
(
ignoreTime
)){
// 是否忽略查询时间范围(Y:是,N:否),使用默认时间范围
fetchParam
.
getMetrics
().
forEach
((
metricId
,
daMetric
)
->{
if
(
daBuild
.
getBuildId
().
equals
(
daMetric
.
getBuildId
())){
daMetric
.
set
(
"ignoreTime"
,
"Y"
);
}
});
}
}
}
...
...
@@ -507,6 +518,7 @@ public class BuildResultService {
Set
<
String
>
sum
=
new
LinkedHashSet
<>();
Set
<
String
>
avg
=
new
LinkedHashSet
<
String
>();
Set
<
String
>
countDistExt1
=
new
LinkedHashSet
<
String
>();
Set
<
String
>
ignoreTime
=
new
LinkedHashSet
<>();
Set
<
String
>
sum_yoy
=
new
LinkedHashSet
<>();
Set
<
String
>
sum_mom
=
new
LinkedHashSet
<>();
...
...
@@ -554,15 +566,22 @@ public class BuildResultService {
}
else
{
sum
.
add
(
metric
.
getMetricId
());
if
(
"YOY"
.
equals
(
metric
.
getExtOp
()))
sum_yoy
.
add
(
metric
.
getMetricId
());
else
if
(
"MOM"
.
equals
(
metric
.
getExtOp
()))
sum_mom
.
add
(
metric
.
getMetricId
());
else
if
(
"Y3"
.
equals
(
metric
.
getExtOp
()))
sum_y3
.
add
(
metric
.
getMetricId
());
else
if
(
"PER"
.
equals
(
metric
.
getExtOp
())
||
"PER_ORI"
.
equals
(
metric
.
getExtOp
()))
sum_per
.
add
(
metric
);
if
(
"Y"
.
equals
(
metric
.
get
(
"ignoreTime"
)))
{
ignoreTime
.
add
(
metric
.
getMetricId
());
}
else
{
sum
.
add
(
metric
.
getMetricId
());
if
(
"YOY"
.
equals
(
metric
.
getExtOp
()))
sum_yoy
.
add
(
metric
.
getMetricId
());
else
if
(
"MOM"
.
equals
(
metric
.
getExtOp
()))
sum_mom
.
add
(
metric
.
getMetricId
());
else
if
(
"Y3"
.
equals
(
metric
.
getExtOp
()))
sum_y3
.
add
(
metric
.
getMetricId
());
else
if
(
"PER"
.
equals
(
metric
.
getExtOp
())
||
"PER_ORI"
.
equals
(
metric
.
getExtOp
()))
sum_per
.
add
(
metric
);
}
}
}
List
<
String
>
dims
=
new
ArrayList
<>();
...
...
@@ -624,6 +643,13 @@ public class BuildResultService {
List
<
BuildResult
>
listcountDistExt1
=
countDistExt1
(
fetchParam
,
countDistExt1
,
null
,
null
);
list
.
addAll
(
listcountDistExt1
);
}
if
(
ignoreTime
.
size
()>
0
)
{
Timestamp
start
=
Timestamp
.
valueOf
(
"1970-01-01 00:00:00"
);
Timestamp
end
=
new
Timestamp
(
System
.
currentTimeMillis
());
List
<
BuildResult
>
listignoreTime
=
sum
(
fetchParam
,
ignoreTime
,
start
,
end
);
list
.
addAll
(
listignoreTime
);
}
for
(
BuildResult
res:
list
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimField
()))
...
...
@@ -934,7 +960,7 @@ public class BuildResultService {
titleMap
.
put
(
"content"
,
DataObject
.
dayFormat
.
format
(
result
.
getStartTime
()).
concat
(
"到"
).
concat
(
DataObject
.
dayFormat
.
format
(
result
.
getEndTime
())));
titleMap
.
put
(
"fieldName"
,
"filter"
);
titleList
.
add
(
titleMap
);
this
.
onHandleColumn
(
result
.
getHeaders
(),
titleList
,
"filter"
);
this
.
onHandleColumn
(
result
.
getHeaders
(),
titleList
,
"filter"
,
result
.
getRows
()
);
}
...
...
@@ -943,7 +969,7 @@ public class BuildResultService {
}
public
List
<
Map
<
String
,
String
>>
onHandleColumn
(
List
<
VMConfig
>
headers
,
List
<
Map
<
String
,
String
>>
columnDataList
,
String
pid
)
{
public
List
<
Map
<
String
,
String
>>
onHandleColumn
(
List
<
VMConfig
>
headers
,
List
<
Map
<
String
,
String
>>
columnDataList
,
String
pid
,
List
<
FetchItem
>
rows
)
{
if
(
columnDataList
==
null
)
columnDataList
=
new
ArrayList
<
Map
<
String
,
String
>>();
if
(
StringUtils
.
isEmpty
(
pid
))
pid
=
"0"
;
for
(
VMConfig
col:
headers
){
...
...
@@ -955,8 +981,11 @@ public class BuildResultService {
titleMap
.
put
(
"content"
,
col
.
getHeaderName
());
titleMap
.
put
(
"fieldName"
,
field
);
columnDataList
.
add
(
titleMap
);
if
(
StringUtils
.
isEmpty
(
col
.
getField
())
&&
!
StringUtils
.
isEmpty
(
col
.
getValueGetter
())){
processExpression
(
field
,
col
.
getValueGetter
(),
rows
);
}
if
(!
ObjectUtils
.
isEmpty
(
col
.
getChildren
()))
onHandleColumn
(
col
.
getChildren
(),
columnDataList
,
field
);
onHandleColumn
(
col
.
getChildren
(),
columnDataList
,
field
,
rows
);
}
return
columnDataList
;
}
...
...
@@ -983,4 +1012,54 @@ public class BuildResultService {
return
null
;
}
/**
* 处理计算表达式并赋值到对应行数据列字段
* @param field 报表计算表达式列id
* @param valueGetter 计算表达式 示例:parseFloat((data['a31f863b14c6299bc4ed1b98badbb6d0']/((data['0fdd75f26e5d8a6c5c7fb0eb2a9e1f84'])>0?(data['0fdd75f26e5d8a6c5c7fb0eb2a9e1f84']):1)).toFixed(2))
* @param rows 报表结果行数据
*/
private
void
processExpression
(
String
field
,
String
valueGetter
,
List
<
FetchItem
>
rows
){
if
(
valueGetter
.
indexOf
(
"data['"
)
>=
0
){
String
[]
split
=
valueGetter
.
split
(
"data\\['"
);
if
(
split
.
length
>
0
){
Map
<
String
,
Object
>
fieldSet
=
new
LinkedHashMap
<>();
for
(
int
i
=
0
;
i
<
split
.
length
;
i
++)
{
String
str
=
split
[
i
];
// 获取表达式中的列id
if
(!
StringUtils
.
isEmpty
(
str
)
&&
str
.
indexOf
(
"']"
)
>
0
){
String
strField
=
str
.
substring
(
0
,
str
.
indexOf
(
"']"
));
fieldSet
.
put
(
strField
,
"1"
);
}
}
if
(
fieldSet
.
size
()
>
0
){
// 创建ScriptEngineManager对象
ScriptEngineManager
scriptEngineManager
=
new
ScriptEngineManager
();
// 获取名为“JavaScript(或者js)”的ScriptEngine对象
ScriptEngine
scriptEngine
=
scriptEngineManager
.
getEngineByName
(
"JavaScript"
);
for
(
FetchItem
fetchItem
:
rows
)
{
String
script
=
valueGetter
;
try
{
// 将表达式中的列id取值内容替换为对应列id的属性值,如:data['a31f863b14c6299bc4ed1b98badbb6d0'] => 16.0
for
(
String
key
:
fieldSet
.
keySet
())
{
script
=
script
.
replaceAll
(
"data\\['"
+
key
+
"']"
,
fetchItem
.
getVal
(
key
)
!=
null
?
fetchItem
.
getVal
(
key
).
toString
()
:
"0"
);
}
// 执行替换完成后的js计算表达式,如:parseFloat((16.0/13.0).toFixed(2))
Object
eval
=
scriptEngine
.
eval
(
script
);
// 将计算表达式的值赋值到行数据中的:field属性。
if
(!
StringUtils
.
isEmpty
(
eval
)){
BigDecimal
bigDecimaVal
=
new
BigDecimal
(
eval
.
toString
()).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
);
fetchItem
.
setVal
(
field
,
bigDecimaVal
);
}
else
{
fetchItem
.
setVal
(
field
,
new
BigDecimal
(
0
));
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
error
(
"执行计算表达式异常,原始表达式:"
+
valueGetter
+
",替换后计算表达式:"
+
script
+
",原因:"
+
e
.
getMessage
());
}
}
}
}
}
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录