Browse Source

feat(计算单元运算): 接口、接口参数计算单元

JoeLazy 2 months ago
parent
commit
5d0da45389

+ 56 - 3
src/main/java/com/sundata/internalevaluation/calc/calcUnit/InterfaceCalcUnit.java

@@ -1,11 +1,18 @@
 package com.sundata.internalevaluation.calc.calcUnit;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import com.sundata.common.util.JsonUtil;
 import com.sundata.internalevaluation.calc.model.CalcResult;
 import com.sundata.internalevaluation.calc.model.CalcUnit;
 import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import com.sundata.internalevaluation.configuration.model.SysInterface;
+import com.sundata.internalevaluation.configuration.model.SysInterfaceParam;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * Created by IntelliJ IDEA.
@@ -15,6 +22,11 @@ import java.util.Map;
  * @description: 接口计算单元
  */
 public class InterfaceCalcUnit extends CalcUnit {
+
+
+    private final SysInterface sysInterface;
+
+
     /**
      * 创建数据单元的绝对对象,对象必须包含如下参数
      *
@@ -23,8 +35,9 @@ public class InterfaceCalcUnit extends CalcUnit {
      * @param calcType    计算类型
      * @param initContext 计算单元初始化参数
      */
-    public InterfaceCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext) {
+    public InterfaceCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext, SysInterface sysInterface) {
         super(calcCode, calcName, calcType, initContext);
+        this.sysInterface = sysInterface;
     }
 
     /**
@@ -56,7 +69,11 @@ public class InterfaceCalcUnit extends CalcUnit {
      */
     @Override
     public List<CalcUnit> getSourceCalcUnits() {
-        return List.of();
+        List<SysInterfaceParam> paramList = sysInterface.getParamList();
+        List<CalcUnit> childCalcUnitList = paramList.stream()
+                .map(item ->new InterfaceParamCalcUnit(item.getParamObjName(), item.getParamChineseName(), CalcType.INTERFACEPARAM, Map.of(), item))
+                .collect(Collectors.toList());
+        return childCalcUnitList;
     }
 
     /**
@@ -88,7 +105,43 @@ public class InterfaceCalcUnit extends CalcUnit {
      * @param sourceResults           源头计算节点的结果
      */
     @Override
-    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+    public void calc(CalcResult<String, Object> thisResult,
+                     String calculateInstanceNumber,
+                     Map<String, Object> context,
+                     Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+
+        // 接口内容类型
+        String reqContentTypeCode = this.sysInterface.getReqContentTypeCode();
+        // 接口请求类型
+        String interfaceTypeCode = this.sysInterface.getInterfaceTypeCode();
+
+
+        // http请求或者 https请求
+        if (interfaceTypeCode.startsWith("http") && "json".equals(reqContentTypeCode)) {
+            Map<String, String> headersMap = new HashMap<>();
+            Map<String, Object> paramMap = new HashMap<>();
+
+            sourceResults.forEach((key, value) -> {
+                String calcCode = key.getCalcCode();
+                Object res = value.get(calcCode);
+                SysInterfaceParam entity = (SysInterfaceParam) value.get("entity");
 
+                // 判断是不是请求头
+                if ("true".equals(entity.getIsHeader())) {
+                    headersMap.put(entity.getParamObjName(), res.toString());
+                } else {
+                    paramMap.put(entity.getParamObjName(), res);
+                }
+            });
+            String url = interfaceTypeCode + "://" + sysInterface.getInterfaceIp() + ":" + sysInterface.getInterfacePort() + sysInterface.getInterfaceUrl();
+            HttpRequest postRequest = HttpUtil.createPost(url);
+            postRequest.addHeaders(headersMap);
+            postRequest.body(JsonUtil.toJSONString(paramMap));
+            String responseStr = postRequest.execute().body();
+            thisResult.put(getCalcCode(), JsonUtil.jsonToMap(responseStr));
+        } else {
+            // TODO Socket 请求
+            thisResult.put(getCalcCode(), "非http、https请求,并且参数不是json格式");
+        }
     }
 }

+ 175 - 0
src/main/java/com/sundata/internalevaluation/calc/calcUnit/InterfaceParamCalcUnit.java

@@ -0,0 +1,175 @@
+package com.sundata.internalevaluation.calc.calcUnit;
+
+import com.sundata.common.util.DBExecutor;
+import com.sundata.common.util.JsonUtil;
+import com.sundata.internalevaluation.calc.model.CalcResult;
+import com.sundata.internalevaluation.calc.model.CalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import com.sundata.internalevaluation.calc.util.InvokeUtil;
+import com.sundata.internalevaluation.configuration.model.SysInterfaceParam;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-13 16:23:55
+ * @description: 接口参数计算单元
+ */
+public class InterfaceParamCalcUnit extends CalcUnit {
+
+    /**
+     * 接口参数实体
+     */
+
+    private final SysInterfaceParam sysInterfaceParam;
+
+    /**
+     * 创建数据单元的绝对对象,对象必须包含如下参数
+     *
+     * @param calcCode    计算对象编号
+     * @param calcName    计算对象名称
+     * @param calcType    计算类型
+     * @param initContext 计算单元初始化参数
+     */
+    public InterfaceParamCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext, SysInterfaceParam sysInterfaceParam) {
+        super(calcCode, calcName, calcType, initContext);
+        this.sysInterfaceParam = sysInterfaceParam;
+    }
+
+    /**
+     * 判断是否已经计算过数据了
+     *
+     * @param calculateInstanceNumber 计算流水号
+     * @return 是否计算过 true 计算过 false 没有计算过
+     */
+    @Override
+    public boolean isCalcFinished(String calculateInstanceNumber) {
+        return false;
+    }
+
+    /**
+     * 初始化计算结果的方法,如果已经计算过,在实现过程中,应当在此方法中根据计算流水号重新初始化 resultContext 结果对象,为其他依赖对象做准备
+     * 若明明计算过本单元但再次计算时没有初始化该对象,则计算依赖出现问题无法定位与处理
+     *
+     * @param calculateInstanceNumber 计算流水号
+     */
+    @Override
+    public void initResultContext(String calculateInstanceNumber) {
+
+    }
+
+    /**
+     * 根据节点配置获取源节点;
+     *
+     * @return 所有源头节点
+     */
+    @Override
+    public List<CalcUnit> getSourceCalcUnits() {
+        return List.of();
+    }
+
+    /**
+     * 计算之后的方法,可实现为空
+     *
+     * @param context
+     */
+    @Override
+    public void afterCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 计算之前,可实现空
+     *
+     * @param context
+     */
+    @Override
+    public void beforeCalc(Map<String, Object> context) {
+
+    }
+
+    /**
+     * 必须实现的主体计算内容
+     *
+     * @param thisResult              本计算单元的结果
+     * @param calculateInstanceNumber 计算流水号
+     * @param context                 节点计算参数清单
+     * @param sourceResults           源头计算节点的结果
+     */
+    @Override
+    public void calc(CalcResult<String, Object> thisResult, String calculateInstanceNumber, Map<String, Object> context, Map<CalcUnit, CalcResult<String, Object>> sourceResults) {
+        // 参数获取类型
+        String paramRetrievalTypeCode = sysInterfaceParam.getParamRetrievalTypeCode();
+
+        // 参数获取内容
+        String paramRetrievalTypeCont = sysInterfaceParam.getParamRetrievalTypeCont();
+
+
+        Object result = null;
+
+        // 获取参数值
+        switch (paramRetrievalTypeCode) {
+            // 固定值
+            case "fixed":
+                result = paramRetrievalTypeCont;
+                break;
+            // java
+            //   获取参数内容
+            case "java":
+                try {
+                    result = InvokeUtil.invokeMethod(paramRetrievalTypeCont);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+                break;
+            // SQL-Map
+            case "sqlmap":
+                result = DBExecutor.doQuery(paramRetrievalTypeCont);
+                break;
+            // SQL-List
+            case "sqllist":
+                result = DBExecutor.doQueryMapList(paramRetrievalTypeCont);
+                break;
+            // SQL-String
+            case "sqlstring":
+                result = DBExecutor.doQuery(paramRetrievalTypeCont);
+                break;
+        }
+
+
+        String paramTypeCode = this.sysInterfaceParam.getParamTypeCode();
+        if ("string".equals(paramTypeCode)) {
+            if (result instanceof String) {
+
+            } else {
+                result = JsonUtil.toJSONString(result);
+            }
+        } else if ("number".equals(paramTypeCode)) {
+            if (result instanceof Number) {
+                if (result instanceof Integer) {
+                    result = ((Number) result).intValue();
+                } else if (result instanceof Long) {
+                    result = ((Number) result).longValue();
+                } else if (result instanceof Float) {
+                    result = ((Number) result).floatValue();
+                } else if (result instanceof Double) {
+                    result = ((Number) result).doubleValue();
+                } else if (result instanceof Short) {
+                    result = ((Number) result).shortValue();
+                } else if (result instanceof Byte) {
+                    result = ((Number) result).byteValue();
+                } else {
+                    throw new RuntimeException("数据类型不匹配:计算机过不为'数字'");
+                }
+
+            } else {
+                throw new RuntimeException("数据类型不匹配:计算机过不为'数字'");
+            }
+        }
+        thisResult.put(getCalcCode(), result);
+        thisResult.put("entity", sysInterfaceParam);
+    }
+}

+ 11 - 3
src/main/java/com/sundata/internalevaluation/calc/calcUnit/RuleCalcUnit.java

@@ -1,15 +1,19 @@
 package com.sundata.internalevaluation.calc.calcUnit;
 
+import cn.hutool.extra.spring.SpringUtil;
 import com.sundata.common.util.StringUtil;
 import com.sundata.internalevaluation.calc.model.CalcResult;
 import com.sundata.internalevaluation.calc.model.CalcUnit;
 import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import com.sundata.internalevaluation.configuration.model.IndexConfigModel;
 import com.sundata.internalevaluation.configuration.model.SysReqRule;
+import com.sundata.internalevaluation.configuration.service.IndexConfigService;
 import com.sundata.internalevaluation.script.ScriptUtil;
 import com.sundata.internalevaluation.script.TemplateUtil;
 
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * Created by IntelliJ IDEA.
@@ -22,6 +26,8 @@ public class RuleCalcUnit extends CalcUnit {
 
     private SysReqRule reqRule;
 
+    private final IndexConfigService indexConfigService;
+
     /**
      * 创建数据单元的绝对对象,对象必须包含如下参数
      *
@@ -33,6 +39,7 @@ public class RuleCalcUnit extends CalcUnit {
     public RuleCalcUnit(String calcCode, String calcName, CalcType calcType, Map<String, Object> initContext, SysReqRule reqRule) {
         super(calcCode, calcName, calcType, initContext);
         this.reqRule = reqRule;
+        this.indexConfigService = SpringUtil.getBean(IndexConfigService.class);
     }
 
     /**
@@ -55,7 +62,7 @@ public class RuleCalcUnit extends CalcUnit {
      */
     @Override
     public void initResultContext(String calculateInstanceNumber) {
-        // TODO  出书画数据??
+        // TODO  初始化数据??
     }
 
     /**
@@ -65,8 +72,9 @@ public class RuleCalcUnit extends CalcUnit {
      */
     @Override
     public List<CalcUnit> getSourceCalcUnits() {
-        // TODO  获取关联的所有指标
-        return List.of();
+        List<IndexConfigModel> indexConfigModels = indexConfigService.selectIndexListByRuleNo(this.reqRule.getRuleNo());
+        return indexConfigModels.stream()
+                .map(item -> new IndexCalcUnit(item.getIndexNo(), item.getIndexName(), Map.of(), item, indexConfigService)).collect(Collectors.toList());
     }
 
     /**

+ 60 - 0
src/main/java/com/sundata/internalevaluation/calc/custom/GetDataTest.java

@@ -0,0 +1,60 @@
+package com.sundata.internalevaluation.calc.custom;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-14 17:12:49
+ * @description: 测试Java方法获取参数
+ */
+public class GetDataTest {
+
+    private static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
+    private static final String YYYYMMDD = "yyyyMMdd";
+    private static final String HHMMSS = "HHmmss";
+    private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
+    private static final String YYYY_MM_DD = "yyyy-MM-dd";
+    private static final String HH_MM_SS = "HH:mm:ss";
+
+    public String getDateTimeNumber() {
+        return getStr(YYYYMMDDHHMMSS);
+    }
+    public String getDateNumber() {
+        return getStr(YYYYMMDD);
+    }
+    public String getTimeNumber() {
+        return getStr(HHMMSS);
+    }
+    public String getDateTime() {
+        return getStr(YYYY_MM_DD_HH_MM_SS);
+    }
+    public String getDate() {
+        return getStr(YYYY_MM_DD);
+    }
+    public String getTime() {
+        return getStr(HH_MM_SS);
+    }
+
+    public String getStr(String format) {
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
+        return simpleDateFormat.format(nowDate());
+    }
+
+    public Date nowDate() {
+        return new Date();
+    }
+
+
+    public int getInt(int i) {
+        return i;
+    }
+
+
+    public String getString(String str) {
+        return str;
+    }
+
+}

+ 16 - 3
src/main/java/com/sundata/internalevaluation/calc/model/finals/CalcType.java

@@ -2,9 +2,22 @@ package com.sundata.internalevaluation.calc.model.finals;
 
 public enum CalcType {
 
-    INTERFACE("接口"),RULE("规则"),RULES("规则集"),DATASET("数据集")
-    ,INDEX("指标"),INDEXLIST("指标清单"),MODEL("模型"),DATAITEM("数据项"),QUERYLOGIC("查询逻辑")
-    ,INPUTPARAM("输入参数"),DATASOURCES("数据来源")
+    INTERFACE("接口"),
+    INTERFACEPARAM("接口参数"),
+    RULE("规则"),
+    RULES("规则集"),
+    DATASET("数据集"),
+    INDEX("指标"),
+    INDEXLIST("指标清单"),
+    MODEL("模型"),
+    DATAITEM("数据项"),
+    QUERYLOGIC("查询逻辑"),
+    INPUTPARAM("输入参数"),
+
+
+    DATASOURCES("数据来源")
+
+
     ;
 
     private final String name ;

+ 168 - 0
src/main/java/com/sundata/internalevaluation/calc/util/InvokeUtil.java

@@ -0,0 +1,168 @@
+package com.sundata.internalevaluation.calc.util;
+
+import cn.hutool.extra.spring.SpringUtil;
+import org.apache.commons.lang3.StringUtils;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-14 17:50:48
+ * @description: 反射
+ */
+public class InvokeUtil {
+    /**
+     * 执行方法
+     *
+     * @param invokeTarget 执行任务的方式
+     */
+    public static Object invokeMethod(String invokeTarget) throws Exception {
+        String beanName = getBeanName(invokeTarget);
+        String methodName = getMethodName(invokeTarget);
+        List<Object[]> methodParams = getMethodParams(invokeTarget);
+
+        if (!isValidClassName(beanName)) {
+            Object bean = SpringUtil.getBean(beanName);
+            return invokeMethod(bean, methodName, methodParams);
+        } else {
+            Object bean = Class.forName(beanName).getDeclaredConstructor().newInstance();
+            return invokeMethod(bean, methodName, methodParams);
+        }
+    }
+
+    /**
+     * 调用任务方法
+     *
+     * @param bean         目标对象
+     * @param methodName   方法名称
+     * @param methodParams 方法参数
+     */
+    private static Object invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
+            throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
+            InvocationTargetException {
+        if (methodParams != null && !methodParams.isEmpty()) {
+            Method method = bean.getClass().getMethod(methodName, getMethodParamsType(methodParams));
+            return method.invoke(bean, getMethodParamsValue(methodParams));
+        } else {
+            Method method = bean.getClass().getMethod(methodName);
+            return method.invoke(bean);
+        }
+    }
+
+    /**
+     * 校验是否为为class包名
+     *
+     * @param invokeTarget 名称
+     * @return true是 false否
+     */
+    public static boolean isValidClassName(String invokeTarget) {
+        return StringUtils.countMatches(invokeTarget, ".") > 1;
+    }
+
+    /**
+     * 获取bean名称
+     *
+     * @param invokeTarget 目标字符串
+     * @return bean名称
+     */
+    public static String getBeanName(String invokeTarget) {
+        String beanName = StringUtils.substringBefore(invokeTarget, "(");
+        return StringUtils.substringBeforeLast(beanName, ".");
+    }
+
+    /**
+     * 获取bean方法
+     *
+     * @param invokeTarget 目标字符串
+     * @return method方法
+     */
+    public static String getMethodName(String invokeTarget) {
+        String methodName = StringUtils.substringBefore(invokeTarget, "(");
+        return StringUtils.substringAfterLast(methodName, ".");
+    }
+
+    /**
+     * 获取method方法参数相关列表
+     *
+     * @param invokeTarget 目标字符串
+     * @return method方法相关参数列表
+     */
+    public static List<Object[]> getMethodParams(String invokeTarget) {
+        //String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
+
+        int i1 = invokeTarget.indexOf("(");
+        int i2 = invokeTarget.lastIndexOf(")");
+        if (i1 == -1 || i2 == -1) {
+            return null;
+        }
+        String methodStr = invokeTarget.substring(i1 + 1, i2);
+
+        if (StringUtils.isEmpty(methodStr)) {
+            return null;
+        }
+        String[] methodParams = methodStr.split(",(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
+        List<Object[]> classs = new LinkedList<>();
+        for (int i = 0; i < methodParams.length; i++) {
+            //platformTask.insertDingShiLog('D:\testTask\tt','/yyyyMMdd/HH','^SDQX_(\d{14})_GOOD\.txt$','.txt',5181518636736516L,180000L,3,true)
+            String str = StringUtils.trimToEmpty(methodParams[i]);
+            // String字符串类型,以'或"开头
+            if (StringUtils.startsWithAny(str, "'", "\"")) {
+                classs.add(new Object[]{StringUtils.substring(str, 1, str.length() - 1), String.class});
+            }
+            // boolean布尔类型,等于true或者false
+            else if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str)) {
+                classs.add(new Object[]{Boolean.valueOf(str), Boolean.class});
+            }
+            // long长整形,以L结尾
+            else if (StringUtils.endsWith(str, "L")) {
+                classs.add(new Object[]{Long.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Long.class});
+            }
+            // double浮点类型,以D结尾
+            else if (StringUtils.endsWith(str, "D")) {
+                classs.add(new Object[]{Double.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Double.class});
+            }
+            // 其他类型归类为整形
+            else {
+                classs.add(new Object[]{Integer.valueOf(str), Integer.class});
+            }
+        }
+        return classs;
+    }
+
+    /**
+     * 获取参数类型
+     *
+     * @param methodParams 参数相关列表
+     * @return 参数类型列表
+     */
+    public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) {
+        Class<?>[] classs = new Class<?>[methodParams.size()];
+        int index = 0;
+        for (Object[] os : methodParams) {
+            classs[index] = (Class<?>) os[1];
+            index++;
+        }
+        return classs;
+    }
+
+    /**
+     * 获取参数值
+     *
+     * @param methodParams 参数相关列表
+     * @return 参数值列表
+     */
+    public static Object[] getMethodParamsValue(List<Object[]> methodParams) {
+        Object[] classs = new Object[methodParams.size()];
+        int index = 0;
+        for (Object[] os : methodParams) {
+            classs[index] = (Object) os[0];
+            index++;
+        }
+        return classs;
+    }
+}

