Commit d94d480c by hzc

对标运算加try捕获未知异常

parent 82229af3
...@@ -10,6 +10,7 @@ import com.keymobile.indicators.constant.Constants; ...@@ -10,6 +10,7 @@ import com.keymobile.indicators.constant.Constants;
import com.keymobile.indicators.model.entity.indicators.CompareUnitCalLog; import com.keymobile.indicators.model.entity.indicators.CompareUnitCalLog;
import com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService; import com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService;
import com.keymobile.indicators.utils.LogManager; import com.keymobile.indicators.utils.LogManager;
import com.netflix.discovery.converters.jackson.EurekaXmlJacksonCodec;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -51,6 +52,7 @@ public class BeforeCompareUnitCalActor extends AbstractActor{ ...@@ -51,6 +52,7 @@ public class BeforeCompareUnitCalActor extends AbstractActor{
@Override @Override
public Receive createReceive() { public Receive createReceive() {
try {
return receiveBuilder() return receiveBuilder()
.match(StartCompareUnitCalMsg.class,beforeCompareUnitCalMsg -> { .match(StartCompareUnitCalMsg.class,beforeCompareUnitCalMsg -> {
List<CompareUnitDef> compareUnitDefs = beforeCompareUnitCalMsg.getCompareInitDefs(); List<CompareUnitDef> compareUnitDefs = beforeCompareUnitCalMsg.getCompareInitDefs();
...@@ -156,6 +158,12 @@ public class BeforeCompareUnitCalActor extends AbstractActor{ ...@@ -156,6 +158,12 @@ public class BeforeCompareUnitCalActor extends AbstractActor{
if(compCalLog!=null) { if(compCalLog!=null) {
compCalLog.setEndTime(System.currentTimeMillis()+""); compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1"); compCalLog.setRunStatus("1");
String logInfo = compCalLog.getLogInfo();
if(StringUtils.isBlank(logInfo)){
logInfo = "没异常";
}
logInfo = "整体试运算成功-运算过程:"+logInfo;
compCalLog.setLogInfo(logInfo);
compareUnitCalLogService.saveOrUndate(compCalLog); compareUnitCalLogService.saveOrUndate(compCalLog);
} }
LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"完成对标单元id:{},日期:{} 的试运行计算",compCalLogId,currentDate ); LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"完成对标单元id:{},日期:{} 的试运行计算",compCalLogId,currentDate );
...@@ -164,18 +172,34 @@ public class BeforeCompareUnitCalActor extends AbstractActor{ ...@@ -164,18 +172,34 @@ public class BeforeCompareUnitCalActor extends AbstractActor{
if(compCalLog!=null) { if(compCalLog!=null) {
compCalLog.setEndTime(System.currentTimeMillis()+""); compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1"); compCalLog.setRunStatus("1");
if(compCalLog.getStatus()==1){ String logInfo = compCalLog.getLogInfo();
compCalLog.setLogInfo("运算成功"); if(StringUtils.isBlank(logInfo)){
logInfo = "没异常";
} }
logInfo = "整体运算成功-运算过程:"+logInfo;
compCalLog.setLogInfo(logInfo);
compareUnitCalLogService.saveOrUndate(compCalLog); compareUnitCalLogService.saveOrUndate(compCalLog);
} }
LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"完成对标单元id:{},日期:{} 的运行计算",compCalLogId,currentDate ); LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"完成对标单元id:{},日期:{} 的正式运行计算",compCalLogId,currentDate );
logger.info("本期同期对标单元计算完成"); logger.info("本期同期对标单元计算完成");
} }
} }
} }
}) })
.build(); .build();
}catch (Exception e){
e.printStackTrace();
CompareUnitCalLog compCalLog = compareUnitCalLogService.findById(compCalLogId);
if(compCalLog!=null){
compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1");
compCalLog.setStatus(0);
compCalLog.setLogInfo("运算失败");
compareUnitCalLogService.saveOrUndate(compCalLog);
}
}
return null;
} }
} }
...@@ -65,6 +65,8 @@ public class CompareUnitCalActor extends AbstractActor{ ...@@ -65,6 +65,8 @@ public class CompareUnitCalActor extends AbstractActor{
@Override @Override
public Receive createReceive() { public Receive createReceive() {
try {
return receiveBuilder() return receiveBuilder()
.match(CompareUnitCalMsg.class,compareUnitCalMsg -> { .match(CompareUnitCalMsg.class,compareUnitCalMsg -> {
CompareUnitDef compareUnitDef = compareUnitCalMsg.getCompareUnitDef(); CompareUnitDef compareUnitDef = compareUnitCalMsg.getCompareUnitDef();
...@@ -75,7 +77,7 @@ public class CompareUnitCalActor extends AbstractActor{ ...@@ -75,7 +77,7 @@ public class CompareUnitCalActor extends AbstractActor{
objScoreRuleId = compareUnitDef.getObjScoreRuleId(); objScoreRuleId = compareUnitDef.getObjScoreRuleId();
code = compareUnitCalMsg.getCode(); code = compareUnitCalMsg.getCode();
isTest = compareUnitCalMsg.getIsTest(); isTest = compareUnitCalMsg.getIsTest();
compCalLogId = compareUnitCalMsg.getCompCalLogId();
// //新增运行日志记录 // //新增运行日志记录
// CompareUnitCalLog compCalLog = new CompareUnitCalLog(compareId,date, // CompareUnitCalLog compCalLog = new CompareUnitCalLog(compareId,date,
// System.currentTimeMillis()+"","0"); // System.currentTimeMillis()+"","0");
...@@ -85,7 +87,7 @@ public class CompareUnitCalActor extends AbstractActor{ ...@@ -85,7 +87,7 @@ public class CompareUnitCalActor extends AbstractActor{
// compCalLog.setType(isTest); // compCalLog.setType(isTest);
//保存 //保存
// Integer compCalLogId = compareUnitCalLogService.saveOrUndate(compCalLog); // Integer compCalLogId = compareUnitCalLogService.saveOrUndate(compCalLog);
compCalLogId = compareUnitCalMsg.getCompCalLogId();
//获取对标对象 //获取对标对象
String compareObjsString = compareUnitDef.getCompareObjs(); String compareObjsString = compareUnitDef.getCompareObjs();
//获取对标指标 //获取对标指标
...@@ -161,5 +163,18 @@ public class CompareUnitCalActor extends AbstractActor{ ...@@ -161,5 +163,18 @@ public class CompareUnitCalActor extends AbstractActor{
} }
}) })
.build(); .build();
}catch (Exception e){
e.printStackTrace();
CompareUnitCalLog compCalLog = compareUnitCalLogService.findById(compCalLogId);
if(compCalLog!=null){
compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1");
compCalLog.setStatus(0);
compCalLog.setLogInfo("运算失败");
compareUnitCalLogService.saveOrUndate(compCalLog);
}
}
return null;
} }
} }
...@@ -6,6 +6,8 @@ import java.util.List; ...@@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.keymobile.indicators.model.entity.indicators.CompareUnitCalLog;
import com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -42,6 +44,7 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -42,6 +44,7 @@ public class DriveIndIdCalActor extends AbstractActor{
private IndicatorsReportService indiReportService = SpringUtil.getBean(IndicatorsReportService.class); private IndicatorsReportService indiReportService = SpringUtil.getBean(IndicatorsReportService.class);
private CompareUnitCalLogService compareUnitCalLogService = SpringUtil.getBean(CompareUnitCalLogService.class);
private int numberOfConfirm = 0;//定义返回确认消息的子actor private int numberOfConfirm = 0;//定义返回确认消息的子actor
private int compareObjSize = 0;//对标对象个数 private int compareObjSize = 0;//对标对象个数
...@@ -58,6 +61,8 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -58,6 +61,8 @@ public class DriveIndIdCalActor extends AbstractActor{
private String isTest; private String isTest;
private Integer compCalLogId;
private final ActorRef compareUnitCalActor;//定义父actor private final ActorRef compareUnitCalActor;//定义父actor
static public Props props(ActorRef compareUnitCalActor) { static public Props props(ActorRef compareUnitCalActor) {
...@@ -70,8 +75,11 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -70,8 +75,11 @@ public class DriveIndIdCalActor extends AbstractActor{
@Override @Override
public Receive createReceive() { public Receive createReceive() {
return receiveBuilder() Receive receive = null;
.match(DriveIndIdCalMsg.class,driveIndIdCalMsg -> { try {
receive= receiveBuilder()
.match(DriveIndIdCalMsg.class, driveIndIdCalMsg -> {
String compareId = driveIndIdCalMsg.getCompareId(); String compareId = driveIndIdCalMsg.getCompareId();
String indId = driveIndIdCalMsg.getIndId(); String indId = driveIndIdCalMsg.getIndId();
List<String> compareObjs = driveIndIdCalMsg.getCompareObj(); List<String> compareObjs = driveIndIdCalMsg.getCompareObj();
...@@ -83,61 +91,61 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -83,61 +91,61 @@ public class DriveIndIdCalActor extends AbstractActor{
isTest = driveIndIdCalMsg.getIsTest(); isTest = driveIndIdCalMsg.getIsTest();
//日志记录id //日志记录id
Integer compCalLogId = driveIndIdCalMsg.getCompCalLogId(); compCalLogId = driveIndIdCalMsg.getCompCalLogId();
for(String compareObj : compareObjs) { for (String compareObj : compareObjs) {
List<DimValue> dimValueList = new ArrayList<>(); List<DimValue> dimValueList = new ArrayList<>();
DimValue dimCompareObj = new DimValue("dim1",compareObj,"varchar"); DimValue dimCompareObj = new DimValue("dim1", compareObj, "varchar");
DimValue dimDateObj = new DimValue("dim2",date,"number"); DimValue dimDateObj = new DimValue("dim2", date, "number");
dimValueList.add(dimCompareObj); dimValueList.add(dimCompareObj);
dimValueList.add(dimDateObj); dimValueList.add(dimDateObj);
DriveIndIdObjCalMsg driveIndIdObjCalMsg = new DriveIndIdObjCalMsg(compareId, DriveIndIdObjCalMsg driveIndIdObjCalMsg = new DriveIndIdObjCalMsg(compareId,
indId,compareObj,date,dimValueList,compCalLogId, indId, compareObj, date, dimValueList, compCalLogId,
driveIndIdCalMsg.getCode(),driveIndIdCalMsg.getIsTest()); driveIndIdCalMsg.getCode(), driveIndIdCalMsg.getIsTest());
ActorRef driveIndIdObjCalActor = this.getContext() ActorRef driveIndIdObjCalActor = this.getContext()
.actorOf(Props.create(DriveIndIdObjCalActor.class, .actorOf(Props.create(DriveIndIdObjCalActor.class,
()->new DriveIndIdObjCalActor(getSelf()))); () -> new DriveIndIdObjCalActor(getSelf())));
driveIndIdObjCalActor.tell(driveIndIdObjCalMsg, getSelf()); driveIndIdObjCalActor.tell(driveIndIdObjCalMsg, getSelf());
} }
}) })
.match(CalIndAverageAndRankMsg.class,calIndAverageAndRankMsg -> { .match(CalIndAverageAndRankMsg.class, calIndAverageAndRankMsg -> {
String value = calIndAverageAndRankMsg.getDriveIndValue(); String value = calIndAverageAndRankMsg.getDriveIndValue();
String id = String.valueOf(calIndAverageAndRankMsg.getId()); String id = String.valueOf(calIndAverageAndRankMsg.getId());
String indType = calIndAverageAndRankMsg.getIndType();//指标类型:正向 反向 String indType = calIndAverageAndRankMsg.getIndType();//指标类型:正向 反向
Integer scoreCardId = calIndAverageAndRankMsg.getScoreCardId();//评分卡id Integer scoreCardId = calIndAverageAndRankMsg.getScoreCardId();//评分卡id
Integer compCalLogId = calIndAverageAndRankMsg.getCompCalLogId();//记录日志id Integer compCalLogId = calIndAverageAndRankMsg.getCompCalLogId();//记录日志id
if(!"-1".equals(id)) { if (!"-1".equals(id)) {
valueMap.put(id, value); valueMap.put(id, value);
compareObjs.add(calIndAverageAndRankMsg.getCompareObj()); compareObjs.add(calIndAverageAndRankMsg.getCompareObj());
} }
if (++numberOfConfirm >= compareObjSize) {//子actor全部返回 if (++numberOfConfirm >= compareObjSize) {//子actor全部返回
if(!valueMap.isEmpty() && !compareObjs.isEmpty()) { if (!valueMap.isEmpty() && !compareObjs.isEmpty()) {
//如果是先执行且没有平均分参考对象的,则不进行平均分和排名计算 //如果是先执行且没有平均分参考对象的,则不进行平均分和排名计算
if("1".equals(firstExe) && StringUtils.isBlank(averageObj)) { if ("1".equals(firstExe) && StringUtils.isBlank(averageObj)) {
//发送确认信息给父actor //发送确认信息给父actor
FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(1,"",compCalLogId); FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(1, "", compCalLogId);
compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender()); compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender());
}else { } else {
String actualAverage = "0.0";//实际平均分 String actualAverage = "0.0";//实际平均分
if(StringUtils.isNotBlank(averageObj)) { if (StringUtils.isNotBlank(averageObj)) {
if("0".equals(isTest)) { if ("0".equals(isTest)) {
TestDriveIndCalResultDef provinceDriveIndCalResult = TestDriveIndCalResultDef provinceDriveIndCalResult =
testDriveIndCalResultService.findCompareObjInfo( testDriveIndCalResultService.findCompareObjInfo(
calIndAverageAndRankMsg.getDriveIndId(), calIndAverageAndRankMsg.getDriveIndId(),
calIndAverageAndRankMsg.getDate(), calIndAverageAndRankMsg.getDate(),
averageObj,code); averageObj, code);
if(provinceDriveIndCalResult!=null) { if (provinceDriveIndCalResult != null) {
//获取实际平均分 //获取实际平均分
actualAverage = provinceDriveIndCalResult.getValue(); actualAverage = provinceDriveIndCalResult.getValue();
} }
}else { } else {
DriveIndCalResultDef provinceDriveIndCalResult = DriveIndCalResultDef provinceDriveIndCalResult =
driveIndCalResultService.findCompareObjInfo( driveIndCalResultService.findCompareObjInfo(
calIndAverageAndRankMsg.getDriveIndId(), calIndAverageAndRankMsg.getDriveIndId(),
calIndAverageAndRankMsg.getDate(), calIndAverageAndRankMsg.getDate(),
averageObj,code); averageObj, code);
if(provinceDriveIndCalResult!=null) { if (provinceDriveIndCalResult != null) {
//获取实际平均分 //获取实际平均分
actualAverage = provinceDriveIndCalResult.getValue(); actualAverage = provinceDriveIndCalResult.getValue();
} }
...@@ -146,28 +154,28 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -146,28 +154,28 @@ public class DriveIndIdCalActor extends AbstractActor{
//算组内平均数 //算组内平均数
String average = driveIndDefService.calGroupAverage( String average = driveIndDefService.calGroupAverage(
calIndAverageAndRankMsg.getIndFormula(), compareObjs, calIndAverageAndRankMsg.getIndFormula(), compareObjs,
calIndAverageAndRankMsg.getDate(),code); calIndAverageAndRankMsg.getDate(), code);
//算组内排名 //算组内排名
Map<String,Integer> rankValue = CalculateUtils.rankValue(valueMap, indType); Map<String, Integer> rankValue = CalculateUtils.rankValue(valueMap, indType);
List<DriveIndCalResultDef> dataList = new ArrayList<>(); List<DriveIndCalResultDef> dataList = new ArrayList<>();
List<TestDriveIndCalResultDef> testDataList = new ArrayList<>(); List<TestDriveIndCalResultDef> testDataList = new ArrayList<>();
//填充平均数和排名到考核结果中 //填充平均数和排名到考核结果中
for(Entry<String,Integer> entry : rankValue.entrySet()) { for (Entry<String, Integer> entry : rankValue.entrySet()) {
if("0".equals(isTest)) { if ("0".equals(isTest)) {
//根据id获取指标值结果 //根据id获取指标值结果
TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService. TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService.
findById(Integer.parseInt(entry.getKey())); findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) { if (driveIndCalResult != null) {
driveIndCalResult.setAverage(average); driveIndCalResult.setAverage(average);
driveIndCalResult.setRank(entry.getValue()); driveIndCalResult.setRank(entry.getValue());
driveIndCalResult.setActualAverage(actualAverage); driveIndCalResult.setActualAverage(actualAverage);
testDataList.add(driveIndCalResult); testDataList.add(driveIndCalResult);
} }
}else { } else {
//根据id获取指标值结果 //根据id获取指标值结果
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService. DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findById(Integer.parseInt(entry.getKey())); findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) { if (driveIndCalResult != null) {
driveIndCalResult.setAverage(average); driveIndCalResult.setAverage(average);
driveIndCalResult.setRank(entry.getValue()); driveIndCalResult.setRank(entry.getValue());
driveIndCalResult.setActualAverage(actualAverage); driveIndCalResult.setActualAverage(actualAverage);
...@@ -175,55 +183,55 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -175,55 +183,55 @@ public class DriveIndIdCalActor extends AbstractActor{
} }
} }
} }
if("0".equals(isTest)) { if ("0".equals(isTest)) {
//批量保存修改 //批量保存修改
testDriveIndCalResultService.batchSaveOrUpdate(testDataList); testDriveIndCalResultService.batchSaveOrUpdate(testDataList);
//批量保存修改 //批量保存修改
testDataList.clear(); testDataList.clear();
}else { } else {
//批量保存修改 //批量保存修改
driveIndCalResultService.batchSaveOrUpdate(dataList); driveIndCalResultService.batchSaveOrUpdate(dataList);
//批量保存修改//批量保存修改 //批量保存修改//批量保存修改
dataList.clear(); dataList.clear();
} }
//根据评分卡算指标分数 //根据评分卡算指标分数
for(Entry<String,Integer> entry : rankValue.entrySet()) { for (Entry<String, Integer> entry : rankValue.entrySet()) {
if("0".equals(isTest)) { if ("0".equals(isTest)) {
//根据id获取指标值结果 //根据id获取指标值结果
TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService. TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService.
findById(Integer.parseInt(entry.getKey())); findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) { if (driveIndCalResult != null) {
//计算分数 //计算分数
Map<String,String> scoreMap = indScorecardService.calculateIndiScore( Map<String, String> scoreMap = indScorecardService.calculateIndiScore(
driveIndCalResult.getIndId(), driveIndCalResult.getDate(), driveIndCalResult.getIndId(), driveIndCalResult.getDate(),
driveIndCalResult.getCompareObj(), scoreCardId, driveIndCalResult.getCompareObj(), scoreCardId,
driveIndCalResult.getCompareId(),compareObjs,code); driveIndCalResult.getCompareId(), compareObjs, code);
driveIndCalResult.setScore(scoreMap.get("score")); driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore")); driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
testDataList.add(driveIndCalResult); testDataList.add(driveIndCalResult);
} }
}else { } else {
//根据id获取指标值结果 //根据id获取指标值结果
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService. DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findById(Integer.parseInt(entry.getKey())); findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) { if (driveIndCalResult != null) {
//计算分数 //计算分数
Map<String,String> scoreMap = indScorecardService.calculateIndiScore( Map<String, String> scoreMap = indScorecardService.calculateIndiScore(
driveIndCalResult.getIndId(), driveIndCalResult.getDate(), driveIndCalResult.getIndId(), driveIndCalResult.getDate(),
driveIndCalResult.getCompareObj(), scoreCardId, driveIndCalResult.getCompareObj(), scoreCardId,
driveIndCalResult.getCompareId(),compareObjs,code); driveIndCalResult.getCompareId(), compareObjs, code);
driveIndCalResult.setScore(scoreMap.get("score")); driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore")); driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
dataList.add(driveIndCalResult); dataList.add(driveIndCalResult);
} }
} }
} }
if("0".equals(isTest)) { if ("0".equals(isTest)) {
//批量保存修改 //批量保存修改
testDriveIndCalResultService.batchSaveOrUpdate(testDataList); testDriveIndCalResultService.batchSaveOrUpdate(testDataList);
//清空list //清空list
testDataList.clear(); testDataList.clear();
}else { } else {
//批量保存修改 //批量保存修改
driveIndCalResultService.batchSaveOrUpdate(dataList); driveIndCalResultService.batchSaveOrUpdate(dataList);
//整合本期同期报表数据 //整合本期同期报表数据
...@@ -233,16 +241,29 @@ public class DriveIndIdCalActor extends AbstractActor{ ...@@ -233,16 +241,29 @@ public class DriveIndIdCalActor extends AbstractActor{
} }
//发送确认信息给父actor //发送确认信息给父actor
FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(1,"",compCalLogId); FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(1, "", compCalLogId);
compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender()); compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender());
} }
}else { } else {
//发送确认信息给父actor //发送确认信息给父actor
FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(0,"",compCalLogId); FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(0, "", compCalLogId);
compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender()); compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender());
} }
} }
}) })
.build(); .build();
}catch (Exception e){
e.printStackTrace();
CompareUnitCalLog compCalLog = compareUnitCalLogService.findById(compCalLogId);
if(compCalLog!=null){
compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1");
compCalLog.setStatus(0);
compCalLog.setLogInfo("运算失败");
compareUnitCalLogService.saveOrUndate(compCalLog);
}
}
return receive;
} }
} }
...@@ -33,6 +33,7 @@ import com.keymobile.indicators.utils.SpringUtil; ...@@ -33,6 +33,7 @@ import com.keymobile.indicators.utils.SpringUtil;
import akka.actor.AbstractActor; import akka.actor.AbstractActor;
import akka.actor.ActorRef; import akka.actor.ActorRef;
import akka.actor.Props; import akka.actor.Props;
import org.springframework.data.redis.core.script.ReactiveScriptExecutor;
public class DriveIndIdObjCalActor extends AbstractActor{ public class DriveIndIdObjCalActor extends AbstractActor{
private Logger logger = LoggerFactory.getLogger(DriveIndIdObjCalActor.class); private Logger logger = LoggerFactory.getLogger(DriveIndIdObjCalActor.class);
...@@ -90,7 +91,9 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -90,7 +91,9 @@ public class DriveIndIdObjCalActor extends AbstractActor{
@Override @Override
public Receive createReceive() { public Receive createReceive() {
return receiveBuilder() Receive receive = null;
try {
receive = receiveBuilder()
.match(DriveIndIdObjCalMsg.class, driveIndIdObjCalMsg -> { .match(DriveIndIdObjCalMsg.class, driveIndIdObjCalMsg -> {
compareId = driveIndIdObjCalMsg.getCompareId(); compareId = driveIndIdObjCalMsg.getCompareId();
compareObj = driveIndIdObjCalMsg.getCompareObj(); compareObj = driveIndIdObjCalMsg.getCompareObj();
...@@ -104,15 +107,15 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -104,15 +107,15 @@ public class DriveIndIdObjCalActor extends AbstractActor{
List<String> indIdList = new ArrayList<>();//定义存储从考核指标公式解析出来的基础指标id List<String> indIdList = new ArrayList<>();//定义存储从考核指标公式解析出来的基础指标id
DriveIndDef driveIndDef = driveIndDefService.getById(driveIndId); DriveIndDef driveIndDef = driveIndDefService.getById(driveIndId);
if(driveIndDef==null) { if (driveIndDef == null) {
logger.info("DriveIndDef:"+driveIndId+" is not exist."); logger.info("DriveIndDef:" + driveIndId + " is not exist.");
//返回父actor信息 //返回父actor信息
CalIndAverageAndRankMsg driveIndAverageAndRankMsg = CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(-1, new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN", compareId, driveIndId, compareObj, date, "NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId); unit, indType, scoreCardId, averageDriveIndFormula, compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender()); driveIndIdCalActor.tell(driveIndAverageAndRankMsg, ActorRef.noSender());
}else { } else {
unit = driveIndDef.getIndUnit();//指标单位 unit = driveIndDef.getIndUnit();//指标单位
indType = driveIndDef.getIndRule();//指标类型:正向 反向 indType = driveIndDef.getIndRule();//指标类型:正向 反向
scoreCardId = driveIndDef.getIndCalScoreRule();//指标评分规则 scoreCardId = driveIndDef.getIndCalScoreRule();//指标评分规则
...@@ -123,34 +126,37 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -123,34 +126,37 @@ public class DriveIndIdObjCalActor extends AbstractActor{
Pattern p = Pattern.compile("(\\[[^\\]]*\\])"); Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
Matcher m = p.matcher(driveIndFormula); Matcher m = p.matcher(driveIndFormula);
while(m.find()){ while (m.find()) {
indIdList.add(m.group().substring(1, m.group().length()-1)); indIdList.add(m.group().substring(1, m.group().length() - 1));
} }
//获取公式中的基础指标id //获取公式中的基础指标id
indIdSize =indIdList.size(); indIdSize = indIdList.size();
if(!indIdList.isEmpty()) { if (!indIdList.isEmpty()) {
for(String indId : indIdList) { for (String indId : indIdList) {
GetBaseIndValueMsg getBaseIndValueMsg = new GetBaseIndValueMsg( GetBaseIndValueMsg getBaseIndValueMsg = new GetBaseIndValueMsg(
indId,driveIndIdObjCalMsg.getDimValues(), indId, driveIndIdObjCalMsg.getDimValues(),
driveIndIdObjCalMsg.getCode()); driveIndIdObjCalMsg.getCode());
//传入日志id
getBaseIndValueMsg.setCompCalLogId(compCalLogId);
ActorRef getBaseIndValueActor = this.getContext() ActorRef getBaseIndValueActor = this.getContext()
.actorOf(Props.create(GetBaseIndValueActor.class, .actorOf(Props.create(GetBaseIndValueActor.class,
()->new GetBaseIndValueActor())); () -> new GetBaseIndValueActor()));
getBaseIndValueActor.tell(getBaseIndValueMsg, getSelf()); getBaseIndValueActor.tell(getBaseIndValueMsg, getSelf());
} }
} }
} }
}) })
.match(BaseIndValueMsg.class,baseIndValueMsg->{ .match(BaseIndValueMsg.class, baseIndValueMsg -> {
//根据日志记录id获取日志 //根据日志记录id获取日志
CompareUnitCalLog compCalLog = null; CompareUnitCalLog compCalLog = null;
if(compCalLogId!=null) { if (compCalLogId != null) {
compCalLog = compareUnitCalLogService.findById(compCalLogId); compCalLog = compareUnitCalLogService.findById(compCalLogId);
} }
if(baseIndValueMsg.getIsFinish()==0) { if (baseIndValueMsg.getIsFinish() == 0) {
//日志填充 //日志填充
if(compCalLog!=null) { if (compCalLog != null) {
// String logInfo = compCalLog.getLogInfo(); // String logInfo = compCalLog.getLogInfo();
// compCalLog.setStatus(0); // compCalLog.setStatus(0);
// if(StringUtils.isNotBlank(logInfo)) { // if(StringUtils.isNotBlank(logInfo)) {
...@@ -159,31 +165,32 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -159,31 +165,32 @@ public class DriveIndIdObjCalActor extends AbstractActor{
// }else { // }else {
// compCalLog.setLogInfo(baseIndValueMsg.getConfirmMessage()+"</n>"); // compCalLog.setLogInfo(baseIndValueMsg.getConfirmMessage()+"</n>");
// } // }
compCalLog.setLogInfo("运算失败:指标为空"); compCalLog.setStatus(0);
compCalLog.setLogInfo("运算过程:有指标为空");
} }
logger.info("日志信息::{},日志id{}",baseIndValueMsg.getConfirmMessage(),compCalLogId); logger.info("日志信息::{},日志id{}", baseIndValueMsg.getConfirmMessage(), compCalLogId);
} }
String indValue = baseIndValueMsg.getValue(); String indValue = baseIndValueMsg.getValue();
//如果指标值返回空值 //如果指标值返回空值
if(StringUtils.isBlank(indValue)) { if (StringUtils.isBlank(indValue)) {
indValue="0.00"; indValue = "0.00";
} }
try { try {
if(indValue.indexOf(".")<0) { if (indValue.indexOf(".") < 0) {
indValue += ".00"; indValue += ".00";
} }
driveIndFormula = driveIndFormula.replace("["+baseIndValueMsg.getIndId()+"]", driveIndFormula = driveIndFormula.replace("[" + baseIndValueMsg.getIndId() + "]",
indValue); indValue);
//替换公式中的基础指标id为确定指标值 //替换公式中的基础指标id为确定指标值
//env.put(baseIndValueMsg.getIndId(), Double.valueOf(indValue)); //env.put(baseIndValueMsg.getIndId(), Double.valueOf(indValue));
}catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
logger.error("driveIndId:"+driveIndId+";"+ logger.error("driveIndId:" + driveIndId + ";" +
"formula:"+driveIndFormula+";"+ "formula:" + driveIndFormula + ";" +
"errorValue:"+indValue+";"+"paramEnv:"+env); "errorValue:" + indValue + ";" + "paramEnv:" + env);
//日志记录 //日志记录
//运算失败 //运算失败
if(compCalLog!=null){ if (compCalLog != null) {
compCalLog.setStatus(0); compCalLog.setStatus(0);
//String logInfo = compCalLog.getLogInfo(); //String logInfo = compCalLog.getLogInfo();
// if(StringUtils.isNotBlank(logInfo)) { // if(StringUtils.isNotBlank(logInfo)) {
...@@ -205,24 +212,24 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -205,24 +212,24 @@ public class DriveIndIdObjCalActor extends AbstractActor{
} }
confirmList.add(baseIndValueMsg.getIsFinish()); confirmList.add(baseIndValueMsg.getIsFinish());
if (++numberOfConfirm >= indIdSize) {//子actor全部返回 if (++numberOfConfirm >= indIdSize) {//子actor全部返回
if(!confirmList.contains(0)) {//取所有基础指标值没错 if (!confirmList.contains(0)) {//取所有基础指标值没错
//进行考核指标值计算 //进行考核指标值计算
try { try {
String driveIndValue = AviatorEvaluator.execute(driveIndFormula).toString(); String driveIndValue = AviatorEvaluator.execute(driveIndFormula).toString();
//保留四位小数 //保留四位小数
if(!driveIndValue.equals("NaN") && !driveIndValue.equals("Infinite")) { if (!driveIndValue.equals("NaN") && !driveIndValue.equals("Infinite")) {
driveIndValue = String.format("%.4f", driveIndValue = String.format("%.4f",
new BigDecimal(Double.valueOf(driveIndValue))); new BigDecimal(Double.valueOf(driveIndValue)));
} }
if("0".equals(isTest)) {//试运行 if ("0".equals(isTest)) {//试运行
//判断结果表中是否已存在该结果数据,存在则覆盖 //判断结果表中是否已存在该结果数据,存在则覆盖
TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService. TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code); findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code);
if(driveIndCalResult==null) { if (driveIndCalResult == null) {
driveIndCalResult = new TestDriveIndCalResultDef(compareId, driveIndCalResult = new TestDriveIndCalResultDef(compareId,
driveIndId,compareObj,date,driveIndValue,unit, driveIndId, compareObj, date, driveIndValue, unit,
"1","1","admin",code,baseIndValueMsg.getCompareObjDesc()); "1", "1", "admin", code, baseIndValueMsg.getCompareObjDesc());
}else { } else {
driveIndCalResult.setCode(code); driveIndCalResult.setCode(code);
driveIndCalResult.setUnit(unit); driveIndCalResult.setUnit(unit);
driveIndCalResult.setValue(driveIndValue); driveIndCalResult.setValue(driveIndValue);
...@@ -233,18 +240,18 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -233,18 +240,18 @@ public class DriveIndIdObjCalActor extends AbstractActor{
//返回指标值回去算平均值和排名 //返回指标值回去算平均值和排名
CalIndAverageAndRankMsg driveIndAverageAndRankMsg = CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(driveIndCalResult.getId(), new CalIndAverageAndRankMsg(driveIndCalResult.getId(),
compareId,driveIndId,compareObj,date,driveIndValue, compareId, driveIndId, compareObj, date, driveIndValue,
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId); unit, indType, scoreCardId, averageDriveIndFormula, compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender()); driveIndIdCalActor.tell(driveIndAverageAndRankMsg, ActorRef.noSender());
}else { } else {
//判断结果表中是否已存在该结果数据,存在则覆盖 //判断结果表中是否已存在该结果数据,存在则覆盖
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService. DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code); findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code);
if(driveIndCalResult==null) { if (driveIndCalResult == null) {
driveIndCalResult = new DriveIndCalResultDef(compareId, driveIndCalResult = new DriveIndCalResultDef(compareId,
driveIndId,compareObj,date,driveIndValue,unit, driveIndId, compareObj, date, driveIndValue, unit,
"1","1","admin",code,baseIndValueMsg.getCompareObjDesc()); "1", "1", "admin", code, baseIndValueMsg.getCompareObjDesc());
}else { } else {
driveIndCalResult.setCode(code); driveIndCalResult.setCode(code);
driveIndCalResult.setUnit(unit); driveIndCalResult.setUnit(unit);
driveIndCalResult.setValue(driveIndValue); driveIndCalResult.setValue(driveIndValue);
...@@ -255,9 +262,9 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -255,9 +262,9 @@ public class DriveIndIdObjCalActor extends AbstractActor{
//返回指标值回去算平均值和排名 //返回指标值回去算平均值和排名
CalIndAverageAndRankMsg driveIndAverageAndRankMsg = CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(driveIndCalResult.getId(), new CalIndAverageAndRankMsg(driveIndCalResult.getId(),
compareId,driveIndId,compareObj,date,driveIndValue, compareId, driveIndId, compareObj, date, driveIndValue,
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId); unit, indType, scoreCardId, averageDriveIndFormula, compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender()); driveIndIdCalActor.tell(driveIndAverageAndRankMsg, ActorRef.noSender());
} }
} catch (Exception e) { } catch (Exception e) {
//判断结果表中是否已存在该结果数据,存在则覆盖 //判断结果表中是否已存在该结果数据,存在则覆盖
...@@ -275,8 +282,8 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -275,8 +282,8 @@ public class DriveIndIdObjCalActor extends AbstractActor{
// } // }
// driveIndCalResultService.saveOrUpdate(driveIndCalResult); // driveIndCalResultService.saveOrUpdate(driveIndCalResult);
logger.error("driveIndId:"+driveIndId+";"+ logger.error("driveIndId:" + driveIndId + ";" +
"paramEnv:"+env+";formula:"+driveIndFormula); "paramEnv:" + env + ";formula:" + driveIndFormula);
//日志记录 //日志记录
// String logInfo = compCalLog.getLogInfo(); // String logInfo = compCalLog.getLogInfo();
// if(StringUtils.isNotBlank(logInfo)) { // if(StringUtils.isNotBlank(logInfo)) {
...@@ -289,7 +296,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -289,7 +296,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{
// } // }
//保存日志 //保存日志
if(compCalLog!=null) { if (compCalLog != null) {
compCalLog.setLogInfo("计算考核指标出错"); compCalLog.setLogInfo("计算考核指标出错");
compCalLog.setStatus(0); compCalLog.setStatus(0);
compareUnitCalLogService.saveOrUndate(compCalLog); compareUnitCalLogService.saveOrUndate(compCalLog);
...@@ -297,24 +304,36 @@ public class DriveIndIdObjCalActor extends AbstractActor{ ...@@ -297,24 +304,36 @@ public class DriveIndIdObjCalActor extends AbstractActor{
//表示计算错误,不生成考核结果 //表示计算错误,不生成考核结果
CalIndAverageAndRankMsg driveIndAverageAndRankMsg = CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(-1, new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN", compareId, driveIndId, compareObj, date, "NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId); unit, indType, scoreCardId, averageDriveIndFormula, compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender()); driveIndIdCalActor.tell(driveIndAverageAndRankMsg, ActorRef.noSender());
} }
}else { } else {
//返回考核指标因为考核指标公式中的数据项不存在而导致的计算错误标识 //返回考核指标因为考核指标公式中的数据项不存在而导致的计算错误标识
//保存日志 //保存日志
if(compCalLog!=null) { if (compCalLog != null) {
compareUnitCalLogService.saveOrUndate(compCalLog); compareUnitCalLogService.saveOrUndate(compCalLog);
} }
CalIndAverageAndRankMsg driveIndAverageAndRankMsg = CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(-1, new CalIndAverageAndRankMsg(-1,
compareId,driveIndId,compareObj,date,"NaN", compareId, driveIndId, compareObj, date, "NaN",
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId); unit, indType, scoreCardId, averageDriveIndFormula, compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender()); driveIndIdCalActor.tell(driveIndAverageAndRankMsg, ActorRef.noSender());
} }
} }
}) })
.build(); .build();
}catch (Exception e){
e.printStackTrace();
CompareUnitCalLog compCalLog = compareUnitCalLogService.findById(compCalLogId);
if(compCalLog!=null){
compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1");
compCalLog.setStatus(0);
compCalLog.setLogInfo("运算失败");
compareUnitCalLogService.saveOrUndate(compCalLog);
}
}
return receive;
} }
} }
...@@ -4,6 +4,8 @@ import java.util.Map; ...@@ -4,6 +4,8 @@ import java.util.Map;
import com.keymobile.indicators.akka.message.indicators.BaseIndValueMsg; import com.keymobile.indicators.akka.message.indicators.BaseIndValueMsg;
import com.keymobile.indicators.akka.message.indicators.GetBaseIndValueMsg; import com.keymobile.indicators.akka.message.indicators.GetBaseIndValueMsg;
import com.keymobile.indicators.model.entity.indicators.CompareUnitCalLog;
import com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService;
import com.keymobile.indicators.service.hytobacco.IndicatorsValueService; import com.keymobile.indicators.service.hytobacco.IndicatorsValueService;
import com.keymobile.indicators.utils.SpringUtil; import com.keymobile.indicators.utils.SpringUtil;
...@@ -13,37 +15,60 @@ public class GetBaseIndValueActor extends AbstractActor{ ...@@ -13,37 +15,60 @@ public class GetBaseIndValueActor extends AbstractActor{
private IndicatorsValueService indicatorsValueService = SpringUtil.getBean(IndicatorsValueService.class); private IndicatorsValueService indicatorsValueService = SpringUtil.getBean(IndicatorsValueService.class);
private CompareUnitCalLogService compareUnitCalLogService = SpringUtil.getBean(CompareUnitCalLogService.class);
private Integer compCalLogId = null;
@Override @Override
public Receive createReceive() { public Receive createReceive() {
return receiveBuilder()
.match(GetBaseIndValueMsg.class,getBaseIndValueMsg -> { Receive receive = null;
try {
receive= receiveBuilder()
.match(GetBaseIndValueMsg.class, getBaseIndValueMsg -> {
//根据维度值和基础指标id获取指标值 //根据维度值和基础指标id获取指标值
Map<String,Object> indValueMap = indicatorsValueService.getIndicatorsValue( compCalLogId = getBaseIndValueMsg.getCompCalLogId();
Map<String, Object> indValueMap = indicatorsValueService.getIndicatorsValue(
getBaseIndValueMsg.getIndId(), getBaseIndValueMsg.getDimValue(), getBaseIndValueMsg.getIndId(), getBaseIndValueMsg.getDimValue(),
getBaseIndValueMsg.getCode()); getBaseIndValueMsg.getCode());
if(indValueMap!=null) { if (indValueMap != null) {
if(indValueMap.get("value")==null) {//如果指标值为空,返回失败结果 if (indValueMap.get("value") == null) {//如果指标值为空,返回失败结果
//返回指标值结果 //返回指标值结果
getSender().tell(new BaseIndValueMsg(getBaseIndValueMsg.getIndId() getSender().tell(new BaseIndValueMsg(getBaseIndValueMsg.getIndId()
,null,indValueMap.get("compareObjDesc").toString(),0, , null, indValueMap.get("compareObjDesc").toString(), 0,
"获取指标id:"+ "获取指标id:" +
getBaseIndValueMsg.getIndId()+";维度:"+ getBaseIndValueMsg.getIndId() + ";维度:" +
getBaseIndValueMsg.getDimValue().get(0).getDimvalue()+","+ getBaseIndValueMsg.getDimValue().get(0).getDimvalue() + "," +
getBaseIndValueMsg.getDimValue().get(1).getDimvalue()+" 的指标值为空;"),getSelf()); getBaseIndValueMsg.getDimValue().get(1).getDimvalue() + " 的指标值为空;"), getSelf());
}else { } else {
getSender().tell(new BaseIndValueMsg(getBaseIndValueMsg.getIndId() getSender().tell(new BaseIndValueMsg(getBaseIndValueMsg.getIndId()
,indValueMap.get("value").toString(), , indValueMap.get("value").toString(),
indValueMap.get("compareObjDesc").toString(),1,""),getSelf()); indValueMap.get("compareObjDesc").toString(), 1, ""), getSelf());
} }
}else { } else {
//返回指标值结果 //返回指标值结果
getSender().tell(new BaseIndValueMsg(getBaseIndValueMsg.getIndId(),null,null, getSender().tell(new BaseIndValueMsg(getBaseIndValueMsg.getIndId(), null, null,
0,"无法获取指标id:"+ 0, "无法获取指标id:" +
getBaseIndValueMsg.getIndId()+";维度:"+ getBaseIndValueMsg.getIndId() + ";维度:" +
getBaseIndValueMsg.getDimValue().get(0).getDimvalue()+","+ getBaseIndValueMsg.getDimValue().get(0).getDimvalue() + "," +
getBaseIndValueMsg.getDimValue().get(1).getDimvalue()+" 的指标值;"),getSelf()); getBaseIndValueMsg.getDimValue().get(1).getDimvalue() + " 的指标值;"), getSelf());
} }
}) })
.build(); .build();
}catch (Exception e){
e.printStackTrace();
CompareUnitCalLog compCalLog = compareUnitCalLogService.findById(compCalLogId);
if(compCalLog!=null){
compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1");
compCalLog.setStatus(0);
compCalLog.setLogInfo("运算失败");
compareUnitCalLogService.saveOrUndate(compCalLog);
}
}
return receive;
} }
} }
...@@ -63,8 +63,10 @@ public class StartCompareUnitCalActor extends AbstractActor{ ...@@ -63,8 +63,10 @@ public class StartCompareUnitCalActor extends AbstractActor{
@Override @Override
public Receive createReceive() { public Receive createReceive() {
return receiveBuilder() Receive receive = null;
.match(StartCompareUnitCalMsg.class,startCompareUnitCalMsg -> { try {
receive = receiveBuilder()
.match(StartCompareUnitCalMsg.class, startCompareUnitCalMsg -> {
code = startCompareUnitCalMsg.getCode(); code = startCompareUnitCalMsg.getCode();
isTest = startCompareUnitCalMsg.getIsTest(); isTest = startCompareUnitCalMsg.getIsTest();
String user = startCompareUnitCalMsg.getUser(); String user = startCompareUnitCalMsg.getUser();
...@@ -73,14 +75,14 @@ public class StartCompareUnitCalActor extends AbstractActor{ ...@@ -73,14 +75,14 @@ public class StartCompareUnitCalActor extends AbstractActor{
//将对标单元进行分类,需要先执行的先开始进行对标计算 //将对标单元进行分类,需要先执行的先开始进行对标计算
for(CompareUnitDef unitDef : compareUnitDefs) { for (CompareUnitDef unitDef : compareUnitDefs) {
if("1".equals(unitDef.getFirstExe())) { if ("1".equals(unitDef.getFirstExe())) {
firstExeList.add(unitDef); firstExeList.add(unitDef);
}else { } else {
afterExeList.add(unitDef); afterExeList.add(unitDef);
} }
//单位评分规则不为空的对标单元加到calTypeExeList中 //单位评分规则不为空的对标单元加到calTypeExeList中
if(unitDef.getObjScoreRuleId()!=null) { if (unitDef.getObjScoreRuleId() != null) {
//ScoreRule scoreRule = scoreRuleServer.getById(unitDef.getObjScoreRuleId()); //ScoreRule scoreRule = scoreRuleServer.getById(unitDef.getObjScoreRuleId());
//if(scoreRule!=null) { //if(scoreRule!=null) {
//if(scoreRule.getCalType()!=null && !"0".equals(scoreRule.getCalType())) { //if(scoreRule.getCalType()!=null && !"0".equals(scoreRule.getCalType())) {
...@@ -91,8 +93,8 @@ public class StartCompareUnitCalActor extends AbstractActor{ ...@@ -91,8 +93,8 @@ public class StartCompareUnitCalActor extends AbstractActor{
} }
firstExeUnitSize = firstExeList.size(); firstExeUnitSize = firstExeList.size();
afterExeUnitSize = afterExeList.size(); afterExeUnitSize = afterExeList.size();
if(!firstExeList.isEmpty()) { if (!firstExeList.isEmpty()) {
for(CompareUnitDef unitDef : firstExeList) { for (CompareUnitDef unitDef : firstExeList) {
CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef, CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef,
startCompareUnitCalMsg.getCode(), startCompareUnitCalMsg.getCode(),
startCompareUnitCalMsg.getIsTest()); startCompareUnitCalMsg.getIsTest());
...@@ -102,28 +104,28 @@ public class StartCompareUnitCalActor extends AbstractActor{ ...@@ -102,28 +104,28 @@ public class StartCompareUnitCalActor extends AbstractActor{
ActorRef compareUnitCalActor = this.getContext() ActorRef compareUnitCalActor = this.getContext()
.actorOf(Props.create(CompareUnitCalActor.class, .actorOf(Props.create(CompareUnitCalActor.class,
()->new CompareUnitCalActor(getSelf()))); () -> new CompareUnitCalActor(getSelf())));
compareUnitCalActor.tell(compareUnitCalMsg, getSelf()); compareUnitCalActor.tell(compareUnitCalMsg, getSelf());
} }
}else { } else {
if(!afterExeList.isEmpty()) { if (!afterExeList.isEmpty()) {
for(CompareUnitDef unitDef : afterExeList) { for (CompareUnitDef unitDef : afterExeList) {
CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef, CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef,
startCompareUnitCalMsg.getCode(), startCompareUnitCalMsg.getCode(),
startCompareUnitCalMsg.getIsTest()); startCompareUnitCalMsg.getIsTest());
compareUnitCalMsg.setCompCalLogId(compCalLogId); compareUnitCalMsg.setCompCalLogId(compCalLogId);
ActorRef compareUnitCalActor = this.getContext() ActorRef compareUnitCalActor = this.getContext()
.actorOf(Props.create(CompareUnitCalActor.class, .actorOf(Props.create(CompareUnitCalActor.class,
()->new CompareUnitCalActor(getSelf()))); () -> new CompareUnitCalActor(getSelf())));
compareUnitCalActor.tell(compareUnitCalMsg, getSelf()); compareUnitCalActor.tell(compareUnitCalMsg, getSelf());
} }
}else { } else {
//发送确认消息给父actor //发送确认消息给父actor
CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1,""); CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1, "");
beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender()); beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender());
if("0".equals(isTest)) { if ("0".equals(isTest)) {
logger.info("对标单元试运行计算完成"); logger.info("对标单元试运行计算完成");
}else { } else {
logger.info("对标单元计算完成"); logger.info("对标单元计算完成");
} }
} }
...@@ -132,49 +134,49 @@ public class StartCompareUnitCalActor extends AbstractActor{ ...@@ -132,49 +134,49 @@ public class StartCompareUnitCalActor extends AbstractActor{
.match(FirstExeConfirmMsg.class, firstExeConfirmMsg -> { .match(FirstExeConfirmMsg.class, firstExeConfirmMsg -> {
if (++numberOfConfirm >= firstExeUnitSize) {//全部先执行的子actor全部返回 if (++numberOfConfirm >= firstExeUnitSize) {//全部先执行的子actor全部返回
//再执行后执行的actor //再执行后执行的actor
if(!afterExeList.isEmpty()) { if (!afterExeList.isEmpty()) {
for(CompareUnitDef unitDef : afterExeList) { for (CompareUnitDef unitDef : afterExeList) {
CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef, CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef,
code,isTest); code, isTest);
compareUnitCalMsg.setCompCalLogId(compCalLogId); compareUnitCalMsg.setCompCalLogId(compCalLogId);
ActorRef compareUnitCalActor = this.getContext() ActorRef compareUnitCalActor = this.getContext()
.actorOf(Props.create(CompareUnitCalActor.class, .actorOf(Props.create(CompareUnitCalActor.class,
()->new CompareUnitCalActor(getSelf()))); () -> new CompareUnitCalActor(getSelf())));
compareUnitCalActor.tell(compareUnitCalMsg, getSelf()); compareUnitCalActor.tell(compareUnitCalMsg, getSelf());
} }
if("0".equals(isTest)) { if ("0".equals(isTest)) {
logger.info("进行后执行对标单元试运行计算...."); logger.info("进行后执行对标单元试运行计算....");
}else { } else {
logger.info("进行后执行对标单元计算...."); logger.info("进行后执行对标单元计算....");
} }
}else { } else {
if(!calTypeExeList.isEmpty()) { if (!calTypeExeList.isEmpty()) {
if("0".equals(isTest)) { if ("0".equals(isTest)) {
logger.info("计算试运行对标单元单位评分......"); logger.info("计算试运行对标单元单位评分......");
}else { } else {
logger.info("计算对标单元单位评分......"); logger.info("计算对标单元单位评分......");
} }
for(CompareUnitDef unitDef : calTypeExeList) { for (CompareUnitDef unitDef : calTypeExeList) {
//试运行 //试运行
if("0".equals(isTest)) { if ("0".equals(isTest)) {
testScoreRuleServer.testCalObjScore(unitDef.getCompareId(), testScoreRuleServer.testCalObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")), Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code); unitDef.getDate(), unitDef.getObjScoreRuleId(), code);
}else { } else {
scoreRuleServer.calObjScore(unitDef.getCompareId(), scoreRuleServer.calObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")), Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code); unitDef.getDate(), unitDef.getObjScoreRuleId(), code);
} }
} }
} }
//发送确认消息给父actor //发送确认消息给父actor
CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1,""); CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1, "");
beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender()); beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender());
if("0".equals(isTest)) { if ("0".equals(isTest)) {
logger.info("对标单元试运行计算完成"); logger.info("对标单元试运行计算完成");
}else { } else {
logger.info("对标单元计算完成"); logger.info("对标单元计算完成");
} }
} }
...@@ -182,37 +184,50 @@ public class StartCompareUnitCalActor extends AbstractActor{ ...@@ -182,37 +184,50 @@ public class StartCompareUnitCalActor extends AbstractActor{
}) })
.match(AfterExeConfirmMsg.class, afterExeConfirmMsg -> { .match(AfterExeConfirmMsg.class, afterExeConfirmMsg -> {
if (++numberOfAfterConfirm >= afterExeUnitSize) {//全部后执行的子actor全部返回 if (++numberOfAfterConfirm >= afterExeUnitSize) {//全部后执行的子actor全部返回
if(!calTypeExeList.isEmpty()) { if (!calTypeExeList.isEmpty()) {
if("0".equals(isTest)) { if ("0".equals(isTest)) {
logger.info("计算试运行对标单元单位评分......"); logger.info("计算试运行对标单元单位评分......");
}else { } else {
logger.info("计算对标单元单位评分......"); logger.info("计算对标单元单位评分......");
} }
for(CompareUnitDef unitDef : calTypeExeList) { for (CompareUnitDef unitDef : calTypeExeList) {
//试运行 //试运行
if("0".equals(isTest)) { if ("0".equals(isTest)) {
testScoreRuleServer.testCalObjScore(unitDef.getCompareId(), testScoreRuleServer.testCalObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")), Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code); unitDef.getDate(), unitDef.getObjScoreRuleId(), code);
}else { } else {
scoreRuleServer.calObjScore(unitDef.getCompareId(), scoreRuleServer.calObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")), Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code); unitDef.getDate(), unitDef.getObjScoreRuleId(), code);
} }
} }
} }
//发送确认消息给父actor //发送确认消息给父actor
CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1,""); CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1, "");
beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender()); beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender());
if("0".equals(isTest)) { if ("0".equals(isTest)) {
logger.info("对标单元试运行计算完成"); logger.info("对标单元试运行计算完成");
}else { } else {
logger.info("对标单元计算完成"); logger.info("对标单元计算完成");
} }
} }
}) })
.build(); .build();
}catch (Exception e){
e.printStackTrace();
CompareUnitCalLog compCalLog = compareUnitCalLogService.findById(compCalLogId);
if(compCalLog!=null){
compCalLog.setEndTime(System.currentTimeMillis()+"");
compCalLog.setRunStatus("1");
compCalLog.setStatus(0);
compCalLog.setLogInfo("运算失败");
compareUnitCalLogService.saveOrUndate(compCalLog);
}
}
return receive;
} }
} }
...@@ -18,12 +18,22 @@ public class GetBaseIndValueMsg implements Serializable{ ...@@ -18,12 +18,22 @@ public class GetBaseIndValueMsg implements Serializable{
private String code; private String code;
private Integer compCalLogId;
public GetBaseIndValueMsg(String indId,List<DimValue> dimValue,String code) { public GetBaseIndValueMsg(String indId,List<DimValue> dimValue,String code) {
this.indId = indId; this.indId = indId;
this.dimValue.addAll(dimValue); this.dimValue.addAll(dimValue);
this.code = code; this.code = code;
} }
public Integer getCompCalLogId() {
return compCalLogId;
}
public void setCompCalLogId(Integer compCalLogId) {
this.compCalLogId = compCalLogId;
}
public List<DimValue> getDimValue() { public List<DimValue> getDimValue() {
return dimValue; return dimValue;
} }
......
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