已添加1个文件
已修改11个文件
134 ■■■■ 文件已修改
iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/enums/ScheduleTriggerMethodEnum.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/db/mysql.sql 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StScheduleRecordDetailServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StScheduleSchemeServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java
@@ -87,5 +87,5 @@
    @GetMapping(PREFIX + "/schedule-scheme/list")
    @Operation(summary = "获取调度方案列表")
    List<StScheduleSchemeDTO> listScheduleScheme(@RequestParam Map<String, Object> params);
    List<StScheduleSchemeDTO> listScheduleScheme(@RequestParam("triggerMethod") String triggerMethod, @RequestParam("triggerCondition") String triggerCondition);
}
iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/enums/ScheduleTriggerMethodEnum.java
对比新文件
@@ -0,0 +1,35 @@
package com.iailab.module.model.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
 * 调度模型触发方式
 *
 * @author PanZhibao
 * @Description
 * @createTime 2024年12月31日
 */
@Getter
@AllArgsConstructor
public enum ScheduleTriggerMethodEnum {
    EVENT("1", "事件触发"),
    JOB("2", "定时触发");
    private String code;
    private String desc;
    public static ScheduleTriggerMethodEnum getEumByCode(String code) {
        if (code == null) {
            return null;
        }
        for (ScheduleTriggerMethodEnum statusEnum : ScheduleTriggerMethodEnum.values()) {
            if (statusEnum.getCode().equals(code)) {
                return statusEnum;
            }
        }
        return null;
    }
}
iailab-module-model/iailab-module-model-biz/db/mysql.sql
@@ -47,8 +47,8 @@
    datatime  datetime,
    datavalue decimal(19, 3),
    primary key (id),
    INDEX     idx_outputid (outputid),
    INDEX     idx_datatime (datatime)
    UNIQUE KEY `unique_outputid_datatime` (`outputid`,`datatime`),
    KEY `idx_outputid_datatime` (`outputid`,`datatime`) USING BTREE
) engine = innodb
  default character set utf8mb4 COMMENT = '预测结果表';
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java
@@ -550,7 +550,10 @@
    }
    @Override
    public List<StScheduleSchemeDTO> listScheduleScheme(Map<String, Object> params) {
    public List<StScheduleSchemeDTO> listScheduleScheme(String triggerMethod, String triggerCondition) {
        Map<String, Object> params = new HashMap<>();
        params.put("triggerMethod", triggerMethod);
        params.put("triggerCondition", triggerCondition);
        return stScheduleSchemeService.list(params);
    }
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
@@ -8,8 +8,6 @@
import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
import com.iailab.module.model.mcs.sche.service.StScheduleRecordService;
import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService;
import com.iailab.module.model.mdk.factory.ItemEntityFactory;
import com.iailab.module.model.mdk.factory.PredictItemFactory;
import com.iailab.module.model.mdk.predict.PredictModuleHandler;
import com.iailab.module.model.mdk.predict.PredictResultHandler;
import com.iailab.module.model.mdk.schedule.ScheduleModelHandler;
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java
@@ -4,7 +4,9 @@
import com.iailab.framework.tenant.core.db.dynamic.TenantDS;
import com.iailab.module.model.mcs.pre.entity.MmItemResultEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
@@ -19,5 +21,7 @@
    void savePredictValue(Map<String, Object> params);
    void saveOrUpdateItemResult(@Param("list") List<MmItemResultEntity> list);
    void savePredictJsonValue(Map<String, Object> params);
}
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
@@ -15,8 +15,6 @@
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -85,14 +83,15 @@
            map4.put("entity", resultJson);
            mmItemResultDao.savePredictJsonValue(map4);
            Map<String, Object> params = new HashMap(4);
            params.put("TABLENAME", T_MM_ITEM_RESULT);
            params.put("OUTPUTID", entry.getKey());
            params.put("STARTTIME", importList.get(0).getDatatime());
            params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime());
            mmItemResultDao.deletePredictValue(params);
