鞍钢鲅鱼圈能源管控系统后端代码
liriming
9 天以前 dd0a874d305ce4173f6fa89500e5c746bafb7f4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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.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.*;
import java.util.stream.Collectors;
 
@Slf4j
@Service
public class McsServiceImpl implements AnSteelApi {
 
    @Autowired
    private DataPointApi dataPointApi;
 
    @Autowired
    private McsApi mcsApi;
 
    @Autowired
    private PowerRunStateDao powerRunStateDao;
 
    @Override
    public List<PowerRunStateDTO> getPowerRunState() {
        List<PowerRunStateDTO> list = ConvertUtils.sourceToTarget(powerRunStateDao.selectList(new QueryWrapper<>()), PowerRunStateDTO.class);
        if (!CollectionUtils.isEmpty(list)) {
            list.stream().map(item -> {
                StringBuffer sb = new StringBuffer();
                sb.append(item.getQhRate());
                sb.append(",");
                sb.append(item.getFhRate());
                sb.append(",");
                sb.append(item.getGasTotal());
                sb.append(",");
                sb.append(item.getGasCost());
                sb.append(",");
                sb.append(item.getGasSurplus());
                sb.append(",");
                sb.append(item.getBfg());
                sb.append(",");
                sb.append(item.getLdg());
                sb.append(",");
                sb.append(item.getCog());
                String[] arr = sb.toString().split(",");
                Map<String, Object> adjValue = dataPointApi.queryPointsRealValue(Arrays.asList(arr));
                item.setQhRate(ObjectUtils.isEmpty(adjValue.get(arr[0])) ? "0" : new BigDecimal(adjValue.get(arr[0]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setFhRate(ObjectUtils.isEmpty(adjValue.get(arr[1])) ? "0" : new BigDecimal(adjValue.get(arr[1]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setGasTotal(ObjectUtils.isEmpty(adjValue.get(arr[2])) ? "0" : new BigDecimal(adjValue.get(arr[2]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setGasCost(ObjectUtils.isEmpty(adjValue.get(arr[3])) ? "0" : new BigDecimal(adjValue.get(arr[3]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setGasSurplus(ObjectUtils.isEmpty(adjValue.get(arr[4])) ? "0" : new BigDecimal(adjValue.get(arr[4]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setBfg(ObjectUtils.isEmpty(adjValue.get(arr[5])) ? "0" : new BigDecimal(adjValue.get(arr[5]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setLdg(ObjectUtils.isEmpty(adjValue.get(arr[6])) ? "0" : new BigDecimal(adjValue.get(arr[6]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                item.setCog(ObjectUtils.isEmpty(adjValue.get(arr[7])) ? "0" : new BigDecimal(adjValue.get(arr[7]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
 
                return item;
            }).collect(Collectors.toList());
        }
        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;
    }
 
}