houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package com.iailab.module.prod.service.impl;
 
import com.iailab.common.dto.echarts.BarLineDTO;
import com.iailab.common.dto.echarts.SeriesItem;
import com.iailab.common.enums.CdbmEnum;
import com.iailab.common.utils.HttpsRequest;
import com.iailab.module.data.dto.FeignQueryPointDTO;
import com.iailab.module.data.dto.ApiDataDTO;
import com.iailab.module.data.api.IFeignDataApi;
import com.iailab.module.param.service.PageParmService;
import com.iailab.module.prod.dto.PageCharsDTO;
import com.iailab.module.quality.service.QualityQualityTrendDayService;
import com.iailab.module.prod.service.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.*;
 
@Service
public class PageCharsServiceImpl implements PageCharsService {
 
    @Resource
    private IFeignDataApi iFeignDataApi;
 
    @Resource
    private HttpsRequest httpsRequest;
 
    @Resource
    private PageParmService pageParmService;
 
    @Resource
    private PrdCurrentPerformanceService prdCurrentPerformanceService;
 
    @Resource
    private PrdCurrentSaleService prdCurrentSaleService;
 
    @Resource
    private PrdDayProdService prdDayProdService;
 
    @Resource
    private PrdPlanMonService prdPlanMonService;
 
    @Resource
    private PrdPlanYearService prdPlanYearService;
 
    @Resource
    private QualityQualityTrendDayService qualityQualityTrendDayService;
 
    @Override
    public List<PageCharsDTO> getData(String page) {
 
        String chars = pageParmService.selectValue(page, "chars");
        String length = pageParmService.selectValue(page, "length");
        String pointLength = pageParmService.selectValue(page, "point_length");
        String coal = pageParmService.selectValue(page, "coal");
        String point = pageParmService.selectValue(page, "point")==null?"":pageParmService.selectValue(page, "point");
        List<String> coalList = Arrays.asList(coal.split(";"));
        List<String> pointList = Arrays.asList(point.split(";"));
        List<String> charsCodeList = Arrays.asList(chars.split(";"));
        List<PageCharsDTO> list = new ArrayList<>();
        charsCodeList.stream().forEach(
                item -> {
                        //如果数据源为报表,类型为煤质或产量,传一个煤种参数
                    if(CdbmEnum.HF.getCode().equals(item)||CdbmEnum.LF.getCode().equals(item)||CdbmEnum.SF.getCode().equals(item)||CdbmEnum.RZ.getCode().equals(item)||CdbmEnum.CL.getCode().equals(item)) {
                        coalList.stream().forEach(
                                coalItem->{
                                    list.add(getPageChars(item, length,coalItem));
                                }
                        );
                    }else if(item.equals("point")){
                        //如果数据源为point,传一个测点参数
                        pointList.stream().forEach(
                                pointItem->{
                                    list.add(getPageChars(item,pointLength,pointItem));
                                }
                        );
                    }else {
                        list.add(getPageChars(item, length,""));
                    }
                }
        );
 
        return list;
    }
 