//            Map<String, Object> params = new HashMap(4);
//            params.put("TABLENAME", T_MM_ITEM_RESULT);
//            params.put("OUTPUTID", entry.getKey());
//            params.put("STARTTIME", importList.get(0).getDatatime());
//            params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime());
//            mmItemResultDao.deletePredictValue(params);
        }
        mmItemResultDao.insertBatch(importList,max_group_count);
        // 存在则修改,不存在插入
        mmItemResultDao.saveOrUpdateItemResult(importList);
        Map<String, Object> map3 = new HashMap<>(2);
        map3.put("TABLENAME", "T_MM_ITEM_RESULT_LAST_POINT");
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StScheduleRecordDetailServiceImpl.java
@@ -32,7 +32,7 @@
        for (Map.Entry<String, Object > entry: resultVO.getResult().entrySet()) {
            StScheduleRecordDetailEntity entity = new StScheduleRecordDetailEntity();
            entity.setId(UUID.randomUUID().toString());
            entity.setId(recordId);
            entity.setRecordId(recordId);
            entity.setSchemeId(resultVO.getSchemeId());
            entity.setModelId(resultVO.getModelId());
            entity.setScheduleTime(resultVO.getScheduleTime());
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StScheduleSchemeServiceImpl.java
@@ -63,8 +63,8 @@
    @Override
    public List<StScheduleSchemeDTO> list(Map<String, Object> params) {
        QueryWrapper<StScheduleSchemeEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("trigger_method", params.get("trigger_method"));
        queryWrapper.eq("trigger_condition", params.get("trigger_condition"));
        queryWrapper.eq("trigger_method", params.get("triggerMethod"));
        queryWrapper.eq("trigger_condition", params.get("triggerCondition"));
        List<StScheduleSchemeEntity> list = baseDao.selectList(queryWrapper);
        return ConvertUtils.sourceToTarget(list, StScheduleSchemeDTO.class);
    }
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
@@ -89,21 +89,15 @@
            param2Values[portLength] = settings;
            log.info("#######################调度模型 " + scheduleModel.getModelName() + " ##########################");
//            JSONObject jsonObjNewModelBean = new JSONObject();
//            jsonObjNewModelBean.put("newModelBean", newModelBean);
//            log.info(String.valueOf(jsonObjNewModelBean));
//            JSONObject jsonObjParam2Values = new JSONObject();
//            jsonObjParam2Values.put("param2Values", param2Values);
            log.info("参数: " + JSON.toJSONString(param2Values));
            //IAILMDK.run
            HashMap<String, Object> modelResult = DllUtils.run(newModelBean, param2Values, scheduleScheme.getMpkprojectid());
            if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT) ||
                    !modelResult.get(CommonConstant.MDK_STATUS_CODE).toString().equals(CommonConstant.MDK_STATUS_100)) {
                throw new RuntimeException("模型结果异常:" + modelResult);
            }
            modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);
            String statusCode = modelResult.get(CommonConstant.MDK_STATUS_CODE).toString();
            modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);
            //打印结果
            JSONObject jsonObjResult = new JSONObject();
            jsonObjResult.put("result", modelResult);
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java
@@ -12,14 +12,18 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import java.util.stream.Collectors;
@Slf4j
public class DllUtils {
    private static HashMap<String, URLClassLoader> classLoaderCache = new HashMap<>();
    private static HashMap<String, Object> classCache = new HashMap<>();
    private static HashMap<String, Method> classMethodCache = new HashMap<>();
    /**
     * @description: 加载dll到指定class下
@@ -147,6 +151,23 @@
            unloadDll(urlClassLoader);
            unloadJar(urlClassLoader);
            classLoaderCache.remove(projectId);
            removeClassCache(projectId);
            removeClassMethodCache(projectId);
        }
    }
    public static synchronized void removeClassCache(String projectId) {
        for (String key : classCache.keySet()) {
            if (key.startsWith(projectId)) {
                classCache.remove(key);
            }
        }
    }
    public static synchronized void removeClassMethodCache(String projectId) {
        for (String key : classMethodCache.keySet()) {
            if (key.startsWith(projectId)) {
                classMethodCache.remove(key);
            }
        }
    }
@@ -216,13 +237,23 @@
        } else if (model == null) {
            throw new RuntimeException("模型文件不能为空!");
        } else {
            URLClassLoader classLoader = DllUtils.getClassLoader(projectId);
            if (null == classLoader) {
                throw new RuntimeException("dll未发布,classLoader为null");
            String classCacheKey = projectId + "_" + model.getClassName();
            String methodParams = Arrays.stream(model.getParamsArray()).map(e -> e.getName()).collect(Collectors.joining(","));
            String classMethodCacheKey = classCacheKey + "." + model.getMethodName() + "(" + methodParams + ")";
            if (classCache.containsKey(classCacheKey) && classMethodCache.containsKey(classMethodCacheKey)) {
                return (HashMap)classMethodCache.get(classMethodCacheKey).invoke( classCache.get(classCacheKey), paramsValueArray);
            }else {
                URLClassLoader classLoader = DllUtils.getClassLoader(projectId);
                if (null == classLoader) {
                    throw new RuntimeException("dll未发布,classLoader为null");
                }
                Class<?> clazz = classLoader.loadClass(model.getClassName());
                Object o = clazz.newInstance();
                Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray());
                classCache.put(classCacheKey,o);
                classMethodCache.put(classMethodCacheKey,method);
                return (HashMap)method.invoke(o, paramsValueArray);
            }
            Class<?> clazz = classLoader.loadClass(model.getClassName());
            Method method = clazz.getMethod(model.getMethodName(), model.getParamsArray());
            return (HashMap)method.invoke(clazz.newInstance(), paramsValueArray);
        }
    }
}
iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml
@@ -28,5 +28,13 @@
        VALUES (#{entity.id},#{entity.outputid},#{entity.predicttime},#{entity.jsonvalue},#{entity.cumulant})
    </insert>
    <insert id="saveOrUpdateItemResult" parameterType="com.iailab.module.model.mcs.pre.entity.MmItemResultEntity">
        INSERT INTO t_mm_item_result (id,outputid, datatime, datavalue) VALUES
        <foreach item="item" collection="list" separator=",">
            (#{item.id},#{item.outputid},#{item.datatime},#{item.datavalue})
        </foreach>
            ON DUPLICATE KEY UPDATE datavalue = VALUES(datavalue)
    </insert>
</mapper>