mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update
This commit is contained in:
@@ -33,9 +33,6 @@ public class CameraController extends BaseController {
|
||||
@Autowired
|
||||
private CameraBusinessService cameraBusinessService;
|
||||
|
||||
@Autowired
|
||||
private BootNettyMqttChannelInboundHandler handler;
|
||||
|
||||
/**
|
||||
* 心跳
|
||||
* @param dto
|
||||
@@ -62,19 +59,16 @@ public class CameraController extends BaseController {
|
||||
return result.successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 给某个 Topic 发消息
|
||||
* @param dto
|
||||
*/
|
||||
@PostMapping("/sendMsg2Topic")
|
||||
public void sendMsg2Topic(@RequestBody SendMsg2TopicDTO dto) {
|
||||
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) {
|
||||
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");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsowell.netty.service.camera;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
|
||||
@@ -21,7 +22,7 @@ public interface CameraBusinessService {
|
||||
* @param msgData 消息内容
|
||||
* @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 进行绑定,存入缓存
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.jsowell.common.util.sign.MD5Util;
|
||||
import com.jsowell.netty.server.mqtt.BootNettyMqttChannelInboundHandler;
|
||||
import com.jsowell.netty.service.camera.CameraBusinessService;
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,6 +24,7 @@ import java.util.Locale;
|
||||
* @Date 2023/12/19 16:07:45
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CameraBusinessServiceImpl implements CameraBusinessService {
|
||||
|
||||
@Autowired
|
||||
@@ -40,7 +42,7 @@ public class CameraBusinessServiceImpl implements CameraBusinessService {
|
||||
* @param msgData 消息内容
|
||||
* @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);
|
||||
// 通过sn查找出对应的channelId
|
||||
String mqttConnectRedisKey = CacheConstants.MQTT_CONNECT_SN + sn;
|
||||
@@ -49,10 +51,11 @@ public class CameraBusinessServiceImpl implements CameraBusinessService {
|
||||
return;
|
||||
}
|
||||
String channelId = (String) cacheObject;
|
||||
if (StringUtils.isNotBlank(msgData)) {
|
||||
if (msgData != null) {
|
||||
jsonObject.put("msg_data", msgData);
|
||||
}
|
||||
|
||||
log.info("给相机发送远程命令,sn:{}, 消息类型:{}, 主题:{}, 最终发送数据:{}", sn, msgType, topic, jsonObject.toJSONString());
|
||||
// 发送消息
|
||||
handler.sendMsg(channelId, topic, jsonObject.toJSONString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user