Commit ef0e6c27 by zhangkb

优化考核指标计算逻辑

parent 7587d22b
...@@ -166,8 +166,15 @@ public class DriveIndCalculateActor extends AbstractActor{ ...@@ -166,8 +166,15 @@ public class DriveIndCalculateActor extends AbstractActor{
unit,indType,markType,averageDriveIndFormula); unit,indType,markType,averageDriveIndFormula);
driveIndCalculateRegionActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender()); driveIndCalculateRegionActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
} catch (Exception e) { } catch (Exception e) {
DriveIndCalResultDef driveIndCalResult = new DriveIndCalResultDef(compareId, //判断结果表中是否已存在该结果数据,存在则覆盖
driveIndId,compareObj,date,"NaN",unit,"1","0","admin"); DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date);
if(driveIndCalResult==null) {
driveIndCalResult = new DriveIndCalResultDef(compareId,
driveIndId,compareObj,date,"NaN",unit,"1","0","admin");
}else {
driveIndCalResult.setValue("NaN");
}
driveIndCalResultService.saveOrUpdate(driveIndCalResult); driveIndCalResultService.saveOrUpdate(driveIndCalResult);
DriveIndAverageAndRankMsg driveIndAverageAndRankMsg = DriveIndAverageAndRankMsg driveIndAverageAndRankMsg =
new DriveIndAverageAndRankMsg(driveIndCalResult.getId(), new DriveIndAverageAndRankMsg(driveIndCalResult.getId(),
......
...@@ -76,51 +76,53 @@ public class DriveIndCalculateRegionActor extends AbstractActor{ ...@@ -76,51 +76,53 @@ public class DriveIndCalculateRegionActor extends AbstractActor{
compareObjs.add(driveIndAverageAndRankMsg.getCompareObj()); compareObjs.add(driveIndAverageAndRankMsg.getCompareObj());
} }
if (++numberOfConfirm >= compareObjSize) {//子actor全部返回 if (++numberOfConfirm >= compareObjSize) {//子actor全部返回
//考核地区只有一个“全省”的情况下 if(!valueMap.isEmpty() && !compareObjs.isEmpty()) {
if(!"全省".equals(driveIndAverageAndRankMsg.getCompareObj())) { //考核地区只有一个“全省”的情况下
//查询有没有全省的考核指标数据 if(!"全省".equals(driveIndAverageAndRankMsg.getCompareObj())) {
DriveIndCalResultDef provinceDriveIndCalResult = driveIndCalResultService.findCompareObjInfo( //查询有没有全省的考核指标数据
driveIndAverageAndRankMsg.getDriveIndId(), driveIndAverageAndRankMsg.getDate(), DriveIndCalResultDef provinceDriveIndCalResult = driveIndCalResultService.findCompareObjInfo(
"全省"); driveIndAverageAndRankMsg.getDriveIndId(), driveIndAverageAndRankMsg.getDate(),
String actualAverage = "0.0"; "全省");
if(provinceDriveIndCalResult!=null) { String actualAverage = "0.0";
//获取实际平均分 if(provinceDriveIndCalResult!=null) {
actualAverage = provinceDriveIndCalResult.getValue(); //获取实际平均分
} actualAverage = provinceDriveIndCalResult.getValue();
//算组内平均数 }
//String average = CalculateUtils.averageValue(values); //算组内平均数
String average = driveIndDefService.calGroupAverage( //String average = CalculateUtils.averageValue(values);
driveIndAverageAndRankMsg.getIndFormula(), compareObjs, String average = driveIndDefService.calGroupAverage(
driveIndAverageAndRankMsg.getDate()); driveIndAverageAndRankMsg.getIndFormula(), compareObjs,
driveIndAverageAndRankMsg.getDate());
//算组内排名
Map<String,Integer> rankValue = CalculateUtils.rankValue(valueMap, indType); //算组内排名
for(Entry<String,Integer> entry : rankValue.entrySet()) { Map<String,Integer> rankValue = CalculateUtils.rankValue(valueMap, indType);
//根据id获取指标值结果 for(Entry<String,Integer> entry : rankValue.entrySet()) {
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService. //根据id获取指标值结果
findById(Integer.parseInt(entry.getKey())); DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
if(driveIndCalResult!=null) { findById(Integer.parseInt(entry.getKey()));
driveIndCalResult.setAverage(average); if(driveIndCalResult!=null) {
driveIndCalResult.setRank(entry.getValue()); driveIndCalResult.setAverage(average);
driveIndCalResult.setActualAverage(actualAverage); driveIndCalResult.setRank(entry.getValue());
driveIndCalResultService.saveOrUpdate(driveIndCalResult); driveIndCalResult.setActualAverage(actualAverage);
driveIndCalResultService.saveOrUpdate(driveIndCalResult);
}
}
//根据评分卡算指标分数
for(Entry<String,Integer> entry : rankValue.entrySet()) {
//根据id获取指标值结果
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) {
//计算分数
Map<String,String> scoreMap = indScorecardService.calculateIndiScore(
driveIndCalResult.getIndId(), driveIndCalResult.getDate(),
driveIndCalResult.getCompareObj(), markType,
driveIndCalResult.getCompareId(),compareObjs);
driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
driveIndCalResultService.saveOrUpdate(driveIndCalResult);
}
} }
}
//根据评分卡算指标分数
for(Entry<String,Integer> entry : rankValue.entrySet()) {
//根据id获取指标值结果
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) {
//计算分数
Map<String,String> scoreMap = indScorecardService.calculateIndiScore(
driveIndCalResult.getIndId(), driveIndCalResult.getDate(),
driveIndCalResult.getCompareObj(), markType,
driveIndCalResult.getCompareId(),compareObjs);
driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
driveIndCalResultService.saveOrUpdate(driveIndCalResult);
}
} }
} }
} }
......
...@@ -697,15 +697,17 @@ public class IndicatorsValueService { ...@@ -697,15 +697,17 @@ public class IndicatorsValueService {
currentDriveResult = driveIndCalResultDefMapper currentDriveResult = driveIndCalResultDefMapper
.findByIndIdAndDateAndSortAndActualAverageIsNotNull(indId, date); .findByIndIdAndDateAndSortAndActualAverageIsNotNull(indId, date);
} }
//去除无效值 if(!currentDriveResult.isEmpty()) {
Iterator<DriveIndCalResultDef> it=currentDriveResult.iterator(); //去除无效值
while(it.hasNext()){ Iterator<DriveIndCalResultDef> it=currentDriveResult.iterator();
DriveIndCalResultDef driveCalResult = it.next(); while(it.hasNext()){
if("NaN".equals(driveCalResult.getValue()) || "Infinite".equals(driveCalResult.getValue()) DriveIndCalResultDef driveCalResult = it.next();
||"0.0000".equals(driveCalResult.getValue())||"0".equals(driveCalResult.getValue())){ if("NaN".equals(driveCalResult.getValue()) || "Infinite".equals(driveCalResult.getValue())
it.remove(); ||"0.0000".equals(driveCalResult.getValue())||"0".equals(driveCalResult.getValue())){
} it.remove();
} }
}
}
//同期考核结果 //同期考核结果
List<DriveIndCalResultDef> sameDriveResult = new ArrayList<>(); List<DriveIndCalResultDef> sameDriveResult = new ArrayList<>();
if(StringUtils.isNotBlank(compareId)) { if(StringUtils.isNotBlank(compareId)) {
...@@ -721,15 +723,17 @@ public class IndicatorsValueService { ...@@ -721,15 +723,17 @@ public class IndicatorsValueService {
sameDriveResult = driveIndCalResultDefMapper.findByIndIdAndDateAndSortAndActualAverageIsNotNull( sameDriveResult = driveIndCalResultDefMapper.findByIndIdAndDateAndSortAndActualAverageIsNotNull(
indId, date); indId, date);
} }
//去除无效值 if(!sameDriveResult.isEmpty()) {
Iterator<DriveIndCalResultDef> sit=sameDriveResult.iterator(); //去除无效值
while(sit.hasNext()){ Iterator<DriveIndCalResultDef> sit=sameDriveResult.iterator();
DriveIndCalResultDef driveCalResult = sit.next(); while(sit.hasNext()){
if("NaN".equals(driveCalResult.getValue()) || "Infinite".equals(driveCalResult.getValue()) DriveIndCalResultDef driveCalResult = sit.next();
||"0.0000".equals(driveCalResult.getValue())||"0".equals(driveCalResult.getValue())){ if("NaN".equals(driveCalResult.getValue()) || "Infinite".equals(driveCalResult.getValue())
sit.remove(); ||"0.0000".equals(driveCalResult.getValue())||"0".equals(driveCalResult.getValue())){
} sit.remove();
} }
}
}
if(!currentDriveResult.isEmpty()) { if(!currentDriveResult.isEmpty()) {
result.put("average", currentDriveResult.get(0).getAverage()); result.put("average", currentDriveResult.get(0).getAverage());
if(!"0.0".equals(currentDriveResult.get(0).getActualAverage())) { if(!"0.0".equals(currentDriveResult.get(0).getActualAverage())) {
......
...@@ -236,13 +236,15 @@ public class ScoreRuleService { ...@@ -236,13 +236,15 @@ public class ScoreRuleService {
findByCompareObjAndDate(compareObj, date); findByCompareObjAndDate(compareObj, date);
double scoreValue = 0.0; double scoreValue = 0.0;
double improveValue = 0.0; double improveValue = 0.0;
if(StringUtils.isNotBlank(scoreRule.getIndTypeWeightsJson())) { if(!calResults.isEmpty()) {
List<IndTypeWeight> indTypeWeights = gson. if(StringUtils.isNotBlank(scoreRule.getIndTypeWeightsJson())) {
fromJson(scoreRule.getIndTypeWeightsJson(), new TypeToken<List<IndTypeWeight>>(){}.getType()); List<IndTypeWeight> indTypeWeights = gson.
for(IndTypeWeight indTypeWeight : indTypeWeights) { fromJson(scoreRule.getIndTypeWeightsJson(), new TypeToken<List<IndTypeWeight>>(){}.getType());
Map<String,Double> calScores = this.calIndTypeScore(scoreRule, indTypeWeight, calResults); for(IndTypeWeight indTypeWeight : indTypeWeights) {
scoreValue += (calScores.get("score")*Double.parseDouble(indTypeWeight.getWeight())); Map<String,Double> calScores = this.calIndTypeScore(scoreRule, indTypeWeight, calResults);
improveValue += (calScores.get("improve")*Double.parseDouble(indTypeWeight.getWeight())); scoreValue += (calScores.get("score")*Double.parseDouble(indTypeWeight.getWeight()));
improveValue += (calScores.get("improve")*Double.parseDouble(indTypeWeight.getWeight()));
}
} }
} }
result.put("scoreValue", String.valueOf(scoreValue)); result.put("scoreValue", String.valueOf(scoreValue));
......
...@@ -236,7 +236,7 @@ public class ShortboardRuleService { ...@@ -236,7 +236,7 @@ public class ShortboardRuleService {
List<DriveIndCalResultDef> realCalResults = new ArrayList<>();//用于保存符合过滤条件的指标结果 List<DriveIndCalResultDef> realCalResults = new ArrayList<>();//用于保存符合过滤条件的指标结果
//获取排名第一的最大值 //获取排名第一的最大值
String maxValue = null; String maxValue = null;
if(!realCalResults.isEmpty()) { if(!calResults.isEmpty()) {
maxValue = calResults.get(0).getValue(); maxValue = calResults.get(0).getValue();
} }
if(maxValue!=null) { if(maxValue!=null) {
......
...@@ -98,10 +98,14 @@ public class CalculateUtils { ...@@ -98,10 +98,14 @@ public class CalculateUtils {
headIndValue = entry.getValue(); headIndValue = entry.getValue();
} }
order+=1; order+=1;
if(!invalidMap.isEmpty()) { if(!invalidMap.isEmpty() && !compareMap.isEmpty()) {
for(Entry<String,String> entry : invalidMap.entrySet()) { for(Entry<String,String> entry : invalidMap.entrySet()) {
result.put(entry.getKey(), order); result.put(entry.getKey(), order);
} }
}else {
for(Entry<String,String> entry : invalidMap.entrySet()) {
result.put(entry.getKey(), 0);
}
} }
return result; return result;
} }
...@@ -214,18 +218,18 @@ public class CalculateUtils { ...@@ -214,18 +218,18 @@ public class CalculateUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
// Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
// map.put("1001", "1"); map.put("1001", "NaN");
// map.put("1002", "3"); map.put("1002", "NaN");
// map.put("1003", "2"); map.put("1003", "NaN");
// map.put("1004", "4"); map.put("1004", "NaN");
// map.put("1005", "8"); map.put("1005", "NaN");
// map.put("1006", "6"); map.put("1006", "NaN");
// map.put("1007", "7"); map.put("1007", "NaN");
// map.put("1008", "5"); map.put("1008", "NaN");
// CalculateUtils cal = new CalculateUtils(); CalculateUtils cal = new CalculateUtils();
// Map<String,Integer> result = cal.rankValue(map, "1"); Map<String,Integer> result = cal.rankValue(map, "1");
// System.out.println(result); System.out.println(result);
// //
// String formula = "([1001]+[1002])/2"; // String formula = "([1001]+[1002])/2";
// formula = formula.replace("[1001]", "3"); // formula = formula.replace("[1001]", "3");
...@@ -234,12 +238,12 @@ public class CalculateUtils { ...@@ -234,12 +238,12 @@ public class CalculateUtils {
// System.out.println(result1); // System.out.println(result1);
// Double b = (double) Math.abs(34-50); // Double b = (double) Math.abs(34-50);
// System.out.println(b); // System.out.println(b);
List<String> listA = new ArrayList<>(); // List<String> listA = new ArrayList<>();
listA.add("a"); // listA.add("a");
listA.add("b"); // listA.add("b");
listA.add("c"); // listA.add("c");
List<String> listB = new ArrayList<>(); // List<String> listB = new ArrayList<>();
listA.retainAll(listB); // listA.retainAll(listB);
System.out.println(listA); // System.out.println(listA);
} }
} }
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