Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
indicators
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangkb
indicators
Commits
d691a580
Commit
d691a580
authored
Jan 26, 2021
by
hzc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
指标积分公式增加绝对值,公式的最大值最小值
parent
8998c6a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
1 deletion
+100
-1
IndScorecardService.java
...ile/indicators/service/hytobacco/IndScorecardService.java
+100
-1
No files found.
src/main/java/com/keymobile/indicators/service/hytobacco/IndScorecardService.java
View file @
d691a580
...
@@ -162,6 +162,7 @@ public class IndScorecardService {
...
@@ -162,6 +162,7 @@ public class IndScorecardService {
List
<
DriveIndCalResultDef
>
currentDriveResult
=
driveIndCalResultDefMapper
List
<
DriveIndCalResultDef
>
currentDriveResult
=
driveIndCalResultDefMapper
.
findByIndIdAndDateAndCompareIdAndSort
(
indId
,
date
,
compareId
,
.
findByIndIdAndDateAndCompareIdAndSort
(
indId
,
date
,
compareId
,
code
,
dateMark
);
code
,
dateMark
);
if
(!
currentDriveResult
.
isEmpty
())
{
if
(!
currentDriveResult
.
isEmpty
())
{
//过滤考核指标结果集无效值
//过滤考核指标结果集无效值
Iterator
<
DriveIndCalResultDef
>
it
=
currentDriveResult
.
iterator
();
Iterator
<
DriveIndCalResultDef
>
it
=
currentDriveResult
.
iterator
();
...
@@ -397,6 +398,30 @@ public class IndScorecardService {
...
@@ -397,6 +398,30 @@ public class IndScorecardService {
List
<
DriveIndCalResultDef
>
currentDriveResult
,
String
acsType
)
{
List
<
DriveIndCalResultDef
>
currentDriveResult
,
String
acsType
)
{
double
value
=
0
;
double
value
=
0
;
Map
<
String
,
Object
>
env
=
Maps
.
newHashMap
();
Map
<
String
,
Object
>
env
=
Maps
.
newHashMap
();
String
formulaTmp
=
""
;
double
fValue
=
0
;
//求公式最大值FMAX
if
(
formula
.
indexOf
(
"FMAX"
)>=
0
){
int
maxIndex
=
formula
.
indexOf
(
"FMAX"
);
String
sub
=
formula
.
substring
(
maxIndex
);
formulaTmp
=
sub
.
substring
(
0
,
sub
.
indexOf
(
")"
)+
1
);
//formula公式,currentDriveResult结果,true 最大值
fValue
=
getFValue
(
formulaTmp
,
currentDriveResult
,
acsType
,
true
);
formula
.
replace
(
formulaTmp
,
String
.
valueOf
(
fValue
));
}
//求公式最小值FMIN
if
(
formula
.
indexOf
(
"FMIN"
)>=
0
){
int
maxIndex
=
formula
.
indexOf
(
"FMIN"
);
String
sub
=
formula
.
substring
(
maxIndex
);
formulaTmp
=
sub
.
substring
(
0
,
sub
.
indexOf
(
")"
)+
1
);
//formula公式,currentDriveResult结果,true 最大值
fValue
=
getFValue
(
formulaTmp
,
currentDriveResult
,
acsType
,
false
);
formula
.
replace
(
formulaTmp
,
String
.
valueOf
(
fValue
));
}
//是否有绝对值
if
(
formula
.
indexOf
(
"ABS"
)>=
0
){
formula
.
replace
(
"ABS"
,
"math.abs"
);
}
//解析X,MIN,MAX,AVG
//解析X,MIN,MAX,AVG
if
(
formula
.
indexOf
(
"X"
)>=
0
)
{
if
(
formula
.
indexOf
(
"X"
)>=
0
)
{
//获取指标值
//获取指标值
...
@@ -439,7 +464,81 @@ public class IndScorecardService {
...
@@ -439,7 +464,81 @@ public class IndScorecardService {
}
}
return
value
;
return
value
;
}
}
/**
* 求公式结果的最大值最小值
* @Param [formula, currentDriveResult, isMax]
* @Date 2021/1/26 9:28
* @Author hzc
**/
private
double
getFValue
(
String
formula
,
List
<
DriveIndCalResultDef
>
currentDriveResult
,
String
acsType
,
boolean
isMax
)
{
Map
<
String
,
Object
>
env
=
new
HashMap
<>();
formula
=
formula
.
substring
(
formula
.
indexOf
(
"("
));
if
(
formula
.
indexOf
(
"MIN"
)>=
0
)
{
//获取组内最小值
double
min
=
0
;
if
(
"1"
.
equals
(
acsType
))
{
min
=
Double
.
valueOf
(
currentDriveResult
.
get
(
0
).
getValue
());
}
else
{
min
=
Double
.
valueOf
(
currentDriveResult
.
get
(
currentDriveResult
.
size
()-
1
).
getValue
());
}
env
.
put
(
"MIN"
,
min
);
}
if
(
formula
.
indexOf
(
"MAX"
)>=
0
)
{
//获取组内最大值
double
max
=
0
;
if
(
"1"
.
equals
(
acsType
))
{
max
=
Double
.
valueOf
(
currentDriveResult
.
get
(
currentDriveResult
.
size
()-
1
).
getValue
());
}
else
{
max
=
Double
.
valueOf
(
currentDriveResult
.
get
(
0
).
getValue
());
}
env
.
put
(
"MAX"
,
max
);
}
if
(
formula
.
indexOf
(
"AVG"
)>=
0
)
{
//获取组内平均值
double
avg
=
0
;
if
(!
currentDriveResult
.
isEmpty
())
{
avg
=
Double
.
valueOf
(
currentDriveResult
.
get
(
0
).
getAverage
());
}
env
.
put
(
"AVG"
,
avg
);
}
double
value
=
0
,
fValue
;
if
(
isMax
){
fValue
=
Double
.
MIN_VALUE
;
}
else
{
fValue
=
Double
.
MAX_VALUE
;
}
for
(
DriveIndCalResultDef
driveIndCalResultDef
:
currentDriveResult
)
{
//解析X,MIN,MAX,AVG
if
(
formula
.
indexOf
(
"X"
)>=
0
)
{
//获取指标值
double
x
=
Double
.
valueOf
(
driveIndCalResultDef
.
getValue
());
env
.
put
(
"X"
,
x
);
}
if
(!
env
.
isEmpty
())
{
try
{
value
=
(
Double
)
AviatorEvaluator
.
execute
(
formula
,
env
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"计算指标积分求公式结果的最大值最小值错误:formula:"
+
formula
+
";env:"
+
env
);
}
}
else
{
value
=
Double
.
valueOf
(
formula
);
}
//是否求最大值
if
(
isMax
){
if
(
value
>
fValue
){
fValue
=
value
;
}
}
else
{
//求最小值
if
(
value
<
fValue
){
fValue
=
value
;
}
}
env
.
remove
(
"X"
);
}
return
fValue
;
}
private
IndScorecard
changeJson
(
IndScorecard
scorecard
)
{
private
IndScorecard
changeJson
(
IndScorecard
scorecard
)
{
Gson
gson
=
new
Gson
();
Gson
gson
=
new
Gson
();
if
(
StringUtils
.
isNotBlank
(
scorecard
.
getAddScoreItemJson
()))
{
if
(
StringUtils
.
isNotBlank
(
scorecard
.
getAddScoreItemJson
()))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment