jinpengyong
2023-11-10 4024ef51a8d22d575dc929d806d49b30598b422d
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
package com.moral.api.service.impl;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.text.NumberFormat;
import java.util.*;
import java.util.stream.Collectors;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.CityAqi;
import com.moral.api.entity.CityAqiDaily;
import com.moral.api.entity.CityAqiMonthly;
import com.moral.api.entity.Device;
import com.moral.api.entity.HistoryDaily;
import com.moral.api.entity.HistoryHourly;
import com.moral.api.entity.HistoryMonthly;
import com.moral.api.entity.Organization;
import com.moral.api.entity.Sensor;
import com.moral.api.entity.SysDictData;
import com.moral.api.service.CityAqiDailyService;
import com.moral.api.service.CityAqiMonthlyService;
import com.moral.api.service.CityAqiService;
import com.moral.api.service.DeviceService;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryHourlyService;
import com.moral.api.service.HistoryMonthlyService;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.ProfessionService;
 
import com.moral.api.service.SensorService;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
 
import com.moral.util.AmendUtils;
import com.moral.util.DateUtils;
 
/**
 * <p>
 * 行业贡献率相关接口
 * </p>
 *
 * @author moral
 * @since 2021-12-23
 */
@Service
public class ProfessionServiceImpl implements ProfessionService {
 
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private RedisTemplate redisTemplate;
 
    @Autowired
    private HistoryMonthlyService historyMonthlyService;
 
    @Autowired
    private HistoryDailyService historyDailyService;
 
    @Autowired
    private HistoryHourlyService historyHourlyService;
 
    @Autowired
    private CityAqiMonthlyService cityAqiMonthlyService;
 
    @Autowired
    private CityAqiDailyService cityAqiDailyService;
 
    @Autowired
    private CityAqiService cityAqiService;
 
    @Autowired
    private OrganizationService organizationService;
 
    @Autowired
    private SensorService sensorService;
 
    private static final Map<String, String> senorMap = new HashMap<>();
 
    static {
        senorMap.put(Constants.SENSOR_CODE_PM25, "PM2_5");
        senorMap.put(Constants.SENSOR_CODE_PM10, "PM10");
        senorMap.put(Constants.SENSOR_CODE_SO2, "SO2");
        senorMap.put(Constants.SENSOR_CODE_NO2, "NO2");
        senorMap.put(Constants.SENSOR_CODE_CO, "CO");
        senorMap.put(Constants.SENSOR_CODE_O3, "O3");
    }
 
    @Override
    public Set<Map<String, Object>> getProfessionsByOrganizationId(Integer organizationId) {
        //获取该组织下所有设备
        List<Map<String, Object>> devices = deviceService.getDevicesByOrganizationId(organizationId);
        Set<Map<String, Object>> result = new HashSet<>();
        for (Map<String, Object> device : devices) {
            if(Objects.nonNull(device)&&Objects.nonNull(device.get("professions"))&&device.containsKey("professions")){
                List<Map<String, Object>> professions = (List<Map<String, Object>>) device.get("professions");
                result.addAll(professions);
            }
        }
        return result;
    }
 
