Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
997ac7c1
提交
997ac7c1
编写于
6月 16, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交
上级
cb3a98b0
变更
8
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
963 行增加
和
110 行删除
+963
-110
ExecResultRepository.java
.../cn/ibizlab/core/extensions/cql/ExecResultRepository.java
+4
-3
FetchItem.java
...c/main/java/cn/ibizlab/core/extensions/dto/FetchItem.java
+85
-0
FetchParam.java
.../main/java/cn/ibizlab/core/extensions/dto/FetchParam.java
+145
-7
FetchResult.java
...main/java/cn/ibizlab/core/extensions/dto/FetchResult.java
+84
-0
VMConfig.java
...rc/main/java/cn/ibizlab/core/extensions/dto/VMConfig.java
+11
-8
BuildResultService.java
...n/ibizlab/core/extensions/service/BuildResultService.java
+621
-88
DABuildExService.java
.../cn/ibizlab/core/extensions/service/DABuildExService.java
+9
-0
DataObject.java
...util/src/main/java/cn/ibizlab/util/helper/DataObject.java
+4
-4
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/cql/ExecResultRepository.java
浏览文件 @
997ac7c1
...
...
@@ -10,6 +10,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import
org.springframework.stereotype.Repository
;
import
java.sql.Timestamp
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.UUID
;
...
...
@@ -125,7 +126,7 @@ public class ExecResultRepository {
public
List
<
ExecResult
>
sum
(
List
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
Timestamp
start
,
Timestamp
end
)
{
public
List
<
ExecResult
>
sum
(
Collection
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
Timestamp
start
,
Timestamp
end
)
{
LocalDate
st
=
ExecResult
.
time2LocalDate
(
start
);
LocalDate
ed
=
ExecResult
.
time2LocalDate
(
end
);
final
ResultSet
result
=
session
.
execute
(
select
().
column
(
"ruleid"
).
column
(
"retvalue"
).
column
(
"dimfield"
).
sum
(
"metricfield"
).
as
(
"metricfield"
).
...
...
@@ -137,7 +138,7 @@ public class ExecResultRepository {
return
mapper
.
map
(
result
).
all
();
}
public
List
<
ExecResult
>
avg
(
List
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
Timestamp
start
,
Timestamp
end
)
{
public
List
<
ExecResult
>
avg
(
Collection
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
Timestamp
start
,
Timestamp
end
)
{
LocalDate
st
=
ExecResult
.
time2LocalDate
(
start
);
LocalDate
ed
=
ExecResult
.
time2LocalDate
(
end
);
final
ResultSet
result
=
session
.
execute
(
select
().
column
(
"ruleid"
).
column
(
"retvalue"
).
column
(
"dimfield"
).
avg
(
"metricfield"
).
as
(
"metricfield"
).
...
...
@@ -149,7 +150,7 @@ public class ExecResultRepository {
return
mapper
.
map
(
result
).
all
();
}
public
List
<
ExecResult
>
group
(
List
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
String
type
,
Timestamp
start
,
Timestamp
end
)
{
public
List
<
ExecResult
>
group
(
Collection
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
String
type
,
Timestamp
start
,
Timestamp
end
)
{
if
(
type
.
equalsIgnoreCase
(
"avg"
))
return
avg
(
ruleids
,
retValue
,
dims
,
start
,
end
);
else
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/dto/FetchItem.java
0 → 100644
浏览文件 @
997ac7c1
package
cn
.
ibizlab
.
core
.
extensions
.
dto
;
import
cn.ibizlab.core.lite.extensions.domain.DataObj
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
java.math.BigDecimal
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
FetchItem
extends
DataObj
{
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
public
String
getDisplayType
()
{
return
this
.
getStringValue
(
"displayType"
,
"default"
);
}
public
FetchItem
setDisplayType
(
String
displayType
)
{
this
.
put
(
"displayType"
,
displayType
);
return
this
;
}
public
int
getNo
()
{
return
this
.
getIntegerValue
(
"no"
,
1
);
}
public
FetchItem
setNo
(
int
no
)
{
this
.
put
(
"no"
,
no
);
return
this
;
}
public
String
getDimId
()
{
return
this
.
getStringValue
(
"dimId"
);
}
public
FetchItem
setDimId
(
String
dimId
)
{
this
.
put
(
"dimId"
,
dimId
);
this
.
put
(
"itemId"
,
dimId
);
return
this
;
}
public
String
getDimName
()
{
return
this
.
getStringValue
(
"dimName"
);
}
public
FetchItem
setDimName
(
String
dimName
)
{
this
.
put
(
"dimName"
,
dimName
);
this
.
put
(
"itemName"
,
dimName
);
return
this
;
}
public
String
getMetricId1
()
{
return
this
.
getStringValue
(
"metricId"
);
}
public
FetchItem
setMetricId
(
String
metricId
)
{
this
.
put
(
"metricId"
,
metricId
);
this
.
put
(
"itemId"
,
metricId
);
return
this
;
}
public
String
getMetricName
()
{
return
this
.
getStringValue
(
"metricName"
);
}
public
FetchItem
setMetricName
(
String
metricName
)
{
this
.
put
(
"metricName"
,
metricName
);
this
.
put
(
"itemName"
,
metricName
);
return
this
;
}
public
BigDecimal
getVal
(
String
colId
)
{
return
this
.
getBigDecimalValue
(
colId
,
BigDecimal
.
ZERO
);
}
public
FetchItem
setVal
(
String
colId
,
BigDecimal
val
)
{
if
(
val
==
null
)
val
=
BigDecimal
.
ZERO
;
this
.
put
(
colId
,
val
);
return
this
;
}
}
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/dto/FetchParam.java
浏览文件 @
997ac7c1
package
cn
.
ibizlab
.
core
.
extensions
.
dto
;
import
cn.ibizlab.core.analysis.domain.DAMetric
;
import
cn.ibizlab.util.dict.CodeItem
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
...
...
@@ -12,10 +15,10 @@ import lombok.experimental.Accessors;
import
org.springframework.util.StringUtils
;
import
java.sql.Timestamp
;
import
java.
util.ArrayLis
t
;
import
java.
util.LinkedHashMap
;
import
java.
util.Lis
t
;
import
java.util.
Map
;
import
java.
text.DateForma
t
;
import
java.
text.ParseException
;
import
java.
text.SimpleDateForma
t
;
import
java.util.
*
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Getter
...
...
@@ -52,6 +55,8 @@ public class FetchParam {
private
int
page
=
0
;
private
int
size
=
100
;
private
boolean
filled
=
false
;
public
List
<
String
>
getDimValues
()
{
if
(
dimValues
==
null
&&(!
includeChild
)&&(!
StringUtils
.
isEmpty
(
dimValue
)))
...
...
@@ -75,10 +80,28 @@ public class FetchParam {
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Map
<
String
,
List
<
String
>>
dimTables
;
private
CodeItem
dimItem
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
CodeItem
getDimItem
()
{
return
dimItem
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
FetchParam
setDimItem
(
CodeItem
dimItem
)
{
this
.
dimItem
=
dimItem
;
return
this
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Map
<
String
,
Set
<
String
>>
dimTables
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Map
<
String
,
Lis
t
<
String
>>
getDimTables
()
public
Map
<
String
,
Se
t
<
String
>>
getDimTables
()
{
if
(
dimTables
==
null
)
dimTables
=
new
LinkedHashMap
<>();
...
...
@@ -86,10 +109,125 @@ public class FetchParam {
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
FetchParam
getDimTables
(
Map
<
String
,
Lis
t
<
String
>>
dimTables
)
public
FetchParam
setDimTables
(
Map
<
String
,
Se
t
<
String
>>
dimTables
)
{
this
.
dimTables
=
dimTables
;
return
this
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Map
<
String
,
DAMetric
>
metrics
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Map
<
String
,
DAMetric
>
getMetrics
()
{
if
(
metrics
==
null
)
metrics
=
new
LinkedHashMap
<>();
return
metrics
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
FetchParam
setMetrics
(
Map
<
String
,
DAMetric
>
metrics
)
{
this
.
metrics
=
metrics
;
return
this
;
}
public
Timestamp
getStartTime
()
{
if
(
startTime
!=
null
)
{
try
{
return
new
Timestamp
(
DataObject
.
dayFormat
.
parse
(
DataObject
.
dayFormat
.
format
(
startTime
)).
getTime
());
}
catch
(
Exception
exception
)
{
}
}
return
getDefaultStartTimestamp
();
}
public
Timestamp
getEndTime
()
{
if
(
endTime
!=
null
)
{
try
{
return
new
Timestamp
(
DataObject
.
dayFormat
.
parse
(
DataObject
.
dayFormat
.
format
(
endTime
)+
" 23:59:59"
).
getTime
());
}
catch
(
Exception
exception
)
{
}
}
return
getDefaultEndTimestamp
();
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
List
<
VMConfig
>
vmConfigs
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
String
group
;
public
static
Timestamp
getDefaultStartTimestamp
()
{
Calendar
c
=
Calendar
.
getInstance
();
Date
d
=
new
Date
();
try
{
d
=
DataObject
.
dayFormat
.
parse
(
DataObject
.
dayFormat
.
format
(
d
));
}
catch
(
ParseException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
c
.
setTime
(
d
);
c
.
add
(
Calendar
.
MONTH
,
-
1
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
return
new
Timestamp
(
c
.
getTime
().
getTime
());
}
public
static
Timestamp
getDefaultEndTimestamp
()
{
Calendar
c
=
Calendar
.
getInstance
();
Date
d
=
new
Date
();
try
{
d
=
DataObject
.
dayFormat
.
parse
(
DataObject
.
dayFormat
.
format
(
d
)+
" 23:59:59"
);
}
catch
(
ParseException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
c
.
setTime
(
d
);
int
month
=
c
.
get
(
Calendar
.
MONTH
);
c
.
set
(
Calendar
.
MONTH
,
month
-
1
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
c
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
return
new
Timestamp
(
c
.
getTime
().
getTime
());
}
public
static
Timestamp
getLastYear
(
Timestamp
time
)
{
Date
date
=
new
Date
(
time
.
getTime
());
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
// 设置为当前时间
calendar
.
set
(
Calendar
.
YEAR
,
calendar
.
get
(
Calendar
.
YEAR
)
-
1
);
// 设置为上一年
date
=
calendar
.
getTime
();
Timestamp
rt
=
new
Timestamp
(
date
.
getTime
());
return
rt
;
}
public
static
Timestamp
getLastMonth
(
Timestamp
time
)
{
Date
date
=
new
Date
(
time
.
getTime
());
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
// 设置为当前时间
calendar
.
set
(
Calendar
.
MONTH
,
calendar
.
get
(
Calendar
.
MONTH
)
-
1
);
// 设置为上一个月
date
=
calendar
.
getTime
();
Timestamp
rt
=
new
Timestamp
(
date
.
getTime
());
return
rt
;
}
}
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/dto/FetchResult.java
0 → 100644
浏览文件 @
997ac7c1
package
cn
.
ibizlab
.
core
.
extensions
.
dto
;
import
cn.ibizlab.core.analysis.domain.DAMetric
;
import
cn.ibizlab.util.dict.CodeItem
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.StringUtils
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.util.*
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
public
class
FetchResult
{
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
private
String
displayType
=
"default"
;
private
List
<
FetchItem
>
rows
;
private
List
<
VMConfig
>
headers
;
public
List
<
VMConfig
>
getHeaders
()
{
if
(
headers
==
null
)
{
headers
=
new
ArrayList
<>();
headers
.
add
(
new
VMConfig
().
setHeaderName
(
"序号"
).
setEntity
(
"item"
).
setField
(
"no"
).
setPinned
(
"left"
));
headers
.
add
(
new
VMConfig
().
setHeaderName
(
getGroup
()).
setEntity
(
"item"
).
setField
(
"itemName"
).
setPinned
(
"left"
));
if
(
vmConfigs
!=
null
)
headers
.
addAll
(
vmConfigs
);
}
return
headers
;
}
public
FetchResult
trans2ListBox
()
{
FetchResult
listBox
=
new
FetchResult
();
List
<
VMConfig
>
vms
=
new
ArrayList
<>();
rows
.
forEach
(
row
->{
VMConfig
config
=
new
VMConfig
();
config
.
setHeaderName
(
row
.
getDimName
()).
setEntity
(
"item"
).
setField
(
row
.
getDimId
()).
setWidth
(
80
);
vms
.
add
(
config
);
});
this
.
setVmConfigs
(
vms
);
return
listBox
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
List
<
VMConfig
>
vmConfigs
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
String
group
;
public
static
FetchResult
from
(
FetchParam
fetchParam
)
{
FetchResult
fetchResult
=
new
FetchResult
();
fetchResult
.
setDisplayType
(
fetchParam
.
getDisplayType
());
if
(
fetchParam
.
getVmConfigs
()!=
null
)
{
fetchResult
.
setVmConfigs
(
fetchParam
.
getVmConfigs
());
}
fetchResult
.
setGroup
(
StringUtils
.
isEmpty
(
fetchParam
.
getGroup
())?
"分项"
:
fetchParam
.
getGroup
());
return
fetchResult
;
}
}
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/dto/VMConfig.java
浏览文件 @
997ac7c1
...
...
@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.dto;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
...
...
@@ -13,19 +14,21 @@ import org.springframework.util.StringUtils;
import
java.util.*
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
public
class
VMConfig
{
private
String
headerName
;
private
String
width
;
private
Integer
width
;
@JSONField
(
name
=
"entity"
)
@JsonProperty
(
"entity"
)
private
String
buildId
;
private
String
entity
;
@JSONField
(
name
=
"field"
)
@JsonProperty
(
"field"
)
private
String
metricId
;
private
String
field
;
private
String
pinned
;
private
List
<
VMConfig
>
children
;
public
Map
<
String
,
Set
<
String
>>
getBuilds
(
Map
<
String
,
Set
<
String
>>
builds
)
...
...
@@ -34,17 +37,17 @@ public class VMConfig {
{
builds
=
new
LinkedHashMap
<>();
}
if
((!
StringUtils
.
isEmpty
(
buildId
))
&&
(!
StringUtils
.
isEmpty
(
metricI
d
)))
if
((!
StringUtils
.
isEmpty
(
entity
))
&&
(!
StringUtils
.
isEmpty
(
fiel
d
)))
{
if
(
builds
.
containsKey
(
buildId
))
if
(
builds
.
containsKey
(
entity
))
{
builds
.
get
(
buildId
).
add
(
metricI
d
);
builds
.
get
(
entity
).
add
(
fiel
d
);
}
else
{
Set
<
String
>
metricIds
=
new
LinkedHashSet
<>();
metricIds
.
add
(
metricI
d
);
builds
.
put
(
buildId
,
metricIds
);
metricIds
.
add
(
fiel
d
);
builds
.
put
(
entity
,
metricIds
);
}
}
if
(!
ObjectUtils
.
isEmpty
(
children
))
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/BuildResultService.java
浏览文件 @
997ac7c1
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
import
cn.ibizlab.core.analysis.domain.DABuild
;
import
cn.ibizlab.core.analysis.domain.DAChart
;
import
cn.ibizlab.core.analysis.domain.DAMetric
;
import
cn.ibizlab.core.analysis.domain.DAReport
;
import
cn.ibizlab.core.analysis.service.IDAChartService
;
import
cn.ibizlab.core.analysis.service.IDAMetricService
;
import
cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl
;
import
cn.ibizlab.core.dict.extensions.service.DictDstService
;
import
cn.ibizlab.core.extensions.cql.ExecResult
;
import
cn.ibizlab.core.extensions.cql.ExecResultRepository
;
import
cn.ibizlab.core.extensions.dto.BuildResult
;
import
cn.ibizlab.core.extensions.dto.FetchParam
;
import
cn.ibizlab.core.extensions.dto.FetchItem
;
import
cn.ibizlab.core.extensions.dto.VMConfig
;
import
cn.ibizlab.core.rule.domain.ExecResult
;
import
cn.ibizlab.core.rule.service.IExecResultService
;
import
cn.ibizlab.util.dict.CodeItem
;
import
cn.ibizlab.util.dict.CodeList
;
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
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -22,6 +34,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.math.BigDecimal
;
import
java.sql.Timestamp
;
import
java.util.*
;
...
...
@@ -51,142 +64,662 @@ public class BuildResultService {
@Lazy
private
IDAChartService
daChartService
;
@Autowired
@Lazy
private
IDAMetricService
daMetricService
;
@Autowired
@Lazy
private
DABuildExService
daBuildExService
;
@Autowired
@Lazy
private
DstDataSourceExService
dstDataSourceService
;
@Autowired
@Lazy
private
IExecResultService
execResultService
;
private
void
prepareFetchParam
(
FetchParam
fetchParam
)
{
if
(
fetchParam
.
isFilled
())
return
;
Map
<
String
,
Set
<
String
>>
builds
=
null
;
if
(
ObjectUtils
.
isEmpty
(
fetchParam
.
getMetricIds
()))
{
String
vmConfig
=
""
;
if
(!
StringUtils
.
isEmpty
(
fetchParam
.
getReportId
()))
{
DAReport
daReport
=
daReportService
.
getById
(
fetchParam
.
getReportId
());
if
(
daReport
!=
null
)
{
vmConfig
=
daReport
.
getConfig
();
if
(!
StringUtils
.
isEmpty
(
daReport
.
getDict
()))
fetchParam
.
setDimDict
(
daReport
.
getDict
());
if
(!
StringUtils
.
isEmpty
(
daReport
.
getGroup
()))
fetchParam
.
setGroup
(
daReport
.
getGroup
());
}
}
else
if
(!
StringUtils
.
isEmpty
(
fetchParam
.
getChartId
()))
{
DAChart
daChart
=
daChartService
.
getById
(
fetchParam
.
getChartId
());
if
(
daChart
!=
null
)
{
vmConfig
=
daChart
.
getConfig
();
if
(!
StringUtils
.
isEmpty
(
daChart
.
getDict
()))
fetchParam
.
setDimDict
(
daChart
.
getDict
());
if
(!
StringUtils
.
isEmpty
(
daChart
.
getGroup
()))
fetchParam
.
setGroup
(
daChart
.
getGroup
());
}
}
if
(!
StringUtils
.
isEmpty
(
vmConfig
))
{
builds
=
VMConfig
.
getBuilds
(
vmConfig
);
fetchParam
.
setVmConfigs
(
JSONArray
.
parseArray
(
vmConfig
,
VMConfig
.
class
));
Map
<
String
,
DAMetric
>
metricMap
=
new
LinkedHashMap
<>();
daMetricService
.
list
(
Wrappers
.<
DAMetric
>
lambdaQuery
().
in
(
DAMetric:
:
getMetricId
,
fetchParam
.
getMetricIds
())).
forEach
(
item
->{
metricMap
.
put
(
item
.
getMetricId
(),
item
);
fetchParam
.
getMetricIds
().
add
(
item
.
getMetricId
());
});
fetchParam
.
setMetrics
(
metricMap
);
}
else
{
builds
=
new
LinkedHashMap
<>();
if
(!
StringUtils
.
isEmpty
(
fetchParam
.
getBuildId
()))
{
Map
<
String
,
DAMetric
>
metricMap
=
new
LinkedHashMap
<>();
daMetricService
.
selectByBuildId
(
fetchParam
.
getBuildId
()).
forEach
(
item
->{
metricMap
.
put
(
item
.
getMetricId
(),
item
);
fetchParam
.
getMetricIds
().
add
(
item
.
getMetricId
());
});
fetchParam
.
setMetrics
(
metricMap
);
Set
set
=
new
LinkedHashSet
();
set
.
addAll
(
fetchParam
.
getMetricIds
());
builds
.
put
(
fetchParam
.
getBuildId
(),
set
);
}
}
}
else
// if(StringUtils.isEmpty(fetchParam.getReportId())&&StringUtils.isEmpty(fetchParam.getChartId())&&StringUtils.isEmpty(fetchParam.getBuildId()))
{
builds
=
new
LinkedHashMap
<>();
Map
<
String
,
DAMetric
>
metricMap
=
new
LinkedHashMap
<>();
List
<
DAMetric
>
list
=
daMetricService
.
list
(
Wrappers
.<
DAMetric
>
lambdaQuery
().
in
(
DAMetric:
:
getMetricId
,
fetchParam
.
getMetricIds
()));
for
(
DAMetric
item:
list
){
metricMap
.
put
(
item
.
getMetricId
(),
item
);
if
(!
builds
.
containsKey
(
item
.
getBuildId
()))
builds
.
put
(
item
.
getBuildId
(),
new
LinkedHashSet
());
builds
.
get
(
item
.
getBuildId
()).
add
(
item
.
getMetricId
());
}
fetchParam
.
setMetrics
(
metricMap
);
}
if
(
(!
StringUtils
.
isEmpty
(
fetchParam
.
getDimDict
()))
&&
(!
StringUtils
.
isEmpty
(
fetchParam
.
getDimValue
()))
&&
fetchParam
.
isIncludeChild
()
&&
fetchParam
.
getDimValues
()
==
null
)
{
List
<
String
>
dimValues
=
new
ArrayList
<>();
dimValues
.
add
(
fetchParam
.
getDimValue
());
CodeList
dict
=
dictDstService
.
getCodeListCatalog
(
fetchParam
.
getDimDict
());
if
(
StringUtils
.
isEmpty
(
fetchParam
.
getGroup
()))
fetchParam
.
setGroup
(
dict
.
getName
());
if
(
dict
!=
null
)
{
CodeItem
code
=
dict
.
findChildren
(
fetchParam
.
getDimValue
());
if
(
code
!=
null
&&
code
.
getChildren
()!=
null
)
{
code
.
getChildren
().
forEach
(
codeItem
->
{
CodeItem
dimItem
=
dict
.
findChildren
(
fetchParam
.
getDimValue
());
if
(
dimItem
!=
null
)
{
fetchParam
.
setDimItem
(
dimItem
);
if
(
dimItem
.
getChildren
()!=
null
)
{
dimItem
.
getChildren
().
forEach
(
codeItem
->
{
dimValues
.
add
(
codeItem
.
getValue
().
toString
());
});
}
}
}
dimValues
.
add
(
fetchParam
.
getDimValue
());
fetchParam
.
setDimValues
(
dimValues
);
}
if
(
ObjectUtils
.
isEmpty
(
fetchParam
.
getMetricIds
()))
if
(
builds
!=
null
)
{
String
vmConfig
=
""
;
if
(!
StringUtils
.
isEmpty
(
fetchParam
.
getReportId
()))
for
(
String
key:
builds
.
keySet
())
{
DAReport
daReport
=
daReportService
.
getById
(
fetchParam
.
getReportId
());
if
(
daReport
!=
null
)
vmConfig
=
daReport
.
getConfig
();
DABuild
daBuild
=
daBuildExService
.
getById
(
key
);
if
(
daBuild
!=
null
)
{
String
resultDataSource
=
Setting
.
getValue
(
daBuild
.
getExtParams
(),
"resultDataSource"
);
String
resultTableName
=
Setting
.
getValue
(
daBuild
.
getExtParams
(),
"resultTableName"
);
if
(
StringUtils
.
isEmpty
(
resultDataSource
))
resultDataSource
=
"default"
;
if
(
StringUtils
.
isEmpty
(
resultTableName
))
resultTableName
=
"IBZRULERESULT"
;
String
table
=
resultDataSource
+
"|"
+
resultTableName
;
if
(!
fetchParam
.
getDimTables
().
containsKey
(
table
))
fetchParam
.
getDimTables
().
put
(
table
,
builds
.
get
(
key
));
else
fetchParam
.
getDimTables
().
get
(
table
).
addAll
(
builds
.
get
(
key
));
}
else
if
(!
StringUtils
.
isEmpty
(
fetchParam
.
getChartId
()))
}
}
fetchParam
.
setFilled
(
true
);
}
public
List
<
BuildResult
>
sum
(
FetchParam
fetchParam
)
{
DAChart
daChart
=
daChartService
.
getById
(
fetchParam
.
getChartId
());
if
(
daChart
!=
null
)
vmConfig
=
daChart
.
getConfig
();
return
sum
(
fetchParam
,
null
,
null
,
null
);
}
Map
<
String
,
Set
<
String
>>
builds
=
null
;
if
(
StringUtils
.
isEmpty
(
vmConfig
))
builds
=
VMConfig
.
getBuilds
(
vmConfig
);
else
public
List
<
BuildResult
>
sum
(
FetchParam
fetchParam
,
Set
<
String
>
subMetricIds
,
Timestamp
start
,
Timestamp
end
)
{
List
<
BuildResult
>
ret
=
new
ArrayList
<>();
Timestamp
startTime
=(
start
==
null
)?
fetchParam
.
getStartTime
():
start
;
Timestamp
endTime
=(
end
==
null
)?
fetchParam
.
getEndTime
():
end
;
if
(
subMetricIds
==
null
)
{
builds
=
new
LinkedHashMap
<>();
if
(
StringUtils
.
isEmpty
(
fetchParam
.
getBuildId
()))
{
builds
.
put
(
fetchParam
.
getBuildId
(),
new
LinkedHashSet
<>());
subMetricIds
=
new
LinkedHashSet
<>();
for
(
DAMetric
item:
fetchParam
.
getMetrics
().
values
()){
if
(!
"AVG"
.
equals
(
item
.
getMetricType
()))
subMetricIds
.
add
(
item
.
getMetricId
());
}
}
builds
.
keySet
().
forEach
(
key
->{
if
(!
StringUtils
.
isEmpty
(
cassandraHost
))
{
List
<
cn
.
ibizlab
.
core
.
extensions
.
cql
.
ExecResult
>
list
=
execResultRepository
.
sum
(
subMetricIds
,
1
,
fetchParam
.
getDimValues
(),
startTime
,
endTime
);
list
.
forEach
(
item
->{
ret
.
add
(
new
BuildResult
().
setCqlResult
(
item
));
});
}
else
{
//prepareFetchParam(fetchParam);
Map
<
String
,
Set
<
String
>>
tab
=
fetchParam
.
getDimTables
();
for
(
String
key:
tab
.
keySet
()){
String
[]
args
=
key
.
split
(
"\\|"
);
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
))
{
if
(
subMetricIds
.
contains
(
id
))
tmpSet
.
add
(
id
);
}
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
.
forEach
(
item
->{
ret
.
add
(
new
BuildResult
().
setSqlResult
(
item
));
});
}
}
catch
(
Exception
ex
)
{
log
.
error
(
"汇总分析结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
}
}
return
ret
;
}
public
List
<
BuildResult
>
avg
(
FetchParam
fetchParam
)
{
return
avg
(
fetchParam
,
null
,
null
,
null
);
}
public
List
<
BuildResult
>
sum
(
List
<
String
>
ruleids
,
Integer
retValue
,
List
<
String
>
dims
,
Timestamp
start
,
Timestamp
end
)
{
public
List
<
BuildResult
>
avg
(
FetchParam
fetchParam
,
Set
<
String
>
subMetricIds
,
Timestamp
start
,
Timestamp
end
)
{
List
<
BuildResult
>
ret
=
new
ArrayList
<>();
Timestamp
startTime
=(
start
==
null
)?
fetchParam
.
getStartTime
():
start
;
Timestamp
endTime
=(
end
==
null
)?
fetchParam
.
getEndTime
():
end
;
if
(
subMetricIds
==
null
)
{
subMetricIds
=
new
LinkedHashSet
<>();
for
(
DAMetric
item:
fetchParam
.
getMetrics
().
values
()){
if
(
"AVG"
.
equals
(
item
.
getMetricType
()))
subMetricIds
.
add
(
item
.
getMetricId
());
}
}
if
(!
StringUtils
.
isEmpty
(
cassandraHost
))
{
List
<
ExecResult
>
list
=
execResultRepository
.
sum
(
ruleids
,
retValue
,
dims
,
start
,
end
);
List
<
cn
.
ibizlab
.
core
.
extensions
.
cql
.
ExecResult
>
list
=
execResultRepository
.
avg
(
fetchParam
.
getMetricIds
(),
1
,
fetchParam
.
getDimValues
(),
startTime
,
endTime
);
list
.
forEach
(
item
->{
ret
.
add
(
new
BuildResult
().
setCqlResult
(
item
));
});
}
else
{
//prepareFetchParam(fetchParam);
Map
<
String
,
Set
<
String
>>
tab
=
fetchParam
.
getDimTables
();
for
(
String
key:
tab
.
keySet
()){
String
[]
args
=
key
.
split
(
"\\|"
);
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
))
{
if
(
subMetricIds
.
contains
(
id
))
tmpSet
.
add
(
id
);
}
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
.
forEach
(
item
->{
ret
.
add
(
new
BuildResult
().
setSqlResult
(
item
));
});
}
}
catch
(
Exception
ex
)
{
log
.
error
(
"汇总分析结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
}
}
return
ret
;
}
public
List
<
String
>
lookup
(
FetchParam
fetchParam
)
{
List
<
String
>
ret
=
new
ArrayList
<>();
if
(!
StringUtils
.
isEmpty
(
cassandraHost
))
{
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
());
int
remaining
=
rs
.
getAvailableWithoutFetching
();
for
(
Row
row
:
rs
)
{
ret
.
add
(
row
.
getString
(
"keyvaluefield"
));
if
(--
remaining
==
0
)
{
break
;
}
}
break
;
}
else
{
ResultSet
rs
=
execResultRepository
.
getPageData
(
fetchParam
.
getMetricId
(),
pagingState
,
1
,
fetchParam
.
getDimValue
(),
fetchParam
.
getStartTime
(),
fetchParam
.
getEndTime
());
pagingState
=
rs
.
getExecutionInfo
().
getPagingState
();
}
}
}
else
{
//prepareFetchParam(fetchParam);
Map
<
String
,
Set
<
String
>>
tab
=
fetchParam
.
getDimTables
();
tab
.
keySet
().
forEach
(
key
->{
String
[]
args
=
key
.
split
(
"\\|"
);
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
->{
ret
.
add
(
item
.
getKeyValueField
());
});
}
catch
(
Exception
ex
)
{
log
.
error
(
"反查分析结果发生异常,详细错误信息:"
+
ex
.
getMessage
());
}
finally
{
if
(!
"default"
.
equalsIgnoreCase
(
dsName
))
{
DynamicDataSourceContextHolder
.
poll
();
}
}
});
}
return
ret
;
// LocalDate st = ExecResult.time2LocalDate(start);
// LocalDate ed = ExecResult.time2LocalDate(end);
// final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").sum("metricfield").as("metricfield").
// from(TABLE).
// where(in("ruleid", ruleids)).
// and(eq("retvalue", retValue)).
// and(in("dimfield", dims)).
// and(gte("timefield", st)).and(lte("timefield", ed)).groupBy("ruleid", "retvalue", "dimfield").limit(5000).setReadTimeoutMillis(200000));
// return mapper.map(result).all();
// }
//
// public List<ExecResult> avg(List<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
// LocalDate st = ExecResult.time2LocalDate(start);
// LocalDate ed = ExecResult.time2LocalDate(end);
// final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").avg("metricfield").as("metricfield").
// from(TABLE).
// where(in("ruleid", ruleids)).
// and(eq("retvalue", retValue)).
// and(in("dimfield", dims)).
// and(gte("timefield", st)).and(lte("timefield", ed)).groupBy("ruleid", "retvalue", "dimfield").limit(5000).setReadTimeoutMillis(200000));
// return mapper.map(result).all();
// }
//
// public List<ExecResult> group(List<String> ruleids, Integer retValue, List<String> dims, String type, Timestamp start, Timestamp end) {
// if (type.equalsIgnoreCase("avg"))
// return avg(ruleids, retValue, dims, start, end);
// else
// return sum(ruleids, retValue, dims, start, end);
// }
//
// public List<ExecResult> group(List<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
//
// return group(ruleids, retValue, dims, "sum", start, end);
// }
//
// /**
// * 根据规则ID、单位和时间查询相应的规则结果数据
// *
// * @param ruleid
// * @param retValue
// * @param dims
// * @param start
// * @param end
// * @return
// */
// public ResultSet getPageData(String ruleid, PagingState pagingState, Integer retValue, String dims, Timestamp start, Timestamp end) {
// final int RESULTS_PER_PAGE = 1000;
// LocalDate st = ExecResult.time2LocalDate(start);
// LocalDate ed = ExecResult.time2LocalDate(end);
// Statement statement = select().column("keyvaluefield").
// from(TABLE).
// where(eq("ruleid", ruleid)).
// and(eq("retvalue", retValue)).
// and(eq("dimfield", dims)).
// and(gte("timefield", st)).and(lte("timefield", ed)).setReadTimeoutMillis(200000);
// statement.setFetchSize(RESULTS_PER_PAGE);
// if (pagingState != null) {
// statement.setPagingState(pagingState);
// }
// final ResultSet result = session.execute(statement);
// return result;
}
public
List
<
FetchItem
>
getResult
(
FetchParam
fetchParam
)
{
this
.
prepareFetchParam
(
fetchParam
);
Set
<
String
>
sum
=
new
LinkedHashSet
<>();
Set
<
String
>
avg
=
new
LinkedHashSet
<
String
>();
Set
<
String
>
sum_yoy
=
new
LinkedHashSet
<>();
Set
<
String
>
sum_mom
=
new
LinkedHashSet
<>();
Set
<
String
>
sum_y3
=
new
LinkedHashSet
<>();
Set
<
DAMetric
>
sum_per
=
new
LinkedHashSet
<>();
Set
<
String
>
avg_yoy
=
new
LinkedHashSet
<>();
Set
<
String
>
avg_mom
=
new
LinkedHashSet
<>();
Set
<
String
>
avg_y3
=
new
LinkedHashSet
<>();
List
<
DAMetric
>
avg_per
=
new
ArrayList
<>();
for
(
DAMetric
metric:
fetchParam
.
getMetrics
().
values
())
{
if
(
"AVG"
.
equals
(
metric
.
getMetricType
()))
{
avg
.
add
(
metric
.
getMetricId
());
if
(
"YOY"
.
equals
(
metric
.
getExtOp
()))
avg_yoy
.
add
(
metric
.
getMetricId
());
else
if
(
"MOM"
.
equals
(
metric
.
getExtOp
()))
avg_mom
.
add
(
metric
.
getMetricId
());
else
if
(
"Y3"
.
equals
(
metric
.
getExtOp
()))
avg_y3
.
add
(
metric
.
getMetricId
());
else
if
(
"PER"
.
equals
(
metric
.
getExtOp
())
||
"PER_ORI"
.
equals
(
metric
.
getExtOp
()))
avg_per
.
add
(
metric
);
}
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
<>();
List
<
FetchItem
>
dimsObj
=
new
ArrayList
<>();
Hashtable
<
String
,
FetchItem
>
dimsSet
=
new
Hashtable
<>();
int
no
=
1
;
if
(
fetchParam
.
isIncludeChild
()&&
fetchParam
.
getDimItem
()!=
null
&&
fetchParam
.
getDimItem
().
getChildren
()!=
null
)
{
for
(
CodeItem
item:
fetchParam
.
getDimItem
().
getChildren
())
{
dims
.
add
(
item
.
getValue
().
toString
());
FetchItem
obj
=
new
FetchItem
().
setNo
(
no
).
setDimId
(
item
.
getValue
().
toString
()).
setDimName
(
item
.
getText
()).
setDisplayType
(
fetchParam
.
getDisplayType
());
for
(
DAMetric
metric:
fetchParam
.
getMetrics
().
values
())
{
obj
.
setVal
(
metric
.
getMetricId
(),
BigDecimal
.
ZERO
);
}
dimsObj
.
add
(
obj
);
dimsSet
.
put
(
obj
.
getDimId
(),
obj
);
no
++;
}
}
boolean
bcalsum
=
false
;
FetchItem
sumobj
=
new
FetchItem
().
setDisplayType
(
fetchParam
.
getDisplayType
());
{
if
(
dims
.
size
()==
0
)
dims
.
add
(
fetchParam
.
getDimValue
());
else
bcalsum
=
true
;
sumobj
.
setNo
(
no
).
setDimId
(
fetchParam
.
getDimValue
()).
setDimName
(
"合计"
);
for
(
DAMetric
metric:
fetchParam
.
getMetrics
().
values
())
{
sumobj
.
setVal
(
metric
.
getMetricId
(),
BigDecimal
.
ZERO
);
}
dimsObj
.
add
(
sumobj
);
dimsSet
.
put
(
sumobj
.
getDimId
(),
sumobj
);
}
List
<
BuildResult
>
list
=
new
ArrayList
<>();
if
(
sum
.
size
()>
0
)
{
List
<
BuildResult
>
listsum
=
sum
(
fetchParam
,
sum
,
null
,
null
);
list
.
addAll
(
listsum
);
}
if
(
avg
.
size
()>
0
)
{
List
<
BuildResult
>
listavg
=
avg
(
fetchParam
,
avg
,
null
,
null
);
list
.
addAll
(
listavg
);
}
for
(
BuildResult
res:
list
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimField
()))
continue
;
FetchItem
obj
=
dimsSet
.
get
(
res
.
getDimField
());
obj
.
setVal
(
res
.
getRuleId
(),
res
.
getMetricField
());
if
(
bcalsum
)
{
Double
d
=
0
d
;
if
(
res
.
getMetricField
()!=
null
)
{
d
=
res
.
getMetricField
().
doubleValue
();
}
Double
sumd
=
0
d
;
if
(
sumobj
.
containsKey
(
res
.
getRuleId
())&&
sumobj
.
get
(
res
.
getRuleId
())!=
null
)
{
sumd
=
sumobj
.
getVal
(
res
.
getRuleId
()).
doubleValue
();
}
sumd
+=
d
;
sumobj
.
setVal
(
res
.
getRuleId
(),
new
BigDecimal
(
sumd
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
}
}
//同比
List
<
BuildResult
>
list_yoy
=
new
ArrayList
<>();
if
(
sum_yoy
.
size
()>
0
)
{
List
<
BuildResult
>
listsum
=
sum
(
fetchParam
,
sum_yoy
,
FetchParam
.
getLastYear
(
fetchParam
.
getStartTime
()),
FetchParam
.
getLastYear
(
fetchParam
.
getEndTime
()));
list_yoy
.
addAll
(
listsum
);
}
if
(
avg_yoy
.
size
()>
0
)
{
List
<
BuildResult
>
listavg
=
avg
(
fetchParam
,
avg_yoy
,
FetchParam
.
getLastYear
(
fetchParam
.
getStartTime
()),
FetchParam
.
getLastYear
(
fetchParam
.
getEndTime
()));
list_yoy
.
addAll
(
listavg
);
}
for
(
BuildResult
res:
list_yoy
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimField
()))
continue
;
FetchItem
obj
=
dimsSet
.
get
(
res
.
getDimField
());
Double
now
=
obj
.
getVal
(
res
.
getRuleId
()).
doubleValue
();
Double
last
=
res
.
getMetricField
()==
null
?
0
d:
res
.
getMetricField
().
doubleValue
();
if
(
last
==
0
d
)
{
last
=
1
d
;
if
(
now
==
0
d
)
now
=
1
d
;
}
Double
d
=(
now
-
last
)/
last
;
d
=
d
*
100
;
obj
.
setVal
(
res
.
getRuleId
(),
new
BigDecimal
(
d
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
}
if
(
bcalsum
)
{
HashMap
<
String
,
Double
>
sumlastset
=
new
HashMap
<
String
,
Double
>();
for
(
BuildResult
res:
list_yoy
)
{
Double
sumlast
=
0
d
;
Double
d
=
0
d
;
if
(
res
.
getMetricField
()!=
null
)
{
d
=
res
.
getMetricField
().
doubleValue
();
}
if
(
sumlastset
.
containsKey
(
res
.
getRuleId
())&&
sumlastset
.
get
(
res
.
getRuleId
())!=
null
)
{
sumlast
=
sumlastset
.
get
(
res
.
getRuleId
());
}
sumlast
+=
d
;
sumlastset
.
put
(
res
.
getRuleId
(),
sumlast
);
}
for
(
String
str:
sumlastset
.
keySet
())
{
Double
now
=
sumobj
.
getVal
(
str
).
doubleValue
();
Double
last
=
sumlastset
.
get
(
str
);
if
(
last
==
0
d
)
{
last
=
1
d
;
if
(
now
==
0
d
)
now
=
1
d
;
}
Double
d
=(
now
-
last
)/
last
;
d
=
d
*
100
;
sumobj
.
setVal
(
str
,
new
BigDecimal
(
d
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
}
}
//环比
List
<
BuildResult
>
list_mom
=
new
ArrayList
<>();
if
(
sum_mom
.
size
()>
0
)
{
List
<
BuildResult
>
listsum
=
sum
(
fetchParam
,
sum_mom
,
FetchParam
.
getLastMonth
(
fetchParam
.
getStartTime
()),
FetchParam
.
getLastMonth
(
fetchParam
.
getEndTime
()));
list_mom
.
addAll
(
listsum
);
}
if
(
avg_mom
.
size
()>
0
)
{
List
<
BuildResult
>
listavg
=
avg
(
fetchParam
,
avg_mom
,
FetchParam
.
getLastMonth
(
fetchParam
.
getStartTime
()),
FetchParam
.
getLastMonth
(
fetchParam
.
getEndTime
()));
list_mom
.
addAll
(
listavg
);
}
for
(
BuildResult
res:
list_mom
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimField
()))
continue
;
FetchItem
obj
=
dimsSet
.
get
(
res
.
getDimField
());
Double
now
=
obj
.
getVal
(
res
.
getRuleId
()).
doubleValue
();
Double
last
=
res
.
getMetricField
()==
null
?
0
d:
res
.
getMetricField
().
doubleValue
();
if
(
last
==
0
d
)
{
last
=
1
d
;
if
(
now
==
0
d
)
now
=
1
d
;
}
Double
d
=(
now
-
last
)/
last
;
d
=
d
*
100
;
obj
.
setVal
(
res
.
getRuleId
(),
new
BigDecimal
(
d
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
}
if
(
bcalsum
)
{
HashMap
<
String
,
Double
>
sumlastset
=
new
HashMap
<
String
,
Double
>();
for
(
BuildResult
res:
list_mom
)
{
Double
sumlast
=
0
d
;
Double
d
=
0
d
;
if
(
res
.
getMetricField
()!=
null
)
{
d
=
res
.
getMetricField
().
doubleValue
();
}
if
(
sumlastset
.
containsKey
(
res
.
getRuleId
())&&
sumlastset
.
get
(
res
.
getRuleId
())!=
null
)
{
sumlast
=
sumlastset
.
get
(
res
.
getRuleId
());
}
sumlast
+=
d
;
sumlastset
.
put
(
res
.
getRuleId
(),
sumlast
);
}
for
(
String
str:
sumlastset
.
keySet
())
{
Double
now
=
sumobj
.
getVal
(
str
).
doubleValue
();
Double
last
=
sumlastset
.
get
(
str
);
if
(
last
==
0
d
)
{
last
=
1
d
;
if
(
now
==
0
d
)
now
=
1
d
;
}
Double
d
=(
now
-
last
)/
last
;
d
=
d
*
100
;
sumobj
.
put
(
str
,
new
BigDecimal
(
d
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
}
}
//占比
sum_per
.
addAll
(
avg_per
);
for
(
DAMetric
res:
sum_per
)
{
boolean
isPerOri
=
false
;
if
(
"PER_ORI"
.
equalsIgnoreCase
(
res
.
getExtOp
()))
isPerOri
=
true
;
for
(
FetchItem
obj:
dimsObj
)
{
if
(
StringUtils
.
isEmpty
(
obj
.
get
(
res
.
getMetricId
()))
||
StringUtils
.
isEmpty
(
obj
.
get
(
res
.
getRefMetric
())))
{
continue
;
}
Double
cur
=
obj
.
getVal
(
res
.
getMetricId
()).
doubleValue
();
Double
per
=
obj
.
getVal
(
res
.
getRefMetric
()).
doubleValue
();
if
(
per
==
0
d
)
per
=
1
d
;
Double
d
=(
cur
)/
per
;
if
(!
isPerOri
)
{
d
=
d
*
100
;
}
obj
.
setVal
(
res
.
getMetricId
(),
new
BigDecimal
(
d
).
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
));
}
}
return
dimsObj
;
}
}
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/DABuildExService.java
浏览文件 @
997ac7c1
...
...
@@ -20,6 +20,7 @@ import cn.ibizlab.core.rule.service.IExecLogService;
import
cn.ibizlab.core.rule.service.IRuleItemService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.helper.Setting
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
...
...
@@ -174,6 +175,14 @@ public class DABuildExService extends DABuildServiceImpl {
msg
.
setBatch
(
engineMQMsg
.
getBatch
());
msg
.
setSystemid
(
et
.
getSystemId
());
msg
.
setEngineId
(
engineMQMsg
.
getEngineId
());
String
resultDataSource
=
Setting
.
getValue
(
et
.
getExtParams
(),
"resultDataSource"
);
String
resultTableName
=
Setting
.
getValue
(
et
.
getExtParams
(),
"resultTableName"
);
if
(!
StringUtils
.
isEmpty
(
resultDataSource
)){
msg
.
setResultDataSource
(
resultDataSource
);
}
if
(!
StringUtils
.
isEmpty
(
resultTableName
)){
msg
.
setResultTableName
(
resultTableName
);
}
ExecLog
execlog
=
new
ExecLog
();
execlog
.
setId
(
msg
.
getId
());
...
...
ibzdst-util/src/main/java/cn/ibizlab/util/helper/DataObject.java
浏览文件 @
997ac7c1
...
...
@@ -238,20 +238,20 @@ public class DataObject {
}
try
{
if
(
objValue
instanceof
BigDecimal
){
return
(
BigDecimal
)(
objValue
);
return
(
(
BigDecimal
)(
objValue
)).
stripTrailingZeros
(
);
}
if
(
objValue
instanceof
Double
){
return
BigDecimal
.
valueOf
((
Double
)
objValue
);
return
BigDecimal
.
valueOf
((
Double
)
objValue
)
.
stripTrailingZeros
()
;
}
if
(
objValue
instanceof
Long
){
return
BigDecimal
.
valueOf
((
Long
)
objValue
);
return
BigDecimal
.
valueOf
((
Long
)
objValue
)
.
stripTrailingZeros
()
;
}
String
strValue
=
objValue
.
toString
();
if
(
StringUtils
.
isEmpty
(
strValue
))
{
return
fDefault
;
}
strValue
=
strValue
.
replace
(
","
,
""
);
return
BigDecimal
.
valueOf
(
Double
.
parseDouble
(
strValue
));
return
BigDecimal
.
valueOf
(
Double
.
parseDouble
(
strValue
))
.
stripTrailingZeros
()
;
}
catch
(
Exception
ex
)
{
return
fDefault
;
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录