From eca625c35d5ed64c98277d2f83963e46438f50ce Mon Sep 17 00:00:00 2001
From: Jay <csj123456>
Date: 星期五, 03 一月 2025 09:57:50 +0800
Subject: [PATCH] 执行调度模型新增可以传入模型参数

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java |   42 ++++++++++++++++++++++++++----------------
 1 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
index 26a3f6c..52b5f90 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.mdk.schedule.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.iail.model.IAILModel;
@@ -27,6 +28,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -50,7 +52,7 @@
     private SampleConstructor sampleConstructor;
 
     @Override
-    public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException {
+    public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime, HashMap<String, Object> params) throws ModelInvokeException {
         ScheduleResultVO scheduleResult = new ScheduleResultVO();
         StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(schemeCode);
         StScheduleModelEntity scheduleModel = stScheduleModelService.get(scheduleScheme.getModelId());
@@ -61,7 +63,9 @@
         String modelId = scheduleModel.getId();
         try {
             //1.根据模型id构造模型输入样本
-            List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime);
+            long now = System.currentTimeMillis();
+            List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName());
+            log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒");
             if (CollectionUtils.isEmpty(sampleDataList)) {
                 log.info("调度模型构造样本失败,schemeCode=" + schemeCode);
                 return null;
@@ -72,6 +76,14 @@
             if (settings == null) {
                 log.error("模型setting不存在,modelId=" + modelId);
                 return null;
+            }
+            //如果输入参数中包含setting,则覆盖默认的setting
+            if (!params.isEmpty()){
+                for (Map.Entry<String, Object> entry : params.entrySet()){
+                    if (settings.containsKey(entry.getKey())){
+                        settings.put(entry.getKey(), entry.getValue());
+                    }
+                }
             }
             // 校验setting必须有pyFile,否则可能导致程序崩溃
             if (!settings.containsKey(MdkConstant.PY_FILE_KEY)) {
@@ -86,28 +98,26 @@
             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(String.valueOf(jsonObjParam2Values));
-
+            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);
+            if (!modelResult.containsKey(CommonConstant.MDK_STATUS_CODE) || !modelResult.containsKey(CommonConstant.MDK_RESULT)) {
+                log.info("模型结果异常:" + modelResult);
             }
-            modelResult = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);
-
+            String statusCode = modelResult.get(CommonConstant.MDK_STATUS_CODE).toString();
+            HashMap<String, Object> result = new HashMap<>();
+            if (modelResult.containsKey(CommonConstant.MDK_RESULT) && modelResult.get(CommonConstant.MDK_RESULT) != null &&
+                    CommonConstant.MDK_STATUS_100.equals(modelResult.get(CommonConstant.MDK_STATUS_CODE).toString())) {
+                result = (HashMap<String, Object>) modelResult.get(CommonConstant.MDK_RESULT);
+            }
             //打印结果
             JSONObject jsonObjResult = new JSONObject();
-            jsonObjResult.put("result", modelResult);
+            jsonObjResult.put("result", result);
             log.info(String.valueOf(jsonObjResult));
 
             //5.返回调度结果
-            scheduleResult.setResult(modelResult);
+            scheduleResult.setResultCode(statusCode);
+            scheduleResult.setResult(result);
             scheduleResult.setModelId(modelId);
             scheduleResult.setSchemeId(scheduleScheme.getId());
             scheduleResult.setScheduleTime(scheduleTime);

--
Gitblit v1.9.3