Commit ef0e6c27 by zhangkb

优化考核指标计算逻辑

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