2021与蓝度共同重构项目,服务端
liuhaonan
2022-02-24 34ee53680318cef28c80cf40959b6fd3d55a0c4e
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
package com.sandu.ximon.admin.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.config.NginxConfigBean;
import com.sandu.ximon.admin.config.RealtimeServerBean;
import com.sandu.ximon.admin.entity.*;
import com.sandu.ximon.admin.utils.Constant;
import com.sandu.ximon.admin.utils.FileUtil;
import com.sandu.ximon.admin.utils.HtmlTemplateUtils;
import com.sandu.ximon.admin.utils.LightemitUtils;
import com.sandu.ximon.admin.utils.request.SubTitleSet;
import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.sandu.ximon.dao.mapper.PoleLightemitEntityMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.util.*;
 
 
@Service
@EnableCaching
public class PoleLightemitService extends BaseServiceImpl<PoleLightemitEntityMapper, PoleLightemitEntity> {
 
    //    @Autowired
//    PoleStreetlightLightemitService poleStreetlightLightemitService;
 
    LightemitUtils lightemitUtils;
    @Autowired
    private RealtimeServerBean realtimeServerBean;
    @Value("${server.port}")
    private String port;
    @Autowired
    ApplicationContext applicationContext;
    //    @Autowired
//    FfmpegUtils ffmpegUtils;
//    @Autowired
//    FileUploadPathBean fileUploadPathBean;
    @Autowired
    NginxConfigBean nginxConfigBean;
 
    @Autowired
    PoleLightemitEntityMapper poleLightemitDao;
 
    @PostConstruct
    public void init() {
        //重新获取单例
        lightemitUtils = applicationContext.getBean(LightemitUtils.class);
    }
 