+ 25 - 4
src/main/java/com/sundata/internalevaluation/configuration/controller/SysInterfaceController.java

@@ -1,13 +1,18 @@
 package com.sundata.internalevaluation.configuration.controller;
 
-import java.util.List;
+import com.sundata.internalevaluation.calc.calcUnit.InterfaceCalcUnit;
+import com.sundata.internalevaluation.calc.model.finals.CalcType;
+import com.sundata.internalevaluation.calc.running.threads.CalcTaskResult;
+import com.sundata.internalevaluation.calc.util.CalcUtil;
+import com.sundata.internalevaluation.configuration.model.SysInterface;
+import com.sundata.internalevaluation.configuration.service.SysInterfaceService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.sundata.internalevaluation.configuration.model.SysInterface;
-import com.sundata.internalevaluation.configuration.service.SysInterfaceService;
+import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/npapi")
@@ -70,5 +75,21 @@ public class SysInterfaceController {
     public int delete(@RequestBody SysInterface sysReqInterface) {
         return sysReqInterfaceService.delete(sysReqInterface);
     }
+
+    /**
+     * 删除记录
+     *
+     * @param sysReqInterface 待删除的记录
+     * @return 返回影响行数
+     */
+    @RequestMapping("testCalc")
+    public Object testCalc(@RequestBody SysInterface sysReqInterface) {
+
+        SysInterface sysInterface = sysReqInterfaceService.getById(sysReqInterface.getId());
+        CalcTaskResult calc = CalcUtil.calc("interface:" + System.currentTimeMillis(),
+                new InterfaceCalcUnit(sysInterface.getId(), sysInterface.getInterfaceName(), CalcType.INTERFACE, Map.of(), sysInterface),
+                null);
+        return calc;
+    }
     
 }

