潘志宝
2024-11-19 97d38f7b7f7d95fe38cdbb79960106c15454b6ba
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemNormalHandlerImpl.java
@@ -34,14 +34,19 @@
    @Autowired
    private PredictModelHandler predictModelHandler;
    /**
     * NormalItem预测
     *
     * @param predictTime
     * @param predictItemDto
     * @return
     * @throws ItemInvokeException
     */
    @Override
    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto)
            throws ItemInvokeException{
        String itemId = predictItemDto.getId();
        ItemPredictStatus itemStatus = ItemPredictStatus.PREDICTING;
        PredictResultVO finalResult = new PredictResultVO();
    public PredictResultVO predict(Date predictTime, ItemVO predictItemDto) throws ItemInvokeException{
        PredictResultVO predictResult = new PredictResultVO();
        List<PredictResultVO> predictResultList = new ArrayList<>();
        String itemId = predictItemDto.getId();
        predictResult.setPredictId(itemId);
        try {
            // 获取预测项模型
            List<MmPredictModelEntity> predictModelList = mmPredictModelService.getActiveModelByItemId(itemId);
@@ -49,26 +54,14 @@
                throw new ModelInvokeException(MessageFormat.format("{0},itemId={1}",
                        ModelInvokeException.errorGetModelEntity, itemId));
            }
            for (MmPredictModelEntity predictModel : predictModelList) {
                predictResult = predictModelHandler.predictByModel(predictTime, predictModel);
                predictResult.setPredictId(itemId);
                predictResultList.add(predictResult);
            }
            itemStatus = ItemPredictStatus.SUCCESS;
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(predictTime);
            calendar.add(Calendar.MINUTE, predictResult.getPredictMatrix().length - 1);
            Timestamp endTime = new Timestamp(calendar.getTime().getTime());
            finalResult = predictResultList.get(0);
            MmPredictModelEntity predictModel = predictModelList.get(0);
            predictResult = predictModelHandler.predictByModel(predictTime, predictModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            //预测项预测失败的状态
            itemStatus = ItemPredictStatus.FAILED;
            throw new ItemInvokeException(MessageFormat.format("{0},itemId={1}",
                    ItemInvokeException.errorItemFailed, itemId));
        }
        return finalResult;
        return predictResult;
    }
}