From 308bc8e5c0db7298a127f3478995ddc6167328e9 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 25 十二月 2025 16:43:27 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/wuhuyancao' into wuhuyancao

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java |  484 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 465 insertions(+), 19 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
index 57eeaa2..b72835a 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
@@ -1,5 +1,6 @@
 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;
@@ -7,27 +8,36 @@
 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.*;
-import com.doumee.core.model.PageData;
-import com.doumee.core.model.PageWrap;
-import com.doumee.core.utils.Constants;
-import com.doumee.core.utils.Utils;
-import com.doumee.dao.business.DeviceMapper;
-import com.doumee.dao.business.PlatformBroadcastLogMapper;
-import com.doumee.dao.business.model.Device;
-import com.doumee.dao.business.model.PlatformBroadcastLog;
+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;
 
 /**
  * 璁惧淇℃伅琛⊿ervice瀹炵幇
@@ -35,25 +45,54 @@
  * @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 device) {
-        deviceMapper.insert(device);
-        return device.getId();
+    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) {
-        deviceMapper.deleteById(id);
+    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
@@ -63,15 +102,22 @@
     }
 
     @Override
-    public void deleteByIdInBatch(List<Integer> ids) {
+    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo userInfo) {
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        deviceMapper.deleteBatchIds(ids);
+        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);
     }
 
@@ -87,7 +133,16 @@
 
     @Override
     public Device findById(Integer id) {
-        return deviceMapper.selectById(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
@@ -98,6 +153,7 @@
 
     @Override
     public List<Device> findList(Device device) {
+        device.setIsdeleted(Constants.ZERO);
         QueryWrapper<Device> wrapper = new QueryWrapper<>(device);
         return deviceMapper.selectList(wrapper);
     }
@@ -110,7 +166,20 @@
                .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());
-        return deviceMapper.selectList(wrapper);
+        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
@@ -219,7 +288,20 @@
                 queryWrapper.orderByAsc(sortData.getProperty());
             }
         }
-        return PageData.from(deviceMapper.selectPage(page, queryWrapper));
+        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
@@ -228,6 +310,192 @@
         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)//寮傚父瑙i攣
+                    .replace("$BUSADDR",model.getChannelNo());
+            mqttClient = mqttBizService.publish(mqttClient,config,cmdTopic, cmdParamAction);//瑙i攣鍛戒护
+            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());
@@ -250,4 +518,182 @@
             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("=======寮�濮嬭嚜鍔ㄥ畾浜巑qtt浠诲姟瀹屾垚锛�"+model.getName() );
+                }catch (Exception e){
+                    log.error("=======寮�濮嬭嚜鍔ㄥ畾浜巑qtt浠诲姟澶辫触锛�"+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)//閰嶇疆浜哅QTT鍙傛暟
+                    .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;
+    }
 }

--
Gitblit v1.9.3