package com.iailab.module.model.mdk.predict; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.data.api.point.dto.ApiPointDTO; import com.iailab.module.data.enums.DataPointFreq; import com.iailab.module.model.mcs.pre.service.MmItemResultService; import com.iailab.module.model.mdk.factory.ItemEntityFactory; import com.iailab.module.model.mdk.vo.MmItemOutputVO; import com.iailab.module.model.mdk.vo.DataValueVO; 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; @Autowired private DataPointApi dataPointApi; /** * 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; } ApiPointDTO point = dataPointApi.getInfoById(itemOutPutList.get(0).getPointId()); List dateTimeList = new ArrayList<>(); Integer rows = predictResult.getPredictMatrix().length; Integer columns = predictResult.getPredictMatrix()[0].length; Date tempTime = predictResult.getPredictTime(); for (Integer i = 0; i < rows; i++) { dateTimeList.add(tempTime); Calendar calendar = Calendar.getInstance(); calendar.setTime(tempTime); calendar.add(Calendar.SECOND, DataPointFreq.getEumByCode(point.getMinfreqid()).getValue()); tempTime = calendar.getTime(); } for (Integer i = 0; i < columns; i++) { List predictDataList = new ArrayList<>(); for (Integer j = 0; j < rows; j++) { DataValueVO predictData = new DataValueVO(); predictData.setDataTime(dateTimeList.get(j)); predictData.setDataValue(Double.valueOf(predictResult.getPredictMatrix()[j][i])); predictDataList.add(predictData); } resultMap.put(itemOutPutList.get(i).getId(), predictDataList); predictResult.setPredictList(predictDataList); } return resultMap; } /** * savePredictResult * * @param predictResult */ @Async 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); } }