From 51759535fc2a70b26abaca6281c4a45d1a1c3984 Mon Sep 17 00:00:00 2001 From: lin <648540858@qq.com> Date: Mon, 7 Jul 2025 09:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bean/FrontEndControlCodeForAuxiliary.java | 2 +- .../bean/FrontEndControlCodeForPreset.java | 7 + .../bean/FrontEndControlCodeForScan.java | 2 +- .../bean/FrontEndControlCodeForTour.java | 2 +- .../bean/FrontEndControlCodeForWiper.java | 27 + ...Controller.java => ChannelController.java} | 2 +- .../controller/ChannelFrontEndController.java | 601 ++++++++++++++++++ .../service/IGbChannelControlService.java | 19 +- .../impl/GbChannelControlServiceImpl.java | 42 +- .../cmd/DeviceControlQueryMessageHandler.java | 10 +- web/src/api/commonChannel.js | 270 +++++++- 11 files changed, 943 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForWiper.java rename src/main/java/com/genersoft/iot/vmp/gb28181/controller/{CommonChannelController.java => ChannelController.java} (99%) create mode 100755 src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelFrontEndController.java diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForAuxiliary.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForAuxiliary.java index df81d3395..4dc994a40 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForAuxiliary.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForAuxiliary.java @@ -14,7 +14,7 @@ public class FrontEndControlCodeForAuxiliary implements IFrontEndControlCode { } /** - * 辅助开关控制指令: 1为开, 2为关, 3为设置自动扫描右边界, 4为设置自动扫描速度 + * 辅助开关控制指令: 1为开, 2为关 */ @Getter @Setter diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForPreset.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForPreset.java index f959ea552..8212d6aea 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForPreset.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForPreset.java @@ -27,6 +27,13 @@ public class FrontEndControlCodeForPreset implements IFrontEndControlCode { @Setter private Integer presetId; + /** + * 预置位名称 + */ + @Getter + @Setter + private String presetName; + @Override public String encode() { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForScan.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForScan.java index 3bb724437..ce16537ce 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForScan.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForScan.java @@ -14,7 +14,7 @@ public class FrontEndControlCodeForScan implements IFrontEndControlCode { } /** - * 预置位指令: 1为开始自动扫描, 2为设置自动扫描左边界, 3为设置自动扫描右边界, 4为设置自动扫描速度 + * 预置位指令: 1为开始自动扫描, 2为设置自动扫描左边界, 3为设置自动扫描右边界, 4为设置自动扫描速度, 5为停止自动扫描 */ @Getter @Setter diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForTour.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForTour.java index 2e27dc318..538ada52d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForTour.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForTour.java @@ -14,7 +14,7 @@ public class FrontEndControlCodeForTour implements IFrontEndControlCode { } /** - * 巡航指令: 1为加入巡航点, 2为删除一个巡航点, 3为设置巡航速度, 4为设置巡航停留时间, 5为开始巡航 + * 巡航指令: 1为加入巡航点, 2为删除一个巡航点, 3为设置巡航速度, 4为设置巡航停留时间, 5为开始巡航, 6为开始巡航 */ @Getter @Setter diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForWiper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForWiper.java new file mode 100644 index 000000000..9e1af0e01 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/FrontEndControlCodeForWiper.java @@ -0,0 +1,27 @@ +package com.genersoft.iot.vmp.gb28181.bean; + + +import lombok.Getter; +import lombok.Setter; + +public class FrontEndControlCodeForWiper implements IFrontEndControlCode { + + private final FrontEndControlType type = FrontEndControlType.AUXILIARY; + + @Override + public FrontEndControlType getType() { + return type; + } + + /** + * 辅助开关控制指令: 1为开, 2为关 + */ + @Getter + @Setter + private Integer code; + + @Override + public String encode() { + return ""; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelController.java similarity index 99% rename from src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java rename to src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelController.java index bb6d2fd34..8a6692235 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/CommonChannelController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelController.java @@ -41,7 +41,7 @@ import java.util.List; @RestController @Slf4j @RequestMapping(value = "/api/common/channel") -public class CommonChannelController { +public class ChannelController { @Autowired private IRedisCatchStorage redisCatchStorage; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelFrontEndController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelFrontEndController.java new file mode 100755 index 000000000..e3ff2aa29 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/ChannelFrontEndController.java @@ -0,0 +1,601 @@ +package com.genersoft.iot.vmp.gb28181.controller; + +import com.genersoft.iot.vmp.conf.exception.ControllerException; +import com.genersoft.iot.vmp.conf.security.JwtUtils; +import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.gb28181.service.IGbChannelControlService; +import com.genersoft.iot.vmp.gb28181.service.IGbChannelService; +import com.genersoft.iot.vmp.service.bean.ErrorCallback; +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; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.async.DeferredResult; + +import java.util.List; + + +@Tag(name = "全局通道前端控制") +@RestController +@Slf4j +@RequestMapping(value = "/api/common/channel/front-end") +public class ChannelFrontEndController { + + @Autowired + private IGbChannelService channelService; + + @Autowired + private IGbChannelControlService channelControlService; + + + @Operation(summary = "云台控制", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道ID", required = true) + @Parameter(name = "command", description = "控制指令,允许值: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop", required = true) + @Parameter(name = "panSpeed", description = "水平速度(0-100)", required = true) + @Parameter(name = "tiltSpeed", description = "垂直速度(0-100)", required = true) + @Parameter(name = "zoomSpeed", description = "缩放速度(0-100)", required = true) + @GetMapping("/ptz") + public DeferredResult> ptz(Integer channelId, String command, Integer panSpeed, Integer tiltSpeed, Integer zoomSpeed){ + + if (log.isDebugEnabled()) { + log.debug("[通用通道]云台控制 API调用,channelId:{} ,command:{} ,panSpeed:{} ,tiltSpeed:{} ,zoomSpeed:{}",channelId, command, panSpeed, tiltSpeed, zoomSpeed); + } + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + if (panSpeed == null) { + panSpeed = 50; + }else if (panSpeed < 0 || panSpeed > 100) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "panSpeed 为 0-100的数字"); + } + if (tiltSpeed == null) { + tiltSpeed = 50; + }else if (tiltSpeed < 0 || tiltSpeed > 100) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "tiltSpeed 为 0-100的数字"); + } + if (zoomSpeed == null) { + zoomSpeed = 50; + }else if (zoomSpeed < 0 || zoomSpeed > 100) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "zoomSpeed 为 0-100的数字"); + } + + FrontEndControlCodeForPTZ controlCode = new FrontEndControlCodeForPTZ(); + controlCode.setPanSpeed(panSpeed); + controlCode.setTiltSpeed(tiltSpeed); + controlCode.setZoomSpeed(zoomSpeed); + switch (command){ + case "left": + controlCode.setPan(0); + break; + case "right": + controlCode.setPan(1); + break; + case "up": + controlCode.setTilt(0); + break; + case "down": + controlCode.setTilt(1); + break; + case "upleft": + controlCode.setPan(0); + controlCode.setTilt(0); + break; + case "upright": + controlCode.setTilt(0); + controlCode.setPan(1); + break; + case "downleft": + controlCode.setPan(0); + controlCode.setTilt(1); + break; + case "downright": + controlCode.setTilt(1); + controlCode.setPan(1); + break; + case "zoomin": + controlCode.setZoom(1); + break; + case "zoomout": + controlCode.setZoom(0); + break; + default: + break; + } + + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + channelControlService.ptz(channel, controlCode, (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }); + return result; + } + + + @Operation(summary = "光圈控制", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "command", description = "控制指令,允许值: in, out, stop", required = true) + @Parameter(name = "speed", description = "光圈速度(0-100)", required = true) + @GetMapping("/fi/iris") + public DeferredResult> iris(Integer channelId, String command, Integer speed){ + + if (log.isDebugEnabled()) { + log.debug("[通用通道]光圈控制 API调用,channelId:{} ,command:{} ,speed:{} ",channelId, command, speed); + } + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + if (speed == null) { + speed = 50; + }else if (speed < 0 || speed > 100) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "speed 为 0-100的数字"); + } + + FrontEndControlCodeForFI controlCode = new FrontEndControlCodeForFI(); + controlCode.setIrisSpeed(speed); + + switch (command){ + case "in": + controlCode.setIris(1); + break; + case "out": + controlCode.setIris(0); + break; + default: + break; + } + + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + + channelControlService.fi(channel, controlCode, callback); + + return result; + } + + @Operation(summary = "聚焦控制", security = @SecurityRequirement(name = JwtUtils.HEADER)) + + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "command", description = "控制指令,允许值: near, far, stop", required = true) + @Parameter(name = "speed", description = "聚焦速度(0-100)", required = true) + @GetMapping("/fi/focus") + public DeferredResult> focus(Integer channelId, String command, Integer speed){ + + if (log.isDebugEnabled()) { + log.debug("[通用通道]聚焦控制 API调用,channelId:{} ,command:{} ,speed:{} ", channelId, command, speed); + } + + if (speed == null) { + speed = 50; + }else if (speed < 0 || speed > 100) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "speed 为 0-100的数字"); + } + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + FrontEndControlCodeForFI controlCode = new FrontEndControlCodeForFI(); + controlCode.setFocusSpeed(speed); + switch (command){ + case "near": + controlCode.setFocus(0); + break; + case "far": + controlCode.setFocus(1); + break; + default: + break; + } + + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + + channelControlService.fi(channel, controlCode, callback); + return result; + } + + @Operation(summary = "查询预置位", security = @SecurityRequirement(name = JwtUtils.HEADER)) + + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @GetMapping("/preset/query") + public DeferredResult>> queryPreset(Integer channelId) { + if (log.isDebugEnabled()) { + log.debug("[通用通道] 预置位查询API调用, {}", channelId); + } + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + DeferredResult>> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult> wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback> callback = (code, msg, data) -> { + WVPResult> wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + + channelControlService.queryPreset(channel, callback); + + return result; + } + + private DeferredResult> controlPreset(Integer channelId, FrontEndControlCodeForPreset controlCode) { + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + + channelControlService.preset(channel, controlCode, callback); + return result; + } + + @Operation(summary = "预置位指令-设置预置位", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "presetId", description = "预置位编号", required = true) + @Parameter(name = "presetName", description = "预置位名称", required = true) + @GetMapping("/preset/add") + public DeferredResult> addPreset(Integer channelId, Integer presetId, String presetName) { + + FrontEndControlCodeForPreset controlCode = new FrontEndControlCodeForPreset(); + controlCode.setCode(1); + controlCode.setPresetId(presetId); + controlCode.setPresetName(presetName); + + return controlPreset(channelId, controlCode); + } + + @Operation(summary = "预置位指令-调用预置位", security = @SecurityRequirement(name = JwtUtils.HEADER)) + + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "presetId", description = "预置位编号(1-100)", required = true) + @GetMapping("/preset/call") + public DeferredResult> callPreset(Integer channelId, Integer presetId) { + FrontEndControlCodeForPreset controlCode = new FrontEndControlCodeForPreset(); + controlCode.setCode(2); + controlCode.setPresetId(presetId); + + return controlPreset(channelId, controlCode); + } + + @Operation(summary = "预置位指令-删除预置位", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "presetId", description = "预置位编号(1-100)", required = true) + @GetMapping("/preset/delete") + public DeferredResult> deletePreset(Integer channelId, Integer presetId) { + + FrontEndControlCodeForPreset controlCode = new FrontEndControlCodeForPreset(); + controlCode.setCode(3); + controlCode.setPresetId(presetId); + + return controlPreset(channelId, controlCode); + } + + private DeferredResult> tourControl(Integer channelId, FrontEndControlCodeForTour controlCode) { + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + + channelControlService.tour(channel, controlCode, callback); + return result; + } + + @Operation(summary = "巡航指令-加入巡航点", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "tourId", description = "巡航组号", required = true) + @Parameter(name = "presetId", description = "预置位编号", required = true) + @GetMapping("/tour/point/add") + public DeferredResult> addTourPoint(Integer channelId, Integer tourId, Integer presetId) { + + FrontEndControlCodeForTour controlCode = new FrontEndControlCodeForTour(); + controlCode.setCode(1); + controlCode.setPresetId(presetId); + controlCode.setTourId(tourId); + + return tourControl(channelId, controlCode); + } + + @Operation(summary = "巡航指令-删除一个巡航点", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "tourId", description = "巡航组号(1-100)", required = true) + @Parameter(name = "presetId", description = "预置位编号(0-100, 为0时删除整个巡航)", required = true) + @GetMapping("/tour/point/delete") + public DeferredResult> deleteCruisePoint(Integer channelId, Integer tourId, Integer presetId) { + FrontEndControlCodeForTour controlCode = new FrontEndControlCodeForTour(); + controlCode.setCode(2); + controlCode.setPresetId(presetId); + controlCode.setTourId(tourId); + + return tourControl(channelId, controlCode); + } + + @Operation(summary = "巡航指令-设置巡航速度", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "tourId", description = "巡航组号(0-100)", required = true) + @Parameter(name = "speed", description = "巡航速度(1-4095)", required = true) + @GetMapping("/tour/speed") + public DeferredResult> setCruiseSpeed(Integer channelId, Integer tourId, Integer speed) { + FrontEndControlCodeForTour controlCode = new FrontEndControlCodeForTour(); + controlCode.setCode(3); + controlCode.setTourSpeed(speed); + controlCode.setTourId(tourId); + return tourControl(channelId, controlCode); + } + + @Operation(summary = "巡航指令-设置巡航停留时间", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "tourId", description = "巡航组号", required = true) + @Parameter(name = "time", description = "巡航停留时间(1-4095)", required = true) + @GetMapping("/tour/time") + public DeferredResult> setCruiseTime(Integer channelId, Integer tourId, Integer time) { + FrontEndControlCodeForTour controlCode = new FrontEndControlCodeForTour(); + controlCode.setCode(4); + controlCode.setTourTime(time); + controlCode.setTourId(tourId); + return tourControl(channelId, controlCode); + } + + @Operation(summary = "巡航指令-开始巡航", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "tourId", description = "巡航组号)", required = true) + @GetMapping("/tour/start") + public DeferredResult> startCruise(Integer channelId, Integer tourId) { + FrontEndControlCodeForTour controlCode = new FrontEndControlCodeForTour(); + controlCode.setCode(5); + controlCode.setTourId(tourId); + return tourControl(channelId, controlCode); + } + + @Operation(summary = "巡航指令-停止巡航", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "tourId", description = "巡航组号", required = true) + @GetMapping("/tour/stop") + public DeferredResult> stopCruise(Integer channelId, Integer tourId) { + FrontEndControlCodeForTour controlCode = new FrontEndControlCodeForTour(); + controlCode.setCode(6); + controlCode.setTourId(tourId); + return tourControl(channelId, controlCode); + } + + private DeferredResult> scanControl(Integer channelId, FrontEndControlCodeForScan controlCode) { + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + channelControlService.scan(channel, controlCode, callback); + + return result; + + } + + @Operation(summary = "扫描指令-开始自动扫描", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "scanId", description = "扫描组号(0-100)", required = true) + @GetMapping("/scan/start") + public DeferredResult> startScan(Integer channelId, Integer scanId) { + FrontEndControlCodeForScan controlCode = new FrontEndControlCodeForScan(); + controlCode.setCode(1); + controlCode.setScanId(scanId); + return scanControl(channelId, controlCode); + + } + + @Operation(summary = "扫描指令-停止自动扫描", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "scanId", description = "扫描组号(0-100)", required = true) + @GetMapping("/scan/stop") + public DeferredResult> stopScan(Integer channelId, Integer scanId) { + FrontEndControlCodeForScan controlCode = new FrontEndControlCodeForScan(); + controlCode.setCode(5); + controlCode.setScanId(scanId); + return scanControl(channelId, controlCode); + } + + @Operation(summary = "扫描指令-设置自动扫描左边界", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "scanId", description = "扫描组号(0-100)", required = true) + @GetMapping("/scan/set/left") + public DeferredResult> setScanLeft(Integer channelId, Integer scanId) { + FrontEndControlCodeForScan controlCode = new FrontEndControlCodeForScan(); + controlCode.setCode(2); + controlCode.setScanId(scanId); + return scanControl(channelId, controlCode); + } + + @Operation(summary = "扫描指令-设置自动扫描右边界", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "scanId", description = "扫描组号(0-100)", required = true) + @GetMapping("/scan/set/right") + public DeferredResult> setScanRight(Integer channelId, Integer scanId) { + FrontEndControlCodeForScan controlCode = new FrontEndControlCodeForScan(); + controlCode.setCode(3); + controlCode.setScanId(scanId); + return scanControl(channelId, controlCode); + } + + + @Operation(summary = "扫描指令-设置自动扫描速度", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "scanId", description = "扫描组号(0-100)", required = true) + @Parameter(name = "speed", description = "自动扫描速度(1-4095)", required = true) + @GetMapping("/scan/set/speed") + public DeferredResult> setScanSpeed(Integer channelId, Integer scanId, Integer speed) { + FrontEndControlCodeForScan controlCode = new FrontEndControlCodeForScan(); + controlCode.setCode(4); + controlCode.setScanId(scanId); + controlCode.setScanSpeed(speed); + return scanControl(channelId, controlCode); + } + + + @Operation(summary = "辅助开关控制指令-雨刷控制", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "command", description = "控制指令,允许值: on, off", required = true) + @GetMapping("/wiper") + public DeferredResult> wiper(Integer channelId, String command){ + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + FrontEndControlCodeForWiper controlCode = new FrontEndControlCodeForWiper(); + + switch (command){ + case "on": + controlCode.setCode(1); + break; + case "off": + controlCode.setCode(2); + break; + default: + break; + } + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + + channelControlService.wiper(channel, controlCode, callback); + + return result; + } + + @Operation(summary = "辅助开关控制指令", security = @SecurityRequirement(name = JwtUtils.HEADER)) + + @Parameter(name = "channelId", description = "通道国标编号", required = true) + @Parameter(name = "command", description = "控制指令,允许值: on, off", required = true) + @Parameter(name = "auxiliaryId", description = "开关编号", required = true) + @GetMapping("/auxiliary") + public DeferredResult> auxiliarySwitch(Integer channelId, String command, Integer auxiliaryId){ + + CommonGBChannel channel = channelService.getOne(channelId); + Assert.notNull(channel, "通道不存在"); + + FrontEndControlCodeForAuxiliary controlCode = new FrontEndControlCodeForAuxiliary(); + controlCode.setAuxiliaryId(auxiliaryId); + switch (command){ + case "on": + controlCode.setCode(1); + break; + case "off": + controlCode.setCode(2); + break; + default: + break; + } + DeferredResult> result = new DeferredResult<>(); + + result.onTimeout(()->{ + WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时"); + result.setResult(wvpResult); + }); + + ErrorCallback callback = (code, msg, data) -> { + WVPResult wvpResult = new WVPResult<>(); + wvpResult.setCode(code); + wvpResult.setMsg(msg); + wvpResult.setData(data); + result.setResult(wvpResult); + }; + channelControlService.auxiliary(channel, controlCode, callback); + return result; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelControlService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelControlService.java index c552c5b45..93f673761 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelControlService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelControlService.java @@ -1,16 +1,21 @@ package com.genersoft.iot.vmp.gb28181.service; -import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; -import com.genersoft.iot.vmp.gb28181.bean.FrontEndControlCodeForPTZ; +import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.service.bean.ErrorCallback; +import java.util.List; + public interface IGbChannelControlService { void ptz(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback); - void fi(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback); - void preset(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback); - void tour(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback); - void scan(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback); - void auxiliary(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback); + void fi(CommonGBChannel channel, FrontEndControlCodeForFI frontEndControlCode, ErrorCallback callback); + void preset(CommonGBChannel channel, FrontEndControlCodeForPreset frontEndControlCode, ErrorCallback callback); + void queryPreset(CommonGBChannel channel, FrontEndControlCodeForPreset frontEndControlCode, ErrorCallback callback); + void tour(CommonGBChannel channel, FrontEndControlCodeForTour frontEndControlCode, ErrorCallback callback); + void scan(CommonGBChannel channel, FrontEndControlCodeForScan frontEndControlCode, ErrorCallback callback); + void wiper(CommonGBChannel channel, FrontEndControlCodeForWiper controlCode, ErrorCallback callback); + void auxiliary(CommonGBChannel channel, FrontEndControlCodeForAuxiliary frontEndControlCode, ErrorCallback callback); + + void queryPreset(CommonGBChannel channel, ErrorCallback> callback); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelControlServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelControlServiceImpl.java index 4751c2eff..bae963f16 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelControlServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelControlServiceImpl.java @@ -1,43 +1,65 @@ package com.genersoft.iot.vmp.gb28181.service.impl; -import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; -import com.genersoft.iot.vmp.gb28181.bean.FrontEndControlCodeForPTZ; +import com.genersoft.iot.vmp.common.enums.ChannelDataType; +import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.service.IGbChannelControlService; import com.genersoft.iot.vmp.service.bean.ErrorCallback; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.List; + @Service @Slf4j public class GbChannelControlServiceImpl implements IGbChannelControlService { + + @Override public void ptz(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback) { - log.info("[通用通道] 云台控制, 通道: {}", channel.getGbId()); + log.info("[通用通道] 云台控制, 通道: {}", channel.getGbDeviceId()); + if (channel.getDataType() == ChannelDataType.GB28181.value) { + + }else if() } @Override - public void preset(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback) { - log.info("[通用通道] 预置位, 通道: {}", channel.getGbId()); + public void preset(CommonGBChannel channel, FrontEndControlCodeForPreset frontEndControlCode, ErrorCallback callback) { + log.info("[通用通道] 预置位, 通道: {}", channel.getGbDeviceId()); } @Override - public void fi(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback) { - log.info("[通用通道] FI指令, 通道: {}", channel.getGbId()); + public void fi(CommonGBChannel channel, FrontEndControlCodeForFI frontEndControlCode, ErrorCallback callback) { + log.info("[通用通道] FI指令, 通道: {}", channel.getGbDeviceId()); } @Override - public void tour(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback) { + public void tour(CommonGBChannel channel, FrontEndControlCodeForTour frontEndControlCode, ErrorCallback callback) { } @Override - public void scan(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback) { + public void scan(CommonGBChannel channel, FrontEndControlCodeForScan frontEndControlCode, ErrorCallback callback) { } @Override - public void auxiliary(CommonGBChannel channel, FrontEndControlCodeForPTZ frontEndControlCode, ErrorCallback callback) { + public void auxiliary(CommonGBChannel channel, FrontEndControlCodeForAuxiliary frontEndControlCode, ErrorCallback callback) { + + } + + @Override + public void queryPreset(CommonGBChannel channel, FrontEndControlCodeForPreset frontEndControlCode, ErrorCallback callback) { + + } + + @Override + public void wiper(CommonGBChannel channel, FrontEndControlCodeForWiper controlCode, ErrorCallback callback) { + + } + + @Override + public void queryPreset(CommonGBChannel channel, ErrorCallback> callback) { } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java index 8f7e036af..536bf223a 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java @@ -173,7 +173,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent })); break; case FI: - channelControlService.fi(channel, (FrontEndControlCodeForPTZ)frontEndControlCode, ((code, msg, data) -> { + channelControlService.fi(channel, (FrontEndControlCodeForFI) frontEndControlCode, ((code, msg, data) -> { try { responseAck(request, code, msg); } catch (InvalidArgumentException | SipException | ParseException exception) { @@ -182,7 +182,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent })); break; case PRESET: - channelControlService.preset(channel, (FrontEndControlCodeForPTZ)frontEndControlCode, ((code, msg, data) -> { + channelControlService.preset(channel, (FrontEndControlCodeForPreset) frontEndControlCode, ((code, msg, data) -> { try { responseAck(request, code, msg); } catch (InvalidArgumentException | SipException | ParseException exception) { @@ -191,7 +191,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent })); break; case TOUR: - channelControlService.tour(channel, (FrontEndControlCodeForPTZ)frontEndControlCode, ((code, msg, data) -> { + channelControlService.tour(channel, (FrontEndControlCodeForTour) frontEndControlCode, ((code, msg, data) -> { try { responseAck(request, code, msg); } catch (InvalidArgumentException | SipException | ParseException exception) { @@ -200,7 +200,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent })); break; case SCAN: - channelControlService.scan(channel, (FrontEndControlCodeForPTZ)frontEndControlCode, ((code, msg, data) -> { + channelControlService.scan(channel, (FrontEndControlCodeForScan) frontEndControlCode, ((code, msg, data) -> { try { responseAck(request, code, msg); } catch (InvalidArgumentException | SipException | ParseException exception) { @@ -209,7 +209,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent })); break; case AUXILIARY: - channelControlService.auxiliary(channel, (FrontEndControlCodeForPTZ)frontEndControlCode, ((code, msg, data) -> { + channelControlService.auxiliary(channel, (FrontEndControlCodeForAuxiliary) frontEndControlCode, ((code, msg, data) -> { try { responseAck(request, code, msg); } catch (InvalidArgumentException | SipException | ParseException exception) { diff --git a/web/src/api/commonChannel.js b/web/src/api/commonChannel.js index 38163c5e9..0d613547a 100644 --- a/web/src/api/commonChannel.js +++ b/web/src/api/commonChannel.js @@ -63,7 +63,7 @@ export function getList(params) { const { page, count, query, online, hasRecordPlan, channelType } = params return request({ method: 'get', - url: `/api/common/channel/list`, + url: '/api/common/channel/list', params: { page: page, count: count, @@ -79,7 +79,7 @@ export function getCivilCodeList(params) { const { page, count, channelType, query, online, civilCode } = params return request({ method: 'get', - url: `/api/common/channel/civilcode/list`, + url: '/api/common/channel/civilcode/list', params: { page: page, count: count, @@ -95,7 +95,7 @@ export function getUnusualCivilCodeList(params) { const { page, count, channelType, query, online } = params return request({ method: 'get', - url: `/api/common/channel/civilCode/unusual/list`, + url: '/api/common/channel/civilCode/unusual/list', params: { page: page, count: count, @@ -110,7 +110,7 @@ export function getUnusualParentList(params) { const { page, count, channelType, query, online } = params return request({ method: 'get', - url: `/api/common/channel/parent/unusual/list`, + url: '/api/common/channel/parent/unusual/list', params: { page: page, count: count, @@ -125,7 +125,7 @@ export function clearUnusualCivilCodeList(params) { const { all, channelIds } = params return request({ method: 'post', - url: `/api/common/channel/civilCode/unusual/clear`, + url: '/api/common/channel/civilCode/unusual/clear', data: { all: all, channelIds: channelIds @@ -137,7 +137,7 @@ export function clearUnusualParentList(params) { const { all, channelIds } = params return request({ method: 'post', - url: `/api/common/channel/parent/unusual/clear`, + url: '/api/common/channel/parent/unusual/clear', data: { all: all, channelIds: channelIds @@ -149,7 +149,7 @@ export function getParentList(params) { const { page, count, channelType, query, online, groupDeviceId } = params return request({ method: 'get', - url: `/api/common/channel/parent/list`, + url: '/api/common/channel/parent/list', params: { page: page, count: count, @@ -165,7 +165,7 @@ export function addToRegion(params) { const { civilCode, channelIds } = params return request({ method: 'post', - url: `/api/common/channel/region/add`, + url: '/api/common/channel/region/add', data: { civilCode: civilCode, channelIds: channelIds @@ -176,7 +176,7 @@ export function addToRegion(params) { export function deleteFromRegion(channels) { return request({ method: 'post', - url: `/api/common/channel/region/delete`, + url: '/api/common/channel/region/delete', data: { channelIds: channels } @@ -187,7 +187,7 @@ export function addDeviceToRegion(params) { const { civilCode, deviceIds } = params return request({ method: 'post', - url: `/api/common/channel/region/device/add`, + url: '/api/common/channel/region/device/add', data: { civilCode: civilCode, deviceIds: deviceIds @@ -198,7 +198,7 @@ export function addDeviceToRegion(params) { export function deleteDeviceFromRegion(deviceIds) { return request({ method: 'post', - url: `/api/common/channel/region/device/delete`, + url: '/api/common/channel/region/device/delete', data: { deviceIds: deviceIds } @@ -209,7 +209,7 @@ export function addToGroup(params) { const { parentId, businessGroup, channelIds } = params return request({ method: 'post', - url: `/api/common/channel/group/add`, + url: '/api/common/channel/group/add', data: { parentId: parentId, businessGroup: businessGroup, @@ -221,7 +221,7 @@ export function addToGroup(params) { export function deleteFromGroup(channels) { return request({ method: 'post', - url: `/api/common/channel/group/delete`, + url: '/api/common/channel/group/delete', data: { channelIds: channels } @@ -232,7 +232,7 @@ export function addDeviceToGroup(params) { const { parentId, businessGroup, deviceIds } = params return request({ method: 'post', - url: `/api/common/channel/group/device/add`, + url: '/api/common/channel/group/device/add', data: { parentId: parentId, businessGroup: businessGroup, @@ -244,7 +244,7 @@ export function addDeviceToGroup(params) { export function deleteDeviceFromGroup(deviceIds) { return request({ method: 'post', - url: `/api/common/channel/group/device/delete`, + url: '/api/common/channel/group/device/delete', data: { deviceIds: deviceIds } @@ -260,3 +260,243 @@ export function playChannel(channelId) { } }) } + + +// 前端控制 + +export function setSpeedForScan({ channelId, scanId, speed }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/scan/set/speed', + params: { + channelId: channelId, + scanId: scanId, + speed: speed + } + }) +} + +export function setLeftForScan({ channelId, scanId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/scan/set/left', + params: { + channelId: channelId, + scanId: scanId + } + }) +} + +export function setRightForScan({ channelId, scanId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/scan/set/right', + params: { + channelId: channelId, + scanId: scanId + } + + }) +} + +export function startScan({ channelId, scanId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/scan/start', + params: { + channelId: channelId, + scanId: scanId + } + }) +} + +export function stopScan({ channelId, scanId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/scan/stop', + params: { + channelId: channelId, + scanId: scanId + } + + }) +} + +export function queryPreset(channelId) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/preset/query', + params: { + channelId: channelId + } + }) +} + +export function addPointForCruise({ channelId, cruiseId, presetId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/cruise/point/add', + params: { + channelId: channelId, + cruiseId: cruiseId, + presetId: presetId + } + }) +} + +export function deletePointForCruise({ channelId, cruiseId, presetId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/cruise/point/delete', + params: { + channelId: channelId, + cruiseId: cruiseId, + presetId: presetId + } + }) +} + +export function setCruiseSpeed({ channelId, cruiseId, cruiseSpeed }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/cruise/speed', + params: { + channelId: channelId, + cruiseId: cruiseId, + speed: cruiseSpeed + } + }) +} + +export function setCruiseTime({ channelId, cruiseId, cruiseTime }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/cruise/time', + params: { + channelId: channelId, + cruiseId: cruiseId, + time: cruiseTime + } + }) +} + +export function startCruise({ channelId, cruiseId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/cruise/start', + params: { + channelId: channelId, + cruiseId: cruiseId + } + }) +} + +export function stopCruise({ channelId, cruiseId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/cruise/stop', + params: { + channelId: channelId, + cruiseId: cruiseId + } + }) +} + +export function addPreset({ channelId, presetId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/preset/add', + params: { + channelId: channelId, + presetId: presetId + } + }) +} + +export function callPreset({ channelId, presetId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/preset/call', + params: { + channelId: channelId, + presetId: presetId + } + }) +} + +export function deletePreset({ channelId, presetId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/preset/delete', + params: { + channelId: channelId, + presetId: presetId + } + }) +} + +/** + * command: on 开启, off 关闭 + */ +export function auxiliary({ channelId, command, switchId }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/auxiliary', + params: { + channelId: channelId, + command: command, + switchId: switchId + } + }) +} +/** + * command: on 开启, off 关闭 + */ +export function wiper({ channelId, command }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/wiper', + params: { + channelId: channelId, + command: command + } + }) +} + +export function ptz({ channelId, command, horizonSpeed, verticalSpeed, zoomSpeed }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/ptz', + params: { + channelId: channelId, + command: command, + horizonSpeed: horizonSpeed, + verticalSpeed: verticalSpeed, + zoomSpeed: zoomSpeed + } + }) +} + +export function iris({ channelId, command, speed }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/fi/iris', + params: { + channelId: channelId, + command: command, + speed: speed + } + }) +} + +export function focus({ channelId, command, speed }) { + return request({ + method: 'get', + url: '/api/common/channel/front-end/fi/focus', + params: { + channelId: channelId, + command: command, + speed: speed + } + }) +}