Commit aaf10b50 by dengwei

多层权重计算逻辑实现

parent b6ae7575
...@@ -31,4 +31,7 @@ public interface WeightIndValueMapper extends BaseMapper<WeightIndValue> { ...@@ -31,4 +31,7 @@ public interface WeightIndValueMapper extends BaseMapper<WeightIndValue> {
void batchDeleteByWeightIds(@Param("ids") List<Integer> ids); void batchDeleteByWeightIds(@Param("ids") List<Integer> ids);
WeightIndValue findByIndIdAndObjId(@Param("indId") String indId,
@Param("objId") String objId);
} }
...@@ -8,6 +8,9 @@ import java.util.Map; ...@@ -8,6 +8,9 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.keymobile.indicators.model.entity.dataenter.TaskRuleIndicator;
import com.keymobile.indicators.model.entity.weight.WeightIndValue;
import com.keymobile.indicators.model.mapper.weight.WeightIndValueMapper;
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;
...@@ -40,6 +43,10 @@ public class ScoreRuleService { ...@@ -40,6 +43,10 @@ public class ScoreRuleService {
private DriveIndCalResultDefMapper driveIndCalResultDefMapper; private DriveIndCalResultDefMapper driveIndCalResultDefMapper;
@Autowired @Autowired
private ObjScoreCalResultMapper objScoreCalResultMapper; private ObjScoreCalResultMapper objScoreCalResultMapper;
@Autowired
private DriveIndDefService driveIndDefService;
@Autowired
private WeightIndValueMapper weightIndValueMapper;
private static final Pattern P = Pattern.compile("(\\[[^\\]]*\\])"); private static final Pattern P = Pattern.compile("(\\[[^\\]]*\\])");
...@@ -534,9 +541,12 @@ public class ScoreRuleService { ...@@ -534,9 +541,12 @@ public class ScoreRuleService {
}else if("2".equals(scoreRule.getCalType())){//2单个指标权重计算 }else if("2".equals(scoreRule.getCalType())){//2单个指标权重计算
objScoreCalResult = this.calSingleIndWeight(compareCatalog,objScoreCalResult ,scoreRule, objScoreCalResult = this.calSingleIndWeight(compareCatalog,objScoreCalResult ,scoreRule,
compareObj, date, code, dateMark); compareObj, date, code, dateMark);
}else {//3:指标总得分 }else if ("3".equals(scoreRule.getCalType())){//3:指标总得分
objScoreCalResult = this.calGroupIndAverageOrSum(compareCatalog,objScoreCalResult, objScoreCalResult = this.calGroupIndAverageOrSum(compareCatalog,objScoreCalResult,
scoreRule, compareObj, date, scoreRule.getCalType(),code,dateMark); scoreRule, compareObj, date, scoreRule.getCalType(),code,dateMark);
}else {//4:多层权重
objScoreCalResult = this.calMoreIndWeight(compareCatalog,objScoreCalResult ,scoreRule,
compareObj, date, code, dateMark);
} }
objScoreCalResult.setCompareCatalog(compareCatalog); objScoreCalResult.setCompareCatalog(compareCatalog);
objScoreCalResult.setCompareId(compareId); objScoreCalResult.setCompareId(compareId);
...@@ -578,7 +588,176 @@ public class ScoreRuleService { ...@@ -578,7 +588,176 @@ public class ScoreRuleService {
logger.info("单位评分卡id:"+scoreRuleId+" 不存在"); logger.info("单位评分卡id:"+scoreRuleId+" 不存在");
} }
} }
/**
* 多层权重计算
* @param compareCatalog
* @param objScoreCalResult
* @param scoreRule
* @param compareObj
* @param date
* @param code
* @param dateMark
* @return
*/
private ObjScoreCalResult calMoreIndWeight(String compareCatalog, ObjScoreCalResult objScoreCalResult, ScoreRule scoreRule, String compareObj, int date, String code, int dateMark) {
objScoreCalResult.setCompareObj(compareObj);
objScoreCalResult.setScoreValue("0.0");
objScoreCalResult.setImproveValue("0.0");
objScoreCalResult.setDate(date);
//改用添加对标单元目录过滤
List<DriveIndCalResultDef> calResults = driveIndCalResultDefMapper.
findByCompareCatalogAndCompareObjAndDate(compareCatalog,compareObj,
date, code, dateMark);
int indCount = 0;//定义用户记录纳入考核指标个数
// 单个指标最终的得分 = 指标分数 * 综合评价权重(改善提升权重) * 维度权重
List<String> improveValues = new ArrayList<>();
List<String> scoreValues = new ArrayList<>();
if(!calResults.isEmpty()) {
objScoreCalResult.setCompareObjDesc(calResults.get(0).getCompareObjDesc());
StringBuilder groupIndIds = new StringBuilder();
for (DriveIndCalResultDef calResult : calResults) {
//根据考核指标id获取考核指标
DriveIndDef driveIndDef = driveIndDefService.getIndById(calResult.getIndId(), true);
WeightIndValue weightIndValue = weightIndValueMapper.findByIndIdAndObjId(calResult.getIndId(), compareObj);
if(driveIndDef != null) {
//如果考核指标是参与单位计分的
if(StringUtils.isBlank(driveIndDef.getIsUnitCalScore()) || "1".equals(driveIndDef.getIsUnitCalScore())) {
// 判断该指标是否为多合一指标(是:1 否:0)
if ("1".equals(driveIndDef.getIsMoreThanOneIndicators())) {
indCount += 1;
// 判断同组内的其他指标是否已经计算
if (!StringUtils.contains(groupIndIds.toString(), driveIndDef.getIndId())) {
// 获取组内指标
List<TaskRuleIndicator> indicators = driveIndDef.getIndicators();
BigDecimal dimensionWeight = BigDecimal.ZERO;
if (weightIndValue.getDimensionWeight() != null) {
dimensionWeight = weightIndValue.getDimensionWeight().divide(new BigDecimal(100));
}
// 获取多合一指标中的最大指标值
Map<String, String> map = getMaxIndValue(driveIndDef, calResult, compareCatalog, compareObj, date, code, dateMark);
if (!StringUtils.equals("0.0", map.get("maxScore"))) {
BigDecimal score = new BigDecimal(map.get("maxScore"));
BigDecimal synthesizeWeight = BigDecimal.ZERO;
if (weightIndValue.getSynthesizeWeight() != null) {
synthesizeWeight = weightIndValue.getSynthesizeWeight().divide(new BigDecimal(100));
}
BigDecimal finalScore = score.multiply(synthesizeWeight).multiply(dimensionWeight);
scoreValues.add(String.valueOf(finalScore));
}
if (!StringUtils.equals("0.0", map.get("maxImproveScore"))) {
BigDecimal improveScore = new BigDecimal(map.get("maxImproveScore"));
BigDecimal improveWeight = BigDecimal.ZERO;
if (weightIndValue.getImproveWeight() != null) {
improveWeight = weightIndValue.getImproveWeight().divide(new BigDecimal(100));
}
BigDecimal finalImproveScore = improveScore.multiply(improveWeight).multiply(dimensionWeight);
improveValues.add(String.valueOf(finalImproveScore));
}
for (TaskRuleIndicator indicator : indicators) {
groupIndIds.append(indicator.getIndId());
}
}
}else {
indCount += 1;
BigDecimal dimensionWeight = BigDecimal.ZERO;
if (weightIndValue.getDimensionWeight() != null) {
dimensionWeight = weightIndValue.getDimensionWeight().divide(new BigDecimal(100));
}
if(!"No".equals(calResult.getImproveScore()) && StringUtils.isNotBlank(calResult.getImproveScore())) {
BigDecimal improveScore = new BigDecimal(calResult.getImproveScore());
BigDecimal improveWeight = BigDecimal.ZERO;
if (weightIndValue.getImproveWeight() != null) {
improveWeight = weightIndValue.getImproveWeight().divide(new BigDecimal(100));
}
BigDecimal finalImproveScore = improveScore.multiply(improveWeight).multiply(dimensionWeight);
improveValues.add(String.valueOf(finalImproveScore));
}
if(!"NaN".equals(calResult.getValue()) && !"Infinite".equals(calResult.getValue()) && !"0".equals(calResult.getValue())) {
BigDecimal score = new BigDecimal(calResult.getScore());
BigDecimal synthesizeWeight = BigDecimal.ZERO;
if (weightIndValue.getSynthesizeWeight() != null) {
synthesizeWeight = weightIndValue.getSynthesizeWeight().divide(new BigDecimal(100));
}
BigDecimal finalScore = score.multiply(synthesizeWeight).multiply(dimensionWeight);
scoreValues.add(String.valueOf(finalScore));
}
}
}
}
}
String averageImproveValue = "0.0";
String improveSumValue = "0.0";
String scoreTmpSumValue = CalculateUtils.sumValue(scoreValues);
if(!improveValues.isEmpty()) {
improveSumValue = CalculateUtils.sumValue(improveValues);
averageImproveValue = improveSumValue;
}
//计算总积分
Double scoreSumValue = (Double.parseDouble(CalculateUtils.sumValue(scoreValues)) + Double.parseDouble(CalculateUtils.sumValue(improveValues)));
objScoreCalResult.setScoreSumValue(String.valueOf(scoreSumValue));
objScoreCalResult.setIndCount(indCount);
objScoreCalResult.setScoreValue(String.valueOf(scoreSumValue));
objScoreCalResult.setImproveValue(averageImproveValue);
objScoreCalResult.setImproveSumValue(improveSumValue);
objScoreCalResult.setScoreTmpSumValue(scoreTmpSumValue);
objScoreCalResult.setScoreTmpValue(scoreTmpSumValue);
}
return objScoreCalResult;
}
/**
* 获取多合一指标的最大值
* @param driveIndDef 指标对象
* @param calResult
* @param compareCatalog
* @param compareObj
* @param date
* @param code
* @param dateMark
* @return 最大值集合
*/
private Map<String, String> getMaxIndValue(DriveIndDef driveIndDef, DriveIndCalResultDef calResult, String compareCatalog, String compareObj, int date, String code, int dateMark) {
List<TaskRuleIndicator> indicators = driveIndDef.getIndicators();
Map<String, String> map = new HashMap<>();
String maxScore = "0.0";
String maxImproveScore = "0.0";
if(!"No".equals(calResult.getImproveScore()) && StringUtils.isNotBlank(calResult.getImproveScore())) {
maxImproveScore = calResult.getImproveScore();
}
if(!"NaN".equals(calResult.getValue()) && !"Infinite".equals(calResult.getValue()) && !"0".equals(calResult.getValue())) {
maxScore = calResult.getScore();
}
for (TaskRuleIndicator indicator : indicators) {
// 获取组内指标的指标积分对象
DriveIndCalResultDef driveIndCalResultDef = driveIndCalResultDefMapper.findByCompareCatalogAndCompareObjAndIndIdAndDate(compareCatalog, compareObj,
indicator.getIndId(), date, code, dateMark);
if(!"No".equals(driveIndCalResultDef.getImproveScore()) && StringUtils.isNotBlank(driveIndCalResultDef.getImproveScore())) {
// 比较大小
BigDecimal improveScore = new BigDecimal(driveIndCalResultDef.getImproveScore());
// 计算两个指标改善提升分数的差值
double poor = improveScore.subtract(new BigDecimal(maxImproveScore)).doubleValue();
// 差值大于0,则说明该指标的改善提升分数更大
if (poor > 0) {
maxImproveScore = driveIndCalResultDef.getImproveScore();
}
}
if(!"NaN".equals(driveIndCalResultDef.getValue()) && !"Infinite".equals(driveIndCalResultDef.getValue()) && !"0".equals(driveIndCalResultDef.getValue())) {
// 比较大小
BigDecimal score = new BigDecimal(driveIndCalResultDef.getScore());
// 计算两个指标改善提升分数的差值
double poor = score.subtract(new BigDecimal(maxScore)).doubleValue();
if (poor > 0) {
maxScore = driveIndCalResultDef.getScore();
}
}
}
map.put("maxScore", maxScore);
map.put("maxImproveScore", maxImproveScore);
return map;
}
private ScoreRule changeJson(ScoreRule scoreRule) { private ScoreRule changeJson(ScoreRule scoreRule) {
Gson gson = new Gson(); Gson gson = new Gson();
if(StringUtils.isNotBlank(scoreRule.getIndTypeWeightsJson())) { if(StringUtils.isNotBlank(scoreRule.getIndTypeWeightsJson())) {
......
...@@ -34,4 +34,9 @@ ...@@ -34,4 +34,9 @@
</foreach> </foreach>
</update> </update>
<select id="findByIndIdAndObjId" resultType="com.keymobile.indicators.model.entity.weight.WeightIndValue">
select * from weight_ind_value
where ind_id = #{indId} and obj_id = #{objId} and state = 1
</select>
</mapper> </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