소스 검색

得分公式增加计算子指标数据

‘xugp 1 년 전
부모
커밋
bacc79911d

+ 3 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/OrganizationEvaluationInfoMapper.java

@@ -27,4 +27,7 @@ public interface OrganizationEvaluationInfoMapper extends BaseMapper<Organizatio
 																	  @Param("optionCode") String optionCode);
 
 	List<OrganizationEvaluationInfo> selectByEvaluationInfoId(@Param("organizationEvaluationId") String organizationEvaluationId);
+
+
+	List<OrganizationEvaluationInfo> selectByIndicatorDictionaryId(@Param("indicatorDictionaryId") String indicatorDictionaryId);
 }

+ 5 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/entity/IntervalScoringTable.java

@@ -36,6 +36,11 @@ public class IntervalScoringTable extends Model {
      */
     private String range;
 
+	/**
+	 * 子指标code
+	 */
+	private String code;
+
     /**
      * 规则描述
      */

+ 1 - 1
ims-service/ims-eval/src/main/java/com/ims/eval/entity/SelfMathFormulaEnum.java

@@ -20,7 +20,7 @@ public enum SelfMathFormulaEnum {
 		floor("floor", 1, 5,"floor()", "对数进行下舍入"),
 		log("log", 1, 3,"log()", "返回数的自然对数(底为e)"),
 		//max("max", 2, 3,"max(,)", "返回 x 和 y 中的最高值"),
-		//min("min", 2, 3,"min(,)", "返回 x 和 y 中的最低值"),
+		//	ints("int", 1, 4,"int()", "返回数的整数"),
 		pow("pow", 2, 3,"pow(,)", "返回 x 的 y 次幂"),
 		round("round", 1, 5,"round()", "把数四舍五入为最接近的整数"),
 		sin("sin", 1, 3,"sin()", "返回数的正弦"),

+ 109 - 70
ims-service/ims-eval/src/main/java/com/ims/eval/schedule/ScoreCalculationSchedule.java

@@ -50,6 +50,9 @@ public class ScoreCalculationSchedule {
 	@Autowired
 	private CalculateIndicatorItemInfoMapper calculateIndicatorItemInfoMapper;
 
+	@Autowired
+	private IndicatorDictionaryMapper indicatorDictionaryMapper;
+
 	/*@Scheduled(cron = "* 10 11 ? * 3")*/
 	public boolean doTask(String id){
 
@@ -96,20 +99,44 @@ public class ScoreCalculationSchedule {
 								e.lambda().eq(EvaluationScoringRule::getIndicatorId,indicator.getIndicatorCode());
 							}
 							EvaluationScoringRule evaluationScoringRule = evaluationScoringRuleMapper.selectOne(e);
-							if (evaluationScoringRule != null){
-								String calculation = replace(listEntry.getValue(), evaluationScoringRule);
-								log.info(indicator.getIndicatorCode()+"得分为" + calculation);
-								//将得分存入考评得分统计表
-								EvaluationScoreCount evaluationScoreCount = EvaluationScoreCount.builder()
-									.indicatorId(listEntry.getKey())
-									.organizationEvaluationRuleId(entry.getKey())
-									.organizationEvaluationId(organizationEvaluation.getId())
-									.score(Double.parseDouble(calculation))
-									.isQuantified("1")
-									.obversionScore(Double.parseDouble(calculation))
-									.build();
-								save = iEvaluatioinScoreCountService.save(evaluationScoreCount);
+							double calculation = 0;
+							if (indicator.getIsChild()){
+								//新建链表用来存储各个子指标得分
+								List<Double> strings = new ArrayList<>();
+								//对子指标进行分组
+								List<IndicatorDictionary> indicatorDictionaryList = indicatorDictionaryMapper.selectByIndicatorId(indicator.getId());
+								Map<String, List<IndicatorDictionary>> map = indicatorDictionaryList.stream().collect(Collectors.groupingBy(IndicatorDictionary::getChildCode));
+								for (Map.Entry<String, List<IndicatorDictionary>> stringListEntry : map.entrySet()){
+									stringListEntry.getValue().stream().forEach(r ->{
+										List<OrganizationEvaluationInfo> organizationEvaluationInfos1 = organizationEvaluationInfoMapper.selectByIndicatorDictionaryId(r.getId());
+										try {
+											String replace = replace(organizationEvaluationInfos1, evaluationScoringRule,stringListEntry.getKey());
+											strings.add(Double.parseDouble(replace));
+										} catch (Exception exception) {
+											log.info(exception.getMessage());
+										}
+									});
+								}
+								//各个子指标计算加和得分
+								calculation = strings.stream().reduce(0.0, (a, b) -> a + b);
+							}else {
+								if (evaluationScoringRule != null){
+									String s = replace(listEntry.getValue(), evaluationScoringRule,indicator.getIndicatorCode());
+									calculation = Double.parseDouble(s);
+									log.info(indicator.getIndicatorCode()+"得分为" + calculation);
+									//将得分存入考评得分统计表
+								}
 							}
+							//得分存入数据库
+							EvaluationScoreCount evaluationScoreCount = EvaluationScoreCount.builder()
+								.indicatorId(listEntry.getKey())
+								.organizationEvaluationRuleId(entry.getKey())
+								.organizationEvaluationId(organizationEvaluation.getId())
+								.score(calculation)
+								.isQuantified("1")
+								.obversionScore(calculation)
+								.build();
+							save = iEvaluatioinScoreCountService.save(evaluationScoreCount);
 						}
 					}
 				}
@@ -124,8 +151,9 @@ public class ScoreCalculationSchedule {
 		return save;
 	}
 
+
 	//中间变量替换为数据
-	public String replace(List<OrganizationEvaluationInfo> list,EvaluationScoringRule evaluationScoringRule) throws Exception {
+	public String replace(List<OrganizationEvaluationInfo> list,EvaluationScoringRule evaluationScoringRule,String code) throws Exception {
 
 		String score = null;
 		//判断可用量化的进行变量替换
@@ -175,7 +203,7 @@ public class ScoreCalculationSchedule {
 					r.setRegularExpression(r.getRegularExpression().replaceAll(neatDTo.getCode(),neatDTo.getValue() + ""));
 				}
 			}
-			//针对只有一种区间评分
+			//针对单个子指标计算
 			if (intervalScoringTables.size() == 1){
 				String regularExpression = intervalScoringTables.get(0).getRegularExpression();
 				log.info(evaluationScoringRule.getScoreRuleName()+ "公式为" + regularExpression);
@@ -185,16 +213,26 @@ public class ScoreCalculationSchedule {
 					score = "0";
 				}
 			} else if(intervalScoringTables.size() > 1){
-				//针对多区间评分
+				//针对多个子指标计算
 				for (IntervalScoringTable intervalScoringTable : intervalScoringTables){
-					String range = intervalScoringTable.getRange();
-					if (rangeHandle(range)){
-						score =  MathCalculatorUtil.handle(intervalScoringTable.getRegularExpression().trim());
+					if (code.equals(intervalScoringTable.getCode())){
+						String regularExpression = intervalScoringTable.getRegularExpression();
+						log.info(evaluationScoringRule.getScoreRuleName()+ "公式为" + regularExpression);
+						//公式计算得分
+						score = MathCalculatorUtil.handle(regularExpression.trim());
 						if (!StringUtils.isNotEmpty(score)){
 							score = "0";
 						}
-						break;
 					}
+					break;
+//					String range = intervalScoringTable.getRange();
+//					if (rangeHandle(range)){
+//						score =  MathCalculatorUtil.handle(intervalScoringTable.getRegularExpression().trim());
+//						if (!StringUtils.isNotEmpty(score)){
+//							score = "0";
+//						}
+//						break;
+//					}
 				}
 			}
 		}else {
@@ -248,55 +286,56 @@ public class ScoreCalculationSchedule {
 
 
 
-//	public static void main(String[] args) {
-//
-//
-//		String sc = "if(10+1*2/maxnum(1)>12,12,if(1<0,10-1*2/minnum(1),10+1*2/maxnum(1)))";
-//
-//
-//		String s2 = "if(1>0,-1*2/maxnum(2)+10,1*2/minnum(1)+10)";
-//
-//		String s4 = "if(0.01<0,-0.01*2/min(1,0.07)+10,1/1*2/max(4,0.07)+10)";
-//		String s5 = "1+if(if(1<0,-1*2/min(2,1)+10,1*2/max(2,1)+10)>12,12,if(1<0,-1*2/min(2,1)+10,1*2/max(2,1)+10))";
-//		String s3 = "if(abs(99)<=5%,if(abs(99)>=1%,(5%-abs(99))/1%*0.25+5,6),if(abs(99)<=10%,(5%-abs(99))/1%*0.2+5,4))+if(99==0,5,if(99>0,6,4))";
-//		/*String sd = "max(1,min(1,2))";
-//		String sc = MathCalculatorUtil.calculator(sd);*/
-//		String ss = "if(max(1,3)<1,1,2)";
-//		String s9 = "maxmin()";
-//		ArrayList<Token> tokens = Analyzer.getTokens(sc);
-//
-//		//使用不同编码代替函数
-//		AlarmExpression alarmExpression = Analyzer.createAlarmExpression(tokens);
-//		if (alarmExpression.getVarList() != null && alarmExpression.getVarList().size() > 0) {
-//			List<AlarmExpression> alarmExpressions = alarmExpression.getChildren();
-//			for (AlarmExpression alarmExpression1 : alarmExpressions){
-//				if (alarmExpression1.getChildren().size() > 0 && alarmExpression1.getChildren() != null){
-//					for (AlarmExpression alarmExpression2 : alarmExpression1.getChildren()){
-//						if (alarmExpression2.getChildren().size() > 0 && alarmExpression2.getChildren() != null){
-//							List<AlarmExpression> al = alarmExpression2.getChildren();
-//							for (AlarmExpression alarmExpression3 : al){
-//								String calculator = MathCalculatorUtil.calculator(alarmExpression3.getExpression());
-//								alarmExpression2.setExpression(alarmExpression2.getExpression().replaceAll(alarmExpression3.getFunCode(), calculator));
-//							}
-//						}
-//						String calculator = MathCalculatorUtil.calculator(alarmExpression2.getExpression());
-//						alarmExpression1.setExpression(alarmExpression1.getExpression().replaceAll(alarmExpression2.getFunCode(), calculator));
-//					}
-//					String calculator = MathCalculatorUtil.calculator(alarmExpression1.getExpression());
-//					alarmExpression.setExpression(alarmExpression.getExpression().replaceAll(alarmExpression1.getFunCode(), calculator));
-//				}else {
-//					String calculator = MathCalculatorUtil.calculator(alarmExpression1.getExpression());
-//					alarmExpression.setExpression(alarmExpression.getExpression().replaceAll(alarmExpression1.getFunCode(), calculator));
-//				}
-//			}
-//		}
-////		Map<String,Object> map = new HashMap<>();
-////		Object o = ScriptShell.parseExpr(alarmExpression.getExpression(), map);
-////		System.out.println(o);
-//		//判断表达式返回结果
-//		String calculator = MathCalculatorUtil.calculator(alarmExpression.getExpression());
-//		System.out.println(calculator);
-//
-//	}
+	public static void main(String[] args) {
+
+
+		String sv = "round(1.2)";
+		String sc = "if(1==0,8,8-0.5*round(0.08/0.04))";
+
+
+		String s2 = "if(1>0,-1*2/maxnum(2)+10,1*2/minnum(1)+10)";
+
+		String s4 = "if(0.01<0,-0.01*2/min(1,0.07)+10,1/1*2/max(4,0.07)+10)";
+		String s5 = "1+if(if(1<0,-1*2/min(2,1)+10,1*2/max(2,1)+10)>12,12,if(1<0,-1*2/min(2,1)+10,1*2/max(2,1)+10))";
+		String s3 = "if(abs(99)<=5%,if(abs(99)>=1%,(5%-abs(99))/1%*0.25+5,6),if(abs(99)<=10%,(5%-abs(99))/1%*0.2+5,4))+if(99==0,5,if(99>0,6,4))";
+		/*String sd = "max(1,min(1,2))";
+		String sc = MathCalculatorUtil.calculator(sd);*/
+		String ss = "if(max(1,3)<1,1,2)";
+		String s9 = "maxnum(1)";
+		ArrayList<Token> tokens = Analyzer.getTokens(sc);
+
+		//使用不同编码代替函数
+		AlarmExpression alarmExpression = Analyzer.createAlarmExpression(tokens);
+		if (alarmExpression.getVarList() != null && alarmExpression.getVarList().size() > 0) {
+			List<AlarmExpression> alarmExpressions = alarmExpression.getChildren();
+			for (AlarmExpression alarmExpression1 : alarmExpressions){
+				if (alarmExpression1.getChildren().size() > 0 && alarmExpression1.getChildren() != null){
+					for (AlarmExpression alarmExpression2 : alarmExpression1.getChildren()){
+						if (alarmExpression2.getChildren().size() > 0 && alarmExpression2.getChildren() != null){
+							List<AlarmExpression> al = alarmExpression2.getChildren();
+							for (AlarmExpression alarmExpression3 : al){
+								String calculator = MathCalculatorUtil.calculator(alarmExpression3.getExpression());
+								alarmExpression2.setExpression(alarmExpression2.getExpression().replaceAll(alarmExpression3.getFunCode(), calculator));
+							}
+						}
+						String calculator = MathCalculatorUtil.calculator(alarmExpression2.getExpression());
+						alarmExpression1.setExpression(alarmExpression1.getExpression().replaceAll(alarmExpression2.getFunCode(), calculator));
+					}
+					String calculator = MathCalculatorUtil.calculator(alarmExpression1.getExpression());
+					alarmExpression.setExpression(alarmExpression.getExpression().replaceAll(alarmExpression1.getFunCode(), calculator));
+				}else {
+					String calculator = MathCalculatorUtil.calculator(alarmExpression1.getExpression());
+					alarmExpression.setExpression(alarmExpression.getExpression().replaceAll(alarmExpression1.getFunCode(), calculator));
+				}
+			}
+		}
+//		Map<String,Object> map = new HashMap<>();
+//		Object o = ScriptShell.parseExpr(alarmExpression.getExpression(), map);
+//		System.out.println(o);
+		//判断表达式返回结果
+		String calculator = MathCalculatorUtil.calculator(alarmExpression.getExpression().trim());
+		System.out.println(calculator);
+
+	}
 
 }

+ 1 - 4
ims-service/ims-eval/src/main/java/com/ims/eval/util/MathCalculatorUtil.java

@@ -655,10 +655,7 @@ public class MathCalculatorUtil {
 			case log:
 				result = Math.log(Double.parseDouble(args[0]));
 				break;
-			/*case max:
-				result = Math.max(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
-				break;
-			case min:
+			/*case min:
 				result = Math.min(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
 				break;*/
 			case pow:

+ 15 - 0
ims-service/ims-eval/src/main/resources/mappers/OrganizationEvaluationInfoMapper.xml

@@ -91,4 +91,19 @@
             </if>
         </where>
     </select>
+
+    <select id="selectByIndicatorDictionaryId" resultType="com.ims.eval.entity.OrganizationEvaluationInfo">
+        SELECT
+        *
+        FROM
+        organization_evaluation_info a
+        <where>
+            1=1
+            <if test="indicatorDictionaryId !=null and indicatorDictionaryId !=''">
+                and a.indicator_dictionary_id=#{indicatorDictionaryId}
+            </if>
+        </where>
+    </select>
+
+
 </mapper>