临时提交
This commit is contained in:
@@ -1,155 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.github.pagehelper.util.StringUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 位置信息管理
|
||||
*/
|
||||
@Tag(name = "位置信息管理")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/position")
|
||||
public class MobilePositionController {
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceChannelService deviceChannelService;
|
||||
|
||||
/**
|
||||
* 查询历史轨迹
|
||||
* @param deviceId 设备ID
|
||||
* @param start 开始时间
|
||||
* @param end 结束时间
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询历史轨迹", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号")
|
||||
@Parameter(name = "start", description = "开始时间")
|
||||
@Parameter(name = "end", description = "结束时间")
|
||||
@GetMapping("/history/{deviceId}")
|
||||
public List<MobilePosition> positions(@PathVariable String deviceId,
|
||||
@RequestParam(required = false) String channelId,
|
||||
@RequestParam(required = false) String start,
|
||||
@RequestParam(required = false) String end) {
|
||||
|
||||
if (StringUtil.isEmpty(start)) {
|
||||
start = null;
|
||||
}
|
||||
if (StringUtil.isEmpty(end)) {
|
||||
end = null;
|
||||
}
|
||||
return storager.queryMobilePositions(deviceId, channelId, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备最新位置
|
||||
* @param deviceId 设备ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询设备最新位置", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/latest/{deviceId}")
|
||||
public MobilePosition latestPosition(@PathVariable String deviceId) {
|
||||
return storager.queryLatestPosition(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取移动位置信息
|
||||
* @param deviceId 设备ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取移动位置信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/realtime/{deviceId}")
|
||||
public DeferredResult<MobilePosition> realTimePosition(@PathVariable String deviceId) {
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_MOBILE_POSITION + deviceId;
|
||||
try {
|
||||
cmder.mobilePostitionQuery(device, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取移动位置信息: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<MobilePosition> result = new DeferredResult<MobilePosition>(5*1000L);
|
||||
result.onTimeout(()->{
|
||||
log.warn(String.format("获取移动位置信息超时"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(key, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅位置信息
|
||||
* @param deviceId 设备ID
|
||||
* @param expires 订阅超时时间
|
||||
* @param interval 上报时间间隔
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
@Operation(summary = "订阅位置信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "expires", description = "订阅超时时间", required = true)
|
||||
@Parameter(name = "interval", description = "上报时间间隔", required = true)
|
||||
@GetMapping("/subscribe/{deviceId}")
|
||||
public void positionSubscribe(@PathVariable String deviceId,
|
||||
@RequestParam String expires,
|
||||
@RequestParam String interval) {
|
||||
|
||||
if (StringUtil.isEmpty(interval)) {
|
||||
interval = "5";
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires));
|
||||
device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
|
||||
deviceService.updateCustomDevice(device);
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "报警信息管理")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/alarm")
|
||||
public class AlarmController {
|
||||
|
||||
@Autowired
|
||||
private IDeviceAlarmService deviceAlarmService;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommander commander;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform commanderForPlatform;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storage;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
|
||||
/**
|
||||
* 删除报警
|
||||
*
|
||||
* @param id 报警id
|
||||
* @param deviceIds 多个设备id,逗号分隔
|
||||
* @param time 结束时间(这个时间之前的报警会被删除)
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除报警", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "id", description = "ID")
|
||||
@Parameter(name = "deviceIds", description = "多个设备id,逗号分隔")
|
||||
@Parameter(name = "time", description = "结束时间")
|
||||
public Integer delete(
|
||||
@RequestParam(required = false) Integer id,
|
||||
@RequestParam(required = false) String deviceIds,
|
||||
@RequestParam(required = false) String time
|
||||
) {
|
||||
if (ObjectUtils.isEmpty(id)) {
|
||||
id = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(deviceIds)) {
|
||||
deviceIds = null;
|
||||
}
|
||||
|
||||
if (ObjectUtils.isEmpty(time)) {
|
||||
time = null;
|
||||
}else if (!DateUtil.verification(time, DateUtil.formatter) ){
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "time格式为" + DateUtil.PATTERN);
|
||||
}
|
||||
List<String> deviceIdList = null;
|
||||
if (deviceIds != null) {
|
||||
String[] deviceIdArray = deviceIds.split(",");
|
||||
deviceIdList = Arrays.asList(deviceIdArray);
|
||||
}
|
||||
|
||||
return deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试向上级/设备发送模拟报警通知
|
||||
*
|
||||
* @param deviceId 报警id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/test/notify/alarm")
|
||||
@Operation(summary = "测试向上级/设备发送模拟报警通知", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号")
|
||||
public void delete(@RequestParam String deviceId) {
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
ParentPlatform platform = storage.queryParentPlatByServerGBId(deviceId);
|
||||
DeviceAlarm deviceAlarm = new DeviceAlarm();
|
||||
deviceAlarm.setChannelId(deviceId);
|
||||
deviceAlarm.setAlarmDescription("test");
|
||||
deviceAlarm.setAlarmMethod("1");
|
||||
deviceAlarm.setAlarmPriority("1");
|
||||
deviceAlarm.setAlarmTime(DateUtil.getNow());
|
||||
deviceAlarm.setAlarmType("1");
|
||||
deviceAlarm.setLongitude(115.33333);
|
||||
deviceAlarm.setLatitude(39.33333);
|
||||
|
||||
if (device != null && platform == null) {
|
||||
|
||||
try {
|
||||
commander.sendAlarmMessage(device, deviceAlarm);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
|
||||
}
|
||||
}else if (device == null && platform != null){
|
||||
try {
|
||||
commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
log.error("[命令发送失败] 国标级联 发送BYE: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}else {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"无法确定" + deviceId + "是平台还是设备");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询报警
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
* @param page 当前页
|
||||
* @param count 每页查询数量
|
||||
* @param alarmPriority 报警级别
|
||||
* @param alarmMethod 报警方式
|
||||
* @param alarmType 报警类型
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询报警", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "page",description = "当前页",required = true)
|
||||
@Parameter(name = "count",description = "每页查询数量",required = true)
|
||||
@Parameter(name = "deviceId",description = "设备id")
|
||||
@Parameter(name = "alarmPriority",description = "查询内容")
|
||||
@Parameter(name = "alarmMethod",description = "查询内容")
|
||||
@Parameter(name = "alarmType",description = "每页查询数量")
|
||||
@Parameter(name = "startTime",description = "开始时间")
|
||||
@Parameter(name = "endTime",description = "结束时间")
|
||||
@GetMapping("/all")
|
||||
public PageInfo<DeviceAlarm> getAll(
|
||||
@RequestParam int page,
|
||||
@RequestParam int count,
|
||||
@RequestParam(required = false) String deviceId,
|
||||
@RequestParam(required = false) String alarmPriority,
|
||||
@RequestParam(required = false) String alarmMethod,
|
||||
@RequestParam(required = false) String alarmType,
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime
|
||||
) {
|
||||
if (ObjectUtils.isEmpty(alarmPriority)) {
|
||||
alarmPriority = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(alarmMethod)) {
|
||||
alarmMethod = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(alarmType)) {
|
||||
alarmType = null;
|
||||
}
|
||||
|
||||
if (ObjectUtils.isEmpty(startTime)) {
|
||||
startTime = null;
|
||||
}else if (!DateUtil.verification(startTime, DateUtil.formatter) ){
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "startTime格式为" + DateUtil.PATTERN);
|
||||
}
|
||||
|
||||
if (ObjectUtils.isEmpty(endTime)) {
|
||||
endTime = null;
|
||||
}else if (!DateUtil.verification(endTime, DateUtil.formatter) ){
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime格式为" + DateUtil.PATTERN);
|
||||
}
|
||||
|
||||
return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
|
||||
alarmType, startTime, endTime);
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
/**
|
||||
* 设备设置命令API接口
|
||||
*
|
||||
* @author lawrencehj
|
||||
* @date 2021年2月2日
|
||||
*/
|
||||
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.device;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "国标设备配置")
|
||||
@RestController
|
||||
@RequestMapping("/api/device/config")
|
||||
public class DeviceConfig {
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
/**
|
||||
* 看守位控制命令API接口
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @param name 名称
|
||||
* @param expiration 到期时间
|
||||
* @param heartBeatInterval 心跳间隔
|
||||
* @param heartBeatCount 心跳计数
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/basicParam/{deviceId}")
|
||||
@Operation(summary = "基本配置设置命令", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "name", description = "名称")
|
||||
@Parameter(name = "expiration", description = "到期时间")
|
||||
@Parameter(name = "heartBeatInterval", description = "心跳间隔")
|
||||
@Parameter(name = "heartBeatCount", description = "心跳计数")
|
||||
public DeferredResult<String> homePositionApi(@PathVariable String deviceId,
|
||||
String channelId,
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) String expiration,
|
||||
@RequestParam(required = false) String heartBeatInterval,
|
||||
@RequestParam(required = false) String heartBeatCount) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("报警复位API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId;
|
||||
try {
|
||||
cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 设备配置: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<String> result = new DeferredResult<String>(3 * 1000L);
|
||||
result.onTimeout(() -> {
|
||||
log.warn(String.format("设备配置操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", deviceId);
|
||||
json.put("Status", "Timeout");
|
||||
json.put("Description", "设备配置操作超时, 设备未返回应答指令");
|
||||
msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(key, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备配置查询请求API接口
|
||||
* @param deviceId 设备ID
|
||||
* @param configType 配置类型
|
||||
* @param channelId 通道ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "设备配置查询请求", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "configType", description = "配置类型")
|
||||
@GetMapping("/query/{deviceId}/{configType}")
|
||||
public DeferredResult<String> configDownloadApi(@PathVariable String deviceId,
|
||||
@PathVariable String configType,
|
||||
@RequestParam(required = false) String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备状态查询API调用");
|
||||
}
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
try {
|
||||
cmder.deviceConfigQuery(device, channelId, configType, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取设备配置: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<String> result = new DeferredResult<String > (3 * 1000L);
|
||||
result.onTimeout(()->{
|
||||
log.warn(String.format("获取设备配置超时"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout. Device did not response to this command.");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(key, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
/**
|
||||
* 设备控制命令API接口
|
||||
*
|
||||
* @author lawrencehj
|
||||
* @date 2021年2月1日
|
||||
*/
|
||||
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.device;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Tag(name = "国标设备控制")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/device/control")
|
||||
public class DeviceControl {
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
/**
|
||||
* 远程启动控制命令API接口
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
@Operation(summary = "远程启动控制命令", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/teleboot/{deviceId}")
|
||||
public void teleBootApi(@PathVariable String deviceId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备远程启动API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
try {
|
||||
cmder.teleBootCmd(device);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 远程启动: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 录像控制命令API接口
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param recordCmdStr Record:手动录像,StopRecord:停止手动录像
|
||||
* @param channelId 通道编码(可选)
|
||||
*/
|
||||
@Operation(summary = "录像控制", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "recordCmdStr", description = "命令, 可选值:Record(手动录像),StopRecord(停止手动录像)", required = true)
|
||||
@GetMapping("/record/{deviceId}/{recordCmdStr}")
|
||||
public DeferredResult<ResponseEntity<String>> recordApi(@PathVariable String deviceId,
|
||||
@PathVariable String recordCmdStr, String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("开始/停止录像API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId;
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
|
||||
result.onTimeout(() -> {
|
||||
log.warn(String.format("开始/停止录像操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setKey(key);
|
||||
msg.setId(uuid);
|
||||
msg.setData("Timeout. Device did not response to this command.");
|
||||
resultHolder.invokeAllResult(msg);
|
||||
});
|
||||
if (resultHolder.exist(key, null)){
|
||||
return result;
|
||||
}
|
||||
resultHolder.put(key, uuid, result);
|
||||
try {
|
||||
cmder.recordCmd(device, channelId, recordCmdStr, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeAllResult(msg);
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 开始/停止录像: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 报警布防/撤防命令API接口
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param guardCmdStr SetGuard:布防,ResetGuard:撤防
|
||||
*/
|
||||
@Operation(summary = "布防/撤防命令", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "guardCmdStr", description = "命令, 可选值:SetGuard(布防),ResetGuard(撤防)", required = true)
|
||||
@GetMapping("/guard/{deviceId}/{guardCmdStr}")
|
||||
public DeferredResult<String> guardApi(@PathVariable String deviceId, @PathVariable String guardCmdStr) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("布防/撤防API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + deviceId;
|
||||
String uuid =UUID.randomUUID().toString();
|
||||
try {
|
||||
cmder.guardCmd(device, guardCmdStr, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 布防/撤防操作: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
|
||||
resultHolder.put(key, uuid, result);
|
||||
result.onTimeout(() -> {
|
||||
log.warn(String.format("布防/撤防操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setKey(key);
|
||||
msg.setId(uuid);
|
||||
msg.setData("Timeout. Device did not response to this command.");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 报警复位API接口
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param alarmMethod 报警方式(可选)
|
||||
* @param alarmType 报警类型(可选)
|
||||
*/
|
||||
@Operation(summary = "报警复位", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "alarmMethod", description = "报警方式")
|
||||
@Parameter(name = "alarmType", description = "报警类型")
|
||||
@GetMapping("/reset_alarm/{deviceId}")
|
||||
public DeferredResult<ResponseEntity<String>> resetAlarmApi(@PathVariable String deviceId, String channelId,
|
||||
@RequestParam(required = false) String alarmMethod,
|
||||
@RequestParam(required = false) String alarmType) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("报警复位API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId;
|
||||
try {
|
||||
cmder.alarmCmd(device, alarmMethod, alarmType, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("报警复位操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 报警复位: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
|
||||
result.onTimeout(() -> {
|
||||
log.warn(String.format("报警复位操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout. Device did not response to this command.");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(key, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制关键帧API接口
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
*/
|
||||
@Operation(summary = "强制关键帧", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号")
|
||||
@GetMapping("/i_frame/{deviceId}")
|
||||
public JSONObject iFrame(@PathVariable String deviceId,
|
||||
@RequestParam(required = false) String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("强制关键帧API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
try {
|
||||
cmder.iFrameCmd(device, channelId);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 强制关键帧: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", deviceId);
|
||||
json.put("ChannelID", channelId);
|
||||
json.put("Result", "OK");
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 看守位控制命令API接口
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param enabled 看守位使能1:开启,0:关闭
|
||||
* @param resetTime 自动归位时间间隔(可选)
|
||||
* @param presetIndex 调用预置位编号(可选)
|
||||
* @param channelId 通道编码(可选)
|
||||
*/
|
||||
@Operation(summary = "看守位控制", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "enabled", description = "是否开启看守位", required = true)
|
||||
@Parameter(name = "presetIndex", description = "调用预置位编号")
|
||||
@Parameter(name = "resetTime", description = "自动归位时间间隔 单位:秒")
|
||||
@GetMapping("/home_position")
|
||||
public DeferredResult<String> homePositionApi(String deviceId, String channelId, Boolean enabled,
|
||||
@RequestParam(required = false) Integer resetTime,
|
||||
@RequestParam(required = false) Integer presetIndex) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("报警复位API调用");
|
||||
}
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
try {
|
||||
cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 看守位控制: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
|
||||
result.onTimeout(() -> {
|
||||
log.warn(String.format("看守位控制操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", deviceId);
|
||||
json.put("Status", "Timeout");
|
||||
json.put("Description", "看守位控制操作超时, 设备未返回应答指令");
|
||||
msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(key, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉框放大
|
||||
* @param deviceId 设备id
|
||||
* @param channelId 通道id
|
||||
* @param length 播放窗口长度像素值
|
||||
* @param width 播放窗口宽度像素值
|
||||
* @param midpointx 拉框中心的横轴坐标像素值
|
||||
* @param midpointy 拉框中心的纵轴坐标像素值
|
||||
* @param lengthx 拉框长度像素值
|
||||
* @param lengthy 拉框宽度像素值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "拉框放大", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "length", description = "播放窗口长度像素值", required = true)
|
||||
@Parameter(name = "midpointx", description = "拉框中心的横轴坐标像素值", required = true)
|
||||
@Parameter(name = "midpointy", description = "拉框中心的纵轴坐标像素值", required = true)
|
||||
@Parameter(name = "lengthx", description = "拉框长度像素值", required = true)
|
||||
@Parameter(name = "lengthy", description = "lengthy", required = true)
|
||||
@GetMapping("drag_zoom/zoom_in")
|
||||
public void dragZoomIn(@RequestParam String deviceId,
|
||||
@RequestParam(required = false) String channelId,
|
||||
@RequestParam int length,
|
||||
@RequestParam int width,
|
||||
@RequestParam int midpointx,
|
||||
@RequestParam int midpointy,
|
||||
@RequestParam int lengthx,
|
||||
@RequestParam int lengthy) throws RuntimeException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("设备拉框放大 API调用,deviceId:%s ,channelId:%s ,length:%d ,width:%d ,midpointx:%d ,midpointy:%d ,lengthx:%d ,lengthy:%d",deviceId, channelId, length, width, midpointx, midpointy,lengthx, lengthy));
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<DragZoomIn>\r\n");
|
||||
cmdXml.append("<Length>" + length+ "</Length>\r\n");
|
||||
cmdXml.append("<Width>" + width+ "</Width>\r\n");
|
||||
cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n");
|
||||
cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n");
|
||||
cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n");
|
||||
cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n");
|
||||
cmdXml.append("</DragZoomIn>\r\n");
|
||||
try {
|
||||
cmder.dragZoomCmd(device, channelId, cmdXml.toString());
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 拉框放大: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉框缩小
|
||||
* @param deviceId 设备id
|
||||
* @param channelId 通道id
|
||||
* @param length 播放窗口长度像素值
|
||||
* @param width 播放窗口宽度像素值
|
||||
* @param midpointx 拉框中心的横轴坐标像素值
|
||||
* @param midpointy 拉框中心的纵轴坐标像素值
|
||||
* @param lengthx 拉框长度像素值
|
||||
* @param lengthy 拉框宽度像素值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "拉框缩小", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号")
|
||||
@Parameter(name = "length", description = "播放窗口长度像素值", required = true)
|
||||
@Parameter(name = "width", description = "拉框中心的横轴坐标像素值", required = true)
|
||||
@Parameter(name = "midpointx", description = "拉框中心的横轴坐标像素值", required = true)
|
||||
@Parameter(name = "midpointy", description = "拉框中心的纵轴坐标像素值", required = true)
|
||||
@Parameter(name = "lengthx", description = "拉框长度像素值", required = true)
|
||||
@Parameter(name = "lengthy", description = "拉框宽度像素值", required = true)
|
||||
@GetMapping("/drag_zoom/zoom_out")
|
||||
public void dragZoomOut(@RequestParam String deviceId,
|
||||
@RequestParam(required = false) String channelId,
|
||||
@RequestParam int length,
|
||||
@RequestParam int width,
|
||||
@RequestParam int midpointx,
|
||||
@RequestParam int midpointy,
|
||||
@RequestParam int lengthx,
|
||||
@RequestParam int lengthy){
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("设备拉框缩小 API调用,deviceId:%s ,channelId:%s ,length:%d ,width:%d ,midpointx:%d ,midpointy:%d ,lengthx:%d ,lengthy:%d",deviceId, channelId, length, width, midpointx, midpointy,lengthx, lengthy));
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<DragZoomOut>\r\n");
|
||||
cmdXml.append("<Length>" + length+ "</Length>\r\n");
|
||||
cmdXml.append("<Width>" + width+ "</Width>\r\n");
|
||||
cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n");
|
||||
cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n");
|
||||
cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n");
|
||||
cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n");
|
||||
cmdXml.append("</DragZoomOut>\r\n");
|
||||
try {
|
||||
cmder.dragZoomCmd(device, channelId, cmdXml.toString());
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 拉框缩小: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,497 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.device;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
|
||||
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Tag(name = "国标设备查询", description = "国标设备查询")
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/device/query")
|
||||
public class DeviceQuery {
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IDeviceChannelService deviceChannelService;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
/**
|
||||
* 使用ID查询国标设备
|
||||
* @param deviceId 国标ID
|
||||
* @return 国标设备
|
||||
*/
|
||||
@Operation(summary = "查询国标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/devices/{deviceId}")
|
||||
public Device devices(@PathVariable String deviceId){
|
||||
|
||||
return deviceService.getDevice(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询国标设备
|
||||
* @param page 当前页
|
||||
* @param count 每页查询数量
|
||||
* @return 分页国标列表
|
||||
*/
|
||||
@Operation(summary = "分页查询国标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
||||
@Parameter(name = "query", description = "搜索", required = false)
|
||||
@Parameter(name = "status", description = "状态", required = false)
|
||||
@GetMapping("/devices")
|
||||
@Options()
|
||||
public PageInfo<Device> devices(int page, int count, String query, Boolean status){
|
||||
if (ObjectUtils.isEmpty(query)){
|
||||
query = null;
|
||||
}
|
||||
return deviceService.getAll(page, count, query, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询通道数
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
* @param page 当前页
|
||||
* @param count 每页条数
|
||||
* @param query 查询内容
|
||||
* @param online 是否在线 在线 true / 离线 false
|
||||
* @param channelType 设备 false/子目录 true
|
||||
* @param catalogUnderDevice 是否直属与设备的目录
|
||||
* @return 通道列表
|
||||
*/
|
||||
@GetMapping("/devices/{deviceId}/channels")
|
||||
@Operation(summary = "分页查询通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
||||
@Parameter(name = "query", description = "查询内容")
|
||||
@Parameter(name = "online", description = "是否在线")
|
||||
@Parameter(name = "channelType", description = "设备/子目录-> false/true")
|
||||
public PageInfo<DeviceChannel> channels(@PathVariable String deviceId,
|
||||
int page, int count,
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) Boolean online,
|
||||
@RequestParam(required = false) Boolean channelType) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
|
||||
return deviceChannelService.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步设备通道
|
||||
* @param deviceId 设备id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "同步设备通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/devices/{deviceId}/sync")
|
||||
public WVPResult<SyncStatus> devicesSync(@PathVariable String deviceId){
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备通道信息同步API调用,deviceId:" + deviceId);
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
boolean status = deviceService.isSyncRunning(deviceId);
|
||||
// 已存在则返回进度
|
||||
if (status) {
|
||||
SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
|
||||
return WVPResult.success(channelSyncStatus);
|
||||
}
|
||||
deviceService.sync(device);
|
||||
|
||||
WVPResult<SyncStatus> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("开始同步");
|
||||
return wvpResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除设备
|
||||
* @param deviceId 设备id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "移除设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@DeleteMapping("/devices/{deviceId}/delete")
|
||||
public String delete(@PathVariable String deviceId){
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备信息删除API调用,deviceId:" + deviceId);
|
||||
}
|
||||
|
||||
// 清除redis记录
|
||||
boolean isSuccess = deviceService.delete(deviceId);
|
||||
if (isSuccess) {
|
||||
inviteStreamService.clearInviteInfo(deviceId);
|
||||
// 停止此设备的订阅更新
|
||||
Set<String> allKeys = dynamicTask.getAllKeys();
|
||||
for (String key : allKeys) {
|
||||
if (key.startsWith(deviceId)) {
|
||||
Runnable runnable = dynamicTask.get(key);
|
||||
if (runnable instanceof ISubscribeTask) {
|
||||
ISubscribeTask subscribeTask = (ISubscribeTask) runnable;
|
||||
subscribeTask.stop(null);
|
||||
}
|
||||
dynamicTask.stop(key);
|
||||
}
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
return json.toString();
|
||||
} else {
|
||||
log.warn("设备信息删除API调用失败!");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备信息删除API调用失败!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询子目录通道
|
||||
* @param deviceId 通道id
|
||||
* @param channelId 通道id
|
||||
* @param page 当前页
|
||||
* @param count 每页条数
|
||||
* @param query 查询内容
|
||||
* @param online 是否在线
|
||||
* @param channelType 通道类型
|
||||
* @return 子通道列表
|
||||
*/
|
||||
@Operation(summary = "分页查询子目录通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页查询数量", required = true)
|
||||
@Parameter(name = "query", description = "查询内容")
|
||||
@Parameter(name = "online", description = "是否在线")
|
||||
@Parameter(name = "channelType", description = "设备/子目录-> false/true")
|
||||
@GetMapping("/sub_channels/{deviceId}/{channelId}/channels")
|
||||
public PageInfo<DeviceChannel> subChannels(@PathVariable String deviceId,
|
||||
@PathVariable String channelId,
|
||||
int page,
|
||||
int count,
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) Boolean online,
|
||||
@RequestParam(required = false) Boolean channelType){
|
||||
|
||||
DeviceChannel deviceChannel = deviceChannelService.getOne(deviceId,channelId);
|
||||
if (deviceChannel == null) {
|
||||
PageInfo<DeviceChannel> deviceChannelPageResult = new PageInfo<>();
|
||||
return deviceChannelPageResult;
|
||||
}
|
||||
|
||||
return deviceChannelService.getSubChannels(deviceChannel.getDeviceDbId(), channelId, query, channelType, online, page, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新通道信息
|
||||
* @param deviceId 设备id
|
||||
* @param channel 通道
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新通道信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channel", description = "通道信息", required = true)
|
||||
@PostMapping("/channel/update/{deviceId}")
|
||||
public void updateChannel(@PathVariable String deviceId,DeviceChannel channel){
|
||||
deviceChannelService.updateChannel(deviceId, channel);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改通道的码流类型", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channel", description = "通道信息", required = true)
|
||||
@PostMapping("/channel/stream/identification/update/")
|
||||
public void updateChannelStreamIdentification(DeviceChannel channel){
|
||||
deviceChannelService.updateChannelStreamIdentification(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据流传输模式
|
||||
* @param deviceId 设备id
|
||||
* @param streamMode 数据流传输模式
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改数据流传输模式", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "streamMode", description = "数据流传输模式, 取值:" +
|
||||
"UDP(udp传输),TCP-ACTIVE(tcp主动模式,暂不支持),TCP-PASSIVE(tcp被动模式)", required = true)
|
||||
@PostMapping("/transport/{deviceId}/{streamMode}")
|
||||
public void updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
device.setStreamMode(streamMode);
|
||||
deviceService.updateCustomDevice(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备信息
|
||||
* @param device 设备信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加设备信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "device", description = "设备", required = true)
|
||||
@PostMapping("/device/add/")
|
||||
public void addDevice(Device device){
|
||||
|
||||
if (device == null || device.getDeviceId() == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
|
||||
// 查看deviceId是否存在
|
||||
boolean exist = deviceService.isExist(device.getDeviceId());
|
||||
if (exist) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备编号已存在");
|
||||
}
|
||||
deviceService.addDevice(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备信息
|
||||
* @param device 设备信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新设备信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "device", description = "设备", required = true)
|
||||
@PostMapping("/device/update/")
|
||||
public void updateDevice(Device device){
|
||||
|
||||
if (device != null && device.getDeviceId() != null) {
|
||||
if (device.getSubscribeCycleForMobilePosition() > 0 && device.getMobilePositionSubmissionInterval() <= 0) {
|
||||
device.setMobilePositionSubmissionInterval(5);
|
||||
}
|
||||
deviceService.updateCustomDevice(device);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备状态查询请求API接口
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
*/
|
||||
@Operation(summary = "设备状态查询", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/devices/{deviceId}/status")
|
||||
public DeferredResult<ResponseEntity<String>> deviceStatusApi(@PathVariable String deviceId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备状态查询API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId;
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L);
|
||||
if(device == null) {
|
||||
result.setResult(new ResponseEntity(String.format("设备%s不存在", deviceId),HttpStatus.OK));
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
cmder.deviceStatusQuery(device, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取设备状态: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
result.onTimeout(()->{
|
||||
log.warn(String.format("获取设备状态超时"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout. Device did not response to this command.");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备报警查询请求API接口
|
||||
* @param deviceId 设备id
|
||||
* @param startPriority 报警起始级别(可选)
|
||||
* @param endPriority 报警终止级别(可选)
|
||||
* @param alarmMethod 报警方式条件(可选)
|
||||
* @param alarmType 报警类型
|
||||
* @param startTime 报警发生起始时间(可选)
|
||||
* @param endTime 报警发生终止时间(可选)
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
@Operation(summary = "设备报警查询", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "startPriority", description = "报警起始级别")
|
||||
@Parameter(name = "endPriority", description = "报警终止级别")
|
||||
@Parameter(name = "alarmMethod", description = "报警方式条件")
|
||||
@Parameter(name = "alarmType", description = "报警类型")
|
||||
@Parameter(name = "startTime", description = "报警发生起始时间")
|
||||
@Parameter(name = "endTime", description = "报警发生终止时间")
|
||||
@GetMapping("/alarm/{deviceId}")
|
||||
public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId,
|
||||
@RequestParam(required = false) String startPriority,
|
||||
@RequestParam(required = false) String endPriority,
|
||||
@RequestParam(required = false) String alarmMethod,
|
||||
@RequestParam(required = false) String alarmType,
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备报警查询API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId;
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
try {
|
||||
cmder.alarmInfoQuery(device, startPriority, endPriority, alarmMethod, alarmType, startTime, endTime, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("设备报警查询失败,错误码: %s, %s",event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 设备报警查询: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L);
|
||||
result.onTimeout(()->{
|
||||
log.warn(String.format("设备报警查询超时"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("设备报警查询超时");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{deviceId}/sync_status")
|
||||
@Operation(summary = "获取通道同步进度", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
public WVPResult<SyncStatus> getSyncStatus(@PathVariable String deviceId) {
|
||||
SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
|
||||
WVPResult<SyncStatus> wvpResult = new WVPResult<>();
|
||||
if (channelSyncStatus == null) {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("同步尚未开始");
|
||||
}else {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
wvpResult.setData(channelSyncStatus);
|
||||
if (channelSyncStatus.getErrorMsg() != null) {
|
||||
wvpResult.setMsg(channelSyncStatus.getErrorMsg());
|
||||
}
|
||||
}
|
||||
return wvpResult;
|
||||
}
|
||||
|
||||
@GetMapping("/{deviceId}/subscribe_info")
|
||||
@Operation(summary = "获取设备的订阅状态", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
public WVPResult<Map<String, Integer>> getSubscribeInfo(@PathVariable String deviceId) {
|
||||
Set<String> allKeys = dynamicTask.getAllKeys();
|
||||
Map<String, Integer> dialogStateMap = new HashMap<>();
|
||||
for (String key : allKeys) {
|
||||
if (key.startsWith(deviceId)) {
|
||||
ISubscribeTask subscribeTask = (ISubscribeTask)dynamicTask.get(key);
|
||||
if (subscribeTask instanceof CatalogSubscribeTask) {
|
||||
dialogStateMap.put("catalog", 1);
|
||||
}else if (subscribeTask instanceof MobilePositionSubscribeTask) {
|
||||
dialogStateMap.put("mobilePosition", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
WVPResult<Map<String, Integer>> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setData(dialogStateMap);
|
||||
return wvpResult;
|
||||
}
|
||||
|
||||
@GetMapping("/snap/{deviceId}/{channelId}")
|
||||
@Operation(summary = "请求截图")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "mark", description = "标识", required = false)
|
||||
public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId, @RequestParam(required = false) String mark) {
|
||||
|
||||
try {
|
||||
final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + (mark == null? ".jpg": ("_" + mark + ".jpg"))).toPath());
|
||||
resp.setContentType(MediaType.IMAGE_PNG_VALUE);
|
||||
ServletOutputStream outputStream = resp.getOutputStream();
|
||||
IOUtils.copy(in, resp.getOutputStream());
|
||||
in.close();
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.media;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
|
||||
import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.streamProxy.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
@Tag(name = "媒体流相关")
|
||||
@Controller
|
||||
@Slf4j
|
||||
@RequestMapping(value = "/api/media")
|
||||
public class MediaController {
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private IStreamProxyService streamProxyService;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
|
||||
/**
|
||||
* 根据应用名和流id获取播放地址
|
||||
* @param app 应用名
|
||||
* @param stream 流id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "根据应用名和流id获取播放地址", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "app", description = "应用名", required = true)
|
||||
@Parameter(name = "stream", description = "流id", required = true)
|
||||
@Parameter(name = "mediaServerId", description = "媒体服务器id")
|
||||
@Parameter(name = "callId", description = "推流时携带的自定义鉴权ID")
|
||||
@Parameter(name = "useSourceIpAsStreamIp", description = "是否使用请求IP作为返回的地址IP")
|
||||
@GetMapping(value = "/stream_info_by_app_and_stream")
|
||||
@ResponseBody
|
||||
public StreamContent getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
|
||||
@RequestParam String stream,
|
||||
@RequestParam(required = false) String mediaServerId,
|
||||
@RequestParam(required = false) String callId,
|
||||
@RequestParam(required = false) Boolean useSourceIpAsStreamIp){
|
||||
boolean authority = false;
|
||||
if (callId != null) {
|
||||
// 权限校验
|
||||
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
|
||||
if (streamAuthorityInfo != null
|
||||
&& streamAuthorityInfo.getCallId() != null
|
||||
&& streamAuthorityInfo.getCallId().equals(callId)) {
|
||||
authority = true;
|
||||
}else {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "获取播放地址鉴权失败");
|
||||
}
|
||||
}else {
|
||||
// 是否登陆用户, 登陆用户返回完整信息
|
||||
LoginUser userInfo = SecurityUtils.getUserInfo();
|
||||
if (userInfo!= null) {
|
||||
authority = true;
|
||||
}
|
||||
}
|
||||
|
||||
StreamInfo streamInfo;
|
||||
|
||||
if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) {
|
||||
String host = request.getHeader("Host");
|
||||
String localAddr = host.split(":")[0];
|
||||
log.info("使用{}作为返回流的ip", localAddr);
|
||||
streamInfo = mediaServerService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, localAddr, authority);
|
||||
}else {
|
||||
streamInfo = mediaServerService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
|
||||
}
|
||||
|
||||
if (streamInfo != null){
|
||||
return new StreamContent(streamInfo);
|
||||
}else {
|
||||
//获取流失败,重启拉流后重试一次
|
||||
streamProxyService.stop(app,stream);
|
||||
boolean start = streamProxyService.start(app, stream);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("[线程休眠失败], {}", e.getMessage());
|
||||
}
|
||||
if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) {
|
||||
String host = request.getHeader("Host");
|
||||
String localAddr = host.split(":")[0];
|
||||
log.info("使用{}作为返回流的ip", localAddr);
|
||||
streamInfo = mediaServerService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, localAddr, authority);
|
||||
}else {
|
||||
streamInfo = mediaServerService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
|
||||
}
|
||||
if (streamInfo != null){
|
||||
return new StreamContent(streamInfo);
|
||||
}else {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,550 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.platform;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IPlatformChannelService;
|
||||
import com.genersoft.iot.vmp.service.IPlatformService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.UpdateChannelParam;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 级联平台管理
|
||||
*/
|
||||
@Tag(name = "级联平台管理")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/platform")
|
||||
public class PlatformController {
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IPlatformChannelService platformChannelService;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private SubscribeHolder subscribeHolder;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform commanderForPlatform;
|
||||
|
||||
@Autowired
|
||||
private SipConfig sipConfig;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Autowired
|
||||
private IPlatformService platformService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceChannelService deviceChannelService;
|
||||
|
||||
/**
|
||||
* 获取国标服务的配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取国标服务的配置", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@GetMapping("/server_config")
|
||||
public JSONObject serverConfig() {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("deviceIp", sipConfig.getShowIp());
|
||||
result.put("devicePort", sipConfig.getPort());
|
||||
result.put("username", sipConfig.getId());
|
||||
result.put("password", sipConfig.getPassword());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取级联服务器信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取级联服务器信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "id", description = "平台国标编号", required = true)
|
||||
@GetMapping("/info/{id}")
|
||||
public ParentPlatform getPlatform(@PathVariable String id) {
|
||||
ParentPlatform parentPlatform = platformService.queryPlatformByServerGBId(id);
|
||||
if (parentPlatform != null) {
|
||||
return parentPlatform;
|
||||
} else {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未查询到此平台");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询级联平台
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param count 每页条数
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/query/{count}/{page}")
|
||||
@Operation(summary = "分页查询级联平台", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页条数", required = true)
|
||||
public PageInfo<ParentPlatform> platforms(@PathVariable int page, @PathVariable int count) {
|
||||
|
||||
PageInfo<ParentPlatform> parentPlatformPageInfo = platformService.queryParentPlatformList(page, count);
|
||||
if (parentPlatformPageInfo.getList().size() > 0) {
|
||||
for (ParentPlatform platform : parentPlatformPageInfo.getList()) {
|
||||
platform.setMobilePositionSubscribe(subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()) != null);
|
||||
platform.setCatalogSubscribe(subscribeHolder.getCatalogSubscribe(platform.getServerGBId()) != null);
|
||||
}
|
||||
}
|
||||
return parentPlatformPageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加上级平台信息
|
||||
*
|
||||
* @param parentPlatform
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加上级平台信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public void addPlatform(@RequestBody ParentPlatform parentPlatform) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("保存上级平台信息API调用");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(parentPlatform.getName())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerGBId())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerIP())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerPort())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getDeviceGBId())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getExpires())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getKeepTimeout())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getTransport())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getCharacterSet())
|
||||
) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
if (parentPlatform.getServerPort() < 0 || parentPlatform.getServerPort() > 65535) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "error severPort");
|
||||
}
|
||||
|
||||
|
||||
ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
|
||||
if (parentPlatformOld != null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台 " + parentPlatform.getServerGBId() + " 已存在");
|
||||
}
|
||||
parentPlatform.setCreateTime(DateUtil.getNow());
|
||||
parentPlatform.setUpdateTime(DateUtil.getNow());
|
||||
boolean updateResult = platformService.add(parentPlatform);
|
||||
|
||||
if (!updateResult) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存上级平台信息
|
||||
*
|
||||
* @param parentPlatform
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "保存上级平台信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public void savePlatform(@RequestBody ParentPlatform parentPlatform) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("保存上级平台信息API调用");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(parentPlatform.getName())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerGBId())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerIP())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getServerPort())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getDeviceGBId())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getExpires())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getKeepTimeout())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getTransport())
|
||||
|| ObjectUtils.isEmpty(parentPlatform.getCharacterSet())
|
||||
) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
|
||||
platformService.update(parentPlatform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除上级平台
|
||||
*
|
||||
* @param serverGBId 上级平台国标ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除上级平台", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "serverGBId", description = "上级平台的国标编号")
|
||||
@DeleteMapping("/delete/{serverGBId}")
|
||||
@ResponseBody
|
||||
public void deletePlatform(@PathVariable String serverGBId) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("删除上级平台API调用");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(serverGBId)
|
||||
) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
|
||||
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(serverGBId);
|
||||
if (parentPlatform == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
|
||||
}
|
||||
if (parentPlatformCatch == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
|
||||
}
|
||||
parentPlatform.setEnable(false);
|
||||
storager.updateParentPlatform(parentPlatform);
|
||||
// 发送离线消息,无论是否成功都删除缓存
|
||||
try {
|
||||
commanderForPlatform.unregister(parentPlatform, parentPlatformCatch.getSipTransactionInfo(), (event -> {
|
||||
// 清空redis缓存
|
||||
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
|
||||
redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
|
||||
redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
|
||||
}), (event -> {
|
||||
// 清空redis缓存
|
||||
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
|
||||
redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
|
||||
redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
|
||||
}));
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
log.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
|
||||
}
|
||||
|
||||
boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
|
||||
storager.delCatalogByPlatformId(parentPlatform.getServerGBId());
|
||||
storager.delRelationByPlatformId(parentPlatform.getServerGBId());
|
||||
// 停止发送位置订阅定时任务
|
||||
String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() + "_MobilePosition_" + parentPlatform.getServerGBId();
|
||||
dynamicTask.stop(key);
|
||||
// 删除缓存的订阅信息
|
||||
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
|
||||
if (!deleteResult) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询上级平台是否存在
|
||||
*
|
||||
* @param serverGBId 上级平台国标ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询上级平台是否存在", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "serverGBId", description = "上级平台的国标编号")
|
||||
@GetMapping("/exit/{serverGBId}")
|
||||
@ResponseBody
|
||||
public Boolean exitPlatform(@PathVariable String serverGBId) {
|
||||
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
|
||||
return parentPlatform != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询级联平台的所有所有通道
|
||||
*
|
||||
* @param page 当前页
|
||||
* @param count 每页条数
|
||||
* @param platformId 上级平台ID
|
||||
* @param query 查询内容
|
||||
* @param online 是否在线
|
||||
* @param channelType 通道类型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询上级平台是否存在", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@Parameter(name = "count", description = "每页条数", required = true)
|
||||
@Parameter(name = "platformId", description = "上级平台的国标编号")
|
||||
@Parameter(name = "catalogId", description = "目录ID")
|
||||
@Parameter(name = "query", description = "查询内容")
|
||||
@Parameter(name = "online", description = "是否在线")
|
||||
@Parameter(name = "channelType", description = "通道类型")
|
||||
@GetMapping("/channel_list")
|
||||
@ResponseBody
|
||||
public PageInfo<ChannelReduce> channelList(int page, int count,
|
||||
@RequestParam(required = false) String platformId,
|
||||
@RequestParam(required = false) String catalogId,
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) Boolean online,
|
||||
@RequestParam(required = false) Boolean channelType) {
|
||||
|
||||
if (ObjectUtils.isEmpty(platformId)) {
|
||||
platformId = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(platformId) || ObjectUtils.isEmpty(catalogId)) {
|
||||
catalogId = null;
|
||||
}
|
||||
PageInfo<ChannelReduce> channelReduces = deviceChannelService.queryAllChannelList(page, count, query, online, channelType, platformId, catalogId);
|
||||
|
||||
return channelReduces;
|
||||
}
|
||||
|
||||
/**
|
||||
* 向上级平台添加国标通道
|
||||
*
|
||||
* @param param 通道关联参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "向上级平台添加国标通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@PostMapping("/update_channel_for_gb")
|
||||
@ResponseBody
|
||||
public void updateChannelForGB(@RequestBody UpdateChannelParam param) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("给上级平台添加国标通道API调用");
|
||||
}
|
||||
int result = 0;
|
||||
if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) {
|
||||
if (param.isAll()) {
|
||||
log.info("[国标级联]添加所有通道到上级平台, {}", param.getPlatformId());
|
||||
List<ChannelReduce> allChannelForDevice = deviceChannelService.queryAllChannelList(param.getPlatformId());
|
||||
result = platformChannelService.updateChannelForGB(param.getPlatformId(), allChannelForDevice, param.getCatalogId());
|
||||
}
|
||||
}else {
|
||||
result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
|
||||
}
|
||||
if (result <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从上级平台移除国标通道
|
||||
*
|
||||
* @param param 通道关联参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "从上级平台移除国标通道", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@DeleteMapping("/del_channel_for_gb")
|
||||
@ResponseBody
|
||||
public void delChannelForGB(@RequestBody UpdateChannelParam param) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("给上级平台删除国标通道API调用");
|
||||
}
|
||||
int result = 0;
|
||||
if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) {
|
||||
if (param.isAll()) {
|
||||
log.info("[国标级联]移除所有通道,上级平台, {}", param.getPlatformId());
|
||||
result = platformChannelService.delAllChannelForGB(param.getPlatformId(), param.getCatalogId());
|
||||
}
|
||||
}else {
|
||||
result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
|
||||
}
|
||||
if (result <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取目录
|
||||
*
|
||||
* @param platformId 平台ID
|
||||
* @param parentId 目录父ID
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取目录", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "platformId", description = "上级平台的国标编号", required = true)
|
||||
@Parameter(name = "parentId", description = "父级目录的国标编号", required = true)
|
||||
@GetMapping("/catalog")
|
||||
@ResponseBody
|
||||
public List<PlatformCatalog> getCatalogByPlatform(String platformId, String parentId) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("查询目录,platformId: {}, parentId: {}", platformId, parentId);
|
||||
}
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
if (platform == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台未找到");
|
||||
}
|
||||
// if (platformId.equals(parentId)) {
|
||||
// parentId = platform.getDeviceGBId();
|
||||
// }
|
||||
|
||||
if (platformId.equals(platform.getDeviceGBId())) {
|
||||
parentId = null;
|
||||
}
|
||||
|
||||
return storager.getChildrenCatalogByPlatform(platformId, parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加目录
|
||||
*
|
||||
* @param platformCatalog 目录
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加目录", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@PostMapping("/catalog/add")
|
||||
@ResponseBody
|
||||
public void addCatalog(@RequestBody PlatformCatalog platformCatalog) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("添加目录,{}", JSON.toJSONString(platformCatalog));
|
||||
}
|
||||
PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getPlatformId(), platformCatalog.getId());
|
||||
|
||||
if (platformCatalogInStore != null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), platformCatalog.getId() + " already exists");
|
||||
}
|
||||
int addResult = storager.addCatalog(platformCatalog);
|
||||
if (addResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑目录
|
||||
*
|
||||
* @param platformCatalog 目录
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "编辑目录", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@PostMapping("/catalog/edit")
|
||||
@ResponseBody
|
||||
public void editCatalog(@RequestBody PlatformCatalog platformCatalog) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("编辑目录,{}", JSON.toJSONString(platformCatalog));
|
||||
}
|
||||
PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getPlatformId(), platformCatalog.getId());
|
||||
|
||||
if (platformCatalogInStore == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), platformCatalog.getId() + " not exists");
|
||||
}
|
||||
int addResult = storager.updateCatalog(platformCatalog);
|
||||
if (addResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除目录
|
||||
*
|
||||
* @param id 目录Id
|
||||
* @param platformId 平台Id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除目录", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "id", description = "目录Id", required = true)
|
||||
@Parameter(name = "platformId", description = "平台Id", required = true)
|
||||
@DeleteMapping("/catalog/del")
|
||||
@ResponseBody
|
||||
public void delCatalog(String id, String platformId) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("删除目录,{}", id);
|
||||
}
|
||||
|
||||
if (ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(platformId)) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
|
||||
int delResult = storager.delCatalog(platformId, id);
|
||||
// 如果删除的是默认目录则根目录设置为默认目录
|
||||
PlatformCatalog parentPlatform = storager.queryDefaultCatalogInPlatform(platformId);
|
||||
|
||||
// 默认节点被移除
|
||||
if (parentPlatform == null) {
|
||||
storager.setDefaultCatalog(platformId, platformId);
|
||||
}
|
||||
|
||||
if (delResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除关联
|
||||
*
|
||||
* @param platformCatalog 关联的信息
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除关联", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@DeleteMapping("/catalog/relation/del")
|
||||
@ResponseBody
|
||||
public void delRelation(@RequestBody PlatformCatalog platformCatalog) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("删除关联,{}", JSON.toJSONString(platformCatalog));
|
||||
}
|
||||
int delResult = storager.delRelation(platformCatalog);
|
||||
|
||||
if (delResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改默认目录
|
||||
*
|
||||
* @param platformId 平台Id
|
||||
* @param catalogId 目录Id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改默认目录", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "catalogId", description = "目录Id", required = true)
|
||||
@Parameter(name = "platformId", description = "平台Id", required = true)
|
||||
@PostMapping("/catalog/default/update")
|
||||
@ResponseBody
|
||||
public void setDefaultCatalog(String platformId, String catalogId) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("修改默认目录,{},{}", platformId, catalogId);
|
||||
}
|
||||
int updateResult = storager.setDefaultCatalog(platformId, catalogId);
|
||||
|
||||
if (updateResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.platform.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 精简的channel信息展示,主要是选择通道的时候展示列表使用
|
||||
*/
|
||||
@Schema(description = "精简的channel信息展示")
|
||||
public class ChannelReduce {
|
||||
|
||||
/**
|
||||
* deviceChannel的数据库自增ID
|
||||
*/
|
||||
@Schema(description = "deviceChannel的数据库自增ID")
|
||||
private int id;
|
||||
|
||||
/**
|
||||
* 通道id
|
||||
*/
|
||||
@Schema(description = "通道国标编号")
|
||||
private String channelId;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
@Schema(description = "设备国标编号")
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 通道名
|
||||
*/
|
||||
@Schema(description = "通道名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 生产厂商
|
||||
*/
|
||||
@Schema(description = "生产厂商")
|
||||
private String manufacturer;
|
||||
|
||||
/**
|
||||
* wan地址
|
||||
*/
|
||||
@Schema(description = "wan地址")
|
||||
private String hostAddress;
|
||||
|
||||
/**
|
||||
* 子节点数
|
||||
*/
|
||||
@Schema(description = "子节点数")
|
||||
private int subCount;
|
||||
|
||||
/**
|
||||
* 平台Id
|
||||
*/
|
||||
@Schema(description = "平台上级国标编号")
|
||||
private String platformId;
|
||||
|
||||
/**
|
||||
* 目录Id
|
||||
*/
|
||||
@Schema(description = "目录国标编号")
|
||||
private String catalogId;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
public void setChannelId(String channelId) {
|
||||
this.channelId = channelId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getManufacturer() {
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
public void setManufacturer(String manufacturer) {
|
||||
this.manufacturer = manufacturer;
|
||||
}
|
||||
|
||||
public String getHostAddress() {
|
||||
return hostAddress;
|
||||
}
|
||||
|
||||
public void setHostAddress(String hostAddress) {
|
||||
this.hostAddress = hostAddress;
|
||||
}
|
||||
|
||||
public int getSubCount() {
|
||||
return subCount;
|
||||
}
|
||||
|
||||
public void setSubCount(int subCount) {
|
||||
this.subCount = subCount;
|
||||
}
|
||||
|
||||
public String getPlatformId() {
|
||||
return platformId;
|
||||
}
|
||||
|
||||
public void setPlatformId(String platformId) {
|
||||
this.platformId = platformId;
|
||||
}
|
||||
|
||||
public String getCatalogId() {
|
||||
return catalogId;
|
||||
}
|
||||
|
||||
public void setCatalogId(String catalogId) {
|
||||
this.catalogId = catalogId;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.platform.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 通道关联参数
|
||||
* @author lin
|
||||
*/
|
||||
@Schema(description = "通道关联参数")
|
||||
public class UpdateChannelParam {
|
||||
|
||||
@Schema(description = "上级平台的国标编号")
|
||||
private String platformId;
|
||||
|
||||
@Schema(description = "目录的国标编号")
|
||||
private String catalogId;
|
||||
|
||||
@Schema(description = "处理所有通道")
|
||||
private boolean all;
|
||||
|
||||
@Schema(description = "")
|
||||
private List<ChannelReduce> channelReduces;
|
||||
|
||||
public String getPlatformId() {
|
||||
return platformId;
|
||||
}
|
||||
|
||||
public void setPlatformId(String platformId) {
|
||||
this.platformId = platformId;
|
||||
}
|
||||
|
||||
public List<ChannelReduce> getChannelReduces() {
|
||||
return channelReduces;
|
||||
}
|
||||
|
||||
public void setChannelReduces(List<ChannelReduce> channelReduces) {
|
||||
this.channelReduces = channelReduces;
|
||||
}
|
||||
|
||||
public String getCatalogId() {
|
||||
return catalogId;
|
||||
}
|
||||
|
||||
public void setCatalogId(String catalogId) {
|
||||
this.catalogId = catalogId;
|
||||
}
|
||||
|
||||
public boolean isAll() {
|
||||
return all;
|
||||
}
|
||||
|
||||
public void setAll(boolean all) {
|
||||
this.all = all;
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.play;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceChannelService;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.AudioBroadcastResult;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Tag(name = "国标设备点播")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/play")
|
||||
public class PlayController {
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager streamSession;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceChannelService deviceChannelService;
|
||||
|
||||
@Operation(summary = "开始点播", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@GetMapping("/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<WVPResult<StreamContent>> play(HttpServletRequest request, @PathVariable String deviceId,
|
||||
@PathVariable String channelId) {
|
||||
|
||||
log.info("[开始点播] deviceId:{}, channelId:{}, ", deviceId, channelId);
|
||||
if (ObjectUtils.isEmpty(deviceId) || ObjectUtils.isEmpty(channelId)) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
// 获取可用的zlm
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
MediaServer newMediaServerItem = playService.getNewMediaServerItem(device);
|
||||
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
|
||||
requestMessage.setKey(key);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
requestMessage.setId(uuid);
|
||||
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
|
||||
result.onTimeout(()->{
|
||||
log.info("[点播等待超时] deviceId:{}, channelId:{}, ", deviceId, channelId);
|
||||
// 释放rtpserver
|
||||
WVPResult<StreamInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("点播超时");
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeAllResult(requestMessage);
|
||||
inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
|
||||
deviceChannelService.stopPlay(deviceId, channelId);
|
||||
});
|
||||
|
||||
// 录像查询以channelId作为deviceId查询
|
||||
resultHolder.put(key, uuid, result);
|
||||
|
||||
playService.play(newMediaServerItem, deviceId, channelId, null, (code, msg, data) -> {
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
|
||||
if (data != null) {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
streamInfo=streamInfo.clone();//深拷贝
|
||||
String host;
|
||||
try {
|
||||
URL url=new URL(request.getRequestURL().toString());
|
||||
host=url.getHost();
|
||||
} catch (MalformedURLException e) {
|
||||
host=request.getLocalAddr();
|
||||
}
|
||||
streamInfo.channgeStreamIp(host);
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(newMediaServerItem.getTranscodeSuffix()) && !"null".equalsIgnoreCase(newMediaServerItem.getTranscodeSuffix())) {
|
||||
streamInfo.setStream(streamInfo.getStream() + "_" + newMediaServerItem.getTranscodeSuffix());
|
||||
}
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
requestMessage.setData(wvpResult);
|
||||
// 此处必须释放所有请求
|
||||
resultHolder.invokeAllResult(requestMessage);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "停止点播", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@GetMapping("/stop/{deviceId}/{channelId}")
|
||||
public JSONObject playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
|
||||
log.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId ));
|
||||
|
||||
if (deviceId == null || channelId == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备[" + deviceId + "]不存在");
|
||||
}
|
||||
|
||||
playService.stopPlay(device, channelId);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
json.put("channelId", channelId);
|
||||
return json;
|
||||
}
|
||||
/**
|
||||
* 结束转码
|
||||
*/
|
||||
@Operation(summary = "结束转码", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "key", description = "视频流key", required = true)
|
||||
@Parameter(name = "mediaServerId", description = "流媒体服务ID", required = true)
|
||||
@PostMapping("/convertStop/{key}")
|
||||
public void playConvertStop(@PathVariable String key, String mediaServerId) {
|
||||
if (mediaServerId == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "流媒体:" + mediaServerId + "不存在" );
|
||||
}
|
||||
MediaServer mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaInfo == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "使用的流媒体已经停止运行" );
|
||||
}else {
|
||||
Boolean deleted = mediaServerService.delFFmpegSource(mediaInfo, key);
|
||||
if (!deleted) {
|
||||
throw new ControllerException(ErrorCode.ERROR100 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "语音广播命令", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "deviceId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "timeout", description = "推流超时时间(秒)", required = true)
|
||||
@GetMapping("/broadcast/{deviceId}/{channelId}")
|
||||
@PostMapping("/broadcast/{deviceId}/{channelId}")
|
||||
public AudioBroadcastResult broadcastApi(@PathVariable String deviceId, @PathVariable String channelId, Integer timeout, Boolean broadcastMode) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("语音广播API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到设备: " + deviceId);
|
||||
}
|
||||
if (channelId == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "未找到通道: " + channelId);
|
||||
}
|
||||
|
||||
return playService.audioBroadcast(device, channelId, broadcastMode);
|
||||
|
||||
}
|
||||
|
||||
@Operation(summary = "停止语音广播")
|
||||
@Parameter(name = "deviceId", description = "设备Id", required = true)
|
||||
@Parameter(name = "channelId", description = "通道Id", required = true)
|
||||
@GetMapping("/broadcast/stop/{deviceId}/{channelId}")
|
||||
@PostMapping("/broadcast/stop/{deviceId}/{channelId}")
|
||||
public void stopBroadcast(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("停止语音广播API调用");
|
||||
}
|
||||
// try {
|
||||
// playService.stopAudioBroadcast(deviceId, channelId);
|
||||
// } catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
// logger.error("[命令发送失败] 停止语音: {}", e.getMessage());
|
||||
// throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
// }
|
||||
playService.stopAudioBroadcast(deviceId, channelId);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有的ssrc", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@GetMapping("/ssrc")
|
||||
public JSONObject getSSRC() {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("获取所有的ssrc");
|
||||
}
|
||||
JSONArray objects = new JSONArray();
|
||||
List<SsrcTransaction> allSsrc = streamSession.getAllSsrc();
|
||||
for (SsrcTransaction transaction : allSsrc) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("deviceId", transaction.getDeviceId());
|
||||
jsonObject.put("channelId", transaction.getChannelId());
|
||||
jsonObject.put("ssrc", transaction.getSsrc());
|
||||
jsonObject.put("streamId", transaction.getStream());
|
||||
objects.add(jsonObject);
|
||||
}
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data", objects);
|
||||
jsonObject.put("count", objects.size());
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取截图", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "isSubStream", description = "是否子码流(true-子码流,false-主码流),默认为false", required = true)
|
||||
@GetMapping("/snap")
|
||||
public DeferredResult<String> getSnap(String deviceId, String channelId,boolean isSubStream) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("获取截图: {}/{}", deviceId, channelId);
|
||||
}
|
||||
|
||||
DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_SNAP + deviceId;
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
resultHolder.put(key, uuid, result);
|
||||
|
||||
RequestMessage message = new RequestMessage();
|
||||
message.setKey(key);
|
||||
message.setId(uuid);
|
||||
|
||||
String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + ".jpg";
|
||||
playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
message.setData(data);
|
||||
}else {
|
||||
message.setData(WVPResult.fail(code, msg));
|
||||
}
|
||||
resultHolder.invokeResult(message);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.play.bean;
|
||||
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
public interface AudioBroadcastEvent {
|
||||
void call(String msg);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.play.bean;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
public class PlayResult {
|
||||
|
||||
private DeferredResult<WVPResult<StreamInfo>> result;
|
||||
private String uuid;
|
||||
|
||||
private Device device;
|
||||
|
||||
public DeferredResult<WVPResult<StreamInfo>> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(DeferredResult<WVPResult<StreamInfo>> result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(Device device) {
|
||||
this.device = device;
|
||||
}
|
||||
}
|
||||
@@ -1,229 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.playback;
|
||||
|
||||
import com.genersoft.iot.vmp.common.InviteInfo;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.exception.ServiceException;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author lin
|
||||
*/
|
||||
@Tag(name = "视频回放")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/playback")
|
||||
public class PlaybackController {
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Operation(summary = "开始视频回放", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@GetMapping("/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<WVPResult<StreamContent>> start(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
}
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId;
|
||||
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
resultHolder.put(key, uuid, result);
|
||||
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
requestMessage.setKey(key);
|
||||
requestMessage.setId(uuid);
|
||||
|
||||
playService.playBack(deviceId, channelId, startTime, endTime,
|
||||
(code, msg, data)->{
|
||||
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
|
||||
if (data != null) {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
streamInfo=streamInfo.clone();//深拷贝
|
||||
String host;
|
||||
try {
|
||||
URL url=new URL(request.getRequestURL().toString());
|
||||
host=url.getHost();
|
||||
} catch (MalformedURLException e) {
|
||||
host=request.getLocalAddr();
|
||||
}
|
||||
streamInfo.channgeStreamIp(host);
|
||||
}
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
}
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeResult(requestMessage);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "停止视频回放", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "stream", description = "流ID", required = true)
|
||||
@GetMapping("/stop/{deviceId}/{channelId}/{stream}")
|
||||
public void playStop(
|
||||
@PathVariable String deviceId,
|
||||
@PathVariable String channelId,
|
||||
@PathVariable String stream) {
|
||||
if (ObjectUtils.isEmpty(deviceId) || ObjectUtils.isEmpty(channelId) || ObjectUtils.isEmpty(stream)) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + " 未找到");
|
||||
}
|
||||
try {
|
||||
cmder.streamByeCmd(device, channelId, stream, null);
|
||||
} catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "发送bye失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "回放暂停", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@GetMapping("/pause/{streamId}")
|
||||
public void playPause(@PathVariable String streamId) {
|
||||
log.info("playPause: "+streamId);
|
||||
|
||||
try {
|
||||
playService.pauseRtp(streamId);
|
||||
} catch (ServiceException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), e.getMessage());
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "回放恢复", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@GetMapping("/resume/{streamId}")
|
||||
public void playResume(@PathVariable String streamId) {
|
||||
log.info("playResume: "+streamId);
|
||||
try {
|
||||
playService.resumeRtp(streamId);
|
||||
} catch (ServiceException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), e.getMessage());
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "回放拖动播放", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@Parameter(name = "seekTime", description = "拖动偏移量,单位s", required = true)
|
||||
@GetMapping("/seek/{streamId}/{seekTime}")
|
||||
public void playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
|
||||
log.info("playSeek: "+streamId+", "+seekTime);
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
|
||||
|
||||
if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
|
||||
log.warn("streamId不存在!");
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
Device device = deviceService.getDevice(inviteInfo.getDeviceId());
|
||||
try {
|
||||
cmder.playSeekCmd(device, inviteInfo.getStreamInfo(), seekTime);
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "回放倍速播放", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@Parameter(name = "speed", description = "倍速0.25 0.5 1、2、4", required = true)
|
||||
@GetMapping("/speed/{streamId}/{speed}")
|
||||
public void playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
|
||||
log.info("playSpeed: "+streamId+", "+speed);
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, streamId);
|
||||
|
||||
if (null == inviteInfo || inviteInfo.getStreamInfo() == null) {
|
||||
log.warn("streamId不存在!");
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
if(speed != 0.25 && speed != 0.5 && speed != 1 && speed != 2.0 && speed != 4.0) {
|
||||
log.warn("不支持的speed: " + speed);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "不支持的speed(0.25 0.5 1、2、4)");
|
||||
}
|
||||
Device device = deviceService.getDevice(inviteInfo.getDeviceId());
|
||||
try {
|
||||
cmder.playSpeedCmd(device, inviteInfo.getStreamInfo(), speed);
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.ptz;
|
||||
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Tag(name = "云台控制")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/ptz")
|
||||
public class PtzController {
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
/***
|
||||
* 云台控制
|
||||
* @param deviceId 设备id
|
||||
* @param channelId 通道id
|
||||
* @param command 控制指令
|
||||
* @param horizonSpeed 水平移动速度
|
||||
* @param verticalSpeed 垂直移动速度
|
||||
* @param zoomSpeed 缩放速度
|
||||
*/
|
||||
|
||||
@Operation(summary = "云台控制", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "command", description = "控制指令,允许值: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop", required = true)
|
||||
@Parameter(name = "horizonSpeed", description = "水平速度", required = true)
|
||||
@Parameter(name = "verticalSpeed", description = "垂直速度", required = true)
|
||||
@Parameter(name = "zoomSpeed", description = "缩放速度", required = true)
|
||||
@PostMapping("/control/{deviceId}/{channelId}")
|
||||
public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,command:%s ,horizonSpeed:%d ,verticalSpeed:%d ,zoomSpeed:%d",deviceId, channelId, command, horizonSpeed, verticalSpeed, zoomSpeed));
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
int cmdCode = 0;
|
||||
switch (command){
|
||||
case "left":
|
||||
cmdCode = 2;
|
||||
break;
|
||||
case "right":
|
||||
cmdCode = 1;
|
||||
break;
|
||||
case "up":
|
||||
cmdCode = 8;
|
||||
break;
|
||||
case "down":
|
||||
cmdCode = 4;
|
||||
break;
|
||||
case "upleft":
|
||||
cmdCode = 10;
|
||||
break;
|
||||
case "upright":
|
||||
cmdCode = 9;
|
||||
break;
|
||||
case "downleft":
|
||||
cmdCode = 6;
|
||||
break;
|
||||
case "downright":
|
||||
cmdCode = 5;
|
||||
break;
|
||||
case "zoomin":
|
||||
cmdCode = 16;
|
||||
break;
|
||||
case "zoomout":
|
||||
cmdCode = 32;
|
||||
break;
|
||||
case "stop":
|
||||
horizonSpeed = 0;
|
||||
verticalSpeed = 0;
|
||||
zoomSpeed = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
try {
|
||||
cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
log.error("[命令发送失败] 云台控制: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "通用前端控制命令", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "cmdCode", description = "指令码", required = true)
|
||||
@Parameter(name = "parameter1", description = "数据一", required = true)
|
||||
@Parameter(name = "parameter2", description = "数据二", required = true)
|
||||
@Parameter(name = "combindCode2", description = "组合码二", required = true)
|
||||
@PostMapping("/front_end_command/{deviceId}/{channelId}")
|
||||
public void frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,cmdCode:%d parameter1:%d parameter2:%d",deviceId, channelId, cmdCode, parameter1, parameter2));
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
|
||||
try {
|
||||
cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
log.error("[命令发送失败] 前端控制: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "预置位查询", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@GetMapping("/preset/query/{deviceId}/{channelId}")
|
||||
public DeferredResult<String> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备预置位查询API调用");
|
||||
}
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
DeferredResult<String> result = new DeferredResult<String> (3 * 1000L);
|
||||
result.onTimeout(()->{
|
||||
log.warn(String.format("获取设备预置位超时"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("获取设备预置位超时");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
if (resultHolder.exist(key, null)) {
|
||||
return result;
|
||||
}
|
||||
resultHolder.put(key, uuid, result);
|
||||
try {
|
||||
cmder.presetQuery(device, channelId, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取设备预置位: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.record;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.SipException;
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
|
||||
@Tag(name = "国标录像")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/gb_record")
|
||||
public class GBRecordController {
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Operation(summary = "录像查询", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@GetMapping("/query/{deviceId}/{channelId}")
|
||||
public DeferredResult<WVPResult<RecordInfo>> recordinfo(@PathVariable String deviceId, @PathVariable String channelId, String startTime, String endTime){
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("录像信息查询 API调用,deviceId:%s ,startTime:%s, endTime:%s",deviceId, startTime, endTime));
|
||||
}
|
||||
DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>();
|
||||
if (!DateUtil.verification(startTime, DateUtil.formatter)){
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime格式为" + DateUtil.PATTERN);
|
||||
}
|
||||
if (!DateUtil.verification(endTime, DateUtil.formatter)){
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime格式为" + DateUtil.PATTERN);
|
||||
}
|
||||
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
// 指定超时时间 1分钟30秒
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
int sn = (int)((Math.random()*9+1)*100000);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + deviceId + sn;
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
try {
|
||||
cmder.recordInfoQuery(device, channelId, startTime, endTime, sn, null, null, null, (eventResult -> {
|
||||
WVPResult<RecordInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("查询录像失败, status: " + eventResult.statusCode + ", message: " + eventResult.msg);
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
}));
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 查询录像: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 录像查询以channelId作为deviceId查询
|
||||
resultHolder.put(key, uuid, result);
|
||||
result.onTimeout(()->{
|
||||
msg.setData("timeout");
|
||||
WVPResult<RecordInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("timeout");
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "开始历史媒体下载", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@Parameter(name = "downloadSpeed", description = "下载倍速", required = true)
|
||||
@GetMapping("/download/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<WVPResult<StreamContent>> download(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime, String downloadSpeed) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed));
|
||||
}
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
|
||||
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(30000L);
|
||||
resultHolder.put(key, uuid, result);
|
||||
RequestMessage requestMessage = new RequestMessage();
|
||||
requestMessage.setId(uuid);
|
||||
requestMessage.setKey(key);
|
||||
|
||||
|
||||
playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed),
|
||||
(code, msg, data)->{
|
||||
|
||||
WVPResult<StreamContent> wvpResult = new WVPResult<>();
|
||||
if (code == InviteErrorCode.SUCCESS.getCode()) {
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
|
||||
if (data != null) {
|
||||
StreamInfo streamInfo = (StreamInfo)data;
|
||||
if (userSetting.getUseSourceIpAsStreamIp()) {
|
||||
streamInfo.channgeStreamIp(request.getLocalAddr());
|
||||
}
|
||||
wvpResult.setData(new StreamContent(streamInfo));
|
||||
}
|
||||
}else {
|
||||
wvpResult.setCode(code);
|
||||
wvpResult.setMsg(msg);
|
||||
}
|
||||
requestMessage.setData(wvpResult);
|
||||
resultHolder.invokeResult(requestMessage);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "停止历史媒体下载", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "stream", description = "流ID", required = true)
|
||||
@GetMapping("/download/stop/{deviceId}/{channelId}/{stream}")
|
||||
public void playStop(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(String.format("设备历史媒体下载停止 API调用,deviceId/channelId:%s_%s", deviceId, channelId));
|
||||
}
|
||||
|
||||
if (deviceId == null || channelId == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
|
||||
Device device = deviceService.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "未找到");
|
||||
}
|
||||
|
||||
try {
|
||||
cmder.streamByeCmd(device, channelId, stream, null);
|
||||
} catch (InvalidArgumentException | ParseException | SipException | SsrcTransactionNotFoundException e) {
|
||||
log.error("[停止历史媒体下载]停止历史媒体下载,发送BYE失败 {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取历史媒体下载进度", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "stream", description = "流ID", required = true)
|
||||
@GetMapping("/download/progress/{deviceId}/{channelId}/{stream}")
|
||||
public StreamContent getProgress(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
StreamInfo downLoadInfo = playService.getDownLoadInfo(deviceId, channelId, stream);
|
||||
if (downLoadInfo == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR404);
|
||||
}
|
||||
return new StreamContent(downLoadInfo);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.sse;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEventListener;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
|
||||
/**
|
||||
* SSE 推送.
|
||||
*
|
||||
* @author lawrencehj
|
||||
* @author <a href="mailto:xiaoQQya@126.com">xiaoQQya</a>
|
||||
* @since 2021/01/20
|
||||
*/
|
||||
@Tag(name = "SSE 推送")
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class SseController {
|
||||
|
||||
@Resource
|
||||
private AlarmEventListener alarmEventListener;
|
||||
|
||||
/**
|
||||
* SSE 推送.
|
||||
*
|
||||
* @param response 响应
|
||||
* @param browserId 浏览器ID
|
||||
* @throws IOException IOEXCEPTION
|
||||
* @author <a href="mailto:xiaoQQya@126.com">xiaoQQya</a>
|
||||
* @since 2023/11/06
|
||||
*/
|
||||
@GetMapping("/emit")
|
||||
public void emit(HttpServletResponse response, @RequestParam String browserId) throws IOException, InterruptedException {
|
||||
response.setContentType("text/event-stream");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
PrintWriter writer = response.getWriter();
|
||||
alarmEventListener.addSseEmitter(browserId, writer);
|
||||
|
||||
while (!writer.checkError()) {
|
||||
Thread.sleep(1000);
|
||||
writer.write(":keep alive\n\n");
|
||||
writer.flush();
|
||||
}
|
||||
alarmEventListener.removeSseEmitter(browserId, writer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user