新增 netty整合mqtt协议,与车位相机通讯并保存通讯信息

This commit is contained in:
Lemon
2023-12-20 16:17:34 +08:00
parent 7015cb1234
commit 5fbce62752
16 changed files with 972 additions and 23 deletions

View File

@@ -4,18 +4,19 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.netty.server.mqtt.BootNettyMqttChannelInboundHandler;
import com.jsowell.netty.service.camera.CameraBusinessService;
import com.jsowell.pile.dto.camera.CameraHeartBeatDTO;
import com.jsowell.pile.dto.camera.CameraIdentifyResultsDTO;
import com.jsowell.pile.dto.camera.SendMsg2TopicDTO;
import com.jsowell.thirdparty.camera.common.CameraCommonResult;
import com.jsowell.thirdparty.camera.service.CameraService;
import io.netty.channel.ChannelFuture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 充电相机 controller
*
@@ -29,6 +30,12 @@ public class CameraController extends BaseController {
@Autowired
private CameraService cameraService;
@Autowired
private CameraBusinessService cameraBusinessService;
@Autowired
private BootNettyMqttChannelInboundHandler handler;
/**
* 心跳
* @param dto
@@ -36,6 +43,7 @@ public class CameraController extends BaseController {
@PostMapping("/v1/receiveHeartBeat")
public CameraCommonResult receiveHeartBeat(@RequestBody CameraHeartBeatDTO dto) {
logger.info("接收相机系统心跳包 params:{}", JSON.toJSONString(dto));
cameraService.saveHeartBeat2Redis(dto);
CameraCommonResult result = new CameraCommonResult();
logger.info("接收相机系统心跳包 result:{}", JSON.toJSONString(result.successResponse()));
return result.successResponse();
@@ -53,4 +61,20 @@ public class CameraController extends BaseController {
cameraService.receiveIdentifyResults(jsonObject);
return result.successResponse();
}
@PostMapping("/sendMsg2Topic")
public void sendMsg2Topic(@RequestBody SendMsg2TopicDTO dto) {
try {
cameraBusinessService.sendGroundLockCommand(dto.getSn(), dto.getMsgType(), dto.getMsgPrefix(), dto.getTopic());
} catch (Exception e) {
logger.error("发送消息 error, ", e);
}
}
// @PostMapping("/sendMsg2Topic")
// public void sendMsg2Topic(@RequestBody SendMsg2TopicDTO dto) throws InterruptedException {
// ChannelFuture channelFuture = handler.sendMsg(dto.getChannelId(), dto.getTopic(), dto.getRequestMsg().toString());
// System.out.println("123");
// }
}

View File

@@ -47,6 +47,7 @@ import com.jsowell.common.util.id.SnowflakeIdWorker;
import com.jsowell.common.util.ip.AddressUtils;
import com.jsowell.netty.handler.HeartbeatRequestHandler;
import com.jsowell.netty.handler.TransactionRecordsRequestHandler;
import com.jsowell.netty.service.camera.impl.CameraBusinessServiceImpl;
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
import com.jsowell.pile.domain.*;
import com.jsowell.pile.domain.ykcCommond.IssueQRCodeCommand;
@@ -85,6 +86,7 @@ import com.jsowell.wxpay.common.WeChatPayParameter;
import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO;
import com.jsowell.wxpay.response.WechatPayRefundRequest;
import com.jsowell.wxpay.service.WxAppletRemoteService;
import io.netty.channel.ChannelFuture;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
@@ -220,6 +222,9 @@ public class SpringBootTestController {
@Autowired
private OrderPileOccupyService orderPileOccupyService;
@Autowired
private CameraBusinessServiceImpl cameraBusinessServiceImpl;
@Autowired
private LTYTService ltytService;
@@ -248,6 +253,23 @@ public class SpringBootTestController {
System.out.println(JSON.toJSONString(memberWalletVOS));
}
@Test
public void testMqttSendMsg() throws InterruptedException {
String channelId = "94dd42b6";
String topic = "/GroundlockStatus";
JSONObject jsonObject = new JSONObject();
jsonObject.put("sign","F4213AD90EBC72C678E03450E4E091EE");
jsonObject.put("sn","e27f089d-5fadf6c6");
jsonObject.put("timestamp","2021-07-01 12:00:01");
jsonObject.put("msg_id","GS2021070112000101");
jsonObject.put("msg_type","GroundlockStatus");
jsonObject.put("msg_data",null);
// ChannelFuture future = cameraBusinessServiceImpl.sendMsg(channelId, topic, jsonObject.toJSONString());
// System.out.println(future.toString());
}
@Test
public void queryPaymentByOrderNoTest() {
String orderNo = "C44903356969";