From 73559ec983f52cb192e52654f0db7674535c8e6a Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期一, 24 三月 2025 16:55:58 +0800
Subject: [PATCH] 新增api controller

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java |   73 ++++++++++++++++++++++++++++++++----
 1 files changed, 65 insertions(+), 8 deletions(-)

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 bc62e43..5647c66 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
@@ -9,21 +9,22 @@
 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.enums.CommonConstant;
+import com.iailab.module.model.enums.PredictItemTypeEnum;
 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;
+import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity;
+import com.iailab.module.model.mcs.sche.entity.StAdjustConfigEntity;
+import com.iailab.module.model.mcs.sche.entity.StScheduleSchemeEntity;
+import com.iailab.module.model.mcs.sche.service.StAdjustConfigService;
 import com.iailab.module.model.mcs.sche.service.StScheduleModelOutService;
 import com.iailab.module.model.mcs.sche.service.StScheduleRecordService;
 import com.iailab.module.model.mcs.sche.service.StScheduleSchemeService;
 import com.iailab.module.model.mdk.predict.PredictModuleHandler;
 import com.iailab.module.model.mdk.predict.PredictResultHandler;
 import com.iailab.module.model.mdk.schedule.ScheduleModelHandler;
-import com.iailab.module.model.mdk.vo.DataValueVO;
-import com.iailab.module.model.mdk.vo.ItemVO;
-import com.iailab.module.model.mdk.vo.PredictResultVO;
-import com.iailab.module.model.mdk.vo.ScheduleResultVO;
+import com.iailab.module.model.mdk.vo.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,11 +33,10 @@
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
-
-import static com.iailab.module.model.common.enums.ModelOutResultType.D;
 
 /**
  * @author PanZhibao
@@ -74,6 +74,9 @@
 
     @Autowired
     private DataPointApi dataPointApi;
+
+    @Autowired
+    private StAdjustConfigService stAdjustConfigService;
 
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
@@ -193,6 +196,60 @@
         return resp;
     }
 
+    @Override
+    public Boolean predictSimAdjust(MdkPredictSimAdjustReqDTO reqDTO) {
+        log.info("开始模拟调整");
+        log.info("ModelResult:" + JSONObject.toJSONString(reqDTO.getModelResult()));
+        StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(reqDTO.getScheduleCode());
+        Map<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> configMap = stAdjustConfigService.getAdjustConfigMap(scheduleScheme.getModelId());
+        if (CollectionUtils.isEmpty(configMap)) {
+            return Boolean.FALSE;
+        }
+        for (Map.Entry<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> entry : configMap.entrySet()) {
+            log.info("AdjustConfigID=" + entry.getKey().getId());
+            if (CollectionUtils.isEmpty(entry.getValue())) {
+                continue;
+            }
+            String firstOutKey = entry.getValue().get(0).getOutKey();
+            if(StringUtils.isBlank(firstOutKey)) {
+                continue;
+            }
+            if(reqDTO.getModelResult().get(firstOutKey) == null || StringUtils.isBlank(reqDTO.getModelResult().get(firstOutKey).toString())) {
+                continue;
+            }
+            BigDecimal firstAdjustValue = new BigDecimal(reqDTO.getModelResult().get(firstOutKey.trim()).toString().trim());
+            if (BigDecimal.ZERO.compareTo(firstAdjustValue) == 0) {
+                log.info("firstAdjustValue = ZERO");
+                continue;
+            }
+            for (StAdjustConfigDetEntity det : entry.getValue()) {
+                ItemVO predictItem = mmPredictItemService.getItemById(det.getPredictItemId());
+                List<StAdjustDeviationDTO> deviationList = new ArrayList<>();
+                switch (PredictItemTypeEnum.getEumById(det.getItemTypeId())) {
+                    case NormalItem:
+                        double adjustValue = 0;
+                        if (StringUtils.isNotBlank(det.getOutKey())) {
+                            adjustValue = new BigDecimal(reqDTO.getModelResult().get(det.getOutKey()).toString()).doubleValue();
+                        }
+                        StAdjustDeviationDTO deviationItem = new StAdjustDeviationDTO();
+                        deviationItem.setPortIdx(det.getModelParamPortOrder() == null ? 0 : det.getModelParamPortOrder());
+                        deviationItem.setParamIdx(det.getModelParamOrder() == null ? 0 : det.getModelParamOrder());
+                        deviationItem.setValue(adjustValue);
+                        deviationList.add(deviationItem);
+                        break;
+                    case MergeItem:
+                        break;
+                    default:
+                        break;
+                }
+                // 开始预测
+                predictModuleHandler.predictAdjust(predictItem, reqDTO.getPredictTime(), deviationList, scheduleScheme.getModelId(), det.getConfigId());
+            }
+        }
+        return Boolean.TRUE;
+    }
+
+
     /**
      * 预测调整
      *
@@ -293,7 +350,7 @@
                 }
                 //返回结果是否存在
                 if (result.get(stScheduleModelOutDTO.getResultKey()) == null) {
-                    log.error(result.get(stScheduleModelOutDTO.getResultKey()) + "resultKey匹配失败");
+                    log.error(stScheduleModelOutDTO.getResultKey() + "resultKey匹配失败");
                     continue;
                 }
                 Object resultValue = result.get(stScheduleModelOutDTO.getResultKey());

--
Gitblit v1.9.3