    public PageCharsDTO getPageChars(String charsCode, String length,String param) {
        PageCharsDTO dto = new PageCharsDTO();
        BarLineDTO barLine;
 
        try {
            switch (charsCode) {
                case "plan":
                    //计划
                    barLine = prdPlanMonService.barLine(length);
                    dto.setCurrentValue(prdPlanMonService.currentValue()==null?new BigDecimal(0):prdPlanMonService.currentValue());
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("plan").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "cl":
                    //产量
                    barLine = prdDayProdService.barLine(length,param);
                    dto.setCurrentValue(prdDayProdService.currentValue(param)==null?new BigDecimal(0):prdDayProdService.currentValue(param));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("cl").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "groundsales":
                    //地销混煤
                    barLine = prdCurrentSaleService.barLine(length,"groundsales");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("groundsales")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("groundsales"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("groundsales").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "medblock":
                    //洗中块外运
                    barLine = prdCurrentSaleService.barLine(length,"medblock");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("medblock")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("medblock"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("medblock").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "nubmeasure":
                    //洗小块外运
                    barLine = prdCurrentSaleService.barLine(length,"nubmeasure");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("nubmeasure")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("nubmeasure"));
                    dto.setBarLineDTO(barLine);
                    dto.setLength(length);
                    dto.setUnit(CdbmEnum.getEumByCode("nubmeasure").getUnit());
                    //调用模型方法
                    this.run(dto);
                    break;
                case "gangue":
                    //矸石外运
                    barLine = prdCurrentSaleService.barLine(length,"gangue");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("gangue")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("gangue"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("gangue").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "reshipped":
                    //小块转载
                    barLine = prdCurrentSaleService.barLine(length,"reshipped");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("reshipped")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("reshipped"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("reshipped").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "trainTon":
                    //火车外运吨数
                    barLine = prdCurrentSaleService.barLine(length,"trainTon");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("trainTon")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("trainTon"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("trainTon").getUnit());
                    //调用模型方法
                    this.run(dto);
                    break;
                case "trainCount":
                    //火车外运列数
                    barLine = prdCurrentSaleService.barLine(length,"trainCount");
                    dto.setCurrentValue(prdCurrentSaleService.currentValue("trainCount")==null?new BigDecimal(0):prdCurrentSaleService.currentValue("trainCount"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("trainCount").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "dbl":
                    //达标率
                    dto.setUnit(CdbmEnum.getEumByCode("dbl").getUnit());
                    barLine = prdDayProdService.barLine(length,"dbl");
                    dto.setCurrentValue(prdDayProdService.currentValue("dbl")==null?new BigDecimal(0):prdDayProdService.currentValue("dbl"));
                    dto.setBarLineDTO(barLine);
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "hf":
                    //灰分
                    barLine = qualityQualityTrendDayService.barLine(length,"hf",param);
                    dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"hf")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"hf"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("hf").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "lf":
                    //硫分
                    barLine = qualityQualityTrendDayService.barLine(length,"lf",param);
                    dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"lf")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"lf"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("lf").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "sf":
                    //水分
                    barLine = qualityQualityTrendDayService.barLine(length,"sf",param);
                    dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"sf")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"sf"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("sf").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "rz":
                    //热值
                    barLine = qualityQualityTrendDayService.barLine(length,"rz",param);
                    dto.setCurrentValue(qualityQualityTrendDayService.currentValue(param,"rz")==null?new BigDecimal(0):qualityQualityTrendDayService.currentValue(param,"rz"));
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByCode("rz").getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                case "point":
                    //测点
                    barLine = this.pointBarline(param,length);
 
                    dto.setBarLineDTO(barLine);
                    dto.setUnit(CdbmEnum.getEumByName(param).getUnit());
                    dto.setLength(length);
                    //调用模型方法
                    this.run(dto);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(charsCode+"查图表渲染异常" + e.getMessage());
        }
        return dto;
    }
 
    private BarLineDTO pointBarline(String param,String length) {
 
        FeignQueryPointDTO dto = new FeignQueryPointDTO();
        dto.setEndTime(new Date());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(length));
        dto.setStartTime(calendar.getTime());
        dto.setPointCode(CdbmEnum.getEumByName(param).getCode());
        dto.setType("float");
        List<ApiDataDTO> list = iFeignDataApi.queryPointValues(dto);
 
        //封装echarsDto
        BarLineDTO barLineDTO = new BarLineDTO();
        List<String> legend = new ArrayList<>();
        List<String> categories = new ArrayList<>();
        List<SeriesItem> series = new ArrayList<>();
        SeriesItem seriesItem = new SeriesItem();
        seriesItem.setName(CdbmEnum.getEumByName(param).getDesc());
        List<Object[]> seriesData = new ArrayList<>();
        for (ApiDataDTO entity : list) {
            // 将数据作为图表数据
            seriesData.add(new Object[]{entity.getTimeStamp(), entity.getDataValue()});
        }
        seriesItem.setData(seriesData);
        series.add(seriesItem);
        barLineDTO.setLegend(legend);
        barLineDTO.setSeries(series);
        barLineDTO.setValueName(CdbmEnum.getEumByName(param).getDesc());
 
        return barLineDTO;
 
        }
 
 
    private PageCharsDTO run(PageCharsDTO dto){
        dto.setSuggest("暂无建议");
        dto.setSuggestTime(new Date());
        dto.setAvg("");
        dto.setMax("");
        dto.setMin("");
        return dto;
    }
}