From 50c6151c164d8d6bd4d052257c75ba424883fecb Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 13 十月 2023 12:02:55 +0800
Subject: [PATCH] mqtt
---
server/platform/src/main/java/com/doumee/service/impl/MqttSubServiceImpl.java | 36 +++++++
server/services/src/main/java/com/doumee/core/mqtt/service/MqttPushCallback.java | 12 +
server/services/src/main/java/com/doumee/core/mqtt/service/MqttToolService.java | 4
server/services/src/main/java/com/doumee/service/business/DeviceService.java | 3
server/platform/src/main/java/com/doumee/service/MqttSubService.java | 16 +++
server/services/src/main/java/com/doumee/service/business/DeviceSubcribeService.java | 2
server/platform/src/main/java/com/doumee/config/shiro/ShiroConfig.java | 17 ---
server/自行车mqtt协议.md | 5
server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java | 5
server/services/src/main/java/com/doumee/service/business/impl/DeviceSubscribeServiceImpl.java | 18 ++-
server/services/src/main/java/com/doumee/core/mqtt/config/MqttClientInit.java | 50 ++++++++-
server/services/src/main/java/com/doumee/core/mqtt/config/MqttConfig.java | 4
server/platform/src/main/java/com/doumee/api/common/TestController.java | 62 ++++++++++++
server/platform/src/main/resources/application.yml | 1
server/services/src/main/java/com/doumee/dao/business/model/MqttLog.java | 7 +
server/services/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java | 12 +-
16 files changed, 207 insertions(+), 47 deletions(-)
diff --git a/server/platform/src/main/java/com/doumee/api/common/TestController.java b/server/platform/src/main/java/com/doumee/api/common/TestController.java
new file mode 100644
index 0000000..b38cf06
--- /dev/null
+++ b/server/platform/src/main/java/com/doumee/api/common/TestController.java
@@ -0,0 +1,62 @@
+package com.doumee.api.common;
+
+import com.alibaba.fastjson.JSONObject;
+import com.doumee.api.BaseController;
+import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.annotation.trace.Trace;
+import com.doumee.core.constants.Constants;
+import com.doumee.core.utils.DateUtil;
+import com.doumee.core.utils.aliyun.ALiYunUtil;
+import com.doumee.service.business.DeviceService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author Eva.Caesar Liu
+ * @date 2023/02/14 11:14
+ */
+@Api(tags = "娴嬭瘯鎺ュ彛宸ュ叿")
+@Trace(exclude = true)
+@RestController
+@RequestMapping("/test")
+@Slf4j
+public class TestController extends BaseController {
+
+
+ @Autowired
+ private DeviceService deviceService;
+
+
+ @ApiOperation(value = "娴嬭瘯mqtt鍙戝竷娑堟伅", notes = "涓婁紶", httpMethod = "POST", position = 6)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "topic", value = "涓婚", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
+ @ApiImplicitParam(name = "json", value = "鍐呭", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
+ })
+ @PostMapping(value = "/testPush" )
+ public void testPush(@RequestParam String topic,@RequestParam String json, HttpServletRequest request, HttpServletResponse response) throws Exception {
+ deviceService.testPush(topic,json);
+ }
+
+}
diff --git a/server/platform/src/main/java/com/doumee/config/shiro/ShiroConfig.java b/server/platform/src/main/java/com/doumee/config/shiro/ShiroConfig.java
index fdd05c9..2dce2f3 100644
--- a/server/platform/src/main/java/com/doumee/config/shiro/ShiroConfig.java
+++ b/server/platform/src/main/java/com/doumee/config/shiro/ShiroConfig.java
@@ -89,13 +89,6 @@
Map<String, String> map = new LinkedHashMap<>();
// 璺緞鎷︽埅閰嶇疆
// 璺緞鎷︽埅閰嶇疆
-// map.put("/system/dictData/companyUserRules","anon");
-// map.put("/system/login", "anon");
-// map.put("/system/logout", "anon");
-// map.put("/common/captcha", "anon");
-// map.put("/business/areas/*", "anon");
-// map.put("/public/uploadPicture","anon");
-// map.put("/public/uploadLocal","anon");
map.put("/system/dictData/companyUserRules","anon");
map.put("/system/login", "anon");
@@ -103,17 +96,9 @@
map.put("/system/loginH5", "anon");
map.put("/common/captcha", "anon");
map.put("/business/areas/*", "anon");
+ map.put("/test/testPush","anon");
map.put("/public/uploadPicture","anon");
map.put("/public/uploadLocal","anon");
-
-
-// map.put("/business/company/register", "anon");
-// map.put("/business/labels/page","anon");
-// map.put("/business/*/list","anon");
-// map.put("/business/goods/goodsPage","anon");
-// map.put("/business/goods/h5Image","anon");
-// map.put("/business/goods/export","anon");
-// map.put("/business/goods/listForH5","anon");
// - 鏀捐swagger
diff --git a/server/platform/src/main/java/com/doumee/service/MqttSubService.java b/server/platform/src/main/java/com/doumee/service/MqttSubService.java
new file mode 100644
index 0000000..732b91e
--- /dev/null
+++ b/server/platform/src/main/java/com/doumee/service/MqttSubService.java
@@ -0,0 +1,16 @@
+package com.doumee.service;
+
+import com.doumee.dao.business.model.Locks;
+import com.doumee.dao.business.model.MqttLog;
+
+/**
+ * 涓庣‖浠跺鎺ユ湇鍔�
+ * @author 姹熻箘韫�
+ * @date 2023/10/09 18:06
+ */
+public interface MqttSubService {
+
+
+ void startSubcribe();
+
+}
diff --git a/server/platform/src/main/java/com/doumee/service/impl/MqttSubServiceImpl.java b/server/platform/src/main/java/com/doumee/service/impl/MqttSubServiceImpl.java
new file mode 100644
index 0000000..9bcdd03
--- /dev/null
+++ b/server/platform/src/main/java/com/doumee/service/impl/MqttSubServiceImpl.java
@@ -0,0 +1,36 @@
+package com.doumee.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.doumee.core.constants.Constants;
+import com.doumee.core.mqtt.config.MqttConfig;
+import com.doumee.core.mqtt.service.MqttToolService;
+import com.doumee.dao.business.MqttLogMapper;
+import com.doumee.dao.business.model.Locks;
+import com.doumee.dao.business.model.MqttLog;
+import com.doumee.service.MqttSubService;
+import com.doumee.service.business.DeviceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.Date;
+
+/**
+ * 涓庣‖浠跺鎺ユ湇鍔�
+ * @author 姹熻箘韫�
+ * @date 2023/10/09 18:06
+ */
+@Service
+public class MqttSubServiceImpl implements MqttSubService {
+ @Autowired
+ private MqttToolService mqttToolService;
+ @Autowired
+ private MqttLogMapper mqttLogMapper;
+ @Autowired
+ private MqttConfig mqttConfig;
+ @Override
+ @PostConstruct
+ public void startSubcribe() {
+ mqttToolService.subscribe(new String[]{ Constants.MqttTopic.lockInfo, Constants.MqttTopic.closeLock});
+ }
+}
diff --git a/server/platform/src/main/resources/application.yml b/server/platform/src/main/resources/application.yml
index 4f60d4d..a54e9b9 100644
--- a/server/platform/src/main/resources/application.yml
+++ b/server/platform/src/main/resources/application.yml
@@ -62,4 +62,5 @@
mqtt:
clientid: doumeetestplat
+ subclientid: doumeetestplatSub
diff --git a/server/services/src/main/java/com/doumee/core/mqtt/config/MqttClientInit.java b/server/services/src/main/java/com/doumee/core/mqtt/config/MqttClientInit.java
index 06884d0..d71719c 100644
--- a/server/services/src/main/java/com/doumee/core/mqtt/config/MqttClientInit.java
+++ b/server/services/src/main/java/com/doumee/core/mqtt/config/MqttClientInit.java
@@ -10,14 +10,49 @@
public class MqttClientInit {
static MqttClient client;
+ static MqttClient subClient;
- public static synchronized MqttClient getInstance(MqttConfig config,MqttPushCallback callBack){
+ public static synchronized MqttClient getInstance(MqttConfig config ){
if(client !=null){
return client;
}
try {
// host涓轰富鏈哄悕锛宑lientid鍗宠繛鎺QTT鐨勫鎴风ID锛屼竴鑸互鍞竴鏍囪瘑绗﹁〃绀猴紝MemoryPersistence璁剧疆clientid鐨勪繚瀛樺舰寮忥紝榛樿涓轰互鍐呭瓨淇濆瓨
- client = new org.eclipse.paho.client.mqttv3.MqttClient(config.getHost(), config.getClientid()+ Constants.getUUID(),new MemoryPersistence());
+// String clientId =config.getClientid()+ Constants.getUUID();
+ String clientId =config.getClientid();
+ client = new org.eclipse.paho.client.mqttv3.MqttClient(config.getHost(), clientId,new MemoryPersistence());
+ // MQTT鐨勮繛鎺ヨ缃�
+ MqttConnectOptions options = new MqttConnectOptions();
+ // 璁剧疆鏄惁娓呯┖session,杩欓噷濡傛灉璁剧疆涓篺alse琛ㄧず鏈嶅姟鍣ㄤ細淇濈暀瀹㈡埛绔殑杩炴帴璁板綍锛岃缃负true琛ㄧず姣忔杩炴帴鍒版湇鍔″櫒閮戒互鏂扮殑韬唤杩炴帴
+ options.setCleanSession(false);
+ // 璁剧疆杩炴帴鐨勭敤鎴峰悕
+ options.setUserName(config.getUsername());
+ // 璁剧疆杩炴帴鐨勫瘑鐮�
+ options.setPassword(config.getPassword().toCharArray());
+ // 璁剧疆瓒呮椂鏃堕棿 鍗曚綅涓虹
+ options.setConnectionTimeout(10);
+ // 璁剧疆浼氳瘽蹇冭烦鏃堕棿 鍗曚綅涓虹 鏈嶅姟鍣ㄤ細姣忛殧1.5*20绉掔殑鏃堕棿鍚戝鎴风鍙戦�佷釜娑堟伅鍒ゆ柇瀹㈡埛绔槸鍚﹀湪绾匡紝浣嗚繖涓柟娉曞苟娌℃湁閲嶈繛鐨勬満鍒�
+ options.setKeepAliveInterval(20);
+ //璁剧疆鏂紑鍚庨噸鏂拌繛鎺�
+ options.setAutomaticReconnect(true);
+ MqttTopic topic = client.getTopic(clientId+"_close");
+ //閬楀槺
+ options.setWill(topic, "close".getBytes(), 1, true);
+ client.connect(options);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return client;
+ }
+ public static synchronized MqttClient getSubInstance(MqttConfig config,MqttPushCallback callBack){
+ if(subClient !=null){
+ return subClient;
+ }
+ try {
+ // host涓轰富鏈哄悕锛宑lientid鍗宠繛鎺QTT鐨勫鎴风ID锛屼竴鑸互鍞竴鏍囪瘑绗﹁〃绀猴紝MemoryPersistence璁剧疆clientid鐨勪繚瀛樺舰寮忥紝榛樿涓轰互鍐呭瓨淇濆瓨
+// String clientId =config.getClientid()+ Constants.getUUID();
+ String clientId =config.getSubclientid();
+ subClient = new org.eclipse.paho.client.mqttv3.MqttClient(config.getHost(), clientId,new MemoryPersistence());
// MQTT鐨勮繛鎺ヨ缃�
MqttConnectOptions options = new MqttConnectOptions();
// 璁剧疆鏄惁娓呯┖session,杩欓噷濡傛灉璁剧疆涓篺alse琛ㄧず鏈嶅姟鍣ㄤ細淇濈暀瀹㈡埛绔殑杩炴帴璁板綍锛岃缃负true琛ㄧず姣忔杩炴帴鍒版湇鍔″櫒閮戒互鏂扮殑韬唤杩炴帴
@@ -31,18 +66,21 @@
// 璁剧疆浼氳瘽蹇冭烦鏃堕棿 鍗曚綅涓虹 鏈嶅姟鍣ㄤ細姣忛殧1.5*20绉掔殑鏃堕棿鍚戝鎴风鍙戦�佷釜娑堟伅鍒ゆ柇瀹㈡埛绔槸鍚﹀湪绾匡紝浣嗚繖涓柟娉曞苟娌℃湁閲嶈繛鐨勬満鍒�
options.setKeepAliveInterval(20);
// 璁剧疆鍥炶皟
- client.setCallback(callBack);
+ subClient.setCallback(callBack);
//璁剧疆鏂紑鍚庨噸鏂拌繛鎺�
options.setAutomaticReconnect(true);
- MqttTopic topic = client.getTopic(config.getClientid()+"_close");
+ MqttTopic topic = subClient.getTopic(clientId+"_close");
//閬楀槺
options.setWill(topic, "close".getBytes(), 1, true);
- client.connect(options);
+ subClient.connect(options);
} catch (Exception e) {
e.printStackTrace();
}
- return client;
+ return subClient;
}
+
+
+
public static synchronized void refreshClient() throws MqttException {
if(client !=null){
boolean result = client.isConnected();
diff --git a/server/services/src/main/java/com/doumee/core/mqtt/config/MqttConfig.java b/server/services/src/main/java/com/doumee/core/mqtt/config/MqttConfig.java
index 439db83..6cbac72 100644
--- a/server/services/src/main/java/com/doumee/core/mqtt/config/MqttConfig.java
+++ b/server/services/src/main/java/com/doumee/core/mqtt/config/MqttConfig.java
@@ -25,6 +25,10 @@
*/
private String clientid;
/**
+ * 瀹㈡埛绔紪鐮佺敤鎴疯闃�
+ */
+ private String subclientid;
+ /**
* 鎺堟潈璐﹀彿
*/
private String username ;
diff --git a/server/services/src/main/java/com/doumee/core/mqtt/service/MqttPushCallback.java b/server/services/src/main/java/com/doumee/core/mqtt/service/MqttPushCallback.java
index aae9670..0470a42 100644
--- a/server/services/src/main/java/com/doumee/core/mqtt/service/MqttPushCallback.java
+++ b/server/services/src/main/java/com/doumee/core/mqtt/service/MqttPushCallback.java
@@ -38,9 +38,13 @@
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
// subscribe鍚庡緱鍒扮殑娑堟伅浼氭墽琛屽埌杩欓噷闈�
- System.out.println("鎺ユ敹娑堟伅涓婚 : " + topic);
- System.out.println("鎺ユ敹娑堟伅Qos : " + message.getQos());
- System.out.println("鎺ユ敹娑堟伅鍐呭 : " + new String(message.getPayload()));
- deviceSubcribeService.listener(new String(message.getPayload()),topic);
+ try {
+ System.out.println("鎺ユ敹娑堟伅涓婚 : " + topic);
+ System.out.println("鎺ユ敹娑堟伅Qos : " + message.getQos());
+ System.out.println("鎺ユ敹娑堟伅鍐呭 : " + new String(message.getPayload()));
+ deviceSubcribeService.listener(message.getId()+"",new String(message.getPayload()),topic);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
}
}
diff --git a/server/services/src/main/java/com/doumee/core/mqtt/service/MqttToolService.java b/server/services/src/main/java/com/doumee/core/mqtt/service/MqttToolService.java
index 0d1b97b..be90149 100644
--- a/server/services/src/main/java/com/doumee/core/mqtt/service/MqttToolService.java
+++ b/server/services/src/main/java/com/doumee/core/mqtt/service/MqttToolService.java
@@ -26,7 +26,7 @@
for (int i = 0; i < Qos.length; i++) {
Qos[i] = 1;
}
- MqttClientInit.getInstance(config,callBack).subscribe(topics, Qos);
+ MqttClientInit.getSubInstance(config,callBack).subscribe(topics, Qos);
} catch (Exception e) {
e.printStackTrace();
}
@@ -42,7 +42,7 @@
mess.setRetained(true);
mess.setPayload(message.getBytes());
try {
- MqttClientInit.getInstance(config,callBack).publish(topic, mess);
+ MqttClientInit.getInstance(config).publish(topic, mess);
return 1;
} catch (Exception e) {
//LOGGER.error(e.getLocalizedMessage());
diff --git a/server/services/src/main/java/com/doumee/dao/business/model/MqttLog.java b/server/services/src/main/java/com/doumee/dao/business/model/MqttLog.java
index abc1d69..2bc4425 100644
--- a/server/services/src/main/java/com/doumee/dao/business/model/MqttLog.java
+++ b/server/services/src/main/java/com/doumee/dao/business/model/MqttLog.java
@@ -18,7 +18,7 @@
*/
@Data
@ApiModel("绯荤粺琛屼负鎿嶄綔璁板綍琛�")
-@TableName("`mqtt_log`")
+@TableName("\"mqtt_log\"")
public class MqttLog {
@ApiModelProperty(value = "缂栫爜")
@@ -73,8 +73,11 @@
@ApiModelProperty(value = "娑堟伅鍐呭")
@ExcelColumn(name="娑堟伅鍐呭")
private String msg;
+ @ApiModelProperty(value = "mqtt娑堟伅绫诲")
+ @ExcelColumn(name="mqtt娑堟伅绫诲")
+ private String msgId;
- @ApiModelProperty(value = "缁撴灉 0鎴愬姛 1澶辫触", example = "1")
+ @ApiModelProperty(value = "缁撴灉 0鎴愬姛 1澶辫触 ", example = "1")
@ExcelColumn(name="缁撴灉 0鎴愬姛 1澶辫触")
private Integer result;
diff --git a/server/services/src/main/java/com/doumee/service/business/DeviceService.java b/server/services/src/main/java/com/doumee/service/business/DeviceService.java
index 2170ace..aaf5079 100644
--- a/server/services/src/main/java/com/doumee/service/business/DeviceService.java
+++ b/server/services/src/main/java/com/doumee/service/business/DeviceService.java
@@ -17,8 +17,7 @@
*/
MqttLog openLock(Locks locks);
- void startSubcribe();
-
MqttLog getLockInfo(Locks locks);
+ void testPush(String topic, String json);
}
diff --git a/server/services/src/main/java/com/doumee/service/business/DeviceSubcribeService.java b/server/services/src/main/java/com/doumee/service/business/DeviceSubcribeService.java
index 0c9b079..62d4bd2 100644
--- a/server/services/src/main/java/com/doumee/service/business/DeviceSubcribeService.java
+++ b/server/services/src/main/java/com/doumee/service/business/DeviceSubcribeService.java
@@ -13,6 +13,6 @@
* 璁惧涓婃姤鏁版嵁锛堜笂鎶ワ級
* @param param 涓婃姤鍙傛暟
*/
- void listener(String param ,String topic);
+ void listener(String msgId,String param ,String topic);
}
diff --git a/server/services/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
index bae593e..07c619d 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/DeviceServiceImpl.java
@@ -9,6 +9,7 @@
import com.doumee.dao.business.model.MqttLog;
import com.doumee.service.business.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.Date;
@@ -26,12 +27,6 @@
private MqttLogMapper mqttLogMapper;
@Autowired
private MqttConfig mqttConfig;
- @Override
- @PostConstruct
- public void startSubcribe() {
- mqttToolService.subscribe(new String[]{ Constants.MqttTopic.openLock, Constants.MqttTopic.closeLock});
- }
-
/**
* 鍙戣捣寮�閿佹寚浠�
* @param locks
@@ -56,6 +51,11 @@
MqttLog mqttLog = createPushLog(topic,result,"瀹炴椂鏌ヨ閿佷俊鎭痏"+locks.getId());
return mqttLog;
}
+ @Override
+ @Async
+ public void testPush(String topic, String json){
+ int result = mqttToolService.pubMessage(json,topic);
+ }
private MqttLog createPushLog(String topic, int result,String info) {
MqttLog log = new MqttLog();
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 039276b..a34dbae 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
@@ -1,6 +1,7 @@
package com.doumee.service.business.impl;
import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.doumee.core.constants.Constants;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.mqtt.config.MqttConfig;
@@ -36,10 +37,10 @@
@Autowired
private MqttConfig mqttConfig;
@Override
- public void listener(String param,String topic) {
+ public void listener(String msgId,String param,String topic) {
log.info("mqtt娑堟伅璁㈤槄==================="+param);
String info = Constants.MqttTopic.lockInfo.substring(Constants.MqttTopic.lockInfo.lastIndexOf("/")+1) ;
- String closeLock = Constants.MqttTopic.lockInfo.substring(Constants.MqttTopic.closeLock.lastIndexOf("/")+1) ;
+ String closeLock = Constants.MqttTopic.closeLock.substring(Constants.MqttTopic.closeLock.lastIndexOf("/")+1) ;
if(topic.indexOf(Constants.MqttTopic.topic_index)!=0
|| (!StringUtils.contains(topic, info)
&&!StringUtils.contains(topic,closeLock))){
@@ -50,6 +51,12 @@
if(StringUtils.isBlank(lockid)){
//濡傛灉閿佸ご缂栫爜涓虹┖
log.error("mqtt娑堟伅璁㈤槄==============鏃犳晥鏁版嵁====="+param);
+ return;
+ }
+ MqttLog mqttLog = new MqttLog();
+ mqttLog.setMsgId(msgId);
+ if(mqttLogMapper.selectCount(new QueryWrapper<MqttLog>().lambda().eq(MqttLog::getMsgId, msgId)) >0){
+ log.error("mqtt娑堟伅璁㈤槄==============宸叉秷璐规暟鎹�====="+param);
return;
}
String logId =Constants.getUUID();
@@ -71,7 +78,7 @@
MemberRides bikes = new MemberRides();
bikes.setBikeCode(pjson.getString("bikeCode"));
bikes.setBackLockId( pjson.getString("lockId"));
- bikes.setBackLockId( pjson.getString("siteId"));
+ bikes.setBackSiteId( pjson.getString("siteId"));
bikes.setBackCommondId(logId);
result = memberRidesService.mqttCloseBikeEvent(bikes);
logInfo = "mqtt娑堟伅璁㈤槄杩樿溅娑堟伅";
@@ -84,9 +91,9 @@
logInfo = "mqtt娑堟伅璁㈤槄寮傚父===";
result =1;
}
- createSubLog(topic,logId,result,param,logInfo);
+ createSubLog(topic,msgId,logId,result,param,logInfo);
}
- private void createSubLog(String topic, String logId, int result,String param,String info) {
+ private void createSubLog(String topic, String msgId,String logId, int result,String param,String info) {
MqttLog log = new MqttLog();
log.setId(logId);
log.setCreateDate(new Date());
@@ -98,6 +105,7 @@
log.setType(Constants.ZERO);
log.setMsg(param);
log.setInfo(info);
+ log.setMsgId(msgId);
mqttLogMapper.insert(log);
}
private String getLockIdFromTopic(String topic) {
diff --git a/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java
index 1c391aa..c6dc2cf 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/MemberRidesServiceImpl.java
@@ -598,7 +598,8 @@
//TODO-----JP------------鏍规嵁杞﹁締code鍒嗘瀽杞﹁締绫诲瀷锛屽緟纭鏂规-------------------
private String getBileTypeByCode(String bikeCode) {
- return null;
+ int temp=1+(int)(Math.random()*(8));
+ return temp+"";
}
private Locks dealLockAndSite(Locks locks) {
@@ -653,7 +654,7 @@
@Override
public int mqttCloseBikeEvent(MemberRides bikes){
//鍏嶈垂楠戣鏃堕暱鏌ヨ锛屾暟鎹瓧鍏搁厤缃�
- if(StringUtils.isBlank(bikes.getBikeCode()) ||StringUtils.isBlank(bikes.getRentLockId())){
+ if(StringUtils.isBlank(bikes.getBikeCode()) ||StringUtils.isBlank(bikes.getBackLockId())||StringUtils.isBlank(bikes.getBackSiteId())){
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"杩樿溅涓婃姤鍙傛暟閿欒锛�");
}
QueryWrapper<MemberRides> wrapper = new QueryWrapper<>();
diff --git "a/server/\350\207\252\350\241\214\350\275\246mqtt\345\215\217\350\256\256.md" "b/server/\350\207\252\350\241\214\350\275\246mqtt\345\215\217\350\256\256.md"
index 358b7b3..179201d 100644
--- "a/server/\350\207\252\350\241\214\350\275\246mqtt\345\215\217\350\256\256.md"
+++ "b/server/\350\207\252\350\241\214\350\275\246mqtt\345\215\217\350\256\256.md"
@@ -16,6 +16,8 @@
"status": 1, // 鐘舵�侊紝0闂悎, 1鎵撳紑锛�2杩愯涓�, 3寮傚父
"bikeCode": "1234567890" // 鑷杞c鍗″彿锛屾棤杞︿负绌�
}
+
+## {"bikeCode":"1234567890","id":"kjflksjlkfsjdlk","siteId": 456,"status":0,"code":"789"}
```
## pub: device/lock/{id}/getInfo
@@ -40,6 +42,7 @@
"bikeCode": "1234567890",
"lockId": 123,
"siteId": 234,
- "time": "2023-10-13 10:12:90" // 绔欑偣涓婁綅鏈烘敹鍒拌繕杞︽寚浠ょ殑鏃堕棿锛屼粎鍋氬弬鑰冿紝璇蜂互鏈嶅姟鍣ㄦ椂闂翠负鍑�
+ "time": "2023-10-13 10:12:90"
}
+## {"bikeCode":"1234567890","lockId":789,"siteId": 456,"time":"2023-10-13 10:12:90"}
```
\ No newline at end of file
--
Gitblit v1.9.3