    /*@Override
    public PageUtils queryPage(Map<String, Object> params, Long userId) {
 
        String key = (String)params.get("key");
 
        Long groupId = StringUtils.isNotBlank((String)params.get("group"))? Long.valueOf((String)params.get("group")): null;
 
        String order = (String)params.get("order");
 
        String column = (String)params.get("sortby");
 
        IPage<PoleLightemitEntity> page = new Page<>();
        //获取角色列表
        Long roleId = (sysUserRoleService.queryRoleId(userId));
 
        if(roleId == null || roleId == 0){
            return null;
        }
 
        if(roleId.longValue() == Constant.SUPER_ADMIN){
//            page = this.page(
//                    new Query<PoleLightemitEntity>().getPage(params),
//                    new QueryWrapper<PoleLightemitEntity>().like(StringUtils.isNotBlank(key),"lightemit_name", key));
            if (order != null && order.equals("ASC") && column.equals("isOpen")) {
                Map<String, Object> map = new HashMap<>();
                Integer pg = 1;
                Integer size = 200;
                map.put("page",pg);
                params.put("limit",size);
                page = baseMapper.superAdminSelectPageVo(PageTransform.transformPage(params),key,groupId,order,column);
                ledOnlineCheck(page.getRecords());
                page.setRecords(page.getRecords().stream().filter(h-> h.getIsOpen().equals(true)).collect(Collectors.toList()));
                return new PageUtils(page);
            }else if (order != null && order.equals("DESC") && column.equals("isOpen")){
                Map<String, Object> map = new HashMap<>();
                Integer pg = 1;
                Integer size = 200;
                map.put("page",pg);
                params.put("limit",size);
                page = baseMapper.superAdminSelectPageVo(PageTransform.transformPage(params),key,groupId,order,column);
                ledOnlineCheck(page.getRecords());
                page.setRecords(page.getRecords().stream().filter(h-> h.getIsOpen().equals(false)).collect(Collectors.toList()));
                return new PageUtils(page);
            }else {
                page = baseMapper.superAdminSelectPageVo(PageTransform.transformPage(params), key, groupId,order,column);
            }
 
        }else if(roleId.longValue() == Constant.ADMIN){
            if (order != null && order.equals("ASC") && column.equals("isOpen")) {
                Map<String, Object> map = new HashMap<>();
                Integer pg = 1;
                Integer size = 200;
                map.put("page",pg);
                params.put("limit",size);
                page = baseMapper.adminSelectPageVo(PageTransform.transformPage(params), userId, key, groupId,order,column);
                ledOnlineCheck(page.getRecords());
                page.setRecords(page.getRecords().stream().filter(h-> h.getIsOpen().equals(true)).collect(Collectors.toList()));
                return new PageUtils(page);
            }else if (order != null && order.equals("DESC") && column.equals("isOpen")){
                Map<String, Object> map = new HashMap<>();
                Integer pg = 1;
                Integer size = 200;
                map.put("page",pg);
                params.put("limit",size);
                page = baseMapper.adminSelectPageVo(PageTransform.transformPage(params), userId, key, groupId,order,column);
                ledOnlineCheck(page.getRecords());
                page.setRecords(page.getRecords().stream().filter(h-> h.getIsOpen().equals(false)).collect(Collectors.toList()));
                return new PageUtils(page);
            }else {
                page = baseMapper.adminSelectPageVo(PageTransform.transformPage(params), userId, key, groupId,order,column);
            }
 
        }else if(roleId.longValue() == Constant.USER){
            if (order != null && order.equals("ASC") && column.equals("isOpen")) {
                Map<String, Object> map = new HashMap<>();
                Integer pg = 1;
                Integer size = 200;
                map.put("page",pg);
                params.put("limit",size);
                page = baseMapper.userSelectPageVo(PageTransform.transformPage(params), userId, key, groupId,order,column);
                ledOnlineCheck(page.getRecords());
                page.setRecords(page.getRecords().stream().filter(h-> h.getIsOpen().equals(true)).collect(Collectors.toList()));
                return new PageUtils(page);
            }else if (order != null && order.equals("DESC") && column.equals("isOpen")){
                Map<String, Object> map = new HashMap<>();
                Integer pg = 1;
                Integer size = 200;
                map.put("page",pg);
                params.put("limit",size);
                page = baseMapper.userSelectPageVo(PageTransform.transformPage(params), userId, key, groupId,order,column);
                ledOnlineCheck(page.getRecords());
                page.setRecords(page.getRecords().stream().filter(h-> h.getIsOpen().equals(false)).collect(Collectors.toList()));
                return new PageUtils(page);
            }else {
                page = baseMapper.userSelectPageVo(PageTransform.transformPage(params), userId, key, groupId,order,column);
            }
 
        }
        ledOnlineCheck(page.getRecords());
        return new PageUtils(page);
    }
*//*
    @Override
    public List<PoleLightemitEntity> getAll(Long userId) {
        //获取角色列表
        Long roleId = (sysUserRoleService.queryRoleId(userId));
 
        if(roleId == null || roleId == 0){
            return null;
        }
        List<PoleLightemitEntity> list = null;
        if(roleId.longValue() == Constant.SUPER_ADMIN){
            list = poleLightemitDao.selectAll();
        }else if(roleId.longValue() == Constant.ADMIN){
            list = poleLightemitDao.selectAllByCompany(userId);
        }else if(roleId.longValue() == Constant.USER){
            list = poleLightemitDao.selectAllByUser(userId);
        }
        return list;
    }
*/
 
/*    public void ledOnlineCheck(List<PoleLightemitEntity> list) {
 
        for(PoleLightemitEntity poleLightemitEntity : list){
            poleLightemitEntity.setIsOpen(lightemitUtils.getIsScreenOpen(poleLightemitEntity.getLightemitControlCode()).contains("true"));
        }
    }*/
 
 
    public void savePoleLightemit(PoleLightemitEntity poleLightemit) {
        boolean save = this.save(poleLightemit);
        // 绑定灯杆
        if(save&&poleLightemit.getPoleId()!=null){
 
        }
      //  poleStreetlightLightemitService.saveStreetlightLightemit(poleLightemit.getLightemitId(),poleLightemit.getStreetlightId());
    }
 
 
  /*  public void updatePoleLightemit(PoleLightemitEntity poleLightemit) {
        this.updateById(poleLightemit);
        poleStreetlightLightemitService.saveStreetlightLightemit(poleLightemit.getLightemitId(),poleLightemit.getStreetlightId());
    }*/
 
