Commit e04a722c by zhangkb

修改指标值排名逻辑

parent f9b26cf3
......@@ -154,107 +154,113 @@ public class DriveIndIdObjCalActor extends AbstractActor{
logger.info(baseIndValueMsg.getConfirmMessage());
}
String indValue = baseIndValueMsg.getValue();
//如果指标值返回空值,那么就不进行下面的计算了,直接返回给父actor
if(StringUtils.isBlank(indValue)) {
indValue="0.0";
}
try {
driveIndFormula = driveIndFormula.replace("["+baseIndValueMsg.getIndId()+"]",
indValue);
//替换公式中的基础指标id为确定指标值
//env.put(baseIndValueMsg.getIndId(), Double.valueOf(indValue));
}catch(Exception e) {
e.printStackTrace();
logger.error("driveIndId:"+driveIndId+";"+
"formula:"+driveIndFormula+";"+
"errorValue:"+indValue+";"+"paramEnv:"+env);
//日志记录
String logInfo = compCalLog.getLogInfo();
if(StringUtils.isNotBlank(logInfo)) {
logInfo+="替换公式值出错:driveIndId:"+driveIndId+";"+
"formula:"+driveIndFormula+";"+
"errorValue:"+indValue+";"+"paramEnv:"+env+"</n>";
compCalLog.setLogInfo(logInfo);
}else {
compCalLog.setLogInfo("替换公式值出错:driveIndId:"+driveIndId+";"+
"formula:"+driveIndFormula+";"+
"errorValue:"+indValue+";"+"paramEnv:"+env+"</n>");
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
}else {
try {
driveIndFormula = driveIndFormula.replace("["+baseIndValueMsg.getIndId()+"]",
indValue);
//替换公式中的基础指标id为确定指标值
//env.put(baseIndValueMsg.getIndId(), Double.valueOf(indValue));
}catch(Exception e) {
e.printStackTrace();
logger.error("driveIndId:"+driveIndId+";"+
"formula:"+driveIndFormula+";"+
"errorValue:"+indValue+";"+"paramEnv:"+env);
//日志记录
String logInfo = compCalLog.getLogInfo();
if(StringUtils.isNotBlank(logInfo)) {
logInfo+="替换公式值出错:driveIndId:"+driveIndId+";"+
"formula:"+driveIndFormula+";"+
"errorValue:"+indValue+";"+"paramEnv:"+env+"</n>";
compCalLog.setLogInfo(logInfo);
}else {
compCalLog.setLogInfo("替换公式值出错:driveIndId:"+driveIndId+";"+
"formula:"+driveIndFormula+";"+
"errorValue:"+indValue+";"+"paramEnv:"+env+"</n>");
}
}
}
confirmList.add(baseIndValueMsg.getIsFinish());
if (++numberOfConfirm >= indIdSize) {//子actor全部返回
if(!confirmList.contains(0)) {//取所有基础指标值没错
//进行考核指标值计算
try {
String driveIndValue = AviatorEvaluator.execute(driveIndFormula).toString();
//保留四位小数
if(!driveIndValue.equals("NaN") && !driveIndValue.equals("Infinite")) {
driveIndValue = String.format("%.4f",
new BigDecimal(Double.valueOf(driveIndValue)));
}
//判断结果表中是否已存在该结果数据,存在则覆盖
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date);
if(driveIndCalResult==null) {
driveIndCalResult = new DriveIndCalResultDef(compareId,
driveIndId,compareObj,date,driveIndValue,unit,
"1","1","admin",code,baseIndValueMsg.getCompareObjDesc());
}else {
driveIndCalResult.setCode(code);
driveIndCalResult.setUnit(unit);
driveIndCalResult.setValue(driveIndValue);
driveIndCalResult.setLastUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
}
//保存进考核指标结果表中
driveIndCalResultService.saveOrUpdate(driveIndCalResult);
//返回指标值回去算平均值和排名
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(driveIndCalResult.getId(),
compareId,driveIndId,compareObj,date,driveIndValue,
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
} catch (Exception e) {
//判断结果表中是否已存在该结果数据,存在则覆盖
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date);
if(driveIndCalResult==null) {
driveIndCalResult = new DriveIndCalResultDef(compareId,
driveIndId,compareObj,date,"NaN",unit,
"1","0","admin",code,baseIndValueMsg.getCompareObjDesc());
}else {
driveIndCalResult.setCode(code);
driveIndCalResult.setUnit(unit);
driveIndCalResult.setValue("NaN");
driveIndCalResult.setLastUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
confirmList.add(baseIndValueMsg.getIsFinish());
if (++numberOfConfirm >= indIdSize) {//子actor全部返回
if(!confirmList.contains(0)) {//取所有基础指标值没错
//进行考核指标值计算
try {
String driveIndValue = AviatorEvaluator.execute(driveIndFormula).toString();
//保留四位小数
if(!driveIndValue.equals("NaN") && !driveIndValue.equals("Infinite")) {
driveIndValue = String.format("%.4f",
new BigDecimal(Double.valueOf(driveIndValue)));
}
//判断结果表中是否已存在该结果数据,存在则覆盖
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date);
if(driveIndCalResult==null) {
driveIndCalResult = new DriveIndCalResultDef(compareId,
driveIndId,compareObj,date,driveIndValue,unit,
"1","1","admin",code,baseIndValueMsg.getCompareObjDesc());
}else {
driveIndCalResult.setCode(code);
driveIndCalResult.setUnit(unit);
driveIndCalResult.setValue(driveIndValue);
driveIndCalResult.setLastUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
}
//保存进考核指标结果表中
driveIndCalResultService.saveOrUpdate(driveIndCalResult);
//返回指标值回去算平均值和排名
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(driveIndCalResult.getId(),
compareId,driveIndId,compareObj,date,driveIndValue,
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
} catch (Exception e) {
//判断结果表中是否已存在该结果数据,存在则覆盖
// DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
// findCalResultDataIsExist(compareId, compareObj, driveIndId, date);
// if(driveIndCalResult==null) {
// driveIndCalResult = new DriveIndCalResultDef(compareId,
// driveIndId,compareObj,date,"NaN",unit,
// "1","0","admin",code,baseIndValueMsg.getCompareObjDesc());
// }else {
// driveIndCalResult.setCode(code);
// driveIndCalResult.setUnit(unit);
// driveIndCalResult.setValue("NaN");
// driveIndCalResult.setLastUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
// }
// driveIndCalResultService.saveOrUpdate(driveIndCalResult);
logger.error("driveIndId:"+driveIndId+";"+
"paramEnv:"+env+";formula:"+driveIndFormula);
//日志记录
String logInfo = compCalLog.getLogInfo();
if(StringUtils.isNotBlank(logInfo)) {
logInfo+="计算考核指标出错:driveIndId:"+driveIndId+";"+
"paramEnv:"+env+";formula:"+driveIndFormula+"</n>";
compCalLog.setLogInfo(logInfo);
}else {
compCalLog.setLogInfo("计算考核指标出错:driveIndId:"+driveIndId+";"+
"paramEnv:"+env+";formula:"+driveIndFormula+"</n>");
}
//表示计算错误,不生成考核结果
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
}
driveIndCalResultService.saveOrUpdate(driveIndCalResult);
logger.error("driveIndId:"+driveIndId+";"+
"paramEnv:"+env+";formula:"+driveIndFormula);
//日志记录
String logInfo = compCalLog.getLogInfo();
if(StringUtils.isNotBlank(logInfo)) {
logInfo+="计算考核指标出错:driveIndId:"+driveIndId+";"+
"paramEnv:"+env+";formula:"+driveIndFormula+"</n>";
compCalLog.setLogInfo(logInfo);
}else {
compCalLog.setLogInfo("计算考核指标出错:driveIndId:"+driveIndId+";"+
"paramEnv:"+env+";formula:"+driveIndFormula+"</n>");
}
}else {
//返回考核指标因为考核指标公式中的数据项不存在而导致的计算错误标识
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(driveIndCalResult.getId(),
new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
}
}else {
//返回考核指标因为考核指标公式中的数据项不存在而导致的计算错误标识
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
}
}
//保存日志
......
......@@ -208,16 +208,22 @@ public class IndicatorsReportService {
String indRule = driveIndDef.getIndRule();
Map<String,String> valueRate = new HashMap<>();
for(IndicatorsReportOne indReportData : datas) {
if(StringUtils.isBlank(indReportData.getValueRate())) {
continue;
}
valueRate.put(indReportData.getCompareObj(), indReportData.getValueRate());
}
//增幅排名
Map<String,Integer> valueRateRank = CalculateUtils.rankValue(valueRate, indRule);
for(Map.Entry<String,Integer> map : valueRateRank.entrySet()) {
for(int i=0;i<datas.size();i++) {
if(map.getKey().equals(datas.get(i).getCompareObj())) {
datas.get(i).setValueRateRank(map.getValue()+"");
datas.set(i, datas.get(i));
break;
if(!valueRate.isEmpty()) {
//增幅排名
Map<String,Integer> valueRateRank = CalculateUtils.rankValue(valueRate, indRule);
for(Map.Entry<String,Integer> map : valueRateRank.entrySet()) {
for(int i=0;i<datas.size();i++) {
IndicatorsReportOne data = datas.get(i);
if(map.getKey().equals(data.getCompareObj())) {
data.setValueRateRank(map.getValue()+"");
datas.set(i, data);
break;
}
}
}
}
......@@ -316,17 +322,18 @@ public class IndicatorsReportService {
//同比提升单位
Map<String,Object> sameImproveResult = this.sameImproveUnits(indId, date, compareObjs,
calDatas);
indReportData.setSameImproveUnits(Integer.parseInt(sameImproveResult.get("improveNum").toString()));
if(Integer.parseInt(sameImproveResult.get("improveNum").toString())!=0) {
indReportData.setSameImproveUnits(Integer.parseInt(sameImproveResult.get("improveNum").toString()));
}
//同比提升前三
int start = 0;
int end = 3;
Map<String,Integer> resultRank = (Map<String,Integer>)sameImproveResult.get("resultRank");
//根据省对市地区顺序排列排名并列的情况
Map<String,Object> objSortRank = CalculateUtils.rankByObjSort(resultRank, objSort);
resultRank = (Map<String,Integer>)objSortRank.get("rankMap");
end = Integer.parseInt(objSortRank.get("rankNum").toString());
if(!resultRank.isEmpty()) {
//根据省对市地区顺序排列排名并列的情况
Map<String,Object> objSortRank = CalculateUtils.rankByObjSort(resultRank, objSort);
resultRank = (Map<String,Integer>)objSortRank.get("rankMap");
end = Integer.parseInt(objSortRank.get("rankNum").toString());
StringBuilder sameImproveHeadThree = new StringBuilder("");//同比提升前三
StringBuilder sameImproveHeadThreeDesc = new StringBuilder("");
for(Map.Entry<String,Integer> entry : resultRank.entrySet()) {
......
......@@ -90,7 +90,8 @@ public class CalculateUtils {
for(Entry<String,Double> entry : compareMap.entrySet()) {
if(i==0) {
result.put(entry.getKey(), 1);
order+=1;
headIndValue = entry.getValue();
order++;
i++;
continue;
}
......@@ -352,20 +353,26 @@ public class CalculateUtils {
}
public static void main(String[] args) {
// Map<String,String> map = new HashMap<>();
// map.put("1001", "12");
// map.put("1002", "-1");
// map.put("1003", "-4");
// map.put("1004", "3");
// map.put("1005", "5");
// map.put("1006", "7");
// map.put("1007", "0");
// map.put("1008", "-6");
Map<String,String> map = new HashMap<>();
map.put("4302", "48.0000");
map.put("4308", "24.0000");
map.put("4304", "24.0000");
map.put("4310", "43.9100");
map.put("4331", "48.0000");
map.put("4312", "48.0000");
map.put("4313", "24.0000");
map.put("4303", "39.8400");
map.put("4309", "48.0000");
map.put("4307", "48.0000");
map.put("4301", "48.0000");
map.put("4306", "48.0000");
map.put("4305", "48.0000");
map.put("4311", "39.8400");
CalculateUtils cal = new CalculateUtils();
System.out.println(cal.isValidformula("([1001]+[1002])-[1004]"));
// Map<String,Integer> result = cal.rankValue(map, "0");
// result = cal.sortMapByValue(result,1);
// System.out.println(result);
// System.out.println(cal.isValidformula("([1001]+[1002])-[1004]"));
Map<String,Integer> result = cal.rankValue(map, "1");
result = cal.sortMapByValue(result,1);
System.out.println(result);
//
// String formula = "([1001]+[1002])/2";
// Map<String,String> map = new HashMap<>();
......
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