update 调整相机相关Service结构

This commit is contained in:
Lemon
2024-01-06 10:57:30 +08:00
parent 838c38adeb
commit ccaba50f07
10 changed files with 149 additions and 74 deletions

View File

@@ -6,7 +6,6 @@ import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.netty.domain.MqttRequest;
import com.jsowell.netty.service.camera.CameraBusinessService;
import com.jsowell.netty.service.camera.impl.CameraBusinessServiceImpl;
import com.jsowell.thirdparty.camera.service.CameraService;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
@@ -17,9 +16,6 @@ import java.net.InetSocketAddress;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**

View File

@@ -13,16 +13,6 @@ import java.net.UnknownHostException;
* @Date 2023/12/20 15:15:26
*/
public interface CameraBusinessService {
/**
* 发送具体指令到某主题
* @param sn 设备 sn
* @param msgType 消息类型
* @param msgPrefix 消息前缀
* @param topic 主题
* @param msgData 消息内容
* @throws InterruptedException
*/
public void sendGroundLockCommand(String sn, String msgType, String msgPrefix, String topic, JSONObject msgData) throws InterruptedException;
/**
* 解析channel中的ip地址 并将 sn 和 channelId 进行绑定,存入缓存

View File

@@ -33,33 +33,6 @@ public class CameraBusinessServiceImpl implements CameraBusinessService {
@Autowired
private BootNettyMqttChannelInboundHandler handler;
/**
* 发送具体指令到某主题
* @param sn 设备 sn
* @param msgType 消息类型
* @param msgPrefix 消息前缀
* @param topic 主题
* @param 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;
Object cacheObject = redisCache.getCacheObject(mqttConnectRedisKey);
if (cacheObject == null) {
return;
}
String channelId = (String) cacheObject;
if (msgData != null) {
jsonObject.put("msg_data", msgData);
}
log.info("给相机发送远程命令sn:{}, 消息类型:{}, 主题:{}, 最终发送数据:{}", sn, msgType, topic, jsonObject.toJSONString());
// 发送消息
handler.sendMsg(channelId, topic, jsonObject.toJSONString());
}
/**
* 解析channel中的ip地址 并将 sn 和 channelId 进行绑定,存入缓存
* @param channel
@@ -90,32 +63,6 @@ public class CameraBusinessServiceImpl implements CameraBusinessService {
}
}
/**
* 根据规则拼装字符串
* @param sn 设备 sn
* @param msgType 消息类型
* @param msgPrefix 消息前缀
* @return 拼装好的json对象
*/
private JSONObject spliceStr(String sn, String msgType, String msgPrefix) {
StringBuilder sb = new StringBuilder();
String msgId = msgPrefix + DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS) + "01";
String timeStamp = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS);
sb.append("sn=").append(sn)
.append("&timestamp=").append(timeStamp)
.append("&msg_id=").append(msgId)
.append("&msg_type=").append(msgType);
// 进行 32 位 MD5 计算
String sign = MD5Util.MD5Encode(sb.toString()).toUpperCase(Locale.ROOT);
JSONObject jsonObject = new JSONObject();
jsonObject.put("sign", sign);
jsonObject.put("sn", sn);
jsonObject.put("timestamp", timeStamp);
jsonObject.put("msg_id", msgId);
jsonObject.put("msg_type", msgType);
return jsonObject;
}
public static void main(String[] args) {
System.out.println(System.currentTimeMillis());