    /**
     * 查询权限范围内的所有led屏信息
     *
     * @param
     * @return
     */
   /* public List<PoleLightemitEntity> selectLightemitByUserId(Long userId) {
        List<PoleLightemitEntity> list = new ArrayList<>();
 
        Long roleId = sysUserRoleService.queryRoleId(userId);
 
        if(roleId == null || roleId == 0){
            return new ArrayList<>();
        }
        if(roleId.longValue() == Constant.SUPER_ADMIN){
            list = this.list();
        }else if(roleId.longValue() == Constant.ADMIN){
            list = baseMapper.selectCompanyLightemitByUserId(userId);
        }else if(roleId.longValue() == Constant.USER){
            list = baseMapper.selectLightemitByUserId(userId);
        }
        return list;
    }
*/
    /*
    通过屏幕编码查询
     */
    public PoleLightemitEntity selectByLightemitControlCode(String lightemitControlCode) {
        QueryWrapper<PoleLightemitEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("lightemit_control_code", lightemitControlCode);
        return this.getOne(queryWrapper);
    }
 
    /*
    led上传图片
     */
    @Async("taskExecutor")
    public void photoUpload(String lightemitControlCode, String path, List<String> filenameList, String userName) throws IOException {
        //获取屏幕宽
        String screenWidth = lightemitUtils.getScreenWidth(lightemitControlCode);
        String screenHeight = lightemitUtils.getScreenHeight(lightemitControlCode);
 
        //html地址
        String filenameTemp = path + userName + "_" + lightemitControlCode + ".html";
        File htmlFile = new File(filenameTemp);
        if (!htmlFile.exists() || htmlFile.delete()) {
            htmlFile.createNewFile();
        }
 
        //获取body的html
        Map<String, Object> params = new HashMap<>();
        params.put("imgList", filenameList);
        params.put("screenWidth", screenWidth);
        params.put("screenHeight", screenHeight);
 
        String body = new HtmlTemplateUtils().renderPath("classpath:templates/lightemitTemplates/photoTemplates.html", params);
 
        boolean flag = new FileUtil().writeToFile(body, filenameTemp);
 
        if (flag) {
            //清屏操作
            lightemitUtils.clear(lightemitControlCode);
            //清除播放列表
            lightemitUtils.clearVideoPlay(lightemitControlCode);
            //清除节目列表
            lightemitUtils.clearPlayerTask(lightemitControlCode);
            //推送图片
            lightemitUtils.postHtml(lightemitControlCode, userName);
        }
    }
 
    /*
    led上传视频
     */
 
    @Async("taskExecutor")
    public void videoUpload(String lightemitControlCode, String filename, String path, String userName) throws IOException {
        //获取屏幕宽
        String screenWidth = lightemitUtils.getScreenWidth(lightemitControlCode);
        String screenHeight = lightemitUtils.getScreenHeight(lightemitControlCode);
 
        //发送视频至开发板并播放
        lightemitUtils.postVideo(screenWidth, screenHeight, filename, lightemitControlCode);
 
        //清屏
        lightemitUtils.clear(lightemitControlCode);
 
    }
 
    /**
     * LED上传单行字幕
     */
    @Async("taskExecutor")
    public Boolean subTitleSet(SubTitleSetEntity subTitleSetEntity, String path, String userName) {
        if (subTitleSetEntity == null) {
            return false;
        }
        if (subTitleSetEntity.getDirection().equals(Constant.LEFT) || subTitleSetEntity.getDirection().equals(Constant.RIGHT)) {
            //字幕横向滚动
            this.BuildHorizonSingSubTitleText(subTitleSetEntity);
        } else if (subTitleSetEntity.getDirection().equals(Constant.UP) || subTitleSetEntity.getDirection().equals(Constant.DOWN)) {
            //字幕纵向滚动
            try {
                this.BuildVerticalSingSubTitleText(subTitleSetEntity, path, userName);
            } catch (IOException e) {
                return false;
            }
        }
        return true;
    }
 
