支持全局异常和统一返回结果,未完待续
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.genersoft.iot.vmp.vmanager.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 全局错误码
|
||||
*/
|
||||
public enum ErrorCode {
|
||||
SUCCESS(0, "成功"),
|
||||
ERROR100(100, "失败"),
|
||||
ERROR400(400, "参数不全或者错误"),
|
||||
ERROR403(403, "无权限操作"),
|
||||
ERROR401(401, "请登录后重新请求"),
|
||||
ERROR500(500, "系统异常");
|
||||
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
ErrorCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.session;
|
||||
package com.genersoft.iot.vmp.vmanager.bean;
|
||||
|
||||
public enum PlayTypeEnum {
|
||||
|
||||
@@ -23,23 +23,21 @@ public class WVPResult<T> {
|
||||
@Schema(description = "数据")
|
||||
private T data;
|
||||
|
||||
private static final Integer SUCCESS = 200;
|
||||
private static final Integer FAILED = 400;
|
||||
|
||||
public static <T> WVPResult<T> Data(T t, String msg) {
|
||||
return new WVPResult<>(SUCCESS, msg, t);
|
||||
public static <T> WVPResult<T> success(T t, String msg) {
|
||||
return new WVPResult<>(ErrorCode.SUCCESS.getCode(), msg, t);
|
||||
}
|
||||
|
||||
public static <T> WVPResult<T> Data(T t) {
|
||||
return Data(t, "成功");
|
||||
public static <T> WVPResult<T> success(T t) {
|
||||
return success(t, ErrorCode.SUCCESS.getMsg());
|
||||
}
|
||||
|
||||
public static <T> WVPResult<T> fail(int code, String msg) {
|
||||
return new WVPResult<>(code, msg, null);
|
||||
}
|
||||
|
||||
public static <T> WVPResult<T> fail(String msg) {
|
||||
return fail(FAILED, msg);
|
||||
public static <T> WVPResult<T> fail(ErrorCode errorCode) {
|
||||
return fail(errorCode.getCode(), errorCode.getMsg());
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class MobilePositionController {
|
||||
@Parameter(name = "start", description = "开始时间")
|
||||
@Parameter(name = "end", description = "结束时间")
|
||||
@GetMapping("/history/{deviceId}")
|
||||
public ResponseEntity<WVPResult<List<MobilePosition>>> positions(@PathVariable String deviceId,
|
||||
public List<MobilePosition> positions(@PathVariable String deviceId,
|
||||
@RequestParam(required = false) String channelId,
|
||||
@RequestParam(required = false) String start,
|
||||
@RequestParam(required = false) String end) {
|
||||
@@ -76,11 +76,7 @@ public class MobilePositionController {
|
||||
if (StringUtil.isEmpty(end)) {
|
||||
end = null;
|
||||
}
|
||||
WVPResult<List<MobilePosition>> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
List<MobilePosition> result = storager.queryMobilePositions(deviceId, channelId, start, end);
|
||||
wvpResult.setData(result);
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
return storager.queryMobilePositions(deviceId, channelId, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,9 +87,8 @@ public class MobilePositionController {
|
||||
@Operation(summary = "查询设备最新位置")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/latest/{deviceId}")
|
||||
public ResponseEntity<MobilePosition> latestPosition(@PathVariable String deviceId) {
|
||||
MobilePosition result = storager.queryLatestPosition(deviceId);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
public MobilePosition latestPosition(@PathVariable String deviceId) {
|
||||
return storager.queryLatestPosition(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +99,7 @@ public class MobilePositionController {
|
||||
@Operation(summary = "获取移动位置信息")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/realtime/{deviceId}")
|
||||
public DeferredResult<ResponseEntity<MobilePosition>> realTimePosition(@PathVariable String deviceId) {
|
||||
public DeferredResult<MobilePosition> realTimePosition(@PathVariable String deviceId) {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId;
|
||||
@@ -115,7 +110,7 @@ public class MobilePositionController {
|
||||
msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
DeferredResult<ResponseEntity<MobilePosition>> result = new DeferredResult<ResponseEntity<MobilePosition>>(5*1000L);
|
||||
DeferredResult<MobilePosition> result = new DeferredResult<MobilePosition>(5*1000L);
|
||||
result.onTimeout(()->{
|
||||
logger.warn(String.format("获取移动位置信息超时"));
|
||||
// 释放rtpserver
|
||||
@@ -141,7 +136,7 @@ public class MobilePositionController {
|
||||
@Parameter(name = "expires", description = "订阅超时时间", required = true)
|
||||
@Parameter(name = "interval", description = "上报时间间隔", required = true)
|
||||
@GetMapping("/subscribe/{deviceId}")
|
||||
public ResponseEntity<String> positionSubscribe(@PathVariable String deviceId,
|
||||
public String positionSubscribe(@PathVariable String deviceId,
|
||||
@RequestParam String expires,
|
||||
@RequestParam String interval) {
|
||||
String msg = ((expires.equals("0")) ? "取消" : "") + "订阅设备" + deviceId + "的移动位置";
|
||||
@@ -163,6 +158,6 @@ public class MobilePositionController {
|
||||
result += ",失败";
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
@@ -8,14 +9,17 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
|
||||
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.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.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -55,22 +59,22 @@ public class AlarmController {
|
||||
@Parameter(name = "id", description = "ID")
|
||||
@Parameter(name = "deviceIds", description = "多个设备id,逗号分隔")
|
||||
@Parameter(name = "time", description = "结束时间")
|
||||
public ResponseEntity<WVPResult<String>> delete(
|
||||
public Integer delete(
|
||||
@RequestParam(required = false) Integer id,
|
||||
@RequestParam(required = false) String deviceIds,
|
||||
@RequestParam(required = false) String time
|
||||
) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
if (ObjectUtils.isEmpty(id)) {
|
||||
id = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(deviceIds)) {
|
||||
if (ObjectUtils.isEmpty(deviceIds)) {
|
||||
deviceIds = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(time)) {
|
||||
if (ObjectUtils.isEmpty(time)) {
|
||||
time = null;
|
||||
}
|
||||
if (!DateUtil.verification(time, DateUtil.formatter) ){
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
return null;
|
||||
}
|
||||
List<String> deviceIdList = null;
|
||||
if (deviceIds != null) {
|
||||
@@ -78,12 +82,7 @@ public class AlarmController {
|
||||
deviceIdList = Arrays.asList(deviceIdArray);
|
||||
}
|
||||
|
||||
int count = deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
wvpResult.setData(count);
|
||||
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
|
||||
return deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +94,7 @@ public class AlarmController {
|
||||
@GetMapping("/test/notify/alarm")
|
||||
@Operation(summary = "测试向上级/设备发送模拟报警通知")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号")
|
||||
public ResponseEntity<WVPResult<String>> delete(
|
||||
@RequestParam(required = false) String deviceId
|
||||
) {
|
||||
if (StringUtils.isEmpty(deviceId)) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
public void delete(@RequestParam String deviceId) {
|
||||
Device device = storage.queryVideoDevice(deviceId);
|
||||
ParentPlatform platform = storage.queryParentPlatByServerGBId(deviceId);
|
||||
DeviceAlarm deviceAlarm = new DeviceAlarm();
|
||||
@@ -118,16 +112,9 @@ public class AlarmController {
|
||||
}else if (device == null && platform != null){
|
||||
commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
|
||||
}else {
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("无法确定" + deviceId + "是平台还是设备");
|
||||
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"无法确定" + deviceId + "是平台还是设备");
|
||||
}
|
||||
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +140,7 @@ public class AlarmController {
|
||||
@Parameter(name = "startTime",description = "开始时间")
|
||||
@Parameter(name = "endTime",description = "结束时间")
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<PageInfo<DeviceAlarm>> getAll(
|
||||
public PageInfo<DeviceAlarm> getAll(
|
||||
@RequestParam int page,
|
||||
@RequestParam int count,
|
||||
@RequestParam(required = false) String deviceId,
|
||||
@@ -163,31 +150,28 @@ public class AlarmController {
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime
|
||||
) {
|
||||
if (StringUtils.isEmpty(alarmPriority)) {
|
||||
if (ObjectUtils.isEmpty(alarmPriority)) {
|
||||
alarmPriority = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(alarmMethod)) {
|
||||
if (ObjectUtils.isEmpty(alarmMethod)) {
|
||||
alarmMethod = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(alarmType)) {
|
||||
if (ObjectUtils.isEmpty(alarmType)) {
|
||||
alarmType = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(startTime)) {
|
||||
if (ObjectUtils.isEmpty(startTime)) {
|
||||
startTime = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(endTime)) {
|
||||
if (ObjectUtils.isEmpty(endTime)) {
|
||||
endTime = null;
|
||||
}
|
||||
|
||||
|
||||
if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "开始时间或结束时间格式有误");
|
||||
}
|
||||
|
||||
PageInfo<DeviceAlarm> allAlarm = deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
|
||||
return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
|
||||
alarmType, startTime, endTime);
|
||||
return new ResponseEntity<>(allAlarm, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
@@ -62,7 +63,7 @@ public class DeviceConfig {
|
||||
@Parameter(name = "expiration", description = "到期时间")
|
||||
@Parameter(name = "heartBeatInterval", description = "心跳间隔")
|
||||
@Parameter(name = "heartBeatCount", description = "心跳计数")
|
||||
public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId,
|
||||
public DeferredResult<String> homePositionApi(@PathVariable String deviceId,
|
||||
String channelId,
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) String expiration,
|
||||
@@ -81,7 +82,7 @@ public class DeviceConfig {
|
||||
msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
|
||||
DeferredResult<String> result = new DeferredResult<String>(3 * 1000L);
|
||||
result.onTimeout(() -> {
|
||||
logger.warn(String.format("设备配置操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
@@ -111,13 +112,13 @@ public class DeviceConfig {
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "configType", description = "配置类型")
|
||||
@GetMapping("/query/{deviceId}/{configType}")
|
||||
public DeferredResult<ResponseEntity<String>> configDownloadApi(@PathVariable String deviceId,
|
||||
public DeferredResult<String> configDownloadApi(@PathVariable String deviceId,
|
||||
@PathVariable String configType,
|
||||
@RequestParam(required = false) String channelId) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备状态查询API调用");
|
||||
}
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
cmder.deviceConfigQuery(device, channelId, configType, event -> {
|
||||
@@ -127,7 +128,7 @@ public class DeviceConfig {
|
||||
msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L);
|
||||
DeferredResult<String> result = new DeferredResult<String > (3 * 1000L);
|
||||
result.onTimeout(()->{
|
||||
logger.warn(String.format("获取设备配置超时"));
|
||||
// 释放rtpserver
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.device;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
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.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.tags.Tag;
|
||||
@@ -22,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
@@ -50,14 +53,10 @@ public class DeviceControl {
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
// //@ApiOperation("远程启动控制命令")
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = "deviceId", value ="设备ID", required = true, dataTypeClass = String.class),
|
||||
// })
|
||||
@Operation(summary = "远程启动控制命令")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/teleboot/{deviceId}")
|
||||
public ResponseEntity<String> teleBootApi(@PathVariable String deviceId) {
|
||||
public String teleBootApi(@PathVariable String deviceId) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备远程启动API调用");
|
||||
}
|
||||
@@ -67,10 +66,10 @@ public class DeviceControl {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", deviceId);
|
||||
json.put("Result", "OK");
|
||||
return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK);
|
||||
return json.toJSONString();
|
||||
} else {
|
||||
logger.warn("设备远程启动API调用失败!");
|
||||
return new ResponseEntity<String>("设备远程启动API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备远程启动API调用失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +254,7 @@ public class DeviceControl {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("报警复位API调用");
|
||||
}
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.device;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
|
||||
@@ -17,6 +18,7 @@ import com.genersoft.iot.vmp.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
|
||||
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;
|
||||
@@ -30,6 +32,7 @@ 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.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
@@ -81,10 +84,9 @@ public class DeviceQuery {
|
||||
@Operation(summary = "查询国标设备")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/devices/{deviceId}")
|
||||
public ResponseEntity<Device> devices(@PathVariable String deviceId){
|
||||
public Device devices(@PathVariable String deviceId){
|
||||
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
return new ResponseEntity<>(device,HttpStatus.OK);
|
||||
return storager.queryVideoDevice(deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,18 +125,17 @@ public class DeviceQuery {
|
||||
@Parameter(name = "online", description = "是否在线")
|
||||
@Parameter(name = "channelType", description = "设备/子目录-> false/true")
|
||||
@Parameter(name = "catalogUnderDevice", description = "是否直属与设备的目录")
|
||||
public ResponseEntity<PageInfo> channels(@PathVariable String deviceId,
|
||||
public PageInfo channels(@PathVariable String deviceId,
|
||||
int page, int count,
|
||||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) Boolean online,
|
||||
@RequestParam(required = false) Boolean channelType,
|
||||
@RequestParam(required = false) Boolean catalogUnderDevice) {
|
||||
if (StringUtils.isEmpty(query)) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
|
||||
PageInfo pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, catalogUnderDevice, page, count);
|
||||
return new ResponseEntity<>(pageResult,HttpStatus.OK);
|
||||
return storager.queryChannelsByDeviceId(deviceId, query, channelType, online, catalogUnderDevice, page, count);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,11 +155,8 @@ public class DeviceQuery {
|
||||
boolean status = deviceService.isSyncRunning(deviceId);
|
||||
// 已存在则返回进度
|
||||
if (status) {
|
||||
WVPResult<SyncStatus> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
|
||||
wvpResult.setData(channelSyncStatus);
|
||||
return wvpResult;
|
||||
return WVPResult.success(channelSyncStatus);
|
||||
}
|
||||
deviceService.sync(device);
|
||||
|
||||
@@ -176,7 +174,7 @@ public class DeviceQuery {
|
||||
@Operation(summary = "移除设备")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@DeleteMapping("/devices/{deviceId}/delete")
|
||||
public ResponseEntity<String> delete(@PathVariable String deviceId){
|
||||
public String delete(@PathVariable String deviceId){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备信息删除API调用,deviceId:" + deviceId);
|
||||
@@ -200,10 +198,10 @@ public class DeviceQuery {
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
return new ResponseEntity<>(json.toString(),HttpStatus.OK);
|
||||
return json.toString();
|
||||
} else {
|
||||
logger.warn("设备信息删除API调用失败!");
|
||||
return new ResponseEntity<String>("设备信息删除API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备信息删除API调用失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +400,8 @@ public class DeviceQuery {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("同步尚未开始");
|
||||
}else {
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
wvpResult.setData(channelSyncStatus);
|
||||
if (channelSyncStatus.getErrorMsg() != null) {
|
||||
wvpResult.setMsg(channelSyncStatus.getErrorMsg());
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -51,13 +52,13 @@ public class GbStreamController {
|
||||
@RequestParam(required = false)String catalogId,
|
||||
@RequestParam(required = false)String query,
|
||||
@RequestParam(required = false)String mediaServerId){
|
||||
if (StringUtils.isEmpty(catalogId)) {
|
||||
if (ObjectUtils.isEmpty(catalogId)) {
|
||||
catalogId = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(query)) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(mediaServerId)) {
|
||||
if (ObjectUtils.isEmpty(mediaServerId)) {
|
||||
mediaServerId = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
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.SecurityUtils;
|
||||
import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -51,7 +53,7 @@ public class MediaController {
|
||||
@Parameter(name = "useSourceIpAsStreamIp", description = "是否使用请求IP作为返回的地址IP")
|
||||
@GetMapping(value = "/stream_info_by_app_and_stream")
|
||||
@ResponseBody
|
||||
public WVPResult<StreamInfo> getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
|
||||
public StreamInfo getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
|
||||
@RequestParam String stream,
|
||||
@RequestParam(required = false) String mediaServerId,
|
||||
@RequestParam(required = false) String callId,
|
||||
@@ -63,10 +65,7 @@ public class MediaController {
|
||||
if (streamAuthorityInfo.getCallId().equals(callId)) {
|
||||
authority = true;
|
||||
}else {
|
||||
WVPResult<StreamInfo> result = new WVPResult<>();
|
||||
result.setCode(401);
|
||||
result.setMsg("fail");
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
}else {
|
||||
// 是否登陆用户, 登陆用户返回完整信息
|
||||
@@ -89,9 +88,7 @@ public class MediaController {
|
||||
|
||||
WVPResult<StreamInfo> result = new WVPResult<>();
|
||||
if (streamInfo != null){
|
||||
result.setCode(0);
|
||||
result.setMsg("scccess");
|
||||
result.setData(streamInfo);
|
||||
return streamInfo;
|
||||
}else {
|
||||
//获取流失败,重启拉流后重试一次
|
||||
streamProxyService.stop(app,stream);
|
||||
@@ -110,14 +107,10 @@ public class MediaController {
|
||||
streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
|
||||
}
|
||||
if (streamInfo != null){
|
||||
result.setCode(0);
|
||||
result.setMsg("scccess");
|
||||
result.setData(streamInfo);
|
||||
return streamInfo;
|
||||
}else {
|
||||
result.setCode(-1);
|
||||
result.setMsg("fail");
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
|
||||
@@ -14,6 +15,7 @@ import com.genersoft.iot.vmp.service.IPlatformChannelService;
|
||||
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.bean.WVPResult;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.UpdateChannelParam;
|
||||
@@ -26,6 +28,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
@@ -74,13 +77,13 @@ public class PlatformController {
|
||||
*/
|
||||
@Operation(summary = "获取国标服务的配置")
|
||||
@GetMapping("/server_config")
|
||||
public ResponseEntity<JSONObject> serverConfig() {
|
||||
public JSONObject serverConfig() {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("deviceIp", sipConfig.getIp());
|
||||
result.put("devicePort", sipConfig.getPort());
|
||||
result.put("username", sipConfig.getId());
|
||||
result.put("password", sipConfig.getPassword());
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,18 +94,14 @@ public class PlatformController {
|
||||
@Operation(summary = "获取级联服务器信息")
|
||||
@Parameter(name = "id", description = "平台国标编号", required = true)
|
||||
@GetMapping("/info/{id}")
|
||||
public ResponseEntity<WVPResult<ParentPlatform>> getPlatform(@PathVariable String id) {
|
||||
public ParentPlatform getPlatform(@PathVariable String id) {
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(id);
|
||||
WVPResult<ParentPlatform> wvpResult = new WVPResult<>();
|
||||
if (parentPlatform != null) {
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
wvpResult.setData(parentPlatform);
|
||||
return parentPlatform;
|
||||
} else {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("未查询到此平台");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未查询到此平台");
|
||||
}
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,38 +136,31 @@ public class PlatformController {
|
||||
@Operation(summary = "添加上级平台信息")
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<String>> addPlatform(@RequestBody ParentPlatform parentPlatform) {
|
||||
public String addPlatform(@RequestBody ParentPlatform parentPlatform) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("保存上级平台信息API调用");
|
||||
}
|
||||
WVPResult<String> wvpResult = new WVPResult<>();
|
||||
if (StringUtils.isEmpty(parentPlatform.getName())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerGBId())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerGBDomain())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerIP())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerPort())
|
||||
|| StringUtils.isEmpty(parentPlatform.getDeviceGBId())
|
||||
|| StringUtils.isEmpty(parentPlatform.getExpires())
|
||||
|| StringUtils.isEmpty(parentPlatform.getKeepTimeout())
|
||||
|| StringUtils.isEmpty(parentPlatform.getTransport())
|
||||
|| StringUtils.isEmpty(parentPlatform.getCharacterSet())
|
||||
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())
|
||||
) {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("missing parameters");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
if (parentPlatform.getServerPort() < 0 || parentPlatform.getServerPort() > 65535) {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("error severPort");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "error severPort");
|
||||
}
|
||||
|
||||
ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
|
||||
if (parentPlatformOld != null) {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("平台 " + parentPlatform.getServerGBId() + " 已存在");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台 " + parentPlatform.getServerGBId() + " 已存在");
|
||||
}
|
||||
parentPlatform.setCreateTime(DateUtil.getNow());
|
||||
parentPlatform.setUpdateTime(DateUtil.getNow());
|
||||
@@ -190,13 +182,9 @@ public class PlatformController {
|
||||
} else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 关闭启用时注销
|
||||
commanderForPlatform.unregister(parentPlatform, null, null);
|
||||
}
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
return null;
|
||||
} else {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("写入数据库失败");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,26 +197,23 @@ public class PlatformController {
|
||||
@Operation(summary = "保存上级平台信息")
|
||||
@PostMapping("/save")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<String>> savePlatform(@RequestBody ParentPlatform parentPlatform) {
|
||||
public String savePlatform(@RequestBody ParentPlatform parentPlatform) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("保存上级平台信息API调用");
|
||||
}
|
||||
WVPResult<String> wvpResult = new WVPResult<>();
|
||||
if (StringUtils.isEmpty(parentPlatform.getName())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerGBId())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerGBDomain())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerIP())
|
||||
|| StringUtils.isEmpty(parentPlatform.getServerPort())
|
||||
|| StringUtils.isEmpty(parentPlatform.getDeviceGBId())
|
||||
|| StringUtils.isEmpty(parentPlatform.getExpires())
|
||||
|| StringUtils.isEmpty(parentPlatform.getKeepTimeout())
|
||||
|| StringUtils.isEmpty(parentPlatform.getTransport())
|
||||
|| StringUtils.isEmpty(parentPlatform.getCharacterSet())
|
||||
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())
|
||||
) {
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("missing parameters");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
|
||||
ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
|
||||
@@ -262,13 +247,9 @@ public class PlatformController {
|
||||
// 停止订阅相关的定时任务
|
||||
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
|
||||
}
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
return null;
|
||||
} else {
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("写入数据库失败");
|
||||
return new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,18 +263,18 @@ public class PlatformController {
|
||||
@Parameter(name = "serverGBId", description = "上级平台的国标编号")
|
||||
@DeleteMapping("/delete/{serverGBId}")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> deletePlatform(@PathVariable String serverGBId) {
|
||||
public String deletePlatform(@PathVariable String serverGBId) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("删除上级平台API调用");
|
||||
}
|
||||
if (StringUtils.isEmpty(serverGBId)
|
||||
if (ObjectUtils.isEmpty(serverGBId)
|
||||
) {
|
||||
return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
|
||||
if (parentPlatform == null) {
|
||||
return new ResponseEntity<>("fail", HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
|
||||
}
|
||||
// 发送离线消息,无论是否成功都删除缓存
|
||||
commanderForPlatform.unregister(parentPlatform, (event -> {
|
||||
@@ -317,9 +298,9 @@ public class PlatformController {
|
||||
// 删除缓存的订阅信息
|
||||
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
|
||||
if (deleteResult) {
|
||||
return new ResponseEntity<>("success", HttpStatus.OK);
|
||||
return null;
|
||||
} else {
|
||||
return new ResponseEntity<>("fail", HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,10 +314,10 @@ public class PlatformController {
|
||||
@Parameter(name = "serverGBId", description = "上级平台的国标编号")
|
||||
@GetMapping("/exit/{serverGBId}")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> exitPlatform(@PathVariable String serverGBId) {
|
||||
public Boolean exitPlatform(@PathVariable String serverGBId) {
|
||||
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
|
||||
return new ResponseEntity<>(String.valueOf(parentPlatform != null), HttpStatus.OK);
|
||||
return parentPlatform != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -367,13 +348,13 @@ public class PlatformController {
|
||||
@RequestParam(required = false) Boolean online,
|
||||
@RequestParam(required = false) Boolean channelType) {
|
||||
|
||||
if (StringUtils.isEmpty(platformId)) {
|
||||
if (ObjectUtils.isEmpty(platformId)) {
|
||||
platformId = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(query)) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(platformId) || StringUtils.isEmpty(catalogId)) {
|
||||
if (ObjectUtils.isEmpty(platformId) || ObjectUtils.isEmpty(catalogId)) {
|
||||
catalogId = null;
|
||||
}
|
||||
PageInfo<ChannelReduce> channelReduces = storager.queryAllChannelList(page, count, query, online, channelType, platformId, catalogId);
|
||||
@@ -390,14 +371,15 @@ public class PlatformController {
|
||||
@Operation(summary = "向上级平台添加国标通道")
|
||||
@PostMapping("/update_channel_for_gb")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> updateChannelForGB(@RequestBody UpdateChannelParam param) {
|
||||
public void updateChannelForGB(@RequestBody UpdateChannelParam param) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("给上级平台添加国标通道API调用");
|
||||
}
|
||||
int result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
|
||||
|
||||
return new ResponseEntity<>(String.valueOf(result > 0), HttpStatus.OK);
|
||||
if (result <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,14 +391,16 @@ public class PlatformController {
|
||||
@Operation(summary = "从上级平台移除国标通道")
|
||||
@DeleteMapping("/del_channel_for_gb")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> delChannelForGB(@RequestBody UpdateChannelParam param) {
|
||||
public void delChannelForGB(@RequestBody UpdateChannelParam param) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("给上级平台删除国标通道API调用");
|
||||
}
|
||||
int result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
|
||||
|
||||
return new ResponseEntity<>(String.valueOf(result > 0), HttpStatus.OK);
|
||||
if (result <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,25 +415,20 @@ public class PlatformController {
|
||||
@Parameter(name = "parentId", description = "父级目录的国标编号", required = true)
|
||||
@GetMapping("/catalog")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<List<PlatformCatalog>>> getCatalogByPlatform(String platformId, String parentId) {
|
||||
public List<PlatformCatalog> getCatalogByPlatform(String platformId, String parentId) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("查询目录,platformId: {}, parentId: {}", platformId, parentId);
|
||||
}
|
||||
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
||||
if (platform == null) {
|
||||
return new ResponseEntity<>(new WVPResult<>(400, "平台未找到", null), HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台未找到");
|
||||
}
|
||||
if (platformId.equals(parentId)) {
|
||||
parentId = platform.getDeviceGBId();
|
||||
}
|
||||
List<PlatformCatalog> platformCatalogList = storager.getChildrenCatalogByPlatform(platformId, parentId);
|
||||
|
||||
WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(platformCatalogList);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
return storager.getChildrenCatalogByPlatform(platformId, parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,28 +440,19 @@ public class PlatformController {
|
||||
@Operation(summary = "添加目录")
|
||||
@PostMapping("/catalog/add")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<List<PlatformCatalog>>> addCatalog(@RequestBody PlatformCatalog platformCatalog) {
|
||||
public void addCatalog(@RequestBody PlatformCatalog platformCatalog) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("添加目录,{}", JSON.toJSONString(platformCatalog));
|
||||
}
|
||||
PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getId());
|
||||
WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
|
||||
|
||||
if (platformCatalogInStore != null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg(platformCatalog.getId() + " already exists");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), platformCatalog.getId() + " already exists");
|
||||
}
|
||||
int addResult = storager.addCatalog(platformCatalog);
|
||||
if (addResult > 0) {
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
} else {
|
||||
result.setCode(-500);
|
||||
result.setMsg("save error");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (addResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,26 +465,19 @@ public class PlatformController {
|
||||
@Operation(summary = "编辑目录")
|
||||
@PostMapping("/catalog/edit")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<List<PlatformCatalog>>> editCatalog(@RequestBody PlatformCatalog platformCatalog) {
|
||||
public void editCatalog(@RequestBody PlatformCatalog platformCatalog) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("编辑目录,{}", JSON.toJSONString(platformCatalog));
|
||||
}
|
||||
PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getId());
|
||||
WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
|
||||
if (platformCatalogInStore == null) {
|
||||
result.setMsg(platformCatalog.getId() + " not exists");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), platformCatalog.getId() + " not exists");
|
||||
}
|
||||
int addResult = storager.updateCatalog(platformCatalog);
|
||||
if (addResult > 0) {
|
||||
result.setMsg("success");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
} else {
|
||||
result.setMsg("save error");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (addResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,19 +493,15 @@ public class PlatformController {
|
||||
@Parameter(name = "platformId", description = "平台Id", required = true)
|
||||
@DeleteMapping("/catalog/del")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<String>> delCatalog(String id, String platformId) {
|
||||
public void delCatalog(String id, String platformId) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("删除目录,{}", id);
|
||||
}
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
|
||||
if (StringUtils.isEmpty(id) || StringUtils.isEmpty(platformId)) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("param error");
|
||||
return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST);
|
||||
if (ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(platformId)) {
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
result.setCode(0);
|
||||
|
||||
int delResult = storager.delCatalog(id);
|
||||
// 如果删除的是默认目录则根目录设置为默认目录
|
||||
@@ -551,16 +510,10 @@ public class PlatformController {
|
||||
// 默认节点被移除
|
||||
if (parentPlatform == null) {
|
||||
storager.setDefaultCatalog(platformId, platformId);
|
||||
result.setData(platformId);
|
||||
}
|
||||
|
||||
|
||||
if (delResult > 0) {
|
||||
result.setMsg("success");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
} else {
|
||||
result.setMsg("save error");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (delResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,21 +526,15 @@ public class PlatformController {
|
||||
@Operation(summary = "删除关联")
|
||||
@DeleteMapping("/catalog/relation/del")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<List<PlatformCatalog>>> delRelation(@RequestBody PlatformCatalog platformCatalog) {
|
||||
public void delRelation(@RequestBody PlatformCatalog platformCatalog) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("删除关联,{}", JSON.toJSONString(platformCatalog));
|
||||
}
|
||||
int delResult = storager.delRelation(platformCatalog);
|
||||
WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
|
||||
if (delResult > 0) {
|
||||
result.setMsg("success");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
} else {
|
||||
result.setMsg("save error");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (delResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,21 +551,15 @@ public class PlatformController {
|
||||
@Parameter(name = "platformId", description = "平台Id", required = true)
|
||||
@PostMapping("/catalog/default/update")
|
||||
@ResponseBody
|
||||
public ResponseEntity<WVPResult<String>> setDefaultCatalog(String platformId, String catalogId) {
|
||||
public void setDefaultCatalog(String platformId, String catalogId) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("修改默认目录,{},{}", platformId, catalogId);
|
||||
}
|
||||
int updateResult = storager.setDefaultCatalog(platformId, catalogId);
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
|
||||
if (updateResult > 0) {
|
||||
result.setMsg("success");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
} else {
|
||||
result.setMsg("save error");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (updateResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.play;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
@@ -11,6 +12,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
@@ -78,7 +80,7 @@ public class PlayController {
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@GetMapping("/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId,
|
||||
public DeferredResult<String> play(@PathVariable String deviceId,
|
||||
@PathVariable String channelId) {
|
||||
|
||||
// 获取可用的zlm
|
||||
@@ -94,12 +96,12 @@ public class PlayController {
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@GetMapping("/stop/{deviceId}/{channelId}")
|
||||
public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
public DeferredResult<String> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
|
||||
logger.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId ));
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>();
|
||||
DeferredResult<String> result = new DeferredResult<>();
|
||||
|
||||
// 录像查询以channelId作为deviceId查询
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId;
|
||||
@@ -164,40 +166,40 @@ public class PlayController {
|
||||
@Operation(summary = "将不是h264的视频通过ffmpeg 转码为h264 + aac")
|
||||
@Parameter(name = "streamId", description = "视频流ID", required = true)
|
||||
@PostMapping("/convert/{streamId}")
|
||||
public ResponseEntity<String> playConvert(@PathVariable String streamId) {
|
||||
public JSONObject playConvert(@PathVariable String streamId) {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
if (streamInfo == null) {
|
||||
streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
}
|
||||
if (streamInfo == null) {
|
||||
logger.warn("视频转码API调用失败!, 视频流已经停止!");
|
||||
return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到视频流信息, 视频流可能已经停止");
|
||||
}
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(streamInfo.getMediaServerId());
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
|
||||
if (!rtpInfo.getBoolean("exist")) {
|
||||
logger.warn("视频转码API调用失败!, 视频流已停止推流!");
|
||||
return new ResponseEntity<String>("推流信息在流媒体中不存在, 视频流可能已停止推流", HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到视频流信息, 视频流可能已停止推流");
|
||||
} else {
|
||||
String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(),
|
||||
streamId );
|
||||
String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(mediaInfo, srcUrl, dstUrl, "1000000", true, false, null);
|
||||
logger.info(jsonObject.toJSONString());
|
||||
JSONObject result = new JSONObject();
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
result.put("code", 0);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (data != null) {
|
||||
result.put("key", data.getString("key"));
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("key", data.getString("key"));
|
||||
StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStreamWithCheck("convert", streamId, mediaInfo.getId(), false);
|
||||
result.put("data", streamInfoResult);
|
||||
result.put("StreamInfo", streamInfoResult);
|
||||
return result;
|
||||
}else {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "转码失败");
|
||||
}
|
||||
}else {
|
||||
result.put("code", 1);
|
||||
result.put("msg", "cover fail");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "转码失败");
|
||||
}
|
||||
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,53 +212,40 @@ public class PlayController {
|
||||
@Parameter(name = "key", description = "视频流key", required = true)
|
||||
@Parameter(name = "mediaServerId", description = "流媒体服务ID", required = true)
|
||||
@PostMapping("/convertStop/{key}")
|
||||
public ResponseEntity<String> playConvertStop(@PathVariable String key, String mediaServerId) {
|
||||
JSONObject result = new JSONObject();
|
||||
public void playConvertStop(@PathVariable String key, String mediaServerId) {
|
||||
if (mediaServerId == null) {
|
||||
result.put("code", 400);
|
||||
result.put("msg", "mediaServerId is null");
|
||||
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "流媒体:" + mediaServerId + "不存在" );
|
||||
}
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaInfo == null) {
|
||||
result.put("code", 0);
|
||||
result.put("msg", "使用的流媒体已经停止运行");
|
||||
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "使用的流媒体已经停止运行" );
|
||||
}else {
|
||||
JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(mediaInfo, key);
|
||||
logger.info(jsonObject.toJSONString());
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
result.put("code", 0);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (data != null && data.getBoolean("flag")) {
|
||||
result.put("code", "0");
|
||||
result.put("msg", "success");
|
||||
}else {
|
||||
|
||||
if (data == null || data.getBoolean("flag") == null || !data.getBoolean("flag")) {
|
||||
throw new ControllerException(ErrorCode.ERROR100 );
|
||||
}
|
||||
}else {
|
||||
result.put("code", 1);
|
||||
result.put("msg", "delFFmpegSource fail");
|
||||
throw new ControllerException(ErrorCode.ERROR100 );
|
||||
}
|
||||
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Operation(summary = "语音广播命令")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/broadcast/{deviceId}")
|
||||
@PostMapping("/broadcast/{deviceId}")
|
||||
public DeferredResult<ResponseEntity<String>> broadcastApi(@PathVariable String deviceId) {
|
||||
public DeferredResult<String> broadcastApi(@PathVariable String deviceId) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("语音广播API调用");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
|
||||
DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
|
||||
if (resultHolder.exist(key, null)) {
|
||||
result.setResult(new ResponseEntity<>("设备使用中",HttpStatus.OK));
|
||||
result.setResult("设备使用中");
|
||||
return result;
|
||||
}
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
@@ -307,7 +296,7 @@ public class PlayController {
|
||||
|
||||
@Operation(summary = "获取所有的ssrc")
|
||||
@GetMapping("/ssrc")
|
||||
public WVPResult<JSONObject> getSSRC() {
|
||||
public JSONObject getSSRC() {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("获取所有的ssrc");
|
||||
}
|
||||
@@ -322,14 +311,10 @@ public class PlayController {
|
||||
objects.add(jsonObject);
|
||||
}
|
||||
|
||||
WVPResult<JSONObject> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("data", objects);
|
||||
jsonObject.put("count", objects.size());
|
||||
result.setData(jsonObject);
|
||||
return result;
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.play.bean;
|
||||
|
||||
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<ResponseEntity<String>> result;
|
||||
private DeferredResult<WVPResult<String>> result;
|
||||
private String uuid;
|
||||
|
||||
private Device device;
|
||||
|
||||
public DeferredResult<ResponseEntity<String>> getResult() {
|
||||
public DeferredResult<WVPResult<String>> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(DeferredResult<ResponseEntity<String>> result) {
|
||||
public void setResult(DeferredResult<WVPResult<String>> result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.genersoft.iot.vmp.vmanager.gb28181.playback;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
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.tags.Tag;
|
||||
@@ -13,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -55,14 +58,14 @@ public class PlaybackController {
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@GetMapping("/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
public DeferredResult<String> play(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime,String endTime) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
}
|
||||
|
||||
DeferredResult<ResponseEntity<String>> result = playService.playBack(deviceId, channelId, startTime, endTime, null, wvpResult->{
|
||||
DeferredResult<String> result = playService.playBack(deviceId, channelId, startTime, endTime, null, wvpResult->{
|
||||
resultHolder.invokeResult(wvpResult.getData());
|
||||
});
|
||||
|
||||
@@ -75,67 +78,46 @@ public class PlaybackController {
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "stream", description = "流ID", required = true)
|
||||
@GetMapping("/stop/{deviceId}/{channelId}/{stream}")
|
||||
public ResponseEntity<String> playStop(
|
||||
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);
|
||||
}
|
||||
cmder.streamByeCmd(deviceId, channelId, stream, null);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备录像回放停止 API调用,deviceId/channelId:%s/%s", deviceId, channelId));
|
||||
}
|
||||
if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(channelId) || StringUtils.isEmpty(stream)) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (deviceId != null && channelId != null) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
json.put("channelId", channelId);
|
||||
return new ResponseEntity<>(json.toString(), HttpStatus.OK);
|
||||
} else {
|
||||
logger.warn("设备录像回放停止API调用失败!");
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "回放暂停")
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@GetMapping("/pause/{streamId}")
|
||||
public ResponseEntity<String> playPause(@PathVariable String streamId) {
|
||||
public void playPause(@PathVariable String streamId) {
|
||||
logger.info("playPause: "+streamId);
|
||||
JSONObject json = new JSONObject();
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
json.put("msg", "streamId不存在");
|
||||
logger.warn("streamId不存在!");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
cmder.playPauseCmd(device, streamInfo);
|
||||
json.put("msg", "ok");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "回放恢复")
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@GetMapping("/resume/{streamId}")
|
||||
public ResponseEntity<String> playResume(@PathVariable String streamId) {
|
||||
public void playResume(@PathVariable String streamId) {
|
||||
logger.info("playResume: "+streamId);
|
||||
JSONObject json = new JSONObject();
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
json.put("msg", "streamId不存在");
|
||||
logger.warn("streamId不存在!");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
cmder.playResumeCmd(device, streamInfo);
|
||||
json.put("msg", "ok");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,43 +125,33 @@ public class PlaybackController {
|
||||
@Parameter(name = "streamId", description = "回放流ID", required = true)
|
||||
@Parameter(name = "seekTime", description = "拖动偏移量,单位s", required = true)
|
||||
@GetMapping("/seek/{streamId}/{seekTime}")
|
||||
public ResponseEntity<String> playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
|
||||
public void playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
|
||||
logger.info("playSeek: "+streamId+", "+seekTime);
|
||||
JSONObject json = new JSONObject();
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
json.put("msg", "streamId不存在");
|
||||
logger.warn("streamId不存在!");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
cmder.playSeekCmd(device, streamInfo, seekTime);
|
||||
json.put("msg", "ok");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Operation(summary = "回放倍速播放")
|
||||
@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 ResponseEntity<String> playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
|
||||
public void playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
|
||||
logger.info("playSpeed: "+streamId+", "+speed);
|
||||
JSONObject json = new JSONObject();
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
|
||||
if (null == streamInfo) {
|
||||
json.put("msg", "streamId不存在");
|
||||
logger.warn("streamId不存在!");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
|
||||
}
|
||||
if(speed != 0.25 && speed != 0.5 && speed != 1 && speed != 2.0 && speed != 4.0) {
|
||||
json.put("msg", "不支持的speed(0.25 0.5 1、2、4)");
|
||||
logger.warn("不支持的speed: " + speed);
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "不支持的speed(0.25 0.5 1、2、4)");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
|
||||
cmder.playSpeedCmd(device, streamInfo, speed);
|
||||
json.put("msg", "ok");
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
@@ -46,7 +45,6 @@ public class PtzController {
|
||||
* @param horizonSpeed 水平移动速度
|
||||
* @param verticalSpeed 垂直移动速度
|
||||
* @param zoomSpeed 缩放速度
|
||||
* @return String 控制结果
|
||||
*/
|
||||
|
||||
@Operation(summary = "云台控制")
|
||||
@@ -57,7 +55,7 @@ public class PtzController {
|
||||
@Parameter(name = "verticalSpeed", description = "垂直速度", required = true)
|
||||
@Parameter(name = "zoomSpeed", description = "缩放速度", required = true)
|
||||
@PostMapping("/control/{deviceId}/{channelId}")
|
||||
public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
|
||||
public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,command:%s ,horizonSpeed:%d ,verticalSpeed:%d ,zoomSpeed:%d",deviceId, channelId, command, horizonSpeed, verticalSpeed, zoomSpeed));
|
||||
@@ -96,13 +94,11 @@ public class PtzController {
|
||||
cmdCode = 32;
|
||||
break;
|
||||
case "stop":
|
||||
cmdCode = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed);
|
||||
return new ResponseEntity<String>("success",HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +110,7 @@ public class PtzController {
|
||||
@Parameter(name = "parameter2", description = "数据二", required = true)
|
||||
@Parameter(name = "combindCode2", description = "组合码二", required = true)
|
||||
@PostMapping("/front_end_command/{deviceId}/{channelId}")
|
||||
public ResponseEntity<String> frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
|
||||
public void frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,cmdCode:%d parameter1:%d parameter2:%d",deviceId, channelId, cmdCode, parameter1, parameter2));
|
||||
@@ -122,7 +118,6 @@ public class PtzController {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
|
||||
cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2);
|
||||
return new ResponseEntity<String>("success",HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,14 +125,14 @@ public class PtzController {
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@GetMapping("/preset/query/{deviceId}/{channelId}")
|
||||
public DeferredResult<ResponseEntity<String>> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
public DeferredResult<String> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备预置位查询API调用");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L);
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
DeferredResult<String> result = new DeferredResult<String> (3 * 1000L);
|
||||
result.onTimeout(()->{
|
||||
logger.warn(String.format("获取设备预置位超时"));
|
||||
// 释放rtpserver
|
||||
@@ -158,7 +153,6 @@ public class PtzController {
|
||||
msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.genersoft.iot.vmp.vmanager.gb28181.record;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -58,28 +60,17 @@ public class GBRecordController {
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@GetMapping("/query/{deviceId}/{channelId}")
|
||||
public DeferredResult<ResponseEntity<WVPResult<RecordInfo>>> recordinfo(@PathVariable String deviceId, @PathVariable String channelId, String startTime, String endTime){
|
||||
public DeferredResult<WVPResult<RecordInfo>> recordinfo(@PathVariable String deviceId, @PathVariable String channelId, String startTime, String endTime){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("录像信息查询 API调用,deviceId:%s ,startTime:%s, endTime:%s",deviceId, startTime, endTime));
|
||||
}
|
||||
DeferredResult<ResponseEntity<WVPResult<RecordInfo>>> result = new DeferredResult<>();
|
||||
DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>();
|
||||
if (!DateUtil.verification(startTime, DateUtil.formatter)){
|
||||
WVPResult<RecordInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("startTime error, format is " + DateUtil.PATTERN);
|
||||
|
||||
ResponseEntity<WVPResult<RecordInfo>> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
result.setResult(resultResponseEntity);
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime error, format is " + DateUtil.PATTERN);
|
||||
}
|
||||
if (!DateUtil.verification(endTime, DateUtil.formatter)){
|
||||
WVPResult<RecordInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("endTime error, format is " + DateUtil.PATTERN);
|
||||
ResponseEntity<WVPResult<RecordInfo>> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK);
|
||||
result.setResult(resultResponseEntity);
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime error, format is " + DateUtil.PATTERN);
|
||||
}
|
||||
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
@@ -92,7 +83,7 @@ public class GBRecordController {
|
||||
msg.setKey(key);
|
||||
cmder.recordInfoQuery(device, channelId, startTime, endTime, sn, null, null, null, (eventResult -> {
|
||||
WVPResult<RecordInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("查询录像失败, status: " + eventResult.statusCode + ", message: " + eventResult.msg);
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
@@ -103,7 +94,7 @@ public class GBRecordController {
|
||||
result.onTimeout(()->{
|
||||
msg.setData("timeout");
|
||||
WVPResult<RecordInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("timeout");
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
@@ -119,59 +110,14 @@ public class GBRecordController {
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
@Parameter(name = "downloadSpeed", description = "下载倍速", required = true)
|
||||
@GetMapping("/download/start/{deviceId}/{channelId}")
|
||||
public DeferredResult<ResponseEntity<String>> download(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
public DeferredResult<String> download(@PathVariable String deviceId, @PathVariable String channelId,
|
||||
String startTime, String endTime, String downloadSpeed) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed));
|
||||
}
|
||||
// String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
|
||||
// String uuid = UUID.randomUUID().toString();
|
||||
// DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L);
|
||||
// // 超时处理
|
||||
// result.onTimeout(()->{
|
||||
// logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
// RequestMessage msg = new RequestMessage();
|
||||
// msg.setId(uuid);
|
||||
// msg.setKey(key);
|
||||
// msg.setData("Timeout");
|
||||
// resultHolder.invokeAllResult(msg);
|
||||
// });
|
||||
// if(resultHolder.exist(key, null)) {
|
||||
// return result;
|
||||
// }
|
||||
// resultHolder.put(key, uuid, result);
|
||||
// Device device = storager.queryVideoDevice(deviceId);
|
||||
//
|
||||
// MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
|
||||
// if (newMediaServerItem == null) {
|
||||
// logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
// RequestMessage msg = new RequestMessage();
|
||||
// msg.setId(uuid);
|
||||
// msg.setKey(key);
|
||||
// msg.setData("Timeout");
|
||||
// resultHolder.invokeAllResult(msg);
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, true);
|
||||
//
|
||||
// cmder.downloadStreamCmd(newMediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, (InviteStreamInfo inviteStreamInfo) -> {
|
||||
// logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString());
|
||||
// playService.onPublishHandlerForDownload(inviteStreamInfo, deviceId, channelId, uuid);
|
||||
// }, event -> {
|
||||
// RequestMessage msg = new RequestMessage();
|
||||
// msg.setId(uuid);
|
||||
// msg.setKey(key);
|
||||
// msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
|
||||
// resultHolder.invokeAllResult(msg);
|
||||
// });
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
}
|
||||
|
||||
DeferredResult<ResponseEntity<String>> result = playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, hookCallBack->{
|
||||
DeferredResult<String> result = playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, hookCallBack->{
|
||||
resultHolder.invokeResult(hookCallBack.getData());
|
||||
});
|
||||
|
||||
@@ -183,7 +129,7 @@ public class GBRecordController {
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "stream", description = "流ID", required = true)
|
||||
@GetMapping("/download/stop/{deviceId}/{channelId}/{stream}")
|
||||
public ResponseEntity<String> playStop(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
public void playStop(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
|
||||
cmder.streamByeCmd(deviceId, channelId, stream, null);
|
||||
|
||||
@@ -191,14 +137,8 @@ public class GBRecordController {
|
||||
logger.debug(String.format("设备历史媒体下载停止 API调用,deviceId/channelId:%s_%s", deviceId, channelId));
|
||||
}
|
||||
|
||||
if (deviceId != null && channelId != null) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("deviceId", deviceId);
|
||||
json.put("channelId", channelId);
|
||||
return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
|
||||
} else {
|
||||
logger.warn("设备历史媒体下载停止API调用失败!");
|
||||
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
if (deviceId == null || channelId == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,9 +147,7 @@ public class GBRecordController {
|
||||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "stream", description = "流ID", required = true)
|
||||
@GetMapping("/download/progress/{deviceId}/{channelId}/{stream}")
|
||||
public ResponseEntity<StreamInfo> getProgress(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
|
||||
StreamInfo streamInfo = playService.getDownLoadInfo(deviceId, channelId, stream);
|
||||
return new ResponseEntity<>(streamInfo, HttpStatus.OK);
|
||||
public StreamInfo getProgress(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
|
||||
return playService.getDownLoadInfo(deviceId, channelId, stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.genersoft.iot.vmp.vmanager.log;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.service.ILogService;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -15,6 +17,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -53,7 +56,7 @@ public class LogController {
|
||||
@Parameter(name = "type", description = "类型", required = true)
|
||||
@Parameter(name = "startTime", description = "开始时间", required = true)
|
||||
@Parameter(name = "endTime", description = "结束时间", required = true)
|
||||
public ResponseEntity<PageInfo<LogDto>> getAll(
|
||||
public PageInfo<LogDto> getAll(
|
||||
@RequestParam int page,
|
||||
@RequestParam int count,
|
||||
@RequestParam(required = false) String query,
|
||||
@@ -61,13 +64,13 @@ public class LogController {
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime
|
||||
) {
|
||||
if (StringUtils.isEmpty(query)) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(startTime)) {
|
||||
if (ObjectUtils.isEmpty(startTime)) {
|
||||
startTime = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(endTime)) {
|
||||
if (ObjectUtils.isEmpty(endTime)) {
|
||||
endTime = null;
|
||||
}
|
||||
if (!userSetting.getLogInDatebase()) {
|
||||
@@ -75,11 +78,10 @@ public class LogController {
|
||||
}
|
||||
|
||||
if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
throw new ControllerException(ErrorCode.ERROR400);
|
||||
}
|
||||
|
||||
PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
|
||||
return new ResponseEntity<>(allLog, HttpStatus.OK);
|
||||
return logService.getAll(page, count, query, type, startTime, endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,14 +90,8 @@ public class LogController {
|
||||
*/
|
||||
@Operation(summary = "停止视频回放")
|
||||
@DeleteMapping("/clear")
|
||||
public ResponseEntity<WVPResult<String>> clear() {
|
||||
|
||||
int count = logService.clear();
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
wvpResult.setData(count);
|
||||
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
|
||||
public void clear() {
|
||||
logService.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,24 +4,27 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.VManageBootstrap;
|
||||
import com.genersoft.iot.vmp.common.VersionPo;
|
||||
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.VersionInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import gov.nist.javax.sip.SipStackImpl;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.ehcache.xml.model.ThreadPoolsType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -30,7 +33,6 @@ import javax.sip.ObjectInUseException;
|
||||
import javax.sip.SipProvider;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Tag(name = "服务控制")
|
||||
@@ -54,45 +56,34 @@ public class ServerController {
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Value("${server.port}")
|
||||
private int serverPort;
|
||||
|
||||
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor taskExecutor;
|
||||
|
||||
|
||||
@GetMapping(value = "/media_server/list")
|
||||
@ResponseBody
|
||||
@Operation(summary = "流媒体服务列表")
|
||||
public WVPResult<List<MediaServerItem>> getMediaServerList() {
|
||||
WVPResult<List<MediaServerItem>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(mediaServerService.getAll());
|
||||
return result;
|
||||
public List<MediaServerItem> getMediaServerList() {
|
||||
return mediaServerService.getAll();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/media_server/online/list")
|
||||
@ResponseBody
|
||||
@Operation(summary = "在线流媒体服务列表")
|
||||
public WVPResult<List<MediaServerItem>> getOnlineMediaServerList() {
|
||||
WVPResult<List<MediaServerItem>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(mediaServerService.getAllOnline());
|
||||
return result;
|
||||
public List<MediaServerItem> getOnlineMediaServerList() {
|
||||
return mediaServerService.getAllOnline();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/media_server/one/{id}")
|
||||
@ResponseBody
|
||||
@Operation(summary = "停止视频回放")
|
||||
@Parameter(name = "id", description = "流媒体服务ID", required = true)
|
||||
public WVPResult<MediaServerItem> getMediaServer(@PathVariable String id) {
|
||||
WVPResult<MediaServerItem> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(mediaServerService.getOne(id));
|
||||
return result;
|
||||
public MediaServerItem getMediaServer(@PathVariable String id) {
|
||||
return mediaServerService.getOne(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "测试流媒体服务")
|
||||
@@ -101,7 +92,7 @@ public class ServerController {
|
||||
@Parameter(name = "secret", description = "流媒体服务secret", required = true)
|
||||
@GetMapping(value = "/media_server/check")
|
||||
@ResponseBody
|
||||
public WVPResult<MediaServerItem> checkMediaServer(@RequestParam String ip, @RequestParam int port, @RequestParam String secret) {
|
||||
public MediaServerItem checkMediaServer(@RequestParam String ip, @RequestParam int port, @RequestParam String secret) {
|
||||
return mediaServerService.checkMediaServer(ip, port, secret);
|
||||
}
|
||||
|
||||
@@ -110,122 +101,87 @@ public class ServerController {
|
||||
@Parameter(name = "port", description = "流媒体服务HTT端口", required = true)
|
||||
@GetMapping(value = "/media_server/record/check")
|
||||
@ResponseBody
|
||||
public WVPResult<String> checkMediaRecordServer(@RequestParam String ip, @RequestParam int port) {
|
||||
public void checkMediaRecordServer(@RequestParam String ip, @RequestParam int port) {
|
||||
boolean checkResult = mediaServerService.checkMediaRecordServer(ip, port);
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
if (checkResult) {
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
|
||||
} else {
|
||||
result.setCode(-1);
|
||||
result.setMsg("连接失败");
|
||||
if (!checkResult) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "保存流媒体服务")
|
||||
@Parameter(name = "mediaServerItem", description = "流媒体信息", required = true)
|
||||
@PostMapping(value = "/media_server/save")
|
||||
@ResponseBody
|
||||
public WVPResult<String> saveMediaServer(@RequestBody MediaServerItem mediaServerItem) {
|
||||
public void saveMediaServer(@RequestBody MediaServerItem mediaServerItem) {
|
||||
MediaServerItem mediaServerItemInDatabase = mediaServerService.getOne(mediaServerItem.getId());
|
||||
|
||||
if (mediaServerItemInDatabase != null) {
|
||||
if (StringUtils.isEmpty(mediaServerItemInDatabase.getSendRtpPortRange()) && StringUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
|
||||
if (ObjectUtils.isEmpty(mediaServerItemInDatabase.getSendRtpPortRange()) && ObjectUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
|
||||
mediaServerItem.setSendRtpPortRange("30000,30500");
|
||||
}
|
||||
mediaServerService.update(mediaServerItem);
|
||||
} else {
|
||||
if (StringUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
|
||||
if (ObjectUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
|
||||
mediaServerItem.setSendRtpPortRange("30000,30500");
|
||||
}
|
||||
return mediaServerService.add(mediaServerItem);
|
||||
mediaServerService.add(mediaServerItem);
|
||||
}
|
||||
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "移除流媒体服务")
|
||||
@Parameter(name = "id", description = "流媒体ID", required = true)
|
||||
@DeleteMapping(value = "/media_server/delete")
|
||||
@ResponseBody
|
||||
public WVPResult<String> deleteMediaServer(@RequestParam String id) {
|
||||
if (mediaServerService.getOne(id) != null) {
|
||||
mediaServerService.delete(id);
|
||||
mediaServerService.deleteDb(id);
|
||||
} else {
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
result.setCode(-1);
|
||||
result.setMsg("未找到此节点");
|
||||
return result;
|
||||
public void deleteMediaServer(@RequestParam String id) {
|
||||
if (mediaServerService.getOne(id) == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到此节点");
|
||||
}
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
return result;
|
||||
mediaServerService.delete(id);
|
||||
mediaServerService.deleteDb(id);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "重启服务")
|
||||
@GetMapping(value = "/restart")
|
||||
@ResponseBody
|
||||
public Object restart() {
|
||||
Thread restartThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
|
||||
SipStackImpl stack = (SipStackImpl) up.getSipStack();
|
||||
stack.stop();
|
||||
Iterator listener = stack.getListeningPoints();
|
||||
while (listener.hasNext()) {
|
||||
stack.deleteListeningPoint((ListeningPoint) listener.next());
|
||||
}
|
||||
Iterator providers = stack.getSipProviders();
|
||||
while (providers.hasNext()) {
|
||||
stack.deleteSipProvider((SipProvider) providers.next());
|
||||
}
|
||||
VManageBootstrap.restart();
|
||||
} catch (InterruptedException ignored) {
|
||||
} catch (ObjectInUseException e) {
|
||||
e.printStackTrace();
|
||||
public void restart() {
|
||||
taskExecutor.execute(()-> {
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
|
||||
SipStackImpl stack = (SipStackImpl) up.getSipStack();
|
||||
stack.stop();
|
||||
Iterator listener = stack.getListeningPoints();
|
||||
while (listener.hasNext()) {
|
||||
stack.deleteListeningPoint((ListeningPoint) listener.next());
|
||||
}
|
||||
Iterator providers = stack.getSipProviders();
|
||||
while (providers.hasNext()) {
|
||||
stack.deleteSipProvider((SipProvider) providers.next());
|
||||
}
|
||||
VManageBootstrap.restart();
|
||||
} catch (InterruptedException | ObjectInUseException e) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
restartThread.setDaemon(false);
|
||||
restartThread.start();
|
||||
return "success";
|
||||
}
|
||||
};
|
||||
|
||||
@Operation(summary = "获取版本信息")
|
||||
@GetMapping(value = "/version")
|
||||
@ResponseBody
|
||||
public WVPResult<VersionPo> getVersion() {
|
||||
WVPResult<VersionPo> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(versionInfo.getVersion());
|
||||
return result;
|
||||
public VersionPo VersionPogetVersion() {
|
||||
return versionInfo.getVersion();
|
||||
}
|
||||
|
||||
@GetMapping(value = "/config")
|
||||
@Operation(summary = "获取配置信息")
|
||||
@Parameter(name = "type", description = "配置类型(sip, base)", required = true)
|
||||
@ResponseBody
|
||||
public WVPResult<JSONObject> getVersion(String type) {
|
||||
WVPResult<JSONObject> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
public JSONObject getVersion(String type) {
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("server.port", serverPort);
|
||||
if (StringUtils.isEmpty(type)) {
|
||||
if (ObjectUtils.isEmpty(type)) {
|
||||
jsonObject.put("sip", JSON.toJSON(sipConfig));
|
||||
jsonObject.put("base", JSON.toJSON(userSetting));
|
||||
} else {
|
||||
@@ -240,50 +196,13 @@ public class ServerController {
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.setData(jsonObject);
|
||||
return result;
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/hooks")
|
||||
@ResponseBody
|
||||
@Operation(summary = "获取当前所有hook")
|
||||
public WVPResult<List<IHookSubscribe>> getHooks() {
|
||||
WVPResult<List<IHookSubscribe>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
List<IHookSubscribe> all = zlmHttpHookSubscribe.getAll();
|
||||
result.setData(all);
|
||||
return result;
|
||||
public List<IHookSubscribe> getHooks() {
|
||||
return zlmHttpHookSubscribe.getAll();
|
||||
}
|
||||
|
||||
// //@ApiOperation("当前进行中的动态任务")
|
||||
// @GetMapping(value = "/dynamicTask")
|
||||
// @ResponseBody
|
||||
// public WVPResult<JSONObject> getDynamicTask(){
|
||||
// WVPResult<JSONObject> result = new WVPResult<>();
|
||||
// result.setCode(0);
|
||||
// result.setMsg("success");
|
||||
//
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
//
|
||||
// Set<String> allKeys = dynamicTask.getAllKeys();
|
||||
// jsonObject.put("server.port", serverPort);
|
||||
// if (StringUtils.isEmpty(type)) {
|
||||
// jsonObject.put("sip", JSON.toJSON(sipConfig));
|
||||
// jsonObject.put("base", JSON.toJSON(userSetting));
|
||||
// }else {
|
||||
// switch (type){
|
||||
// case "sip":
|
||||
// jsonObject.put("sip", sipConfig);
|
||||
// break;
|
||||
// case "base":
|
||||
// jsonObject.put("base", userSetting);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// result.setData(jsonObject);
|
||||
// return result;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package com.genersoft.iot.vmp.vmanager.streamProxy;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
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;
|
||||
@@ -18,6 +20,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -33,10 +36,6 @@ public class StreamProxyController {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(StreamProxyController.class);
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@@ -64,35 +63,32 @@ public class StreamProxyController {
|
||||
})
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public WVPResult save(@RequestBody StreamProxyItem param){
|
||||
public StreamInfo save(@RequestBody StreamProxyItem param){
|
||||
logger.info("添加代理: " + JSONObject.toJSONString(param));
|
||||
if (StringUtils.isEmpty(param.getMediaServerId())) {
|
||||
if (ObjectUtils.isEmpty(param.getMediaServerId())) {
|
||||
param.setMediaServerId("auto");
|
||||
}
|
||||
if (StringUtils.isEmpty(param.getType())) {
|
||||
if (ObjectUtils.isEmpty(param.getType())) {
|
||||
param.setType("default");
|
||||
}
|
||||
if (StringUtils.isEmpty(param.getGbId())) {
|
||||
if (ObjectUtils.isEmpty(param.getGbId())) {
|
||||
param.setGbId(null);
|
||||
}
|
||||
WVPResult<StreamInfo> result = streamProxyService.save(param);
|
||||
return result;
|
||||
return streamProxyService.save(param);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/ffmpeg_cmd/list")
|
||||
@ResponseBody
|
||||
@Operation(summary = "获取ffmpeg.cmd模板")
|
||||
@Parameter(name = "mediaServerId", description = "流媒体ID", required = true)
|
||||
public WVPResult getFFmpegCMDs(@RequestParam String mediaServerId){
|
||||
public JSONObject getFFmpegCMDs(@RequestParam String mediaServerId){
|
||||
logger.debug("获取节点[ {} ]ffmpeg.cmd模板", mediaServerId );
|
||||
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
JSONObject data = streamProxyService.getFFmpegCMDs(mediaServerItem);
|
||||
WVPResult<JSONObject> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(data);
|
||||
return result;
|
||||
if (mediaServerItem == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "流媒体: " + mediaServerId + "未找到");
|
||||
}
|
||||
return streamProxyService.getFFmpegCMDs(mediaServerItem);
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/del")
|
||||
@@ -100,18 +96,13 @@ public class StreamProxyController {
|
||||
@Operation(summary = "移除代理")
|
||||
@Parameter(name = "app", description = "应用名", required = true)
|
||||
@Parameter(name = "stream", description = "流id", required = true)
|
||||
public WVPResult del(@RequestParam String app, @RequestParam String stream){
|
||||
public void del(@RequestParam String app, @RequestParam String stream){
|
||||
logger.info("移除代理: " + app + "/" + stream);
|
||||
WVPResult<Object> result = new WVPResult<>();
|
||||
if (app == null || stream == null) {
|
||||
result.setCode(400);
|
||||
result.setMsg(app == null ?"app不能为null":"stream不能为null");
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), app == null ?"app不能为null":"stream不能为null");
|
||||
}else {
|
||||
streamProxyService.del(app, stream);
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/start")
|
||||
@@ -119,13 +110,13 @@ public class StreamProxyController {
|
||||
@Operation(summary = "启用代理")
|
||||
@Parameter(name = "app", description = "应用名", required = true)
|
||||
@Parameter(name = "stream", description = "流id", required = true)
|
||||
public Object start(String app, String stream){
|
||||
public void start(String app, String stream){
|
||||
logger.info("启用代理: " + app + "/" + stream);
|
||||
boolean result = streamProxyService.start(app, stream);
|
||||
if (!result) {
|
||||
logger.info("启用代理失败: " + app + "/" + stream);
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
return result?"success":"fail";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/stop")
|
||||
@@ -133,9 +124,12 @@ public class StreamProxyController {
|
||||
@Operation(summary = "停用代理")
|
||||
@Parameter(name = "app", description = "应用名", required = true)
|
||||
@Parameter(name = "stream", description = "流id", required = true)
|
||||
public Object stop(String app, String stream){
|
||||
public void stop(String app, String stream){
|
||||
logger.info("停用代理: " + app + "/" + stream);
|
||||
boolean result = streamProxyService.stop(app, stream);
|
||||
return result?"success":"fail";
|
||||
if (!result) {
|
||||
logger.info("停用代理失败: " + app + "/" + stream);
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
@@ -81,10 +82,10 @@ public class StreamPushController {
|
||||
@RequestParam(required = false)Boolean pushing,
|
||||
@RequestParam(required = false)String mediaServerId ){
|
||||
|
||||
if (StringUtils.isEmpty(query)) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
if (StringUtils.isEmpty(mediaServerId)) {
|
||||
if (ObjectUtils.isEmpty(mediaServerId)) {
|
||||
mediaServerId = null;
|
||||
}
|
||||
PageInfo<StreamPushItem> pushList = streamPushService.getPushList(page, count, query, pushing, mediaServerId);
|
||||
@@ -285,11 +286,11 @@ public class StreamPushController {
|
||||
@ResponseBody
|
||||
@Operation(summary = "停止视频回放")
|
||||
public WVPResult<StreamInfo> add(@RequestBody StreamPushItem stream){
|
||||
if (StringUtils.isEmpty(stream.getGbId())) {
|
||||
if (ObjectUtils.isEmpty(stream.getGbId())) {
|
||||
|
||||
return new WVPResult<>(400, "国标ID不可为空", null);
|
||||
}
|
||||
if (StringUtils.isEmpty(stream.getApp()) && StringUtils.isEmpty(stream.getStream())) {
|
||||
if (ObjectUtils.isEmpty(stream.getApp()) && ObjectUtils.isEmpty(stream.getStream())) {
|
||||
return new WVPResult<>(400, "app或stream不可为空", null);
|
||||
}
|
||||
stream.setStatus(false);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.genersoft.iot.vmp.vmanager.user;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
|
||||
import com.genersoft.iot.vmp.service.IRoleService;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.Role;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -29,16 +31,13 @@ public class RoleController {
|
||||
@Operation(summary = "添加角色")
|
||||
@Parameter(name = "name", description = "角色名", required = true)
|
||||
@Parameter(name = "authority", description = "权限(自行定义内容,目前未使用)", required = true)
|
||||
public ResponseEntity<WVPResult<Integer>> add(@RequestParam String name,
|
||||
public void add(@RequestParam String name,
|
||||
@RequestParam(required = false) String authority){
|
||||
WVPResult<Integer> result = new WVPResult<>();
|
||||
// 获取当前登录用户id
|
||||
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
|
||||
if (currenRoleId != 1) {
|
||||
// 只用角色id为1才可以删除和添加用户
|
||||
result.setCode(-1);
|
||||
result.setMsg("用户无权限");
|
||||
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
|
||||
throw new ControllerException(ErrorCode.ERROR403);
|
||||
}
|
||||
|
||||
Role role = new Role();
|
||||
@@ -48,42 +47,33 @@ public class RoleController {
|
||||
role.setUpdateTime(DateUtil.getNow());
|
||||
|
||||
int addResult = roleService.add(role);
|
||||
|
||||
result.setCode(addResult > 0 ? 0 : -1);
|
||||
result.setMsg(addResult > 0 ? "success" : "fail");
|
||||
result.setData(addResult);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (addResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除角色")
|
||||
@Parameter(name = "id", description = "用户Id", required = true)
|
||||
public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
|
||||
public void delete(@RequestParam Integer id){
|
||||
// 获取当前登录用户id
|
||||
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
if (currenRoleId != 1) {
|
||||
// 只用角色id为0才可以删除和添加用户
|
||||
result.setCode(-1);
|
||||
result.setMsg("用户无权限");
|
||||
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
|
||||
throw new ControllerException(ErrorCode.ERROR403);
|
||||
}
|
||||
int deleteResult = roleService.delete(id);
|
||||
|
||||
result.setCode(deleteResult>0? 0 : -1);
|
||||
result.setMsg(deleteResult>0? "success" : "fail");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (deleteResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
@Operation(summary = "查询角色")
|
||||
public ResponseEntity<WVPResult<List<Role>>> all(){
|
||||
public List<Role> all(){
|
||||
// 获取当前登录用户id
|
||||
List<Role> allRoles = roleService.getAll();
|
||||
WVPResult<List<Role>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(allRoles);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
return roleService.getAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.vmanager.user;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
|
||||
import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
|
||||
import com.genersoft.iot.vmp.service.IRoleService;
|
||||
@@ -7,6 +8,7 @@ import com.genersoft.iot.vmp.service.IUserService;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.Role;
|
||||
import com.genersoft.iot.vmp.storager.dao.dto.User;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -18,6 +20,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -43,25 +46,17 @@ public class UserController {
|
||||
@Operation(summary = "登录")
|
||||
@Parameter(name = "username", description = "用户名", required = true)
|
||||
@Parameter(name = "password", description = "密码(32位md5加密)", required = true)
|
||||
public WVPResult<LoginUser> login(@RequestParam String username, @RequestParam String password){
|
||||
public LoginUser login(@RequestParam String username, @RequestParam String password){
|
||||
LoginUser user = null;
|
||||
WVPResult<LoginUser> result = new WVPResult<>();
|
||||
try {
|
||||
user = SecurityUtils.login(username, password, authenticationManager);
|
||||
} catch (AuthenticationException e) {
|
||||
e.printStackTrace();
|
||||
result.setCode(-1);
|
||||
result.setMsg("fail");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
if (user != null) {
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(user);
|
||||
}else {
|
||||
result.setCode(-1);
|
||||
result.setMsg("fail");
|
||||
if (user == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "用户名或密码错误");
|
||||
}
|
||||
return result;
|
||||
return user;
|
||||
}
|
||||
|
||||
@PostMapping("/changePassword")
|
||||
@@ -69,27 +64,27 @@ public class UserController {
|
||||
@Parameter(name = "username", description = "用户名", required = true)
|
||||
@Parameter(name = "oldpassword", description = "旧密码(已md5加密的密码)", required = true)
|
||||
@Parameter(name = "password", description = "新密码(未md5加密的密码)", required = true)
|
||||
public String changePassword(@RequestParam String oldPassword, @RequestParam String password){
|
||||
public void changePassword(@RequestParam String oldPassword, @RequestParam String password){
|
||||
// 获取当前登录用户id
|
||||
LoginUser userInfo = SecurityUtils.getUserInfo();
|
||||
if (userInfo== null) {
|
||||
return "fail";
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
String username = userInfo.getUsername();
|
||||
LoginUser user = null;
|
||||
try {
|
||||
user = SecurityUtils.login(username, oldPassword, authenticationManager);
|
||||
if (user != null) {
|
||||
int userId = SecurityUtils.getUserId();
|
||||
boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
|
||||
if (result) {
|
||||
return "success";
|
||||
}
|
||||
if (user == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
int userId = SecurityUtils.getUserId();
|
||||
boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
|
||||
if (!result) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
} catch (AuthenticationException e) {
|
||||
e.printStackTrace();
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
|
||||
}
|
||||
return "fail";
|
||||
}
|
||||
|
||||
|
||||
@@ -98,22 +93,17 @@ public class UserController {
|
||||
@Parameter(name = "username", description = "用户名", required = true)
|
||||
@Parameter(name = "password", description = "密码(未md5加密的密码)", required = true)
|
||||
@Parameter(name = "roleId", description = "角色ID", required = true)
|
||||
public ResponseEntity<WVPResult<Integer>> add(@RequestParam String username,
|
||||
public void add(@RequestParam String username,
|
||||
@RequestParam String password,
|
||||
@RequestParam Integer roleId){
|
||||
WVPResult<Integer> result = new WVPResult<>();
|
||||
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || roleId == null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("参数不可为空");
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
if (ObjectUtils.isEmpty(username) || ObjectUtils.isEmpty(password) || roleId == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "参数不可为空");
|
||||
}
|
||||
// 获取当前登录用户id
|
||||
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
|
||||
if (currenRoleId != 1) {
|
||||
// 只用角色id为1才可以删除和添加用户
|
||||
result.setCode(-1);
|
||||
result.setMsg("用户无权限");
|
||||
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
|
||||
}
|
||||
User user = new User();
|
||||
user.setUsername(username);
|
||||
@@ -123,53 +113,38 @@ public class UserController {
|
||||
Role role = roleService.getRoleById(roleId);
|
||||
|
||||
if (role == null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("roleId is not found");
|
||||
// 角色不存在
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "角色不存在");
|
||||
}
|
||||
user.setRole(role);
|
||||
user.setCreateTime(DateUtil.getNow());
|
||||
user.setUpdateTime(DateUtil.getNow());
|
||||
int addResult = userService.addUser(user);
|
||||
|
||||
|
||||
result.setCode(addResult > 0 ? 0 : -1);
|
||||
result.setMsg(addResult > 0 ? "success" : "fail");
|
||||
result.setData(addResult);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (addResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/删除用户")
|
||||
@Operation(summary = "停止视频回放")
|
||||
@Parameter(name = "id", description = "用户Id", required = true)
|
||||
public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
|
||||
public void delete(@RequestParam Integer id){
|
||||
// 获取当前登录用户id
|
||||
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
if (currenRoleId != 1) {
|
||||
// 只用角色id为0才可以删除和添加用户
|
||||
result.setCode(-1);
|
||||
result.setMsg("用户无权限");
|
||||
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
|
||||
}
|
||||
int deleteResult = userService.deleteUser(id);
|
||||
|
||||
result.setCode(deleteResult>0? 0 : -1);
|
||||
result.setMsg(deleteResult>0? "success" : "fail");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (deleteResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
@Operation(summary = "查询用户")
|
||||
public ResponseEntity<WVPResult<List<User>>> all(){
|
||||
public List<User> all(){
|
||||
// 获取当前登录用户id
|
||||
List<User> allUsers = userService.getAllUsers();
|
||||
WVPResult<List<User>> result = new WVPResult<>();
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
result.setData(allUsers);
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
return userService.getAllUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,21 +166,18 @@ public class UserController {
|
||||
@Operation(summary = "修改pushkey")
|
||||
@Parameter(name = "userId", description = "用户Id", required = true)
|
||||
@Parameter(name = "pushKey", description = "新的pushKey", required = true)
|
||||
public ResponseEntity<WVPResult<String>> changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
|
||||
public void changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
|
||||
// 获取当前登录用户id
|
||||
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
if (currenRoleId != 1) {
|
||||
// 只用角色id为0才可以删除和添加用户
|
||||
result.setCode(-1);
|
||||
result.setMsg("用户无权限");
|
||||
return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
|
||||
}
|
||||
int resetPushKeyResult = userService.changePushKey(userId,pushKey);
|
||||
|
||||
result.setCode(resetPushKeyResult > 0 ? 0 : -1);
|
||||
result.setMsg(resetPushKeyResult > 0 ? "success" : "fail");
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
if (resetPushKeyResult <= 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/changePasswordForAdmin")
|
||||
@@ -213,20 +185,18 @@ public class UserController {
|
||||
@Parameter(name = "adminId", description = "管理员id", required = true)
|
||||
@Parameter(name = "userId", description = "用户id", required = true)
|
||||
@Parameter(name = "password", description = "新密码(未md5加密的密码)", required = true)
|
||||
public String changePasswordForAdmin(@RequestParam int userId, @RequestParam String password) {
|
||||
public void changePasswordForAdmin(@RequestParam int userId, @RequestParam String password) {
|
||||
// 获取当前登录用户id
|
||||
LoginUser userInfo = SecurityUtils.getUserInfo();
|
||||
if (userInfo == null) {
|
||||
return "fail";
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
Role role = userInfo.getRole();
|
||||
if (role != null && role.getId() == 1) {
|
||||
boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
|
||||
if (result) {
|
||||
return "success";
|
||||
if (!result) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user