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
a6bc68e9
Commit
a6bc68e9
authored
Jul 10, 2020
by
zhangkb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改获取基础项值接口和修复指标计算bug
parent
76d9f242
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
47 additions
and
75 deletions
+47
-75
DriveIndCalculateActor.java
...ymobile/indicators/akka/actor/DriveIndCalculateActor.java
+4
-3
DriveIndIdObjCalActor.java
...dicators/akka/actor/indicators/DriveIndIdObjCalActor.java
+6
-3
IndicatorsDataMapper.java
...dicators/model/mapper/indmapper/IndicatorsDataMapper.java
+4
-1
BaseIndDataService.java
...bile/indicators/service/hytobacco/BaseIndDataService.java
+10
-62
DriveIndDefService.java
...bile/indicators/service/hytobacco/DriveIndDefService.java
+2
-2
IndicatorsValueService.java
.../indicators/service/hytobacco/IndicatorsValueService.java
+4
-4
CalculateUtils.java
...n/java/com/keymobile/indicators/utils/CalculateUtils.java
+4
-0
IndicatorsDataMapper.xml
src/main/resources/mybatis/mapping/IndicatorsDataMapper.xml
+13
-0
No files found.
src/main/java/com/keymobile/indicators/akka/actor/DriveIndCalculateActor.java
View file @
a6bc68e9
...
@@ -127,9 +127,10 @@ public class DriveIndCalculateActor extends AbstractActor{
...
@@ -127,9 +127,10 @@ public class DriveIndCalculateActor extends AbstractActor{
indValue
=
"0.0"
;
indValue
=
"0.0"
;
}
}
try
{
try
{
driveIndFormula
=
driveIndFormula
.
replace
(
"["
+
indValueMsg
.
getIndId
()+
"]"
,
indValueMsg
.
getIndId
());
driveIndFormula
=
driveIndFormula
.
replace
(
"["
+
indValueMsg
.
getIndId
()+
"]"
,
indValue
);
//替换公式中的基础指标id为确定指标值
//替换公式中的基础指标id为确定指标值
env
.
put
(
indValueMsg
.
getIndId
(),
Double
.
valueOf
(
indValue
));
//
env.put(indValueMsg.getIndId(), Double.valueOf(indValue));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
logger
.
error
(
driveIndFormula
+
";"
+
env
);
logger
.
error
(
driveIndFormula
+
";"
+
env
);
...
@@ -141,7 +142,7 @@ public class DriveIndCalculateActor extends AbstractActor{
...
@@ -141,7 +142,7 @@ public class DriveIndCalculateActor extends AbstractActor{
driveIndDataType
=
null
;
driveIndDataType
=
null
;
//进行考核指标值计算
//进行考核指标值计算
try
{
try
{
String
driveIndValue
=
AviatorEvaluator
.
execute
(
driveIndFormula
,
env
).
toString
();
String
driveIndValue
=
AviatorEvaluator
.
execute
(
driveIndFormula
).
toString
();
//保留四位小数
//保留四位小数
if
(!
driveIndValue
.
equals
(
"NaN"
)
&&
!
driveIndValue
.
equals
(
"Infinite"
))
{
if
(!
driveIndValue
.
equals
(
"NaN"
)
&&
!
driveIndValue
.
equals
(
"Infinite"
))
{
driveIndValue
=
String
.
format
(
"%.4f"
,
driveIndValue
=
String
.
format
(
"%.4f"
,
...
...
src/main/java/com/keymobile/indicators/akka/actor/indicators/DriveIndIdObjCalActor.java
View file @
a6bc68e9
...
@@ -2,6 +2,7 @@ package com.keymobile.indicators.akka.actor.indicators;
...
@@ -2,6 +2,7 @@ package com.keymobile.indicators.akka.actor.indicators;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CopyOnWriteArrayList
;
...
@@ -24,6 +25,7 @@ import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
...
@@ -24,6 +25,7 @@ import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import
com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService
;
import
com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService
;
import
com.keymobile.indicators.service.hytobacco.DriveIndCalResultService
;
import
com.keymobile.indicators.service.hytobacco.DriveIndCalResultService
;
import
com.keymobile.indicators.service.hytobacco.DriveIndDefService
;
import
com.keymobile.indicators.service.hytobacco.DriveIndDefService
;
import
com.keymobile.indicators.utils.DateUtils
;
import
com.keymobile.indicators.utils.SpringUtil
;
import
com.keymobile.indicators.utils.SpringUtil
;
import
akka.actor.AbstractActor
;
import
akka.actor.AbstractActor
;
...
@@ -144,9 +146,9 @@ public class DriveIndIdObjCalActor extends AbstractActor{
...
@@ -144,9 +146,9 @@ public class DriveIndIdObjCalActor extends AbstractActor{
}
}
try
{
try
{
driveIndFormula
=
driveIndFormula
.
replace
(
"["
+
baseIndValueMsg
.
getIndId
()+
"]"
,
driveIndFormula
=
driveIndFormula
.
replace
(
"["
+
baseIndValueMsg
.
getIndId
()+
"]"
,
baseIndValueMsg
.
getIndId
()
);
indValue
);
//替换公式中的基础指标id为确定指标值
//替换公式中的基础指标id为确定指标值
env
.
put
(
baseIndValueMsg
.
getIndId
(),
Double
.
valueOf
(
indValue
));
//
env.put(baseIndValueMsg.getIndId(), Double.valueOf(indValue));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
logger
.
error
(
"driveIndId:"
+
driveIndId
+
";"
+
logger
.
error
(
"driveIndId:"
+
driveIndId
+
";"
+
...
@@ -170,7 +172,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{
...
@@ -170,7 +172,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{
if
(!
confirmList
.
contains
(
0
))
{
//取所有基础指标值没错
if
(!
confirmList
.
contains
(
0
))
{
//取所有基础指标值没错
//进行考核指标值计算
//进行考核指标值计算
try
{
try
{
String
driveIndValue
=
AviatorEvaluator
.
execute
(
driveIndFormula
,
env
).
toString
();
String
driveIndValue
=
AviatorEvaluator
.
execute
(
driveIndFormula
).
toString
();
//保留四位小数
//保留四位小数
if
(!
driveIndValue
.
equals
(
"NaN"
)
&&
!
driveIndValue
.
equals
(
"Infinite"
))
{
if
(!
driveIndValue
.
equals
(
"NaN"
)
&&
!
driveIndValue
.
equals
(
"Infinite"
))
{
driveIndValue
=
String
.
format
(
"%.4f"
,
driveIndValue
=
String
.
format
(
"%.4f"
,
...
@@ -185,6 +187,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{
...
@@ -185,6 +187,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{
}
else
{
}
else
{
driveIndCalResult
.
setUnit
(
unit
);
driveIndCalResult
.
setUnit
(
unit
);
driveIndCalResult
.
setValue
(
driveIndValue
);
driveIndCalResult
.
setValue
(
driveIndValue
);
driveIndCalResult
.
setLastUpdateTime
(
DateUtils
.
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
));
}
}
//保存进考核指标结果表中
//保存进考核指标结果表中
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
...
...
src/main/java/com/keymobile/indicators/model/mapper/indmapper/IndicatorsDataMapper.java
View file @
a6bc68e9
package
com
.
keymobile
.
indicators
.
model
.
mapper
.
indmapper
;
package
com
.
keymobile
.
indicators
.
model
.
mapper
.
indmapper
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
...
@@ -10,5 +11,7 @@ import tk.mybatis.mapper.common.BaseMapper;
...
@@ -10,5 +11,7 @@ import tk.mybatis.mapper.common.BaseMapper;
@Mapper
@Mapper
public
interface
IndicatorsDataMapper
extends
BaseMapper
<
IndicatorsData
>{
public
interface
IndicatorsDataMapper
extends
BaseMapper
<
IndicatorsData
>{
public
IndicatorsData
getDataByDimension
(
Map
<
String
,
Object
>
param
);
public
List
<
IndicatorsData
>
getDataByDimension
(
Map
<
String
,
Object
>
param
);
public
List
<
IndicatorsData
>
getIndDataByParam
(
Map
<
String
,
Object
>
param
);
}
}
src/main/java/com/keymobile/indicators/service/hytobacco/BaseIndDataService.java
View file @
a6bc68e9
...
@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
...
@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
import
com.keymobile.indicators.conf.MongoDBConfig
;
import
com.keymobile.indicators.conf.MongoDBConfig
;
import
com.keymobile.indicators.model.entity.indicators.IndicatorsData
;
import
com.keymobile.indicators.model.entity.indicators.IndicatorsData
;
import
com.keymobile.indicators.model.mapper.indmapper.IndicatorsDataMapper
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.DB
;
import
com.mongodb.DB
;
import
com.mongodb.DBCollection
;
import
com.mongodb.DBCollection
;
...
@@ -25,73 +26,20 @@ public class BaseIndDataService {
...
@@ -25,73 +26,20 @@ public class BaseIndDataService {
private
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseIndDataService
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseIndDataService
.
class
);
@Autowired
@Autowired
private
MongoDBConfig
mongoDbConfig
;
private
IndicatorsDataMapper
indicatorsDataMapper
;
@Value
(
"${mongodb.database}"
)
private
String
database
;
public
List
<
IndicatorsData
>
getAllIndData
(){
List
<
IndicatorsData
>
result
=
new
ArrayList
<>();
MongoClient
client
=
mongoDbConfig
.
mongoClient
();
/* 新建数据库实例,有则使用已有的数据库,没有则准别新建 */
DB
dataBase
=
client
.
getDB
(
database
);
/* 新建集合命名为user_info,如果该集合存在,则使用。否则新建 */
DBCollection
collection
=
dataBase
.
getCollection
(
"hy_indi_data"
);
DBObject
query
=
new
BasicDBObject
();
try
(
DBCursor
cursor
=
collection
.
find
(
query
))
{
while
(
cursor
.
hasNext
())
{
DBObject
dbo
=
cursor
.
next
();
IndicatorsData
data
=
new
IndicatorsData
();
data
.
setIndId
(
dbo
.
get
(
"indId"
).
toString
());
data
.
setIndDesc
(
dbo
.
get
(
"indDesc"
).
toString
());
data
.
setType
(
dbo
.
get
(
"type"
).
toString
());
data
.
setBatchNo
(
dbo
.
get
(
"batchNo"
).
toString
());
data
.
setDataType
(
dbo
.
get
(
"dataType"
).
toString
());
data
.
setUnit
(
dbo
.
get
(
"unit"
).
toString
());
data
.
setDim1
(
dbo
.
get
(
"dim1"
).
toString
());
data
.
setDim2
(
Integer
.
parseInt
(
dbo
.
get
(
"dim2"
).
toString
()));
if
(
dbo
.
get
(
"value"
)==
null
||
""
.
equals
(
dbo
.
get
(
"value"
)))
{
data
.
setValue
(
""
);
}
else
{
data
.
setValue
(
dbo
.
get
(
"value"
).
toString
());
}
result
.
add
(
data
);
}
}
client
.
close
();
return
result
;
}
public
List
<
String
>
getIndData
(
String
indId
,
int
date
,
List
<
String
>
compareObjs
){
public
List
<
String
>
getIndData
(
String
indId
,
int
date
,
List
<
String
>
compareObjs
){
List
<
String
>
result
=
new
ArrayList
<>();
List
<
String
>
result
=
new
ArrayList
<>();
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
MongoClient
client
=
mongoDbConfig
.
mongoClient
();
paramMap
.
put
(
"indId"
,
indId
);
/* 新建数据库实例,有则使用已有的数据库,没有则准别新建 */
paramMap
.
put
(
"date"
,
date
);
DB
dataBase
=
client
.
getDB
(
database
);
paramMap
.
put
(
"compareObjs"
,
compareObjs
);
List
<
IndicatorsData
>
resultData
=
indicatorsDataMapper
.
getIndDataByParam
(
paramMap
);
/* 新建集合命名为user_info,如果该集合存在,则使用。否则新建 */
if
(!
resultData
.
isEmpty
())
{
DBCollection
collection
=
dataBase
.
getCollection
(
"hy_indi_data"
);
for
(
IndicatorsData
data
:
resultData
)
{
result
.
add
(
data
.
getValue
());
DBObject
query
=
new
BasicDBObject
();
query
.
put
(
"indId"
,
indId
);
query
.
put
(
"dim2"
,
date
);
query
.
put
(
"dim1"
,
new
BasicDBObject
(
"$in"
,
compareObjs
));
try
(
DBCursor
cursor
=
collection
.
find
(
query
))
{
while
(
cursor
.
hasNext
())
{
DBObject
dbo
=
cursor
.
next
();
if
(
dbo
.
get
(
"value"
)==
null
||
""
.
equals
(
dbo
.
get
(
"value"
)))
{
result
.
add
(
"0.0"
);
}
else
{
result
.
add
(
dbo
.
get
(
"value"
).
toString
());
}
}
}
}
}
client
.
close
();
return
result
;
return
result
;
}
}
}
}
src/main/java/com/keymobile/indicators/service/hytobacco/DriveIndDefService.java
View file @
a6bc68e9
...
@@ -187,9 +187,9 @@ public class DriveIndDefService {
...
@@ -187,9 +187,9 @@ public class DriveIndDefService {
List
<
String
>
indDateList
=
baseIndDataService
.
getIndData
(
indId
,
date
,
compareObjs
);
List
<
String
>
indDateList
=
baseIndDataService
.
getIndData
(
indId
,
date
,
compareObjs
);
String
sumValue
=
CalculateUtils
.
sumValue
(
indDateList
);
String
sumValue
=
CalculateUtils
.
sumValue
(
indDateList
);
env
.
put
(
indId
,
Double
.
valueOf
(
sumValue
));
env
.
put
(
indId
,
Double
.
valueOf
(
sumValue
));
driveIndFormula
=
driveIndFormula
.
replace
(
"["
+
indId
+
"]"
,
indId
);
driveIndFormula
=
driveIndFormula
.
replace
(
"["
+
indId
+
"]"
,
sumValue
);
}
}
result
=
AviatorEvaluator
.
execute
(
driveIndFormula
,
env
).
toString
();
result
=
AviatorEvaluator
.
execute
(
driveIndFormula
).
toString
();
//保留四位小数
//保留四位小数
if
(!
"NaN"
.
equals
(
result
)
&&
!
"Infinite"
.
equals
(
result
))
{
if
(!
"NaN"
.
equals
(
result
)
&&
!
"Infinite"
.
equals
(
result
))
{
result
=
String
.
format
(
"%.4f"
,
result
=
String
.
format
(
"%.4f"
,
...
...
src/main/java/com/keymobile/indicators/service/hytobacco/IndicatorsValueService.java
View file @
a6bc68e9
...
@@ -665,12 +665,12 @@ public class IndicatorsValueService {
...
@@ -665,12 +665,12 @@ public class IndicatorsValueService {
paramMap
.
put
(
"dim1"
,
dimValue
.
getDimvalue
());
paramMap
.
put
(
"dim1"
,
dimValue
.
getDimvalue
());
}
}
}
}
IndicatorsData
indicatorsData
=
indicatorsDataMapper
.
getDataByDimension
(
paramMap
);
List
<
IndicatorsData
>
indicatorsData
=
indicatorsDataMapper
.
getDataByDimension
(
paramMap
);
if
(
indicatorsData
!=
null
)
{
if
(
indicatorsData
!=
null
)
{
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<>();
resultMap
.
put
(
"value"
,
indicatorsData
.
getValue
());
resultMap
.
put
(
"value"
,
indicatorsData
.
get
(
0
).
get
Value
());
resultMap
.
put
(
"unit"
,
indicatorsData
.
getUnit
());
resultMap
.
put
(
"unit"
,
indicatorsData
.
get
(
0
).
get
Unit
());
resultMap
.
put
(
"dataType"
,
indicatorsData
.
getDataType
());
resultMap
.
put
(
"dataType"
,
indicatorsData
.
get
(
0
).
get
DataType
());
return
resultMap
;
return
resultMap
;
}
}
return
null
;
return
null
;
...
...
src/main/java/com/keymobile/indicators/utils/CalculateUtils.java
View file @
a6bc68e9
...
@@ -9,6 +9,7 @@ import java.util.Map;
...
@@ -9,6 +9,7 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -111,6 +112,9 @@ public class CalculateUtils {
...
@@ -111,6 +112,9 @@ public class CalculateUtils {
StringBuilder
formula
=
new
StringBuilder
();
StringBuilder
formula
=
new
StringBuilder
();
if
(!
values
.
isEmpty
())
{
if
(!
values
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
if
(
StringUtils
.
isBlank
(
values
.
get
(
i
)))
{
continue
;
}
if
(
i
==
values
.
size
()-
1
)
{
//最后一个不加+号
if
(
i
==
values
.
size
()-
1
)
{
//最后一个不加+号
formula
.
append
(
"("
).
append
(
values
.
get
(
i
)).
append
(
")"
);
formula
.
append
(
"("
).
append
(
values
.
get
(
i
)).
append
(
")"
);
}
else
{
}
else
{
...
...
src/main/resources/mybatis/mapping/IndicatorsDataMapper.xml
View file @
a6bc68e9
...
@@ -9,4 +9,16 @@
...
@@ -9,4 +9,16 @@
dim1 = #{dim1} and
dim1 = #{dim1} and
dim2= #{dim2}
dim2= #{dim2}
</select>
</select>
<select
id=
"getIndDataByParam"
parameterType=
"map"
resultType=
"com.keymobile.indicators.model.entity.indicators.IndicatorsData"
>
select *
from indi_data_def
where
ind_id=#{indId} and
dim2= #{date} and
dim1 in
<foreach
item=
"obj"
collection=
"compareObjs"
open=
"("
close=
")"
separator=
","
>
#{obj}
</foreach>
</select>
</mapper>
</mapper>
\ No newline at end of file
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