1078-添加查询指定终端参数

This commit is contained in:
648540858
2024-04-15 00:31:11 +08:00
parent 205e529660
commit 570307669e
7 changed files with 165 additions and 7 deletions

View File

@@ -1,319 +0,0 @@
package com.genersoft.iot.vmp.jt1078.config;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.proc.request.J1205;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.util.List;
@ConditionalOnProperty(value = "jt1078.enable", havingValue = "true")
@RestController
@RequestMapping("/api/jt1078")
public class JT1078Controller {
private final static Logger logger = LoggerFactory.getLogger(JT1078Controller.class);
@Resource
Ijt1078Service service;
@Autowired
UserSetting userSetting;
@Operation(summary = "1078-开始点播", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@GetMapping("/live/start")
public DeferredResult<WVPResult<StreamContent>> startLive(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId) {
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
String finalChannelId = channelId;
result.onTimeout(()->{
logger.info("[1078-点播等待超时] deviceId{}, channelId{}, ", deviceId, finalChannelId);
// 释放rtpserver
WVPResult<StreamContent> wvpResult = new WVPResult<>();
wvpResult.setCode(ErrorCode.ERROR100.getCode());
wvpResult.setMsg("点播超时");
result.setResult(wvpResult);
service.stopPlay(deviceId, finalChannelId);
});
service.play(deviceId, channelId, (code, msg, streamInfo) -> {
WVPResult<StreamContent> wvpResult = new WVPResult<>();
if (code == InviteErrorCode.SUCCESS.getCode()) {
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
if (streamInfo != null) {
if (userSetting.getUseSourceIpAsStreamIp()) {
streamInfo=streamInfo.clone();//深拷贝
String host;
try {
URL url=new URL(request.getRequestURL().toString());
host=url.getHost();
} catch (MalformedURLException e) {
host=request.getLocalAddr();
}
streamInfo.channgeStreamIp(host);
}
wvpResult.setData(new StreamContent(streamInfo));
}else {
wvpResult.setCode(code);
wvpResult.setMsg(msg);
}
}else {
wvpResult.setCode(code);
wvpResult.setMsg(msg);
}
result.setResult(wvpResult);
});
return result;
}
@Operation(summary = "1078-结束点播", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@GetMapping("/live/stop")
public void stopLive(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId) {
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
service.stopPlay(deviceId, channelId);
}
@Operation(summary = "1078-暂停点播", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@GetMapping("/live/pause")
public void pauseLive(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId) {
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
service.pausePlay(deviceId, channelId);
}
@Operation(summary = "1078-继续点播", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@GetMapping("/live/continue")
public void continueLive(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId) {
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
service.continueLivePlay(deviceId, channelId);
}
@Operation(summary = "1078-录像-查询资源列表", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@Parameter(name = "startTime", description = "开始时间,格式: yyyy-MM-dd HH:mm:ss", required = true)
@Parameter(name = "endTime", description = "结束时间,格式: yyyy-MM-dd HH:mm:ss", required = true)
@GetMapping("/record/list")
public WVPResult<List<J1205.JRecordItem>> playbackList(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId,
@Parameter(required = true) String startTime,
@Parameter(required = true) String endTime
) {
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
List<J1205.JRecordItem> recordList = service.getRecordList(deviceId, channelId, startTime, endTime);
if (recordList == null) {
return WVPResult.fail(ErrorCode.ERROR100);
}else {
return WVPResult.success(recordList);
}
}
@Operation(summary = "1078-开始回放", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@Parameter(name = "startTime", description = "开始时间,格式: yyyy-MM-dd HH:mm:ss", required = true)
@Parameter(name = "endTime", description = "结束时间,格式: yyyy-MM-dd HH:mm:ss", required = true)
@GetMapping("/playback/start")
public DeferredResult<WVPResult<StreamContent>> recordLive(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId,
@Parameter(required = true) String startTime,
@Parameter(required = true) String endTime) {
DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
String finalChannelId = channelId;
result.onTimeout(()->{
logger.info("[1078-回放-等待超时] deviceId{}, channelId{}, ", deviceId, finalChannelId);
// 释放rtpserver
WVPResult<StreamContent> wvpResult = new WVPResult<>();
wvpResult.setCode(ErrorCode.ERROR100.getCode());
wvpResult.setMsg("回放超时");
result.setResult(wvpResult);
service.stopPlay(deviceId, finalChannelId);
});
service.playback(deviceId, channelId, startTime, endTime, (code, msg, streamInfo) -> {
WVPResult<StreamContent> wvpResult = new WVPResult<>();
if (code == InviteErrorCode.SUCCESS.getCode()) {
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
if (streamInfo != null) {
if (userSetting.getUseSourceIpAsStreamIp()) {
streamInfo=streamInfo.clone();//深拷贝
String host;
try {
URL url=new URL(request.getRequestURL().toString());
host=url.getHost();
} catch (MalformedURLException e) {
host=request.getLocalAddr();
}
streamInfo.channgeStreamIp(host);
}
wvpResult.setData(new StreamContent(streamInfo));
}else {
wvpResult.setCode(code);
wvpResult.setMsg(msg);
}
}else {
wvpResult.setCode(code);
wvpResult.setMsg(msg);
}
result.setResult(wvpResult);
});
return result;
}
@Operation(summary = "1078-结束回放", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@GetMapping("/playback/stop")
public void stopPlayback(HttpServletRequest request,
@Parameter(required = true) String deviceId,
@Parameter(required = false) String channelId) {
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
service.stopPlayback(deviceId, channelId);
}
@Operation(summary = "分页查询部标设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "page", description = "当前页", required = true)
@Parameter(name = "count", description = "每页查询数量", required = true)
@Parameter(name = "query", description = "查询内容")
@Parameter(name = "online", description = "是否在线")
@GetMapping("/device/list")
public PageInfo<JTDevice> getDevices(int page, int count,
@RequestParam(required = false) String query,
@RequestParam(required = false) Boolean online) {
return service.getDeviceList(page, count, query, online);
}
@Operation(summary = "更新设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "device", description = "设备", required = true)
@PostMapping("/device/update")
public void updateDevice(JTDevice device){
assert device.getId() > 0;
assert device.getDeviceId() != null;
service.updateDevice(device);
}
@Operation(summary = "新增设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "device", description = "设备", required = true)
@PostMapping("/device/add")
public void addDevice(JTDevice device){
assert device.getDeviceId() != null;
service.addDevice(device);
}
@Operation(summary = "删除设备", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备ID", required = true)
@DeleteMapping("/device/delete")
public void addDevice(String deviceId){
assert deviceId != null;
service.deleteDeviceByDeviceId(deviceId);
}
@Operation(summary = "云台控制", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@Parameter(name = "command", description = "控制指令,允许值: left, right, up, down, zoomin, zoomout, irisin, irisout, focusnear, focusfar, stop", required = true)
@Parameter(name = "speed", description = "速度(0-255) command,值 left, right, up, down时有效", required = true)
@PostMapping("/ptz")
public void ptz(String deviceId, String channelId, String command, int speed){
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
logger.info("[1078-云台控制] deviceId{}, channelId{}, command: {}, speed: {}", deviceId, channelId, command, speed);
service.ptzControl(deviceId, channelId, command, speed);
}
@Operation(summary = "补光灯开关", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@Parameter(name = "command", description = "控制指令,允许值: on off", required = true)
@PostMapping("/fill-light")
public void fillLight(String deviceId, String channelId, String command){
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
logger.info("[1078-补光灯开关] deviceId{}, channelId{}, command: {}", deviceId, channelId, command);
service.supplementaryLight(deviceId, channelId, command);
}
@Operation(summary = "雨刷开关", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true)
@Parameter(name = "command", description = "控制指令,允许值: on off", required = true)
@PostMapping("/wiper")
public void wiper(String deviceId, String channelId, String command){
if (ObjectUtils.isEmpty(channelId)) {
channelId = "1";
}
logger.info("[1078-雨刷开关] deviceId{}, channelId{}, command: {}", deviceId, channelId, command);
service.wiper(deviceId, channelId, command);
}
}