    /**
     * LED上传多行字幕
     */
    @Async("taskExecutor")
    public Boolean subMultiTitleSet(SubTitleSetEntity subTitleSetEntity, String path, String userName) {
        try {
            this.BuildVerticalMultiSubTitleText(subTitleSetEntity, path, userName);
            return true;
        } catch (IOException e) {
            return false;
        }
    }
 
    /*
    删除
     */
 
   /* public void deleteByIds(List<Long> lightemitIds) {
        this.removeByIds(lightemitIds);
        //删除关系表中的数据
        poleStreetlightLightemitService.remove(
                new UpdateWrapper<PoleStreetlightLightemitEntity>().in("lightemit_id", lightemitIds.toArray()));
    }*/
 
    /*
    熙讯视频设置
     */
 
    @Async("taskExecutor")
    public void videoXixunPlayer(String lightemitControlCode, String ip, String filename, Long filesize, Integer videoTime) {
        //获取屏幕宽
        Integer screenWidth = Integer.valueOf(lightemitUtils.getScreenWidth(lightemitControlCode));
        Integer screenHeight = Integer.valueOf(lightemitUtils.getScreenHeight(lightemitControlCode));
        Source source = new Source();
        Layer layer = new Layer();
        Program pro = new Program();
        TaskItem items = new TaskItem();
        ProgramsTask task = new ProgramsTask();
        Command command = new Command();
        XixunPlayer xixun = new XixunPlayer();
        source.set_id(UUID.randomUUID().toString());//所有_id都可用UUID随机生成
        source.setId(filename);//请求头拼接该ID为该资源的完整下载地址
        source.set_type("Video");    //设置资源类型,其他资源类型请参考xixunplayer节目json说明文档
        source.setFileExt(".mp4");    //资源后缀名
        source.setHeight(screenHeight);        //资源高度
        source.setWidth(screenWidth);        //资源宽度
        source.setLeft(0);            //距左
        source.setMd5("dd135d5d2d44d619a542db773ab529a4");
        source.setMime("video/mp4");
        source.setName(filename);
        source.setPlayTime(0);    //播放起始时间
        source.setSize(filesize);    //资源字节数,要精准
        source.setTimeSpan(videoTime);        //该资源播放时长
        source.setTop(0);            //距顶
        List<Source> list = new ArrayList<Source>();
        list.add(source);
        layer.setSources(list);
        pro.set_id(UUID.randomUUID().toString());
        pro.setHeight(screenHeight);        //节目高度
        List<Layer> list1 = new ArrayList<Layer>();
        list1.add(layer);
        pro.setLayers(list1);
        pro.setName("demo");    //节目名称
        pro.setOthers(true);//如果为true,则该节目来自第三方接口,不是来自我们自己的web,二次开发请务必赋值为true
        pro.setTotalSize(filesize);    //所有资源总字节数
        pro.setVersion(0);            //高级节目=0,简易节目=2
        pro.setWidth(screenWidth);        //节目宽度
        items.set_id(UUID.randomUUID().toString());
        items.set_program(pro);
        items.setRepeatTimes(1);
        items.setSchedules(null);//定时段,不做定时可为null
        task.set_id(UUID.randomUUID().toString());
        task.setName("这是一个示例");
        List<TaskItem> list2 = new ArrayList<TaskItem>();
        list2.add(items);
        task.setItems(list2);
        command.setId(UUID.randomUUID().toString());
        //这里是下方的post回调地址,需要修改IP地址
        command.setNotificationURL("http://" + ip + ":" + port + "/machine-fast/serv/download/getJSON");
        //资源下载链接的请求头
        command.setPreDownloadURL("http://" + ip + ":" + port + "/machine-fast/serv/download/downloadFile/");
        command.setTask(task);
        xixun.set_id(UUID.randomUUID().toString());
        xixun.setCommand(command);
        xixun.setType("commandXixunPlayer");    //命令固定类型,不可更改
        String jsondata = new Gson().toJson(xixun);
        lightemitUtils.clear(lightemitControlCode);
        poleLightemitDao.updateRequestBody(lightemitControlCode, jsondata);
        lightemitUtils.post(realtimeServerBean.getCommand() + lightemitControlCode, jsondata);
    }
 
