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
1b3a72c7
Commit
1b3a72c7
authored
May 09, 2020
by
zhangkb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传对标评分卡功能代码
parent
21b63d21
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1109 additions
and
30 deletions
+1109
-30
DriveIndCalculateActor.java
...ymobile/indicators/akka/actor/DriveIndCalculateActor.java
+7
-2
DriveIndCalculateRegionActor.java
...ors/akka/actor/specific/DriveIndCalculateRegionActor.java
+43
-11
DriveIndAverageAndRankMsg.java
...tors/akka/message/specific/DriveIndAverageAndRankMsg.java
+12
-2
IndScorecardCtrl.java
.../keymobile/indicators/api/hytobacco/IndScorecardCtrl.java
+57
-0
IndicatorsValueCtrl.java
...ymobile/indicators/api/hytobacco/IndicatorsValueCtrl.java
+36
-0
DriveIndCalResult.java
.../keymobile/indicators/model/entity/DriveIndCalResult.java
+4
-1
ImproveScoreDef.java
...le/indicators/model/entity/scorecard/ImproveScoreDef.java
+18
-0
IndScorecard.java
...obile/indicators/model/entity/scorecard/IndScorecard.java
+59
-0
RankScoreDef.java
...obile/indicators/model/entity/scorecard/RankScoreDef.java
+16
-0
DriveIndCalResultRepository.java
...persistence/hyindicators/DriveIndCalResultRepository.java
+16
-0
IndScorecardRepository.java
...tors/persistence/hyindicators/IndScorecardRepository.java
+9
-0
DriveIndCalResultService.java
...ndicators/service/hytobacco/DriveIndCalResultService.java
+9
-0
IndScorecardService.java
...ile/indicators/service/hytobacco/IndScorecardService.java
+290
-0
IndicatorsValueService.java
.../indicators/service/hytobacco/IndicatorsValueService.java
+490
-6
CalculateUtils.java
...n/java/com/keymobile/indicators/utils/CalculateUtils.java
+43
-8
No files found.
src/main/java/com/keymobile/indicators/akka/actor/DriveIndCalculateActor.java
View file @
1b3a72c7
...
@@ -59,6 +59,8 @@ public class DriveIndCalculateActor extends AbstractActor{
...
@@ -59,6 +59,8 @@ public class DriveIndCalculateActor extends AbstractActor{
private
String
unit
;
private
String
unit
;
private
String
markType
;
private
String
driveIndId
;
private
String
driveIndId
;
private
Map
<
String
,
Object
>
env
=
Maps
.
newHashMap
();
private
Map
<
String
,
Object
>
env
=
Maps
.
newHashMap
();
...
@@ -89,6 +91,7 @@ public class DriveIndCalculateActor extends AbstractActor{
...
@@ -89,6 +91,7 @@ public class DriveIndCalculateActor extends AbstractActor{
IndAcsDef
indAcsDef
=
indAcsDefService
.
getById
(
driveIndId
);
IndAcsDef
indAcsDef
=
indAcsDefService
.
getById
(
driveIndId
);
unit
=
indAcsDef
.
getUnt
();
unit
=
indAcsDef
.
getUnt
();
indType
=
indAcsDef
.
getIndType
();
indType
=
indAcsDef
.
getIndType
();
markType
=
indAcsDef
.
getMarkType
();
List
<
IndAcsScoreInfo
>
acsSoreInfoList
=
indAcsScoreInfoService
.
getListByIndId
(
List
<
IndAcsScoreInfo
>
acsSoreInfoList
=
indAcsScoreInfoService
.
getListByIndId
(
driveIndId
);
driveIndId
);
...
@@ -155,7 +158,8 @@ public class DriveIndCalculateActor extends AbstractActor{
...
@@ -155,7 +158,8 @@ public class DriveIndCalculateActor extends AbstractActor{
//返回指标值回去算平均值和排名
//返回指标值回去算平均值和排名
DriveIndAverageAndRankMsg
driveIndAverageAndRankMsg
=
DriveIndAverageAndRankMsg
driveIndAverageAndRankMsg
=
new
DriveIndAverageAndRankMsg
(
driveIndCalResult
.
getId
(),
new
DriveIndAverageAndRankMsg
(
driveIndCalResult
.
getId
(),
compareId
,
driveIndId
,
compareObj
,
date
,
driveIndValue
,
unit
,
indType
);
compareId
,
driveIndId
,
compareObj
,
date
,
driveIndValue
,
unit
,
indType
,
markType
);
driveIndCalculateRegionActor
.
tell
(
driveIndAverageAndRankMsg
,
ActorRef
.
noSender
());
driveIndCalculateRegionActor
.
tell
(
driveIndAverageAndRankMsg
,
ActorRef
.
noSender
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
DriveIndCalResult
driveIndCalResult
=
new
DriveIndCalResult
(
compareId
,
DriveIndCalResult
driveIndCalResult
=
new
DriveIndCalResult
(
compareId
,
...
@@ -163,7 +167,8 @@ public class DriveIndCalculateActor extends AbstractActor{
...
@@ -163,7 +167,8 @@ public class DriveIndCalculateActor extends AbstractActor{
driveIndCalResult
=
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
driveIndCalResult
=
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
DriveIndAverageAndRankMsg
driveIndAverageAndRankMsg
=
DriveIndAverageAndRankMsg
driveIndAverageAndRankMsg
=
new
DriveIndAverageAndRankMsg
(
driveIndCalResult
.
getId
(),
new
DriveIndAverageAndRankMsg
(
driveIndCalResult
.
getId
(),
compareId
,
driveIndId
,
compareObj
,
date
,
"0(Error)"
,
unit
,
indType
);
compareId
,
driveIndId
,
compareObj
,
date
,
"0(Error)"
,
unit
,
indType
,
markType
);
driveIndCalculateRegionActor
.
tell
(
driveIndAverageAndRankMsg
,
ActorRef
.
noSender
());
driveIndCalculateRegionActor
.
tell
(
driveIndAverageAndRankMsg
,
ActorRef
.
noSender
());
logger
.
error
(
"env:"
+
env
+
";formula:"
+
driveIndFormula
);
logger
.
error
(
"env:"
+
env
+
";formula:"
+
driveIndFormula
);
}
}
...
...
src/main/java/com/keymobile/indicators/akka/actor/specific/DriveIndCalculateRegionActor.java
View file @
1b3a72c7
...
@@ -13,6 +13,7 @@ import com.keymobile.indicators.akka.message.specific.DriveIndCalculateRegionMsg
...
@@ -13,6 +13,7 @@ import com.keymobile.indicators.akka.message.specific.DriveIndCalculateRegionMsg
import
com.keymobile.indicators.model.entity.DimValue
;
import
com.keymobile.indicators.model.entity.DimValue
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
import
com.keymobile.indicators.service.hytobacco.DriveIndCalResultService
;
import
com.keymobile.indicators.service.hytobacco.DriveIndCalResultService
;
import
com.keymobile.indicators.service.hytobacco.IndScorecardService
;
import
com.keymobile.indicators.utils.CalculateUtils
;
import
com.keymobile.indicators.utils.CalculateUtils
;
import
com.keymobile.indicators.utils.SpringUtil
;
import
com.keymobile.indicators.utils.SpringUtil
;
...
@@ -24,6 +25,8 @@ public class DriveIndCalculateRegionActor extends AbstractActor{
...
@@ -24,6 +25,8 @@ public class DriveIndCalculateRegionActor extends AbstractActor{
private
DriveIndCalResultService
driveIndCalResultService
=
SpringUtil
.
getBean
(
DriveIndCalResultService
.
class
);
private
DriveIndCalResultService
driveIndCalResultService
=
SpringUtil
.
getBean
(
DriveIndCalResultService
.
class
);
private
IndScorecardService
indScorecardService
=
SpringUtil
.
getBean
(
IndScorecardService
.
class
);
private
int
numberOfConfirm
=
0
;
//定义返回确认消息的子actor
private
int
numberOfConfirm
=
0
;
//定义返回确认消息的子actor
private
int
compareObjSize
=
0
;
//对标对象个数
private
int
compareObjSize
=
0
;
//对标对象个数
...
@@ -61,20 +64,49 @@ public class DriveIndCalculateRegionActor extends AbstractActor{
...
@@ -61,20 +64,49 @@ public class DriveIndCalculateRegionActor extends AbstractActor{
String
value
=
driveIndAverageAndRankMsg
.
getDriveIndValue
();
String
value
=
driveIndAverageAndRankMsg
.
getDriveIndValue
();
String
id
=
driveIndAverageAndRankMsg
.
getId
();
String
id
=
driveIndAverageAndRankMsg
.
getId
();
String
indType
=
driveIndAverageAndRankMsg
.
getIndType
();
String
indType
=
driveIndAverageAndRankMsg
.
getIndType
();
String
markType
=
driveIndAverageAndRankMsg
.
getMarkType
();
//评分卡id
valueMap
.
put
(
id
,
value
);
valueMap
.
put
(
id
,
value
);
values
.
add
(
value
);
values
.
add
(
value
);
if
(++
numberOfConfirm
>=
compareObjSize
)
{
//子actor全部返回
if
(++
numberOfConfirm
>=
compareObjSize
)
{
//子actor全部返回
//算平均数
//考核地区只有一个“全省”的情况下
String
average
=
CalculateUtils
.
averageValue
(
values
);
if
(!
"全省"
.
equals
(
driveIndAverageAndRankMsg
.
getCompareObj
()))
{
//算组内排名
//查询有没有全省的考核指标数据
Map
<
String
,
Integer
>
rankValue
=
CalculateUtils
.
rankValue
(
valueMap
,
indType
);
DriveIndCalResult
provinceDriveIndCalResult
=
driveIndCalResultService
.
findCompareObjInfo
(
for
(
Entry
<
String
,
Integer
>
entry
:
rankValue
.
entrySet
())
{
driveIndAverageAndRankMsg
.
getDriveIndId
(),
driveIndAverageAndRankMsg
.
getDate
(),
//根据id获取指标值结果
"全省"
);
DriveIndCalResult
driveIndCalResult
=
driveIndCalResultService
.
findById
(
entry
.
getKey
());
String
actualAverage
=
"0.0"
;
if
(
driveIndCalResult
!=
null
)
{
if
(
provinceDriveIndCalResult
!=
null
)
{
driveIndCalResult
.
setAverage
(
average
);
//获取实际平均分
driveIndCalResult
.
setRank
(
entry
.
getValue
());
actualAverage
=
provinceDriveIndCalResult
.
getValue
();
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
}
//算组内平均数
String
average
=
CalculateUtils
.
averageValue
(
values
);
//算组内排名
Map
<
String
,
Integer
>
rankValue
=
CalculateUtils
.
rankValue
(
valueMap
,
indType
);
for
(
Entry
<
String
,
Integer
>
entry
:
rankValue
.
entrySet
())
{
//根据id获取指标值结果
DriveIndCalResult
driveIndCalResult
=
driveIndCalResultService
.
findById
(
entry
.
getKey
());
if
(
driveIndCalResult
!=
null
)
{
driveIndCalResult
.
setAverage
(
average
);
driveIndCalResult
.
setRank
(
entry
.
getValue
());
driveIndCalResult
.
setActualAverage
(
actualAverage
);
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
}
}
//根据评分卡算指标分数
for
(
Entry
<
String
,
Integer
>
entry
:
rankValue
.
entrySet
())
{
//根据id获取指标值结果
DriveIndCalResult
driveIndCalResult
=
driveIndCalResultService
.
findById
(
entry
.
getKey
());
if
(
driveIndCalResult
!=
null
)
{
//计算分数
Map
<
String
,
String
>
scoreMap
=
indScorecardService
.
calculateIndiScore
(
driveIndCalResult
.
getIndId
(),
driveIndCalResult
.
getDate
(),
driveIndCalResult
.
getCompareObj
(),
markType
,
driveIndCalResult
.
getCompareId
());
driveIndCalResult
.
setScore
(
scoreMap
.
get
(
"score"
));
driveIndCalResult
.
setImproveScore
(
scoreMap
.
get
(
"improveScore"
));
driveIndCalResultService
.
saveOrUpdate
(
driveIndCalResult
);
}
}
}
}
}
}
}
...
...
src/main/java/com/keymobile/indicators/akka/message/specific/DriveIndAverageAndRankMsg.java
View file @
1b3a72c7
...
@@ -16,9 +16,10 @@ public class DriveIndAverageAndRankMsg implements Serializable{
...
@@ -16,9 +16,10 @@ public class DriveIndAverageAndRankMsg implements Serializable{
private
String
driveIndValue
;
private
String
driveIndValue
;
private
String
unit
;
private
String
unit
;
private
String
indType
;
private
String
indType
;
private
String
markType
;
public
DriveIndAverageAndRankMsg
(
String
id
,
String
compareId
,
String
driveIndId
,
String
compareObj
,
public
DriveIndAverageAndRankMsg
(
String
id
,
String
compareId
,
String
driveIndId
,
String
compareObj
,
int
date
,
String
driveIndValue
,
String
unit
,
String
indType
)
{
int
date
,
String
driveIndValue
,
String
unit
,
String
indType
,
String
markType
)
{
this
.
id
=
id
;
this
.
id
=
id
;
this
.
compareId
=
compareId
;
this
.
compareId
=
compareId
;
this
.
driveIndId
=
driveIndId
;
this
.
driveIndId
=
driveIndId
;
...
@@ -26,7 +27,8 @@ public class DriveIndAverageAndRankMsg implements Serializable{
...
@@ -26,7 +27,8 @@ public class DriveIndAverageAndRankMsg implements Serializable{
this
.
date
=
date
;
this
.
date
=
date
;
this
.
driveIndValue
=
driveIndValue
;
this
.
driveIndValue
=
driveIndValue
;
this
.
unit
=
unit
;
this
.
unit
=
unit
;
this
.
setIndType
(
indType
);
this
.
indType
=
indType
;
this
.
markType
=
markType
;
}
}
public
String
getCompareId
()
{
public
String
getCompareId
()
{
...
@@ -92,4 +94,12 @@ public class DriveIndAverageAndRankMsg implements Serializable{
...
@@ -92,4 +94,12 @@ public class DriveIndAverageAndRankMsg implements Serializable{
public
void
setIndType
(
String
indType
)
{
public
void
setIndType
(
String
indType
)
{
this
.
indType
=
indType
;
this
.
indType
=
indType
;
}
}
public
String
getMarkType
()
{
return
markType
;
}
public
void
setMarkType
(
String
markType
)
{
this
.
markType
=
markType
;
}
}
}
src/main/java/com/keymobile/indicators/api/hytobacco/IndScorecardCtrl.java
0 → 100644
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
api
.
hytobacco
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.keymobile.indicators.model.entity.scorecard.IndScorecard
;
import
com.keymobile.indicators.service.hytobacco.IndScorecardService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
@Api
(
tags
={
"评分卡CRUD"
})
@RestController
@RequestMapping
(
value
=
"/indScorecard"
)
public
class
IndScorecardCtrl
{
@Autowired
private
IndScorecardService
indScorecardService
;
@ApiOperation
(
value
=
"新增/修改"
,
notes
=
"新增/修改"
)
@PostMapping
(
value
=
"/saveOrUpdate"
)
public
String
saveOrUpdate
(
@RequestBody
IndScorecard
indScorecard
)
{
return
indScorecardService
.
saveOrUpdate
(
indScorecard
);
}
@ApiOperation
(
value
=
"删除"
,
notes
=
"删除"
)
@PostMapping
(
value
=
"/delete"
)
public
void
delete
(
@RequestBody
List
<
String
>
ids
)
{
indScorecardService
.
delete
(
ids
);
}
@ApiOperation
(
value
=
"获取所有评分卡"
,
notes
=
"获取所有评分卡"
)
@PostMapping
(
value
=
"/getAll"
)
public
List
<
IndScorecard
>
getAll
(){
return
indScorecardService
.
getAll
();
}
@ApiOperation
(
value
=
"根据id获取评分卡"
,
notes
=
"根据id获取评分卡"
)
@PostMapping
(
value
=
"/findById"
)
public
IndScorecard
findById
(
@RequestParam
String
id
)
{
return
indScorecardService
.
findById
(
id
);
}
@ApiOperation
(
value
=
"根据评分卡计算指标分数"
,
notes
=
"根据评分卡计算指标分数"
)
@PostMapping
(
value
=
"/calculateIndiScore"
)
public
Map
<
String
,
String
>
calculateIndiScore
(
@RequestParam
String
indId
,
@RequestParam
int
date
,
@RequestParam
String
compareObj
,
@RequestParam
String
indScorecardId
,
@RequestParam
String
compareId
)
{
return
indScorecardService
.
calculateIndiScore
(
indId
,
date
,
compareObj
,
indScorecardId
,
compareId
);
}
}
src/main/java/com/keymobile/indicators/api/hytobacco/IndicatorsValueCtrl.java
View file @
1b3a72c7
...
@@ -33,6 +33,15 @@ public class IndicatorsValueCtrl {
...
@@ -33,6 +33,15 @@ public class IndicatorsValueCtrl {
}
}
}
}
@ApiOperation
(
value
=
"上传解析县2020第一季度基础指标数据"
,
notes
=
"上传解析县2020第一季度基础指标数据"
)
@PostMapping
(
value
=
"/importXianOneIndiValue"
)
public
void
importXianOneIndiValue
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
Exception
{
try
(
InputStream
is
=
file
.
getInputStream
()){
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
is
);
indicatorsValueService
.
importXianOneIndicatorsData
(
xssfWorkbook
);
}
}
@ApiOperation
(
value
=
"上传解析市基础指标数据"
,
notes
=
"上传解析市基础指标数据"
)
@ApiOperation
(
value
=
"上传解析市基础指标数据"
,
notes
=
"上传解析市基础指标数据"
)
@PostMapping
(
value
=
"/importShiIndiValue"
)
@PostMapping
(
value
=
"/importShiIndiValue"
)
public
void
importShiIndicatorsData
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
Exception
{
public
void
importShiIndicatorsData
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
Exception
{
...
@@ -48,4 +57,31 @@ public class IndicatorsValueCtrl {
...
@@ -48,4 +57,31 @@ public class IndicatorsValueCtrl {
@RequestParam
String
type
,
@RequestParam
(
required
=
false
)
String
compareId
)
throws
Exception
{
@RequestParam
String
type
,
@RequestParam
(
required
=
false
)
String
compareId
)
throws
Exception
{
indicatorsValueService
.
fillExcelFileOne
(
indIds
,
date
,
type
,
compareId
);
indicatorsValueService
.
fillExcelFileOne
(
indIds
,
date
,
type
,
compareId
);
}
}
@ApiOperation
(
value
=
"填充excel file2数据"
,
notes
=
"填充excel file2数据"
)
@PostMapping
(
value
=
"/fillExcelFileTwo"
)
public
void
fillExcelFileTwo
(
@RequestBody
List
<
String
>
indIds
)
throws
Exception
{
indicatorsValueService
.
fillExcelFileTwo
(
indIds
);
}
@ApiOperation
(
value
=
"填充excel file3数据"
,
notes
=
"填充excel file3数据"
)
@PostMapping
(
value
=
"/fillExcelFileThree"
)
public
void
fillExcelFileThree
(
@RequestBody
List
<
String
>
indIds
,
@RequestParam
String
type
)
throws
Exception
{
indicatorsValueService
.
fillExcelFileThree
(
indIds
,
type
);
}
@ApiOperation
(
value
=
"填充excel file4数据"
,
notes
=
"填充excel file4数据"
)
@PostMapping
(
value
=
"/fillExcelFileFour"
)
public
void
fillExcelFileFour
(
@RequestBody
List
<
String
>
indIds
,
@RequestParam
int
date
,
@RequestParam
String
type
)
throws
Exception
{
indicatorsValueService
.
fillExcelFileFour
(
indIds
,
date
,
type
);
}
@ApiOperation
(
value
=
"填充excel file5数据"
,
notes
=
"填充excel file5数据"
)
@PostMapping
(
value
=
"/fillExcelFileFive"
)
public
void
fillExcelFileFive
(
@RequestBody
List
<
String
>
indIds
,
@RequestParam
int
date
,
@RequestParam
String
type
,
@RequestParam
(
required
=
false
)
String
compareIds
)
throws
Exception
{
indicatorsValueService
.
fillExcelFileFive
(
indIds
,
date
,
type
,
compareIds
);
}
}
}
src/main/java/com/keymobile/indicators/model/entity/DriveIndCalResult.java
View file @
1b3a72c7
...
@@ -34,8 +34,11 @@ public class DriveIndCalResult implements Serializable{
...
@@ -34,8 +34,11 @@ public class DriveIndCalResult implements Serializable{
private
String
isRight
;
//表示考核指标的值是否计算正常得到的 0:计算有误 1:计算正常
private
String
isRight
;
//表示考核指标的值是否计算正常得到的 0:计算有误 1:计算正常
private
String
lastUpdateTime
=
DateUtils
.
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
private
String
lastUpdateTime
=
DateUtils
.
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
private
String
lastUpdater
;
private
String
lastUpdater
;
private
String
average
;
//平均数
private
String
average
;
//
组内
平均数
private
int
rank
;
//同组排名
private
int
rank
;
//同组排名
private
String
score
;
//指标评分分数
private
String
improveScore
;
//改善提升得分
private
String
actualAverage
;
//实际平均数:用于省对市的操作,如果有全省的基础项数据,直接拿全省的基础项数据算考核指标做为其实际平均值
public
DriveIndCalResult
(
String
compareId
,
String
indId
,
String
compareObj
,
int
date
,
String
value
,
public
DriveIndCalResult
(
String
compareId
,
String
indId
,
String
compareObj
,
int
date
,
String
value
,
String
unit
,
String
type
,
String
isRight
,
String
lastUpdater
)
{
String
unit
,
String
type
,
String
isRight
,
String
lastUpdater
)
{
...
...
src/main/java/com/keymobile/indicators/model/entity/scorecard/ImproveScoreDef.java
0 → 100644
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
model
.
entity
.
scorecard
;
import
java.io.Serializable
;
import
lombok.Data
;
@Data
public
class
ImproveScoreDef
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
String
gradeType
;
//改善提升类型 0:同期排位比 1:单位同期比
private
String
opType
;
//加减分类型 0:累计加减 1:一次加减 (通常同期排位比配合累计加减使用)
private
String
gradeOp
;
//加减分操作 0:加分 1:减分
private
double
score
;
//分值
}
src/main/java/com/keymobile/indicators/model/entity/scorecard/IndScorecard.java
0 → 100644
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
model
.
entity
.
scorecard
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
com.keymobile.indicators.utils.DateUtils
;
import
lombok.Data
;
/**
*author:zhangkb time:2020-5-6 desc:考核指标评分卡
*/
@Data
@Document
(
collection
=
"drive_ind_score_card"
)
public
class
IndScorecard
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Id
private
String
id
;
private
String
cardName
;
private
String
desc
;
private
String
scoreType
;
//综合评分类型 0:定义 1:公式
//定义综合评价
private
double
indBaseScore
;
//基础分
private
double
moreAverage
;
//大于组内平均分加分
private
double
lessAverage
;
//小于组内平均分减分
private
List
<
RankScoreDef
>
addScoreItem
=
new
ArrayList
<>();
//加分项
private
List
<
RankScoreDef
>
minusScoreItem
=
new
ArrayList
<>();
//减分项
//公式综合评价
private
double
bestIndScore
;
//最佳指标分
private
double
worstIndScore
;
//最差指标分
private
String
otherCalFormula
;
//其他计算公式
//改善提升
private
double
limitScore
;
//上限分数
private
List
<
ImproveScoreDef
>
improveScoreItem
=
new
ArrayList
<>();
//改善提升分数
private
String
lastUpdateTime
=
DateUtils
.
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
private
String
lastUpdater
;
public
void
setAddScoreItem
(
List
<
RankScoreDef
>
addScoreItem
)
{
this
.
addScoreItem
.
addAll
(
addScoreItem
);
}
public
void
setMinusScoreItem
(
List
<
RankScoreDef
>
minusScoreItem
)
{
this
.
minusScoreItem
.
addAll
(
minusScoreItem
);
}
public
void
setImproveScoreItem
(
List
<
ImproveScoreDef
>
improveScoreItem
)
{
this
.
improveScoreItem
.
addAll
(
improveScoreItem
);
}
}
src/main/java/com/keymobile/indicators/model/entity/scorecard/RankScoreDef.java
0 → 100644
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
model
.
entity
.
scorecard
;
import
java.io.Serializable
;
import
lombok.Data
;
@Data
public
class
RankScoreDef
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
int
rank
;
private
double
score
;
}
src/main/java/com/keymobile/indicators/persistence/hyindicators/DriveIndCalResultRepository.java
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
persistence
.
hyindicators
;
package
com
.
keymobile
.
indicators
.
persistence
.
hyindicators
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
public
interface
DriveIndCalResultRepository
extends
MongoRepository
<
DriveIndCalResult
,
String
>{
public
interface
DriveIndCalResultRepository
extends
MongoRepository
<
DriveIndCalResult
,
String
>{
public
List
<
DriveIndCalResult
>
findByIndId
(
String
indId
);
public
List
<
DriveIndCalResult
>
findByIndIdAndCompareObj
(
String
indId
,
String
compareObj
);
public
Optional
<
DriveIndCalResult
>
findByIndIdAndDateAndCompareObj
(
String
indId
,
int
date
,
String
compareObj
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDate
(
String
indId
,
int
date
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDate
(
String
indId
,
int
date
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDateAndActualAverageIsNotNull
(
String
indId
,
int
date
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDate
(
String
indId
,
int
date
,
Sort
sort
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDateAndActualAverageIsNotNull
(
String
indId
,
int
date
,
Sort
sort
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDateAndCompareId
(
String
indId
,
int
date
,
String
compareId
,
Sort
sort
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDateAndCompareId
(
String
indId
,
int
date
,
String
compareId
);
public
List
<
DriveIndCalResult
>
findByIndIdAndDateAndCompareId
(
String
indId
,
int
date
,
String
compareId
);
}
}
src/main/java/com/keymobile/indicators/persistence/hyindicators/IndScorecardRepository.java
0 → 100644
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
persistence
.
hyindicators
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
import
com.keymobile.indicators.model.entity.scorecard.IndScorecard
;
public
interface
IndScorecardRepository
extends
MongoRepository
<
IndScorecard
,
String
>{
}
src/main/java/com/keymobile/indicators/service/hytobacco/DriveIndCalResultService.java
View file @
1b3a72c7
...
@@ -36,6 +36,15 @@ public class DriveIndCalResultService {
...
@@ -36,6 +36,15 @@ public class DriveIndCalResultService {
return
null
;
return
null
;
}
}
public
DriveIndCalResult
findCompareObjInfo
(
String
driveIndId
,
int
date
,
String
compareObj
)
{
Optional
<
DriveIndCalResult
>
resultOp
=
driveIndCalResultRepo
.
findByIndIdAndDateAndCompareObj
(
driveIndId
,
date
,
compareObj
);
if
(
resultOp
.
isPresent
())
{
return
resultOp
.
get
();
}
return
null
;
}
public
void
calculateComp
(
String
compareId
,
String
compareObjsString
,
String
driveIndIdsString
,
public
void
calculateComp
(
String
compareId
,
String
compareObjsString
,
String
driveIndIdsString
,
int
date
)
{
int
date
)
{
String
[]
compareObjs
=
compareObjsString
.
split
(
";"
);
String
[]
compareObjs
=
compareObjsString
.
split
(
";"
);
...
...
src/main/java/com/keymobile/indicators/service/hytobacco/IndScorecardService.java
0 → 100644
View file @
1b3a72c7
package
com
.
keymobile
.
indicators
.
service
.
hytobacco
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.stereotype.Service
;
import
com.google.common.collect.Maps
;
import
com.googlecode.aviator.AviatorEvaluator
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
import
com.keymobile.indicators.model.entity.IndAcsDef
;
import
com.keymobile.indicators.model.entity.scorecard.ImproveScoreDef
;
import
com.keymobile.indicators.model.entity.scorecard.IndScorecard
;
import
com.keymobile.indicators.model.entity.scorecard.RankScoreDef
;
import
com.keymobile.indicators.persistence.hyindicators.DriveIndCalResultRepository
;
import
com.keymobile.indicators.persistence.hyindicators.IndScorecardRepository
;
import
com.keymobile.indicators.service.cmbkpi.IndAcsDefService
;
import
com.keymobile.indicators.utils.CalculateUtils
;
@Service
public
class
IndScorecardService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
IndScorecardService
.
class
);
@Autowired
private
IndScorecardRepository
indScorecardRepo
;
@Autowired
private
DriveIndCalResultRepository
driveIndResultRepo
;
@Autowired
private
IndAcsDefService
indAcsDefService
;
//id不为空为修改,为空为新增
public
String
saveOrUpdate
(
IndScorecard
indScorecard
)
{
indScorecard
=
indScorecardRepo
.
save
(
indScorecard
);
return
indScorecard
.
getId
();
}
public
void
delete
(
List
<
String
>
ids
)
{
for
(
String
id
:
ids
)
{
indScorecardRepo
.
deleteById
(
id
);
}
}
public
List
<
IndScorecard
>
getAll
(){
return
indScorecardRepo
.
findAll
();
}
public
IndScorecard
findById
(
String
id
)
{
Optional
<
IndScorecard
>
result
=
indScorecardRepo
.
findById
(
id
);
if
(
result
.
isPresent
())
{
return
result
.
get
();
}
return
null
;
}
public
Map
<
String
,
String
>
calculateIndiScore
(
String
indId
,
int
date
,
String
compareObj
,
String
indScorecardId
,
String
compareId
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<>();
String
indScoreValue
=
"0.0"
;
String
indImproveScoreValue
=
"0.0"
;
result
.
put
(
"score"
,
indScoreValue
);
result
.
put
(
"improveScore"
,
indImproveScoreValue
);
if
(
StringUtils
.
isNotBlank
(
indScorecardId
))
{
//根据评分卡id获取评分卡信息
IndScorecard
scoreCard
=
this
.
findById
(
indScorecardId
);
double
baseScoreValue
=
0
;
if
(
scoreCard
!=
null
)
{
IndAcsDef
acsDef
=
indAcsDefService
.
getById
(
indId
);
//获取指标是正向还是反向类型
String
acsType
=
acsDef
.
getIndType
();
String
unit
=
acsDef
.
getUnt
();
List
<
DriveIndCalResult
>
currentDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareId
(
indId
,
date
,
compareId
,
new
Sort
(
Sort
.
Direction
.
ASC
,
"rank"
));
if
(!
currentDriveResult
.
isEmpty
())
{
//过滤考核指标结果集无效值
Iterator
<
DriveIndCalResult
>
it
=
currentDriveResult
.
iterator
();
while
(
it
.
hasNext
()){
DriveIndCalResult
driveCalResult
=
it
.
next
();
if
(
"NaN"
.
equals
(
driveCalResult
.
getValue
())||
"0(Error)"
.
equals
(
driveCalResult
.
getValue
())
||
"0.0000"
.
equals
(
driveCalResult
.
getValue
())||
"0"
.
equals
(
driveCalResult
.
getValue
())){
it
.
remove
();
}
}
int
currentDriveResultSize
=
currentDriveResult
.
size
();
//根据indId,date,compareObj获取考核结果
Optional
<
DriveIndCalResult
>
currentCompareObjResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareObj
(
indId
,
date
,
compareObj
);
if
(
currentCompareObjResult
.
isPresent
())
{
String
average
=
currentCompareObjResult
.
get
().
getAverage
();
//如果实际平均值存在
if
(
currentCompareObjResult
.
get
().
getActualAverage
()!=
null
)
{
if
(!
"0.0"
.
equals
(
currentCompareObjResult
.
get
().
getActualAverage
()))
{
average
=
currentCompareObjResult
.
get
().
getActualAverage
();
}
}
String
value
=
currentCompareObjResult
.
get
().
getValue
();
if
(!
"NaN"
.
equals
(
value
)
&&
!
"0(Error)"
.
equals
(
value
)
&&
!
"0.0000"
.
equals
(
value
)
&&
!
"0"
.
equals
(
value
))
{
//综合评价
if
(
"0"
.
equals
(
scoreCard
.
getScoreType
()))
{
//定义
baseScoreValue
=
scoreCard
.
getIndBaseScore
();
//基础分
//如果是反向指标(越小越好)
if
(
"1"
.
equals
(
acsType
))
{
if
(
Double
.
valueOf
(
value
)<
Double
.
valueOf
(
average
))
{
//大于组内平均分
baseScoreValue
+=
scoreCard
.
getMoreAverage
();
}
else
{
baseScoreValue
-=
scoreCard
.
getLessAverage
();
}
}
else
{
//正向指标,越大越好
if
(
Double
.
valueOf
(
value
)>
Double
.
valueOf
(
average
))
{
//大于组内平均分
baseScoreValue
+=
scoreCard
.
getMoreAverage
();
}
else
{
baseScoreValue
-=
scoreCard
.
getLessAverage
();
}
}
int
rank
=
currentCompareObjResult
.
get
().
getRank
();
//获取排位
//加分项
if
(!
scoreCard
.
getAddScoreItem
().
isEmpty
())
{
List
<
RankScoreDef
>
addScoreItem
=
scoreCard
.
getAddScoreItem
();
for
(
RankScoreDef
scoreDef
:
addScoreItem
)
{
if
(
scoreDef
.
getRank
()==
rank
)
{
baseScoreValue
+=
scoreDef
.
getScore
();
break
;
}
}
}
//减分项
if
(!
scoreCard
.
getMinusScoreItem
().
isEmpty
())
{
List
<
RankScoreDef
>
minusScoreItem
=
scoreCard
.
getMinusScoreItem
();
rank
=
currentDriveResultSize
-
rank
+
1
;
for
(
RankScoreDef
scoreDef
:
minusScoreItem
)
{
if
(
scoreDef
.
getRank
()==
rank
)
{
baseScoreValue
-=
scoreDef
.
getScore
();
break
;
}
}
}
}
else
{
//公式
int
rank
=
currentCompareObjResult
.
get
().
getRank
();
//获取排位
if
(
rank
==
1
)
{
//最佳指标
baseScoreValue
=
scoreCard
.
getBestIndScore
();
}
else
if
(
rank
==
currentDriveResultSize
)
{
//最差指标
baseScoreValue
=
scoreCard
.
getWorstIndScore
();
}
else
{
//其他
if
(
StringUtils
.
isNotBlank
(
scoreCard
.
getOtherCalFormula
()))
{
baseScoreValue
=
this
.
getValueFromFormula
(
scoreCard
.
getOtherCalFormula
(),
currentCompareObjResult
.
get
(),
currentDriveResult
,
acsType
);
}
}
}
//改善提升
//同期
Optional
<
DriveIndCalResult
>
sameCompareObjResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareObj
(
indId
,
(
date
-
100
),
compareObj
);
if
(
sameCompareObjResult
.
isPresent
())
{
double
improveScore
=
this
.
calImproveValue
(
acsType
,
unit
,
scoreCard
.
getImproveScoreItem
(),
currentCompareObjResult
.
get
(),
sameCompareObjResult
.
get
());
if
(
scoreCard
.
getLimitScore
()!=
0
)
{
if
(
improveScore
>
scoreCard
.
getLimitScore
())
{
improveScore
=
scoreCard
.
getLimitScore
();
}
}
indImproveScoreValue
=
String
.
format
(
"%.4f"
,
new
BigDecimal
(
improveScore
));
result
.
put
(
"improveScore"
,
indImproveScoreValue
);
}
}
}
}
}
else
{
logger
.
error
(
"id:"
+
indScorecardId
+
" 的评分卡不存在"
);
}
indScoreValue
=
String
.
format
(
"%.4f"
,
new
BigDecimal
(
baseScoreValue
));
result
.
put
(
"score"
,
indScoreValue
);
}
else
{
logger
.
error
(
"考核指标没有关联评分卡"
);
}
return
result
;
}
private
double
calImproveValue
(
String
acsType
,
String
unit
,
List
<
ImproveScoreDef
>
importScoreDefList
,
DriveIndCalResult
current
,
DriveIndCalResult
same
)
{
double
sumValue
=
0
;
for
(
ImproveScoreDef
scoreDef
:
importScoreDefList
)
{
// 0:同期排位比 1:单位同期比
if
(
"0"
.
equals
(
scoreDef
.
getGradeType
()))
{
int
rankDiff
=
same
.
getRank
()-
current
.
getRank
();
//加减分操作 0:加分 1:减分
if
(
"0"
.
equals
(
scoreDef
.
getGradeOp
()))
{
if
(
rankDiff
>
0
)
{
//加减分类型 0:累计加减 1:一次加减
if
(
"0"
.
equals
(
scoreDef
.
getOpType
()))
{
sumValue
+=
rankDiff
*
scoreDef
.
getScore
();
}
else
{
sumValue
+=
scoreDef
.
getScore
();
}
}
}
else
{
if
(
rankDiff
<
0
)
{
//加减分类型 0:累计加减 1:一次加减
if
(
"0"
.
equals
(
scoreDef
.
getOpType
()))
{
sumValue
-=
rankDiff
*
scoreDef
.
getScore
();
}
else
{
sumValue
-=
scoreDef
.
getScore
();
}
}
}
}
else
{
//获取单位同期比率
String
rate
=
CalculateUtils
.
calGowth
(
unit
,
current
.
getValue
(),
same
.
getValue
(),
null
);
if
(
StringUtils
.
isNotBlank
(
rate
))
{
if
(
"0"
.
equals
(
acsType
))
{
if
(
Double
.
valueOf
(
rate
)>
0
)
{
//同比趋好
//加减分操作 0:加分 1:减分
if
(
"0"
.
equals
(
scoreDef
.
getGradeOp
()))
{
sumValue
+=
scoreDef
.
getScore
();
}
}
else
{
//同比趋差
if
(
"1"
.
equals
(
scoreDef
.
getGradeOp
()))
{
sumValue
-=
scoreDef
.
getScore
();
}
}
}
else
{
if
(
Double
.
valueOf
(
rate
)>
0
)
{
//同比趋差
if
(
"1"
.
equals
(
scoreDef
.
getGradeOp
()))
{
sumValue
-=
scoreDef
.
getScore
();
}
}
else
{
//同比趋好
if
(
"0"
.
equals
(
scoreDef
.
getGradeOp
()))
{
sumValue
+=
scoreDef
.
getScore
();
}
}
}
}
}
}
return
sumValue
;
}
private
double
getValueFromFormula
(
String
formula
,
DriveIndCalResult
resultObject
,
List
<
DriveIndCalResult
>
currentDriveResult
,
String
acsType
)
{
double
value
=
0
;
Map
<
String
,
Object
>
env
=
Maps
.
newHashMap
();
//解析X,MIN,MAX
if
(
formula
.
indexOf
(
"X"
)>=
0
)
{
//获取指标值
double
x
=
Double
.
valueOf
(
resultObject
.
getValue
());
env
.
put
(
"X"
,
x
);
}
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
(!
env
.
isEmpty
())
{
value
=
(
Double
)
AviatorEvaluator
.
execute
(
formula
,
env
);
}
return
value
;
}
}
src/main/java/com/keymobile/indicators/service/hytobacco/IndicatorsValueService.java
View file @
1b3a72c7
...
@@ -5,13 +5,17 @@ import java.io.FileOutputStream;
...
@@ -5,13 +5,17 @@ import java.io.FileOutputStream;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellStyle
;
import
org.apache.poi.ss.usermodel.Font
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddress
;
...
@@ -22,12 +26,16 @@ import org.slf4j.Logger;
...
@@ -22,12 +26,16 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.keymobile.indicators.conf.MongoDBConfig
;
import
com.keymobile.indicators.conf.MongoDBConfig
;
import
com.keymobile.indicators.model.entity.DimValue
;
import
com.keymobile.indicators.model.entity.DimValue
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
import
com.keymobile.indicators.model.entity.DriveIndCalResult
;
import
com.keymobile.indicators.model.entity.IndAcsDef
;
import
com.keymobile.indicators.persistence.hyindicators.DriveIndCalResultRepository
;
import
com.keymobile.indicators.persistence.hyindicators.DriveIndCalResultRepository
;
import
com.keymobile.indicators.service.cmbkpi.IndAcsDefService
;
import
com.keymobile.indicators.utils.CalculateUtils
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.DB
;
import
com.mongodb.DB
;
import
com.mongodb.DBCollection
;
import
com.mongodb.DBCollection
;
...
@@ -42,10 +50,279 @@ public class IndicatorsValueService {
...
@@ -42,10 +50,279 @@ public class IndicatorsValueService {
private
MongoDBConfig
mongoDbConfig
;
private
MongoDBConfig
mongoDbConfig
;
@Autowired
@Autowired
private
DriveIndCalResultRepository
driveIndResultRepo
;
private
DriveIndCalResultRepository
driveIndResultRepo
;
@Autowired
private
IndAcsDefService
indAcsDefService
;
@Value
(
"${mongodb.database}"
)
@Value
(
"${mongodb.database}"
)
private
String
database
;
private
String
database
;
//填充市对标通报一览表
public
void
fillExcelFileFive
(
List
<
String
>
indIds
,
int
date
,
String
type
,
String
compareIdString
)
throws
Exception
{
FileInputStream
fs
=
new
FileInputStream
(
"D://indicatorsFile/file5.xlsx"
);
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
fs
);
XSSFSheet
excelSheet
=
xssfWorkbook
.
getSheet
(
"Sheet1"
);
Map
<
String
,
Integer
>
rowMap
=
new
HashMap
<>();
rowMap
.
put
(
"SC001"
,
3
);
rowMap
.
put
(
"SC002"
,
4
);
rowMap
.
put
(
"SC003"
,
5
);
rowMap
.
put
(
"SC004"
,
6
);
rowMap
.
put
(
"SC006"
,
7
);
rowMap
.
put
(
"SC007"
,
8
);
rowMap
.
put
(
"SC005"
,
9
);
rowMap
.
put
(
"SC008"
,
10
);
rowMap
.
put
(
"SC009"
,
11
);
rowMap
.
put
(
"SC0010"
,
12
);
rowMap
.
put
(
"SC0011"
,
13
);
rowMap
.
put
(
"SC0012"
,
14
);
rowMap
.
put
(
"SC0013"
,
15
);
rowMap
.
put
(
"SC0014"
,
16
);
rowMap
.
put
(
"SC0015"
,
17
);
rowMap
.
put
(
"SC0016"
,
18
);
rowMap
.
put
(
"SC0017"
,
19
);
rowMap
.
put
(
"SC0018"
,
20
);
rowMap
.
put
(
"SC0019"
,
21
);
rowMap
.
put
(
"SC0020"
,
22
);
rowMap
.
put
(
"SC0021"
,
23
);
rowMap
.
put
(
"SC0022"
,
24
);
rowMap
.
put
(
"SC0023"
,
25
);
rowMap
.
put
(
"SC0024"
,
26
);
rowMap
.
put
(
"SC0025"
,
27
);
rowMap
.
put
(
"SC0026"
,
28
);
rowMap
.
put
(
"SC0027"
,
29
);
rowMap
.
put
(
"SC0028"
,
30
);
rowMap
.
put
(
"SC0029"
,
31
);
rowMap
.
put
(
"SC0030"
,
32
);
rowMap
.
put
(
"SC0031"
,
33
);
rowMap
.
put
(
"SC0032"
,
34
);
rowMap
.
put
(
"SC0033"
,
35
);
rowMap
.
put
(
"SC0034"
,
36
);
rowMap
.
put
(
"SC0035"
,
37
);
rowMap
.
put
(
"SC0036"
,
38
);
rowMap
.
put
(
"SC0037"
,
39
);
rowMap
.
put
(
"SC0038"
,
40
);
rowMap
.
put
(
"SC0039"
,
41
);
rowMap
.
put
(
"SC0040"
,
42
);
rowMap
.
put
(
"SC0041"
,
43
);
rowMap
.
put
(
"SC0042"
,
44
);
rowMap
.
put
(
"SC0043"
,
45
);
if
(
"0"
.
equals
(
type
))
{
for
(
String
indId
:
indIds
)
{
Map
<
String
,
Object
>
map
=
this
.
getIndicatorInfo
(
indId
,
date
,
3
,
type
,
null
);
XSSFRow
row
=
excelSheet
.
getRow
(
rowMap
.
get
(
indId
));
row
.
getCell
(
3
).
setCellValue
(
map
.
get
(
"average"
).
toString
());
row
.
getCell
(
5
).
setCellValue
(
map
.
get
(
"bestUnits"
).
toString
());
row
.
getCell
(
7
).
setCellValue
(
map
.
get
(
"bestUnitsValue"
).
toString
());
row
.
getCell
(
9
).
setCellValue
(
map
.
get
(
"moreAverageUnits"
).
toString
());
row
.
getCell
(
10
).
setCellValue
(
map
.
get
(
"compareSameUnits"
).
toString
());
row
.
getCell
(
11
).
setCellValue
(
map
.
get
(
"topUnits"
).
toString
());
row
.
getCell
(
12
).
setCellValue
(
map
.
get
(
"bottomUnits"
).
toString
());
}
}
else
{
String
[]
compareIds
=
compareIdString
.
split
(
";"
);
for
(
String
indId
:
indIds
)
{
Map
<
String
,
Object
>
map
=
this
.
getIndicatorInfo
(
indId
,
date
,
3
,
type
,
compareIds
[
0
]);
Map
<
String
,
Object
>
map1
=
this
.
getIndicatorInfo
(
indId
,
date
,
3
,
type
,
compareIds
[
1
]);
XSSFRow
row
=
excelSheet
.
getRow
(
rowMap
.
get
(
indId
));
row
.
getCell
(
3
).
setCellValue
(
map
.
get
(
"average"
).
toString
());
row
.
getCell
(
4
).
setCellValue
(
map1
.
get
(
"average"
).
toString
());
row
.
getCell
(
5
).
setCellValue
(
map
.
get
(
"bestUnits"
).
toString
());
row
.
getCell
(
6
).
setCellValue
(
map1
.
get
(
"bestUnits"
).
toString
());
row
.
getCell
(
7
).
setCellValue
(
map
.
get
(
"bestUnitsValue"
).
toString
());
row
.
getCell
(
8
).
setCellValue
(
map1
.
get
(
"bestUnitsValue"
).
toString
());
row
.
getCell
(
9
).
setCellValue
(
Integer
.
valueOf
(
map
.
get
(
"moreAverageUnits"
).
toString
())+
Integer
.
valueOf
(
map1
.
get
(
"moreAverageUnits"
).
toString
()));
row
.
getCell
(
10
).
setCellValue
(
Integer
.
valueOf
(
map
.
get
(
"compareSameUnits"
).
toString
())+
Integer
.
valueOf
(
map1
.
get
(
"compareSameUnits"
).
toString
()));
row
.
getCell
(
11
).
setCellValue
(
"["
+
map
.
get
(
"topUnits"
).
toString
()+
"]"
+
"["
+
map1
.
get
(
"topUnits"
).
toString
()+
"]"
);
row
.
getCell
(
12
).
setCellValue
(
"["
+
map
.
get
(
"bottomUnits"
).
toString
()+
"]"
+
"["
+
map1
.
get
(
"bottomUnits"
).
toString
()+
"]"
);
}
}
FileOutputStream
out
=
new
FileOutputStream
(
"D://indicatorsFile/file5.xlsx"
);
out
.
flush
();
xssfWorkbook
.
write
(
out
);
out
.
close
();
fs
.
close
();
logger
.
info
(
"填充完成"
);
}
//填充市排名
public
void
fillExcelFileFour
(
List
<
String
>
indIds
,
int
date
,
String
type
)
throws
Exception
{
FileInputStream
fs
=
new
FileInputStream
(
"D://indicatorsFile/file4.xlsx"
);
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
fs
);
XSSFSheet
excelSheet
=
xssfWorkbook
.
getSheet
(
"Sheet1"
);
Map
<
String
,
String
>
rowMap
=
new
HashMap
<>();
rowMap
.
put
(
"SC001"
,
"1:1"
);
rowMap
.
put
(
"SC002"
,
"1:3"
);
rowMap
.
put
(
"SC003"
,
"1:5"
);
rowMap
.
put
(
"SC004"
,
"1:7"
);
rowMap
.
put
(
"SC006"
,
"1:9"
);
rowMap
.
put
(
"SC007"
,
"1:11"
);
rowMap
.
put
(
"SC005"
,
"1:13"
);
rowMap
.
put
(
"SC008"
,
"1:15"
);
rowMap
.
put
(
"SC009"
,
"1:17"
);
rowMap
.
put
(
"SC0010"
,
"1:19"
);
rowMap
.
put
(
"SC0011"
,
"1:21"
);
rowMap
.
put
(
"SC0012"
,
"1:23"
);
rowMap
.
put
(
"SC0013"
,
"1:25"
);
rowMap
.
put
(
"SC0014"
,
"1:27"
);
rowMap
.
put
(
"SC0015"
,
"1:29"
);
rowMap
.
put
(
"SC0016"
,
"16:1"
);
rowMap
.
put
(
"SC0017"
,
"16:3"
);
rowMap
.
put
(
"SC0018"
,
"16:5"
);
rowMap
.
put
(
"SC0019"
,
"16:7"
);
rowMap
.
put
(
"SC0020"
,
"16:9"
);
rowMap
.
put
(
"SC0021"
,
"16:11"
);
rowMap
.
put
(
"SC0022"
,
"16:13"
);
rowMap
.
put
(
"SC0023"
,
"16:15"
);
rowMap
.
put
(
"SC0024"
,
"16:17"
);
rowMap
.
put
(
"SC0025"
,
"16:19"
);
rowMap
.
put
(
"SC0026"
,
"16:21"
);
rowMap
.
put
(
"SC0027"
,
"16:23"
);
rowMap
.
put
(
"SC0028"
,
"16:25"
);
rowMap
.
put
(
"SC0029"
,
"16:27"
);
rowMap
.
put
(
"SC0030"
,
"31:1"
);
rowMap
.
put
(
"SC0031"
,
"31:3"
);
rowMap
.
put
(
"SC0032"
,
"31:5"
);
rowMap
.
put
(
"SC0033"
,
"31:7"
);
rowMap
.
put
(
"SC0034"
,
"31:9"
);
rowMap
.
put
(
"SC0035"
,
"31:11"
);
rowMap
.
put
(
"SC0036"
,
"31:13"
);
rowMap
.
put
(
"SC0037"
,
"31:15"
);
rowMap
.
put
(
"SC0038"
,
"31:17"
);
rowMap
.
put
(
"SC0039"
,
"31:19"
);
rowMap
.
put
(
"SC0040"
,
"31:21"
);
rowMap
.
put
(
"SC0041"
,
"31:23"
);
rowMap
.
put
(
"SC0042"
,
"31:25"
);
rowMap
.
put
(
"SC0043"
,
"31:27"
);
for
(
String
indId
:
indIds
)
{
List
<
DriveIndCalResult
>
currentDriveResult
=
driveIndResultRepo
.
findByIndIdAndDate
(
indId
,
date
,
new
Sort
(
Sort
.
Direction
.
ASC
,
"rank"
));
String
rowAndCellInfo
=
rowMap
.
get
(
indId
);
String
[]
rowAndCell
=
rowAndCellInfo
.
split
(
":"
);
int
rowNum
=
Integer
.
valueOf
(
rowAndCell
[
0
])+
1
;
int
cellNum
=
Integer
.
valueOf
(
rowAndCell
[
1
]);
for
(
DriveIndCalResult
result
:
currentDriveResult
)
{
XSSFRow
row
=
excelSheet
.
getRow
(
rowNum
);
row
.
getCell
(
cellNum
).
setCellValue
(
result
.
getCompareObj
());
row
.
getCell
(
cellNum
+
1
).
setCellValue
(
result
.
getValue
()+
"("
+
result
.
getRank
()+
")"
);
rowNum
++;
}
}
FileOutputStream
out
=
new
FileOutputStream
(
"D://indicatorsFile/file4.xlsx"
);
out
.
flush
();
xssfWorkbook
.
write
(
out
);
out
.
close
();
fs
.
close
();
logger
.
info
(
"填充完成"
);
}
//填充市考核指标平均值
public
void
fillExcelFileThree
(
List
<
String
>
indIds
,
String
type
)
throws
Exception
{
FileInputStream
fs
=
new
FileInputStream
(
"D://indicatorsFile/file3.xlsx"
);
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
fs
);
XSSFSheet
excelSheet
=
xssfWorkbook
.
getSheet
(
"Sheet1"
);
Font
font
=
xssfWorkbook
.
createFont
();
font
.
setColor
(
Font
.
COLOR_RED
);
CellStyle
cellStyle
=
xssfWorkbook
.
createCellStyle
();
cellStyle
.
setFont
(
font
);
Map
<
String
,
Integer
>
rowMap
=
new
HashMap
<>();
rowMap
.
put
(
"SC001"
,
3
);
rowMap
.
put
(
"SC002"
,
4
);
rowMap
.
put
(
"SC003"
,
5
);
rowMap
.
put
(
"SC004"
,
6
);
rowMap
.
put
(
"SC006"
,
7
);
rowMap
.
put
(
"SC007"
,
8
);
rowMap
.
put
(
"SC005"
,
9
);
rowMap
.
put
(
"SC008"
,
10
);
rowMap
.
put
(
"SC009"
,
11
);
rowMap
.
put
(
"SC0010"
,
12
);
rowMap
.
put
(
"SC0011"
,
13
);
rowMap
.
put
(
"SC0012"
,
14
);
rowMap
.
put
(
"SC0013"
,
15
);
rowMap
.
put
(
"SC0014"
,
16
);
rowMap
.
put
(
"SC0015"
,
17
);
rowMap
.
put
(
"SC0016"
,
18
);
rowMap
.
put
(
"SC0017"
,
19
);
rowMap
.
put
(
"SC0018"
,
20
);
rowMap
.
put
(
"SC0019"
,
21
);
rowMap
.
put
(
"SC0020"
,
22
);
rowMap
.
put
(
"SC0021"
,
23
);
rowMap
.
put
(
"SC0022"
,
24
);
rowMap
.
put
(
"SC0023"
,
25
);
rowMap
.
put
(
"SC0024"
,
26
);
rowMap
.
put
(
"SC0025"
,
27
);
rowMap
.
put
(
"SC0026"
,
28
);
rowMap
.
put
(
"SC0027"
,
29
);
rowMap
.
put
(
"SC0028"
,
30
);
rowMap
.
put
(
"SC0029"
,
31
);
rowMap
.
put
(
"SC0030"
,
32
);
rowMap
.
put
(
"SC0031"
,
33
);
rowMap
.
put
(
"SC0032"
,
34
);
rowMap
.
put
(
"SC0033"
,
35
);
rowMap
.
put
(
"SC0034"
,
36
);
rowMap
.
put
(
"SC0035"
,
37
);
rowMap
.
put
(
"SC0036"
,
38
);
rowMap
.
put
(
"SC0037"
,
39
);
rowMap
.
put
(
"SC0038"
,
40
);
rowMap
.
put
(
"SC0039"
,
41
);
rowMap
.
put
(
"SC0040"
,
42
);
rowMap
.
put
(
"SC0041"
,
43
);
rowMap
.
put
(
"SC0042"
,
44
);
rowMap
.
put
(
"SC0043"
,
45
);
for
(
String
indId
:
indIds
)
{
//如果是非两烟区,直接取平均值
String
currentValue
=
""
;
String
sameValue
=
""
;
String
rate
=
""
;
//本期
List
<
DriveIndCalResult
>
currentDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndActualAverageIsNotNull
(
indId
,
201912
);
if
(!
currentDriveResult
.
isEmpty
())
{
if
(
"1"
.
equals
(
type
))
{
List
<
String
>
values
=
new
ArrayList
<>();
for
(
DriveIndCalResult
result
:
currentDriveResult
)
{
values
.
add
(
result
.
getValue
());
}
currentValue
=
CalculateUtils
.
averageValue
(
values
);
}
else
{
currentValue
=
currentDriveResult
.
get
(
0
).
getAverage
();
if
(!
"0.0"
.
equals
(
currentDriveResult
.
get
(
0
).
getActualAverage
()))
{
currentValue
=
currentDriveResult
.
get
(
0
).
getActualAverage
();
}
}
}
//同期
List
<
DriveIndCalResult
>
sameDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndActualAverageIsNotNull
(
indId
,
201812
);
if
(!
sameDriveResult
.
isEmpty
())
{
if
(
"1"
.
equals
(
type
))
{
List
<
String
>
values
=
new
ArrayList
<>();
for
(
DriveIndCalResult
result
:
sameDriveResult
)
{
values
.
add
(
result
.
getValue
());
}
sameValue
=
CalculateUtils
.
averageValue
(
values
);
}
else
{
sameValue
=
sameDriveResult
.
get
(
0
).
getAverage
();
if
(!
"0.0"
.
equals
(
sameDriveResult
.
get
(
0
).
getActualAverage
()))
{
sameValue
=
sameDriveResult
.
get
(
0
).
getActualAverage
();
}
}
}
//根据指标id获取指标信息
IndAcsDef
acs
=
indAcsDefService
.
getById
(
indId
);
rate
=
CalculateUtils
.
calGowth
(
acs
.
getUnt
(),
currentValue
,
sameValue
,
"0"
);
XSSFRow
row
=
excelSheet
.
getRow
(
rowMap
.
get
(
indId
));
row
.
getCell
(
3
).
setCellValue
(
currentValue
);
row
.
getCell
(
4
).
setCellValue
(
sameValue
);
row
.
getCell
(
5
).
setCellValue
(
rate
);
String
acsType
=
acs
.
getIndType
();
if
(
"0"
.
equals
(
acsType
))
{
if
(
Double
.
valueOf
(
rate
)>
0
)
{
row
.
getCell
(
6
).
setCellValue
(
"同比趋好"
);
}
else
{
row
.
getCell
(
6
).
setCellStyle
(
cellStyle
);
row
.
getCell
(
6
).
setCellValue
(
"同比趋差"
);
}
}
else
{
if
(
Double
.
valueOf
(
rate
)>
0
)
{
row
.
getCell
(
6
).
setCellStyle
(
cellStyle
);
row
.
getCell
(
6
).
setCellValue
(
"同比趋差"
);
}
else
{
row
.
getCell
(
6
).
setCellValue
(
"同比趋好"
);
}
}
}
FileOutputStream
out
=
new
FileOutputStream
(
"D://indicatorsFile/file3.xlsx"
);
out
.
flush
();
xssfWorkbook
.
write
(
out
);
out
.
close
();
fs
.
close
();
logger
.
info
(
"填充完成"
);
}
//填充县考核指标值
public
void
fillExcelFileTwo
(
List
<
String
>
indIds
)
throws
Exception
{
FileInputStream
fs
=
new
FileInputStream
(
"D://indicatorsFile/file2.xlsx"
);
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
fs
);
XSSFSheet
excelSheet
=
xssfWorkbook
.
getSheet
(
"Sheet1"
);
Map
<
String
,
Integer
>
cellMap
=
new
HashMap
<>();
cellMap
.
put
(
"FC001"
,
2
);
cellMap
.
put
(
"FC002"
,
5
);
cellMap
.
put
(
"FC003"
,
8
);
cellMap
.
put
(
"FC004"
,
11
);
cellMap
.
put
(
"FC005"
,
14
);
cellMap
.
put
(
"FC006"
,
17
);
cellMap
.
put
(
"FC007"
,
20
);
cellMap
.
put
(
"FC008"
,
23
);
cellMap
.
put
(
"FC009"
,
26
);
cellMap
.
put
(
"FC0010"
,
29
);
cellMap
.
put
(
"FC0011"
,
32
);
cellMap
.
put
(
"FC0012"
,
35
);
cellMap
.
put
(
"FC0013"
,
38
);
cellMap
.
put
(
"FC0014"
,
41
);
cellMap
.
put
(
"FC0015"
,
44
);
cellMap
.
put
(
"FC0016"
,
47
);
cellMap
.
put
(
"FC0017"
,
50
);
Map
<
String
,
Integer
>
rowMap
=
new
HashMap
<>();
//获取行值
for
(
int
i
=
3
;
i
<
93
;
i
++)
{
XSSFRow
row
=
excelSheet
.
getRow
(
i
);
String
value
=
row
.
getCell
(
1
)==
null
?
""
:
row
.
getCell
(
1
).
getStringCellValue
();
if
(
StringUtils
.
isNotBlank
(
value
))
{
rowMap
.
put
(
value
,
i
);
}
}
//根据考核指标id获取本期和同期的指标值
for
(
String
indId
:
indIds
)
{
List
<
DriveIndCalResult
>
driveResult
=
driveIndResultRepo
.
findByIndId
(
indId
);
for
(
DriveIndCalResult
result
:
driveResult
)
{
String
region
=
result
.
getCompareObj
();
if
(
rowMap
.
get
(
region
)!=
null
)
{
XSSFRow
row
=
excelSheet
.
getRow
(
rowMap
.
get
(
region
));
if
(
result
.
getDate
()==
201912
)
{
row
.
getCell
(
cellMap
.
get
(
indId
)).
setCellValue
(
result
.
getValue
());
}
else
{
row
.
getCell
((
cellMap
.
get
(
indId
)+
1
)).
setCellValue
(
result
.
getValue
());
}
}
else
{
logger
.
info
(
"找不到 "
+
region
+
" 对应的列"
);
}
//算一次
if
(
result
.
getDate
()==
201912
)
{
String
currentValue
=
""
;
String
sameValue
=
""
;
//算增幅
List
<
DriveIndCalResult
>
gowthValues
=
driveIndResultRepo
.
findByIndIdAndCompareObj
(
indId
,
region
);
for
(
DriveIndCalResult
gowth
:
gowthValues
)
{
if
(
gowth
.
getDate
()==
201912
)
{
currentValue
=
gowth
.
getValue
();
}
else
{
sameValue
=
gowth
.
getValue
();
}
}
XSSFRow
row
=
excelSheet
.
getRow
(
rowMap
.
get
(
region
));
row
.
getCell
((
cellMap
.
get
(
indId
)+
2
)).
setCellValue
(
CalculateUtils
.
calGowth
(
gowthValues
.
get
(
0
).
getUnit
(),
currentValue
,
sameValue
,
null
));
}
}
}
FileOutputStream
out
=
new
FileOutputStream
(
"D://indicatorsFile/file2.xlsx"
);
out
.
flush
();
xssfWorkbook
.
write
(
out
);
out
.
close
();
fs
.
close
();
logger
.
info
(
"填充完成"
);
}
//填充市考核指标值
public
void
fillExcelFileOne
(
List
<
String
>
indIds
,
int
date
,
String
type
,
String
compareId
)
throws
Exception
{
public
void
fillExcelFileOne
(
List
<
String
>
indIds
,
int
date
,
String
type
,
String
compareId
)
throws
Exception
{
Map
<
String
,
Integer
>
cellMap
=
new
HashMap
<>();
Map
<
String
,
Integer
>
cellMap
=
new
HashMap
<>();
cellMap
.
put
(
"aver"
,
3
);
cellMap
.
put
(
"liang"
,
5
);
cellMap
.
put
(
"cun"
,
7
);
cellMap
.
put
(
"aver"
,
3
);
cellMap
.
put
(
"liang"
,
5
);
cellMap
.
put
(
"cun"
,
7
);
...
@@ -93,19 +370,31 @@ public class IndicatorsValueService {
...
@@ -93,19 +370,31 @@ public class IndicatorsValueService {
}
else
{
}
else
{
averCellNum
=
cellMap
.
get
(
"cun"
);
averCellNum
=
cellMap
.
get
(
"cun"
);
}
}
String
average
=
result
.
getAverage
();
String
average
=
null
;
if
(
"0"
.
equals
(
type
))
{
average
=
result
.
getActualAverage
();
//不分组取实际平均值
if
(
average
!=
null
)
{
if
(
"0.0"
.
equals
(
result
.
getActualAverage
()))
{
average
=
result
.
getAverage
();
}
}
}
else
{
average
=
result
.
getAverage
();
}
if
(
date
==
201812
)
{
if
(
date
==
201812
)
{
averCellNum
+=
1
;
averCellNum
+=
1
;
}
}
xssfRow
.
getCell
(
averCellNum
).
setCellValue
(
average
);
xssfRow
.
getCell
(
averCellNum
).
setCellValue
(
average
);
}
}
//填内容
//填内容
int
cellNum
=
cellMap
.
get
(
result
.
getCompareObj
());
if
(
cellMap
.
get
(
result
.
getCompareObj
())!=
null
)
{
if
(
date
==
201812
)
{
int
cellNum
=
cellMap
.
get
(
result
.
getCompareObj
());
cellNum
+=
1
;
if
(
date
==
201812
)
{
cellNum
+=
1
;
}
xssfRow
.
getCell
(
cellNum
).
setCellValue
(
result
.
getValue
());
i
++;
}
}
xssfRow
.
getCell
(
cellNum
).
setCellValue
(
result
.
getValue
());
i
++;
}
}
}
}
FileOutputStream
out
=
new
FileOutputStream
(
"D://indicatorsFile/file1.xlsx"
);
FileOutputStream
out
=
new
FileOutputStream
(
"D://indicatorsFile/file1.xlsx"
);
...
@@ -211,6 +500,82 @@ public class IndicatorsValueService {
...
@@ -211,6 +500,82 @@ public class IndicatorsValueService {
this
.
addIndicatorData
(
datas
);
this
.
addIndicatorData
(
datas
);
}
}
public
void
importXianOneIndicatorsData
(
XSSFWorkbook
xssfWorkbook
)
throws
Exception
{
Map
<
String
,
String
>
indMappingIndId
=
new
HashMap
<>();
indMappingIndId
.
put
(
"卷烟总销量(箱)"
,
"F002"
);
indMappingIndId
.
put
(
"二类烟销量(箱)"
,
"F004"
);
indMappingIndId
.
put
(
"零售客户进货规格数之和(个)"
,
"F006"
);
indMappingIndId
.
put
(
"零售客户总数(个)"
,
"F008"
);
indMappingIndId
.
put
(
"卷烟销售单箱均价(万元)"
,
"F0010"
);
indMappingIndId
.
put
(
"卷烟营销费用(万元)"
,
"F0016"
);
indMappingIndId
.
put
(
"卷烟管理费用(万元)"
,
"F0018"
);
indMappingIndId
.
put
(
"查获烟叶量(千克)"
,
"F0032"
);
indMappingIndId
.
put
(
"查获烟丝量(千克)"
,
"F0034"
);
indMappingIndId
.
put
(
"查获真烟量(万支)"
,
"F0040"
);
indMappingIndId
.
put
(
"查获未当案件卷烟量(万支)"
,
"F0058"
);
indMappingIndId
.
put
(
"专卖线在岗人员数(人)"
,
"F0038"
);
indMappingIndId
.
put
(
"营销线在岗人员数(人)"
,
"F0014"
);
String
regex
=
"\\((.*?))"
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
List
<
DBObject
>
datas
=
new
ArrayList
<>();
XSSFSheet
excelSheet
=
xssfWorkbook
.
getSheet
(
"县级局对标"
);
int
startDataRow
=
2
;
//开始读excel数据的行号
for
(
int
i
=
2
;
i
<=
28
;
i
=
i
+
2
)
{
String
cellValue
=
this
.
getMergedRegionValue
(
excelSheet
,
startDataRow
,
i
);
if
(
StringUtils
.
isNotBlank
(
cellValue
))
{
List
<
String
>
unitList
=
new
ArrayList
<>();
String
unit
=
""
;
//获取单位
Matcher
matcher
=
pattern
.
matcher
(
cellValue
);
while
(
matcher
.
find
())
{
unitList
.
add
(
matcher
.
group
(
1
));
}
if
(!
unitList
.
isEmpty
())
{
unit
=
unitList
.
get
(
0
);
}
XSSFRow
xssfRow
=
excelSheet
.
getRow
(
3
);
String
dim2Value1
=
xssfRow
.
getCell
(
i
)==
null
?
""
:
xssfRow
.
getCell
(
i
).
getStringCellValue
();
String
dim2Value2
=
xssfRow
.
getCell
(
i
+
1
)==
null
?
""
:
xssfRow
.
getCell
(
i
+
1
).
getStringCellValue
();
if
(
"本期"
.
equals
(
dim2Value1
)
&&
"同期"
.
equals
(
dim2Value2
)){
for
(
int
k
=
4
;
k
<
94
;
k
++)
{
DBObject
doc
=
new
BasicDBObject
();
DBObject
doc1
=
new
BasicDBObject
();
doc
.
put
(
"indId"
,
indMappingIndId
.
get
(
cellValue
));
doc1
.
put
(
"indId"
,
indMappingIndId
.
get
(
cellValue
));
doc
.
put
(
"indDesc"
,
cellValue
);
doc1
.
put
(
"indDesc"
,
cellValue
);
doc
.
put
(
"type"
,
"0"
);
doc1
.
put
(
"type"
,
"0"
);
doc
.
put
(
"batchNo"
,
"B002"
);
doc1
.
put
(
"batchNo"
,
"B002"
);
doc
.
put
(
"dataType"
,
"double"
);
doc1
.
put
(
"dataType"
,
"double"
);
doc
.
put
(
"unit"
,
unit
);
doc1
.
put
(
"unit"
,
unit
);
if
(
"本期"
.
equals
(
dim2Value1
))
{
doc
.
put
(
"dim2"
,
202003
);
}
if
(
"同期"
.
equals
(
dim2Value2
))
{
doc1
.
put
(
"dim2"
,
201903
);
}
XSSFRow
xssfRowRigon
=
excelSheet
.
getRow
(
k
);
String
dim1Value
=
xssfRowRigon
.
getCell
(
1
)==
null
?
""
:
xssfRowRigon
.
getCell
(
1
).
getStringCellValue
();
doc
.
put
(
"dim1"
,
dim1Value
);
doc1
.
put
(
"dim1"
,
dim1Value
);
String
indValue1
=
this
.
getCellValue
(
xssfRowRigon
,
i
);
String
indValue2
=
this
.
getCellValue
(
xssfRowRigon
,
i
+
1
);
doc
.
put
(
"value"
,
indValue1
);
doc1
.
put
(
"value"
,
indValue2
);
datas
.
add
(
doc
);
datas
.
add
(
doc1
);
}
}
}
}
}
public
void
importIndicatorsData
(
XSSFWorkbook
xssfWorkbook
)
throws
Exception
{
public
void
importIndicatorsData
(
XSSFWorkbook
xssfWorkbook
)
throws
Exception
{
String
regex
=
"\\((.*?))"
;
String
regex
=
"\\((.*?))"
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Pattern
pattern
=
Pattern
.
compile
(
regex
);
...
@@ -343,4 +708,123 @@ public class IndicatorsValueService {
...
@@ -343,4 +708,123 @@ public class IndicatorsValueService {
client
.
close
();
client
.
close
();
}
}
//计算同期考核指标排名变化
private
Map
<
String
,
Integer
>
getSameIndicatorRankChange
(
String
indId
,
int
date
,
String
compareObj
){
Map
<
String
,
Integer
>
result
=
new
HashMap
<>();
result
.
put
(
compareObj
,
0
);
//获取本期考核指标值结果
Optional
<
DriveIndCalResult
>
currentResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareObj
(
indId
,
date
,
compareObj
);
Optional
<
DriveIndCalResult
>
sameResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareObj
(
indId
,
(
date
-
100
),
compareObj
);
//获取同期考核指标值结果
if
(
currentResult
.
isPresent
()
&&
sameResult
.
isPresent
())
{
result
.
put
(
compareObj
,
(
sameResult
.
get
().
getRank
()-
currentResult
.
get
().
getRank
()));
}
return
result
;
}
private
Map
<
String
,
Object
>
getIndicatorInfo
(
String
indId
,
int
date
,
int
orderNum
,
String
type
,
String
compareId
){
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
//本期考核结果
List
<
DriveIndCalResult
>
currentDriveResult
=
new
ArrayList
<>();
if
(
StringUtils
.
isNotBlank
(
compareId
))
{
currentDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareId
(
indId
,
date
,
compareId
,
new
Sort
(
Sort
.
Direction
.
ASC
,
"rank"
));
}
else
{
currentDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndActualAverageIsNotNull
(
indId
,
date
,
new
Sort
(
Sort
.
Direction
.
ASC
,
"rank"
));
}
//去除无效值
Iterator
<
DriveIndCalResult
>
it
=
currentDriveResult
.
iterator
();
while
(
it
.
hasNext
()){
DriveIndCalResult
driveCalResult
=
it
.
next
();
if
(
"NaN"
.
equals
(
driveCalResult
.
getValue
())||
"0(Error)"
.
equals
(
driveCalResult
.
getValue
())
||
"0.0000"
.
equals
(
driveCalResult
.
getValue
())||
"0"
.
equals
(
driveCalResult
.
getValue
())){
it
.
remove
();
}
}
//同期考核结果
List
<
DriveIndCalResult
>
sameDriveResult
=
new
ArrayList
<>();
if
(
StringUtils
.
isNotBlank
(
compareId
))
{
if
(
"SCC003"
.
equals
(
compareId
))
{
compareId
=
"SCC004"
;
}
if
(
"SCC005"
.
equals
(
compareId
))
{
compareId
=
"SCC006"
;
}
sameDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndCompareId
(
indId
,
(
date
-
100
),
compareId
,
new
Sort
(
Sort
.
Direction
.
ASC
,
"rank"
));
}
else
{
sameDriveResult
=
driveIndResultRepo
.
findByIndIdAndDateAndActualAverageIsNotNull
(
indId
,
date
,
new
Sort
(
Sort
.
Direction
.
ASC
,
"rank"
));
}
//去除无效值
Iterator
<
DriveIndCalResult
>
sit
=
sameDriveResult
.
iterator
();
while
(
sit
.
hasNext
()){
DriveIndCalResult
driveCalResult
=
sit
.
next
();
if
(
"NaN"
.
equals
(
driveCalResult
.
getValue
())||
"0(Error)"
.
equals
(
driveCalResult
.
getValue
())
||
"0.0000"
.
equals
(
driveCalResult
.
getValue
())||
"0"
.
equals
(
driveCalResult
.
getValue
())){
sit
.
remove
();
}
}
if
(!
currentDriveResult
.
isEmpty
())
{
result
.
put
(
"average"
,
currentDriveResult
.
get
(
0
).
getAverage
());
if
(!
"0.0"
.
equals
(
currentDriveResult
.
get
(
0
).
getActualAverage
()))
{
result
.
put
(
"average"
,
currentDriveResult
.
get
(
0
).
getActualAverage
());
}
result
.
put
(
"bestUnits"
,
currentDriveResult
.
get
(
0
).
getCompareObj
());
result
.
put
(
"bestUnitsValue"
,
currentDriveResult
.
get
(
0
).
getValue
());
int
currentMoreAverageNum
=
0
;
int
sameMoreAverageNum
=
0
;
for
(
DriveIndCalResult
driveCalResult:
currentDriveResult
)
{
if
(!
"0.0"
.
equals
(
driveCalResult
.
getActualAverage
()))
{
if
(
Double
.
valueOf
(
driveCalResult
.
getValue
())>
Double
.
valueOf
(
driveCalResult
.
getActualAverage
()))
{
currentMoreAverageNum
+=
1
;
}
}
else
{
if
(
Double
.
valueOf
(
driveCalResult
.
getValue
())>
Double
.
valueOf
(
driveCalResult
.
getAverage
()))
{
currentMoreAverageNum
+=
1
;
}
}
}
for
(
DriveIndCalResult
driveCalResult:
sameDriveResult
)
{
if
(!
"0.0"
.
equals
(
driveCalResult
.
getActualAverage
()))
{
if
(
Double
.
valueOf
(
driveCalResult
.
getValue
())>
Double
.
valueOf
(
driveCalResult
.
getActualAverage
()))
{
sameMoreAverageNum
+=
1
;
}
}
else
{
if
(
Double
.
valueOf
(
driveCalResult
.
getValue
())>
Double
.
valueOf
(
driveCalResult
.
getAverage
()))
{
sameMoreAverageNum
+=
1
;
}
}
}
result
.
put
(
"moreAverageUnits"
,
currentMoreAverageNum
);
result
.
put
(
"compareSameUnits"
,
(
currentMoreAverageNum
-
sameMoreAverageNum
));
String
topUnits
=
""
;
String
bottomUnits
=
""
;
if
(
currentDriveResult
.
size
()<
orderNum
)
{
for
(
DriveIndCalResult
driveCalResult:
currentDriveResult
)
{
topUnits
+=
driveCalResult
.
getCompareObj
()+
";"
;
}
for
(
int
i
=(
currentDriveResult
.
size
()-
1
);
i
>=
0
;
i
--)
{
bottomUnits
+=
currentDriveResult
.
get
(
i
).
getCompareObj
()+
";"
;
}
}
else
{
for
(
int
i
=
0
;
i
<
orderNum
;
i
++)
{
topUnits
+=
currentDriveResult
.
get
(
i
).
getCompareObj
()+
";"
;
}
for
(
int
j
=(
currentDriveResult
.
size
()-
1
);
j
>=(
currentDriveResult
.
size
()-
orderNum
);
j
--)
{
bottomUnits
+=
currentDriveResult
.
get
(
j
).
getCompareObj
()+
";"
;
}
}
result
.
put
(
"topUnits"
,
topUnits
);
result
.
put
(
"bottomUnits"
,
bottomUnits
);
}
return
result
;
}
}
}
src/main/java/com/keymobile/indicators/utils/CalculateUtils.java
View file @
1b3a72c7
...
@@ -10,9 +10,43 @@ import java.util.Map;
...
@@ -10,9 +10,43 @@ 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.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.googlecode.aviator.AviatorEvaluator
;
import
com.googlecode.aviator.AviatorEvaluator
;
public
class
CalculateUtils
{
public
class
CalculateUtils
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
CalculateUtils
.
class
);
public
static
String
calGowth
(
String
unit
,
String
currentValue
,
String
sameValue
,
String
type
)
{
String
gowthValue
=
""
;
StringBuilder
formula
=
new
StringBuilder
();
if
(!
"NaN"
.
equals
(
currentValue
)&&!
"0(Error)"
.
equals
(
currentValue
)&&
!
"NaN"
.
equals
(
sameValue
)&&!
"0(Error)"
.
equals
(
sameValue
))
{
Object
value
=
null
;
if
(
"0"
.
equals
(
type
))
{
if
(
"%"
.
equals
(
unit
))
{
formula
.
append
(
currentValue
).
append
(
"-"
).
append
(
sameValue
);
}
else
{
formula
.
append
(
"("
).
append
(
currentValue
).
append
(
"-"
).
append
(
sameValue
).
append
(
")"
)
.
append
(
"/"
).
append
(
sameValue
).
append
(
"*100"
);
}
}
else
{
formula
.
append
(
"("
).
append
(
currentValue
).
append
(
"-"
).
append
(
sameValue
).
append
(
")"
)
.
append
(
"/"
).
append
(
sameValue
).
append
(
"*100"
);
}
value
=
AviatorEvaluator
.
execute
(
formula
.
toString
());
if
(
value
!=
null
&&
!
"NaN"
.
equals
(
value
.
toString
())
&&
!
"Infinite"
.
equals
(
value
.
toString
()))
{
try
{
gowthValue
=
String
.
format
(
"%.4f"
,
new
BigDecimal
((
Double
)
value
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"计算异常:"
+
formula
.
toString
());
}
}
}
return
gowthValue
;
}
//考虑同分并列的情况,type:0 正向排序:从大到小 1:反向排序:从小到大
//考虑同分并列的情况,type:0 正向排序:从大到小 1:反向排序:从小到大
public
static
Map
<
String
,
Integer
>
rankValue
(
Map
<
String
,
String
>
valueMap
,
String
type
){
public
static
Map
<
String
,
Integer
>
rankValue
(
Map
<
String
,
String
>
valueMap
,
String
type
){
...
@@ -61,6 +95,7 @@ public class CalculateUtils {
...
@@ -61,6 +95,7 @@ public class CalculateUtils {
return
result
;
return
result
;
}
}
//计算平均值
public
static
String
averageValue
(
List
<
String
>
values
)
{
public
static
String
averageValue
(
List
<
String
>
values
)
{
String
calValue
=
"0.0"
;
String
calValue
=
"0.0"
;
StringBuilder
formula
=
new
StringBuilder
();
StringBuilder
formula
=
new
StringBuilder
();
...
@@ -138,7 +173,7 @@ public class CalculateUtils {
...
@@ -138,7 +173,7 @@ public class CalculateUtils {
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// System.out.println(AviatorEvaluator.execute("0/1.
0"));
System
.
out
.
println
(
AviatorEvaluator
.
execute
(
"(35.9756-84.4884)/(35.9756-2556.3310)*1
0"
));
// Map<String, Object> env = Maps.newHashMap();
// Map<String, Object> env = Maps.newHashMap();
// env.put("F004", 18471.8080);
// env.put("F004", 18471.8080);
...
@@ -146,13 +181,13 @@ public class CalculateUtils {
...
@@ -146,13 +181,13 @@ public class CalculateUtils {
// // 输出的是6.333333333333333
// // 输出的是6.333333333333333
// System.out.println(AviatorEvaluator.execute("F004/F002*100", env));
// System.out.println(AviatorEvaluator.execute("F004/F002*100", env));
List
<
String
>
values
=
new
ArrayList
<>();
//
List<String> values = new ArrayList<>();
values
.
add
(
"0"
);
//
values.add("0");
values
.
add
(
"18"
);
//
values.add("18");
values
.
add
(
"18"
);
//
values.add("18");
CalculateUtils
cal
=
new
CalculateUtils
();
//
CalculateUtils cal = new CalculateUtils();
String
average
=
cal
.
averageValue
(
values
);
//
String average = cal.averageValue(values);
System
.
out
.
println
(
average
);
//
System.out.println(average);
// Map<String,String> map = new HashMap<>();
// Map<String,String> map = new HashMap<>();
// map.put("1", "NaN");
// map.put("1", "NaN");
...
...
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