Skip to content

Commit c73577f

Browse files
committed
充电宝归还
1 parent fa8b2e5 commit c73577f

File tree

7 files changed

+24
-39
lines changed

7 files changed

+24
-39
lines changed

share-parent/share-modules/share-device/src/main/java/com/share/device/api/DeviceApiControlller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public AjaxResult getStation(@PathVariable Long id, @PathVariable String latitud
4242

4343
@Operation(summary = "扫码充电")
4444
@RequiresLogin
45-
@GetMapping("scanCharge/{cabinetNo}")
45+
@GetMapping("/scanCharge/{cabinetNo}")
4646
public AjaxResult scanCharge(@PathVariable String cabinetNo) {
4747
return success(deviceService.scanCharge(cabinetNo));
4848
}

share-parent/share-modules/share-device/src/main/java/com/share/device/emqx/callback/OnMessageCallback.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package com.share.device.emqx.callback;
22

3+
import com.alibaba.fastjson2.JSONObject;
4+
import com.share.device.emqx.factory.MessageHandlerFactory;
35
import lombok.extern.slf4j.Slf4j;
6+
import com.share.device.emqx.handler.MessageHandler;
47
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
58
import org.eclipse.paho.client.mqttv3.MqttCallback;
69
import org.eclipse.paho.client.mqttv3.MqttMessage;
10+
import org.springframework.beans.factory.annotation.Autowired;
711
import org.springframework.stereotype.Component;
812

913
@Slf4j
1014
@Component
1115
public class OnMessageCallback implements MqttCallback {
1216

17+
@Autowired
18+
private MessageHandlerFactory messageHandlerFactory;
1319

1420
@Override
1521
public void connectionLost(Throwable cause) {
@@ -23,6 +29,17 @@ public void messageArrived(String topic, MqttMessage message) {
2329
System.out.println("接收消息主题:" + topic);
2430
System.out.println("接收消息Qos:" + message.getQos());
2531
System.out.println("接收消息内容:" + new String(message.getPayload()));
32+
try {
33+
// 根据主题选择不同的处理逻辑
34+
MessageHandler massageHandler = messageHandlerFactory.getMassageHandler(topic);
35+
if(null != massageHandler) {
36+
String content = new String(message.getPayload());
37+
massageHandler.handleMessage(JSONObject.parseObject(content));
38+
}
39+
} catch (Exception e) {
40+
e.printStackTrace();
41+
log.error("mqtt消息异常:{}", new String(message.getPayload()));
42+
}
2643

2744
}
2845

share-parent/share-modules/share-device/src/main/java/com/share/device/emqx/handler/impl/PowerBankConnectedHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
import com.share.device.domain.PowerBank;
1111
import com.share.device.domain.Station;
1212
import com.share.device.emqx.annotation.JiaEmqx;
13+
import com.share.device.emqx.constant.EmqxConstants;
1314
import com.share.device.emqx.handler.MessageHandler;
1415
import com.share.device.service.ICabinetService;
1516
import com.share.device.service.ICabinetSlotService;
1617
import com.share.device.service.IPowerBankService;
1718
import com.share.device.service.IStationService;
18-
import com.share.order.api.RemoteOrderInfoService;
1919
import com.share.order.domain.EndOrderVo;
2020
import lombok.extern.slf4j.Slf4j;
2121
import org.apache.commons.lang3.StringUtils;
@@ -25,13 +25,11 @@
2525

2626
import java.math.BigDecimal;
2727
import java.util.Date;
28-
import java.util.List;
2928
import java.util.concurrent.TimeUnit;
30-
import java.util.stream.Collectors;
3129

3230
@Slf4j
3331
@Component
34-
@JiaEmqx(topic = com.share.device.emqx.constant.EmqxConstants.TOPIC_POWERBANK_CONNECTED)
32+
@JiaEmqx(topic = EmqxConstants.TOPIC_POWERBANK_CONNECTED)
3533
public class PowerBankConnectedHandler implements MessageHandler {
3634

3735
@Autowired

share-parent/share-modules/share-device/src/main/java/com/share/device/emqx/handler/impl/PowerBankUnlockHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.share.device.domain.PowerBank;
1010
import com.share.device.domain.Station;
1111
import com.share.device.emqx.annotation.JiaEmqx;
12+
import com.share.device.emqx.constant.EmqxConstants;
1213
import com.share.device.emqx.handler.MessageHandler;
1314
import com.share.device.service.ICabinetService;
1415
import com.share.device.service.ICabinetSlotService;
@@ -27,7 +28,7 @@
2728

2829
@Slf4j
2930
@Component
30-
@JiaEmqx(topic = com.share.device.emqx.constant.EmqxConstants.TOPIC_POWERBANK_UNLOCK)
31+
@JiaEmqx(topic = EmqxConstants.TOPIC_POWERBANK_UNLOCK)
3132
public class PowerBankUnlockHandler implements MessageHandler {
3233

3334
@Autowired

share-parent/share-modules/share-device/src/main/java/com/share/device/emqx/handler/impl/PropertyPostHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
import com.alibaba.fastjson2.JSONObject;
55
import com.share.device.emqx.annotation.JiaEmqx;
6+
import com.share.device.emqx.constant.EmqxConstants;
67
import com.share.device.emqx.handler.MessageHandler;
78
import lombok.extern.slf4j.Slf4j;
89
import org.springframework.stereotype.Component;
910

1011
@Slf4j
1112
@Component
12-
@JiaEmqx(topic = com.share.device.emqx.constant.EmqxConstants.TOPIC_PROPERTY_POST)
13+
@JiaEmqx(topic = EmqxConstants.TOPIC_PROPERTY_POST)
1314
public class PropertyPostHandler implements MessageHandler {
1415

1516
@Override

share-parent/share-modules/share-order/src/main/java/com/share/order/service/impl/OrderInfoServiceImpl.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -294,36 +294,4 @@ public OrderInfo selectOrderInfoById(Long id) {
294294
return orderInfo;
295295
}
296296

297-
public static void main(String[] args) {
298-
// 假设这是从JSON解析得到的List<Map<String, Object>>
299-
List<Map<String, Object>> dataList = new ArrayList<>();
300-
Map<String, Object> map1 = new HashMap<>();
301-
map1.put("MONTH", "2024-10");
302-
map1.put("order_count", 1);
303-
dataList.add(map1);
304-
305-
Map<String, Object> map2 = new HashMap<>();
306-
map2.put("MONTH", "2024-11");
307-
map2.put("order_count", 4);
308-
dataList.add(map2);
309-
310-
Map<String, Object> map3 = new HashMap<>();
311-
map3.put("MONTH", "2024-12");
312-
map3.put("order_count", 1);
313-
dataList.add(map3);
314-
315-
Map dataMap = new HashMap<>();
316-
317-
List<Object> monthList = new ArrayList<>();
318-
List<Object> orderCountList = new ArrayList<>();
319-
320-
for (Map<String, Object> map : dataList) {
321-
monthList.add(map.get("MONTH"));
322-
orderCountList.add(map.get("order_count"));
323-
}
324-
325-
dataMap.put("dateList", monthList);
326-
dataMap.put("countList", orderCountList);
327-
328-
}
329297
}

0 commit comments

Comments
 (0)