package com.iailab.module.model.mdk.predict; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.service.MmItemResultService; import com.iailab.module.model.mdk.factory.ItemEntityFactory; import com.iailab.module.model.mdk.vo.DataValueVO; import com.iailab.module.model.mdk.vo.MmItemOutputVO; import com.iailab.module.model.mdk.vo.PredictResultVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; @Service public class PredictResultHandler { @Autowired private MmItemResultService mmItemResultService; @Autowired private ItemEntityFactory itemEntityFactory; /** * convertToPredictData * * @param predictResult * @return */ public Map> convertToPredictData(PredictResultVO predictResult) { Map> resultMap = new HashMap<>(); List itemOutPutList = itemEntityFactory.getOutPutByItemId(predictResult.getPredictId()); if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); return resultMap; } Map predictMatrixs = predictResult.getPredictMatrixs(); HashMap> predictLists = new HashMap<>(); for (Map.Entry entry : predictMatrixs.entrySet()) { Integer rows = entry.getValue().length; List predictDataList = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); calendar.setTime(predictResult.getPredictTime()); for (Integer i = 0; i < rows; i++) { DataValueVO predictData = new DataValueVO(); predictData.setDataTime(calendar.getTime()); predictData.setDataValue(Double.valueOf(entry.getValue()[i])); predictDataList.add(predictData); calendar.add(Calendar.SECOND, predictResult.getGranularity()); } resultMap.put(entry.getKey().getId(), predictDataList); predictLists.put(entry.getKey().getResultstr(), predictDataList); } predictResult.setPredictLists(predictLists); return resultMap; } public Map> convertToPredictData2(PredictResultVO predictResult) { Map> predictLists = new HashMap<>(); if (!CollectionUtils.isEmpty(predictResult.getPredictList())) { return predictLists; } Map predictMatrixs = predictResult.getPredictMatrixs(); for (Map.Entry entry : predictMatrixs.entrySet()) { Integer rows = entry.getValue().length; List predictDataList = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); calendar.setTime(predictResult.getPredictTime()); for (Integer i = 0; i < rows; i++) { DataValueVO predictData = new DataValueVO(); predictData.setDataTime(calendar.getTime()); predictData.setDataValue(Double.valueOf(entry.getValue()[i])); predictDataList.add(predictData); calendar.add(Calendar.SECOND, predictResult.getGranularity()); } predictLists.put(entry.getKey().getResultstr(), predictDataList); } return predictLists; } /** * savePredictResult * * @param predictResult */ @Async @DSTransactional public void savePredictResult(PredictResultVO predictResult) { Map> resultMap = convertToPredictData(predictResult); mmItemResultService.savePredictValue(resultMap, predictResult.getLt(), "n", predictResult.getPredictTime()); } public List getPredictValueByItemNo(String itemNo, Date start, Date end) { String itemId = itemEntityFactory.getItemByItemNo(itemNo).getId(); List outputList = itemEntityFactory.getOutPutByItemId(itemId); return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end); } public List getPredictValueByItemId(String itemId, Date start, Date end) { List outputList = itemEntityFactory.getOutPutByItemId(itemId); return mmItemResultService.getPredictValue(outputList.get(0).getId(), start, end); } }