mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update 调整相机相关Service结构
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 进行绑定,存入缓存
|
||||
|
||||
@@ -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("×tamp=").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());
|
||||
|
||||
Reference in New Issue
Block a user