doum
7 天以前 308bc8e5c0db7298a127f3478995ddc6167328e9
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
package com.doumee.service.business.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.CustomBroadcastRequest;
import com.doumee.core.haikang.model.param.request.TransparentChannelSingleRequest;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.utils.*;
import com.doumee.dao.business.*;
import com.doumee.dao.business.model.*;
import com.doumee.mqtt.config.MqttConfig;
import com.doumee.mqtt.service.MqttBizService;
import com.doumee.service.business.impl.mqtt.MqttClientCache;
import com.doumee.service.business.third.model.LoginUserInfo;
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.model.PageWrap;
import com.doumee.service.business.DeviceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.business.impl.hksync.HkSyncPushServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.Date;
import java.util.stream.Collectors;
 
/**
 * 设备信息表Service实现
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Service
@Slf4j
public class DeviceServiceImpl implements DeviceService {
 
    @Autowired
    private MqttBizService mqttBizService;
    @Autowired
    private DeviceMapper deviceMapper;
    @Autowired
    private DeviceDataMapper deviceDataMapper;
    @Autowired
    private PlatformMapper platformMapper;
    @Autowired
    private PlatformDeviceMapper platformDeviceMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private PlatformBroadcastLogMapper platformBroadcastLogMapper;
    @Autowired
    private InterfaceLogMapper interfaceLogMapper;
 
 
    @Override
    public Integer create(Device model) {
        model.setCreator(model.getLoginUserInfo().getId()+"");
        model.setEdirot(model.getCreator());
        model.setIsdeleted(Constants.ZERO);
        model.setEditDate(new Date());
        model.setCreateDate(model.getEditDate());
        if(model.getDoorNameObj()!=null && Constants.equalsInteger(model.getType(),Constants.DEVICE_TYPE.duanluqi)){
            model.setDoorName(JSONObject.toJSONString(model.getDoorNameObj()));
            if(StringUtils.isNotBlank(model.getLevel())){
                if(getNumberByStr(model.getLevel()) <300){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,控制时长必须大于等于300秒");
                }
            }
        }
        deviceMapper.insert(model);
        return model.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo userInfo) {
        Device update = new Device();
        update.setEdirot(userInfo.getId()+"");
        update.setEditDate(new Date());
        update.setIsdeleted(Constants.ONE);
        update.setId(id);
        deviceMapper.updateById(update);
    }
 
    @Override
    public void delete(Device device) {
        UpdateWrapper<Device> deleteWrapper = new UpdateWrapper<>(device);
        deviceMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo userInfo) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for(Integer id :ids){
            deleteById(id,userInfo);
        }
    }
 
    @Override
    public void updateById(Device device) {
        device.setEdirot(device.getLoginUserInfo().getId()+"");
        device.setEditDate(new Date());
        if(device.getDoorNameObj()!=null && Constants.equalsInteger(device.getType(),Constants.DEVICE_TYPE.duanluqi)){
            device.setDoorName(JSONObject.toJSONString(device.getDoorNameObj()));
        }
        deviceMapper.updateById(device);
    }
 
    @Override
    public void updateByIdInBatch(List<Device> devices) {
        if (CollectionUtils.isEmpty(devices)) {
            return;
        }
        for (Device device: devices) {
            this.updateById(device);
        }
    }
 
    @Override
    public Device findById(Integer id) {
        Device d = deviceMapper.selectById(id);
        if(StringUtils.isNotBlank(d.getDoorName()) &&Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)){
            try {
                //断路器设备参数
                d.setDoorNameObj(JSONObject.parseObject(d.getDoorName()));
            }catch (Exception e){
 
            }
        }
        return d;
    }
 
    @Override
    public Device findOne(Device device) {
        QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
        return deviceMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Device> findList(Device device) {
        device.setIsdeleted(Constants.ZERO);
        QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
        return deviceMapper.selectList(wrapper);
    }
 
    @Override
    public List<Device> findIdAndNameList(Device param) {
        LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(param);
        wrapper.select(Device::getId, Device::getName, Device::getDoorName,Device::getRegionPathName, Device::getRegionName);
        wrapper.eq(null != param.getType(),Device::getType,param.getType())
               .eq(null !=param.getIsdeleted(),Device::getIsdeleted,param.getIsdeleted())
               .eq(Objects.isNull(param.getIsdeleted()),Device::getIsdeleted,Constants.ZERO)
               .eq(null != param.getHkStatus(),Device::getHkStatus,param.getHkStatus());
        List<Device> list = deviceMapper.selectList(wrapper);
        if(list!=null){
            for(Device d : list){
                if(StringUtils.isNotBlank(d.getDoorName()) &&Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)){
                    try {
                        //断路器设备参数
                        d.setDoorNameObj(JSONObject.parseObject(d.getDoorName()));
                    }catch (Exception e){
 
                    }
                }
            }
        }
        return list;
    }
  
    @Override
    public PageData<Device> findPage(PageWrap<Device> pageWrap) {
        IPage<Device> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
        pageWrap.getModel().setIsdeleted(Constants.ZERO);
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(Device::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(Device::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(Device::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(Device::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEdirot() != null) {
            queryWrapper.lambda().eq(Device::getEdirot, pageWrap.getModel().getEdirot());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(Device::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(Device::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(Device::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(Device::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getIsEntrance() != null) {
            queryWrapper.lambda().eq(Device::getIsEntrance, pageWrap.getModel().getIsEntrance());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().like(Device::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getDoorName() != null) {
            queryWrapper.lambda().like(Device::getDoorName, pageWrap.getModel().getDoorName());
        }
        if (pageWrap.getModel().getRegionPathName() != null) {
            queryWrapper.lambda().like(Device::getRegionPathName, pageWrap.getModel().getRegionPathName());
        }
        if (pageWrap.getModel().getRegionName() != null) {
            queryWrapper.lambda().like(Device::getRegionName, pageWrap.getModel().getRegionName());
        }
        if (pageWrap.getModel().getHkId() != null) {
            queryWrapper.lambda().eq(Device::getHkId, pageWrap.getModel().getHkId());
        }
        if (pageWrap.getModel().getHkStatus() != null) {
            queryWrapper.lambda().eq(Device::getHkStatus, pageWrap.getModel().getHkStatus());
        }
        if (pageWrap.getModel().getHkDate() != null) {
            queryWrapper.lambda().ge(Device::getHkDate, Utils.Date.getStart(pageWrap.getModel().getHkDate()));
            queryWrapper.lambda().le(Device::getHkDate, Utils.Date.getEnd(pageWrap.getModel().getHkDate()));
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(Device::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.lambda().eq(Device::getType, pageWrap.getModel().getType());
        }
        if (pageWrap.getModel().getResourceType() != null) {
            queryWrapper.lambda().eq(Device::getResourceType, pageWrap.getModel().getResourceType());
        }
        if (pageWrap.getModel().getNo() != null) {
            queryWrapper.lambda().eq(Device::getNo, pageWrap.getModel().getNo());
        }
        if (pageWrap.getModel().getChannelNo() != null) {
            queryWrapper.lambda().eq(Device::getChannelNo, pageWrap.getModel().getChannelNo());
        }
        if (pageWrap.getModel().getDevTypeCode() != null) {
            queryWrapper.lambda().eq(Device::getDevTypeCode, pageWrap.getModel().getDevTypeCode());
        }
        if (pageWrap.getModel().getManufature() != null) {
            queryWrapper.lambda().eq(Device::getManufature, pageWrap.getModel().getManufature());
        }
        if (pageWrap.getModel().getIp() != null) {
            queryWrapper.lambda().eq(Device::getIp, pageWrap.getModel().getIp());
        }
        if (pageWrap.getModel().getPort() != null) {
            queryWrapper.lambda().eq(Device::getPort, pageWrap.getModel().getPort());
        }
        if (pageWrap.getModel().getInoutType() != null) {
            queryWrapper.lambda().eq(Device::getInoutType, pageWrap.getModel().getInoutType());
        }
        if (pageWrap.getModel().getLevel() != null) {
            queryWrapper.lambda().eq(Device::getLevel, pageWrap.getModel().getLevel());
        }
        if (pageWrap.getModel().getIsUsed() != null) {
            queryWrapper.lambda().eq(Device::getIsUsed, pageWrap.getModel().getIsUsed());
        }
        if (pageWrap.getModel().getOnline() != null) {
            queryWrapper.lambda().eq(Device::getOnline, pageWrap.getModel().getOnline());
        }
        if (pageWrap.getModel().getKqType() != null) {
            queryWrapper.lambda().eq(Device::getKqType, pageWrap.getModel().getKqType());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(Device::getStatus, pageWrap.getModel().getStatus());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        IPage<Device> result = deviceMapper.selectPage(page, queryWrapper);
        if(result!=null){
            for(Device d : result.getRecords()){
                if(StringUtils.isNotBlank(d.getDoorName()) &&Constants.equalsInteger(d.getType(),Constants.DEVICE_TYPE.duanluqi)){
                    try {
                        //断路器设备参数
                        d.setDoorNameObj(JSONObject.parseObject(d.getDoorName()));
                    }catch (Exception e){
 
                    }
                }
            }
        }
        return PageData.from(result);
    }
 
    @Override
    public long count(Device device) {
        QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
        return deviceMapper.selectCount(wrapper);
    }
 
    @Override
    public void setBroadcaseBobao(Device model){
        List<String> ids = new ArrayList<>();
        ids.add(model.getHkId());
        CustomBroadcastRequest request = new CustomBroadcastRequest();
        request.setAudioPointIndexCode(ids);
        request.setPlayDuration(15);//单位秒
        request.setBroadCastMode("tts");
        request.setPriority(1);
        request.setState(1);//播放/停止标识 1-播放,0-停止
        request.setPlayTtsContent(model.getSendInfo());
        BaseResponse response =  HKService.customBroadcast(request);
        if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
          throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"发送失败:"+ JSONObject.toJSONString(response));
        }
    }
 
    @Override
    public   void updateUsedById(Device param){
        Device model = deviceMapper.selectById(param.getId());
        if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.duanluqi)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
 
        MqttConfig config = getMqttConfigByParam(model,"device_");
        MqttClient mqttClient = MqttClientCache.clientMapCache.get("device"+param.getId());
        String[] topics =new String[]{Constants.MqttTopic.mts_status,
                Constants.MqttTopic.mts_attr,
                Constants.MqttTopic.mts_resp};
        if(Constants.equalsInteger(param.getIsUsed(),Constants.ONE)){
            //如果系统不用了,端口mqtt连接
            try {
                mqttClient = mqttBizService.unsubscribe(mqttClient,config  ,topics);
                if(mqttClient ==null){
                    throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"建立连接失败!");
                }
                if(mqttClient.isConnected()){
                    mqttClient.disconnect();
                }
            }catch (Exception e){
                log.error("==============端口mqtt链接失败:"+model.getName()+e.getMessage());
            }
        }else{
            //如果开始使用,开始订阅
            mqttClient = mqttBizService.subscribe(mqttClient,config ,topics);
            if(mqttClient ==null){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"建立连接失败!");
            }
            MqttClientCache.clientMapCache.put("device"+param.getId(),mqttClient);
        }
 
        this.updateById(param);
    }
    @Override
    public  void duanluqiCmd(Device param){
        Device model = deviceMapper.selectById(param.getId());
        if(model ==null && Constants.equalsInteger(param.getType(),Constants.DEVICE_TYPE.duanluqi)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        dealDuanluqiCmd(model,param,"device_");
 
    }
 
    private void dealDuanluqiCmd(Device model, Device param,String clientIndex) {
        MqttConfig config = getMqttConfigByParam(model,clientIndex);
        MqttClient mqttClient = MqttClientCache.clientMapCache.get("device"+param.getId());
        String cmdTopic = Constants.MqttTopic.mts_cmd.replace("$CATE",model.getNo()).replace("$DEVID",model.getDoorNo());
        if(Constants.equalsInteger(param.getStatus(),Constants.ONE)){
            //如果是开闸,先解锁
            String cmdParamAction = CmdContants.T30A.cmdParam.replace("$DEVID", model.getDoorNo())
                    .replace("$CMD",  CmdContants.T30ACmd.do_err_clear)//异常解锁
                    .replace("$BUSADDR",model.getChannelNo());
            mqttClient = mqttBizService.publish(mqttClient,config,cmdTopic, cmdParamAction);//解锁命令
            if(mqttClient ==null){
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"指令发送失败!");
            }
        }
        String cmdParamAction =CmdContants.T30A.cmdParam.replace("$DEVID", model.getDoorNo())
                .replace("$CMD",(Constants.equalsInteger(param.getStatus(),Constants.ONE)?CmdContants.T30ACmd.do_turn_on:CmdContants.T30ACmd.do_turn_off))
                .replace("$BUSADDR", param.getChannelNo());
        mqttClient = mqttBizService.publish(mqttClient,config,cmdTopic, cmdParamAction);//开关闸命令
        if(mqttClient ==null){
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"指令发送失败!");
        }
        MqttClientCache.clientMapCache.put("device"+param.getId(),mqttClient);
        String curremak = "【"+param.getLoginUserInfo().getRealname()
                +"】于"+ DateUtil.getPlusTime2(new Date()) +"进行了"+(Constants.equalsInteger(param.getStatus(),Constants.ONE)?"【开闸】":"【关闸】")+"操作,开关【"+param.getChannelNo()+"】;";
        deviceMapper.update(null,new UpdateWrapper<Device>().lambda()
//                        .setSql("remark = concat(ifnull(remark,''),'"+curremak+"','\n')")
                .set(Device::getRemark,curremak)
                .set(Device::getEditDate,new Date())
                .set(Device::getEdirot,param.getLoginUserInfo().getId())
                .eq(Device::getId,param.getId()));
    }
 
    private MqttConfig getMqttConfigByParam(Device model,String index) {
        MqttConfig config = new MqttConfig();
        JSONObject mqtt = new JSONObject();
        if(StringUtils.isBlank(model.getNo())
                ||StringUtils.isBlank(model.getDoorNo()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,设备标识符和设备号未配置!");
        }
        if(StringUtils.isNotBlank(model.getDoorName())){
            try {
                //断路器设备参数
                mqtt = (JSONObject.parseObject(model.getDoorName()));
            }catch (Exception e){
            }
        }
        if(mqtt == null
                ||StringUtils.isBlank(mqtt.getString("mqttUsername"))
                ||StringUtils.isBlank(mqtt.getString("mqttIp"))
                ||StringUtils.isBlank(mqtt.getString("mqttPort"))
                ||StringUtils.isBlank(mqtt.getString("mqttPassword"))){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,设备mqtt服务参数配置不正确!");
        }
        /**
         *   MqttConfig config = (new MqttConfig());
         *         config.setHost("tcp://192.168.0.7:1883");
         *         config.setClientid("doumee1");
         *         config.setPassword("doumee@168");
         *         config.setUsername("doumee");
         *         config.setVersion("003");
         */
        config.setVersion("003");
        config.setUsername( mqtt.getString("mqttUsername"));
        config.setPassword( mqtt.getString("mqttPassword"));
        config.setHost("tcp://"+ mqtt.getString("mqttIp")+":"+mqtt.getString("mqttPort"));
        config.setClientid(index+model.getId());
        return config;
    }
    public  void mqttCallbackService(String topic, MqttMessage message){
       log.error("mqtt收到消息=====topic:",topic);
       log.error("mqtt收到消息=====message:",JSONObject.toJSONString(message));
    }
    @Override
    public String setBroadcaseBobaoHttp(Device param){
        Device model = deviceMapper.selectById(param.getId());
        if(model ==null && Constants.equalsInteger(param.getType(),Constants.FOUR)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        String input = "";
 
        model.setSendInfo(param.getSendInfo());
        return  sendBroadcaseBobaoHttpBiz(model,interfaceLogMapper);
    }
    public static String sendBroadcaseBobaoHttpBiz(Device model,InterfaceLogMapper interfaceLogMapper){
        //重新下发计划
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("command","start");
        jsonObject.put("TTSContent",model.getSendInfo());
        jsonObject.put("audioLevel",6);
        jsonObject.put("audioVolume",100);
        jsonObject.put("TTSLanguageType","chinese");
        jsonObject.put("voiceType","female");
        jsonObject.put("pace",50);
        JSONArray a = new JSONArray();
        a.add(1);
        jsonObject.put("audioOutID",a);
        String params =jsonObject.toJSONString();
        log.error("========海康广播播放入参内容 : " + params);
        String result = HttpsUtil.doPutHk(model.getIp(),Integer.parseInt(StringUtils.defaultString(model.getPort(),"80")),model.getDoorId(), model.getDoorName()
                ,"/ISAPI/AccessControl/EventCardLinkageCfg/TTSAudio?format=json",params);
        log.error("========海康广播播放返回内容 : " + result);
 
        JSONObject resultJson = JSONObject.parseObject(result);
        Boolean success = false;
        if(Constants.equalsInteger(resultJson.getInteger("statusCode"),Constants.ONE)){
            success = true;
        }
        InterfaceLog log = new InterfaceLog();
        log.setCreateDate(new Date());
        log.setUrl("/ISAPI/AccessControl/EventCardLinkageCfg/TTSAudio?format=json");
        log.setEditDate(log.getCreateDate());
        log.setPlat(Constants.ZERO);
        log.setName("海康广播播放");
        log.setIsdeleted(Constants.ZERO);
        log.setRequest(params);
        log.setType(Constants.ZERO);
        log.setSuccess(success?Constants.ZERO:Constants.ONE);
        log.setRepose(result);
        interfaceLogMapper.insert(log);
 
 
        return result;
    }
    @Override
    public void setLedContent(TransparentChannelSingleRequest model) {
        Device device = findById(model.getDeviceId());
        if(device == null
                || Constants.equalsInteger(device.getIsdeleted(),Constants.ONE)
                || !Constants.equalsInteger(device.getType(),Constants.TWO)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(model.getSpeed()<=0){
            int speed = 13;
            try {
                speed = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.LED_CONTENT_SPEED).getCode());
            }catch (Exception e){
            }
            model.setSpeed(speed);
        }
        PlatformBroadcastLog log  =  HkSyncPushServiceImpl.dealLedContentBiz(0,device.getNo(),device.getName(),model.getContent(),model.getSpeed(),1);
        platformBroadcastLogMapper.insert(log);
        if(log.getHkStatus() == null || !Constants.equalsInteger(log.getHkStatus(), Constants.TWO)){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,屏幕内容设置失败"+(log!=null?log.getHkInfo():""));
        }
    }
    @Override
    public void allLedDefualtContent() {
        log.error( "屏幕内容设置=======================开始========" );
        int speed = 13;
        try {
            speed = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.LED_CONTENT_SPEED).getCode());
        }catch (Exception e){
        }
        //所有月台关联设备信息
        List<PlatformDevice> list =  platformDeviceMapper.selectList(new MPJLambdaWrapper<PlatformDevice>().
                 selectAll(PlatformDevice.class)
                .selectAs(Platform::getLedContent,PlatformDevice::getLedContent)
                .leftJoin(Platform.class,Platform::getId,PlatformDevice::getPlatformId)
                .eq(PlatformDevice::getType,Constants.ZERO)
                .eq(PlatformDevice::getIsdeleted,Constants.ZERO)
                .eq(Platform::getIsdeleted,Constants.ZERO)
        );
        if(list==null || list.size()==0){
            return;
        }
        for(PlatformDevice device :list){
            try {
                String content = device.getLedContent();
                if(StringUtils.isBlank(content)){
                    continue;
                }
                PlatformBroadcastLog log1  =  HkSyncPushServiceImpl.dealLedContentBiz(0,device.getHkNo(),device.getName(),content,speed,1);
                platformBroadcastLogMapper.insert(log1);
                if(log1.getHkStatus() == null || !Constants.equalsInteger(log1.getHkStatus(), Constants.TWO)){
                    log.error( "对不起,屏幕内容设置失败"+(log1!=null?log1.getHkInfo():""));
                }
            }catch (Exception e){
                log.error( "对不起,屏幕内容设置异常"+ device.getName());
            }
        }
        log.error( "屏幕内容设置=======================结束========" );
    }
 
 
    /**
     * 服务开启订阅任务
     */
    @Override
    public   void startCheckDuanluqiSubjob() {
        List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>().lambda()
                .eq(Device::getType,Constants.DEVICE_TYPE.duanluqi)//断路器
                .eq(Device::getIsUsed,Constants.ZERO)
                .eq(Device::getIsdeleted,Constants.ZERO)
        );
        if(devices!=null && devices.size()>0){
            for (Device model : devices){
                try {
                    MqttConfig config = getMqttConfigByParam(model,"device_");
                    MqttClient mqttClient = MqttClientCache.clientMapCache.get("device"+model.getId());
                    String[] topics =new String[]{Constants.MqttTopic.mts_status,
                            Constants.MqttTopic.mts_attr,
                            Constants.MqttTopic.mts_resp};
                        //如果开始使用,开始订阅
                    mqttClient = mqttBizService.subscribe(mqttClient,config ,topics);
                    if(mqttClient ==null){
                        throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"建立连接失败!");
                    }
                    MqttClientCache.clientMapCache.put("device"+model.getId(),mqttClient);
                    log.error("=======开始自动定于mqtt任务完成:"+model.getName() );
                }catch (Exception e){
                    log.error("=======开始自动定于mqtt任务失败:"+model.getName()+e.getMessage());
                }
            }
 
        }
    }
    /**
     * 断路器判断是否需要远程分闸定人任务
     */
    @Override
    public   void autoCloseCmdTimer(){
        if(Constants.DEALING_DUANLUQI_CLOSE){
            return;
        }
        log.error("开启定时远程控制断路器开始=========");
        Constants.DEALING_DUANLUQI_CLOSE = true;
        try {
            List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>().lambda()
                    .eq(Device::getType,Constants.DEVICE_TYPE.duanluqi)//断路器
                    .isNotNull(Device::getLevel)//配置了空闲时长限制
                    .isNotNull(Device::getDoorName)//配置了MQTT参数
                    .isNotNull(Device::getChannelInfo)//配置了控制开关序号
                    .eq(Device::getIsUsed,Constants.ZERO)
                    .eq(Device::getIsdeleted,Constants.ZERO)
            );
            if(devices!=null && devices.size()>0){
                for(Device device : devices){
                    try {
                        long time = (long)getNumberByStr(device.getLevel());//控制时长
                        if(time < 300 ){
                            log.error("开启定时远程控制断路器分闸失败=========空闲时长未正确配置"+time);
                            continue;
                        }
                        double closeDianliu = getCloseDianliuByParam(device);
                        if(closeDianliu < 0 ){
                            log.error("开启定时远程控制断路器分闸失败=========空闲电流阈值设置错误"+closeDianliu);
                            continue;
                        }
                        List<String> closeBtn = new ArrayList<>();
                        String[] btns = device.getChannelInfo().split(",");
                        Date startDate = new Date((System.currentTimeMillis()-time*1000));//查询开始时间
                        List<DeviceData> dataList = deviceDataMapper.selectList(new QueryWrapper<DeviceData>().lambda()
                                .eq(DeviceData::getDeviceId,device.getId())
                                .in(DeviceData::getVal1,btns)
                                .ge(DeviceData::getHappenTime,DateUtil.getPlusTime2(startDate))
                                .orderByDesc(DeviceData::getHappenTime));
                        if(dataList != null && dataList.size()>0 ){
                           for(String b : btns){
                               DeviceData last = getLastDataByVal1(b,dataList,closeDianliu);
                               if(last !=null && StringUtils.equals(last.getVal7(),"1")){
                                   closeBtn.add(b);//需要分闸
                               }
                           }
                           if(StringUtils.equals( dataList.get(0).getVal7(),"0")){
                               log.error("开启定时远程控制断路器分闸结束======分闸状态无需操作==="+device.getName());
                               continue;
                           }
                        }
                        if(closeBtn.size()>0){
                            Device param = new Device();
                            param.setLoginUserInfo(new LoginUserInfo());
                            param.getLoginUserInfo().setRealname("系统自动控制");
                            param.setChannelNo(String.join(",",closeBtn));
                            param.setId(device.getId());
                            param.setStatus(Constants.ZERO);
                            dealDuanluqiCmd(device,param,"deviceTimer_");
                        }
                    }catch (Exception e){
                        log.error("开启定时远程控制断路器分闸失败========="+device.getName()+e.getMessage());
                    }
                }
            }
            log.error("开启定时远程控制断路器分闸数量========="+devices.size());
        }catch (Exception e){
            log.error("开启定时远程控制断路器分闸异常========="+e.getMessage());
        }finally {
            Constants.DEALING_DUANLUQI_CLOSE = false;
        }
        log.error("开启定时远程控制断路器分闸结束=========");
    }
 
    private double getCloseDianliuByParam(Device device) {
        try {
            JSONObject json = JSONObject.parseObject(device.getDoorName() );
            return json.getDouble("max");
        }catch (Exception e){
 
        }
        return 0;
    }
 
    private DeviceData getLastDataByVal1(String b, List<DeviceData> dataList,double limit) {
        List<DeviceData> list = new ArrayList<>();
        for(DeviceData d :dataList){
            if(StringUtils.equals(d.getVal1(),b)){
                if(limit <= getNumberByStr(d.getVal2())){
                    //如果有实时电流值大于空闲阈值,则表示工作中,不做处理
                    return null;
                }
                list.add(d);
            }
        }
        return list.size()>0?list.get(0):null;
    }
 
    private double getNumberByStr(String level) {
        try {
            return Double.parseDouble(level);
        }catch (Exception e){
 
        }
        return 0;
    }
}