From dd0a874d305ce4173f6fa89500e5c746bafb7f4d Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期一, 24 三月 2025 16:37:33 +0800
Subject: [PATCH] 接口修改

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java |  133 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 128 insertions(+), 5 deletions(-)

diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java
index 1311665..022aa71 100644
--- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java
+++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java
@@ -1,21 +1,29 @@
 package com.iailab.module.ansteel.api;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.iailab.framework.common.util.date.DateUtils;
 import com.iailab.framework.common.util.object.ConvertUtils;
 import com.iailab.module.ansteel.api.dao.PowerRunStateDao;
+import com.iailab.module.ansteel.common.constant.CommonConstant;
+import com.iailab.module.ansteel.common.enums.PreLineTypeEnum;
+import com.iailab.module.api.mcs.AnSteelApi;
+import com.iailab.module.api.mcs.dto.ApiPointValueDTO;
+import com.iailab.module.api.mcs.dto.PowerRunStateDTO;
+import com.iailab.module.api.mcs.dto.PreDataChartRespVO;
+import com.iailab.module.api.mcs.dto.PreDataViewDTO;
 import com.iailab.module.data.api.point.DataPointApi;
-import com.iailab.module.model.api.mcs.AnSteelApi;
-import com.iailab.module.sms.api.dto.PowerRunStateDTO;
+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 lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
 import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -24,6 +32,9 @@
 
     @Autowired
     private DataPointApi dataPointApi;
+
+    @Autowired
+    private McsApi mcsApi;
 
     @Autowired
     private PowerRunStateDao powerRunStateDao;
@@ -65,4 +76,116 @@
         }
         return list;
     }
+
+    @Override
+    public PreDataChartRespVO getPreDataChart(PreDataSingleChartReqVO reqVO) {
+        Map<String, String> tMap = new HashMap<>();
+        List<ChartParamDTO> list = mcsApi.getChartParamList(reqVO.getChartCode());
+        if (CollectionUtils.isEmpty(list)) {
+            return null;
+        }
+        list.forEach(item -> {
+            tMap.put(item.getParamCode(), item.getParamValue());
+        });
+        String itemCode = tMap.get(CommonConstant.ITEM_CODE);
+        if (itemCode == null) {
+            return null;
+        }
+        String resultStr = tMap.get(CommonConstant.RESULT_STR);
+        if (resultStr == null) {
+            return null;
+        }
+        String resultIndex = tMap.get(CommonConstant.RESULT_INDEX);
+
+        PredictItemVO predictItem = mcsApi.getPredictItemByItemNo(itemCode);
+        if (predictItem == null || predictItem.getLastTime() == null) {
+            return null;
+        }
+        String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat();
+        PreLineTypeEnum lineType = tMap.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(tMap.get(CommonConstant.LINE_TYPE));
+        int lengthLeft = tMap.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(tMap.get(CommonConstant.LENGTH_LEFT)).intValue();
+        int lengthRight = tMap.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(tMap.get(CommonConstant.LENGTH_RIGHT)).intValue();
+        String trendsDataH = tMap.get(CommonConstant.TRENDSDATA_H) == null ? null : tMap.get(CommonConstant.TRENDSDATA_H);
+        String trendsDataL = tMap.get(CommonConstant.TRENDSDATA_L) == null ? null : tMap.get(CommonConstant.TRENDSDATA_L);
+
+        Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight);
+        Date predictTime = timeArray[0];
+        Date startTime = timeArray[1];
+        Date endTime = timeArray[2];
+
+        PreDataChartRespVO result = ConvertUtils.sourceToTarget(mcsApi.getPreDataSingleChart(reqVO), PreDataChartRespVO.class);
+        PreDataViewRespDTO dataView = result.getDataView();
+        PreDataViewDTO preDataView = ConvertUtils.sourceToTarget(dataView, PreDataViewDTO.class);
+        if(trendsDataH != null) {
+            ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO();
+            pointValueQueryDTO.setPointNo(trendsDataH);
+            List<ApiPointValueDTO> trendsDataHList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class);
+            preDataView.setTrendsDataH(trendsDataHList);
+        }
+        if(trendsDataL != null) {
+            ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO();
+            pointValueQueryDTO.setPointNo(trendsDataL);
+            List<ApiPointValueDTO> trendsDataLList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class);
+            preDataView.setTrendsDataL(trendsDataLList);
+        }
+        MmItemOutputDTO outputDTO = mcsApi.getItemOutputByItemid(predictItem.getId(), resultStr, resultIndex);
+
+        PreItemResultReqVO preItemResultReqVO = new PreItemResultReqVO();
+        preItemResultReqVO.setOutputid(outputDTO.getId());
+        preItemResultReqVO.setStartTime(startTime);
+        preItemResultReqVO.setEndTime(endTime);
+        preItemResultReqVO.setTimeFormat(timeFormat);
+        switch (lineType) {
+            case TN:
+                if(reqVO.getChartCode().equals(CommonConstant.LDG_CHARRCODE)){
+                    preDataView.setPreData(mcsApi.getItemResult(preItemResultReqVO));
+                }else{
+                    preDataView.setPreData(mcsApi.getItemResult(preItemResultReqVO));
+                }
+
+                break;
+            case TL:
+                if(reqVO.getChartCode().equals(CommonConstant.LDG_CHARRCODE)){
+                    preDataView.setPreData(mcsApi.getItemResultLastPoint(preItemResultReqVO));
+                }else{
+                    preDataView.setPreData(mcsApi.getItemResultLastPoint(preItemResultReqVO));
+                }
+                break;
+            default:
+                break;
+        }
+        result.setPreDataView(preDataView);
+        return result;
+    }
+
+    private Date[] calResultTime(PredictItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) {
+        Date[] result = new Date[3];
+        Date predictTime = predictItem.getLastTime();
+        Integer granularity = predictItem.getGranularity();
+        Date startTime = startTimeReq;
+        if (startTime == null) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(predictItem.getLastTime());
+            calendar.add(Calendar.SECOND, -1 * lengthLeft * granularity);
+            startTime = calendar.getTime();
+        }
+        Date endTime = endTimeReq;
+        if (endTime == null) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(predictItem.getLastTime());
+            calendar.add(Calendar.SECOND, lengthRight * granularity);
+            endTime = calendar.getTime();
+        }
+        if (endTime.getTime() <= startTime.getTime()) {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(startTime);
+            calendar.add(Calendar.SECOND, lengthRight * granularity);
+            endTime = calendar.getTime();
+        }
+        result[0] = predictTime;
+        result[1] = startTime;
+        result[2] = endTime;
+        return result;
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3