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/sample/SampleFactory.java                   |    2 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java               |    2 +-
 iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java              |    5 ++++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java |   11 ++++++++++-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java                             |    5 +----
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/ScheduleModelHandler.java          |    3 ++-
 6 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java
index 589d7f1..b4b52cf 100644
--- a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java
+++ b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java
@@ -6,7 +6,7 @@
 
 import javax.validation.constraints.NotNull;
 import java.util.Date;
-import java.util.Map;
+import java.util.HashMap;
 
 /**
  * @author PanZhibao
@@ -25,4 +25,7 @@
     @NotNull(message="调度方案时间不能为空")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date scheduleTime;
+
+    @Schema(description = "模型参数")
+    private HashMap<String, Object> params;
 }
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
index 3e0d626..3b44294 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java
@@ -8,7 +8,6 @@
 import com.iailab.module.model.api.mdk.dto.*;
 import com.iailab.module.model.common.enums.IsWriteEnum;
 import com.iailab.module.model.common.enums.ModelOutResultType;
-import com.iailab.module.model.common.enums.OutResultType;
 import com.iailab.module.model.mcs.pre.entity.DmModuleEntity;
 import com.iailab.module.model.mcs.pre.service.DmModuleService;
 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
@@ -30,8 +29,6 @@
 
 import java.util.*;
 import java.util.stream.Collectors;
-
-import static com.iailab.module.model.common.enums.ModelOutResultType.D;
 
 /**
  * @author PanZhibao
@@ -216,7 +213,7 @@
         resp.setScheduleTime(reqDTO.getScheduleTime());
         try {
             log.info("调度计算开始: " + System.currentTimeMillis());
-            ScheduleResultVO scheduleResult = scheduleModelHandler.doSchedule(reqDTO.getScheduleCode(), reqDTO.getScheduleTime());
+            ScheduleResultVO scheduleResult = scheduleModelHandler.doSchedule(reqDTO.getScheduleCode(), reqDTO.getScheduleTime(), reqDTO.getParams());
             resp.setStatusCode(scheduleResult.getResultCode());
             resp.setResult(scheduleResult.getResult());
             stScheduleRecordService.create(scheduleResult);
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java
index e42c921..59eb9b5 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java
@@ -29,7 +29,7 @@
         try {
             SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId);
             SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime);
-            SampleDataConstructor sampleDataConstructor = sampleFactory.createSampelData(typeA);
+            SampleDataConstructor sampleDataConstructor = sampleFactory.createSampleData(typeA);
             return sampleDataConstructor.prepareSampleData(sampleInfo);
         } catch (Exception e) {
             e.printStackTrace();
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleFactory.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleFactory.java
index 194b6a3..46a0f1a 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleFactory.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleFactory.java
@@ -36,7 +36,7 @@
         return sampleInfoConstructor;
     }
 
-    public SampleDataConstructor createSampelData(String typeA) {
+    public SampleDataConstructor createSampleData(String typeA) {
         SampleDataConstructor sampleDataConstructor = null;
         if (typeA.compareTo(TypeA.Predict.name()) == 0) {
             sampleDataConstructor = predictSampleDataConstructor;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/ScheduleModelHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/ScheduleModelHandler.java
index facd20f..6aa42b2 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/ScheduleModelHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/ScheduleModelHandler.java
@@ -4,6 +4,7 @@
 import com.iailab.module.model.mdk.vo.ScheduleResultVO;
 
 import java.util.Date;
+import java.util.HashMap;
 
 /**
  * @author PanZhibao
@@ -12,5 +13,5 @@
  */
 public interface ScheduleModelHandler {
 
-    ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException;
+    ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime, HashMap<String, Object> params) throws ModelInvokeException;
 }
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 ec0e7b0..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
@@ -28,6 +28,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -51,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());
@@ -76,6 +77,14 @@
                 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)) {
                 log.error("模型设置参数缺少必要信息【" + MdkConstant.PY_FILE_KEY +  "】,请重新上传模型!");

--
Gitblit v1.9.3