+ 9 - 0
src/main/java/com/sundata/internalevaluation/configuration/mapper/IndexConfigMapper.java

@@ -1,7 +1,9 @@
 package com.sundata.internalevaluation.configuration.mapper;
 
+import com.sundata.admin.nounmanage.model.DictContent;
 import com.sundata.internalevaluation.configuration.model.IndexConfigModel;
 import com.sundata.internalevaluation.configuration.model.IndexSourceModel;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -16,5 +18,12 @@ public interface IndexConfigMapper {
 
     IndexConfigModel selectDetailData(IndexConfigModel model);
 
+    DictContent selectAllIndexToDict();
+
     List<IndexSourceModel> getIndexSourceList(IndexConfigModel indexConfigModel);
+
+    /**
+     * 根据规则编号查询所有指标
+     */
+    List<IndexConfigModel> selectIndexListByRuleNo(@Param("ruleNo") String ruleNo);
 }

+ 27 - 2
src/main/java/com/sundata/internalevaluation/configuration/mapper/SysReqRuleMapper.java

@@ -1,10 +1,12 @@
 package com.sundata.internalevaluation.configuration.mapper;
 
-import java.util.List;
-import org.apache.ibatis.annotations.Mapper;
 import com.sundata.internalevaluation.configuration.model.SysReqRule;
