[集群] 增加强制关键帧/看守位控制/拉框放大缩小/设备状态查询
parent
71390a7b51
commit
c38c4e3979
|
@ -16,6 +16,7 @@ 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.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;
|
||||
|
@ -102,7 +103,7 @@ public class DeviceConfig {
|
|||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "configType", description = "配置类型")
|
||||
@GetMapping("/query/{deviceId}/{configType}")
|
||||
public DeferredResult<String> configDownloadApi(@PathVariable String deviceId,
|
||||
public DeferredResult<WVPResult<String>> configDownloadApi(@PathVariable String deviceId,
|
||||
@PathVariable String configType,
|
||||
@RequestParam(required = false) String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
|
@ -111,15 +112,11 @@ public class DeviceConfig {
|
|||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
Assert.notNull(device, "设备不存在");
|
||||
|
||||
DeferredResult<String> result = deviceService.deviceConfigQuery(device, channelId, configType);
|
||||
DeferredResult<WVPResult<String>> result = deviceService.deviceConfigQuery(device, channelId, configType);
|
||||
|
||||
result.onTimeout(() -> {
|
||||
log.warn("获取设备配置超时");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", device.getDeviceId());
|
||||
json.put("Status", "Timeout");
|
||||
json.put("Description", "操作超时");
|
||||
result.setResult(json.toString());
|
||||
log.warn("[获取设备配置] 超时, {}", device.getDeviceId());
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "超时"));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -78,17 +78,17 @@ public class DeviceControl {
|
|||
@Parameter(name = "channelId", description = "通道国标编号", required = true)
|
||||
@Parameter(name = "recordCmdStr", description = "命令, 可选值:Record(手动录像),StopRecord(停止手动录像)", required = true)
|
||||
@GetMapping("/record/{deviceId}/{recordCmdStr}")
|
||||
public DeferredResult<String> recordApi(@PathVariable String deviceId,
|
||||
public DeferredResult<WVPResult<String>> recordApi(@PathVariable String deviceId,
|
||||
@PathVariable String recordCmdStr, String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("开始/停止录像API调用");
|
||||
}
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
Assert.notNull(device, "设备不存在");
|
||||
DeferredResult<String> result = deviceService.record(device, channelId, recordCmdStr);
|
||||
DeferredResult<WVPResult<String>> result = deviceService.record(device, channelId, recordCmdStr);
|
||||
result.onTimeout(() -> {
|
||||
log.warn("[开始/停止录像] 操作超时, 设备未返回应答指令, {}", deviceId);
|
||||
result.setResult("操作超时, 设备未应答");
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
@ -156,23 +156,14 @@ public class DeviceControl {
|
|||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "channelId", description = "通道国标编号")
|
||||
@GetMapping("/i_frame/{deviceId}")
|
||||
public JSONObject iFrame(@PathVariable String deviceId,
|
||||
public void iFrame(@PathVariable String deviceId,
|
||||
@RequestParam(required = false) String channelId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("强制关键帧API调用");
|
||||
}
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
try {
|
||||
cmder.iFrameCmd(device, channelId);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 强制关键帧: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", deviceId);
|
||||
json.put("ChannelID", channelId);
|
||||
json.put("Result", "OK");
|
||||
return json;
|
||||
Assert.notNull(device, "设备不存在");
|
||||
deviceService.iFrame(device, channelId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,34 +186,15 @@ public class DeviceControl {
|
|||
@RequestParam(required = false) Integer resetTime,
|
||||
@RequestParam(required = false) Integer presetIndex) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("报警复位API调用");
|
||||
log.debug("看守位控制API调用");
|
||||
}
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
try {
|
||||
cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("操作失败,错误码: %s, %s", event.statusCode, event.msg)));
|
||||
resultHolder.invokeResult(msg);
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 看守位控制: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(3 * 1000L);
|
||||
Assert.notNull(device, "设备不存在");
|
||||
DeferredResult<WVPResult<String>> result = deviceService.homePosition(device, channelId, enabled, resetTime, presetIndex);
|
||||
result.onTimeout(() -> {
|
||||
log.warn(String.format("看守位控制操作超时, 设备未返回应答指令"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答")); //("看守位控制操作超时, 设备未返回应答指令");
|
||||
resultHolder.invokeResult(msg);
|
||||
log.warn("[看守位控制] 操作超时, 设备未返回应答指令, {}", deviceId);
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
});
|
||||
resultHolder.put(key, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -259,21 +231,8 @@ public class DeviceControl {
|
|||
log.debug(String.format("设备拉框放大 API调用,deviceId:%s ,channelId:%s ,length:%d ,width:%d ,midpointx:%d ,midpointy:%d ,lengthx:%d ,lengthy:%d",deviceId, channelId, length, width, midpointx, midpointy,lengthx, lengthy));
|
||||
}
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<DragZoomIn>\r\n");
|
||||
cmdXml.append("<Length>" + length+ "</Length>\r\n");
|
||||
cmdXml.append("<Width>" + width+ "</Width>\r\n");
|
||||
cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n");
|
||||
cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n");
|
||||
cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n");
|
||||
cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n");
|
||||
cmdXml.append("</DragZoomIn>\r\n");
|
||||
try {
|
||||
cmder.dragZoomCmd(device, channelId, cmdXml.toString());
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 拉框放大: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
Assert.notNull(device, "设备不存在");
|
||||
deviceService.dragZoomIn(device, channelId, length, width, midpointx, midpointy, lengthx,lengthy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,20 +270,7 @@ public class DeviceControl {
|
|||
log.debug(String.format("设备拉框缩小 API调用,deviceId:%s ,channelId:%s ,length:%d ,width:%d ,midpointx:%d ,midpointy:%d ,lengthx:%d ,lengthy:%d",deviceId, channelId, length, width, midpointx, midpointy,lengthx, lengthy));
|
||||
}
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<DragZoomOut>\r\n");
|
||||
cmdXml.append("<Length>" + length+ "</Length>\r\n");
|
||||
cmdXml.append("<Width>" + width+ "</Width>\r\n");
|
||||
cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n");
|
||||
cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n");
|
||||
cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n");
|
||||
cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n");
|
||||
cmdXml.append("</DragZoomOut>\r\n");
|
||||
try {
|
||||
cmder.dragZoomCmd(device, channelId, cmdXml.toString());
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 拉框缩小: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
Assert.notNull(device, "设备不存在");
|
||||
deviceService.dragZoomOut(device, channelId, length, width, midpointx, midpointy, lengthx,lengthy);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -312,40 +312,18 @@ public class DeviceQuery {
|
|||
@Operation(summary = "设备状态查询", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/devices/{deviceId}/status")
|
||||
public DeferredResult<ResponseEntity<String>> deviceStatusApi(@PathVariable String deviceId) {
|
||||
public DeferredResult<WVPResult<String>> deviceStatusApi(@PathVariable String deviceId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("设备状态查询API调用");
|
||||
}
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId;
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L);
|
||||
if(device == null) {
|
||||
result.setResult(new ResponseEntity(String.format("设备%s不存在", deviceId),HttpStatus.OK));
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
cmder.deviceStatusQuery(device, event -> {
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
resultHolder.invokeResult(msg);
|
||||
Assert.notNull(device, "设备不存在");
|
||||
|
||||
DeferredResult<WVPResult<String>> result = deviceService.deviceStatus(device);
|
||||
result.onTimeout(() -> {
|
||||
log.warn("[设备状态查询] 操作超时, 设备未返回应答指令, {}", deviceId);
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取设备状态: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
result.onTimeout(()->{
|
||||
log.warn(String.format("获取设备状态超时"));
|
||||
// 释放rtpserver
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
msg.setKey(key);
|
||||
msg.setData("Timeout. Device did not response to this command.");
|
||||
resultHolder.invokeResult(msg);
|
||||
});
|
||||
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId, uuid, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -369,7 +347,7 @@ public class DeviceQuery {
|
|||
@Parameter(name = "startTime", description = "报警发生起始时间")
|
||||
@Parameter(name = "endTime", description = "报警发生终止时间")
|
||||
@GetMapping("/alarm/{deviceId}")
|
||||
public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId,
|
||||
public DeferredResult<WVPResult<String>> alarmApi(@PathVariable String deviceId,
|
||||
@RequestParam(required = false) String startPriority,
|
||||
@RequestParam(required = false) String endPriority,
|
||||
@RequestParam(required = false) String alarmMethod,
|
||||
|
@ -380,6 +358,16 @@ public class DeviceQuery {
|
|||
log.debug("设备报警查询API调用");
|
||||
}
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
Assert.notNull(device, "设备不存在");
|
||||
|
||||
DeferredResult<WVPResult<String>> result = deviceService.deviceStatus(device);
|
||||
result.onTimeout(() -> {
|
||||
log.warn("[设备报警查询] 操作超时, 设备未返回应答指令, {}", deviceId);
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
});
|
||||
return result;
|
||||
|
||||
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId;
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
try {
|
||||
|
|
|
@ -170,15 +170,26 @@ public interface IDeviceService {
|
|||
|
||||
WVPResult<SyncStatus> devicesSync(Device device);
|
||||
|
||||
DeferredResult<String> deviceBasicConfig(Device device, String channelId, String name, String expiration, String heartBeatInterval, String heartBeatCount);
|
||||
DeferredResult<WVPResult<String>> deviceBasicConfig(Device device, String channelId, String name, String expiration, String heartBeatInterval, String heartBeatCount);
|
||||
|
||||
DeferredResult<String> deviceConfigQuery(Device device, String channelId, String configType);
|
||||
DeferredResult<WVPResult<String>> deviceConfigQuery(Device device, String channelId, String configType);
|
||||
|
||||
void teleboot(Device device);
|
||||
|
||||
DeferredResult<String> record(Device device, String channelId, String recordCmdStr);
|
||||
DeferredResult<WVPResult<String>> record(Device device, String channelId, String recordCmdStr);
|
||||
|
||||
DeferredResult<WVPResult<String>> guard(Device device, String guardCmdStr);
|
||||
|
||||
DeferredResult<WVPResult<String>> resetAlarm(Device device, String channelId, String alarmMethod, String alarmType);
|
||||
|
||||
void iFrame(Device device, String channelId);
|
||||
|
||||
DeferredResult<WVPResult<String>> homePosition(Device device, String channelId, Boolean enabled, Integer resetTime, Integer presetIndex);
|
||||
|
||||
void dragZoomIn(Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy);
|
||||
|
||||
void dragZoomOut(Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy);
|
||||
|
||||
DeferredResult<WVPResult<String>> deviceStatus(Device device);
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.github.pagehelper.PageHelper;
|
|||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -493,9 +494,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||
@Transactional
|
||||
public boolean delete(String deviceId) {
|
||||
Device device = getDeviceByDeviceIdFromDb(deviceId);
|
||||
if (device == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId);
|
||||
}
|
||||
Assert.notNull(device, "未找到设备");
|
||||
platformChannelMapper.delChannelForDeviceId(deviceId);
|
||||
deviceChannelMapper.cleanChannelsByDeviceId(device.getId());
|
||||
deviceMapper.del(deviceId);
|
||||
|
@ -619,7 +618,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||
// 已存在则返回进度
|
||||
if (isSyncRunning(device.getDeviceId())) {
|
||||
SyncStatus channelSyncStatus = getChannelSyncStatus(device.getDeviceId());
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
WVPResult<SyncStatus> wvpResult = new WVPResult();
|
||||
if (channelSyncStatus.getErrorMsg() != null) {
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg(channelSyncStatus.getErrorMsg());
|
||||
|
@ -641,46 +640,46 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<String> deviceBasicConfig(Device device, String channelId, String name, String expiration,
|
||||
public DeferredResult<WVPResult<String>> deviceBasicConfig(Device device, String channelId, String name, String expiration,
|
||||
String heartBeatInterval, String heartBeatCount) {
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
String result = redisRpcService.deviceBasicConfig(device.getServerId(), device, channelId, name, expiration,
|
||||
WVPResult<String> result = redisRpcService.deviceBasicConfig(device.getServerId(), device, channelId, name, expiration,
|
||||
heartBeatInterval, heartBeatCount);
|
||||
DeferredResult<String> deferredResult = new DeferredResult<String>(3 * 1000L);
|
||||
DeferredResult<WVPResult<String>> deferredResult = new DeferredResult<>(3 * 1000L);
|
||||
deferredResult.setResult(result);
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
DeferredResult<String> result = new DeferredResult<String>(3 * 1000L);
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(3 * 1000L);
|
||||
try {
|
||||
sipCommander.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> {
|
||||
result.setResult(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时"));
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 设备配置: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<String> deviceConfigQuery(Device device, String channelId, String configType) {
|
||||
public DeferredResult<WVPResult<String>> deviceConfigQuery(Device device, String channelId, String configType) {
|
||||
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
String result = redisRpcService.deviceConfigQuery(device.getServerId(), device, channelId, configType);
|
||||
DeferredResult<String> deferredResult = new DeferredResult<String>(3 * 1000L);
|
||||
WVPResult<String> result = redisRpcService.deviceConfigQuery(device.getServerId(), device, channelId, configType);
|
||||
DeferredResult<WVPResult<String>> deferredResult = new DeferredResult<>(3 * 1000L);
|
||||
deferredResult.setResult(result);
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
DeferredResult<String> result = new DeferredResult<String>(3 * 1000L);
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(3 * 1000L);
|
||||
try {
|
||||
sipCommander.deviceConfigQuery(device, channelId, configType, event -> {
|
||||
result.setResult(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100));
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取设备配置: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -700,23 +699,23 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<String> record(Device device, String channelId, String recordCmdStr) {
|
||||
public DeferredResult<WVPResult<String>> record(Device device, String channelId, String recordCmdStr) {
|
||||
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
String result = redisRpcService.recordControl(device.getServerId(), device, channelId, recordCmdStr);
|
||||
DeferredResult<String> deferredResult = new DeferredResult<String>(3 * 1000L);
|
||||
WVPResult<String> result = redisRpcService.recordControl(device.getServerId(), device, channelId, recordCmdStr);
|
||||
DeferredResult<WVPResult<String>> deferredResult = new DeferredResult<>(3 * 1000L);
|
||||
deferredResult.setResult(result);
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(3 * 1000L);
|
||||
try {
|
||||
sipCommander.recordCmd(device, channelId, recordCmdStr, event -> {
|
||||
result.setResult(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg)));
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 开始/停止录像: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -765,4 +764,111 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iFrame(Device device, String channelId) {
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
redisRpcService.iFrame(device.getServerId(), device, channelId);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
sipCommander.iFrameCmd(device, channelId);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 强制关键帧操作: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<WVPResult<String>> homePosition(Device device, String channelId, Boolean enabled, Integer resetTime, Integer presetIndex) {
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
WVPResult<String> result = redisRpcService.homePosition(device.getServerId(), device, channelId, enabled, resetTime, presetIndex);
|
||||
DeferredResult<WVPResult<String>> deferredResult = new DeferredResult<>(3 * 1000L);
|
||||
deferredResult.setResult(result);
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(3 * 1000L);
|
||||
|
||||
try {
|
||||
sipCommander.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("操作失败,错误码: %s, %s", event.statusCode, event.msg)));
|
||||
},null);
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 看守位控制: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragZoomIn(Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy) {
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
redisRpcService.dragZoomIn(device.getServerId(), device, channelId, length, width, midpointx, midpointy, lengthx, lengthy);
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<DragZoomIn>\r\n");
|
||||
cmdXml.append("<Length>" + length+ "</Length>\r\n");
|
||||
cmdXml.append("<Width>" + width+ "</Width>\r\n");
|
||||
cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n");
|
||||
cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n");
|
||||
cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n");
|
||||
cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n");
|
||||
cmdXml.append("</DragZoomIn>\r\n");
|
||||
try {
|
||||
sipCommander.dragZoomCmd(device, channelId, cmdXml.toString());
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 拉框放大: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragZoomOut(Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy) {
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
redisRpcService.dragZoomOut(device.getServerId(), device, channelId, length, width, midpointx, midpointy, lengthx, lengthy);
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<DragZoomOut>\r\n");
|
||||
cmdXml.append("<Length>" + length+ "</Length>\r\n");
|
||||
cmdXml.append("<Width>" + width+ "</Width>\r\n");
|
||||
cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n");
|
||||
cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n");
|
||||
cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n");
|
||||
cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n");
|
||||
cmdXml.append("</DragZoomOut>\r\n");
|
||||
try {
|
||||
sipCommander.dragZoomCmd(device, channelId, cmdXml.toString());
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 拉框放大: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<WVPResult<String>> deviceStatus(Device device) {
|
||||
|
||||
if (!userSetting.getServerId().equals(device.getServerId())) {
|
||||
WVPResult<String> result = redisRpcService.deviceStatus(device.getServerId(), device);
|
||||
DeferredResult<WVPResult<String>> deferredResult = new DeferredResult<>(3 * 1000L);
|
||||
deferredResult.setResult(result);
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(2*1000L);
|
||||
try {
|
||||
sipCommander.deviceStatusQuery(device, event -> {
|
||||
result.setResult(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("操作失败,错误码: %s, %s", event.statusCode, event.msg)));
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
log.error("[命令发送失败] 获取设备状态: {}", e.getMessage());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,13 +40,25 @@ public interface IRedisRpcService {
|
|||
|
||||
SyncStatus getChannelSyncStatus(String serverId, String deviceId);
|
||||
|
||||
String deviceBasicConfig(String serverId, Device device, String channelId, String name, String expiration, String heartBeatInterval, String heartBeatCount);
|
||||
WVPResult<String> deviceBasicConfig(String serverId, Device device, String channelId, String name, String expiration, String heartBeatInterval, String heartBeatCount);
|
||||
|
||||
String deviceConfigQuery(String serverId, Device device, String channelId, String configType);
|
||||
WVPResult<String> deviceConfigQuery(String serverId, Device device, String channelId, String configType);
|
||||
|
||||
void teleboot(String serverId, Device device);
|
||||
|
||||
String recordControl(String serverId, Device device, String channelId, String recordCmdStr);
|
||||
WVPResult<String> recordControl(String serverId, Device device, String channelId, String recordCmdStr);
|
||||
|
||||
WVPResult<String> guard(String serverId, Device device, String guardCmdStr);
|
||||
|
||||
WVPResult<String> resetAlarm(String serverId, Device device, String channelId, String alarmMethod, String alarmType);
|
||||
|
||||
void iFrame(String serverId, Device device, String channelId);
|
||||
|
||||
WVPResult<String> homePosition(String serverId, Device device, String channelId, Boolean enabled, Integer resetTime, Integer presetIndex);
|
||||
|
||||
void dragZoomIn(String serverId, Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy);
|
||||
|
||||
void dragZoomOut(String serverId, Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy);
|
||||
|
||||
WVPResult<String> deviceStatus(String serverId, Device device);
|
||||
}
|
||||
|
|
|
@ -107,22 +107,18 @@ public class RedisRpcDeviceController extends RpcController {
|
|||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
DeferredResult<String> deferredResult = deviceService.deviceBasicConfig(device, channelId, name, expiration, heartBeatInterval, heartBeatInterval);
|
||||
DeferredResult<WVPResult<String>> deferredResult = deviceService.deviceBasicConfig(device, channelId, name,
|
||||
expiration, heartBeatInterval, heartBeatInterval);
|
||||
deferredResult.onCompletion(() ->{
|
||||
String resultStr = (String)deferredResult.getResult();
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(resultStr);
|
||||
response.setBody(deferredResult.getResult());
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn(String.format("设备配置操作超时, 设备未返回应答指令"));
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", device.getDeviceId());
|
||||
json.put("Status", "Timeout");
|
||||
json.put("Description", "设备配置操作超时, 设备未返回应答指令");
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(json);
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
|
@ -144,22 +140,17 @@ public class RedisRpcDeviceController extends RpcController {
|
|||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
DeferredResult<String> deferredResult = deviceService.deviceConfigQuery(device, channelId, configType);
|
||||
DeferredResult<WVPResult<String>> deferredResult = deviceService.deviceConfigQuery(device, channelId, configType);
|
||||
deferredResult.onCompletion(() ->{
|
||||
String resultStr = (String)deferredResult.getResult();
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(resultStr);
|
||||
response.setBody(deferredResult.getResult());
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn(String.format("设备配置操作超时, 设备未返回应答指令"));
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", device.getDeviceId());
|
||||
json.put("Status", "Timeout");
|
||||
json.put("Description", "设备配置操作超时, 设备未返回应答指令");
|
||||
log.warn("[设备配置]操作超时, 设备未返回应答指令, {}", deviceId);
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(json);
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "超时"));
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
|
@ -182,11 +173,11 @@ public class RedisRpcDeviceController extends RpcController {
|
|||
deviceService.teleboot(device);
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(e.getMsg());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
return response;
|
||||
}
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(ErrorCode.SUCCESS.getMsg());
|
||||
response.setBody(WVPResult.success());
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -206,28 +197,22 @@ public class RedisRpcDeviceController extends RpcController {
|
|||
return response;
|
||||
}
|
||||
try {
|
||||
DeferredResult<String> deferredResult = deviceService.record(device, channelId, recordCmdStr);
|
||||
DeferredResult<WVPResult<String>> deferredResult = deviceService.record(device, channelId, recordCmdStr);
|
||||
deferredResult.onCompletion(() ->{
|
||||
String resultStr = (String)deferredResult.getResult();
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(resultStr);
|
||||
response.setBody(deferredResult.getResult());
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn("设备录像控制操作超时, 设备未返回应答指令");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", device.getDeviceId());
|
||||
json.put("Status", "Timeout");
|
||||
json.put("Description", "设备录像控制操作超时, 设备未返回应答指令");
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(json);
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(e.getMsg());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
|
@ -256,7 +241,7 @@ public class RedisRpcDeviceController extends RpcController {
|
|||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn("设备录像控制操作超时, 设备未返回应答指令");
|
||||
log.warn("[布防/撤防]操作超时, 设备未返回应答指令");
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
// 手动发送结果
|
||||
|
@ -264,12 +249,210 @@ public class RedisRpcDeviceController extends RpcController {
|
|||
});
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(e.getMsg());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("resetAlarm")
|
||||
public RedisRpcResponse resetAlarm(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
String alarmMethod = paramJson.getString("alarmMethod");
|
||||
String alarmType = paramJson.getString("alarmType");
|
||||
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
if (device == null || !userSetting.getServerId().equals(device.getServerId())) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
DeferredResult<WVPResult<String>> deferredResult = deviceService.resetAlarm(device, channelId, alarmMethod, alarmType);
|
||||
deferredResult.onCompletion(() ->{
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(deferredResult.getResult());
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn("[报警重置] 操作超时, 设备未返回应答指令");
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("iFrame")
|
||||
public RedisRpcResponse iFrame(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
if (device == null || !userSetting.getServerId().equals(device.getServerId())) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
deviceService.iFrame(device, channelId);
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("homePosition")
|
||||
public RedisRpcResponse homePosition(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
|
||||
Boolean enabled = paramJson.getBoolean("enabled");
|
||||
Integer resetTime = paramJson.getInteger("resetTime");
|
||||
Integer presetIndex = paramJson.getInteger("presetIndex");
|
||||
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
if (device == null || !userSetting.getServerId().equals(device.getServerId())) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
DeferredResult<WVPResult<String>> deferredResult = deviceService.homePosition(device, channelId, enabled, resetTime, presetIndex);
|
||||
deferredResult.onCompletion(() ->{
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(deferredResult.getResult());
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn("[看守位控制] 操作超时, 设备未返回应答指令");
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("dragZoomIn")
|
||||
public RedisRpcResponse dragZoomIn(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
Integer length = paramJson.getInteger("length");
|
||||
Integer width = paramJson.getInteger("width");
|
||||
Integer midpointx = paramJson.getInteger("midpointx");
|
||||
Integer midpointy = paramJson.getInteger("midpointy");
|
||||
Integer lengthx = paramJson.getInteger("lengthx");
|
||||
Integer lengthy = paramJson.getInteger("lengthy");
|
||||
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
if (device == null || !userSetting.getServerId().equals(device.getServerId())) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
deviceService.dragZoomIn(device, channelId, length, width, midpointx, midpointy, lengthx, lengthy);
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("dragZoomOut")
|
||||
public RedisRpcResponse dragZoomOut(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
Integer length = paramJson.getInteger("length");
|
||||
Integer width = paramJson.getInteger("width");
|
||||
Integer midpointx = paramJson.getInteger("midpointx");
|
||||
Integer midpointy = paramJson.getInteger("midpointy");
|
||||
Integer lengthx = paramJson.getInteger("lengthx");
|
||||
Integer lengthy = paramJson.getInteger("lengthy");
|
||||
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
if (device == null || !userSetting.getServerId().equals(device.getServerId())) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
deviceService.dragZoomOut(device, channelId, length, width, midpointx, midpointy, lengthx, lengthy);
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("deviceStatus")
|
||||
public RedisRpcResponse deviceStatus(RedisRpcRequest request) {
|
||||
String deviceId = request.getParam().toString();
|
||||
|
||||
Device device = deviceService.getDeviceByDeviceId(deviceId);
|
||||
|
||||
RedisRpcResponse response = request.getResponse();
|
||||
if (device == null || !userSetting.getServerId().equals(device.getServerId())) {
|
||||
response.setStatusCode(ErrorCode.ERROR400.getCode());
|
||||
response.setBody("param error");
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
DeferredResult<WVPResult<String>> deferredResult = deviceService.deviceStatus(device);
|
||||
deferredResult.onCompletion(() ->{
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(deferredResult.getResult());
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
deferredResult.onTimeout(() -> {
|
||||
log.warn("[获取设备状态] 操作超时, 设备未返回应答指令");
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答"));
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
}catch (ControllerException e) {
|
||||
response.setStatusCode(e.getCode());
|
||||
response.setBody(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMsg()));
|
||||
sendResponse(response);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String deviceBasicConfig(String serverId, Device device, String channelId, String name, String expiration,
|
||||
public WVPResult<String> deviceBasicConfig(String serverId, Device device, String channelId, String name, String expiration,
|
||||
String heartBeatInterval, String heartBeatCount) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
|
@ -279,11 +279,11 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
|||
RedisRpcRequest request = buildRequest("device/deviceBasicConfig", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return response.getBody().toString();
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deviceConfigQuery(String serverId, Device device, String channelId, String configType) {
|
||||
public WVPResult<String> deviceConfigQuery(String serverId, Device device, String channelId, String configType) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
|
@ -291,7 +291,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
|||
RedisRpcRequest request = buildRequest("device/deviceConfigQuery", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return response.getBody().toString();
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -305,7 +305,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String recordControl(String serverId, Device device, String channelId, String recordCmdStr) {
|
||||
public WVPResult<String> recordControl(String serverId, Device device, String channelId, String recordCmdStr) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
|
@ -313,7 +313,7 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
|||
RedisRpcRequest request = buildRequest("device/record", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return response.getBody().toString();
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -326,4 +326,82 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
|||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WVPResult<String> resetAlarm(String serverId, Device device, String channelId, String alarmMethod, String alarmType) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
jsonObject.put("alarmMethod", alarmMethod);
|
||||
jsonObject.put("alarmType", alarmType);
|
||||
RedisRpcRequest request = buildRequest("device/resetAlarm", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iFrame(String serverId, Device device, String channelId) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
RedisRpcRequest request = buildRequest("device/iFrame", jsonObject);
|
||||
request.setToId(serverId);
|
||||
redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WVPResult<String> homePosition(String serverId, Device device, String channelId, Boolean enabled, Integer resetTime, Integer presetIndex) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
jsonObject.put("enabled", enabled);
|
||||
jsonObject.put("resetTime", resetTime);
|
||||
jsonObject.put("presetIndex", presetIndex);
|
||||
RedisRpcRequest request = buildRequest("device/homePosition", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragZoomIn(String serverId, Device device, String channelId, int length, int width, int midpointx,
|
||||
int midpointy, int lengthx, int lengthy) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
jsonObject.put("length", length);
|
||||
jsonObject.put("width", width);
|
||||
jsonObject.put("midpointx", midpointx);
|
||||
jsonObject.put("midpointy", midpointy);
|
||||
jsonObject.put("lengthx", lengthx);
|
||||
jsonObject.put("lengthy", lengthy);
|
||||
RedisRpcRequest request = buildRequest("device/dragZoomIn", jsonObject);
|
||||
request.setToId(serverId);
|
||||
redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragZoomOut(String serverId, Device device, String channelId, int length, int width, int midpointx, int midpointy, int lengthx, int lengthy) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
jsonObject.put("length", length);
|
||||
jsonObject.put("width", width);
|
||||
jsonObject.put("midpointx", midpointx);
|
||||
jsonObject.put("midpointy", midpointy);
|
||||
jsonObject.put("lengthx", lengthx);
|
||||
jsonObject.put("lengthy", lengthy);
|
||||
RedisRpcRequest request = buildRequest("device/dragZoomOut", jsonObject);
|
||||
request.setToId(serverId);
|
||||
redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WVPResult<String> deviceStatus(String serverId, Device device) {
|
||||
RedisRpcRequest request = buildRequest("device/deviceStatus", device.getDeviceId());
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return JSON.parseObject(response.getBody().toString(), WVPResult.class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue