From 4fabfe4dbd2eb28d07a4350597d314958cc1c281 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期四, 09 十月 2025 11:16:43 +0800
Subject: [PATCH] 优化

---
 server/services/src/main/java/com/doumee/service/business/impl/DeviceSubscribeServiceImpl.java |   62 ++++++++++++++++++++++++-------
 1 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/DeviceSubscribeServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/DeviceSubscribeServiceImpl.java
index 0b483c2..6314d3a 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/DeviceSubscribeServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/DeviceSubscribeServiceImpl.java
@@ -5,19 +5,18 @@
 import com.doumee.core.constants.Constants;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.mqtt.config.MqttConfig;
-import com.doumee.core.mqtt.service.MqttToolService;
-import com.doumee.dao.business.MemberRidesMapper;
 import com.doumee.dao.business.MqttLogMapper;
-import com.doumee.dao.business.SitesMapper;
 import com.doumee.dao.business.model.*;
-import com.doumee.service.business.*;
+import com.doumee.service.business.ActionLogService;
+import com.doumee.service.business.DeviceSubcribeService;
+import com.doumee.service.business.MemberRidesService;
+import com.doumee.service.business.SitesService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.PostConstruct;
 import java.util.Date;
 
 /**
@@ -33,9 +32,12 @@
     MemberRidesService memberRidesService;
     @Lazy
     @Autowired
-    SitesMapper sitesMapper;
+    SitesService sitesService;
     @Autowired
     private MqttLogMapper mqttLogMapper;
+    @Autowired
+    @Lazy
+    private ActionLogService actionLogService;
     @Autowired
     private MqttConfig mqttConfig;
     @Override
@@ -44,11 +46,15 @@
         String info = Constants.MqttTopic.sub_lockInfo.substring(Constants.MqttTopic.sub_lockInfo.lastIndexOf("/")+1) ;
         String closeLock = Constants.MqttTopic.sub_closeLock.substring(Constants.MqttTopic.sub_closeLock.lastIndexOf("/")+1) ;
         String health = Constants.MqttTopic.sub_health.substring(Constants.MqttTopic.sub_health.lastIndexOf("/")+1) ;
+        String adminCard = Constants.MqttTopic.sub_adminCard.substring(Constants.MqttTopic.sub_adminCard.lastIndexOf("/")+1) ;
+        String siteInfo = Constants.MqttTopic.sub_siteInfo.substring(Constants.MqttTopic.sub_siteInfo.lastIndexOf("/")+1) ;
         String brokers = "brokers";
         if(!StringUtils.contains(topic, brokers)){
             if(topic.indexOf(Constants.MqttTopic.topic_index)!=0
                     ||topic.split("/").length < 4
                     || (!StringUtils.contains(topic, info)
+                    &&!StringUtils.contains(topic, siteInfo)
+                    &&!StringUtils.contains(topic, adminCard)
                     &&!StringUtils.contains(topic, health)
                     &&!StringUtils.contains(topic,closeLock))){
                 log.error("mqtt娑堟伅璁㈤槄===========鏃犳晥鏁版嵁========"+param);
@@ -58,7 +64,7 @@
         MqttLog mqttLog = new MqttLog();
         mqttLog.setMsgId(msgId);
         mqttLog.setTopic(topic);
-        int msgCount  =mqttLogMapper.selectCount(new QueryWrapper<MqttLog>().lambda().eq(MqttLog::getMsg, param).eq(MqttLog::getType, Constants.ZERO));
+        long msgCount  =mqttLogMapper.selectCount(new QueryWrapper<MqttLog>().lambda().eq(MqttLog::getMsg, param).eq(MqttLog::getType, Constants.ZERO));
         if(msgCount>0){
             log.error("mqtt娑堟伅璁㈤槄==============宸叉秷璐规暟鎹�====="+param);
             return;
@@ -77,8 +83,8 @@
                 }
                 if(StringUtils.contains(topic, info)){
                     //濡傛灉閿佸ご淇℃伅涓婃姤
-                    String lockid =  ss[3];//閿佸ご缂栫爜
-                    if( StringUtils.isBlank(lockid)){
+                    Integer lockid = Constants.formatIntegerFromStr(ss[3])  ;//閿佸ご缂栫爜
+                    if( lockid == null){
                         //濡傛灉閿佸ご缂栫爜涓虹┖
                         log.error("mqtt娑堟伅璁㈤槄==============鏃犳晥鏁版嵁====="+topic+param);
                         return;
@@ -92,8 +98,8 @@
                     log.info("mqtt娑堟伅璁㈤槄=========閿佷俊鎭�==========鎴愬姛");
                 }else if(StringUtils.contains(topic, closeLock)){
                     //濡傛灉杩樿溅涓婃姤
-                    String lockid =  ss[3];//閿佸ご缂栫爜
-                    if( StringUtils.isBlank(lockid)){
+                    Integer lockid = Constants.formatIntegerFromStr(ss[3]);//閿佸ご缂栫爜
+                    if( lockid == null){
                         //濡傛灉閿佸ご缂栫爜涓虹┖
                         log.error("mqtt娑堟伅璁㈤槄==============鏃犳晥鏁版嵁====="+topic+param);
                         return;
@@ -104,6 +110,7 @@
                     bikes.setBackLockId( lockid);
                     bikes.setBackSiteId( siteid);
                     bikes.setBackCommondId(logId);
+                    bikes.setStatus(pjson.getInteger("status"));
                     result = memberRidesService.mqttCloseBikeEvent(bikes);
                     logInfo = "mqtt娑堟伅璁㈤槄杩樿溅娑堟伅";
                     log.info("mqtt娑堟伅璁㈤槄=========杩樿溅==========鎴愬姛");
@@ -113,10 +120,34 @@
                     site.setId(siteid);
                     site.setOnline(Constants.ZERO);
                     site.setLastLinkDate(new Date());
-                    sitesMapper.updateById(site);//鏇存柊绔欑偣鐘舵��
+                    sitesService.updateByMqtt(site);//鏇存柊绔欑偣鐘舵��
                     logInfo = "mqtt娑堟伅璁㈤槄蹇冭烦娑堟伅";
                     log.info("mqtt娑堟伅璁㈤槄=========蹇冭烦娑堟伅==========鎴愬姛");
 
+                }else if(StringUtils.contains(topic, adminCard)){
+                    //绠$悊鍛樺埛鍗″紑閿�
+                    JSONObject pjson  = JSONObject.parseObject(param);
+                    ActionLog actionLog = new ActionLog();
+                    actionLog.setParam3(pjson.getString("bikeCode"));
+                    actionLog.setParam2(pjson.getString("lockId"));
+                    actionLog.setTitle(pjson.getString("cardNo"));
+                    actionLog.setParam(siteid);
+                    actionLog.setType(Constants.TWO);
+                    actionLog.setIsdeleted(Constants.ZERO);
+                    actionLog.setCreateDate(new Date());
+                    actionLogService.create(actionLog);
+                    logInfo = "绠$悊鍛樺埛鍗″紑閿�";
+                    log.info("mqtt娑堟伅璁㈤槄=========绠$悊鍛樺埛鍗″紑閿�==========鎴愬姛");
+                } else if(StringUtils.contains(topic, siteInfo)){
+                    //濡傛灉閿佸ご鍏ㄩ噺淇℃伅涓婃姤
+                    JSONObject pjson  = JSONObject.parseObject(param);
+                    Sites sites = new Sites();
+                    sites.setId(siteid);
+                    sites.setClientVersion(pjson.getString("version"));
+                    sites.setLockNum(pjson.getInteger("locks"));
+                    sitesService.dealSiteLocks(sites);
+                    logInfo = "mqtt娑堟伅璁㈤槄閿佸ご鍏ㄩ噺淇℃伅涓婃姤";
+                    log.info("mqtt娑堟伅璁㈤槄=========閿佸ご鍏ㄩ噺淇℃伅涓婃姤==========鎴愬姛");
                 }
             }else {
                 //濡傛灉绔欑偣涓婁笅绾挎秷鎭�
@@ -126,7 +157,7 @@
                     log.error("mqtt娑堟伅璁㈤槄==============鏃犳晥璁㈤槄鐘舵��====="+topic+param);
                     return;
                 }
-                Sites site = sitesMapper.selectById(clientId);
+                Sites site = sitesService.findById(clientId);
                 if(site == null){
                     log.error("mqtt娑堟伅璁㈤槄==============鏃犳晥璁㈤槄鐘舵��====="+topic+param);
                     return;
@@ -145,7 +176,7 @@
                     site.setOnline(Constants.ZERO);
                 }
                 site.setLastLinkDate(new Date());
-                sitesMapper.updateById(site);//鏇存柊绔欑偣鐘舵��
+                sitesService.updateByMqtt(site);//鏇存柊绔欑偣鐘舵��
                 log.info("mqtt娑堟伅璁㈤槄=========绔欑偣涓婁笅绾�==========鎴愬姛");
             }
         }catch (BusinessException e){
@@ -159,6 +190,9 @@
         }
         createSubLog(topic,msgId,logId,result,param,logInfo);
     }
+
+
+
     private void createSubLog(String topic, String msgId,String logId, int result,String param,String info) {
         MqttLog log = new MqttLog();
         log.setId(logId);

--
Gitblit v1.9.3