    /*
    推送天气数据
     */
 
    //@Async("taskExecutor")
   /* public Boolean pushWeather(String lightemitControlCode, PoleSensorEntity sensorEntity, PoleStreetlightEntity streetlightEntity) {
        if(StringUtils.isBlank(lightemitControlCode)){
            return Boolean.valueOf(false);
        }
        Integer screenHeight = Integer.parseInt(lightemitUtils.getScreenHeight(lightemitControlCode));
        String size = String.valueOf(screenHeight/18);
        //字幕主体拼接
        String body =
                "<head><style type=\"text/css\">body{background-color:#000;}</style></head>" +
                        "<p style=\"font-size:" + size + "px;line-height:17px;color:#fff\">" +
                        (streetlightEntity == null || streetlightEntity.getCity() == null? "": streetlightEntity.getCity().replace("市", "")) + "<br/>" +
                        "温度:" + (sensorEntity == null || sensorEntity.getTemperature() == null? "-": sensorEntity.getTemperature()) + "℃<br/>" +
                        "湿度:" + (sensorEntity == null || sensorEntity.getHumidity() == null? "-": sensorEntity.getHumidity()) + "%RH<br/>" +
                        "亮度:" + (sensorEntity == null || sensorEntity.getBrightness() == null? "-": sensorEntity.getBrightness()) + "lux<br/>" +
                        "风速:" + (sensorEntity == null || sensorEntity.getWindSpeed() == null? "-": sensorEntity.getWindSpeed()) + "m/s<br/>" +
                        "CO2:" + (sensorEntity == null || sensorEntity.getEco2() == null? "-": sensorEntity.getEco2()) + "ppm<br/>" +
                        "甲醛:" + (sensorEntity == null || sensorEntity.getEch2o() == null? "-": sensorEntity.getEch2o()) + "mg/m³<br/>" +
                        "TVOC:" + (sensorEntity == null || sensorEntity.getTvoc() == null? "-": sensorEntity.getTvoc()) + "mg/m³<br/>" +
                        "PM25:" + (sensorEntity == null || sensorEntity.getPm25() == null? "-": sensorEntity.getPm25()) + "mg/m³<br/>" +
                        "PM10:" + (sensorEntity == null || sensorEntity.getPm10() == null? "-": sensorEntity.getPm10()) + "mg/m³<br/>";
 
        //组装请求参数
        SubTitleSet subTitleSet = new SubTitleSet();
        subTitleSet.html = body;
        subTitleSet.num = 1;
 
        //清屏操作
        lightemitUtils.clear(lightemitControlCode);
        //清除播放列表
        lightemitUtils.clearVideoPlay(lightemitControlCode);
        //清除节目列表
        lightemitUtils.clearPlayerTask(lightemitControlCode);
        try{
            lightemitUtils.subTitleSet(subTitleSet, lightemitControlCode, false);
            return true;
        }catch (Exception e){
            return false;
        }finally {
            //一分钟后清除屏幕
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    lightemitUtils.clear(lightemitControlCode);
                    //清除播放列表
                    lightemitUtils.clearVideoPlay(lightemitControlCode);
                    //清除节目列表
                    lightemitUtils.clearPlayerTask(lightemitControlCode);
                    //推送最后命令
                    lightemitUtils.sendLastCommand(lightemitControlCode);
                }
            }, 60*1000);
        }
    }*/
 
    /*
    更新请求数据
     */
 
    public void updateRequestBody(String ledCode, String postBody) {
        baseMapper.updateRequestBody(ledCode, postBody);
    }
 
    /*
    根据led屏编码获取灯杆所有信息
     */
 
//    public PoleStreetlightEntity getStreetlightByLedCode(String ledCode) {
//        return baseMapper.getStreetlightByLedCode(ledCode);
//    }
 
