fix(优化):订单显示手机号功能,视频流生成下发任务时一起下发
This commit is contained in:
+5
-1
@@ -17,6 +17,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -40,7 +41,10 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "设备管理")
|
||||
@RequiredArgsConstructor
|
||||
public class AgeDeviceController {
|
||||
private final IAgeDeviceService ageDeviceService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private IAgeDeviceService ageDeviceService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
|
||||
+11
-4
@@ -9,10 +9,10 @@ import com.central.device.message.ControlEnum;
|
||||
import com.central.device.message.ControlMessageConstant;
|
||||
import com.central.device.model.LineFile;
|
||||
import com.central.device.service.ILineFileService;
|
||||
import com.central.device.service.LiveStreamService;
|
||||
import com.central.device.util.IotRequestResult;
|
||||
import com.central.device.util.MapUtil;
|
||||
import com.central.device.util.RequestUtils;
|
||||
import com.central.device.util.http.HeaderUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -41,7 +41,7 @@ public class ApiDeviceController {
|
||||
private String baseUrl;// = "http://119.45.169.13:8848/";
|
||||
|
||||
@Autowired
|
||||
private HeaderUtils headerUtils;
|
||||
private LiveStreamService liveStreamService;
|
||||
|
||||
@Autowired
|
||||
private RequestUtils requestUtils;
|
||||
@@ -92,7 +92,7 @@ public class ApiDeviceController {
|
||||
}
|
||||
|
||||
// 3. 构建控制消息
|
||||
JsonObject controlMessage = buildControlMessage(control, orderNo);
|
||||
JsonObject controlMessage = buildControlMessage(control, orderNo, deviceId);
|
||||
if (controlMessage == null) {
|
||||
return Result.succeed("暂未开放控制权限");
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class ApiDeviceController {
|
||||
return !StringUtils.isEmpty(orderStatus) && orderStatus.equals("1");
|
||||
}
|
||||
|
||||
private JsonObject buildControlMessage(String control, String orderNo) {
|
||||
private JsonObject buildControlMessage(String control, String orderNo, String deviceId) {
|
||||
if (!ControlEnum.contains(ControlEnum.valueOf(control.toUpperCase()))) {
|
||||
return null;
|
||||
}
|
||||
@@ -138,6 +138,13 @@ public class ApiDeviceController {
|
||||
LineFile lineFile = lineFileService.findLineFileByWaylineId(waylineId);
|
||||
Assert.notNull(lineFile,"航线文件签名不正确");
|
||||
data.addProperty("file_md5", lineFile.getSign());
|
||||
// 设置设备视频流地址
|
||||
try {
|
||||
data.addProperty("stream_urls", liveStreamService.generateStreamUrls(deviceId).toString());
|
||||
} catch (Exception e) {
|
||||
log.error("生成设备推流/拉流地址异常: deviceId={}, error={}", deviceId, e.getMessage(), e);
|
||||
data.addProperty("stream_urls", "{}"); // 或者空字符串 ""
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.central.device.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.device.service.LiveStreamService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/live")
|
||||
public class LiveStreamController {
|
||||
|
||||
@Autowired
|
||||
private LiveStreamService liveStreamService;
|
||||
|
||||
@GetMapping("/stream-urls")
|
||||
public JSONObject getStreamUrls(@RequestParam String deviceId) {
|
||||
return liveStreamService.generateStreamUrls(deviceId);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.central.device.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.device.util.TencentLiveUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class LiveStreamService {
|
||||
|
||||
@Value("${tencent.live.push-domain}")
|
||||
private String pushDomain;
|
||||
@Value("${tencent.live.play-domain}")
|
||||
private String playDomain;
|
||||
@Value("${tencent.live.app-name}")
|
||||
private String appName;
|
||||
@Value("${tencent.live.key}")
|
||||
private String key;
|
||||
@Value("${tencent.live.expire-seconds:3600}")
|
||||
private long expireSeconds;
|
||||
|
||||
private static final String STREAM_URL_KEY_PREFIX = "device:stream_urls:";
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 生成设备推流和拉流地址,并缓存到Redis
|
||||
*/
|
||||
public JSONObject generateStreamUrls(String deviceId) {
|
||||
String cacheKey = STREAM_URL_KEY_PREFIX + deviceId;
|
||||
String cacheValue = redisTemplate.opsForValue().get(cacheKey);
|
||||
if (cacheValue != null) {
|
||||
return JSONObject.parseObject(cacheValue);
|
||||
}
|
||||
|
||||
long expire = System.currentTimeMillis() / 1000 + expireSeconds;
|
||||
String pushUrl = TencentLiveUtil.generatePushUrl(pushDomain, appName, deviceId, key, expire);
|
||||
String playRtmpUrl = TencentLiveUtil.generatePlayUrl(playDomain, appName, deviceId, "rtmp");
|
||||
String playFlvUrl = TencentLiveUtil.generatePlayUrl(playDomain, appName, deviceId, "flv");
|
||||
String playM3u8Url = TencentLiveUtil.generatePlayUrl(playDomain, appName, deviceId, "m3u8");
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("pushUrl", pushUrl);
|
||||
result.put("playRtmpUrl", playRtmpUrl);
|
||||
result.put("playFlvUrl", playFlvUrl);
|
||||
result.put("playM3u8Url", playM3u8Url);
|
||||
|
||||
// 缓存到redis,设置过期时间(如1小时)
|
||||
redisTemplate.opsForValue().set(cacheKey, result.toJSONString(), 1, TimeUnit.HOURS);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.central.device.util;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
public class TencentLiveUtil {
|
||||
|
||||
/**
|
||||
* 生成推流地址
|
||||
*/
|
||||
public static String generatePushUrl(String pushDomain, String appName, String streamName, String key, long expireTime) {
|
||||
String txTime = Long.toHexString(expireTime).toUpperCase();
|
||||
String txSecret = DigestUtils.md5Hex(key + streamName + txTime).toLowerCase();
|
||||
return String.format("rtmp://%s/%s/%s?txSecret=%s&txTime=%s", pushDomain, appName, streamName, txSecret, txTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成拉流地址
|
||||
*/
|
||||
public static String generatePlayUrl(String playDomain, String appName, String streamName, String type) {
|
||||
switch (type.toLowerCase()) {
|
||||
case "flv":
|
||||
return String.format("http://%s/%s/%s.flv", playDomain, appName, streamName);
|
||||
case "m3u8":
|
||||
return String.format("http://%s/%s/%s.m3u8", playDomain, appName, streamName);
|
||||
case "rtmp":
|
||||
default:
|
||||
return String.format("rtmp://%s/%s/%s", playDomain, appName, streamName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,3 +40,10 @@ jetlinks:
|
||||
# jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/logger-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
|
||||
# username: ${zlt.datasource.username}
|
||||
# password: ${zlt.datasource.password}
|
||||
tencent:
|
||||
live:
|
||||
push-domain: 208280.push.tlivecloud.com
|
||||
play-domain: goflytec.com
|
||||
expire-seconds: 3600 #过期时间为1小时
|
||||
app-name: live
|
||||
key: 06b20e5b7d637c1128fa1b48ea91a13e
|
||||
|
||||
Reference in New Issue
Block a user