| | |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.*; |
| | | import com.iailab.module.model.common.enums.CommonConstant; |
| | | import com.iailab.module.model.common.enums.PreLineTypeEnum; |
| | | import com.iailab.module.model.mcs.pre.entity.DmModuleEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.service.*; |
| | | import com.iailab.module.model.mdk.vo.ItemVO; |
| | | import com.iailab.module.model.mpk.service.ChartParamService; |
| | | import com.iailab.module.model.mpk.service.ChartService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private MmItemResultJsonService mmItemResultJsonService; |
| | | |
| | | @Autowired |
| | | private ChartService chartService; |
| | | |
| | | private int HOUR_MINS = 60; |
| | | |
| | |
| | | if (startTime == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictItem.getLastTime()); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | calendar.add(Calendar.MINUTE, -1 * predictItem.getPredictLength()); |
| | | startTime = calendar.getTime(); |
| | | } |
| | | Date endTime = reqVO.getEndTime(); |
| | | if (endTime == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictItem.getLastTime()); |
| | | calendar.add(Calendar.HOUR_OF_DAY, 1); |
| | | calendar.add(Calendar.MINUTE, predictItem.getPredictLength()); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | if (endTime.getTime() <= startTime.getTime()) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(startTime); |
| | | calendar.add(Calendar.HOUR_OF_DAY, 1); |
| | | calendar.add(Calendar.MINUTE, predictItem.getPredictLength()); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PreDataItemChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { |
| | | PreDataItemChartRespVO result = new PreDataItemChartRespVO(); |
| | | public PreDataSingleChartRespVO getPreDataSingleChart(PreDataSingleChartReqVO reqVO) { |
| | | PreDataSingleChartRespVO result = new PreDataSingleChartRespVO(); |
| | | |
| | | |
| | | Map<String, String> chartParams = chartService.getByChartCode(reqVO.getChartCode()); |
| | | if (CollectionUtils.isEmpty(chartParams)) { |
| | | return result; |
| | | } |
| | | String itemCode = chartParams.get(CommonConstant.ITEM_CODE); |
| | | if (itemCode == null) { |
| | | return result; |
| | | } |
| | | String resultStr = chartParams.get(CommonConstant.RESULT_STR); |
| | | if (resultStr == null) { |
| | | return result; |
| | | } |
| | | ItemVO predictItem = mmPredictItemService.getItemByItemNo(itemCode); |
| | | if (predictItem == null || predictItem.getLastTime() == null) { |
| | | return result; |
| | | } |
| | | PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.valueOf(chartParams.get(CommonConstant.LINE_TYPE)); |
| | | BigDecimal rangeH = chartParams.get(CommonConstant.RANGE_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_H)); |
| | | BigDecimal rangeL = chartParams.get(CommonConstant.RANGE_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_L)); |
| | | BigDecimal limitH = chartParams.get(CommonConstant.LIMIT_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_H)); |
| | | BigDecimal limitL = chartParams.get(CommonConstant.LIMIT_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_L)); |
| | | int lengthLeft = chartParams.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_LEFT)).intValue(); |
| | | int lengthRight = chartParams.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(chartParams.get(CommonConstant.LENGTH_RIGHT)).intValue(); |
| | | result.setPredictTime(predictItem.getLastTime()); |
| | | Date predictTime = predictItem.getLastTime(); |
| | | Date startTime = reqVO.getStartTime(); |
| | | if (startTime == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictItem.getLastTime()); |
| | | calendar.add(Calendar.MINUTE, -1 * lengthLeft); |
| | | startTime = calendar.getTime(); |
| | | } |
| | | Date endTime = reqVO.getEndTime(); |
| | | if (endTime == null) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(predictItem.getLastTime()); |
| | | calendar.add(Calendar.MINUTE, lengthRight); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | if (endTime.getTime() <= startTime.getTime()) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(startTime); |
| | | calendar.add(Calendar.MINUTE, lengthRight); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity()); |
| | | List<String> legend = new ArrayList<>(); |
| | | MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), resultStr); |
| | | PreDataViewRespDTO dataView = new PreDataViewRespDTO(); |
| | | dataView.setItemId(predictItem.getId()); |
| | | dataView.setItemName(predictItem.getItemName()); |
| | | dataView.setResultstr(resultStr); |
| | | dataView.setRangeH(rangeH); |
| | | dataView.setRangeL(rangeL); |
| | | dataView.setLimitH(limitH); |
| | | dataView.setLimitL(limitL); |
| | | dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime)); |
| | | dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime)); |
| | | switch (lineType) { |
| | | case TN: |
| | | dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime)); |
| | | break; |
| | | case TL: |
| | | dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime)); |
| | | dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime)); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | result.setStartTime(startTime); |
| | | result.setEndTime(endTime); |
| | | result.setCategories(categories); |
| | | result.setLegend(legend); |
| | | result.setDataView(dataView); |
| | | return result; |
| | | } |
| | | |