2021与蓝度共同重构项目,服务端
liuhaonan
2022-11-04 e55c8b0a92eb9715edd90c31dfd4de51a47b588b
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
package com.sandu.ximon.admin.service;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.config.VnnoxConstant;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartbeatReportInnerFrame;
import com.sandu.ximon.admin.redis.DeviceRedisKey;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.*;
import com.sandu.ximon.admin.utils.request.VnnoxScreenStatusType;
import com.sandu.ximon.admin.utils.response.VnnoxPlayerListResponse;
import com.sandu.ximon.admin.utils.response.VnnoxPlayerResponse;
import com.sandu.ximon.admin.utils.response.VnnoxResult;
import com.sandu.ximon.admin.utils.response.VnnoxResultResponse;
import com.sandu.ximon.admin.vo.*;
import com.sandu.ximon.dao.domain.LedPlayerEntity;
import com.sandu.ximon.dao.domain.LedPlayerInfoEntity;
import com.sandu.ximon.dao.domain.LedV2RegisterResultEntity;
import com.sandu.ximon.dao.enums.PoleBindingEnums;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.net.URISyntaxException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Author liuhaonan
 * @Date 2021/12/22 14:18
 * @Version 1.0
 */
@Service
@AllArgsConstructor
public class VnnoxService {
 
 
    private VnnoxAPIUtil vnnoxAPIUtil;
 
    private RedisUtils redisUtils;
 
    private LedPlayerEntityService ledPlayerEntityService;
 
    private VnnoxProgramAPIUtil vnnoxProgramAPIUtil;
    private CountDownLatchUtil countDownLatchUtil;
 
    /**
     * 设备校验注册
     *
     * @param sn
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public LedV2RegisterResultEntity validateSN(String name, String sn) throws URISyntaxException {
        LedV2RegisterResultEntity ledV2RegisterResultEntity = new LedV2RegisterResultEntity();
 
        //  判断数据库是否存在,若不存在,判断是否已经注册到Vnnox服务器
        //LedPlayerEntity ledPlayerEntity = vnnoxDao.getBySN(sn);
        // LambdaQueryWrapper<LedPlayerEntity> eq = Wrappers.lambdaQuery(LedPlayerEntity.class).eq(LedPlayerEntity::getSn, sn);
        LedPlayerEntity ledPlayerEntity = ledPlayerEntityService.getBySn(sn);
        if (null != ledPlayerEntity) {
            ledV2RegisterResultEntity.setRegister(1);
            ledV2RegisterResultEntity.setMsg("设备已存在!");
            return ledV2RegisterResultEntity;
        }
 
        Integer page = 0;
        Integer limit = 100;
        List<VnnoxPlayerResponse> playerList;
        //  获取Vnnox服务器列表
        VnnoxPlayerListResponse response = vnnoxAPIUtil.getPlayerList(limit, page, name);
        playerList = response.getRows();
        Integer total = response.getTotal() - limit;
        while (total > 0) {
            page = page + 1;
            total = total - limit;
            response = vnnoxAPIUtil.getPlayerList(limit, page, name);
            playerList.addAll(response.getRows());
        }
        ledPlayerEntity = new LedPlayerEntity();
        for (VnnoxPlayerResponse res : playerList) {
            if (res.getSn().equals(sn)) {
                ledPlayerEntity.setSn(sn);
                ledPlayerEntity.setPlayerId(res.getPlayerId());
                ledPlayerEntity.setPlayerName(res.getName());
                ledPlayerEntity.setCreateTimestamp(new Date().getTime());
                ledPlayerEntityService.saveLed(ledPlayerEntity);
                ledV2RegisterResultEntity.setRegister(1);
                ledV2RegisterResultEntity.setMsg("设备校验通过,设备注册成功!");
                return ledV2RegisterResultEntity;
            }
        }
 
        ledV2RegisterResultEntity.setRegister(0);
        ledV2RegisterResultEntity.setMsg("设备未注册到平台!");
        return ledV2RegisterResultEntity;
    }
 
 
    /**
     * 屏幕状态调整-POST-JSON
     *
     * @param playerList
     * @param screenStatus
     * @return
     */
    public Map<String, Object> screenStatusChange(List<LedPlayerEntity> playerList, Integer screenStatus) {
        playerList.forEach(item -> {
            if (item.getName() == null || item.getPlayerId() == null) {
                throw new BusinessException("playerId或playerName为空");
            }
            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
                throw new BusinessException("playerId或playerName为空");
            }
        });
        VnnoxScreenStatusType type;
        if (screenStatus.equals(0)) {
            type = VnnoxScreenStatusType.CLOSE;
        } else {
            type = VnnoxScreenStatusType.OPEN;
        }
 
