Browse Source

新增计算类指标项明细表,实现计算指标明细数据新增,支持求多个数据最大值函数的解析

‘xugp 1 year ago
parent
commit
84fe534f38

+ 22 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/CalculateIndicatorItemInfoMapper.java

@@ -0,0 +1,22 @@
+package com.ims.eval.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ims.eval.entity.BinSection;
+import com.ims.eval.entity.CalculateIndicatorItmeInfo;
+import jdk.internal.dynalink.linker.LinkerServices;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 计算指标明细 Mapper 接口
+ * </p>
+ *
+ * @author xugp
+ * @since 2023-03-26
+ */
+public interface CalculateIndicatorItemInfoMapper extends BaseMapper<CalculateIndicatorItmeInfo> {
+
+	List<CalculateIndicatorItmeInfo> selectList(String organizationType,String checkCycle,String year,String month);
+
+}

+ 19 - 18
ims-service/ims-eval/src/main/java/com/ims/eval/entity/OrganizationIndicatorItmeInfo.java

@@ -6,13 +6,13 @@ import lombok.Data;
 /**
  * @author :xugp
  * @date :Created in 2023/3/25 16:43
- * @description:考评指标项明细
+ * @description:计算指标项明细
  * @modified By:
  * @version: $
  */
 
 @Data
