Commit 084d81a1 by zhangkb

添加对标运算试运算功能代码

parent b4dcd4d2
......@@ -39,6 +39,8 @@ public class BeforeCompareUnitCalActor extends AbstractActor{
private String code = null;
private String isTest = null;//试运行,0:试运行 1:正式运行
@Override
public Receive createReceive() {
return receiveBuilder()
......@@ -47,10 +49,17 @@ public class BeforeCompareUnitCalActor extends AbstractActor{
sameCompareUnitDef.addAll(compareUnitDefs);
sameDate = compareUnitDefs.get(0).getDate();
code = beforeCompareUnitCalMsg.getCode();
logger.info("进行date:"+sameDate+" 的对标单元计算.....");
isTest = beforeCompareUnitCalMsg.getIsTest();
if("0".equals(isTest)) {
logger.info("进行date:"+sameDate+" 的对标单元试运行计算.....");
}else {
logger.info("进行date:"+sameDate+" 的对标单元计算.....");
}
//计算同期对标单元
StartCompareUnitCalMsg startCompareUnitCalMsg = new StartCompareUnitCalMsg(
compareUnitDefs,beforeCompareUnitCalMsg.getCode());
compareUnitDefs,beforeCompareUnitCalMsg.getCode(),
beforeCompareUnitCalMsg.getIsTest());
ActorRef startCompareUnitCalActor = this.getContext().actorOf(Props.create(
StartCompareUnitCalActor.class,()-> new StartCompareUnitCalActor(getSelf())));
startCompareUnitCalActor.tell(startCompareUnitCalMsg, getSelf());
......@@ -66,61 +75,71 @@ public class BeforeCompareUnitCalActor extends AbstractActor{
}
if(!currentCompareUnitDef.isEmpty()) {
currentDate = currentCompareUnitDef.get(0).getDate();
logger.info("进行date:"+currentDate+" 的对标单元计算.....");
if("0".equals(isTest)) {
logger.info("进行date:"+currentDate+" 的对标单元试运行计算.....");
}else {
logger.info("进行date:"+currentDate+" 的对标单元计算.....");
}
//计算同期对标单元
StartCompareUnitCalMsg startCompareUnitCalMsg = new StartCompareUnitCalMsg(
currentCompareUnitDef,code);
currentCompareUnitDef,code,isTest);
ActorRef startCompareUnitCalActor = this.getContext().actorOf(Props.create(
StartCompareUnitCalActor.class,()-> new StartCompareUnitCalActor(getSelf())));
startCompareUnitCalActor.tell(startCompareUnitCalMsg, getSelf());
}
}
if(numberOfConfirm>1) {
Map<String,String> compareObjMap = new HashMap<>();
logger.info("进行date:"+currentDate+" 指标本期同期报表数据和考核指标报表数据2数据整合");
//整合考核指标报表数据2
for(CompareUnitDef unitDef : currentCompareUnitDef) {
if(StringUtils.isNotBlank(unitDef.getIndIds()) &&
StringUtils.isNotBlank(unitDef.getCompareObjs())) {
//用map整合对标机构
List<String> compareObjsList =Arrays
.asList(unitDef.getCompareObjs().split(","));
for(String compareObj : compareObjsList) {
compareObjMap.put(compareObj, compareObj);
if("1".equals(isTest)) {//正式对标单元运算才进行报表数据生成
Map<String,String> compareObjMap = new HashMap<>();
logger.info("进行date:"+currentDate+" 指标本期同期报表数据和考核指标报表数据2数据整合");
//整合考核指标报表数据2
for(CompareUnitDef unitDef : currentCompareUnitDef) {
if(StringUtils.isNotBlank(unitDef.getIndIds()) &&
StringUtils.isNotBlank(unitDef.getCompareObjs())) {
//用map整合对标机构
List<String> compareObjsList =Arrays
.asList(unitDef.getCompareObjs().split(","));
for(String compareObj : compareObjsList) {
compareObjMap.put(compareObj, compareObj);
}
//整合指标本期同期报表数据
indicatorsReportService.dealReportOne(
unitDef.getCompareId(), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), code);
//整合考核指标报表数据2
indicatorsReportService.dealDriveIndReportTwoData(
unitDef.getCompareId(), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")), unitDef.getDate(),code);
}
//整合指标本期同期报表数据
indicatorsReportService.dealReportOne(
unitDef.getCompareId(), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), code);
//整合考核指标报表数据2
indicatorsReportService.dealDriveIndReportTwoData(
unitDef.getCompareId(), Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")), unitDef.getDate(),code);
}
//整合基础项本期同期报表数据
logger.info("进行date:"+currentDate+" 基础项本期同期报表数据整合");
if(!compareObjMap.isEmpty()) {
List<String> compareObjs = new ArrayList<String>(compareObjMap.keySet());
indicatorsReportService.dealBaseIndReportOneData(currentDate, compareObjs, code);
}
//整合考核指标报表数据3
logger.info("进行date:"+currentDate+" 指标报表3数据整合");
//删除历史数据
indicatorsReportService.deleteReportThreeDataByParam(currentDate,
new ArrayList<String>(compareObjMap.keySet()),code);
for(CompareUnitDef unitDef : currentCompareUnitDef) {
indicatorsReportService.dealDriveIndReportThreeData(
unitDef.getCompareId(), Arrays.asList(unitDef.getIndIds().split(",")),
unitDef.getDate(),code);
}
}
//整合基础项本期同期报表数据
logger.info("进行date:"+currentDate+" 基础项本期同期报表数据整合");
if(!compareObjMap.isEmpty()) {
List<String> compareObjs = new ArrayList<String>(compareObjMap.keySet());
indicatorsReportService.dealBaseIndReportOneData(currentDate, compareObjs, code);
}
//整合考核指标报表数据3
logger.info("进行date:"+currentDate+" 指标报表3数据整合");
//删除历史数据
indicatorsReportService.deleteReportThreeDataByParam(currentDate,
new ArrayList<String>(compareObjMap.keySet()),code);
for(CompareUnitDef unitDef : currentCompareUnitDef) {
indicatorsReportService.dealDriveIndReportThreeData(
unitDef.getCompareId(), Arrays.asList(unitDef.getIndIds().split(",")),
unitDef.getDate(),code);
if("0".equals(isTest)) {
logger.info("本期同期对标单元试运行计算完成");
}else {
logger.info("本期同期对标单元计算完成");
}
logger.info("本期同期对标单元计算完成");
}
}
})
......
......@@ -50,6 +50,8 @@ public class CompareUnitCalActor extends AbstractActor{
private String code;//机构编码
private String isTest;
private final ActorRef startCompareUnitCalActor;//定义父actor
static public Props props(ActorRef startCompareUnitCalActor) {
......@@ -71,6 +73,7 @@ public class CompareUnitCalActor extends AbstractActor{
averageObj = compareUnitDef.getAverageObj();
objScoreRuleId = compareUnitDef.getObjScoreRuleId();
code = compareUnitCalMsg.getCode();
isTest = compareUnitCalMsg.getIsTest();
//新增运行日志记录
CompareUnitCalLog compCalLog = new CompareUnitCalLog(compareId,date,
......@@ -92,7 +95,8 @@ public class CompareUnitCalActor extends AbstractActor{
for(String indId : indIdsList) {
DriveIndIdCalMsg driveIndIdCalMsg = new DriveIndIdCalMsg(
compareUnitDef.getCompareId(),indId,compareObjsList,compareUnitDef.getDate(),
firstExe,averageObj,compCalLogId,compareUnitCalMsg.getCode());
firstExe,averageObj,compCalLogId,compareUnitCalMsg.getCode(),
compareUnitCalMsg.getIsTest());
//start akka
ActorRef driveIndIdCalActor = this.getContext()
.actorOf(Props.create(DriveIndIdCalActor.class,
......
......@@ -16,10 +16,12 @@ import com.keymobile.indicators.akka.message.indicators.DriveIndIdObjCalMsg;
import com.keymobile.indicators.akka.message.indicators.FirstExeConfirmMsg;
import com.keymobile.indicators.model.entity.DimValue;
import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef;
import com.keymobile.indicators.service.hytobacco.DriveIndCalResultService;
import com.keymobile.indicators.service.hytobacco.DriveIndDefService;
import com.keymobile.indicators.service.hytobacco.IndScorecardService;
import com.keymobile.indicators.service.report.IndicatorsReportService;
import com.keymobile.indicators.service.testrun.TestDriveIndCalResultService;
import com.keymobile.indicators.utils.CalculateUtils;
import com.keymobile.indicators.utils.SpringUtil;
......@@ -32,6 +34,8 @@ public class DriveIndIdCalActor extends AbstractActor{
private DriveIndCalResultService driveIndCalResultService = SpringUtil.getBean(DriveIndCalResultService.class);
private TestDriveIndCalResultService testDriveIndCalResultService = SpringUtil.getBean(TestDriveIndCalResultService.class);
private IndScorecardService indScorecardService = SpringUtil.getBean(IndScorecardService.class);
private DriveIndDefService driveIndDefService = SpringUtil.getBean(DriveIndDefService.class);
......@@ -51,6 +55,8 @@ public class DriveIndIdCalActor extends AbstractActor{
private String averageObj;//平均分参考对象
private String code;//机构编码
private String isTest;
private final ActorRef compareUnitCalActor;//定义父actor
......@@ -74,6 +80,8 @@ public class DriveIndIdCalActor extends AbstractActor{
averageObj = driveIndIdCalMsg.getAverageObj();
compareObjSize = compareObjs.size();
code = driveIndIdCalMsg.getCode();
isTest = driveIndIdCalMsg.getIsTest();
//日志记录id
Integer compCalLogId = driveIndIdCalMsg.getCompCalLogId();
......@@ -85,7 +93,8 @@ public class DriveIndIdCalActor extends AbstractActor{
dimValueList.add(dimDateObj);
DriveIndIdObjCalMsg driveIndIdObjCalMsg = new DriveIndIdObjCalMsg(compareId,
indId,compareObj,date,dimValueList,compCalLogId,driveIndIdCalMsg.getCode());
indId,compareObj,date,dimValueList,compCalLogId,
driveIndIdCalMsg.getCode(),driveIndIdCalMsg.getIsTest());
ActorRef driveIndIdObjCalActor = this.getContext()
.actorOf(Props.create(DriveIndIdObjCalActor.class,
()->new DriveIndIdObjCalActor(getSelf())));
......@@ -110,17 +119,29 @@ public class DriveIndIdCalActor extends AbstractActor{
FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(1,"",compCalLogId);
compareUnitCalActor.tell(firstExeConfirmMsg, ActorRef.noSender());
}else {
DriveIndCalResultDef provinceDriveIndCalResult = null;
String actualAverage = "0.0";//实际平均分
if(StringUtils.isNotBlank(averageObj)) {
provinceDriveIndCalResult = driveIndCalResultService.findCompareObjInfo(
calIndAverageAndRankMsg.getDriveIndId(),
calIndAverageAndRankMsg.getDate(),
averageObj,code);
}
if(provinceDriveIndCalResult!=null) {
//获取实际平均分
actualAverage = provinceDriveIndCalResult.getValue();
if("0".equals(isTest)) {
TestDriveIndCalResultDef provinceDriveIndCalResult =
testDriveIndCalResultService.findCompareObjInfo(
calIndAverageAndRankMsg.getDriveIndId(),
calIndAverageAndRankMsg.getDate(),
averageObj,code);
if(provinceDriveIndCalResult!=null) {
//获取实际平均分
actualAverage = provinceDriveIndCalResult.getValue();
}
}else {
DriveIndCalResultDef provinceDriveIndCalResult =
driveIndCalResultService.findCompareObjInfo(
calIndAverageAndRankMsg.getDriveIndId(),
calIndAverageAndRankMsg.getDate(),
averageObj,code);
if(provinceDriveIndCalResult!=null) {
//获取实际平均分
actualAverage = provinceDriveIndCalResult.getValue();
}
}
}
//算组内平均数
String average = driveIndDefService.calGroupAverage(
......@@ -129,44 +150,87 @@ public class DriveIndIdCalActor extends AbstractActor{
//算组内排名
Map<String,Integer> rankValue = CalculateUtils.rankValue(valueMap, indType);
List<DriveIndCalResultDef> dataList = new ArrayList<>();
List<TestDriveIndCalResultDef> testDataList = new ArrayList<>();
//填充平均数和排名到考核结果中
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);
dataList.add(driveIndCalResult);
if("0".equals(isTest)) {
//根据id获取指标值结果
TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService.
findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) {
driveIndCalResult.setAverage(average);
driveIndCalResult.setRank(entry.getValue());
driveIndCalResult.setActualAverage(actualAverage);
testDataList.add(driveIndCalResult);
}
}else {
//根据id获取指标值结果
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) {
driveIndCalResult.setAverage(average);
driveIndCalResult.setRank(entry.getValue());
driveIndCalResult.setActualAverage(actualAverage);
dataList.add(driveIndCalResult);
}
}
}
//批量保存修改
driveIndCalResultService.batchSaveOrUpdate(dataList);
//清空list
dataList.clear();
if("0".equals(isTest)) {
//批量保存修改
testDriveIndCalResultService.batchSaveOrUpdate(testDataList);
//批量保存修改
testDataList.clear();
}else {
//批量保存修改
driveIndCalResultService.batchSaveOrUpdate(dataList);
//批量保存修改//批量保存修改
dataList.clear();
}
//根据评分卡算指标分数
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(), scoreCardId,
driveIndCalResult.getCompareId(),compareObjs,code);
driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
dataList.add(driveIndCalResult);
if("0".equals(isTest)) {
//根据id获取指标值结果
TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService.
findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) {
//计算分数
Map<String,String> scoreMap = indScorecardService.calculateIndiScore(
driveIndCalResult.getIndId(), driveIndCalResult.getDate(),
driveIndCalResult.getCompareObj(), scoreCardId,
driveIndCalResult.getCompareId(),compareObjs,code);
driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
testDataList.add(driveIndCalResult);
}
}else {
//根据id获取指标值结果
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findById(Integer.parseInt(entry.getKey()));
if(driveIndCalResult!=null) {
//计算分数
Map<String,String> scoreMap = indScorecardService.calculateIndiScore(
driveIndCalResult.getIndId(), driveIndCalResult.getDate(),
driveIndCalResult.getCompareObj(), scoreCardId,
driveIndCalResult.getCompareId(),compareObjs,code);
driveIndCalResult.setScore(scoreMap.get("score"));
driveIndCalResult.setImproveScore(scoreMap.get("improveScore"));
dataList.add(driveIndCalResult);
}
}
}
//批量保存修改
driveIndCalResultService.batchSaveOrUpdate(dataList);
//整合本期同期报表数据
//indiReportService.dealReportOneDatas(dataList);
//清空list
dataList.clear();
if("0".equals(isTest)) {
//批量保存修改
testDriveIndCalResultService.batchSaveOrUpdate(testDataList);
//清空list
testDataList.clear();
}else {
//批量保存修改
driveIndCalResultService.batchSaveOrUpdate(dataList);
//整合本期同期报表数据
//indiReportService.dealReportOneDatas(dataList);
//清空list
dataList.clear();
}
//发送确认信息给父actor
FirstExeConfirmMsg firstExeConfirmMsg = new FirstExeConfirmMsg(1,"",compCalLogId);
......
......@@ -22,9 +22,11 @@ import com.keymobile.indicators.akka.message.indicators.GetBaseIndValueMsg;
import com.keymobile.indicators.model.entity.indicators.CompareUnitCalLog;
import com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef;
import com.keymobile.indicators.service.hytobacco.CompareUnitCalLogService;
import com.keymobile.indicators.service.hytobacco.DriveIndCalResultService;
import com.keymobile.indicators.service.hytobacco.DriveIndDefService;
import com.keymobile.indicators.service.testrun.TestDriveIndCalResultService;
import com.keymobile.indicators.utils.DateUtils;
import com.keymobile.indicators.utils.SpringUtil;
......@@ -39,6 +41,8 @@ public class DriveIndIdObjCalActor extends AbstractActor{
private DriveIndCalResultService driveIndCalResultService = SpringUtil.getBean(DriveIndCalResultService.class);
private TestDriveIndCalResultService testDriveIndCalResultService = SpringUtil.getBean(TestDriveIndCalResultService.class);
private CompareUnitCalLogService compareUnitCalLogService = SpringUtil.getBean(CompareUnitCalLogService.class);
private String compareId ;
......@@ -65,6 +69,8 @@ public class DriveIndIdObjCalActor extends AbstractActor{
private String code;//编码标识
private String isTest;//试运行
private Map<String, Object> env = Maps.newHashMap();
//定义线程安全的收集反馈确认消息list
......@@ -93,6 +99,7 @@ public class DriveIndIdObjCalActor extends AbstractActor{
//日志记录id
compCalLogId = driveIndIdObjCalMsg.getCompCalLogId();
code = driveIndIdObjCalMsg.getCode();
isTest = driveIndIdObjCalMsg.getIsTest();
List<String> indIdList = new ArrayList<>();//定义存储从考核指标公式解析出来的基础指标id
......@@ -196,28 +203,51 @@ public class DriveIndIdObjCalActor extends AbstractActor{
driveIndValue = String.format("%.4f",
new BigDecimal(Double.valueOf(driveIndValue)));
}
//判断结果表中是否已存在该结果数据,存在则覆盖
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code);
if(driveIndCalResult==null) {
driveIndCalResult = new DriveIndCalResultDef(compareId,
driveIndId,compareObj,date,driveIndValue,unit,
"1","1","admin",code,baseIndValueMsg.getCompareObjDesc());
if("0".equals(isTest)) {//试运行
//判断结果表中是否已存在该结果数据,存在则覆盖
TestDriveIndCalResultDef driveIndCalResult = testDriveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code);
if(driveIndCalResult==null) {
driveIndCalResult = new TestDriveIndCalResultDef(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"));
}
//保存进考核指标结果表中
testDriveIndCalResultService.saveOrUpdate(driveIndCalResult);
//返回指标值回去算平均值和排名
CalIndAverageAndRankMsg driveIndAverageAndRankMsg =
new CalIndAverageAndRankMsg(driveIndCalResult.getId(),
compareId,driveIndId,compareObj,date,driveIndValue,
unit,indType,scoreCardId,averageDriveIndFormula,compCalLogId);
driveIndIdCalActor.tell(driveIndAverageAndRankMsg,ActorRef.noSender());
}else {
driveIndCalResult.setCode(code);
driveIndCalResult.setUnit(unit);
driveIndCalResult.setValue(driveIndValue);
driveIndCalResult.setLastUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
//判断结果表中是否已存在该结果数据,存在则覆盖
DriveIndCalResultDef driveIndCalResult = driveIndCalResultService.
findCalResultDataIsExist(compareId, compareObj, driveIndId, date, code);
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());
}
//保存进考核指标结果表中
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.
......
......@@ -15,6 +15,7 @@ import com.keymobile.indicators.akka.message.indicators.StartCompareUnitCalMsg;
import com.keymobile.indicators.model.entity.indicators.CompareUnitDef;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
import com.keymobile.indicators.service.hytobacco.ScoreRuleService;
import com.keymobile.indicators.service.testrun.TestScoreRuleService;
import com.keymobile.indicators.utils.SpringUtil;
import akka.actor.AbstractActor;
......@@ -26,6 +27,8 @@ public class StartCompareUnitCalActor extends AbstractActor{
private ScoreRuleService scoreRuleServer = SpringUtil.getBean(ScoreRuleService.class);
private TestScoreRuleService testScoreRuleServer = SpringUtil.getBean(TestScoreRuleService.class);
private List<CompareUnitDef> firstExeList = new ArrayList<>();//先执行对标单元list
private List<CompareUnitDef> afterExeList = new ArrayList<>();//后执行对标单元list
......@@ -42,6 +45,8 @@ public class StartCompareUnitCalActor extends AbstractActor{
private String code = null;//机构编码
private String isTest = null;//试运行,0:试运行 1:正式运行
private final ActorRef beforeCompareUnitActor;//定义父actor
static public Props props(ActorRef beforeCompareUnitActor) {
......@@ -57,6 +62,7 @@ public class StartCompareUnitCalActor extends AbstractActor{
return receiveBuilder()
.match(StartCompareUnitCalMsg.class,startCompareUnitCalMsg -> {
code = startCompareUnitCalMsg.getCode();
isTest = startCompareUnitCalMsg.getIsTest();
List<CompareUnitDef> compareUnitDefs = startCompareUnitCalMsg.getCompareInitDefs();
//将对标单元进行分类,需要先执行的先开始进行对标计算
for(CompareUnitDef unitDef : compareUnitDefs) {
......@@ -80,7 +86,8 @@ public class StartCompareUnitCalActor extends AbstractActor{
if(!firstExeList.isEmpty()) {
for(CompareUnitDef unitDef : firstExeList) {
CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef,
startCompareUnitCalMsg.getCode());
startCompareUnitCalMsg.getCode(),
startCompareUnitCalMsg.getIsTest());
ActorRef compareUnitCalActor = this.getContext()
.actorOf(Props.create(CompareUnitCalActor.class,
()->new CompareUnitCalActor(getSelf())));
......@@ -90,7 +97,8 @@ public class StartCompareUnitCalActor extends AbstractActor{
if(!afterExeList.isEmpty()) {
for(CompareUnitDef unitDef : afterExeList) {
CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef,
startCompareUnitCalMsg.getCode());
startCompareUnitCalMsg.getCode(),
startCompareUnitCalMsg.getIsTest());
ActorRef compareUnitCalActor = this.getContext()
.actorOf(Props.create(CompareUnitCalActor.class,
()->new CompareUnitCalActor(getSelf())));
......@@ -100,7 +108,11 @@ public class StartCompareUnitCalActor extends AbstractActor{
//发送确认消息给父actor
CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1,"");
beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender());
logger.info("对标单元计算完成");
if("0".equals(isTest)) {
logger.info("对标单元试运行计算完成");
}else {
logger.info("对标单元计算完成");
}
}
}
})
......@@ -110,45 +122,81 @@ public class StartCompareUnitCalActor extends AbstractActor{
if(!afterExeList.isEmpty()) {
for(CompareUnitDef unitDef : afterExeList) {
CompareUnitCalMsg compareUnitCalMsg = new CompareUnitCalMsg(unitDef,
code);
code,isTest);
ActorRef compareUnitCalActor = this.getContext()
.actorOf(Props.create(CompareUnitCalActor.class,
()->new CompareUnitCalActor(getSelf())));
compareUnitCalActor.tell(compareUnitCalMsg, getSelf());
}
logger.info("进行后执行对标单元计算....");
if("0".equals(isTest)) {
logger.info("进行后执行对标单元试运行计算....");
}else {
logger.info("进行后执行对标单元计算....");
}
}else {
if(!calTypeExeList.isEmpty()) {
logger.info("计算对标单元单位评分......");
if("0".equals(isTest)) {
logger.info("计算试运行对标单元单位评分......");
}else {
logger.info("计算对标单元单位评分......");
}
for(CompareUnitDef unitDef : calTypeExeList) {
scoreRuleServer.calObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code);
//试运行
if("0".equals(isTest)) {
testScoreRuleServer.testCalObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code);
}else {
scoreRuleServer.calObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code);
}
}
}
//发送确认消息给父actor
CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1,"");
beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender());
logger.info("对标单元计算完成");
if("0".equals(isTest)) {
logger.info("对标单元试运行计算完成");
}else {
logger.info("对标单元计算完成");
}
}
}
})
.match(AfterExeConfirmMsg.class, afterExeConfirmMsg -> {
if (++numberOfAfterConfirm >= afterExeUnitSize) {//全部后执行的子actor全部返回
if(!calTypeExeList.isEmpty()) {
logger.info("计算对标单元单位评分......");
if("0".equals(isTest)) {
logger.info("计算试运行对标单元单位评分......");
}else {
logger.info("计算对标单元单位评分......");
}
for(CompareUnitDef unitDef : calTypeExeList) {
scoreRuleServer.calObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code);
//试运行
if("0".equals(isTest)) {
testScoreRuleServer.testCalObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code);
}else {
scoreRuleServer.calObjScore(unitDef.getCompareId(),
Arrays.asList(unitDef.getIndIds().split(",")),
Arrays.asList(unitDef.getCompareObjs().split(",")),
unitDef.getDate(), unitDef.getObjScoreRuleId(),code);
}
}
}
//发送确认消息给父actor
CurrentCompUnitExeMsg currentCompUnitExeMsg = new CurrentCompUnitExeMsg(1,"");
beforeCompareUnitActor.tell(currentCompUnitExeMsg, ActorRef.noSender());
logger.info("对标单元计算完成");
if("0".equals(isTest)) {
logger.info("对标单元试运行计算完成");
}else {
logger.info("对标单元计算完成");
}
}
})
.build();
......
......@@ -14,9 +14,12 @@ public class CompareUnitCalMsg implements Serializable{
private String code;
public CompareUnitCalMsg(CompareUnitDef compareUnitDef,String code) {
private String isTest;
public CompareUnitCalMsg(CompareUnitDef compareUnitDef,String code,String isTest) {
this.compareUnitDef = compareUnitDef;
this.code = code;
this.isTest = isTest;
}
public CompareUnitDef getCompareUnitDef() {
......@@ -34,4 +37,12 @@ public class CompareUnitCalMsg implements Serializable{
public void setCode(String code) {
this.code = code;
}
public String getIsTest() {
return isTest;
}
public void setIsTest(String isTest) {
this.isTest = isTest;
}
}
......@@ -18,9 +18,10 @@ public class DriveIndIdCalMsg implements Serializable{
private String averageObj;//平均分参考对象
private Integer compCalLogId;//运行日志记录id
private String code;//机构编码
private String isTest;//试运行 0:试运行 1:正式运行
public DriveIndIdCalMsg(String compareId,String indId,List<String> compareObj,Integer date,
String firstExe,String averageObj,Integer compCalLogId,String code) {
String firstExe,String averageObj,Integer compCalLogId,String code,String isTest) {
this.compareId = compareId;
this.indId = indId;
this.compareObj.addAll(compareObj);
......@@ -29,6 +30,7 @@ public class DriveIndIdCalMsg implements Serializable{
this.averageObj = averageObj;
this.compCalLogId = compCalLogId;
this.code = code;
this.isTest = isTest;
}
public String getCompareId() {
......@@ -84,4 +86,12 @@ public class DriveIndIdCalMsg implements Serializable{
public void setCode(String code) {
this.code = code;
}
public String getIsTest() {
return isTest;
}
public void setIsTest(String isTest) {
this.isTest = isTest;
}
}
......@@ -19,9 +19,11 @@ public class DriveIndIdObjCalMsg implements Serializable{
private List<DimValue> dimValues = new ArrayList<>();//维度值list
private Integer compCalLogId;//运行日志记录id
private String code;//机构编码
private String isTest;//试运行
public DriveIndIdObjCalMsg(String compareId,String indId,String compareObj,
Integer date,List<DimValue> dimValues,Integer compCalLogId,String code) {
Integer date,List<DimValue> dimValues,Integer compCalLogId,
String code,String isTest) {
this.compareId = compareId;
this.indId = indId;
this.compareObj = compareObj;
......@@ -29,6 +31,7 @@ public class DriveIndIdObjCalMsg implements Serializable{
this.dimValues.addAll(dimValues);
this.compCalLogId = compCalLogId;
this.code = code;
this.isTest = isTest;
}
public String getCompareId() {
......@@ -77,4 +80,12 @@ public class DriveIndIdObjCalMsg implements Serializable{
public void setCode(String code) {
this.code = code;
}
public String getIsTest() {
return isTest;
}
public void setIsTest(String isTest) {
this.isTest = isTest;
}
}
......@@ -16,9 +16,12 @@ public class StartCompareUnitCalMsg implements Serializable{
private String code;
public StartCompareUnitCalMsg(List<CompareUnitDef> compareInitDefs,String code) {
private String isTest;
public StartCompareUnitCalMsg(List<CompareUnitDef> compareInitDefs,String code,String isTest) {
this.compareInitDefs.addAll(compareInitDefs);
this.code = code;
this.setIsTest(isTest);
}
public List<CompareUnitDef> getCompareInitDefs() {
......@@ -36,4 +39,12 @@ public class StartCompareUnitCalMsg implements Serializable{
public void setCode(String code) {
this.code = code;
}
public String getIsTest() {
return isTest;
}
public void setIsTest(String isTest) {
this.isTest = isTest;
}
}
......@@ -3,6 +3,7 @@ package com.keymobile.indicators.api.hytobacco;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -35,17 +36,33 @@ public class DriveIndCalResultCtrl {
driveIndCalResultService.batchSaveOrUpdate(calResults);
}
@ApiOperation(value = "对标单元综合计算", notes = "对标单元综合计算")
@ApiOperation(value = "对标单元综合计算(isTest: 0试运行 1正式运行)", notes = "对标单元综合计算")
@PostMapping(value = "/compareUnitListCal")
public void compareUnitListCal(@RequestBody List<CompareUnitDef> compareUnitList,
@RequestParam(value="code",required = false) String code) {
@RequestParam(value="code",required = false) String code,
@RequestParam(value="isTest",required = false) String isTest) throws Exception{
if(StringUtils.isBlank(code)) {
throw new Exception("user org number is null");
}
if(StringUtils.isBlank(isTest)) {//空值默认为正式运算
isTest = "1";
}else {
if(!"0".equals(isTest) && !"1".equals(isTest)) {
throw new Exception("the param isTest's value must be '0' or '1'");
}
}
StringBuilder compUnitDefString = new StringBuilder("");
for(CompareUnitDef compUnitDef : compareUnitList) {
compUnitDefString.append(compUnitDef.getCompareId()).append(";");
}
LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"执行对标单元id:{},日期:{} 的计算",
compUnitDefString.toString(),compareUnitList.get(0).getDate());
driveIndCalResultService.compareUnitListCal(compareUnitList,code);
if("0".equals(isTest)) {
LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"执行对标单元id:{},日期:{} 的试运行计算",
compUnitDefString.toString(),compareUnitList.get(0).getDate());
}else {
LogManager.logInfo(Constants.LOG_INDICATOR_UNIT_CAL_API,"执行对标单元id:{},日期:{} 的计算",
compUnitDefString.toString(),compareUnitList.get(0).getDate());
}
driveIndCalResultService.compareUnitListCal(compareUnitList,code,isTest);
}
@ApiOperation(value = "根据对标单元id分页获取日志详情", notes = "根据对标单元id分页获取日志详情")
......
package com.keymobile.indicators.model.entity.testrun;
import java.util.Date;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
/**
* author:zhangkb time:2020-8-31 desc:试运行考核指标结果表
*/
@Data
@Table(name="test_drive_ind_cal_result_def")
public class TestDriveIndCalResultDef {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String compareId;
private String indId;
private String compareObj;
private String compareObjDesc;
private Integer date;
private String value;
private String unit;
private String type;//0:季度 1:年度
private String isRight;//表示考核指标的值是否计算正常得到的 0:计算有误 1:计算正常
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
private String lastUpdater;
private String average;//组内平均数
private Integer rank;//同组排名
private String score;//指标评分分数
private String improveScore;//改善提升得分
private String actualAverage;//实际平均数:用于省对市的操作,如果有全省的基础项数据,直接拿全省的基础项数据算考核指标做为其实际平均值
private String code;//编码标识
public TestDriveIndCalResultDef() {
super();
}
public TestDriveIndCalResultDef(String compareId,String indId,String compareObj,int date,String value,
String unit,String type,String isRight,String lastUpdater,String code,String compareObjDesc) {
this.compareId = compareId;
this.indId = indId;
this.compareObj = compareObj;
this.date = date;
this.value = value;
this.unit = unit;
this.type = type;
this.isRight = isRight;
this.lastUpdater = lastUpdater;
this.code = code;
this.compareObjDesc = compareObjDesc;
}
}
package com.keymobile.indicators.model.entity.testrun;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
*author:zhangkb time:2020-8-31 desc:试运行单位评分结果存放实体
*/
@Data
@Table(name ="test_obj_score_cal_result")
public class TestObjScoreCalResult {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String compareId;//对标单元id
private String compareObj;//对标对象
private String compareObjDesc;//对标对象描述
private String indIds;//对标考核指标id
private Integer date;//对标日期
private String scoreValue;//考核对象得分
private String improveValue;//考核对象改善得分
private String scoreSumValue;//指标总积分
private Integer indCount;//指标个数
private String code;//机构编码
}
package com.keymobile.indicators.model.mapper.testrun;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface TestDriveIndCalResultDefMapper extends BaseMapper<TestDriveIndCalResultDef>{
public List<TestDriveIndCalResultDef> findByCompareObjAndDate(@Param("compareObj") String compareObj,
@Param("date") int date,@Param("code") String code);
public TestDriveIndCalResultDef findByIndIdAndDateAndCompareObj(@Param("indId") String indId,
@Param("date") int date,@Param("compareObj") String compareObj,@Param("code") String code);
public TestDriveIndCalResultDef findByCompareIdAndCompareObjAndIndIdAndDate(
@Param("compareId") String compareId,@Param("compareObj") String compareObj,
@Param("indId") String indId,@Param("date") Integer date,@Param("code") String code);
//批量保存
public void batchSave(@Param("datas")List<TestDriveIndCalResultDef> datas);
//批量修改
public void batchUpdate(@Param("datas")List<TestDriveIndCalResultDef> datas);
}
package com.keymobile.indicators.model.mapper.testrun;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.keymobile.indicators.model.entity.testrun.TestObjScoreCalResult;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface TestObjScoreCalResultMapper extends BaseMapper<TestObjScoreCalResult>{
public TestObjScoreCalResult getTestObjScoreCalResultByParam(@Param("compareId")String compareId,
@Param("compareObj")String compareObj,@Param("date")Integer date,@Param("code") String code);
public void batchSave(@Param("datas")List<TestObjScoreCalResult> datas);
public void batchUpdate(@Param("datas")List<TestObjScoreCalResult> datas);
}
......@@ -73,7 +73,7 @@ public class DriveIndCalResultService {
return driveIndCalResultDefMapper.findByCompareIdAndDate(compareId, date);
}
public void compareUnitListCal(List<CompareUnitDef> compareUnitList,String code) {
public void compareUnitListCal(List<CompareUnitDef> compareUnitList,String code,String isTest) {
if(!compareUnitList.isEmpty()) {
List<CompareUnitDef> sameCompareUnitList = new ArrayList<>();
//将对标单元的日期改成同期
......@@ -85,7 +85,7 @@ public class DriveIndCalResultService {
//启动回流actor
final ActorSystem system = ActorSystem.create("CompareUnitCalAkka");//创建akka
StartCompareUnitCalMsg startCompareUnitCalMsg = new StartCompareUnitCalMsg(
sameCompareUnitList,code);
sameCompareUnitList,code,isTest);
ActorRef beforeCompareUnitCalActor = system.actorOf(Props.create(
BeforeCompareUnitCalActor.class,()-> new BeforeCompareUnitCalActor()));
beforeCompareUnitCalActor.tell(startCompareUnitCalMsg, ActorRef.noSender());
......
package com.keymobile.indicators.service.testrun;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef;
import com.keymobile.indicators.model.mapper.testrun.TestDriveIndCalResultDefMapper;
@Service
public class TestDriveIndCalResultService {
private Logger logger = LoggerFactory.getLogger(TestDriveIndCalResultService.class);
@Autowired
private TestDriveIndCalResultDefMapper testDriveIndCalResultDefMapper;
public TestDriveIndCalResultDef findById(Integer id) {
return testDriveIndCalResultDefMapper.selectByPrimaryKey(id);
}
public TestDriveIndCalResultDef findCompareObjInfo(String driveIndId,int date,String compareObj,
String code) {
return testDriveIndCalResultDefMapper.findByIndIdAndDateAndCompareObj(
driveIndId, date, compareObj, code);
}
public TestDriveIndCalResultDef findCalResultDataIsExist(String compareId,String compareObj,
String indId,int date,String code) {
return testDriveIndCalResultDefMapper.
findByCompareIdAndCompareObjAndIndIdAndDate(compareId, compareObj, indId, date, code);
}
public int saveOrUpdate(TestDriveIndCalResultDef driveIndCalResult) {
if(driveIndCalResult.getId()==null) {
testDriveIndCalResultDefMapper.insert(driveIndCalResult);
}else {
testDriveIndCalResultDefMapper.updateByPrimaryKey(driveIndCalResult);
}
return driveIndCalResult.getId();
}
//批量新增或者修改
public void batchSaveOrUpdate(List<TestDriveIndCalResultDef> driveIndCalResults) {
List<TestDriveIndCalResultDef> addList = new ArrayList<>();
List<TestDriveIndCalResultDef> updateList = new ArrayList<>();
for(TestDriveIndCalResultDef driveIndCalResult : driveIndCalResults) {
if(driveIndCalResult.getId()==null) {
addList.add(driveIndCalResult);//新增list
}else {
updateList.add(driveIndCalResult);//修改list
}
}
if(!addList.isEmpty()) {//批量新增
testDriveIndCalResultDefMapper.batchSave(addList);
}
if(!updateList.isEmpty()) {//批量修改
testDriveIndCalResultDefMapper.batchUpdate(updateList);
}
}
}
package com.keymobile.indicators.service.testrun;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.googlecode.aviator.AviatorEvaluator;
import com.keymobile.indicators.model.entity.indicators.DriveIndDef;
import com.keymobile.indicators.model.entity.objscorerule.IndTypeWeight;
import com.keymobile.indicators.model.entity.objscorerule.ScoreRule;
import com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef;
import com.keymobile.indicators.model.entity.testrun.TestObjScoreCalResult;
import com.keymobile.indicators.model.mapper.indicators.DriveIndDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.ScoreRuleMapper;
import com.keymobile.indicators.model.mapper.testrun.TestDriveIndCalResultDefMapper;
import com.keymobile.indicators.model.mapper.testrun.TestObjScoreCalResultMapper;
import com.keymobile.indicators.utils.CalculateUtils;
@Service
public class TestScoreRuleService {
private Logger logger = LoggerFactory.getLogger(TestScoreRuleService.class);
@Autowired
private ScoreRuleMapper scoreRuleMapper;
@Autowired
private DriveIndDefMapper driveIndDefMapper;
@Autowired
private TestObjScoreCalResultMapper testObjScoreCalResultMapper;
@Autowired
private TestDriveIndCalResultDefMapper testDriveIndCalResultDefMapper;
private static final Pattern P = Pattern.compile("(\\[[^\\]]*\\])");
//根据单位评分规则计算单位分数
public void testCalObjScore(String compareId,List<String> indIds,
List<String> compareObjs,int date,Integer scoreRuleId,String code) {
//根据单位得分评分卡id获取评分卡详情
ScoreRule scoreRule = this.getById(scoreRuleId);
List<TestObjScoreCalResult> datas = new ArrayList<>();
if(scoreRule!=null) {
if(!indIds.isEmpty() && !compareObjs.isEmpty()) {
for(String compareObj : compareObjs) {
//判断库表是否已存在改结果数据
TestObjScoreCalResult objScoreCalResult = testObjScoreCalResultMapper.
getTestObjScoreCalResultByParam(compareId, compareObj, date, code);
if(objScoreCalResult == null) {
objScoreCalResult = new TestObjScoreCalResult();
}
//计算类型:0 地区所有纳入评价的考核指标平均数
if("0".equals(scoreRule.getCalType())) {
objScoreCalResult = this.calGroupIndAverageOrSum(objScoreCalResult, scoreRule,
compareObj, date, scoreRule.getCalType(),code);
}else if("1".equals(scoreRule.getCalType())) {//1 根据目录类别分类算平均分后根据权重计算考核指标
objScoreCalResult = this.calIndCatalogTypeAverage(objScoreCalResult, scoreRule,
compareObj, date, code);
}else if("2".equals(scoreRule.getCalType())){//2单个指标权重计算
objScoreCalResult = this.calSingleIndWeight(objScoreCalResult ,scoreRule,
compareObj, date, code);
}else {//3:指标总得分
objScoreCalResult = this.calGroupIndAverageOrSum(objScoreCalResult, scoreRule,
compareObj, date, scoreRule.getCalType(),code);
}
objScoreCalResult.setCompareId(compareId);
datas.add(objScoreCalResult);
}
//批量新增或修改
this.batchSaveOrUpdateObjScoreCalResult(datas);
}
}else {
logger.info("单位评分卡id:"+scoreRuleId+" 不存在");
}
}
//计算组内考核指标平均值或者总和 type:0 计算地区所有纳入考核指标平均数 3指标总得分
private TestObjScoreCalResult calGroupIndAverageOrSum(TestObjScoreCalResult objResult,ScoreRule scoreRule,
String compareObj,int date,String type,String code){
objResult.setCompareObj(compareObj);
objResult.setScoreValue("0.0");
objResult.setImproveValue("0.0");
objResult.setDate(date);
//objResult.setIndIds(String.join(",", indIds));
//根据日期,对标对象和考核的指标获取考核指标结果详情
//Map<String,Object> paremMap = new HashMap<>();
//paremMap.put("compareObj", compareObj);
//paremMap.put("date", date);
//paremMap.put("indIds", indIds);
//List<DriveIndCalResultDef> calResults = driveIndCalResultDefMapper.
//findByCompareObjAndDateAndIndIdIn(paremMap);
List<TestDriveIndCalResultDef> calResults = testDriveIndCalResultDefMapper.
findByCompareObjAndDate(compareObj, date, code);
int indCount = 0;//定义用户记录纳入考核指标个数
List<String> values = new ArrayList<>();
List<String> improveValues = new ArrayList<>();
if(!calResults.isEmpty()) {
//auth:zhangkb time:2020-7-15 desc:填充对标对象描述
objResult.setCompareObjDesc(calResults.get(0).getCompareObjDesc());
for(TestDriveIndCalResultDef calResult : calResults) {
//根据考核指标id获取考核指标
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(calResult.getIndId());
if(driveIndDef!=null) {
//如果考核指标是参与单位计分的
if(StringUtils.isBlank(driveIndDef.getIsUnitCalScore()) ||
"1".equals(driveIndDef.getIsUnitCalScore())) {
indCount += 1;
//得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) {
if(!"NaN".equals(calResult.getValue()) && !"Infinite".equals(calResult.getValue())
&& !"0.0000".equals(calResult.getValue()) && !"0".equals(calResult.getValue())) {
values.add(calResult.getValue());
}
}else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
values.add(calResult.getScore());
if(!"No".equals(calResult.getImproveScore()) &&
StringUtils.isNotBlank(calResult.getImproveScore())) {
improveValues.add(calResult.getImproveScore());
}
}else {//2指标得分分数参与计算(指标分数=综合+改善)
if(!"No".equals(calResult.getImproveScore()) &&
StringUtils.isNotBlank(calResult.getImproveScore())) {
double indScore = Double.parseDouble(calResult.getScore());
double improveScore = Double.parseDouble(calResult.getImproveScore());
double sum = indScore+improveScore;
values.add(String.valueOf(sum));
}else {
values.add(calResult.getScore());
}
}
}
}
}
String averageValue = "0.0";
String averageImproveValue = "0.0";
if("0".equals(type)) {//计算平均值
averageValue = CalculateUtils.averageValue(values,1);
}
if("3".equals(type)){//计算总和
averageValue = CalculateUtils.sumValue(values);
}
if(!improveValues.isEmpty()) {
if("0".equals(type)) {
averageImproveValue = CalculateUtils.averageValue(improveValues,1);
}
if("3".equals(type)){
averageImproveValue = CalculateUtils.sumValue(improveValues);
}
}
//计算总积分
Double scoreSumValue = (Double.parseDouble(CalculateUtils.sumValue(values))+
Double.parseDouble(CalculateUtils.sumValue(improveValues)));
objResult.setScoreSumValue(String.valueOf(scoreSumValue));
objResult.setIndCount(indCount);
objResult.setScoreValue(averageValue);
objResult.setImproveValue(averageImproveValue);
}
return objResult;
}
private TestObjScoreCalResult calSingleIndWeight(TestObjScoreCalResult objResult,ScoreRule scoreRule,
String compareObj,int date,String code){
objResult.setCompareObj(compareObj);
objResult.setScoreValue("0.0");
objResult.setImproveValue("0.0");
objResult.setDate(date);
String calFormula = scoreRule.getCalFormula();//计算综合评分分数
String improveCalFormula = scoreRule.getCalFormula();//计算改善提升分数
if(StringUtils.isNotBlank(calFormula)) {
//获取公式中的考核指标编码
List<String> indIdList = new ArrayList<>();
Matcher m = P.matcher(calFormula);
while(m.find()){
indIdList.add(m.group().substring(1, m.group().length()-1));
}
for(String indId : indIdList) {
//根据日期,对标对象和考核的指标获取考核指标结果详情
TestDriveIndCalResultDef calresultOp = testDriveIndCalResultDefMapper.
findByIndIdAndDateAndCompareObj(indId, date, compareObj, code);
if(calresultOp!=null) {
//auth:zhangkb time:2020-7-15 desc:填充对标对象描述
objResult.setCompareObjDesc(calresultOp.getCompareObjDesc());
//得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) {
if(!"NaN".equals(calresultOp.getValue()) && !"Infinite".equals(calresultOp.getValue())) {
calFormula = calFormula.replace("["+indId+"]", calresultOp.getValue());
}else {
calFormula = calFormula.replace("["+indId+"]", "0.0");
}
}else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
calFormula = calFormula.replace("["+indId+"]", calresultOp.getValue());
if(!"No".equals(calresultOp.getImproveScore()) &&
StringUtils.isNotBlank(calresultOp.getImproveScore())) {
improveCalFormula = improveCalFormula.replace("["+indId+"]",
calresultOp.getImproveScore());
}else {
improveCalFormula = improveCalFormula.replace("["+indId+"]","0.0");
}
}else {//2指标得分分数参与计算(指标分数=综合+改善)
String score = "0.0";
if(!"No".equals(calresultOp.getImproveScore()) &&
StringUtils.isNotBlank(calresultOp.getImproveScore())) {
double indScore = Double.parseDouble(calresultOp.getScore());
double improveScore = Double.parseDouble(calresultOp.getImproveScore());
double sum = indScore+improveScore;
score = String.valueOf(sum);
}else {
score = calresultOp.getScore();
}
calFormula = calFormula.replace("["+indId+"]", score);
}
}else {
//得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) {
calFormula = calFormula.replace("["+indId+"]", "0.0");
}else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
calFormula = calFormula.replace("["+indId+"]", "0.0");
improveCalFormula = improveCalFormula.replace("["+indId+"]", "0.0");
}else {//2指标得分分数参与计算(指标分数=综合+改善)
calFormula = calFormula.replace("["+indId+"]", "0.0");
}
}
}
//得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType()) ||
"2".equals(scoreRule.getScoreType())) {
String scoreValue = String.format("%.4f",
new BigDecimal((Double)AviatorEvaluator.execute(calFormula)));
objResult.setScoreValue(scoreValue);
objResult.setImproveValue("0.0");
}else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
String scoreValue = String.format("%.4f",
new BigDecimal((Double)AviatorEvaluator.execute(calFormula)));
String improveValue = String.format("%.4f",
new BigDecimal((Double)AviatorEvaluator.execute(improveCalFormula)));
objResult.setScoreValue(scoreValue);
objResult.setImproveValue(improveValue);
}
}
return objResult;
}
//按照指标类别进行分类分别计算平均分后再跟类别权重相乘后相加得到最终分数
private TestObjScoreCalResult calIndCatalogTypeAverage(TestObjScoreCalResult objResult,ScoreRule scoreRule,
String compareObj,int date,String code){
Gson gson = new Gson();
objResult.setCompareObj(compareObj);
objResult.setScoreValue("0.0");
objResult.setImproveValue("0.0");
objResult.setDate(date);
//根据对标对象,日期查找该对标对象对标的所有指标结果
List<TestDriveIndCalResultDef> calResults = testDriveIndCalResultDefMapper.
findByCompareObjAndDate(compareObj, date, code);
double scoreValue = 0.0;
double improveValue = 0.0;
if(!calResults.isEmpty()) {
//auth:zhangkb time:2020-7-15 desc:填充对标对象描述
objResult.setCompareObjDesc(calResults.get(0).getCompareObjDesc());
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())/100);
improveValue += (calScores.get("improve")*Double.parseDouble(indTypeWeight.getWeight())/100);
}
}
}
objResult.setScoreValue(String.format("%.4f",new BigDecimal(scoreValue)));
objResult.setImproveValue(String.format("%.4f",new BigDecimal(improveValue)));
return objResult;
}
//根据指标分类计算指标平均值
private Map<String,Double> calIndTypeScore(ScoreRule scoreRule,IndTypeWeight indTypeWeight,
List<TestDriveIndCalResultDef> calResults) {
Map<String,Double> result = new HashMap<>();
result.put("score", 0.0);
result.put("improve", 0.0);
List<String> values = new ArrayList<>();
List<String> improveValues = new ArrayList<>();
for(TestDriveIndCalResultDef calResult : calResults) {
String catalogIdPath = indTypeWeight.getCatalogIdPath();
//根据考核指标id获取考核指标
DriveIndDef driveIndDef = driveIndDefMapper.selectByPrimaryKey(calResult.getIndId());
if(driveIndDef!=null) {
//如果考核指标是参与单位计分的
if(StringUtils.isBlank(driveIndDef.getIsUnitCalScore()) ||
"1".equals(driveIndDef.getIsUnitCalScore())) {
//如果指标是该指标分类下的
if(driveIndDef.getCatalogIdPath().indexOf(catalogIdPath)>=0) {
//得分类型:0 指标值直接参与计算
if("0".equals(scoreRule.getScoreType())) {
if(!"NaN".equals(calResult.getValue()) && !"Infinite".equals(calResult.getValue())
/*&& !"0.0000".equals(calResult.getValue()) && !"0".equals(calResult.getValue())*/) {
values.add(calResult.getValue());
}
}else if("1".equals(scoreRule.getScoreType())) {//1 指标得分分数参与计算(综合评分和改善提升分开算)
values.add(calResult.getScore());
if(!"No".equals(calResult.getImproveScore()) &&
StringUtils.isNotBlank(calResult.getImproveScore())) {
improveValues.add(calResult.getImproveScore());
}
}else {//2指标得分分数参与计算(指标分数=综合+改善)
if(!"No".equals(calResult.getImproveScore()) &&
StringUtils.isNotBlank(calResult.getImproveScore())) {
double indScore = Double.parseDouble(calResult.getScore());
double improveScore = Double.parseDouble(calResult.getImproveScore());
double sum = indScore+improveScore;
values.add(String.valueOf(sum));
}else {
values.add(calResult.getScore());
}
}
}
}
}
}
//计算平均值
String averageValue = CalculateUtils.averageValue(values,1);
String averageImproveValue = "0.0";
if(!improveValues.isEmpty()) {
averageImproveValue = CalculateUtils.averageValue(improveValues,1);
}
result.put("score", Double.parseDouble(averageValue));
result.put("improve", Double.parseDouble(averageImproveValue));
return result;
}
public void batchSaveOrUpdateObjScoreCalResult(List<TestObjScoreCalResult> calDatas) {
List<TestObjScoreCalResult> addList = new ArrayList<>();//新增list
List<TestObjScoreCalResult> updateList = new ArrayList<>();//修改list
for(TestObjScoreCalResult calData : calDatas) {
if(calData.getId()==null) {
addList.add(calData);
}else {
updateList.add(calData);
}
}
if(!addList.isEmpty()) {
testObjScoreCalResultMapper.batchSave(addList);
}
if(!updateList.isEmpty()) {
testObjScoreCalResultMapper.batchUpdate(updateList);
}
}
private ScoreRule getById(Integer id) {
ScoreRule scoreRule = scoreRuleMapper.selectByPrimaryKey(id);
if(scoreRule!=null) {
return this.changeJson(scoreRule);
}
return null;
}
private ScoreRule changeJson(ScoreRule scoreRule) {
Gson gson = new Gson();
if(StringUtils.isNotBlank(scoreRule.getIndTypeWeightsJson())) {
List<IndTypeWeight> indTypeWeights = gson.
fromJson(scoreRule.getIndTypeWeightsJson(), new TypeToken<List<IndTypeWeight>>(){}.getType());
scoreRule.setIndTypeWeights(indTypeWeights);
}
return scoreRule;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.keymobile.indicators.model.mapper.testrun.TestDriveIndCalResultDefMapper">
<select id="findByCompareObjAndDate" resultType="com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef" >
select *
from test_drive_ind_cal_result_def
where
compare_obj = #{compareObj} and
date = #{date} and
code = #{code}
</select>
<select id="findByIndIdAndDateAndCompareObj" resultType="com.keymobile.indicators.model.entity.testrun.TestDriveIndCalResultDef" >
select *
from test_drive_ind_cal_result_def
where
ind_id = #{indId} and
compare_obj = #{compareObj} and
date = #{date} and
code = #{code}
</select>
<select id="findByCompareIdAndCompareObjAndIndIdAndDate" resultType="com.keymobile.indicators.model.entity.indicators.DriveIndCalResultDef" >
select *
from test_drive_ind_cal_result_def
where
compare_id = #{compareId} and
compare_obj = #{compareObj} and
ind_id = #{indId} and
date = #{date} and
code = #{code}
</select>
<insert id="batchSave" parameterType="java.util.List">
insert into test_drive_ind_cal_result_def(
compare_id, ind_id, compare_obj, compare_obj_desc, date, value, unit, type,
is_right, last_update_time, last_updater, average, rank, score, improve_score,
actual_average, code)
values
<foreach collection="datas" item="val" separator=",">
(
#{val.compareId}, #{val.indId}, #{val.compareObj}, #{val.compareObjDesc}, #{val.date},
#{val.value},#{val.unit},#{val.type},#{val.isRight},#{val.lastUpdateTime},#{val.lastUpdater},
#{val.average},#{val.rank},#{val.score},#{val.improveScore},#{val.actualAverage},#{val.code}
)
</foreach>
</insert>
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="datas" item="val" index="index" separator=";">
update test_drive_ind_cal_result_def
<set>
<if test="val.compareId != null">
compare_id = #{val.compareId},
</if>
<if test="val.indId != null">
ind_id = #{val.indId},
</if>
<if test="val.compareObj != null">
compare_obj = #{val.compareObj},
</if>
<if test="val.compareObjDesc != null">
compare_obj_desc = #{val.compareObjDesc},
</if>
<if test="val.date != null">
date = #{val.date},
</if>
<if test="val.value != null">
value = #{val.value},
</if>
<if test="val.unit != null">
unit = #{val.unit},
</if>
<if test="val.type != null">
type = #{val.type},
</if>
<if test="val.isRight != null">
is_right = #{val.isRight},
</if>
<if test="val.lastUpdateTime != null">
last_update_time = #{val.lastUpdateTime},
</if>
<if test="val.lastUpdater != null">
last_updater = #{val.lastUpdater},
</if>
<if test="val.average != null">
average = #{val.average},
</if>
<if test="val.rank != null">
rank = #{val.rank},
</if>
<if test="val.score != null">
score = #{val.score},
</if>
<if test="val.improveScore != null">
improve_score = #{val.improveScore},
</if>
<if test="val.actualAverage != null">
actual_average = #{val.actualAverage},
</if>
<if test="val.code != null">
code = #{val.code},
</if>
</set>
where id = ${val.id}
</foreach>
</update>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.keymobile.indicators.model.mapper.testrun.TestObjScoreCalResultMapper">
<select id="getTestObjScoreCalResultByParam" resultType="com.keymobile.indicators.model.entity.testrun.TestObjScoreCalResult" >
select *
from test_obj_score_cal_result
where
compare_id=#{compareId} and
compare_obj=#{compareObj} and
date=#{date} and
code=#{code}
</select>
<insert id="batchSave" parameterType="java.util.List">
insert into test_obj_score_cal_result(
compare_id, compare_obj, compare_obj_desc, ind_ids, date, score_value, improve_value,
score_sum_value, ind_count, code)
values
<foreach collection="datas" item="val" separator=",">
(
#{val.compareId}, #{val.compareObj}, #{val.compareObjDesc}, #{val.indIds}, #{val.date},
#{val.scoreValue},#{val.improveValue},#{val.scoreSumValue},#{val.indCount},#{val.code})
</foreach>
</insert>
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="datas" item="val" separator=";">
update test_obj_score_cal_result
<set>
<if test="val.compareId != null">
compare_id = #{val.compareId},
</if>
<if test="val.compareObj != null">
compare_obj = #{val.compareObj},
</if>
<if test="val.compareObjDesc != null">
compare_obj_desc = #{val.compareObjDesc},
</if>
<if test="val.indIds != null">
ind_ids = #{val.indIds},
</if>
<if test="val.date != null">
date = #{val.date},
</if>
<if test="val.scoreValue != null">
score_value = #{val.scoreValue},
</if>
<if test="val.improveValue != null">
improve_value = #{val.improveValue},
</if>
<if test="val.scoreSumValue != null">
score_sum_value = #{val.scoreSumValue},
</if>
<if test="val.indCount != null">
ind_count = #{val.indCount},
</if>
<if test="val.code != null">
code = #{val.code},
</if>
</set>
where id = ${val.id}
</foreach>
</update>
</mapper>
\ No newline at end of file
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