2021与蓝度共同重构项目,服务端
Van333
2022-12-15 5e94332935da62448c17f89a807acf46a5ae3e75
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
package com.sandu.ximon.admin.newnova.led;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.newnova.conf.ProgramPathConfig;
import com.sandu.ximon.admin.newnova.param.NewNovaLedParam;
import com.sandu.ximon.admin.newnova.param.ProgramPrarm;
import com.sandu.ximon.admin.newnova.program.LEDInfoParam;
import com.sandu.ximon.admin.newnova.program.NewNovaProgramService;
import com.sandu.ximon.admin.newnova.utils.NovaAPIUtil;
import com.sandu.ximon.admin.newnova.vo.ProWHVO;
import com.sandu.ximon.admin.newnova.vo.StatusVO;
import com.sandu.ximon.admin.newnova.vo.TrasfromStatusVO;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.service.PoleBindingService;
import com.sandu.ximon.admin.service.PoleService;
import com.sandu.ximon.dao.bo.AirDataNongGengBo;
import com.sandu.ximon.dao.bo.NewNovaGroupListBo;
import com.sandu.ximon.dao.domain.NewNovaLed;
import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.mapper.AirDataNongGengMapper;
import com.sandu.ximon.dao.mapper.NewNovaLedMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
 
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @author LiuHaoNan
 * @date 2022/11/9
 */
@Service
@AllArgsConstructor
public class NewNovaLedService extends BaseServiceImpl<NewNovaLedMapper, NewNovaLed> {
 
    private final PoleBindingService poleBindingService;
    private ProgramPathConfig filePathConfig;
 
    /**
     * 屏幕注册
     *
     * @param param
     * @return
     */
    public boolean saveLed(NewNovaLedParam param) {
        NewNovaLed one = getOne(Wrappers.lambdaQuery(NewNovaLed.class).eq(NewNovaLed::getSn, param.getSn()));
        if (one != null) {
            throw new BusinessException("设备已存在,请勿重复注册!");
        }
        NewNovaLed led = new NewNovaLed();
        led.setSn(param.getSn());
        led.setName(param.getName());
        led.setOnlineSign(0);
        return save(led);
    }
 
 
    /**
     * 编辑屏幕名称
     *
     * @param param
     * @return
     */
    public boolean editLed(NewNovaLedParam param) {
        if (param.getId() == null) {
            throw new BusinessException("屏幕id不能为空");
        }
        if (param.getName() == null || param.getName().isEmpty()) {
            throw new BusinessException("屏幕名称不能为空");
        }
 
        NewNovaLed one = getById(param.getId());
        if (one == null) {
            throw new BusinessException("设备不存在!");
        }
//        one.setSn(param.getSn());
        one.setName(param.getName());
        return updateById(one);
    }
 
    /**
     * 删除LED
     *
     * @param ids
     * @return
     */
    public boolean delLed(List<Long> ids) {
        if (ids.isEmpty()) {
            throw new BusinessException("id不能为空");
        }
        List<NewNovaLed> newNovaLeds = listByIds(ids);
        if (newNovaLeds.isEmpty()) {
            throw new BusinessException("设备不存在!");
        }
        //获取删除设备的设备码
        List<String> snList = newNovaLeds.stream().map(NewNovaLed::getSn).collect(Collectors.toList());
        //删除绑定关系
        SpringContextHolder.getBean(PoleBindingService.class).remove(Wrappers.lambdaQuery(PoleBinding.class)
                .eq(PoleBinding::getDeviceType, 12).in(PoleBinding::getDeviceCode, snList));
        //删除设备
        return removeByIds(ids);
    }
 
    /**
     * LED列表
     *
     * @param baseConditionVO
     * @param keyword
     * @param groupId
     * @param onlineStatus
     * @return
     */
    public List<NewNovaLed> listLed(BaseConditionVO baseConditionVO, String keyword, Long groupId, boolean onlineStatus) {
 
        NovaAPIUtil instanceUtil = NovaAPIUtil.getInstanceUtil();
        //排序
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        List<NewNovaLed> newNovaListBos = baseMapper.listLed(keyword, groupId, SecurityUtils.getClientId());
        //获取在线状态
        List<NewNovaLed> onLine = instanceUtil.getOnlineStatus(newNovaListBos, onlineStatus);
        //获取分辨率
        instanceUtil.getDisplayInfoAsync(onLine);
 
        updateBatchById(onLine);
        return onLine;
    }
 
    public NewNovaLed getInfo(Long ledId) {
        NovaAPIUtil instanceUtil = NovaAPIUtil.getInstanceUtil();
        NewNovaLed byId = getById(ledId);
        if (byId == null) {
            throw new BusinessException("设备不存在或id不正确 !");
        }
        PoleBinding poleBinding = SpringContextHolder.getBean(PoleBindingService.class).getOne(Wrappers.lambdaQuery(PoleBinding.class)
                .eq(PoleBinding::getDeviceCode, byId.getSn()).eq(PoleBinding::getDeviceType, 12));
        if (poleBinding != null) {
            Pole pole = SpringContextHolder.getBean(PoleService.class).getById(poleBinding.getPoleId());
            byId.setPoleId(pole.getId());
            byId.setPoleName(pole.getPoleName());
        }
        List<NewNovaLed> list = new ArrayList<>();
        list.add(byId);
        //获取在线状态
        instanceUtil.getOnlineStatus(list, false);
        //获取屏幕开关
        instanceUtil.getScreenPowerState(list);
        //获取音量
        instanceUtil.getVolumeState(list);
        //获取亮度
        instanceUtil.getScreenBrightness(list);
        //获取同步状态
        instanceUtil.getSync(list);
        //获取详情
        instanceUtil.getInfo(byId);
        //获取分辨率
        instanceUtil.getDisplayInfoAsync(list);
        //获取时区
        instanceUtil.getTimezone(list);
        //获取视频源
        instanceUtil.getVideoInfoAsync(list);
 
        return list.get(0);
    }
 
    /**
     * 获取整组的屏幕
     *
     * @param groupId
     */
    public List<NewNovaGroupListBo> getListByGroupId(Long groupId) {
        List<NewNovaGroupListBo> listByGroupId = baseMapper.getListByGroupId(groupId, SecurityUtils.getClientId());
        return listByGroupId;
    }
 
    /**
     * 推送大气
     *
     * @param id
     * @param duration
     * @param fontSize
     */
    public Object pushAirData(Long id, Long duration, Long fontSize) throws InterruptedException {
        NovaAPIUtil apiUtil = NovaAPIUtil.getInstanceUtil();
        NewNovaLed byId = getById(id);
        PoleBinding nova = poleBindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, byId.getSn()).eq(PoleBinding::getDeviceType, 12));
        if (nova == null) {
            throw new BusinessException("未绑定诺瓦设备");
        }
        PoleBinding air = poleBindingService.getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getPoleId, nova.getPoleId()).eq(PoleBinding::getDeviceType, 11));
        if (air == null) {
            throw new BusinessException("未绑定大气设备");
        }
 
        //获取大气监测数据
        AirDataNongGengBo data = SpringContextHolder.getBean(AirDataNongGengMapper.class).historyData(air.getDeviceCode()).get(0);
 
        //解析大气数据
        Map pageInfo = parseData(data, duration, fontSize);
        ProgramPrarm page = new ProgramPrarm();
        page.setPageInfo(pageInfo);
        page.setInsertPlay(true);
        ProWHVO whvo = new ProWHVO("大气监测", 128, 256);
        page.setProgramMsg(whvo);
        StatusVO createPro = apiUtil.createPro(whvo);
        Integer pid = Integer.valueOf(createPro.getStatusData());
        page.setProgramID(pid);
 
        StatusVO editPro = apiUtil.editProgram(pid, pageInfo);
        if (editPro.getStatusCode() != 0) {
            throw new BusinessException(editPro.getStatusData());
        }
        StatusVO genVO = apiUtil.genrateProgram(pid);
        if (genVO.getStatusCode() != 0) {
            throw new BusinessException(genVO.getStatusData());
        }
        page.setProgramID(Integer.valueOf(createPro.getStatusData()));
        page.setStartPlayAfterTransferred(true);
        List<String> sns = new ArrayList<String>();
        sns.add(byId.getSn());
        page.setSnList(sns);
 
        List<TrasfromStatusVO> trasfromStatusVOS = apiUtil.trasfromProgram(page);
 
        File file = new File(filePathConfig.getOutPutPath() + "/program" + pid);
        SpringContextHolder.getBean(NewNovaProgramService.class).deleteFile(file);
 
        return trasfromStatusVOS;
    }
 
    /**
     * 处理大气数据
     *
     * @param data
     * @param duration
     * @param fontSize
     * @return
     */
 
    private Map parseData(AirDataNongGengBo data, Long duration, Long fontSize) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z+8:00'");
        Date end = new Date();
        end.setTime(end.getTime() + duration);
        String str = "{\n" +
                "        \"name\": \"大气监测\",\n" +
                "        \"widgetContainers\": [\n" +
                "            {\n" +
                "                \"contents\": {\n" +
                "                    \"widgets\": [\n" +
                "                        {\n" +
                "                            \"constraints\": [\n" +
                "                                {\n" +
                "                                    \"cron\": [\n" +
                "                                        \"\"\n" +
                "                                    ],\n" +
                "                                    \"endTime\": \"" + sdf.format(end) + "\",\n" +
                "                                    \"startTime\": \"" + sdf.format(new Date()) + "\"\n" +
                "                                }\n" +
                "                            ],\n" +
                "                            \"duration\":" + duration + ",\n" +
                "                            \"metadata\": {\n" +
                "                                \"content\": {\n" +
                "                                    \"autoPaging\": true,\n" +
                "                                    \"backgroundMusic\": {\n" +
                "                                        \"duration\": 0,\n" +
                "                                        \"isTextSync\": false\n" +
                "                                    },\n" +
                "                                    \"displayStyle\": {\n" +
                "                                        \"scrollAttributes\": {\n" +
                "                                            \"effects\": {\n" +
                "                                                \"animation\": \"MARQUEE_LEFT\",\n" +
                "                                                \"speed\": 3\n" +
                "                                            }\n" +
                "                                        },\n" +
                "                                        \"type\": \"STATIC\"\n" +
                "                                    },\n" +
                "                                    \"paragraphs\": [\n" +
                "                                        {\n" +
                "                                            \"backgroundColor\": \"#00000000\",\n" +
                "                                            \"horizontalAlignment\": \"LEFT\",\n" +
                "                                            \"letterSpacing\": 0,\n" +
                "                                            \"lineSpacing\": 0,\n" +
                "                                            \"lines\": [\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"环境监测:\"\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                },\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"温度:" + (data == null || data.getAirTemperature() == null ? " - " : data.getAirTemperature()) + "\"" + "\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                },\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"湿度:" + (data == null || data.getAirHumidity() == null ? " - " : data.getAirHumidity()) + "\"" + "\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                },\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"pm25:" + (data == null || data.getPm2point5() == null ? " - " : data.getPm2point5()) + "\"" + "\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                },\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"pm10:" + (data == null || data.getPm10() == null ? " - " : data.getPm10()) + "\"" + "\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                },\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"光照:" + (data == null || data.getIllumination() == null ? " - " : data.getIllumination()) + "\"" + "\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                },\n" +
                "                                                {\n" +
                "                                                    \"segs\": [\n" +
                "                                                        {\n" +
                "                                                            \"content\": \"噪音:" + (data == null || data.getNoise() == null ? " - " : data.getNoise()) + "\"" + "\n" +
                "                                                        }\n" +
                "                                                    ]\n" +
                "                                                }\n" +
                "                                            ],\n" +
                "                                            \"verticalAlignment\": \"TOP\"\n" +
                "                                        }\n" +
                "                                    ],\n" +
                "                                    \"textAttributes\": [\n" +
                "                                        {\n" +
                "                                            \"backgroundColor\": \"#ff000000\",\n" +
                "                                            \"attributes\": {\n" +
                "                                                \"font\": {\n" +
                "                                                    \"family\": [\n" +
                "                                                        \"Helvetica\"\n" +
                "                                                    ],\n" +
                "                                                    \"isUnderline\": false,\n" +
                "                                                    \"size\": " + fontSize + ",\n" +
                "                                                    \"style\": \"NORMAL\"\n" +
                "                                                },\n" +
                "                                                \"letterSpacing\": 0,\n" +
                "                                                \"textColor\": \"#ffff0000\"\n" +
                "                                            }\n" +
                "                                        }\n" +
                "                                    ]\n" +
                "                                }\n" +
                "                            },\n" +
                "                            \"name\": \"环境监测\",\n" +
                "                            \"type\": \"ARCH_TEXT\"\n" +
                "                        }\n" +
                "                    ]\n" +
                "                },\n" +
                "                \"id\": 1,\n" +
                "                \"name\": \"widgetContainers1\"\n" +
                "            }\n" +
                "        ]\n" +
                "    }";
 
        return JSON.parseObject(str, Map.class);
    }
 
 
    /**
     * 获取状态信息
     *
     * @param param
     * @return
     */
    public Object infoList(LEDInfoParam param) {
 
        NovaAPIUtil instanceUtil = NovaAPIUtil.getInstanceUtil();
 
        List<NewNovaLed> newNovaLeds = listByIds(param.getLedIds());
        param.setLedList(newNovaLeds);
 
        switch (param.getType()) {
            case "all":
                //获取屏幕开关
                instanceUtil.getScreenPowerState(param.getLedList());
                //获取音量
                instanceUtil.getVolumeState(param.getLedList());
                //获取亮度
                instanceUtil.getScreenBrightness(param.getLedList());
                //获取同步状态
                instanceUtil.getSync(param.getLedList());
                //获取分辨率
                instanceUtil.getDisplayInfoAsync(param.getLedList());
                //获取时区
                instanceUtil.getTimezone(param.getLedList());
                //获取视频源
                instanceUtil.getVideoInfoAsync(param.getLedList());
                break;
            case "volumeValue":
                //获取音量
                instanceUtil.getVolumeState(param.getLedList());
                break;
            case "brightnessValue":
                //获取亮度
                instanceUtil.getScreenBrightness(param.getLedList());
                break;
            case "videoSourceValue":
                //获取视频源
                instanceUtil.getVideoInfoAsync(param.getLedList());
                break;
            case "timeValue":
                //获取时区
                instanceUtil.getTimezone(param.getLedList());
                break;
            case "screenPowerStatus":
                //获取屏幕开关
                instanceUtil.getScreenPowerState(param.getLedList());
                break;
            case "syncPlayStatus":
                //获取同步状态
                instanceUtil.getSync(param.getLedList());
                break;
            default:
        }
 
 
        return param.getLedList();
    }
}