From 6c2ff1c7c8e0aba3af92110b76687b78f8278e86 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期五, 03 一月 2025 09:57:37 +0800
Subject: [PATCH] 动态数据长度

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleConstructor.java               |   16 +++++++++++++++-
 iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkScheduleReqDTO.java              |    3 +++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/ColumnItemPort.java              |    2 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java |    6 ++++--
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java           |   11 -----------
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java                             |    2 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/ScheduleModelHandler.java          |    3 ++-
 7 files changed, 26 insertions(+), 17 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..6da1c45 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
@@ -25,4 +25,7 @@
     @NotNull(message="调度方案时间不能为空")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date scheduleTime;
+
+    @Schema(description = "动态数据长度(输入端口,数据长度)")
+    private Map<Integer, Integer> dynamicDataLength;
 }
\ 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..69e416a 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
@@ -216,7 +216,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.getDynamicDataLength());
             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..47c8268 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
@@ -1,15 +1,18 @@
 package com.iailab.module.model.mdk.sample;
 
 import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException;
+import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
 import com.iailab.module.model.mdk.sample.dto.SampleData;
 import com.iailab.module.model.mdk.sample.dto.SampleInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 样本构造
@@ -25,10 +28,21 @@
     @Autowired
     private SampleFactory sampleFactory;
 
-    public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName) throws ModelInvokeException {
+    public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, Map<Integer, Integer> dynamicDataLength) throws ModelInvokeException {
         try {
             SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId);
             SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime);
+            if (!CollectionUtils.isEmpty(dynamicDataLength) && sampleInfo.getColumnInfo() != null) {
+                 for(ColumnItemPort columnInfo : sampleInfo.getColumnInfo()) {
+                     if (!dynamicDataLength.containsKey(columnInfo.getPortOrder())) {
+                         continue;
+                     }
+                     columnInfo.setDataLength(dynamicDataLength.get(columnInfo.getPortOrder()));
+                     columnInfo.getColumnItemList().forEach(columnItem -> {
+                         columnItem.setDataLength(columnInfo.getDataLength());
+                     });
+                 }
+            }
             SampleDataConstructor sampleDataConstructor = sampleFactory.createSampelData(typeA);
             return sampleDataConstructor.prepareSampleData(sampleInfo);
         } catch (Exception e) {
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
index 53bed0b..0d6431e 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
@@ -2,23 +2,18 @@
 
 import com.iailab.module.data.api.ind.IndItemApi;
 import com.iailab.module.data.api.ind.dto.ApiIndItemDTO;
-import com.iailab.module.data.api.plan.PlanItemApi;
 import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
-import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
 import com.iailab.module.data.enums.DataPointFreqEnum;
-import com.iailab.module.data.enums.TimeGranularityEnum;
 import com.iailab.module.data.enums.TimeGranularitySecEnum;
 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
 import com.iailab.module.model.mdk.common.enums.ModelParamType;
 import com.iailab.module.model.mdk.sample.dto.ColumnItem;
-import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
 import com.iailab.module.model.mdk.sample.dto.SampleInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Calendar;
 import java.util.Date;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -27,12 +22,6 @@
  * @createTime 2024年09月03日
  */
 abstract class SampleInfoConstructor {
-
-    @Autowired
-    private DataPointApi dataPointApi;
-
-    @Autowired
-    private PlanItemApi planItemApi;
 
     @Autowired
     private IndItemApi indItemApi;
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/ColumnItemPort.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/ColumnItemPort.java
index 05706f9..ef04a7d 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/ColumnItemPort.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/dto/ColumnItemPort.java
@@ -26,7 +26,7 @@
     private int portOrder;
 
     /**
-     * 预测数据长度
+     * 数据长度
      */
     private int dataLength;
 }
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..62c3aa2 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.Map;
 
 /**
  * @author PanZhibao
@@ -12,5 +13,5 @@
  */
 public interface ScheduleModelHandler {
 
-    ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException;
+    ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime, Map<Integer, Integer> dynamicDataLength) 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..bf9930d 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, Map<Integer, Integer> dynamicDataLength) throws ModelInvokeException {
         ScheduleResultVO scheduleResult = new ScheduleResultVO();
         StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(schemeCode);
         StScheduleModelEntity scheduleModel = stScheduleModelService.get(scheduleScheme.getModelId());
@@ -63,7 +64,8 @@
         try {
             //1.根据模型id构造模型输入样本
             long now = System.currentTimeMillis();
-            List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName());
+            List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,
+                    scheduleScheme.getName(), dynamicDataLength);
             log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒");
             if (CollectionUtils.isEmpty(sampleDataList)) {
                 log.info("调度模型构造样本失败,schemeCode=" + schemeCode);

--
Gitblit v1.9.3