Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
b5502fd3
提交
b5502fd3
编写于
1月 28, 2021
作者:
yuefenglong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dst增加报表的功能
上级
db69c851
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
1014 行增加
和
2 行删除
+1014
-2
DACoreService.java
...ava/cn/ibizlab/core/extensions/service/DACoreService.java
+922
-0
DACoreResource.java
...n/java/cn/ibizlab/api/rest/extensions/DACoreResource.java
+81
-2
CodeList.java
ibzdst-util/src/main/java/cn/ibizlab/util/dict/CodeList.java
+11
-0
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/DACoreService.java
浏览文件 @
b5502fd3
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
import
cn.ibizlab.core.analysis.domain.DAMetric
;
import
cn.ibizlab.core.analysis.domain.DAReport
;
import
cn.ibizlab.core.analysis.filter.DAMetricSearchContext
;
import
cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl
;
import
cn.ibizlab.core.extensions.cql.ExecResult
;
import
cn.ibizlab.core.extensions.cql.ExecResultRepository
;
import
cn.ibizlab.core.extensions.domain.FetchMetricDatasParam
;
import
cn.ibizlab.core.rule.domain.RuleItem
;
import
cn.ibizlab.util.dict.CodeItem
;
import
cn.ibizlab.util.dict.CodeList
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.datastax.driver.core.PagingState
;
import
com.datastax.driver.core.ResultSet
;
import
com.datastax.driver.core.Row
;
import
com.datastax.driver.mapping.Mapper
;
import
com.datastax.driver.mapping.MappingManager
;
import
lombok.extern.log4j.Log4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.math.BigDecimal
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
@Slf4j
@Service
public
class
DACoreService
{
@Autowired
@Lazy
private
DAMetricExService
daMetricExService
;
@Autowired
(
required
=
false
)
@Lazy
private
ExecResultRepository
execResultRepository
;
@Autowired
@Lazy
private
cn
.
ibizlab
.
util
.
client
.
IBZDictFeignClient
ibzDictFeignClient
;
@Autowired
@Lazy
private
DAReportServiceImpl
daReportService
;
@Autowired
@Lazy
private
RuleItemExService
ruleItemExService
;
/**
* 通过指标、维度、时间获取相应的规则结果数据
* @param param
* @return
*/
@Cacheable
(
value
=
"onFetchMetricDatas"
,
keyGenerator
=
"keyGenerator"
)
public
List
<
HashMap
<
String
,
Object
>>
onFetchMetricDatas
(
FetchMetricDatasParam
param
)
{
List
<
HashMap
<
String
,
Object
>>
execResults
=
new
ArrayList
<
HashMap
<
String
,
Object
>>();
try
{
if
(
param
==
null
){
return
execResults
;
}
List
<
String
>
ruleidList
=
param
.
getMetricids
();
String
strDimval
=
param
.
getDimval
();
boolean
isIncludeChild
=
param
.
isIncludechild
();
String
strDIMCodeList
=
param
.
getDimcodelist
();
Timestamp
timeStartTime
=
param
.
getStarttime
();
Timestamp
timeEndTime
=
param
.
getEndtime
();
execResults
=
this
.
getResultIds
(
ruleidList
,
strDIMCodeList
,
strDimval
,
isIncludeChild
,
timeStartTime
,
timeEndTime
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"获取查询报表错误, 错误原因:"
+
ex
.
getMessage
());
}
return
execResults
;
}
/**
* 呈报报表获取数据
* @param param
* @return
*/
@Cacheable
(
value
=
"onFetchReportDatas"
,
keyGenerator
=
"keyGenerator"
)
public
Map
<
String
,
Object
>
onFetchReportDatas
(
FetchMetricDatasParam
param
)
{
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<
String
,
Object
>();
try
{
if
(
param
==
null
){
return
resultMap
;
}
String
id
=
param
.
getReportid
();
if
(
StringUtils
.
isEmpty
(
id
))
{
return
resultMap
;
}
//获取表头及表单名称
DAReport
daReport
=
daReportService
.
getById
(
id
);
String
vmcfg
=
daReport
!=
null
?
daReport
.
getConfig
()
:
""
;
String
reportname
=
daReport
!=
null
?
daReport
.
getReportName
()
:
""
;
String
strTableDisplayType
=
param
.
getTableDisplayType
();
//获取表格数据
JSONObject
jsonObject
=
this
.
getERPortData
(
daReport
,
param
.
getDimval
(),
param
.
getDimcodelist
(),
param
.
getStarttime
(),
param
.
getEndtime
(),
strTableDisplayType
);
resultMap
.
put
(
"vmcfg"
,
vmcfg
);
resultMap
.
put
(
"reportname"
,
reportname
);
resultMap
.
put
(
"resportdata"
,
jsonObject
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"获取查询报表错误, 错误原因:"
+
ex
.
getMessage
());
}
return
resultMap
;
}
/**
* 获取反查数据用到的keyvalue
* @param param
* @return
*/
@Cacheable
(
value
=
"onFetchKeyValueField"
,
keyGenerator
=
"keyGenerator"
)
public
Map
<
String
,
String
>
onFetchKeyValueField
(
FetchMetricDatasParam
param
)
{
Map
<
String
,
String
>
resultMap
=
new
HashMap
<
String
,
String
>();
try
{
String
strKeyValue
=
""
;
if
(
param
==
null
)
{
return
resultMap
;
}
long
lPagingCurrent
=
param
.
getPagingCurrent
();
String
strRuleid
=
param
.
getRuleid
();
String
strDimval
=
param
.
getDimval
();
Timestamp
timeStart
=
param
.
getStarttime
()
==
null
?
this
.
getDefaultStartTimestamp
()
:
param
.
getStarttime
();
Timestamp
timeEnd
=
param
.
getEndtime
()
==
null
?
this
.
getDefaultEndTimestamp
()
:
param
.
getEndtime
();
if
(
StringUtils
.
isEmpty
(
strRuleid
))
{
return
resultMap
;
}
resultMap
=
this
.
getKeyvaluefields
(
lPagingCurrent
,
strRuleid
,
strDimval
,
timeStart
,
timeEnd
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"获取查询报表错误, 错误原因:"
+
ex
.
getMessage
());
}
return
resultMap
;
}
/**
* 根据报表ID查询相应的数据
*
* @param strDST_CBID
* @return
*/
public
JSONObject
getERPortData
(
DAReport
report
,
String
strLoadDimval
,
String
strDict
,
Timestamp
timeLoadStartTime
,
Timestamp
timeLoadEndTime
,
String
strTableDisplayType
)
{
JSONObject
jsonObject
=
new
JSONObject
();
if
(
report
!=
null
)
{
DAReport
daReport
=
report
;
String
strVMCFG
=
daReport
.
getConfig
();
if
(
StringUtils
.
isEmpty
(
strVMCFG
))
{
throw
new
BadRequestAlertException
(
"报表配置不存在"
,
""
,
""
);
}
List
<
String
>
ruleidList
=
getRuleids
(
JSONArray
.
parseArray
(
strVMCFG
));
String
strDimval
=
StringUtils
.
isEmpty
(
strLoadDimval
)
?
"%"
:
strLoadDimval
;
strDict
=
StringUtils
.
isEmpty
(
strDict
)
?
this
.
getDict
(
daReport
)
:
strDict
;
Timestamp
startTime
=
timeLoadStartTime
==
null
?
this
.
getDefaultStartTimestamp
()
:
timeLoadStartTime
;
Timestamp
endTime
=
timeLoadEndTime
==
null
?
this
.
getDefaultEndTimestamp
()
:
timeLoadEndTime
;
JSONArray
jsonArray
=
new
JSONArray
();
List
<
HashMap
<
String
,
Object
>>
execResults
=
this
.
getResultIds
(
ruleidList
,
strDict
,
strDimval
,
startTime
,
endTime
);
jsonArray
.
add
(
execResults
);
if
(!
StringUtils
.
isEmpty
(
strTableDisplayType
)
&&
"LIST_BOX"
.
equals
(
strTableDisplayType
))
{
JSONArray
rowJson
=
new
JSONArray
();
rowJson
.
addAll
(
JSONArray
.
parseArray
(
strVMCFG
));
jsonObject
=
this
.
getErReportHeader
(
execResults
,
rowJson
);
// 行转列模式
}
else
{
jsonObject
.
put
(
"headData"
,
getVMCFG
(
strVMCFG
,
"report"
));
jsonObject
.
put
(
"erportdata"
,
jsonArray
);
}
}
else
{
throw
new
BadRequestAlertException
(
"报表不存在"
,
""
,
""
);
}
return
jsonObject
;
}
/**
* 获取指标相关的查询结果数据
* @param ruleid
* @param dimval
* @param start
* @param end
* @return
*/
@Cacheable
(
value
=
"reportinspec"
,
keyGenerator
=
"keyGenerator"
)
public
Map
<
String
,
String
>
getKeyvaluefields
(
long
lPagingCurrent
,
String
ruleid
,
String
dimval
,
Timestamp
start
,
Timestamp
end
)
{
Map
<
String
,
String
>
result
=
null
;
PagingState
pagingState
=
null
;
for
(
long
i
=
1L
;
i
<=
lPagingCurrent
;
i
++)
{
if
(
lPagingCurrent
==
i
)
{
result
=
this
.
page
(
pagingState
,
ruleid
,
1
,
dimval
,
start
,
end
,
true
);
break
;
}
else
{
result
=
this
.
page
(
pagingState
,
ruleid
,
1
,
dimval
,
start
,
end
,
false
);
}
String
strPagingState
=
result
.
get
(
"pagingState"
);
if
(!
StringUtils
.
isEmpty
(
strPagingState
))
{
pagingState
=
PagingState
.
fromString
(
strPagingState
);
}
}
return
result
;
}
@Cacheable
(
value
=
"reportshow"
,
keyGenerator
=
"keyGenerator"
)
public
List
<
HashMap
<
String
,
Object
>>
getResultIds
(
List
<
String
>
metricList
,
String
dimcodelist
,
String
dimval
,
Timestamp
start
,
Timestamp
end
)
{
return
this
.
getResultIds
(
metricList
,
dimcodelist
,
dimval
,
true
,
start
,
end
);
}
@Cacheable
(
value
=
"reportshow"
,
keyGenerator
=
"keyGenerator"
)
public
List
<
HashMap
<
String
,
Object
>>
getResultIds
(
List
<
String
>
metricList
,
String
dimcodelist
,
String
dimval
,
boolean
includeChild
,
Timestamp
start
,
Timestamp
end
)
{
QueryWrapper
<
DAMetric
>
sf
=
new
QueryWrapper
<>();
sf
.
in
(
"da_metricid"
,
metricList
);
return
this
.
getResult
(
this
.
daMetricExService
.
list
(
sf
),
dimcodelist
,
dimval
,
includeChild
,
start
,
end
);
}
public
List
<
HashMap
<
String
,
Object
>>
getResult
(
List
<
DAMetric
>
metricList
,
String
dimcodelist
,
String
dimval
,
boolean
includeChild
,
Timestamp
start
,
Timestamp
end
)
{
List
<
String
>
sum
=
new
ArrayList
<
String
>();
List
<
String
>
avg
=
new
ArrayList
<
String
>();
List
<
String
>
sum_yoy
=
new
ArrayList
<>();
List
<
String
>
sum_mom
=
new
ArrayList
<>();
List
<
String
>
sum_y3
=
new
ArrayList
<>();
List
<
DAMetric
>
sum_per
=
new
ArrayList
<>();
List
<
String
>
avg_yoy
=
new
ArrayList
<>();
List
<
String
>
avg_mom
=
new
ArrayList
<>();
List
<
String
>
avg_y3
=
new
ArrayList
<>();
List
<
DAMetric
>
avg_per
=
new
ArrayList
<>();
for
(
DAMetric
metric:
metricList
)
{
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
<
HashMap
<
String
,
Object
>>
dimsObj
=
new
ArrayList
<>();
Hashtable
<
String
,
HashMap
<
String
,
Object
>>
dimsSet
=
new
Hashtable
<>();
// CodeItem code=CodeListBase.getCodeList(dimcodelist).getCodeList().getCodeItemModelMap().get(dimval);
CodeItem
code
=
ibzDictFeignClient
.
getCodeList
(
dimcodelist
).
findChildren
(
dimval
);
if
(
code
==
null
)
return
null
;
int
no
=
1
;
if
(
code
.
getChildren
()!=
null
&&
includeChild
)
{
for
(
CodeItem
item:
code
.
getChildren
())
{
dims
.
add
(
item
.
getValue
().
toString
());
HashMap
<
String
,
Object
>
obj
=
new
HashMap
<>();
obj
.
put
(
"no"
,
no
);
obj
.
put
(
"dimcode"
,
item
.
getValue
().
toString
());
obj
.
put
(
"dimname"
,
item
.
getText
());
for
(
DAMetric
metric:
metricList
)
{
obj
.
put
(
metric
.
getMetricId
(),
0
d
);
}
dimsObj
.
add
(
obj
);
dimsSet
.
put
(
item
.
getValue
().
toString
(),
obj
);
no
++;
}
}
boolean
bcalsum
=
false
;
HashMap
<
String
,
Object
>
sumobj
=
new
HashMap
<>();
{
if
(
dims
.
size
()==
0
)
dims
.
add
(
code
.
getValue
().
toString
());
else
bcalsum
=
true
;
sumobj
.
put
(
"no"
,
no
);
sumobj
.
put
(
"dimcode"
,
code
.
getValue
().
toString
());
sumobj
.
put
(
"dimname"
,
"合计"
);
for
(
DAMetric
metric:
metricList
)
{
sumobj
.
put
(
metric
.
getMetricId
(),
0
d
);
}
dimsObj
.
add
(
sumobj
);
dimsSet
.
put
(
code
.
getValue
().
toString
(),
sumobj
);
}
List
<
ExecResult
>
list
=
new
ArrayList
<>();
if
(
sum
.
size
()>
0
)
{
List
<
ExecResult
>
listsum
=
execResultRepository
.
sum
(
sum
,
1
,
dims
,
start
,
end
);
list
.
addAll
(
listsum
);
}
if
(
avg
.
size
()>
0
)
{
List
<
ExecResult
>
listavg
=
execResultRepository
.
avg
(
avg
,
1
,
dims
,
start
,
end
);
list
.
addAll
(
listavg
);
}
for
(
ExecResult
res:
list
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimfield
()))
continue
;
HashMap
<
String
,
Object
>
obj
=
dimsSet
.
get
(
res
.
getDimfield
());
obj
.
put
(
res
.
getRuleid
(),
res
.
getMetricfield
());
if
(
bcalsum
)
{
Double
d
=
0
d
;
if
(
res
.
getMetricfield
()!=
null
)
{
d
=
res
.
getMetricfield
();
}
Double
sumd
=
0
d
;
if
(
sumobj
.
containsKey
(
res
.
getRuleid
())&&
sumobj
.
get
(
res
.
getRuleid
())!=
null
)
{
sumd
=(
double
)
sumobj
.
get
(
res
.
getRuleid
());
}
sumd
+=
d
;
sumobj
.
put
(
res
.
getRuleid
(),
sumd
);
}
}
//同比
List
<
ExecResult
>
list_yoy
=
new
ArrayList
<>();
if
(
sum_yoy
.
size
()>
0
)
{
List
<
ExecResult
>
listsum
=
execResultRepository
.
sum
(
sum_yoy
,
1
,
dims
,
getLastYear
(
start
),
getLastYear
(
end
));
list_yoy
.
addAll
(
listsum
);
}
if
(
avg_yoy
.
size
()>
0
)
{
List
<
ExecResult
>
listavg
=
execResultRepository
.
avg
(
avg_yoy
,
1
,
dims
,
getLastYear
(
start
),
getLastYear
(
end
));
list_yoy
.
addAll
(
listavg
);
}
for
(
ExecResult
res:
list_yoy
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimfield
()))
continue
;
HashMap
<
String
,
Object
>
obj
=
dimsSet
.
get
(
res
.
getDimfield
());
Double
now
=(
double
)
obj
.
get
(
res
.
getRuleid
());
Double
last
=
res
.
getMetricfield
();
if
(
last
==
0
d
)
{
last
=
1
d
;
if
(
now
==
0
d
)
now
=
1
d
;
}
Double
d
=(
now
-
last
)/
last
;
d
=
d
*
100
;
//DecimalFormat df = new DecimalFormat("#.00");
BigDecimal
b
=
new
BigDecimal
(
d
);
d
=
b
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
obj
.
put
(
res
.
getRuleid
(),
d
);
}
if
(
bcalsum
)
{
HashMap
<
String
,
Double
>
sumlastset
=
new
HashMap
<
String
,
Double
>();
for
(
ExecResult
res:
list_yoy
)
{
Double
sumlast
=
0
d
;
Double
d
=
0
d
;
if
(
res
.
getMetricfield
()!=
null
)
{
d
=
res
.
getMetricfield
();
}
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
=(
double
)
sumobj
.
get
(
str
);
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
;
//DecimalFormat df = new DecimalFormat("#.00");
BigDecimal
b
=
new
BigDecimal
(
d
);
d
=
b
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
sumobj
.
put
(
str
,
d
);
}
}
//环比
List
<
ExecResult
>
list_mom
=
new
ArrayList
<>();
if
(
sum_mom
.
size
()>
0
)
{
List
<
ExecResult
>
listsum
=
execResultRepository
.
sum
(
sum_mom
,
1
,
dims
,
getLastMonth
(
start
),
getLastMonth
(
end
));
list_mom
.
addAll
(
listsum
);
}
if
(
avg_mom
.
size
()>
0
)
{
List
<
ExecResult
>
listavg
=
execResultRepository
.
avg
(
avg_mom
,
1
,
dims
,
getLastMonth
(
start
),
getLastMonth
(
end
));
list_mom
.
addAll
(
listavg
);
}
for
(
ExecResult
res:
list_mom
)
{
if
(!
dimsSet
.
containsKey
(
res
.
getDimfield
()))
continue
;
HashMap
<
String
,
Object
>
obj
=
dimsSet
.
get
(
res
.
getDimfield
());
Double
now
=(
double
)
obj
.
get
(
res
.
getRuleid
());
Double
last
=
res
.
getMetricfield
();
if
(
last
==
0
d
)
{
last
=
1
d
;
if
(
now
==
0
d
)
now
=
1
d
;
}
Double
d
=(
now
-
last
)/
last
;
d
=
d
*
100
;
//DecimalFormat df = new DecimalFormat("#.00");
BigDecimal
b
=
new
BigDecimal
(
d
);
d
=
b
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
obj
.
put
(
res
.
getRuleid
(),
d
);
}
if
(
bcalsum
)
{
HashMap
<
String
,
Double
>
sumlastset
=
new
HashMap
<
String
,
Double
>();
for
(
ExecResult
res:
list_mom
)
{
Double
sumlast
=
0
d
;
Double
d
=
0
d
;
if
(
res
.
getMetricfield
()!=
null
)
{
d
=
res
.
getMetricfield
();
}
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
=(
double
)
sumobj
.
get
(
str
);
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
;
//DecimalFormat df = new DecimalFormat("#.00");
BigDecimal
b
=
new
BigDecimal
(
d
);
d
=
b
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
sumobj
.
put
(
str
,
d
);
}
}
//占比
sum_per
.
addAll
(
avg_per
);
for
(
DAMetric
res:
sum_per
)
{
boolean
isPerOri
=
false
;
if
(
"PER_ORI"
.
equalsIgnoreCase
(
res
.
getExtOp
()))
isPerOri
=
true
;
for
(
HashMap
<
String
,
Object
>
obj:
dimsObj
)
{
if
(
StringUtils
.
isEmpty
(
obj
.
get
(
res
.
getMetricId
()))
||
StringUtils
.
isEmpty
(
obj
.
get
(
res
.
getRefMetric
())))
{
continue
;
}
Double
cur
=(
double
)
obj
.
get
(
res
.
getMetricId
());
Double
per
=(
double
)
obj
.
get
(
res
.
getRefMetric
());
if
(
per
==
0
d
)
per
=
1
d
;
Double
d
=(
cur
)/
per
;
if
(!
isPerOri
)
{
d
=
d
*
100
;
}
BigDecimal
b
=
new
BigDecimal
(
d
);
d
=
b
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
obj
.
put
(
res
.
getMetricId
(),
d
);
}
}
return
dimsObj
;
}
/**
* 清除和绩效考核有关的缓存
*/
@Caching
(
evict
={
@CacheEvict
(
value
=
"getPerformanceData"
,
allEntries
=
true
),
@CacheEvict
(
value
=
"sumPerformancePiece"
,
allEntries
=
true
)})
public
void
resetPerformance
()
{
}
@Caching
(
evict
={
@CacheEvict
(
value
=
"onFetchMetricDatas"
,
allEntries
=
true
),
@CacheEvict
(
value
=
"onFetchReportDatas"
,
allEntries
=
true
),
@CacheEvict
(
value
=
"onFetchKeyValueField"
,
allEntries
=
true
)})
public
void
resetsnap
()
{
}
/**
* 清除获取指标的缓存
*/
@CacheEvict
(
value
=
"onFetchMetricDatas"
,
allEntries
=
true
)
public
void
resetsnapSingle
()
{
}
/**
* 清除报表的缓存
*/
@Caching
(
evict
={
@CacheEvict
(
value
=
"onFetchReportDatas"
,
allEntries
=
true
)})
public
void
resetsnapReport
()
{
}
/**
* 获取以单位为表头的表格数据结构
* @param execResults
* @param rowJson
* @return
*/
public
JSONObject
getErReportHeader
(
List
<
HashMap
<
String
,
Object
>>
execResults
,
JSONArray
rowJson
)
{
JSONObject
allData
=
new
JSONObject
();
JSONArray
Vmcfg
=
new
JSONArray
();
if
(
execResults
==
null
||
execResults
.
size
()
==
0
)
{
return
allData
;
}
JSONObject
employeeIdRowJson
=
new
JSONObject
();
employeeIdRowJson
.
put
(
"field"
,
"employeeId"
);
employeeIdRowJson
.
put
(
"hide"
,
true
);
// employeeIdRowJson.put("width", 150);
Vmcfg
.
add
(
employeeIdRowJson
);
JSONObject
no
=
new
JSONObject
();
no
.
put
(
"headerName"
,
""
);
// no.put("width", 80);
no
.
put
(
"hide"
,
true
);
// no.put("entity", "TEST");
no
.
put
(
"field"
,
"employeeName"
);
no
.
put
(
"pinned"
,
"left"
);
Vmcfg
.
add
(
no
);
JSONArray
allRowData
=
new
JSONArray
();
int
iStart
=
100
;
JSONArray
initTreeJson
=
this
.
initGroupTreeData
(
rowJson
,
iStart
,
true
);
// 初始化表格数据
try
{
for
(
HashMap
<
String
,
Object
>
dataMap:
execResults
)
{
JSONObject
headerJson
=
new
JSONObject
();
String
strDimname
=
DataObject
.
getStringValue
(
dataMap
.
get
(
"dimname"
),
""
);
String
strDimcode
=
DataObject
.
getStringValue
(
dataMap
.
get
(
"dimcode"
),
""
);
headerJson
.
put
(
"headerName"
,
strDimname
);
headerJson
.
put
(
"entity"
,
"TEST"
);
// headerJson.put("width", 80);
headerJson
.
put
(
"field"
,
strDimcode
);
Vmcfg
.
add
(
headerJson
);
// 设置表头
// 设置表格数据
this
.
setReportRowData
(
initTreeJson
,
dataMap
,
allRowData
,
true
);
}
allRowData
=
initTreeJson
;
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
JSONArray
jsonArray
=
new
JSONArray
();
jsonArray
.
add
(
allRowData
);
allData
.
put
(
"headData"
,
Vmcfg
);
allData
.
put
(
"erportdata"
,
jsonArray
);
return
allData
;
}
/**
* 设置表格的数据
* @param jsonArray
* @param dataMap
* @param allRowData
* @param isInstall
* @return
*/
public
JSONArray
setReportRowData
(
JSONArray
jsonArray
,
HashMap
<
String
,
Object
>
dataMap
,
JSONArray
allRowData
,
boolean
isInstall
)
{
JSONArray
allRowDataJson
=
new
JSONArray
();
if
(
isInstall
)
{
allRowDataJson
=
allRowData
;
}
if
(
jsonArray
==
null
||
dataMap
==
null
||
dataMap
.
size
()
==
0
)
{
return
allRowDataJson
;
}
try
{
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
JSONObject
jsonObject
=
jsonArray
.
getJSONObject
(
i
);
String
strField
=
jsonObject
.
getString
(
"field"
);
JSONArray
childrenJson
=
jsonObject
.
getJSONArray
(
"children"
);
JSONObject
treeRowData
=
new
JSONObject
();
if
(!
StringUtils
.
isEmpty
(
strField
)
&&
dataMap
.
containsKey
(
strField
))
{
String
strDimcode
=
DataObject
.
getStringValue
(
dataMap
.
get
(
"dimcode"
),
""
);
Double
strNumber
=
DataObject
.
getDoubleValue
(
dataMap
.
get
(
strField
),
0
d
);
jsonObject
.
put
(
strDimcode
,
strNumber
);
}
if
(
childrenJson
!=
null
&&
childrenJson
.
size
()
>
0
)
{
JSONArray
headerChildrenJson
=
this
.
setReportRowData
(
childrenJson
,
dataMap
,
allRowDataJson
,
false
);
treeRowData
.
put
(
"children"
,
headerChildrenJson
);
}
// allRowDataJson.add(treeRowData);
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
return
allRowDataJson
;
}
/**
* 初始化表格数据
* @param jsonArray
* @param employeeId
* @param isSum
* @return
*/
public
JSONArray
initGroupTreeData
(
JSONArray
jsonArray
,
int
employeeId
,
boolean
isSum
)
{
JSONArray
groupData
=
new
JSONArray
();
if
(
jsonArray
==
null
)
{
return
jsonArray
;
}
try
{
int
no
=
employeeId
;
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
if
(
isSum
)
{
no
=
employeeId
*(
i
+
1
);
isSum
=
false
;
}
no
++;
JSONObject
jsonObject
=
jsonArray
.
getJSONObject
(
i
);
String
strHeaderName
=
jsonObject
.
getString
(
"headerName"
);
String
strField
=
jsonObject
.
getString
(
"field"
);
String
strEntity
=
jsonObject
.
getString
(
"entity"
);
JSONArray
childrenJson
=
jsonObject
.
getJSONArray
(
"children"
);
JSONObject
treeRowData
=
new
JSONObject
();
treeRowData
.
put
(
"employeeName"
,
strHeaderName
);
treeRowData
.
put
(
"employeeId"
,
no
);
treeRowData
.
put
(
"entity"
,
strEntity
);
if
(!
StringUtils
.
isEmpty
(
strField
))
{
treeRowData
.
put
(
"field"
,
strField
);
}
if
(
childrenJson
!=
null
&&
childrenJson
.
size
()
>
0
)
{
JSONArray
headerChildrenJson
=
this
.
initGroupTreeData
(
childrenJson
,
no
,
false
);
treeRowData
.
put
(
"children"
,
headerChildrenJson
);
isSum
=
true
;
}
groupData
.
add
(
treeRowData
);
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
return
groupData
;
}
/**
* 获取查询指标清单
*
* @param jsonArray
* @return
*/
public
List
<
String
>
getRuleids
(
JSONArray
jsonArray
)
{
List
<
String
>
ruleidList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
JSONObject
jsonObject
=
jsonArray
.
getJSONObject
(
i
);
String
strField
=
jsonObject
.
getString
(
"field"
);
jsonObject
.
getString
(
"field"
);
if
(
jsonObject
.
containsKey
(
"children"
))
{
JSONArray
childrenJson
=
jsonObject
.
getJSONArray
(
"children"
);
if
(
childrenJson
!=
null
)
{
ruleidList
.
addAll
(
this
.
getRuleids
(
childrenJson
));
}
}
if
(!
StringUtils
.
isEmpty
(
strField
))
ruleidList
.
add
(
strField
);
}
return
ruleidList
;
}
/**
* 获取报表的数据字典
* @param daReport
* @return
*/
public
String
getDict
(
DAReport
daReport
)
{
String
strDict
=
"DST_cl_dst_region"
;
if
(
daReport
!=
null
&&
!
StringUtils
.
isEmpty
(
daReport
.
getDict
()))
{
strDict
=
"DST_"
+
daReport
.
getDict
();
}
return
strDict
;
}
public
JSONArray
getVMCFG
(
String
strVMCFG
,
String
strType
)
{
JSONArray
Vmcfg
=
new
JSONArray
();
JSONObject
no
=
new
JSONObject
();
JSONObject
dimname
=
new
JSONObject
();
if
(!
StringUtils
.
isEmpty
(
strType
)
&&
"JXKH"
.
equals
(
strType
))
{
dimname
.
put
(
"headerName"
,
"承办人"
);
no
.
put
(
"headerName"
,
"单位"
);
no
.
put
(
"width"
,
150
);
}
else
{
dimname
.
put
(
"headerName"
,
"地区"
);
no
.
put
(
"headerName"
,
"序号"
);
no
.
put
(
"width"
,
80
);
}
no
.
put
(
"entity"
,
"TEST"
);
no
.
put
(
"field"
,
"no"
);
no
.
put
(
"pinned"
,
"left"
);
dimname
.
put
(
"entity"
,
"TEST"
);
dimname
.
put
(
"field"
,
"dimname"
);
dimname
.
put
(
"width"
,
120
);
dimname
.
put
(
"pinned"
,
"left"
);
Vmcfg
.
add
(
no
);
Vmcfg
.
add
(
dimname
);
Vmcfg
.
addAll
(
JSONArray
.
parseArray
(
strVMCFG
));
this
.
setHeaderEntity
(
Vmcfg
);
return
Vmcfg
;
}
/**
* 增加设置报表指标的实体
* @param jsonArray
* @return
*/
public
JSONArray
setHeaderEntity
(
JSONArray
jsonArray
)
{
JSONArray
resultJson
=
new
JSONArray
();
if
(
jsonArray
==
null
||
jsonArray
.
size
()
==
0
)
{
return
resultJson
;
}
for
(
int
i
=
0
;
i
<
jsonArray
.
size
();
i
++)
{
JSONObject
cellJson
=
jsonArray
.
getJSONObject
(
i
);
String
strField
=
cellJson
.
getString
(
"field"
);
if
(!
StringUtils
.
isEmpty
(
strField
))
{
RuleItem
dstRule
=
this
.
ruleItemExService
.
getById
(
strField
);
if
(
dstRule
!=
null
)
{
String
strEntityName
=
dstRule
.
getRuleName
();
cellJson
.
put
(
"entity"
,
strEntityName
);
}
}
else
{
JSONArray
childrenJson
=
cellJson
.
getJSONArray
(
"children"
);
if
(
childrenJson
!=
null
)
{
this
.
setHeaderEntity
(
childrenJson
);
}
}
}
return
resultJson
;
}
public
Map
<
String
,
String
>
page
(
PagingState
pagingState
,
String
ruleid
,
Integer
retValue
,
String
dims
,
Timestamp
start
,
Timestamp
end
,
boolean
bResolve
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<
String
,
String
>();
List
<
String
>
keyvaluefield
=
new
ArrayList
<
String
>();
// 查询数据
ResultSet
rs
=
execResultRepository
.
getPageData
(
ruleid
,
pagingState
,
retValue
,
dims
,
start
,
end
);
// 分页信息处理
PagingState
resultpagingState
=
rs
.
getExecutionInfo
().
getPagingState
();
String
strPagingState
=
""
;
if
(
resultpagingState
!=
null
)
{
strPagingState
=
resultpagingState
.
toString
();
}
result
.
put
(
"pagingState"
,
strPagingState
);
// 代码实现跳页查询,bResolve等于TRUE表示真正要查询的页数
if
(!
bResolve
)
{
return
result
;
}
//请注意,我们不依赖RESULTS_PER_PAGE,因为fetch size并不意味着cassandra总是返回准确的结果集
//它可能返回比fetch size稍微多一点或者少一点,另外,我们可能在结果集的结尾
int
remaining
=
rs
.
getAvailableWithoutFetching
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
Row
row
:
rs
)
{
String
strSymbolKeyValue
=
String
.
format
(
"\'%s\', "
,
row
.
getString
(
"keyvaluefield"
));
stringBuilder
.
append
(
strSymbolKeyValue
);
if
(--
remaining
==
0
)
{
break
;
}
}
String
strKeyValues
=
""
;
if
(
stringBuilder
!=
null
&&
stringBuilder
.
length
()
>
0
)
{
String
strKeyValueLists
=
stringBuilder
.
toString
();
strKeyValues
=
strKeyValueLists
.
substring
(
0
,
strKeyValueLists
.
length
()
-
2
);
}
result
.
put
(
"datas"
,
strKeyValues
);
return
result
;
}
public
static
Timestamp
getDefaultStartTimestamp
()
{
Calendar
c
=
Calendar
.
getInstance
();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
d
=
new
Date
();
try
{
d
=
simpleDateFormat
.
parse
(
simpleDateFormat
.
format
(
new
Date
()));
}
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
();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
d
=
new
Date
();
try
{
d
=
simpleDateFormat
.
parse
(
simpleDateFormat
.
format
(
new
Date
()));
}
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
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
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-provider/ibzdst-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/DACoreResource.java
浏览文件 @
b5502fd3
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
import
cn.ibizlab.core.analysis.domain.DAReport
;
import
cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl
;
import
cn.ibizlab.core.extensions.domain.FetchMetricDatasParam
;
import
cn.ibizlab.core.extensions.service.DACoreService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Api
(
tags
=
{
"接口"
})
...
...
@@ -16,4 +27,72 @@ public class DACoreResource {
@Autowired
private
DACoreService
daCoreService
;
@Autowired
private
DAReportServiceImpl
daReportService
;
/**
* 通过指标获取相应的规则结果数据
* @param param
* @return
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/analyse/reportdata/fetchmetricdatas"
)
public
ResponseEntity
<
List
<
HashMap
<
String
,
Object
>>>
fetchMetricDatas
(
@Validated
@RequestBody
FetchMetricDatasParam
param
){
List
<
HashMap
<
String
,
Object
>>
execResults
=
daCoreService
.
onFetchMetricDatas
(
param
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
execResults
);
}
/**
* 呈报报表获取数据
* @param param
* @return
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/analyse/reportdata/fetchreportdatas"
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
fetchReportDatas
(
@Validated
@RequestBody
FetchMetricDatasParam
param
)
{
Map
<
String
,
Object
>
resultMap
=
daCoreService
.
onFetchReportDatas
(
param
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
resultMap
);
}
/**
* 获取反查数据用到的keyvalue
* @param param
* @return
*/
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/analyse/reportdata/fetchkeyvaluefield"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
fetchKeyValueField
(
@Validated
@RequestBody
FetchMetricDatasParam
param
)
{
Map
<
String
,
String
>
results
=
daCoreService
.
onFetchKeyValueField
(
param
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
results
);
}
/**
* 清除绩效数据缓存
* @param
* @return
*/
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"dst/analyse/reportdata/resetperformancedata/{resettype}"
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
resetPerformanceData
(
@PathVariable
(
name
=
"resettype"
,
required
=
false
)
String
resettype
)
{
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>();
if
(
StringUtils
.
isEmpty
(
resettype
))
{
throw
new
BadRequestAlertException
(
"请求参数为空"
,
""
,
""
);
}
String
strType
=
resettype
.
toUpperCase
();
switch
(
strType
)
{
case
"WORK_ALL"
:
// 消除所有的缓存
this
.
daCoreService
.
resetsnap
();
break
;
case
"WORK"
:
// 消除指定指标的缓存
this
.
daCoreService
.
resetsnapSingle
();
break
;
case
"JXKH"
:
// 消除绩效报表的缓存
daCoreService
.
resetPerformance
();
daCoreService
.
resetsnap
();
break
;
case
"reloadReportData"
:
// 消除绩效报表的缓存
daCoreService
.
resetsnapReport
();
break
;
default
:
break
;
}
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
resultMap
);
}
}
ibzdst-util/src/main/java/cn/ibizlab/util/dict/CodeList.java
浏览文件 @
b5502fd3
...
...
@@ -42,4 +42,15 @@ public class CodeList
}
return
null
;
}
public
CodeItem
findChildren
(
Object
value
){
CodeItem
resultCodeItem
=
this
.
findCodeItem
(
value
);
List
<
CodeItem
>
children
=
new
ArrayList
<>();
for
(
CodeItem
codeItem
:
options
){
if
(
value
!=
null
&&
resultCodeItem
.
getValue
()
!=
null
&&
codeItem
.
getParent
()
!=
null
&&
codeItem
.
getParent
().
equals
(
resultCodeItem
.
getValue
()))
children
.
add
(
codeItem
);
}
resultCodeItem
.
setChildren
(
children
);
return
resultCodeItem
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录