Commit 8f2f3cee by zhangkb

优化单位评分功能代码

parent 3a704693
...@@ -23,8 +23,8 @@ public class ScoreRule implements Serializable{ ...@@ -23,8 +23,8 @@ public class ScoreRule implements Serializable{
@Id @Id
private String id; private String id;
private String ruleName;//规则名称 private String ruleName;//规则名称
private String scoreType;//得分类型:0 指标值直接参与计算 1 指标得分分数参与计算(包括综合评分和改善提升 private String scoreType;//得分类型:0 指标值直接参与计算 1 指标得分分数参与计算(综合评分和改善提升分开算) 2指标得分分数参与计算(指标分数=综合+改善
private String calType;//计算类型:0 计算所有考核指标平均数 1 根据目录类别分类算平均分后根据权重计算考核指标 private String calType;//计算类型:0 计算组内所有考核指标平均数 1 根据目录类别分类算平均分后根据权重计算考核指标
private List<IndTypeWeight> indTypeWeights = new ArrayList<>();//目录类别权重数据 private List<IndTypeWeight> indTypeWeights = new ArrayList<>();//目录类别权重数据
private String code;//标识编码 private String code;//标识编码
......
...@@ -31,4 +31,6 @@ public interface DriveIndCalResultRepository extends MongoRepository<DriveIndCal ...@@ -31,4 +31,6 @@ public interface DriveIndCalResultRepository extends MongoRepository<DriveIndCal
public List<DriveIndCalResult> findByIndIdAndDateAndCompareId(String indId,int date,String compareId); public List<DriveIndCalResult> findByIndIdAndDateAndCompareId(String indId,int date,String compareId);
public List<DriveIndCalResult> findByCompareObjAndDate(String compareObj,int date); public List<DriveIndCalResult> findByCompareObjAndDate(String compareObj,int date);
public List<DriveIndCalResult> findByCompareObjAndDateAndIndIdIn(String compareObj,int date,List<String> indIds);
} }
...@@ -52,29 +52,38 @@ public class ScoreRuleService { ...@@ -52,29 +52,38 @@ public class ScoreRuleService {
return null; return null;
} }
public void calObjScore(String reportId,List<String> compareObjs,int date,String scoreRuleId) { //计算组内考核指标平均值
List<Map<String,String>> results = new ArrayList<>(); private Map<String,String> calGroupIndAverage(ScoreRule scoreRule,List<String> indIds,
//根据单位得分评分卡id获取评分卡详情 String compareObj,int date){
ScoreRule scoreRule = this.getById(scoreRuleId); Map<String,String> result = new HashMap<>();
if(scoreRule!=null) { result.put("compareObj", compareObj);
for(String compareObj : compareObjs) { result.put("scoreValue", "0.0");
//根据对标对象,日期查找该对标对象对标的所有指标结果 result.put("improveValue", "0.0");
result.put("date",String.valueOf(date));
//根据日期,对标对象和考核的指标获取考核指标结果详情
List<DriveIndCalResult> calResults = driveIndCalResultRepo. List<DriveIndCalResult> calResults = driveIndCalResultRepo.
findByCompareObjAndDate(compareObj, date); findByCompareObjAndDateAndIndIdIn(compareObj, date, indIds);
if(!calResults.isEmpty()) {
//计算类型:0 计算所有考核指标平均数
if("0".equals(scoreRule.getCalType())) {
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
List<String> improveValues = new ArrayList<>(); List<String> improveValues = new ArrayList<>();
if(!calResults.isEmpty()) {
for(DriveIndCalResult calResult : calResults) { for(DriveIndCalResult calResult : calResults) {
//得分类型:0 指标值直接参与计算 //得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) { if("0".equals(scoreRule.getScoreType())) {
values.add(calResult.getValue()); values.add(calResult.getValue());
}else { }else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
values.add(calResult.getScore()); values.add(calResult.getScore());
if(!"No".equals(calResult.getImproveScore())) { if(!"No".equals(calResult.getImproveScore())) {
improveValues.add(calResult.getImproveScore()); improveValues.add(calResult.getImproveScore());
} }
}else {//2指标得分分数参与计算(指标分数=综合+改善)
if(!"No".equals(calResult.getImproveScore())) {
double indScore = Double.valueOf(calResult.getScore());
double improveScore = Double.valueOf(calResult.getImproveScore());
double sum = indScore+improveScore;
values.add(String.valueOf(sum));
}else {
values.add(calResult.getScore());
}
} }
} }
//计算平均值 //计算平均值
...@@ -83,37 +92,71 @@ public class ScoreRuleService { ...@@ -83,37 +92,71 @@ public class ScoreRuleService {
if(!improveValues.isEmpty()) { if(!improveValues.isEmpty()) {
averageImproveValue = CalculateUtils.averageValue(improveValues,0); averageImproveValue = CalculateUtils.averageValue(improveValues,0);
} }
Map<String,String> resultMap = new HashMap<>(); result.put("scoreValue", averageValue);
resultMap.put("reportId", reportId); result.put("improveValue", averageImproveValue);
resultMap.put("compareObj", compareObj); }
resultMap.put("scoreValue", averageValue); return result;
resultMap.put("improveValue", averageImproveValue); }
resultMap.put("date",String.valueOf(date));
results.add(resultMap); //按照指标类别进行分类分别计算平均分后再跟类别权重相乘后相加得到最终分数
}else {//1 根据目录类别分类算平均分后根据权重计算考核指标 private Map<String,String> calIndCatalogTypeAverage(ScoreRule scoreRule,
if(!scoreRule.getIndTypeWeights().isEmpty()) { String compareObj,int date){
Map<String,String> result = new HashMap<>();
result.put("compareObj", compareObj);
result.put("scoreValue", "0.0");
result.put("improveValue", "0.0");
result.put("date",String.valueOf(date));
//根据对标对象,日期查找该对标对象对标的所有指标结果
List<DriveIndCalResult> calResults = driveIndCalResultRepo.
findByCompareObjAndDate(compareObj, date);
double scoreValue = 0.0; double scoreValue = 0.0;
double improveValue = 0.0; double improveValue = 0.0;
if(!scoreRule.getIndTypeWeights().isEmpty()) {
for(IndTypeWeight indTypeWeight : scoreRule.getIndTypeWeights()) { for(IndTypeWeight indTypeWeight : scoreRule.getIndTypeWeights()) {
Map<String,Double> calScores = this.calIndTypeScore(scoreRule, indTypeWeight, calResults);
scoreValue += (calScores.get("score")*Double.valueOf(indTypeWeight.getWeight()));
improveValue += (calScores.get("improve")*Double.valueOf(indTypeWeight.getWeight()));
}
}
result.put("scoreValue", String.valueOf(scoreValue));
result.put("improveValue", String.valueOf(improveValue));
return result;
}
//根据指标分类计算指标平均值
private Map<String,Double> calIndTypeScore(ScoreRule scoreRule,IndTypeWeight indTypeWeight,List<DriveIndCalResult> calResults) {
Map<String,Double> result = new HashMap<>();
result.put("score", 0.0);
result.put("improve", 0.0);
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
List<String> improveValues = new ArrayList<>(); List<String> improveValues = new ArrayList<>();
for(DriveIndCalResult calResult : calResults) { for(DriveIndCalResult calResult : calResults) {
String catalogIdPath = indTypeWeight.getCatalogIdPath(); String catalogIdPath = indTypeWeight.getCatalogIdPath();
String driveIndId = calResult.getIndId();
//根据考核指标id获取考核指标 //根据考核指标id获取考核指标
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(driveIndId); DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(calResult.getIndId());
if(driveIndDef!=null) { if(driveIndDef!=null) {
//如果考核指标是参与单位计分的 //如果考核指标是参与单位计分的
if("1".equals(driveIndDef.getIsUnitCalScore())) { if("1".equals(driveIndDef.getIsUnitCalScore())) {
//如果指标是该指标分类下的
if(indTypeWeight.getCatalogIdPath().indexOf(catalogIdPath)>=0) { if(indTypeWeight.getCatalogIdPath().indexOf(catalogIdPath)>=0) {
//得分类型:0 指标值直接参与计算 //得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) { if("0".equals(scoreRule.getScoreType())) {
values.add(calResult.getValue()); values.add(calResult.getValue());
}else { }else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
values.add(calResult.getScore()); values.add(calResult.getScore());
if(!"No".equals(calResult.getImproveScore())) { if(!"No".equals(calResult.getImproveScore())) {
improveValues.add(calResult.getImproveScore()); improveValues.add(calResult.getImproveScore());
} }
}else {//2指标得分分数参与计算(指标分数=综合+改善)
if(!"No".equals(calResult.getImproveScore())) {
double indScore = Double.valueOf(calResult.getScore());
double improveScore = Double.valueOf(calResult.getImproveScore());
double sum = indScore+improveScore;
values.add(String.valueOf(sum));
}else {
values.add(calResult.getScore());
}
} }
} }
} }
...@@ -125,22 +168,35 @@ public class ScoreRuleService { ...@@ -125,22 +168,35 @@ public class ScoreRuleService {
if(!improveValues.isEmpty()) { if(!improveValues.isEmpty()) {
averageImproveValue = CalculateUtils.averageValue(improveValues,0); averageImproveValue = CalculateUtils.averageValue(improveValues,0);
} }
scoreValue = scoreValue+Double.valueOf(averageValue)* result.put("score", Double.valueOf(averageValue));
(Double.valueOf(indTypeWeight.getWeight())/100); result.put("improve", Double.valueOf(averageImproveValue));
improveValue = improveValue+Double.valueOf(averageImproveValue)* return result;
(Double.valueOf(indTypeWeight.getWeight())/100);
} }
//根据单位评分规则计算单位分数
public void calObjScore(String reportId,String compareId,List<String> indIds,
List<String> compareObjs,int date,String scoreRuleId) {
List<Map<String,String>> results = new ArrayList<>();
//根据单位得分评分卡id获取评分卡详情
ScoreRule scoreRule = this.getById(scoreRuleId);
if(scoreRule!=null) {
for(String compareObj : compareObjs) {
//根据对标对象,日期查找该对标对象对标的所有指标结果
List<DriveIndCalResult> calResults = driveIndCalResultRepo.
findByCompareObjAndDate(compareObj, date);
if(!calResults.isEmpty()) {
Map<String,String> resultMap = new HashMap<>(); Map<String,String> resultMap = new HashMap<>();
//计算类型:0 计算组内所有考核指标平均数
if("0".equals(scoreRule.getCalType())) {
resultMap = this.calGroupIndAverage(scoreRule, indIds, compareObj, date);
}else {//1 根据目录类别分类算平均分后根据权重计算考核指标
resultMap = this.calIndCatalogTypeAverage(scoreRule, compareObj, date);
}
resultMap.put("reportId", reportId); resultMap.put("reportId", reportId);
resultMap.put("compareObj", compareObj); resultMap.put("compareId", compareId);
resultMap.put("scoreValue", String.valueOf(scoreValue));
resultMap.put("improveValue", String.valueOf(improveValue));
resultMap.put("date",String.valueOf(date));
results.add(resultMap); results.add(resultMap);
} }
} }
}
}
}else { }else {
logger.info("单位评分卡id:"+scoreRuleId+" 不存在"); logger.info("单位评分卡id:"+scoreRuleId+" 不存在");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment