From a874b928e16320839315b9abcdf2cece1229a424 Mon Sep 17 00:00:00 2001 From: houzhongjian <houzhongyi@126.com> Date: 星期四, 07 十一月 2024 09:20:38 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/MdkApiImpl.java | 78 ++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 13 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 6a7df4f..a5d05a8 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,23 +1,30 @@ package com.iailab.module.model.api; import com.alibaba.fastjson.JSON; +import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.model.api.mdk.MdkApi; import com.iailab.module.model.api.mdk.dto.*; import com.iailab.framework.common.pojo.CommonResult; 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.mdk.factory.ItemEntityFactory; +import com.iailab.module.model.mdk.factory.PredictItemFactory; +import com.iailab.module.model.mdk.predict.PredictItemHandler; 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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import javax.validation.Valid; - +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -45,6 +52,18 @@ @Autowired private PredictModuleHandler predictModuleHandler; + @Autowired + private ItemEntityFactory itemEntityFactory; + + @Autowired + private PredictItemFactory predictItemFactory; + + @Autowired + private PredictResultHandler predictResultHandler; + + @Autowired + private ScheduleModelHandler scheduleModelHandler; + /** * 按模块预测 * @@ -52,7 +71,7 @@ * @return */ @Override - public CommonResult<MdkPredictModuleRespDTO> predictModule(MdkPredictReqDTO reqDTO) { + public MdkPredictModuleRespDTO predictModule(MdkPredictReqDTO reqDTO) { MdkPredictModuleRespDTO resp = new MdkPredictModuleRespDTO(); Map<String, MdkPredictItemRespDTO> predictItemRespMap = new HashMap<>(); try { @@ -90,10 +109,11 @@ } log.info("预测计算结束: " + System.currentTimeMillis()); } catch (Exception ex) { - return error(999, ex.getMessage()); + ex.printStackTrace(); + return resp; } resp.setPredictItemRespMap(predictItemRespMap); - return success(resp); + return resp; } /** @@ -103,10 +123,31 @@ * @return */ @Override - public CommonResult<MdkPredictItemRespDTO> predictItem(@Valid @RequestBody MdkPredictReqDTO reqDTO) { + public MdkPredictItemRespDTO predictItem(MdkPredictReqDTO reqDTO) { MdkPredictItemRespDTO resp = new MdkPredictItemRespDTO(); - return success(resp); + try { + log.info("预测计算开始: " + System.currentTimeMillis()); + List<MdkPredictDataDTO> predictData = new ArrayList<>(); + ItemVO predictItem = itemEntityFactory.getItemByItemNo(reqDTO.getItemNo()); + PredictItemHandler predictItemHandler = (PredictItemHandler)predictItemFactory.create(predictItem.getId()); + PredictResultVO predictResult = predictItemHandler.predict(reqDTO.getPredictTime(), predictItem); + Map<String, List<DataValueVO>> resultMap = predictResultHandler.convertToPredictData(predictResult); + if (!CollectionUtils.isEmpty(resultMap)) { + for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { + predictData = ConvertUtils.sourceToTarget(entry.getValue(), MdkPredictDataDTO.class); + } + } + resp.setPredictData(predictData); + resp.setItemId(predictItem.getId()); + resp.setPredictTime(reqDTO.getPredictTime()); + log.info("预测计算结束: " + System.currentTimeMillis()); + } catch (Exception ex) { + log.info("预测计算异常: " + System.currentTimeMillis(),ex); + return resp; + } + + return resp; } /** @@ -116,10 +157,10 @@ * @return */ @Override - public CommonResult<Boolean> predictAutoAdjust(@Valid @RequestBody MdkPredictReqDTO reqDTO) { + public Boolean predictAutoAdjust(MdkPredictReqDTO reqDTO) { - return success(true); + return true; } /** @@ -129,9 +170,20 @@ * @return */ @Override - public CommonResult<MdkScheduleRespDTO> doSchedule(@Valid @RequestBody MdkScheduleReqDTO reqDTO) { + public MdkScheduleRespDTO doSchedule(MdkScheduleReqDTO reqDTO) { MdkScheduleRespDTO resp = new MdkScheduleRespDTO(); - - return success(resp); + resp.setScheduleCode(reqDTO.getScheduleCode()); + resp.setScheduleTime(reqDTO.getScheduleTime()); + try { + log.info("调度计算开始: " + System.currentTimeMillis()); + ScheduleResultVO scheduleResult = scheduleModelHandler.doSchedule(reqDTO.getModelCode(), reqDTO.getScheduleTime()); + resp.setResult(scheduleResult.getResult()); + log.info("预测计算结束: " + System.currentTimeMillis()); + } catch (Exception ex) { + log.info("调度计算异常: " + System.currentTimeMillis()); + ex.printStackTrace(); + return resp; + } + return resp; } } \ No newline at end of file -- Gitblit v1.9.3