    /*
    根据led屏编码设置音量
     */
 
    @Async("taskExecutor")
    public void setVolume(String lightemitControlCode, Integer volume) {
        lightemitUtils.setVoiume(lightemitControlCode, volume);
    }
 
 
//    public List<PoleLightemitEntity> listOfStreetlight(String streetlightId) {
//        return baseMapper.listOfStreetlight(streetlightId);
//    }
 
 
//    public List<PoleLightemitEntity> selectLedByStreetlightId(String streetlightId) {
//        return baseMapper.getLedByStreetlightId(streetlightId);
//    }
 
    /*
        上传水平滚动单行字幕
         */
    private void BuildHorizonSingSubTitleText(SubTitleSetEntity subTitleSetEntity) {
        //拼装LED屏幕设置请求body
        SubTitleSet subTitleSet = new SubTitleSet();
        subTitleSet.num = subTitleSetEntity.getNum() != null ? subTitleSetEntity.getNum() : subTitleSet.num;
        subTitleSet.interval = subTitleSetEntity.getInterval() != null ? subTitleSetEntity.getInterval() : subTitleSet.interval;
        subTitleSet.step = subTitleSetEntity.getStep() != null ? subTitleSetEntity.getStep() : subTitleSet.step;
        subTitleSet.direction = subTitleSetEntity.getDirection() != null ? subTitleSetEntity.getDirection() : subTitleSet.direction;
        subTitleSet.align = subTitleSetEntity.getAlign() != null ? subTitleSetEntity.getAlign() : subTitleSet.align;
        //拼接html 背景默认显色为白色
        subTitleSet.html = "<head><style type=\"text/css\">body{background-color:" +
                (subTitleSetEntity.getColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getColor()) ? subTitleSetEntity.getColor() : "#000000") +
                "}</style></head><i style=\"color:" +
                (subTitleSetEntity.getFontColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontColor()) ? subTitleSetEntity.getFontColor() : "#ffffff")
                + "; font-size: " +
                (subTitleSetEntity.getFontSize() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontSize()) ? subTitleSetEntity.getFontSize() : "1")
                + "em\">" + subTitleSetEntity.getContent() + "</i>";
 
        //获取所有led数据
        Collection poleLightemitControllers = this.listByIds(Arrays.asList(subTitleSetEntity.getId()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                //清屏操作
                lightemitUtils.clear(poleLightemitEntity.getLightemitControlCode());
                //清除播放列表
                lightemitUtils.clearVideoPlay(poleLightemitEntity.getLightemitControlCode());
                //清除节目列表
                lightemitUtils.clearPlayerTask(poleLightemitEntity.getLightemitControlCode());
                //发送字幕设置请求
                lightemitUtils.subTitleSet(subTitleSet, poleLightemitEntity.getLightemitControlCode(), true);
            }
        }
    }
 
    /*
    上传垂直滚动单行字幕
     */
    private void BuildVerticalSingSubTitleText(SubTitleSetEntity subTitleSetEntity, String path, String userName) throws IOException {
        //html地址
        //获取所有led数据
        Collection poleLightemitControllers = this.listByIds(Arrays.asList(subTitleSetEntity.getId()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
 
                String lightemitControlCode = poleLightemitEntity.getLightemitControlCode();
 
                //获取屏幕宽
                Integer screenWidth = Integer.valueOf(lightemitUtils.getScreenWidth(lightemitControlCode));
                Integer screenHeight = Integer.valueOf(lightemitUtils.getScreenHeight(lightemitControlCode));
 
                String filenameTemp = path + userName + "_" + lightemitControlCode + ".html";
                File htmlFile = new File(filenameTemp);
                if (!htmlFile.exists() || htmlFile.delete()) {
                    htmlFile.createNewFile();
                }
 
                //若向下滚动,文字顺序相反
                if (Constant.DOWN.equals(subTitleSetEntity.getDirection())) {
                    subTitleSetEntity.setContent(StringUtils.reverse(subTitleSetEntity.getContent()));
                }
 
                Map<String, Object> params = new HashMap<>();
                params.put("direction", subTitleSetEntity.getDirection());
                params.put("screenWidth", screenWidth);
                params.put("screenHeight", screenHeight);
                params.put("fontSize", subTitleSetEntity.getFontSize() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontSize()) ? subTitleSetEntity.getFontSize() : "1");
                params.put("align", subTitleSetEntity.getAlign());
                params.put("fontColor", subTitleSetEntity.getFontColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontColor()) ? subTitleSetEntity.getFontColor() : "#ffffff");
                params.put("backgroundColor", subTitleSetEntity.getColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getColor()) ? subTitleSetEntity.getColor() : "#000000");
                params.put("interval", subTitleSetEntity.getInterval() != null ? subTitleSetEntity.getInterval() : 50);
                params.put("step", subTitleSetEntity.getStep() != null ? subTitleSetEntity.getStep() : 1);
                params.put("num", subTitleSetEntity.getNum() != null ? subTitleSetEntity.getNum() : -1);
                params.put("contentArray", subTitleSetEntity.getContent().toCharArray());
 
                String body = new HtmlTemplateUtils().renderPath("classpath:templates/lightemitTemplates/buildVerticalSingSubTitleTemplates.html", params);
 
                boolean flag = new FileUtil().writeToFile(body, filenameTemp);
 
                if (flag) {
                    //清屏操作
                    lightemitUtils.clear(lightemitControlCode);
                    //清除播放列表
                    lightemitUtils.clearVideoPlay(lightemitControlCode);
                    //清除节目列表
                    lightemitUtils.clearPlayerTask(lightemitControlCode);
                    //推送
                    lightemitUtils.postHtmlUseNginx(lightemitControlCode, userName);
                }
            }
        }
    }
 
 
    /*
    上传垂直滚动多行字幕
     */
    private void BuildVerticalMultiSubTitleText(SubTitleSetEntity subTitleSetEntity, String path, String userName) throws IOException {
        //html地址
        //获取所有led数据
        Collection poleLightemitControllers = this.listByIds(Arrays.asList(subTitleSetEntity.getId()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
 
                String lightemitControlCode = poleLightemitEntity.getLightemitControlCode();
 
                //获取屏幕宽
                Integer screenWidth = Integer.valueOf(lightemitUtils.getScreenWidth(lightemitControlCode));
                Integer screenHeight = Integer.valueOf(lightemitUtils.getScreenHeight(lightemitControlCode));
 
                String filenameTemp = path + userName + "_" + lightemitControlCode + ".html";
                File htmlFile = new File(filenameTemp);
                if (!htmlFile.exists() || htmlFile.delete()) {
                    htmlFile.createNewFile();
                }
 
                Map<String, Object> params = new HashMap<>();
                params.put("direction", subTitleSetEntity.getDirection());
                params.put("screenWidth", screenWidth);
                params.put("screenHeight", screenHeight);
                params.put("fontSize", subTitleSetEntity.getFontSize() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontSize()) ? subTitleSetEntity.getFontSize() : "1");
                params.put("align", subTitleSetEntity.getAlign());
                params.put("fontColor", subTitleSetEntity.getFontColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getFontColor()) ? subTitleSetEntity.getFontColor() : "#ffffff");
                params.put("backgroundColor", subTitleSetEntity.getColor() != null && StringUtils.isNotBlank(subTitleSetEntity.getColor()) ? subTitleSetEntity.getColor() : "#000000");
                params.put("interval", subTitleSetEntity.getInterval() != null ? subTitleSetEntity.getInterval() : 50);
                params.put("step", subTitleSetEntity.getStep() != null ? subTitleSetEntity.getStep() : 1);
                params.put("num", subTitleSetEntity.getNum() != null ? subTitleSetEntity.getNum() : -1);
                params.put("contentArray", subTitleSetEntity.getContent().split("\n"));
 
                String body = new HtmlTemplateUtils().renderPath("classpath:templates/lightemitTemplates/buildVerticalSingSubTitleTemplates.html", params);
 
                boolean flag = new FileUtil().writeToFile(body, filenameTemp);
 
                if (flag) {
                    //清屏操作
                    lightemitUtils.clear(lightemitControlCode);
                    //清除播放列表
                    lightemitUtils.clearVideoPlay(lightemitControlCode);
                    //清除节目列表
                    lightemitUtils.clearPlayerTask(lightemitControlCode);
                    //推送
                    lightemitUtils.postHtmlUseNginx(lightemitControlCode, userName);
                }
            }
        }
    }
 
    //   @Override
    public void xixunplaySetting(String lightemitControlCode) {
        //获取屏幕宽
//        Integer screenWidth = Integer.valueOf(lightemitUtils.getScreenWidth(lightemitControlCode));
//        Integer screenHeight = Integer.valueOf(lightemitUtils.getScreenHeight(lightemitControlCode));
//        Source source = new Source();
//        Layer layer = new Layer();
//        Program pro = new Program();
//        TaskItem items = new TaskItem();
//        ProgramsTask task = new ProgramsTask();
//        Command payload = new Command();
//        XixunPlayer xixun = new XixunPlayer();
//        source.set_id(UUID.randomUUID().toString());//所有_id都可用UUID随机生成
//        source.setId(filename);//请求头拼接该ID为该资源的完整下载地址
//        source.set_type("Video");    //设置资源类型,其他资源类型请参考xixunplayer节目json说明文档
//        source.setFileExt(".mp4");    //资源后缀名
//        source.setHeight(screenHeight);        //资源高度
//        source.setWidth(screenWidth);        //资源宽度
//        source.setLeft(0);            //距左
//        source.setMd5("dd135d5d2d44d619a542db773ab529a4");
//        source.setMime("video/mp4");
//        source.setName(filename);
//        source.setPlayTime(0);    //播放起始时间
//        source.setSize(filesize);    //资源字节数,要精准
//        source.setTimeSpan(videoTime);        //该资源播放时长
//        source.setTop(0);            //距顶
//        List<Source> list = new ArrayList<Source>();
//        list.add(source);
//        layer.setSources(list);
//        pro.set_id(UUID.randomUUID().toString());
//        pro.setHeight(screenHeight);        //节目高度
//        List<Layer> list1=new ArrayList<Layer>();
//        list1.add(layer);
//        pro.setLayers(list1);
//        pro.setName("demo");    //节目名称
//        pro.setOthers(true);//如果为true,则该节目来自第三方接口,不是来自我们自己的web,二次开发请务必赋值为true
//        pro.setTotalSize(filesize);    //所有资源总字节数
//        pro.setVersion(0);            //高级节目=0,简易节目=2
//        pro.setWidth(screenWidth);        //节目宽度
//        items.set_id(UUID.randomUUID().toString());
//        items.set_program(pro);
//        items.setRepeatTimes(1);
//        items.setSchedules(null);//定时段,不做定时可为null
//        task.set_id(UUID.randomUUID().toString());
//        task.setName("这是一个示例");
//        List<TaskItem> list2=new ArrayList<TaskItem>();
//        list2.add(items);
//        task.setItems(list2);
//        payload.setId(UUID.randomUUID().toString());
//        //这里是下方的post回调地址,需要修改IP地址
//        payload.setNotificationURL("http://" + ip + ":" + port + "/machine-fast/serv/download/getJSON");
//        //资源下载链接的请求头
//        payload.setPreDownloadURL("http://" + ip + ":" + port + "/machine-fast/serv/download/downloadFile/");
//        payload.setTask(task);
//        xixun.set_id(UUID.randomUUID().toString());
//        xixun.setCommand(payload);
//        xixun.setType("commandXixunPlayer");    //命令固定类型,不可更改
//        String jsondata = new Gson().toJson(xixun);
//        lightemitUtils.clear(lightemitControlCode);
//        this.updateRequestBody(lightemitControlCode,jsondata);
//        lightemitUtils.post(realtimeServerBean.getCommand() + lightemitControlCode,jsondata);
    }
}