+import com.sundata.internalevaluation.configuration.model.SysRuleIndex;
+import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 @Mapper
 public interface SysReqRuleMapper {
 
@@ -51,4 +53,27 @@ public interface SysReqRuleMapper {
 	int delete(SysReqRule sysReqRule);
 
 	List<SysReqRule> selectRuleListByRulesNo(@Param("rulesNo") String rulesNo);
+
+
+	/**
+	 * 根据规则编号删除所有指标
+	 * @param ruleNo 规则编号
+	 * @return 返回影响行数
+	 */
+	int deleteIndexByRuleNo(@Param("ruleNo") String ruleNo);
+
+
+	/**
+	 * 插入所有规则 指标管关联关系
+	 * @param list 集合
+	 * @return 返回影响行数
+	 */
+	int insertIndexList(@Param("list") List<SysRuleIndex> list);
+
+	/**
+	 * 根据规则的编号  查询关联的指标
+	 * @param ruleNo 规则编号
+	 * @return 返回集合
+	 */
+	List<String> selectIndexByRuleNo(@Param("ruleNo") String ruleNo);
 }

+ 12 - 0
src/main/java/com/sundata/internalevaluation/configuration/model/SysReqRule.java

@@ -1,6 +1,8 @@
 package com.sundata.internalevaluation.configuration.model;
 
 
+import java.util.List;
+
 /**
  * 规则信息表
  */
@@ -34,6 +36,16 @@ public class SysReqRule {
      */
     private String ruleThreshold;
 
+    private List<String> indexNoList;
+
+    public List<String> getIndexNoList() {
+        return indexNoList;
+    }
+
+    public void setIndexNoList(List<String> indexNoList) {
+        this.indexNoList = indexNoList;
+    }
+
     /**
      * 规则结论模板
      */

+ 60 - 0
src/main/java/com/sundata/internalevaluation/configuration/model/SysRuleIndex.java

@@ -0,0 +1,60 @@
+package com.sundata.internalevaluation.configuration.model;
+
+/**
+ * Created by IntelliJ IDEA.
+ *
+ * @author JoeLazy
+ * @date 2025-02-14 11:45:52
+ * @description: 规则 指标关联实体
+ */
+public class SysRuleIndex {
+
+    private String ruleNo;
+
+    private String indexNo;
+
+
+    public SysRuleIndex() {
+    }
+
+    public SysRuleIndex(String ruleNo, String indexNo) {
+        this.ruleNo = ruleNo;
+        this.indexNo = indexNo;
+    }
+
+    /**
+     * 获取
+     * @return ruleNo
+     */
+    public String getRuleNo() {
+        return ruleNo;
+    }
+
+    /**
+     * 设置
+     * @param ruleNo
+     */
+    public void setRuleNo(String ruleNo) {
+        this.ruleNo = ruleNo;
+    }
+
+    /**
+     * 获取
+     * @return indexNo
+     */
+    public String getIndexNo() {
+        return indexNo;
+    }
+
+    /**
+     * 设置
+     * @param indexNo
+     */
+    public void setIndexNo(String indexNo) {
+        this.indexNo = indexNo;
+    }
+
+    public String toString() {
+        return "SysRuleIndex{ruleNo = " + ruleNo + ", indexNo = " + indexNo + "}";
+    }
+}

+ 17 - 0
src/main/java/com/sundata/internalevaluation/configuration/mybatis/IndexConfigMapper.xml

@@ -115,4 +115,21 @@
         select  DATASETNO as id, DATASETNAME as text from SYS_DATASET_CONFIG
     </select>
 
+    <select id="selectAllIndexToDict" resultType="com.sundata.admin.nounmanage.model.DictContent">
+        select  INDEXNO as id, INDEXNAME as text from SYS_INDEX
+    </select>
+
+
+    <select id="selectIndexListByRuleNo" resultType="com.sundata.internalevaluation.configuration.model.IndexConfigModel"
+            parameterType="string">
+        select
+            i.INDEXNO as indexNo,
+            i.INDEXNAME as indexName,
+            i.INDEXLOGIC as indexLogic
+        from SYS_INDEX i inner join SYS_REQ_RULE_INDEX ri on i.indexNo = ri.indexNo
+        where ri.ruleNo = #{ruleNo}
+
+
+    </select>
+
 </mapper>

+ 21 - 0
src/main/java/com/sundata/internalevaluation/configuration/mybatis/SysReqRuleMapper.xml

@@ -179,4 +179,25 @@
     </select>
 
 
+    <!-- 根据规则编号删除所有指标 -->
+    <delete id="deleteIndexByRuleNo">
+        delete from SYS_REQ_RULE_INDEX where RULE_NO = #{ruleNo}
+    </delete>
+
+
+    <!-- 插入所有规则 指标管关联关系 -->
+    <insert id="insertIndexList" parameterType="java.util.List">
+        INSERT ALL
+        <foreach collection="list" item="item" >
+            into SYS_REQ_RULE_INDEX (RULE_NO,INDEX_NO) values (#{item.ruleNo},#{item.indexNo})
+        </foreach>
+        SELECT 1 FROM dual
+    </insert>
+
+    <!-- 根据规则的编号  查询关联的指标 -->
+    <select id="selectIndexByRuleNo" resultType="java.lang.String">
+        select index_No from SYS_REQ_RULE_INDEX where RULE_NO = #{ruleNo}
+    </select>
+
+
 </mapper>

+ 4 - 2
src/main/java/com/sundata/internalevaluation/configuration/service/IndexConfigService.java

@@ -2,10 +2,8 @@ package com.sundata.internalevaluation.configuration.service;
 
 import com.sundata.common.util.JsonUtil;
 import com.sundata.internalevaluation.configuration.mapper.IndexConfigMapper;
-import com.sundata.internalevaluation.configuration.model.DataSetConfigModel;
 import com.sundata.internalevaluation.configuration.model.IndexConfigModel;
 import com.sundata.internalevaluation.configuration.model.IndexSourceModel;
-import net.sf.json.util.JSONUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -85,4 +83,8 @@ public class IndexConfigService {
     public List<IndexSourceModel> getIndexSourceList(IndexConfigModel indexConfigModel) {
         return indexConfigMapper.getIndexSourceList(indexConfigModel);
     }
+
+    public List<IndexConfigModel> selectIndexListByRuleNo(String ruleNo) {
+        return indexConfigMapper.selectIndexListByRuleNo(ruleNo);
+    }
 }

+ 21 - 5
src/main/java/com/sundata/internalevaluation/configuration/service/SysReqRuleService.java

@@ -1,16 +1,19 @@
 package com.sundata.internalevaluation.configuration.service;
 
 import com.sundata.common.exception.BusinessException;
+import com.sundata.internalevaluation.configuration.mapper.SysReqRuleMapper;
 import com.sundata.internalevaluation.configuration.mapper.SysReqRulesMapper;
 import com.sundata.internalevaluation.configuration.model.SysReqRule;
-import com.sundata.internalevaluation.configuration.mapper.SysReqRuleMapper;
+import com.sundata.internalevaluation.configuration.model.SysRuleIndex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class SysReqRuleService {
@@ -22,6 +25,7 @@ public class SysReqRuleService {
     @Autowired
     private SysReqRulesMapper sysReqRulesMapper;
 
+
     /**
      * 查询所有记录
      *
@@ -38,8 +42,12 @@ public class SysReqRuleService {
      * @param ruleNo 主键
      * @return 返回记录,没有返回null
      */
+    @Transactional
     public SysReqRule getById(String ruleNo) {
-    	return sysReqRuleMapper.getById(ruleNo);
+        List<String> indexNoList = sysReqRuleMapper.selectIndexByRuleNo(ruleNo);
+        SysReqRule resEntity = sysReqRuleMapper.getById(ruleNo);
+        resEntity.setIndexNoList(indexNoList);
+        return resEntity;
     }
 	
 
@@ -51,6 +59,9 @@ public class SysReqRuleService {
      */
     public int insertIgnoreNull(SysReqRule sysReqRule) {
         try {
+            sysReqRuleMapper.deleteIndexByRuleNo(sysReqRule.getRuleNo());
+            List<SysRuleIndex> list = sysReqRule.getIndexNoList().stream().map(indexNo -> new SysRuleIndex(sysReqRule.getRuleNo(), indexNo)).collect(Collectors.toList());
+            sysReqRuleMapper.insertIndexList(list);
             return sysReqRuleMapper.insertIgnoreNull(sysReqRule);
         } catch (DuplicateKeyException e) {
             throw new BusinessException("规则编码已存在,请重新输入.");
@@ -65,8 +76,14 @@ public class SysReqRuleService {
      * @param sysReqRule 修改的记录
      * @return 返回影响行数
      */
+    @Transactional
     public int updateIgnoreNull(SysReqRule sysReqRule) {
-    	return sysReqRuleMapper.updateIgnoreNull(sysReqRule);
+
+        sysReqRuleMapper.deleteIndexByRuleNo(sysReqRule.getRuleNo());
+        List<SysRuleIndex> list = sysReqRule.getIndexNoList().stream().map(indexNo -> new SysRuleIndex(sysReqRule.getRuleNo(), indexNo)).collect(Collectors.toList());
+        sysReqRuleMapper.insertIndexList(list);
+        return sysReqRuleMapper.updateIgnoreNull(sysReqRule);
+
     }
 	
     /**
@@ -82,11 +99,10 @@ public class SysReqRuleService {
         List<String> rulesNo = sysReqRulesMapper.selectRulesByRuleNo(sysReqRule.getRuleNo());
 
         if (rulesNo == null || rulesNo.isEmpty()) {
+            sysReqRuleMapper.deleteIndexByRuleNo(sysReqRule.getRuleNo());
             return sysReqRuleMapper.delete(sysReqRule);
         } else {
             throw new BusinessException("该规则已被引用,不能删除");
-//            log.error("该规则已被引用,不能删除");
-//            return 0;
         }
     }