    @Override
    public Set<Map<String, Object>> getSensorByProfessionsAndOrganizationId(Map<String, Object> params) {
        Set<Map<String, Object>> result = new HashSet<>();
        //获取属于该行业所有设备
        Integer orgId = Integer.parseInt(params.get("organizationId").toString());
        List<String> professions = Arrays.asList(params.get("professions").toString().split(","));
        List<Device> devices = getDevicesOfProfessions(orgId, professions);
        //从redis获取设备详细信息
        for (Device device : devices) {
            device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, device.getMac());
            List<Sensor> sensors = device.getVersion().getSensors();
            for (Sensor sensor : sensors) {
                Map<String, Object> sensorMap = new HashMap<>();
                sensorMap.put("sensorCode", sensor.getCode());
                sensorMap.put("sensorName", sensor.getName());
                result.add(sensorMap);
            }
        }
        return result;
    }
 
    private List<Device> getDevicesOfProfessions(Integer orgId, List<String> professions) {
        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("mac", "profession")
                .eq("organization_id", orgId)
                .eq("is_delete", Constants.NOT_DELETE);
        List<Device> devices = deviceService.list(queryWrapper);
        devices = devices.stream().filter(device -> {
            String[] list = device.getProfession().split(",");
            for (String s : list) {
                if (professions.contains(s)) {
                    return true;
                }
            }
            return false;
        }).collect(Collectors.toList());
        return devices;
    }
 
    @Override
    public Map<String, Object> professionContribution(Map<String, Object> params) {
        int orgId = Integer.parseInt(params.get("organizationId").toString());
        List<String> professions = Arrays.asList(params.get("professions").toString().split(","));
        String type = params.get("type").toString();
        String time = params.get("time").toString();
        String sensorCode = params.get("sensorCode").toString();
        Map<String, Object> result = new HashMap<>();
 
        switch (type) {
            case "year":
                result = professionContributionOfYear(orgId, professions, time, sensorCode);
                break;
            case "month":
                result = professionContributionOfMonth(orgId, professions, time, sensorCode);
                break;
            case "day":
                result = professionContributionOfDay(orgId, professions, time, sensorCode);
                break;
            default:
                break;
        }
        return result;
    }
 
    //贡献率,年
    private Map<String, Object> professionContributionOfYear(Integer orgId, List<String> professions, String time, String sensorCode) {
        Map<String, Object> result = new HashMap<>();
 
        //1.时间信息结果
        List<String> timeLag = DateUtils.getTimeLag(time);
        result.put("time", timeLag);
 
 
        //根据组织获取区域定位
        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
        organizationQueryWrapper.select("location_level_code")
                .eq("id", orgId);
        Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode();
 
 
        //本市本年所有月数据
        QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>();
        cityAqiMonthlyQueryWrapper.select("time", "value")
                .eq("city_code", locationLevelCode)
                .likeRight("time", time);
        List<Map<String, Object>> cityAqis = cityAqiMonthlyService.listMaps(cityAqiMonthlyQueryWrapper);
        Map<String, Object> cityAqiMap = new HashMap<>();
        if (!ObjectUtils.isEmpty(cityAqis)) {
            for (Map<String, Object> cityAqi : cityAqis) {
                cityAqiMap.put(cityAqi.get("time").toString().substring(0, 7), cityAqi.get("value"));
            }
        }
 
 
        //该组织所有设备信息,本年所有月数据
        List<String> allMacs = deviceService.getMacsByOrganizationId(orgId);
        List<HistoryMonthly> allDeviceData = historyMonthlyService.getValueByMacs(allMacs, time);
        Map<String, List<HistoryMonthly>> allDeviceDataMap = allDeviceData.stream()
                .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 7)));
 
 
        //本市数据结果集
        Map<String, Object> resultCityDataMap = new HashMap<>();
        List<Map<String, Object>> cityDataList = new ArrayList<>();
        //所有设备每个时间点,和值
        Map<String, Object> allDeviceSumMap = new HashMap<>();
        for (String yearMonth : timeLag) {
            //所有设备该因子累加值
            Double allDeviceSum = null;
            List<HistoryMonthly> historyMonthlyList = allDeviceDataMap.get(yearMonth);
            if (!ObjectUtils.isEmpty(historyMonthlyList)) {
                allDeviceSum = historyMonthlyService.calculatedValue(historyMonthlyList, sensorCode, "sum");
            }
            allDeviceSumMap.put(yearMonth, allDeviceSum);
 
 
            //本市值
            Double cityValue = null;
            if (cityAqiMap.get(yearMonth) != null) {
                Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonth).toString(), Map.class);
                //判断城市aqi是否有该因子数据
                String sensorName = senorMap.get(sensorCode);
                if (sensorName != null) {
                    cityValue = Double.parseDouble(dataValue.get(sensorName).toString());
                }
            }
            Map<String, Object> cityDataMap = new HashMap<>();
            //本市数据
            cityDataMap.put("value", cityValue);
            cityDataList.add(cityDataMap);
        }
 
        //2.本市数据结果
        resultCityDataMap.put("data", cityDataList);
        result.put("本市", resultCityDataMap);
 
 
        for (String profession : professions) {
            //每个行业数据结果集
            HashMap<String, Object> professionMap = new HashMap<>();
            List<Map<String, Object>> dataList = new ArrayList<>();
 
 
            //查询行业名称
            String professionName = null;
            Map<String, Object> dictData = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DICT_DATA_KEY);
            List<SysDictData> professionInfo = (List<SysDictData>) dictData.get("profession");
            for (SysDictData sysDictData : professionInfo) {
                if (sysDictData.getDataKey().equals(profession)) {
                    professionName = sysDictData.getDataValue();
                    break;
                }
            }
 
 
            //获取该行业所有设备信息,年所有月数据
            List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
            List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList());
            List<HistoryMonthly> professionDeviceData = historyMonthlyService.getValueByMacs(professionMacs, time);
            Map<String, List<HistoryMonthly>> professionDataMap = professionDeviceData.stream()
                    .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 7)));
 
 
            for (String resultTime : timeLag) {
                //每个时间点数据
                Map<String, Object> timeDataMap = new HashMap<>();
                Object o = allDeviceSumMap.get(resultTime);
                Double allDeviceSum = null;
                if (o != null) {
                    allDeviceSum = Double.parseDouble(o.toString());
                }
 
                List<HistoryMonthly> professionDeviceHistoryMonthlyList = professionDataMap.get(resultTime);
                //贡献率
                String contributionRate = null;
                Double professionAvg = null;
                if (!ObjectUtils.isEmpty(professionDeviceHistoryMonthlyList)) {
                    //该行业均值计算
                    professionAvg = historyMonthlyService.calculatedValue(professionDeviceHistoryMonthlyList, sensorCode, "avg");
                    //该行业累加值计算
                    Double professionSum = historyMonthlyService.calculatedValue(professionDeviceHistoryMonthlyList, sensorCode, "sum");
                    //行业贡献率计算
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMaximumFractionDigits(2);
                    if (allDeviceSum != null && allDeviceSum != 0d) {
                        contributionRate = numberFormat.format(professionSum / (allDeviceSum) * 100) + "%";
                    }
                }
 
                //行业均值
                timeDataMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
                //贡献率
                timeDataMap.put("name", contributionRate);
                dataList.add(timeDataMap);
            }
            professionMap.put("data", dataList);
            result.put(professionName, professionMap);
        }
        return result;
    }
 
    //贡献率,月
    private Map<String, Object> professionContributionOfMonth(Integer orgId, List<String> professions, String time, String sensorCode) {
        Map<String, Object> result = new HashMap<>();
 
        //1.时间信息结果
        List<String> timeLag = DateUtils.getTimeLag(time);
        result.put("time", timeLag);
 
 
        //根据组织获取区域定位
        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
        organizationQueryWrapper.select("location_level_code")
                .eq("id", orgId);
        Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode();
 
 
        //本市本月所有日数据
        QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
        cityAqiDailyQueryWrapper.select("time", "value")
                .eq("city_code", locationLevelCode)
                .likeRight("time", time);
        List<Map<String, Object>> cityAqis = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
        Map<String, Object> cityAqiMap = new HashMap<>();
        if (!ObjectUtils.isEmpty(cityAqis)) {
            for (Map<String, Object> cityAqi : cityAqis) {
                cityAqiMap.put(cityAqi.get("time").toString().substring(0, 10), cityAqi.get("value"));
            }
        }
 
 
        //该组织所有设备信息,本月所有日数据
        List<String> allMacs = deviceService.getMacsByOrganizationId(orgId);
        List<HistoryDaily> allDeviceData = historyDailyService.getValueByMacs(allMacs, time);
        Map<String, List<HistoryDaily>> allDeviceDataMap = allDeviceData.stream()
                .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 10)));
 
 
        //本市数据结果集
        Map<String, Object> resultCityDataMap = new HashMap<>();
        List<Map<String, Object>> cityDataList = new ArrayList<>();
        //所有设备每个时间点,和值
        Map<String, Object> allDeviceSumMap = new HashMap<>();
        for (String yearMonthDay : timeLag) {
            //所有设备该因子累加值
            Double allDeviceSum = null;
            List<HistoryDaily> historyDailyList = allDeviceDataMap.get(yearMonthDay);
            if (!ObjectUtils.isEmpty(historyDailyList)) {
                allDeviceSum = historyDailyService.calculatedValue(historyDailyList, sensorCode, "sum");
            }
            allDeviceSumMap.put(yearMonthDay, allDeviceSum);
 
 
            //本市值
            Double cityValue = null;
            if (cityAqiMap.get(yearMonthDay) != null) {
                Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDay).toString(), Map.class);
                //判断城市aqi是否有该因子数据
                String sensorName = senorMap.get(sensorCode);
                if (sensorName != null) {
                    cityValue = Double.parseDouble(dataValue.get(sensorName).toString());
                }
            }
            Map<String, Object> cityDataMap = new HashMap<>();
            //本市数据
            cityDataMap.put("value", cityValue);
            cityDataList.add(cityDataMap);
        }
 
        //2.本市数据结果
        resultCityDataMap.put("data", cityDataList);
        result.put("本市", resultCityDataMap);
 
 
        for (String profession : professions) {
            //每个行业数据结果集
            HashMap<String, Object> professionMap = new HashMap<>();
            List<Map<String, Object>> dataList = new ArrayList<>();
 
 
            //查询行业名称
            String professionName = null;
            Map<String, Object> dictData = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DICT_DATA_KEY);
            List<SysDictData> professionInfo = (List<SysDictData>) dictData.get("profession");
            for (SysDictData sysDictData : professionInfo) {
                if (sysDictData.getDataKey().equals(profession)) {
                    professionName = sysDictData.getDataValue();
                    break;
                }
            }
 
 
            //获取该行业所有设备信息,年所有月数据
            List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
            List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList());
            List<HistoryDaily> professionDeviceData = historyDailyService.getValueByMacs(professionMacs, time);
            Map<String, List<HistoryDaily>> professionDataMap = professionDeviceData.stream()
                    .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 10)));
 
 
            for (String resultTime : timeLag) {
                //每个时间点数据
                Map<String, Object> timeDataMap = new HashMap<>();
                Object o = allDeviceSumMap.get(resultTime);
                Double allDeviceSum = null;
                if (o != null) {
                    allDeviceSum = Double.parseDouble(o.toString());
                }
 
                List<HistoryDaily> preofessionDeviceHistoryDailyList = professionDataMap.get(resultTime);
                //贡献率
                String contributionRate = null;
                Double professionAvg = null;
                if (!ObjectUtils.isEmpty(preofessionDeviceHistoryDailyList)) {
                    //该行业均值计算
                    professionAvg = historyDailyService.calculatedValue(preofessionDeviceHistoryDailyList, sensorCode, "avg");
                    //该行业累加值计算
                    Double professionSum = historyDailyService.calculatedValue(preofessionDeviceHistoryDailyList, sensorCode, "sum");
                    //行业贡献率计算
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMaximumFractionDigits(2);
                    if (allDeviceSum != null && allDeviceSum != 0d) {
                        contributionRate = numberFormat.format(professionSum / (allDeviceSum) * 100) + "%";
                    }
                }
 
                //行业均值
                timeDataMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
                //贡献率
                timeDataMap.put("name", contributionRate);
                dataList.add(timeDataMap);
            }
            professionMap.put("data", dataList);
            result.put(professionName, professionMap);
        }
        return result;
    }
 
    private Map<String, Object> professionContributionOfDay(Integer orgId, List<String> professions, String time, String sensorCode) {
        Map<String, Object> result = new HashMap<>();
 
        //1.时间信息结果
        List<String> timeLag = DateUtils.getTimeLag(time);
        result.put("time", timeLag);
 
 
        //根据组织获取区域定位
        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
        organizationQueryWrapper.select("location_level_code")
                .eq("id", orgId);
        Integer locationLevelCode = organizationService.getOne(organizationQueryWrapper).getLocationLevelCode();
 
        //查询因子上下限
        QueryWrapper<Sensor> sensorQueryWrapper = new QueryWrapper<>();
        sensorQueryWrapper.select("lower", "upper").eq("code", sensorCode);
        Sensor sensor = sensorService.getOne(sensorQueryWrapper);
        Double sensorLower = null;
        Double sensorUpper = null;
        if (sensor != null) {
            sensorLower = sensor.getLower();
            sensorUpper = sensor.getUpper();
        }
 
 
        //本市本日所有小时数据
        QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>();
        cityAqiQueryWrapper.select("time", "value")
                .eq("city_code", locationLevelCode)
                .likeRight("time", time);
        List<Map<String, Object>> cityAqis = cityAqiService.listMaps(cityAqiQueryWrapper);
        Map<String, Object> cityAqiMap = new HashMap<>();
        if (!ObjectUtils.isEmpty(cityAqis)) {
            for (Map<String, Object> cityAqi : cityAqis) {
                cityAqiMap.put(cityAqi.get("time").toString().substring(0, 13), cityAqi.get("value"));
            }
        }
 
 
        //该组织所有设备信息,本日所有小时数据
        List<String> allMacs = deviceService.getMacsByOrganizationId(orgId);
        List<HistoryHourly> allDeviceData = historyHourlyService.getValueByMacs(allMacs, time);
        Map<String, List<HistoryHourly>> allDeviceDataMap = allDeviceData.stream()
                .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 13)));
 
 
        //本市数据结果集
        Map<String, Object> resultCityDataMap = new HashMap<>();
        List<Map<String, Object>> cityDataList = new ArrayList<>();
        //所有设备每个时间点,和值
        Map<String, Object> allDeviceSumMap = new HashMap<>();
        for (String yearMonthDayHour : timeLag) {
            //所有设备该因子累加值
            Double allDeviceSum = null;
            List<HistoryHourly> historyHourlyList = allDeviceDataMap.get(yearMonthDayHour);
            if (!ObjectUtils.isEmpty(historyHourlyList)) {
                allDeviceSum = historyHourlyService.calculatedValue(historyHourlyList, sensorCode, "sum", sensorLower, sensorUpper);
            }
            allDeviceSumMap.put(yearMonthDayHour, allDeviceSum);
 
 
            //本市值
            Double cityValue = null;
            if (cityAqiMap.get(yearMonthDayHour) != null) {
                Map<String, Object> dataValue = JSONObject.parseObject(cityAqiMap.get(yearMonthDayHour).toString(), Map.class);
                //判断城市aqi是否有该因子数据
                String sensorName = senorMap.get(sensorCode);
                if (sensorName != null) {
                    cityValue = Double.parseDouble(dataValue.get(sensorName).toString());
                }
            }
            Map<String, Object> cityDataMap = new HashMap<>();
            //本市数据
            cityDataMap.put("value", cityValue);
            cityDataList.add(cityDataMap);
        }
 
        //2.本市数据结果
        resultCityDataMap.put("data", cityDataList);
        result.put("本市", resultCityDataMap);
 
 
        for (String profession : professions) {
            //每个行业数据结果集
            HashMap<String, Object> professionMap = new HashMap<>();
            List<Map<String, Object>> dataList = new ArrayList<>();
 
 
            //查询行业名称
            String professionName = null;
            Map<String, Object> dictData = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DICT_DATA_KEY);
            List<SysDictData> professionInfo = (List<SysDictData>) dictData.get("profession");
            for (SysDictData sysDictData : professionInfo) {
                if (sysDictData.getDataKey().equals(profession)) {
                    professionName = sysDictData.getDataValue();
                    break;
                }
            }
 
 
            //获取该行业所有设备信息,年所有月数据
            List<Device> professionDevices = getDevicesOfProfessions(orgId, Collections.singletonList(profession));
            List<String> professionMacs = professionDevices.stream().map(Device::getMac).collect(Collectors.toList());
            List<HistoryHourly> professionDeviceData = historyHourlyService.getValueByMacs(professionMacs, time);
            Map<String, List<HistoryHourly>> professionDataMap = professionDeviceData.stream()
                    .collect(Collectors.groupingBy(o -> DateUtils.dateToDateString(o.getTime()).substring(0, 13)));
 
 
            for (String resultTime : timeLag) {
                //每个时间点数据
                Map<String, Object> timeDataMap = new HashMap<>();
                Object o = allDeviceSumMap.get(resultTime);
                Double allDeviceSum = null;
                if (o != null) {
                    allDeviceSum = Double.parseDouble(o.toString());
                }
 
                List<HistoryHourly> preofessionDeviceHistoryHourlyList = professionDataMap.get(resultTime);
                //贡献率
                String contributionRate = null;
                Double professionAvg = null;
                if (!ObjectUtils.isEmpty(preofessionDeviceHistoryHourlyList)) {
                    //该行业均值计算
                    professionAvg = historyHourlyService.calculatedValue(preofessionDeviceHistoryHourlyList, sensorCode, "avg", sensorLower, sensorUpper);
                    //该行业累加值计算
                    Double professionSum = historyHourlyService.calculatedValue(preofessionDeviceHistoryHourlyList, sensorCode, "sum", sensorLower, sensorUpper);
                    //行业贡献率计算
                    NumberFormat numberFormat = NumberFormat.getInstance();
                    numberFormat.setMaximumFractionDigits(2);
                    if (allDeviceSum != null && allDeviceSum != 0d) {
                        contributionRate = numberFormat.format(professionSum / (allDeviceSum) * 100) + "%";
                    }
                }
 
                //行业均值
                timeDataMap.put("value", professionAvg == null ? null : AmendUtils.sciCal(professionAvg, 0));
                //贡献率
                timeDataMap.put("name", contributionRate);
                dataList.add(timeDataMap);
            }
            professionMap.put("data", dataList);
            result.put(professionName, professionMap);
        }
        return result;
    }
}