2021与蓝度共同重构项目,服务端
Van333
2022-12-29 727a69f859060093e685582fa10e5de82dcc138a
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
package com.sandu.ximon.admin.service;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.iot.model.v20180120.BatchGetDeviceStateResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.domain.CommonPage;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.redis.RedisService;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.manager.iot.frame.A7Frame;
import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder;
import com.sandu.ximon.admin.manager.iot.frame.IRequestFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A7PlcOperationReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.*;
import com.sandu.ximon.admin.manager.iot.frame.inner.response.*;
import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.dto.WrapResponseCommonFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A2OrderEnum;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.A7OrderEnum;
import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
import com.sandu.ximon.admin.param.PlcControlParam;
import com.sandu.ximon.admin.param.PlcRemarkParam;
import com.sandu.ximon.admin.redis.LightKey;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.RedisUtils;
import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
import com.sandu.ximon.dao.bo.PlcBo;
import com.sandu.ximon.dao.domain.*;
import com.sandu.ximon.dao.enums.DeviceRespStatusEnums;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.PlcMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * plc路灯表(Plc)表服务接口
 *
 * @author van
 * @since 2022-12-15 14:45:27
 */
@Service
@Slf4j
@AllArgsConstructor
public class PlcService extends BaseServiceImpl<PlcMapper,Plc> {
 
    private final RedisService redisService;
    private final PlcReportDataService plcReportDataService;
    private final PoleBindingService bindingService;
    private final PoleService poleService;
    private final RedisUtils redisUtils;
 
    public List<PlcBo> listPlc(int pageNo, int pageSize, String keyword, Integer order, Integer seq) {
        Long clientId = SecurityUtils.getClientId();
 
        //排序字段
        String orderByResult = "plc_id";
        //正序、倒叙
        String orderBySeq = OrderByEnums.ASC.getCode();
        if (order != null) {
            switch (order) {
                case 1:
                    orderByResult = OrderByEnums.LIGHT_POLE_NAME.getCode();
                    break;
                case 2:
                    orderByResult = OrderByEnums.LIGHT_UPDATE_TIME.getCode();
                    break;
                case 3:
                    orderByResult = OrderByEnums.LIGHT_CREATE_TIME.getCode();
                    break;
                default:
            }
        }
        if (seq != null) {
            switch (seq) {
                case 1:
                    orderBySeq = OrderByEnums.ASC.getCode();
                    break;
                case 2:
                    orderBySeq = OrderByEnums.DESC.getCode();
                    break;
                default:
                    break;
            }
        }
        //排序方式
        String orderBy = orderByResult + " " + orderBySeq;
 
        PageHelper.startPage(pageNo, pageSize, orderBy);
 
        List<PlcBo> listPlc = baseMapper.listPlc(clientId, keyword);
 
        // 获取最近的上报时间
        List<String> deviceCodeList = listPlc.stream().map(Plc::getDeviceCode).collect(Collectors.toList());
        //拆分list
        List<List<String>> split = CollectionUtil.split(deviceCodeList, 100);
 
        List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = null;
        for (List<String> splist : split) {
            deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(splist);
            if (deviceStatuses != null) {
                for (PlcBo plcBo : listPlc ) {
                    for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) {
 
                        if (plcBo.getDeviceCode() != null && plcBo.getDeviceCode().equals(deviceStatus.getDeviceName())) {
                            if ("ONLINE".equals(deviceStatus.getStatus())) {
                                plcBo.setOnlineStatus(0);
                            } else if ("OFFLINE".equals(deviceStatus.getStatus())) {
                                plcBo.setOnlineStatus(1);
                            } else {
                                plcBo.setOnlineStatus(2);
                            }
 
                        }
                    }
 
                }
            }
        }
 
        if (CollectionUtil.isNotEmpty(deviceCodeList)) {
            List<PlcReportData> reportDataList = plcReportDataService.getNewestReportByDeviceCode(deviceCodeList);
            for (PlcBo plcBo : listPlc) {
                deviceCodeList.forEach(code -> {
                    PoleBinding bind = bindingService.getPoleIdByMac(code);
                    if (bind != null && plcBo.getDeviceCode().equals(bind.getDeviceCode())) {
                        Long poleId = bind.getPoleId();
                        Pole pole = poleService.getById(poleId);
                        plcBo.setPoleId(pole.getId());
                        plcBo.setPoleCode(pole.getDeviceCode());
                        plcBo.setPoleName(pole.getPoleName());
                    }
                });
                for (PlcReportData plcReportData : reportDataList) {
                    if (StrUtil.equals(plcBo.getDeviceCode(), plcReportData.getDeviceCode())) {
                        plcBo.setReportTime(plcReportData.getCreateTime1());
                        break;
                    }
                }
            }
        }
        return listPlc;
    }
 
    /**
     * 获取单个plc信息
     *
     * @param deviceCode 设备码
     * @return
     */
    public Plc getPlc(String deviceCode) {
        Plc one = getOne(Wrappers.<Plc>lambdaQuery().eq(Plc::getDeviceCode, deviceCode));
        if (one == null) {
            return null;
        } else {
            Object o = redisService.get(LightKey.REPORT_MAC.key(deviceCode));
            if (o != null) {
                one.setOnlineStatus(1);
            } else {
                one.setOnlineStatus(0);
            }
            return one;
        }
    }
 
    public boolean addRemark(PlcRemarkParam param) {
        Plc plc = getById(param.getPlcId());
        if (plc == null) {
            throw new BusinessException("找不到PLC");
        }
        Plc update = new Plc();
        update.setPlcId(param.getPlcId());
        update.setPlcRemark(param.getPlcRemark());
        return updateById(update);
    }
 
    /**
     * PLC亮度控制
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> controlBrightness(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcBrightnessReqInnerFrame plcControlFrame = new A7PlcBrightnessReqInnerFrame(param.getBrightness(), param.getPlcAddress());
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcBrightnessRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame, A7PlcBrightnessRespInnerFrame.class);
                //存储控制帧指令
                StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "PLC帧-亮度开关控制", a7Frame, frame);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
                String responseStatus = frame.getResponseInnerFrame().getResponseStatus();
                int status = HexUtil.hexToInt(responseStatus);
                map.put("status", status);
                resultList.add(map);
                // 更新亮度成功,修改到数据库
                if (DeviceRespStatusEnums.SUCCESS.getCode().equals(status)) {
                    Plc plc = new Plc();
                    if (param.getPlcAddress().equals("0001")){
                        plc.setPlcLight1(param.getBrightness());
                    }
                    else if (param.getPlcAddress().equals("0002")){
                        plc.setPlcLight2(param.getBrightness());
                    }
                    else if (param.getPlcAddress().equals("0003")){
                        plc.setPlcLight3(param.getBrightness());
                    }
                    else if (param.getPlcAddress().equals("FFFF")){
                        plc.setPlcLight1(param.getBrightness());
                        plc.setPlcLight2(param.getBrightness());
                        plc.setPlcLight3(param.getBrightness());
 
                    }
                    update(plc, Wrappers.lambdaUpdate(Plc.class).eq(Plc::getDeviceCode, param.getDeviceCode()));
 
                }
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
        /**
         * 服务端批量控灯日志记录开始
         */
        String content = "{PLC控灯请求:" + paramList.toString()
                + ", PLC控灯结果:" + resultList.toString() + "}";
        List<String> codeList = new ArrayList<>();
        for (PlcControlParam bean : paramList) {
            codeList.add(bean.getDeviceCode());
        }
        StoreOperationRecordsUtils.storeOperationData(codeList, null, "服务端批量PLC控灯", content);
        /**
         * 服务端批量控灯日志记录结束
         */
 
        return resultList;
 
    }
 
    /**
     * PLC设置心跳时间
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> setHeartBeatTime(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcSettingHeartBeatTimeReqInnerFrame plcControlFrame = new A7PlcSettingHeartBeatTimeReqInnerFrame(param.getHeartBeatTime());
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcBrightnessRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame, A7PlcBrightnessRespInnerFrame.class);
                //存储控制帧指令
                StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "PLC帧-设置PLC心跳包间隔时间", a7Frame, frame);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
                String responseStatus = frame.getResponseInnerFrame().getResponseStatus();
                int status = HexUtil.hexToInt(responseStatus);
                map.put("status", status);
                resultList.add(map);
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
        /**
         * 服务端批量控灯日志记录开始
         */
        String content = "{PLC设置心跳时间:" + paramList.toString()
                + ", PLC设置心跳时间结果:" + resultList.toString() + "}";
        List<String> codeList = new ArrayList<>();
        for (PlcControlParam bean : paramList) {
            codeList.add(bean.getDeviceCode());
        }
        StoreOperationRecordsUtils.storeOperationData(codeList, null, "PLC设置心跳时间", content);
        /**
         * 服务端批量控灯日志记录结束
         */
 
        return resultList;
 
    }
 
    /**
     * PLC 查询心跳时间
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> queryHeartBeatTime(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcQueryHeartBeatTimeReqInnerFrame plcControlFrame = new A7PlcQueryHeartBeatTimeReqInnerFrame();
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcQueryHeartBeatTimeRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame,  A7PlcQueryHeartBeatTimeRespInnerFrame.class);
                //存储控制帧指令
                StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "PLC帧-设置PLC心跳包间隔时间", a7Frame, frame);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
                String time = frame.getResponseInnerFrame().getTime();
                map.put("status", 0);
                map.put("time",time);
                resultList.add(map);
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
        /**
         * 服务端批量控灯日志记录开始
         */
        String content = "{PLC查询心跳时间:" + paramList.toString()
                + ", PLC查询心跳时间结果:" + resultList.toString() + "}";
        List<String> codeList = new ArrayList<>();
        for (PlcControlParam bean : paramList) {
            codeList.add(bean.getDeviceCode());
        }
        StoreOperationRecordsUtils.storeOperationData(codeList, null, "PLC查询心跳时间", content);
        /**
         * 服务端批量控灯日志记录结束
         */
 
        return resultList;
 
    }
 
    /**
     * PLC 查询心跳包
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> queryHeartBeatData(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcQueryHeartBeatDataReqInnerFrame plcControlFrame = new A7PlcQueryHeartBeatDataReqInnerFrame();
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcQueryHeartBeatDataRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame,  A7PlcQueryHeartBeatDataRespInnerFrame.class);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
                String data = JSON.toJSONString(frame.getResponseInnerFrame().getHeartbeatReportInnerFrame().getHeartBeatDataPackage());
                map.put("status", 0);
                map.put("heartBeatData",data);
                resultList.add(map);
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
 
 
        return resultList;
 
    }
 
 
    /**
     * PLC 查询版本
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> queryVersion(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcQueryVersionReqInnerFrame plcControlFrame = new A7PlcQueryVersionReqInnerFrame();
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcQueryVersionRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame,  A7PlcQueryVersionRespInnerFrame.class);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
                map.put("status", 0);
                map.put("hardwareVersion",frame.getResponseInnerFrame().getHardwareVersionDouble());
                map.put("softwareVersion",frame.getResponseInnerFrame().getSoftwareVersionDouble());
 
                resultList.add(map);
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
        return resultList;
 
    }
 
 
    /**
     * PLC重启
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> reboot(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcRebootReqInnerFrame plcControlFrame = new A7PlcRebootReqInnerFrame();
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcBrightnessRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame, A7PlcBrightnessRespInnerFrame.class);
                //存储控制帧指令
                StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "PLC帧-设置PLC重启", a7Frame, frame);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
                String responseStatus = frame.getResponseInnerFrame().getResponseStatus();
                int status = HexUtil.hexToInt(responseStatus);
                map.put("status", status);
                resultList.add(map);
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
        /**
         * 服务端批量控灯日志记录开始
         */
        String content = "{PLC重启:" + paramList.toString()
                + ", PLC重启:" + resultList.toString() + "}";
        List<String> codeList = new ArrayList<>();
        for (PlcControlParam bean : paramList) {
            codeList.add(bean.getDeviceCode());
        }
        StoreOperationRecordsUtils.storeOperationData(codeList, null, "PLC重启", content);
        /**
         * 服务端批量控灯日志记录结束
         */
 
        return resultList;
 
    }
 
 
    /**
     * PLC恢复出厂设置
     *
     * @return com.sandu.ximon.dao.enums.DeviceRespStatusEnums
     */
    public List<Map<String, Object>> reset(List<PlcControlParam> paramList) {
        if (CollectionUtil.isEmpty(paramList)) {
            throw new BusinessException("参数不能为空");
        }
 
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (PlcControlParam param : paramList) {
            A7PlcResetReqInnerFrame plcControlFrame = new A7PlcResetReqInnerFrame();
            A7Frame a7Frame = new A7Frame(A7OrderEnum.REQUEST_PLC_DATA.getCode(), plcControlFrame);
            Map<String, Object> map = new HashMap<>();
            try {
                map.put("deviceCode", param.getDeviceCode());
                WrapResponseCommonFrame<A7PlcResetRespInnerFrame> frame
                        = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), a7Frame, A7PlcResetRespInnerFrame.class);
                //存储控制帧指令
                StoreOperationRecordsUtils.storeInnerFrameData(param.getDeviceCode(), "PLC帧-设置PLC恢复出厂设置", a7Frame, frame);
 
                if (frame == null) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
 
                String responseStatus = frame.getResponseInnerFrame().getResponseStatus();
                int status = HexUtil.hexToInt(responseStatus);
 
                IRequestFrame iRequestFrame = FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame()).orderType(A2OrderEnum.REQUEST_MAIN_BOARD_RESET.getCode()).build();
                CommonFrame rebootFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(param.getDeviceCode(), iRequestFrame);
 
                boolean b = false;
 
                if (!"00".equals(rebootFrame.getPayload())) {
                    map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                    resultList.add(map);
                    continue;
                }
 
                map.put("status", status);
                resultList.add(map);
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
        }
 
        /**
         * 服务端批量控灯日志记录开始
         */
        String content = "{PLC恢复出厂设置:" + paramList.toString()
                + ", PLC恢复出厂设置:" + resultList.toString() + "}";
        List<String> codeList = new ArrayList<>();
        for (PlcControlParam bean : paramList) {
            codeList.add(bean.getDeviceCode());
        }
        StoreOperationRecordsUtils.storeOperationData(codeList, null, "PLC恢复出厂设置", content);
        /**
         * 服务端批量控灯日志记录结束
         */
 
        return resultList;
 
    }
 
 
    /**
     * 获取用户所有的设备码
     */
    public CommonPage<String> listDeviceCode(int pageNo, int pageSize, String keyword, String deviceCode, String orderBy) {
        List<String> list;
        if (SecurityUtils.getClientId() != null) {
            PageHelper.startPage(pageNo, pageSize);
            list = baseMapper.listCode(SecurityUtils.getUserId(), keyword, deviceCode);
        } else {
 
            PageHelper.startPage(pageNo, pageSize, orderBy);
            list = baseMapper.listCode(null, keyword, deviceCode);
        }
 
        return CommonPage.restPage(list);
    }
 
    public void timeSynchronizationInitiative(String deviceCode, String destinationAddress) {
        Plc plc = getPlc(deviceCode);
        if (plc == null) {
            log.error("PLC主动同步时间请求异常,PLC信息不存在!");
            return;
        }
        SetCalendar(plc.getPlcId(), destinationAddress);
 
    }
    /**
     * 设置日历(同心跳包中的6字节日期时间)
     *
     * @return
     */
    public String SetCalendar(Long plcId, String address) {
        Calendar cal = Calendar.getInstance();
        //获取当前时间
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DATE);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int min = cal.get(Calendar.MINUTE);
        int sec = cal.get(Calendar.SECOND);
 
 
        Plc one = getById(plcId);
        if (one == null) {
            System.out.println("plc不存在!");
        }
 
        A7PlcSetCalendarReqInnerFrame setCalendarReqInnerFrame =
                new A7PlcSetCalendarReqInnerFrame(address, year % 100, month + 1, day, hour, min, sec);
 
        A7Frame a7Frame = new A7Frame(A5OrderEnum.REQUEST_LIGHT_DATA.getCode(), setCalendarReqInnerFrame);
        System.out.println(a7Frame + "            -----A7Frame");
 
        CommonFrame commonFrame;
 
        commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(one.getDeviceCode(), a7Frame);
        StoreOperationRecordsUtils.storeInnerFrameData(one.getDeviceCode(), "PLC帧-设置日历", a7Frame, commonFrame);
 
        System.out.println(commonFrame + "            -----commonFrame");
 
        A7PlcOperationReportInnerFrame operationReportInnerFrame = new A7PlcOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
        if (operationReportInnerFrame.isValidate()) {
            return operationReportInnerFrame.getState();
        } else {
            throw new BusinessException("数据校验错误,请重新请求");
        }
    }
}