From f2d87e1e765f525c63b742943c8b865032db82df Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期三, 19 三月 2025 07:45:41 +0800 Subject: [PATCH] 模型调整 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigDetService.java | 2 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigService.java | 6 - iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java | 3 - iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/AdjustConfigStatusEnum.java | 20 ++++++ iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java | 7 -- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java | 59 +++++++++++++------ iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StAdjustConfigServiceImpl.java | 31 ++++++---- 7 files changed, 82 insertions(+), 46 deletions(-) diff --git a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java index 4d22066..9affbfd 100644 --- a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java +++ b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/McsApi.java @@ -126,9 +126,6 @@ @GetMapping(PREFIX + "/schedule/model/setting/update") @Operation(summary = "修改调度模型配置") Boolean updateScheduleModelSetting(@RequestParam("modelCode") String modelCode, @RequestParam("key") String key, @RequestParam("value") String value); - @GetMapping(PREFIX + "/schedule/adjust/config-list") - @Operation(summary = "获取模拟调整配置") - List<StAdjustConfigDetDTO> getAdjustConfigListByModelId(@RequestParam("modelId") String modelId); @GetMapping(PREFIX + "/alarm-config/update") @Operation(summary = "修改预警配置") diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java index f6fd187..8cf7c27 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java @@ -354,6 +354,7 @@ return result; } + @Override public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { PreDataSingleChartRespVO result = new PreDataSingleChartRespVO(); @@ -819,12 +820,6 @@ StScheduleModelEntity model = stScheduleModelService.getByModelCode(modelCode); stScheduleModelSettingService.updateByModelIdAndKey(model.getId(), key, value); return true; - } - - @Override - public List<StAdjustConfigDetDTO> getAdjustConfigListByModelId(String modelId) { - List<StAdjustConfigDetEntity> list = stAdjustConfigService.getDetByModelId(modelId); - return ConvertUtils.sourceToTarget(list, StAdjustConfigDetDTO.class); } @Override 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 334d710..883b075 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 @@ -1,6 +1,7 @@ package com.iailab.module.model.api; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.data.api.point.dto.ApiPointValueWriteDTO; import com.iailab.module.model.api.mcs.dto.StScheduleModelOutDTO; @@ -14,6 +15,7 @@ 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; @@ -196,30 +198,47 @@ @Override public Boolean predictSimAdjust(MdkPredictSimAdjustReqDTO reqDTO) { + log.info("开始模拟调整"); + log.info("ModelResult:" + JSONObject.toJSONString(reqDTO.getModelResult())); StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(reqDTO.getScheduleCode()); - List<StAdjustConfigDetEntity> detList = stAdjustConfigService.getDetByModelId(scheduleScheme.getModelId()); - if (CollectionUtils.isEmpty(detList)) { + Map<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> configMap = stAdjustConfigService.getAdjustConfigMap(scheduleScheme.getModelId()); + if (CollectionUtils.isEmpty(configMap)) { return Boolean.FALSE; } - for (StAdjustConfigDetEntity det : detList) { - ItemVO predictItem = mmPredictItemService.getItemById(det.getPredictItemId()); - List<StAdjustDeviationDTO> deviationList = new ArrayList<>(); - switch (PredictItemTypeEnum.getEumById(det.getItemTypeId())) { - case NormalItem: - double adjustValue = new BigDecimal(reqDTO.getModelResult().get(det.getOutKey()).toString()).doubleValue(); - StAdjustDeviationDTO deviationItem = new StAdjustDeviationDTO(); - deviationItem.setPortIdx(det.getModelParamPortOrder()); - deviationItem.setParamIdx(det.getModelParamPortOrder()); - deviationItem.setValue(adjustValue); - deviationList.add(deviationItem); - break; - case MergeItem: - break; - default: - break; + for (Map.Entry<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> entry : configMap.entrySet()) { + log.info("AdjustConfigID=" + entry.getKey().getId()); + if (CollectionUtils.isEmpty(entry.getValue())) { + continue; } - // 开始预测 - predictModuleHandler.predictAdjust(predictItem, reqDTO.getPredictTime(), deviationList, scheduleScheme.getModelId(), det.getConfigId()); + String firstOutKey = entry.getValue().get(0).getOutKey(); + BigDecimal firstAdjustValue = new BigDecimal(reqDTO.getModelResult().get(firstOutKey.trim()).toString().trim()); + if (BigDecimal.ZERO.compareTo(firstAdjustValue) == 0) { + log.info("adjustValue = 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().trim())) { + adjustValue = new BigDecimal(reqDTO.getModelResult().get(det.getOutKey().trim()).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; } diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/AdjustConfigStatusEnum.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/AdjustConfigStatusEnum.java new file mode 100644 index 0000000..45986a9 --- /dev/null +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/AdjustConfigStatusEnum.java @@ -0,0 +1,20 @@ +package com.iailab.module.model.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author PanZhibao + * @Description + * @createTime 2025年03月18日 + */ +@Getter +@AllArgsConstructor +public enum AdjustConfigStatusEnum { + + ENABLE(1), + + DISABLE(0); + + private Integer code; +} \ No newline at end of file diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigDetService.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigDetService.java index 6705a36..66a3aaa 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigDetService.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigDetService.java @@ -2,8 +2,10 @@ import com.iailab.framework.common.service.BaseService; import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; +import com.iailab.module.model.mcs.sche.entity.StAdjustConfigEntity; import java.util.List; +import java.util.Map; /** * @author PanZhibao diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigService.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigService.java index f52d19c..7c4a24f 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigService.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StAdjustConfigService.java @@ -19,10 +19,6 @@ */ public interface StAdjustConfigService extends BaseService<StAdjustConfigEntity> { - StAdjustConfigEntity getByModelId(String modelId); - - List<StAdjustConfigDetEntity> getDetByModelId(String modelId); - PageResult<StAdjustConfigRespVO> page(StAdjustConfigPageReqVO reqVO); void create(StAdjustConfigSaveReqVO createReqVO); @@ -35,4 +31,6 @@ List<StAdjustConfigDTO> list(Map<String, Object> params); + Map<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> getAdjustConfigMap(String modelId); + } \ No newline at end of file diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StAdjustConfigServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StAdjustConfigServiceImpl.java index 60a5a8a..335d715 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StAdjustConfigServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StAdjustConfigServiceImpl.java @@ -9,6 +9,7 @@ import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.model.api.mcs.dto.StAdjustConfigDTO; +import com.iailab.module.model.common.enums.AdjustConfigStatusEnum; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.sche.dao.StAdjustConfigDao; import com.iailab.module.model.mcs.sche.entity.StAdjustConfigDetEntity; @@ -21,10 +22,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * @author PanZhibao @@ -87,16 +87,21 @@ return ConvertUtils.sourceToTarget(list, StAdjustConfigDTO.class); } - public StAdjustConfigEntity getByModelId(String modelId) { - return baseDao.selectOne("schedule_model_id", modelId,"status",1); - } - - - public List<StAdjustConfigDetEntity> getDetByModelId(String modelId) { - StAdjustConfigEntity configEntity = getByModelId(modelId); - if (null == configEntity) { - return null; + @Override + public Map<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> getAdjustConfigMap(String modelId) { + Map<StAdjustConfigEntity, List<StAdjustConfigDetEntity>> result = new HashMap<>(); + QueryWrapper<StAdjustConfigEntity> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("schedule_model_id", modelId) + .eq("status", AdjustConfigStatusEnum.ENABLE.getCode()); + List<StAdjustConfigEntity> configList = baseDao.selectList(queryWrapper); + if (!CollectionUtils.isEmpty(configList)) { + return result; } - return stAdjustConfigDetService.getListByConfigId(configEntity.getId()); + for (StAdjustConfigEntity entity : configList) { + List<StAdjustConfigDetEntity> detList = stAdjustConfigDetService.getListByConfigId(entity.getId()); + result.put(entity, detList); + } + + return result; } } \ No newline at end of file -- Gitblit v1.9.3