2021与蓝度共同重构项目,服务端
liuhaonan
2022-07-04 5c87a6a19e76ce8ae9b276532e1c4c53f5cf800b
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
package com.sandu.ximon.admin.controller;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.sandu.common.domain.CommonPage;
import com.sandu.common.domain.ResponseVO;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.util.ResponseUtil;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.entity.ProgramPro;
import com.sandu.ximon.admin.param.LEDScheduleParam_xixun;
import com.sandu.ximon.admin.param.SetBrightnessParam;
import com.sandu.ximon.admin.param.SetScreenOpenParam;
import com.sandu.ximon.admin.param.SetVolumeParam;
import com.sandu.ximon.admin.security.PermissionConfig;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.service.*;
import com.sandu.ximon.admin.utils.LightemitUtils;
import com.sandu.ximon.admin.utils.ListPagingUtils;
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.admin.vo.LedScheduleVO;
import com.sandu.ximon.dao.domain.PoleLightemitEntity;
import com.sandu.ximon.dao.domain.PoleXixunPlayerEntity;
import com.sandu.ximon.dao.enums.MenuEnum;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
/**
 * @Author liuhaonan
 * @Date 2022/2/22 13:55
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/xixun")
public class XiXunController {
 
    private final XiXunPlayerService xiXunPlayerService;
    private final ClientService clientService;
    private final PoleLightemitService poleLightemitService;
    private final LightemitUtils lightemitUtils;
    private final LedScheduleService scheduleService;
 
    private PermissionConfig permissionConfig;
    // private final ListPageUtil listPageUtil;
 
    /**
     * 新增节目
     *
     * @param programPro
     * @return
     */
    @PostMapping("/addProgram")
    public ResponseVO<Object> addProgram(@RequestBody ProgramPro programPro) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PROGRAM_ADD.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(xiXunPlayerService.insert(programPro));
    }
 
    /**
     * 修改
     */
    @PostMapping("/updateProgram")
    public ResponseVO<Object> update(@RequestBody ProgramPro programPro) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PROGRAM_UPDATE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        PoleXixunPlayerEntity byId = xiXunPlayerService.getById(programPro.getProgramId());
        if (byId == null) {
            throw new BusinessException("未选择LED屏");
        }
 
        boolean update = xiXunPlayerService.update(programPro);
        if (update) {
            return ResponseUtil.success("编辑成功!");
 
        } else {
            return ResponseUtil.fail("编辑失败!");
 
        }
 
    }
 
    /**
     * 删除节目
     *
     * @param pid
     * @return
     */
    @PostMapping("/deleteProgram/{pid}")
    public ResponseVO<Object> deleteProgram(@PathVariable Long pid) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PROGRAM_DELETE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(xiXunPlayerService.deleteProgram(pid));
    }
 
    /**
     * 获取节目详情
     *
     * @param pid
     * @return
     */
    @GetMapping("/getByPid/{pid}")
    public ResponseVO<Object> getByPid(@PathVariable Long pid) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PROGRAM_DETAIL.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(xiXunPlayerService.getByPid(pid));
    }
 
    /**
     * 节目列表
     *
     * @param baseConditionVO
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    public ResponseVO<Object> list(BaseConditionVO baseConditionVO,
                                   @RequestParam(value = "order", required = false) Integer order,
                                   @RequestParam(value = "seq", required = false) Integer seq,
                                   @RequestParam(value = "keyword", required = false) String keyword) {
        if (!permissionConfig.check(MenuEnum.LED_PROGRAM_LIST.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        List<PoleXixunPlayerEntity> list = xiXunPlayerService.listProgram(baseConditionVO, order, seq, keyword);
        return ResponseUtil.success(list);
    }
 
 
    /**
     * 节目推送
     *
     * @param pid
     * @param lightemitIds
     * @return
     */
    @PostMapping("/pushToXixun/{pid}")
    public ResponseVO<Object> pushByPid(@PathVariable Long pid, @RequestBody List<Long> lightemitIds) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PROGRAM_PUSH.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
 
        return ResponseUtil.success(xiXunPlayerService.videoXixunPlayer(pid, lightemitIds));
    }
 
    //执行中的节目
    @GetMapping("/getProgram/{lightemitId}")
    public ResponseVO<Object> getProgram(@PathVariable Long lightemitId) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PROGRAM_PLAYING.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(xiXunPlayerService.getByPid(lightemitId));
    }
 
 
    /**
     * LED屏幕新增
     *
     * @param poleLightemit
     * @return
     */
    @PostMapping("/saveLed")
    public ResponseVO<Object> save(@RequestBody PoleLightemitEntity poleLightemit) {
        if (!permissionConfig.check(MenuEnum.XIXUN_LED_ADD.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        int count = poleLightemitService.count(new QueryWrapper<PoleLightemitEntity>().eq("lightemit_control_code", poleLightemit.getLightemitControlCode()));
        if (count != 0) {
            throw new BusinessException("LED控制卡编号不能重复");
        }
 
        if (SecurityUtils.getClientId() == null) {
            poleLightemit.setClientId(clientService.getClientId());
            poleLightemit.setUserId(SecurityUtils.getUserId());
            poleLightemit.setCreateUserId(SecurityUtils.getUserId());
        }
 
        poleLightemitService.savePoleLightemit(poleLightemit);
 
 
        return ResponseUtil.success("新增成功");
    }
 
    /**
     * LED屏幕修改
     *
     * @param ledId
     * @param poleLightemit
     * @return
     */
    @PostMapping("/updateLed/{ledId}")
    public ResponseVO<Object> updatePoleLightemit(@PathVariable Long ledId, @RequestBody PoleLightemitEntity poleLightemit) {
        if (!permissionConfig.check(MenuEnum.XIXUN_LED_UPDATE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        poleLightemitService.updatePoleLightemit(ledId, poleLightemit);
        return ResponseUtil.success("修改成功");
    }
 
    /**
     * LED屏幕删除
     *
     * @param ledIds
     * @return
     */
    @PostMapping("/deleteLed")
    public ResponseVO<Object> deleteLed(@RequestBody List<Long> ledIds) {
        if (!permissionConfig.check(MenuEnum.XIXUN_LED_DELETE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        boolean b = poleLightemitService.deletePoleLightemit(ledIds);
        if (b) {
            return ResponseUtil.success("删除成功");
        } else {
            return ResponseUtil.success("删除失败");
        }
    }
 
    /**
     * LED屏幕列表
     *
     * @param baseConditionVO
     * @param keyword
     * @return
     */
    @GetMapping("/listLed")
    public ResponseVO<Object> listLed(BaseConditionVO baseConditionVO,
                                      @RequestParam(value = "order", required = false) Integer order,
                                      @RequestParam(value = "seq", required = false) Integer seq,
                                      @RequestParam(value = "keyword", required = false) String keyword,
                                      @RequestParam(value = "isOnLine", required = false) boolean isOnLine) {
        if (!permissionConfig.check(MenuEnum.LED_LIST.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        List<PoleLightemitEntity> poleLightemitEntityList = poleLightemitService.listLed(keyword, order, seq, isOnLine);
 
 
        CommonPage commonPage = ListPagingUtils.pages(poleLightemitEntityList, baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
 
        return ResponseUtil.success(commonPage);
    }
 
    /**
     * @param
     * @return
     */
    @GetMapping("/getbycode")
    public ResponseVO<Object> getLedByLightControlCode(String lightemitControlCode) {
        return ResponseUtil.success(poleLightemitService.getLedByLightControlCode(lightemitControlCode));
    }
 
    /**
     * 设置屏幕开关
     */
    @PostMapping("/setScreenOpen")
    public ResponseVO<Object> setScreenOpen(@RequestBody SetScreenOpenParam setScreenOpenEntity) {
        if (!permissionConfig.check(MenuEnum.XIXUN_ON_OFF.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (setScreenOpenEntity.getIds() == null || setScreenOpenEntity.getIds().length == 0 || setScreenOpenEntity.getBool() == null) {
            throw new BusinessException("未选择LED屏");
        }
        Collection poleLightemitControllers = poleLightemitService.listByIds(Arrays.asList(setScreenOpenEntity.getIds()));
        if (!poleLightemitControllers.isEmpty()) {
 
            Map<Long, Object> map = new HashMap<>();
 
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                //结果查询
                String result = lightemitUtils.setScreenOpen(poleLightemitEntity.getLightemitControlCode(), setScreenOpenEntity.getBool());
 
                System.out.println("result:---------------------" + result);
                if (result.isEmpty() || !"true".equals(result)) {
 
                }
 
                map.put(poleLightemitEntity.getLightemitId(), result);
            }
            return ResponseUtil.success(map);
        } else {
            throw new BusinessException("未正确选择LED屏");
        }
    }
 
 
    /*
  获取led实时画面
   */
    @GetMapping("/getPicture/{id}")
    public ResponseVO<Object> getPicture(@PathVariable Long id) {
        if (!permissionConfig.check(MenuEnum.XIXUN_SCREENSHOT.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (id == null) {
            throw new BusinessException("未选择LED屏");
        }
        PoleLightemitEntity poleLightemitEntity = poleLightemitService.getById(id);
        if (poleLightemitEntity != null) {
            String result = lightemitUtils.getPicture(poleLightemitEntity.getLightemitControlCode());
            return ResponseUtil.success(result);
        } else {
            throw new BusinessException("未选择LED屏");
        }
    }
 
    /*
  获取音量
   */
    @PostMapping("/getVolume/{id}")
    public ResponseVO<Object> getVolume(@PathVariable Long id) {
        if (!permissionConfig.check(MenuEnum.XIXUN_VOL_CHANGE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (id == null) {
            throw new BusinessException("未选择LED屏");
        }
        PoleLightemitEntity poleLightemitEntity = poleLightemitService.getById(id);
        if (poleLightemitEntity != null) {
            String result = lightemitUtils.getVoiume(poleLightemitEntity.getLightemitControlCode());
            return ResponseUtil.success(result);
        } else {
            throw new BusinessException("未选择LED屏");
        }
    }
 
 
    /*
    设置亮度
   */
    @PostMapping("/setBrightness")
    public ResponseVO<Object> setBrightness(@RequestBody SetBrightnessParam setBrightnessParam) {
        if (!permissionConfig.check(MenuEnum.XIXUN_BRIGHTNESS_CHANGE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (setBrightnessParam == null || setBrightnessParam.getIds() == null || setBrightnessParam.getBrightness() > 255) {
            throw new BusinessException("参数错误为空或亮度不能超过255");
        }
 
        Collection poleLightemitControllers = poleLightemitService.listByIds(Arrays.asList(setBrightnessParam.getIds()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                poleLightemitService.setBrightness(poleLightemitEntity.getLightemitControlCode(), setBrightnessParam.getBrightness());
            }
            return ResponseUtil.success("设置亮度成功");
        } else {
            throw new BusinessException("未选择LED屏");
        }
    }
 
    /*
 设置音量
  */
    @PostMapping("/setVolume")
    public ResponseVO<Object> setVolume(@RequestBody SetVolumeParam setVolumeEntity) {
        if (!permissionConfig.check(MenuEnum.XIXUN_VOL_CHANGE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (setVolumeEntity == null || setVolumeEntity.getIds() == null || setVolumeEntity.getVolume() > 15) {
            throw new BusinessException("音量范围为0---15");
        }
 
        Collection poleLightemitControllers = poleLightemitService.listByIds(Arrays.asList(setVolumeEntity.getIds()));
        if (!poleLightemitControllers.isEmpty()) {
            Iterator iterator = poleLightemitControllers.iterator();
            while (iterator.hasNext()) {
                PoleLightemitEntity poleLightemitEntity = (PoleLightemitEntity) iterator.next();
                poleLightemitService.setVolume(poleLightemitEntity.getLightemitControlCode(), setVolumeEntity.getVolume());
            }
            return ResponseUtil.success("设置音量成功");
        } else {
            throw new BusinessException("未选择LED屏");
        }
    }
 
    @PostMapping("/addSchedule")
    public ResponseVO<Object> addSchedule(@RequestBody LEDScheduleParam_xixun ledEntity) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PLAN_ADD.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(scheduleService.insert(ledEntity));
    }
 
    @PostMapping("/updateSchedule")
    public ResponseVO<Object> updateSchedule(@RequestBody LEDScheduleParam_xixun ledEntity) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PLAN_UPDATE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(scheduleService.updateSchedule(ledEntity));
    }
 
    @PostMapping("/deleteSchedule")
    public ResponseVO<Object> deleteSchedule(@RequestBody List<Integer> ids) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PLAN_DELETE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        /**
         * 熙汛定时删除 日志记录开始
         */
 
        String content = "{删除的熙汛定时id:" + ids + " }";
        StoreOperationRecordsUtils.storeOperationData(null, null, "熙汛定时任务删除", content);
        /**
         * 熙汛定时删除 日志记录结束
         */
        return ResponseUtil.success(scheduleService.removeByIds(ids));
    }
 
    @GetMapping("/getSchedule/{id}")
    public ResponseVO<Object> getSchedule(@PathVariable Integer id) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PLAN_DETAIL.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        return ResponseUtil.success(scheduleService.getSchedule(id));
    }
 
 
    @GetMapping("/listSchedule")
    public ResponseVO<Object> listSchedule(BaseConditionVO baseConditionVO,
                                           @RequestParam(value = "order", required = false) Integer order,
                                           @RequestParam(value = "seq", required = false) Integer seq,
                                           @RequestParam(value = "keyword", required = false) String keyword) {
        if (!permissionConfig.check(MenuEnum.PLAYPLAN_LIST.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        return ResponseUtil.success(scheduleService.listSchedule(baseConditionVO, order, seq, keyword));
    }
 
 
    /**
     * 设置定时
     *
     * @param id
     * @param lightemitIds
     * @return
     */
    @PostMapping("/pushSchedule/{id}")
    public ResponseVO<Object> pushSchedule(@PathVariable Integer id, @RequestBody Long[] lightemitIds) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PLAN_PUSH_SCHEDULE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        scheduleService.ledschedulepush(id, lightemitIds);
        return ResponseUtil.success("设置成功");
    }
 
    /**
     * 获取执行中的定时
     *
     * @param
     * @return
     */
 
    @PostMapping("/getPushSchedule")
    public ResponseVO<Object> getPushSchedule(@RequestBody List<Long> ids) {
        if (!permissionConfig.check(MenuEnum.XIXUN_PLAN_SCHEDULE.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (ids.isEmpty()) {
            throw new BusinessException("未选择LED屏");
        }
        List<LedScheduleVO> list = new ArrayList<>();
        for (Long id : ids) {
            LedScheduleVO ledScheduleVO = scheduleService.getledschedules(id);
            list.add(ledScheduleVO);
        }
        return ResponseUtil.success(list);
    }
 
 
    /**
     * 关闭天气推送
     */
    @GetMapping("/closeWeatherPush/{id}")
    public ResponseVO<Object> closeWeatherPush(@PathVariable Long id) {
        if (!permissionConfig.check(MenuEnum.XIXUN_CLOSE_AIR.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        if (id == null) {
            throw new BusinessException("未选择LED屏");
        }
        SpringContextHolder.getBean(PoleService.class).closeXiXunAirPush(id);
        return ResponseUtil.success("关闭成功");
    }
 
    /**
     * 清屏操作
     */
    @PostMapping("/clearScreen")
    public ResponseVO<Object> clearScreen(@RequestBody List<Long> ids) {
        if (!permissionConfig.check(MenuEnum.XIXUN_CLEAN.getCode())) {
            return ResponseUtil.fail("缺少对应用户权限");
        }
        List<PoleLightemitEntity> list = poleLightemitService.listByIds(ids);
        if (ids.isEmpty() && list.isEmpty()) {
            throw new BusinessException("未选择LED屏");
        }
        for (PoleLightemitEntity playerId : list) {
            //清屏
            String clear = lightemitUtils.clear(playerId.getLightemitControlCode());
            //清除播放列表
            lightemitUtils.clearVideoPlay(playerId.getLightemitControlCode());
            //清除节目列表
            lightemitUtils.clearPlayerTask(playerId.getLightemitControlCode());
        }
 
        /**
         * 熙汛清屏 日志记录开始
         */
        //获取listCode
        List<String> listCode = new ArrayList<>();
        List<String> msg = new ArrayList<>();
        for (PoleLightemitEntity poleLightemitEntity : list) {
            listCode.add(poleLightemitEntity.getLightemitControlCode());
            msg.add("[屏幕名称" + poleLightemitEntity.getLightemitName() + "设备编码" + poleLightemitEntity.getLightemitControlCode() + "],");
        }
        String content = JSON.toJSONString(msg);
        StoreOperationRecordsUtils.storeOperationData(listCode, null, "熙汛清屏", content);
        /**
         * 熙汛清屏 日志记录结束
         */
        return ResponseUtil.success("清屏成功");
    }
}