        VnnoxResult vnnoxResult = vnnoxAPIUtil.screenStatus(playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()), type);
 
 
        List<String> success = vnnoxResult.getSuccess();
        List<String> fail = vnnoxResult.getFail();
        //拼接成功失败的结果
        Map<String, Object> result = new HashMap<>();
        List<NovaPushResultVO> successList = new ArrayList<>();
        List<NovaPushResultVO> faileList = new ArrayList<>();
        List<String> finalSuccess = success;
        List<String> finalFail = fail;
        playerList.forEach(n -> {
            if (finalSuccess.contains(n.getPlayerId())) {
                NovaPushResultVO vo = new NovaPushResultVO();
                vo.setName(n.getName());
                vo.setPlayerId(n.getPlayerId());
                successList.add(vo);
            } else if (finalFail.contains(n.getPlayerId())) {
                NovaPushResultVO vo = new NovaPushResultVO();
                vo.setName(n.getName());
                vo.setPlayerId(n.getPlayerId());
                faileList.add(vo);
            }
        });
 
        result.put("success", successList);
        result.put("fail", faileList);
 
        //  根据屏幕状态调整REDIS标识位
        for (String playerId : vnnoxResult.getSuccess()) {
            redisUtils.set(VnnoxConstant.REDIS_SCREEN_STATUS + playerId, screenStatus);
        }
        return result;
    }
 
    public Map<String, Object> volChange(List<LedPlayerEntity> playerList, Integer vol) {
        playerList.forEach(item -> {
            if (item.getName() == null || item.getPlayerId() == null) {
                throw new BusinessException("playerId或playerName为空");
            }
            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
                throw new BusinessException("playerId或playerName为空");
            }
        });
        VnnoxResult vnnoxResult = vnnoxAPIUtil.volChange(playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()), vol);
        //  根据音量调整REDIS标识位
        for (String playerId : vnnoxResult.getSuccess()) {
            redisUtils.set(VnnoxConstant.REDIS_VOL + playerId, vol, VnnoxConstant.STATUS_TIME);
        }
        List<String> success = vnnoxResult.getSuccess();
        List<String> fail = vnnoxResult.getFail();
        //拼接成功失败的结果
        Map<String, Object> result = new HashMap<>();
        List<NovaPushResultVO> successList = new ArrayList<>();
        List<NovaPushResultVO> faileList = new ArrayList<>();
        List<String> finalSuccess = success;
        List<String> finalFail = fail;
        playerList.forEach(n -> {
            if (finalSuccess.contains(n.getPlayerId())) {
                NovaPushResultVO vo = new NovaPushResultVO();
                vo.setName(n.getName());
                vo.setPlayerId(n.getPlayerId());
                successList.add(vo);
            } else if (finalFail.contains(n.getPlayerId())) {
                NovaPushResultVO vo = new NovaPushResultVO();
                vo.setName(n.getName());
                vo.setPlayerId(n.getPlayerId());
                faileList.add(vo);
            }
        });
 
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
    }
 
    public Map<String, Object> brightnessChange(List<LedPlayerEntity> playerList, Integer brightness) {
        playerList.forEach(item -> {
            if (item.getName() == null || item.getPlayerId() == null) {
                throw new BusinessException("playerId或playerName为空");
            }
            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
                throw new BusinessException("playerId或playerName为空");
            }
        });
        VnnoxResult vnnoxResult = vnnoxAPIUtil.brightnessChange(playerList.stream().map(item -> item.getPlayerId()).collect(Collectors.toList()), brightness);
        //  根据亮度调整REDIS标识位
        for (String playerId : vnnoxResult.getSuccess()) {
            redisUtils.set(VnnoxConstant.REDIS_BRIGHTNESS + playerId, brightness, VnnoxConstant.STATUS_TIME);
        }
        List<String> success = vnnoxResult.getSuccess();
        List<String> fail = vnnoxResult.getFail();
        //拼接成功失败的结果
        Map<String, Object> result = new HashMap<>();
        List<NovaPushResultVO> successList = new ArrayList<>();
        List<NovaPushResultVO> faileList = new ArrayList<>();
        List<String> finalSuccess = success;
        List<String> finalFail = fail;
        playerList.forEach(n -> {
            if (finalSuccess.contains(n.getPlayerId())) {
                NovaPushResultVO vo = new NovaPushResultVO();
                vo.setName(n.getName());
                vo.setPlayerId(n.getPlayerId());
                successList.add(vo);
            } else if (finalFail.contains(n.getPlayerId())) {
                NovaPushResultVO vo = new NovaPushResultVO();
                vo.setName(n.getName());
                vo.setPlayerId(n.getPlayerId());
                faileList.add(vo);
            }
        });
 
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
 
    }
 
    //截屏
    public Map<String, String> getScreenShotUrl(Integer id) {
        Map<String, String> map = new HashMap();
 
        LedPlayerEntity playerEntity = ledPlayerEntityService.getById(id);
        try {
            redisUtils.delete(VnnoxConstant.REDIS_SCREEN_SHOT + playerEntity.getPlayerId());
        } catch (Exception e) {
 
        }
        VnnoxResult vnnoxResult = vnnoxAPIUtil.screenShot(playerEntity.getPlayerId());
 
        if (null == vnnoxResult) {
            map.put("code", "500");
            map.put("msg", "设备已下线");
            return map;
        }
 
        if (vnnoxResult.getSuccess().size() == 0) {
            map.put("code", "500");
            map.put("msg", "获取缩略图失败!");
            return map;
        }
        String url = null;
        Integer checkCount = 0;
        while (checkCount < 10) {
            url = redisUtils.get(VnnoxConstant.REDIS_SCREEN_SHOT + playerEntity.getPlayerId());
            if (null != url) {
                break;
            }
            try {
                Thread.sleep(2000);
                checkCount = checkCount + 1;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        map.put("url", url);
        map.put("code", "200");
        return map;
    }
 
 
    // 批量截屏
    public List<NovaScreenShorUrlVO> getScreenShotUrl(List<NovaPushResultVO> playerIds) throws InterruptedException {
        List<NovaScreenShorUrlVO> screenShorUrlList = new ArrayList<>();
 
        //从playerIds中获取playerId
        List<String> AllplayerIdsList = playerIds.stream().map(item -> item.getPlayerId()).collect(Collectors.toList());
        List<List<String>> split = CollectionUtil.split(AllplayerIdsList, 100);
        for (List<String> playerIdsList : split) {
            VnnoxResult vnnoxResult = vnnoxAPIUtil.screenShot(playerIdsList);
            LocalDateTime now = LocalDateTime.now();
            NovaScreenShorUrlVO screenShorUrlVO;
            for (String successStrId : vnnoxResult.getSuccess()) {
                screenShorUrlVO = new NovaScreenShorUrlVO();
                String url = null;
                int num = 0;
                while (num < 3) {
                    url = redisUtils.get(VnnoxConstant.REDIS_SCREEN_SHOT + successStrId);
                    if (url != null) {
                        break;
                    } else {
                        num++;
                        Thread.sleep(500);
                    }
                }
                screenShorUrlVO.setShortUrl(url);
                screenShorUrlVO.setPlayerId(successStrId);
                screenShorUrlVO.setTime(now);
                for (NovaPushResultVO bean : playerIds) {
                    if (bean.getPlayerId().equals(successStrId)) {
                        screenShorUrlVO.setName(bean.getName());
                        break;
                    }
                }
                screenShorUrlList.add(screenShorUrlVO);
            }
            for (String failStrId : vnnoxResult.getFail()) {
                screenShorUrlVO = new NovaScreenShorUrlVO();
 
                String url = null;
                screenShorUrlVO.setShortUrl(url);
                screenShorUrlVO.setPlayerId(failStrId);
                screenShorUrlVO.setTime(now);
                for (NovaPushResultVO bean : playerIds) {
                    if (bean.getPlayerId().equals(failStrId)) {
                        screenShorUrlVO.setName(bean.getName());
                        break;
                    }
                }
                screenShorUrlList.add(screenShorUrlVO);
            }
        }
        return screenShorUrlList;
    }
 
 
//    //重启
//    public VnnoxResult reboot(List<LedPlayerEntity> playerList) {
//        return vnnoxAPIUtil.reboot(
//                playerList.stream().map(
//                        item -> item.getPlayerId()
//                ).collect(Collectors.toList())
//        );
//    }
 
    //重启
    public Map<String, Object> reboot(List<NovaPushResultVO> nova) {
        List<String> playerIds = new ArrayList<>();
        nova.forEach(item -> {
            if (item.getName() == null || item.getPlayerId() == null) {
                throw new BusinessException("playerId或playerName为空");
            }
            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
                throw new BusinessException("playerId或playerName为空");
            }
            playerIds.add(item.getPlayerId());
        });
 
        VnnoxResult reboot = vnnoxAPIUtil.reboot(playerIds);
 
 
        List<String> success = reboot.getSuccess();
        List<String> fail = reboot.getFail();
        //拼接成功失败的结果
        Map<String, Object> result = new HashMap<>();
        List<NovaPushResultVO> successList = new ArrayList<>();
        List<NovaPushResultVO> faileList = new ArrayList<>();
        List<String> finalSuccess = success;
        List<String> finalFail = fail;
        nova.forEach(n -> {
            if (finalSuccess.contains(n.getPlayerId())) {
                successList.add(n);
            } else if (finalFail.contains(n.getPlayerId())) {
                faileList.add(n);
            }
        });
 
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
    }
 
    /**
     * 同步播放
     *
     * @param
     * @return
     */
    public Map<String, Object> syncPlay(List<NovaPushResultVO> nova, Integer option) {
        List<String> playerIds = new ArrayList<>();
        nova.forEach(item -> {
            if (item.getName() == null || item.getPlayerId() == null) {
                throw new BusinessException("playerId或playerName为空");
            }
            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
                throw new BusinessException("playerId或playerName为空");
            }
            playerIds.add(item.getPlayerId());
        });
        VnnoxResult vnnoxResult = vnnoxAPIUtil.syncPlay(playerIds, option);
 
        List<String> success = vnnoxResult.getSuccess();
        List<String> fail = vnnoxResult.getFail();
        //拼接成功失败的结果
        Map<String, Object> result = new HashMap<>();
        List<NovaPushResultVO> successList = new ArrayList<>();
        List<NovaPushResultVO> faileList = new ArrayList<>();
        List<String> finalSuccess = success;
        List<String> finalFail = fail;
        nova.forEach(n -> {
            if (finalSuccess.contains(n.getPlayerId())) {
                successList.add(n);
            } else if (finalFail.contains(n.getPlayerId())) {
                faileList.add(n);
            }
        });
 
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
    }
 
    /**
     * 对时
     *
     * @param
     * @return
     */
    public Map<String, Object> ntpSync(List<NovaPushResultVO> nova, boolean enable) {
        List<String> playerIds = new ArrayList<>();
        nova.forEach(item -> {
            if (item.getName() == null || item.getPlayerId() == null) {
                throw new BusinessException("playerId或playerName为空");
            }
            if (item.getPlayerId().isEmpty() || item.getName().isEmpty()) {
                throw new BusinessException("playerId或playerName为空");
            }
            playerIds.add(item.getPlayerId());
        });
        VnnoxResult vnnoxResult = vnnoxAPIUtil.ntpSync(playerIds, enable);
 
        List<String> success = vnnoxResult.getSuccess();
        List<String> fail = vnnoxResult.getFail();
        //拼接成功失败的结果
        Map<String, Object> result = new HashMap<>();
        List<NovaPushResultVO> successList = new ArrayList<>();
        List<NovaPushResultVO> faileList = new ArrayList<>();
        List<String> finalSuccess = success;
        List<String> finalFail = fail;
        nova.forEach(n -> {
            if (finalSuccess.contains(n.getPlayerId())) {
                successList.add(n);
            } else if (finalFail.contains(n.getPlayerId())) {
                faileList.add(n);
            }
        });
 
        result.put("success", successList);
        result.put("fail", faileList);
        return result;
    }
 
 
    public boolean updateDataName(Long id, String name) {
        LedPlayerEntity byId = ledPlayerEntityService.getById(id);
        if (byId == null) {
            throw new BusinessException("未找到该设备");
        }
        if (SecurityUtils.getClientId() != null) {
            boolean belong = SpringContextHolder.getBean(PoleBindingService.class).isBelong(byId.getSn(), PoleBindingEnums.VONNOX);
            if (!belong) {
                throw new BusinessException("该设备不属于您,不能修改设备信息");
            }
        }
        LedPlayerEntity led = new LedPlayerEntity();
        led.setId(id);
        led.setName(name);
        /**
         * 诺瓦设备编辑 日志记录开始
         */
        List<String> listCode = new ArrayList<>(1);
        listCode.add(byId.getSn());
        String content = "{ 设备id:" + led.getId() + "设备code:" + byId.getSn() + "诺瓦playId:" + led.getPlayerId() + "诺瓦设备原名:" + byId.getName() + "诺瓦设备更改后的名称:" + led.getName() + "}";
 
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "诺瓦设备编辑", content);
        /**
         * 诺瓦设备编辑 日志记录结束
         */
        return ledPlayerEntityService.updateById(led);
    }
 
    /**
     * 获取缓存数据
     *
     * @param
     * @return
     */
    public List<LedPlayerEntity> setCacheInfo(List<LedPlayerEntity> ledList) {
        List<String> temp = new ArrayList<>();
        for (LedPlayerEntity item : ledList) {
            String playerId = item.getPlayerId();
            if (redisUtils.get(VnnoxConstant.REDIS_VOL + playerId) == null
                    || redisUtils.get(VnnoxConstant.REDIS_BRIGHTNESS + playerId) == null
                    || redisUtils.get(VnnoxConstant.REDIS_SCREEN_STATUS + playerId) == null) {
                temp.add(item.getPlayerId());
            }
        }
        if (temp.size() > 0) {
            List<List<String>> split = CollectionUtil.split(temp, 100);
            for (List<String> playIds : split) {
                System.out.println(playIds.size());
                vnnoxAPIUtil.asyncStatus(playIds);
            }
        }
 
        List<List<LedPlayerEntity>> split = CollectionUtil.split(ledList, 100);
        for (List<LedPlayerEntity> list : split) {
            for (LedPlayerEntity playerEntity : list) {
                String playerId = playerEntity.getPlayerId();
                LedPlayerInfoEntity cache = new LedPlayerInfoEntity();
                //  设置屏幕状态  更新状态之后还拿不到数据说明设备有问题或不在线  设置默认为黑屏
                String result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_STATUS + playerId);
                Integer screenStatus = 0;
                if (null != result) {
                    screenStatus = Integer.parseInt(result);
                }
                cache.setScreenStatus(screenStatus);
                //  设置屏幕音量
                result = redisUtils.get(VnnoxConstant.REDIS_VOL + playerId);
                Integer vol = 0;
                if (null != result) {
                    vol = Float.valueOf(result).intValue();
 
                }
                cache.setVol(vol);
                //  设置屏幕亮度
                result = redisUtils.get(VnnoxConstant.REDIS_BRIGHTNESS + playerId);
                Integer brightness = 0;
                if (null != result) {
                    brightness = Float.valueOf(result).intValue();
                }
                cache.setBrightness(brightness);
 
                //  设置缩略图访问路径
                result = redisUtils.get(VnnoxConstant.REDIS_SCREEN_SHOT + playerId);
                if (null != result) {
                    playerEntity.setScreenShotUrl(result);
                } else {
                    playerEntity.setScreenShotUrl("");
                }
 
                playerEntity.setPlayerInfo(cache);
            }
        }
        return ledList;
    }
 
 
    public VnnoxResult WaterData(String playerId, Long duration, A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage poleSensorEntity) {
        List<String> playerIds = new ArrayList<>();
        playerIds.add(playerId);
        NovaWeatherVO playerProgram = new NovaWeatherVO();
        playerProgram.setPlayerIds(playerIds);
 
        NovaWeatherVO.AttributeDTO attributeDTO = new NovaWeatherVO.AttributeDTO();
        attributeDTO.setDuration(duration);
        playerProgram.setAttribute(attributeDTO);
        List<NovaWeatherVO.PageDTO.WidgetsDTO> widgets = setWeather(duration, poleSensorEntity);
        NovaWeatherVO.PageDTO page = new NovaWeatherVO.PageDTO();
        page.setWidgets(widgets);
        playerProgram.setPage(page);
 
        return vnnoxProgramAPIUtil.emergencyProgram(playerProgram).getData();
    }
 
 
    private List<NovaWeatherVO.PageDTO.WidgetsDTO> setWeather(Long duration, A5AtmosphereHeartbeatReportInnerFrame.HeartBeatDataPackage poleSensorEntity) {
 
        List<NovaWeatherVO.PageDTO.WidgetsDTO> widgets = new ArrayList<>();
        List<String> list = new ArrayList<>();
        if (Objects.nonNull(poleSensorEntity)) {
            list.add("环境监测:");
            list.add("温度:" + poleSensorEntity.getTemperature() + "°");
            list.add("湿度:" + poleSensorEntity.getHumidity() + "%");
            list.add("pm25:" + poleSensorEntity.getPm25() + "μg/m³");
            list.add("pm10:" + poleSensorEntity.getPm10() + "μg/m³");
            list.add("甲醛:" + poleSensorEntity.getEch2o() + "μg/m³");
            list.add("CO2:" + poleSensorEntity.getCo2() + "ppm");
        } else {
            list.add("大气设备不在线");
            list.add("目前是固定数据:");
            list.add("环境监测:");
            list.add("温度: 40°");
            list.add("湿度: 60%");
            list.add("pm25:0.58 μg/m³");
            list.add("pm10:0.58 μg/m³");
            list.add("甲醛:99.9 μg/m³");
            list.add("CO2:200 ppm");
        }
 
 
        List<NovaWeatherVO.PageDTO.WidgetsDTO.LinesDTO> lines = new ArrayList<>();
 
        list.forEach(txt -> {
            List<NovaWeatherVO.PageDTO.WidgetsDTO.LinesDTO.TextAttributesDTO> textAttributes = new ArrayList<>();
 
            NovaWeatherVO.PageDTO.WidgetsDTO.LinesDTO linesDTO = new NovaWeatherVO.PageDTO.WidgetsDTO.LinesDTO();
            NovaWeatherVO.PageDTO.WidgetsDTO.LinesDTO.TextAttributesDTO textAttributesDTO = new NovaWeatherVO.PageDTO.WidgetsDTO.LinesDTO.TextAttributesDTO();
            textAttributesDTO.setContent(txt);
            textAttributes.add(textAttributesDTO);
            System.out.println(txt + "文本内容");
            linesDTO.setTextAttributes(textAttributes);
            lines.add(linesDTO);
        });
 
        NovaWeatherVO.PageDTO.WidgetsDTO widgetsDTO = new NovaWeatherVO.PageDTO.WidgetsDTO();
        NovaWeatherVO.PageDTO.WidgetsDTO.ScrollAttributeDTO scrollAttribute = new NovaWeatherVO.PageDTO.WidgetsDTO.ScrollAttributeDTO();
 
        NovaWeatherVO.PageDTO.WidgetsDTO.LayoutDTO layout = new NovaWeatherVO.PageDTO.WidgetsDTO.LayoutDTO();
 
        widgetsDTO.setScrollAttribute(scrollAttribute);
        widgetsDTO.setLayout(layout);
        widgetsDTO.setLines(lines);
 
        widgetsDTO.setDuration(duration);
        widgets.add(widgetsDTO);
        System.out.println(lines + "播放内容");
 
        return widgets;
    }
 
 
    /**
     * 更新诺瓦屏幕分辨率
     */
    public void saveInfo() {
        List<LedPlayerEntity> all = ledPlayerEntityService.list();
        List<List<LedPlayerEntity>> split = CollectionUtil.split(all, 100);
        List<LedPlayerEntity> list = new ArrayList<>();
        for (List<LedPlayerEntity> ledList : split) {
            list.addAll(vnnoxAPIUtil.saveCurrentInfo(ledList));
        }
        boolean b = SpringContextHolder.getBean(LedPlayerEntityService.class).updateBatchById(list);
        if (b) {
            LogUtils.error("更新诺瓦屏幕分辨率成功");
        }
    }
 
 
    public void asyncStatus(List<String> playerIds) {
        VnnoxResultResponse vnnoxResultResponse = vnnoxAPIUtil.asyncStatus(playerIds);
    }
 
    /**
     * 获取诺瓦屏幕信息
     *
     * @param stateValue
     * @param playIdList
     * @return
     */
    public List<NovaAStateInfoVO> getInfo(String stateValue, List<String> playIdList) {
        List<NovaAStateInfoVO> list = new ArrayList<>();
        NovaAStateInfoVO novaAStateInfoVO;
        for (String playId : playIdList) {
            String volumeValue = RedisUtils.getBean().get(VnnoxConstant.REDIS_VOL + playId);
            String brightnessValue = RedisUtils.getBean().get(VnnoxConstant.REDIS_BRIGHTNESS + playId);
            String videoSourceValue = RedisUtils.getBean().get(VnnoxConstant.VIDEO_SOURCE_VALUE + playId);
            String timezoneValue = RedisUtils.getBean().get(VnnoxConstant.TIME_VALUE_TIMEZONE + playId);
            String timeValue = RedisUtils.getBean().get(VnnoxConstant.TIME_VALUE_TIME + playId);
            String screenPowerStatus = RedisUtils.getBean().get(VnnoxConstant.REDIS_SCREEN_STATUS + playId);
            String syncPlayStatus = RedisUtils.getBean().get(VnnoxConstant.SYNC_PLAY_STATUS + playId);
            novaAStateInfoVO = new NovaAStateInfoVO();
            novaAStateInfoVO.setPlayerId(playId);
            switch (stateValue) {
                case "all":
                    novaAStateInfoVO.setVolumeValue(volumeValue);
                    novaAStateInfoVO.setBrightnessValue(brightnessValue);
                    novaAStateInfoVO.setVideoSourceValue(videoSourceValue);
                    novaAStateInfoVO.setTimezoneValue(timezoneValue);
                    novaAStateInfoVO.setTimeValue(timeValue);
                    novaAStateInfoVO.setScreenPowerStatus(screenPowerStatus);
                    novaAStateInfoVO.setSyncPlayStatus(syncPlayStatus);
                    break;
                case "volumeValue":
                    novaAStateInfoVO.setVolumeValue(volumeValue);
                    break;
                case "brightnessValue":
                    novaAStateInfoVO.setBrightnessValue(brightnessValue);
                    break;
                case "videoSourceValue":
                    novaAStateInfoVO.setVideoSourceValue(videoSourceValue);
                    break;
                case "timeValue":
                    novaAStateInfoVO.setTimezoneValue(timezoneValue);
                    novaAStateInfoVO.setTimeValue(timeValue);
                    break;
                case "screenPowerStatus":
                    novaAStateInfoVO.setScreenPowerStatus(screenPowerStatus);
                    break;
                case "syncPlayStatus":
                    novaAStateInfoVO.setSyncPlayStatus(syncPlayStatus);
                    break;
                default:
            }
            list.add(novaAStateInfoVO);
        }
        return list;
    }
 
    public void getAsyncStatus(List<String> playerIdList, String stateValue) {
        List<List<String>> split = CollectionUtil.split(playerIdList, 100);
        split.forEach(
                playerIds -> {
                    vnnoxAPIUtil.getAsyncStatus(playerIdList, stateValue);
                }
        );
    }
 
 
    /**
     * 向Redis中存入设备状态
     */
    public void setCacheData() {
 
        List<List<LedPlayerEntity>> split = CollectionUtil.split(ledPlayerEntityService.list(), 100);
        List<LedPlayerEntity> ledList = new ArrayList<>();
        split.forEach(
                list -> {
                    List<LedPlayerEntity> ledPlayerEntities = vnnoxAPIUtil.syncCurrentInfo(list);
                    ledList.addAll(ledPlayerEntities);
                }
        );
 
        ledList.forEach(
                device -> {
                    RedisDeviceStatus deviceStatus = new RedisDeviceStatus();
                    deviceStatus.setDeviceId(device.getPlayerId());
                    if (device.getOnlineStatus() == 0) {
                        deviceStatus.setStatus(1);
                    } else if (device.getOnlineStatus() == 1) {
                        deviceStatus.setStatus(0);
                    } else {
                        deviceStatus.setStatus(1);
                    }
                    redisUtils.set(DeviceRedisKey.NOVA + device.getPlayerId(), JSON.toJSONString(deviceStatus));
//                    redisUtils.delete(DeviceRedisKey.IP_BROADCAST + device.getId());
                }
        );
 
    }
}