This commit is contained in:
Lemon
2023-12-27 08:17:22 +08:00
parent 2174a550f5
commit a596dea3f2
3 changed files with 12 additions and 14 deletions

View File

@@ -33,9 +33,6 @@ public class CameraController extends BaseController {
@Autowired @Autowired
private CameraBusinessService cameraBusinessService; private CameraBusinessService cameraBusinessService;
@Autowired
private BootNettyMqttChannelInboundHandler handler;
/** /**
* 心跳 * 心跳
* @param dto * @param dto
@@ -62,19 +59,16 @@ public class CameraController extends BaseController {
return result.successResponse(); return result.successResponse();
} }
/**
* 给某个 Topic 发消息
* @param dto
*/
@PostMapping("/sendMsg2Topic") @PostMapping("/sendMsg2Topic")
public void sendMsg2Topic(@RequestBody SendMsg2TopicDTO dto) { public void sendMsg2Topic(@RequestBody SendMsg2TopicDTO dto) {
try { try {
cameraBusinessService.sendGroundLockCommand(dto.getSn(), dto.getMsgType(), dto.getMsgPrefix(), dto.getTopic(), dto.getMsgData().toJSONString()); cameraBusinessService.sendGroundLockCommand(dto.getSn(), dto.getMsgType(), dto.getMsgPrefix(), dto.getTopic(), dto.getMsgData());
} catch (Exception e) { } catch (Exception e) {
logger.error("发送消息 error, ", 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

@@ -1,5 +1,6 @@
package com.jsowell.netty.service.camera; package com.jsowell.netty.service.camera;
import com.alibaba.fastjson2.JSONObject;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@@ -21,7 +22,7 @@ public interface CameraBusinessService {
* @param msgData 消息内容 * @param msgData 消息内容
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendGroundLockCommand(String sn, String msgType, String msgPrefix, String topic, String msgData) throws InterruptedException; public void sendGroundLockCommand(String sn, String msgType, String msgPrefix, String topic, JSONObject msgData) throws InterruptedException;
/** /**
* 解析channel中的ip地址 并将 sn 和 channelId 进行绑定,存入缓存 * 解析channel中的ip地址 并将 sn 和 channelId 进行绑定,存入缓存

View File

@@ -9,6 +9,7 @@ import com.jsowell.common.util.sign.MD5Util;
import com.jsowell.netty.server.mqtt.BootNettyMqttChannelInboundHandler; import com.jsowell.netty.server.mqtt.BootNettyMqttChannelInboundHandler;
import com.jsowell.netty.service.camera.CameraBusinessService; import com.jsowell.netty.service.camera.CameraBusinessService;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -23,6 +24,7 @@ import java.util.Locale;
* @Date 2023/12/19 16:07:45 * @Date 2023/12/19 16:07:45
*/ */
@Service @Service
@Slf4j
public class CameraBusinessServiceImpl implements CameraBusinessService { public class CameraBusinessServiceImpl implements CameraBusinessService {
@Autowired @Autowired
@@ -40,7 +42,7 @@ public class CameraBusinessServiceImpl implements CameraBusinessService {
* @param msgData 消息内容 * @param msgData 消息内容
* @throws InterruptedException * @throws InterruptedException
*/ */
public void sendGroundLockCommand(String sn, String msgType, String msgPrefix, String topic, String msgData) throws InterruptedException { public void sendGroundLockCommand(String sn, String msgType, String msgPrefix, String topic, JSONObject msgData) throws InterruptedException {
JSONObject jsonObject = spliceStr(sn, msgType, msgPrefix); JSONObject jsonObject = spliceStr(sn, msgType, msgPrefix);
// 通过sn查找出对应的channelId // 通过sn查找出对应的channelId
String mqttConnectRedisKey = CacheConstants.MQTT_CONNECT_SN + sn; String mqttConnectRedisKey = CacheConstants.MQTT_CONNECT_SN + sn;
@@ -49,10 +51,11 @@ public class CameraBusinessServiceImpl implements CameraBusinessService {
return; return;
} }
String channelId = (String) cacheObject; String channelId = (String) cacheObject;
if (StringUtils.isNotBlank(msgData)) { if (msgData != null) {
jsonObject.put("msg_data", msgData); jsonObject.put("msg_data", msgData);
} }
log.info("给相机发送远程命令sn:{}, 消息类型:{}, 主题:{}, 最终发送数据:{}", sn, msgType, topic, jsonObject.toJSONString());
// 发送消息 // 发送消息
handler.sendMsg(channelId, topic, jsonObject.toJSONString()); handler.sendMsg(channelId, topic, jsonObject.toJSONString());
} }