-public class OrganizationIndicatorItmeInfo extends Model {
+public class CalculateIndicatorItmeInfo extends Model {
 
 	private static final long serialVersionUID = 1L;
 
@@ -22,44 +22,45 @@ public class OrganizationIndicatorItmeInfo extends Model {
 	private String id;
 
 	/**
-	 * 指标id
+	 * 考评类别(单位、部门)
 	 */
-	private String indicatorId;
+	private String organizationType;
 
 	/**
-	 * 生成经营id
+	 * 周期
 	 */
-	private String sectionId;
+	private String checkCycle;
 
 	/**
-	 * 差值最小值
+	 * 
 	 */
-	private String minnum;
+	private String year;
 
 	/**
-	 * 差值最大值
+	 * 
 	 */
-	private String maxnum;
+	private String month;
 
 	/**
-	 * 利润贡献考核最小值
+	 * 指标id
 	 */
-	private String minLrgxl;
+	private String indicatorId;
 
 	/**
-	 * 利润贡献考核最大值
+	 * 生产经营id
 	 */
-	private String maxLrgxl;
+	private String sectionId;
 
 	/**
-	 * 单位利润千瓦最小值
+	 * 指标项编码
 	 */
-	private String minDwlrqw;
+	private String optionCode;
 
 	/**
-	 * 单位利润千瓦最大
+	 * 编码
 	 */
-	private String maxDwlrqw;
+	private double quantifiedValue;
+
 
 
 }

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

@@ -19,8 +19,8 @@ public enum SelfMathFormulaEnum {
 		exp("exp", 1, 3,"exp()", "返回 e 的指数"),
 		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 中的最低值"),
+		//max("max", 2, 3,"max(,)", "返回 x 和 y 中的最高值"),
+		//min("min", 2, 3,"min(,)", "返回 x 和 y 中的最低值"),
 		pow("pow", 2, 3,"pow(,)", "返回 x 的 y 次幂"),
 		round("round", 1, 5,"round()", "把数四舍五入为最接近的整数"),
 		sin("sin", 1, 3,"sin()", "返回数的正弦"),
@@ -28,7 +28,7 @@ public enum SelfMathFormulaEnum {
 		tan("tan", 1, 3,"tan()", "返回角的正切"),
 	    ifs("if",3, 2,"if(,,)", "if表达式"),
 		maxnum("maxnum",1,6,"maxnum()","返回一组数据的最大值"),
-	    minnum("maxnum",1,6,"minnum()","返回一组数据的最小值");
+	    minnum("minnum",1,6,"minnum()","返回一组数据的最小值");
 
 
 		/**

+ 60 - 53
ims-service/ims-eval/src/main/java/com/ims/eval/schedule/ScoreCalculationSchedule.java

@@ -49,6 +49,9 @@ public class ScoreCalculationSchedule {
 	@Autowired
 	private IEvaluationScoreCountService iEvaluatioinScoreCountService;
 
+	@Autowired
+	private CalculateIndicatorItemInfoMapper calculateIndicatorItemInfoMapper;
+
 	/*@Scheduled(cron = "* 10 11 ? * 3")*/
 	public boolean doTask(){
 
@@ -117,6 +120,13 @@ public class ScoreCalculationSchedule {
 		//判断可用量化的进行变量替换
 		if ("是".equals(list.get(0).getIsQuantified())){
 			Map<String, Double> doubleMap = list.stream().collect(Collectors.toMap(OrganizationEvaluationInfo::getOptionCode, OrganizationEvaluationInfo::getQuantifiedValue));
+			//添加计算指标项的code和值  例如:差值最大值和最小值
+			OrganizationEvaluation organizationEvaluation = organizationEvaluationMapper.selectById(list.get(0).getOrganizationEvaluationId());
+			List<CalculateIndicatorItmeInfo> calculateIndicatorItmeInfos = calculateIndicatorItemInfoMapper.selectList(organizationEvaluation.getOrganizationType(),organizationEvaluation.getCheckCycle(),organizationEvaluation.getYear(),organizationEvaluation.getMonth());
+			calculateIndicatorItmeInfos.stream().forEach(r ->{
+				doubleMap.put(r.getOptionCode(),r.getQuantifiedValue());
+			});
+			//查询得分规则公式
 			QueryWrapper<IntervalScoringTable> qw = new QueryWrapper<>();
 			if (StringUtils.isNotEmpty(evaluationScoringRule.getId())) {
 				qw.lambda().eq(IntervalScoringTable::getRuleId,evaluationScoringRule.getId());
@@ -124,7 +134,6 @@ public class ScoreCalculationSchedule {
 			List<IntervalScoringTable> intervalScoringTables = intervalScoringTableMapper.selectList(qw);
 			for (Map.Entry<String, Double> entry : doubleMap.entrySet()){
 				intervalScoringTables.stream().forEach(r ->{
-
 					r.setRange(r.getRange().replaceAll(entry.getKey(), entry.getValue() + ""));
 					r.setRegularExpression(r.getRegularExpression().replaceAll(entry.getKey(),entry.getValue() + ""));
 				});
@@ -196,57 +205,55 @@ public class ScoreCalculationSchedule {
 
 
 
-	public static void main(String[] args) {
-
-
-		String sc = "max(sc,sd)+maxnum(sc)";
-		boolean contains = sc.contains("maxnum");
-
-		System.out.println(contains);
-
-		String s2 = "if(if(2>0,max(1,2)+20,min(1,3)+10)>11,12,if(2<0,min(5,4)+1,max(1,3)+2))";
-
-		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(s4);
-
-		//使用不同编码代替函数
-		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 sc = "maxnum(1)";
+//
+//
+//		String s2 = "if(if(2>0,max(1,2)+20,min(1,3)+10)>11,12,if(2<0,min(5,4)+1,max(1,3)+2))";
+//
+//		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);
+//
+//	}
 
 }

+ 20 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/ICalculateIndicatorItemInfoService.java

@@ -0,0 +1,20 @@
+package com.ims.eval.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ims.eval.entity.BinSection;
+import com.ims.eval.entity.CalculateIndicatorItmeInfo;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 计算指标项明细 服务类
+ * </p>
+ *
+ * @author xugp
+ * @since 2023-03-26
+ */
+public interface ICalculateIndicatorItemInfoService extends IService<CalculateIndicatorItmeInfo> {
+
+	int save(String organizationType,String checkCycle,String year,String month) throws Exception;
+}

+ 143 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/CalculateIndicatorItemInfoServiceImpl.java

@@ -0,0 +1,143 @@
+package com.ims.eval.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ims.common.utils.StringUtils;
+import com.ims.eval.config.CustomException;
+import com.ims.eval.dao.*;
+import com.ims.eval.entity.BinSection;
+import com.ims.eval.entity.CalculateIndicatorItmeInfo;
+import com.ims.eval.entity.OrganizationEvaluation;
+import com.ims.eval.entity.OrganizationEvaluationInfo;
+import com.ims.eval.service.IBinSectionService;
+import com.ims.eval.service.ICalculateIndicatorItemInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 计算指标项明细 服务实现类
+ * </p>
+ *
+ * @author xugp
+ * @since 2023-03-26
+ */
+@Service
+public class CalculateIndicatorItemInfoServiceImpl extends ServiceImpl<CalculateIndicatorItemInfoMapper, CalculateIndicatorItmeInfo> implements ICalculateIndicatorItemInfoService {
+
+
+	@Autowired
+	private OrganizationEvaluationInfoMapper organizationEvaluationInfoMapper;
+
+	@Autowired
+	private OrganizationEvaluationMapper organizationEvaluationMapper;
+
+	@Autowired
+	private CalculateIndicatorItemInfoMapper calculateIndicatorItemInfoMapper;
+
+	@Autowired
+	private IndicatorMapper indicatorMapper;
+
+	@Override
+	public int save(String organizationType,String checkCycle, String year,String month) throws Exception {
+
+		List<CalculateIndicatorItmeInfo> list = new ArrayList<>();
+		//加载单位/部门考评记录
+		QueryWrapper<OrganizationEvaluation> or = new QueryWrapper<>();
+
+		if (StringUtils.isNotEmpty(organizationType)) {
+			or.lambda().eq(OrganizationEvaluation::getOrganizationType, organizationType);
+		}
+
+		if (StringUtils.isNotEmpty(checkCycle)) {
+			or.lambda().eq(OrganizationEvaluation::getCheckCycle, checkCycle);
+		}
+		if (StringUtils.isNotEmpty(year)) {
+			or.lambda().eq(OrganizationEvaluation::getYear, year);
+		}
+
+		if (StringUtils.isNotEmpty(month)) {
+			or.lambda().eq(OrganizationEvaluation::getMonth, month);
+		}
+
+		List<OrganizationEvaluation> organizationEvaluations = organizationEvaluationMapper.selectList(or);
+		if (organizationEvaluations.size() <= 0) {
+			throw new Exception("考评记录为空!!!");
+		}
+
+		for (OrganizationEvaluation organizationEvaluation : organizationEvaluations) {
+			//加载该考评记录下的考评指标明细数据
+			QueryWrapper<OrganizationEvaluationInfo> qw = new QueryWrapper<>();
+			if (StringUtils.isNotEmpty(organizationEvaluation.getOrganizationEvaluationRuleId())) {
+				qw.lambda().in(OrganizationEvaluationInfo::getOrganizationEvaluationRuleId, organizationEvaluation.getOrganizationEvaluationRuleId());
+			}
+			List<OrganizationEvaluationInfo> organizationEvaluationInfos = organizationEvaluationInfoMapper.selectList(qw);
+			//对考评规则id进行分组
+			Map<String, List<OrganizationEvaluationInfo>> collect = organizationEvaluationInfos.stream().collect(Collectors.groupingBy(OrganizationEvaluationInfo::getOrganizationEvaluationRuleId));
+			for (Map.Entry<String, List<OrganizationEvaluationInfo>> entry : collect.entrySet()) {
+				if (entry.getValue().size() > 0) {
+					//对指标id进行分组
+					Map<String, List<OrganizationEvaluationInfo>> collectIn = entry.getValue().stream().collect(Collectors.groupingBy(OrganizationEvaluationInfo::getIndicatorId));
+					for (Map.Entry<String, List<OrganizationEvaluationInfo>> listEntry : collectIn.entrySet()) {
+						List<OrganizationEvaluationInfo> listEntryValue = listEntry.getValue();
+						listEntryValue.stream().forEach(r -> {
+							if (r.getOptionCode().equals("CZ") || r.getOptionCode().equals("LRGXKL") || r.getOptionCode().equals("DWQWLR")) {
+								CalculateIndicatorItmeInfo calculateIndicatorItmeInfo = new CalculateIndicatorItmeInfo();
+								calculateIndicatorItmeInfo.setIndicatorId(listEntry.getKey());
+								calculateIndicatorItmeInfo.setOptionCode(r.getOptionCode());
+								calculateIndicatorItmeInfo.setQuantifiedValue(r.getQuantifiedValue());
+								calculateIndicatorItmeInfo.setSectionId(indicatorMapper.selectById(listEntry.getKey()).getBinSection());
+								calculateIndicatorItmeInfo.setOrganizationType(organizationEvaluation.getOrganizationType());
+								calculateIndicatorItmeInfo.setCheckCycle(organizationEvaluation.getCheckCycle());
+								calculateIndicatorItmeInfo.setYear(organizationEvaluation.getYear());
+								calculateIndicatorItmeInfo.setMonth(organizationEvaluation.getMonth());
+								list.add(calculateIndicatorItmeInfo);
+							}
+						});
+					}
+				}
+			}
+		}
+		return saveCalculate(list);
+	}
+
+
+	public int saveCalculate(List<CalculateIndicatorItmeInfo> list) throws Exception {
+		//遍历list解析最大值和最小值
+		if (list.size() > 0){
+			Map<String, List<CalculateIndicatorItmeInfo>> collect = list.stream().collect(Collectors.groupingBy(CalculateIndicatorItmeInfo::getOptionCode));
+			for (Map.Entry<String, List<CalculateIndicatorItmeInfo>> listEntry : collect.entrySet()){
+				CalculateIndicatorItmeInfo maxNum = listEntry.getValue().stream().max(Comparator.comparing(CalculateIndicatorItmeInfo::getQuantifiedValue)).get();
+				CalculateIndicatorItmeInfo minNum = listEntry.getValue().stream().min(Comparator.comparing(CalculateIndicatorItmeInfo::getQuantifiedValue)).get();
+				if (listEntry.getKey().equals("CZ")){
+					//存储最大值
+					maxNum.setOptionCode("CZMAX");
+					calculateIndicatorItemInfoMapper.insert(maxNum);
+					//存储最小值
+					maxNum.setOptionCode("CZMIN");
+					calculateIndicatorItemInfoMapper.insert(minNum);
+				}else if (listEntry.getKey().equals("LRGXKL")){
+					maxNum.setOptionCode("LRGXKLMAX");
+					calculateIndicatorItemInfoMapper.insert(maxNum);
+					//存储最小值
+					maxNum.setOptionCode("LRGXKLMIN");
+					calculateIndicatorItemInfoMapper.insert(minNum);
+				}else if (listEntry.getKey().equals("DWQWLR")){
+					maxNum.setOptionCode("DWQWLRMAX");
+					calculateIndicatorItemInfoMapper.insert(maxNum);
+					//存储最小值
+					maxNum.setOptionCode("DWQWLRMIN");
+					calculateIndicatorItemInfoMapper.insert(minNum);
+				}
+
+			}
+		}else {
+			throw new Exception("计算指标项明细为空");
+		}
+		return 1;
+	}
+}

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

@@ -655,12 +655,12 @@ public class MathCalculatorUtil {
 			case log:
 				result = Math.log(Double.parseDouble(args[0]));
 				break;
-			case max:
+			/*case max:
 				result = Math.max(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
 				break;
 			case min:
 				result = Math.min(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
-				break;
+				break;*/
 			case pow:
 				result = Math.pow(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
 				break;
@@ -685,10 +685,10 @@ public class MathCalculatorUtil {
 				}
 				break;
 			case maxnum:
-				result = Math.tan(Double.parseDouble(args[0]));
+				result = Double.parseDouble(args[0]);
 				break;
 			case minnum:
-				result = Math.tan(Double.parseDouble(args[0]));
+				result = Double.parseDouble(args[0]);
 				break;
 			default:
 				throw new RuntimeException("找不到匹配的计算公式!");

+ 27 - 0
ims-service/ims-eval/src/main/resources/mappers/CalculateIndicatorItemInfoMapper.xml

@@ -0,0 +1,27 @@
+<?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.ims.eval.dao.CalculateIndicatorItemInfoMapper">
+
+    <select id="selectList" resultType="com.ims.eval.entity.CalculateIndicatorItmeInfo">
+        SELECT
+            *
+        FROM
+            calculate_indicator_item_info a
+        <where>
+            1=1
+            <if test="organizationType !=null and organizationType !=''">
+                and a.organizator_type=#{organizationType}
+            </if>
+            <if test="checkCycle !=null and checkCycle !=''">
+                and a.check_cycle=#{checkCycle}
+            </if>
+            <if test="year !=null and year !=''">
+                and a.year=#{year}
+            </if>
+            <if test="month !=null and month !=''">
+                and a.month=#{month}
+            </if>
+        </where>
+    </select>
+
+</mapper>