[集群] 增加设备基本配置和设备配置查询
This commit is contained in:
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service.redisMsg;
|
||||
|
||||
import com.genersoft.iot.vmp.common.CommonCallback;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Platform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
|
||||
@@ -38,4 +39,8 @@ public interface IRedisRpcService {
|
||||
WVPResult<SyncStatus> devicesSync(String serverId, String deviceId);
|
||||
|
||||
SyncStatus getChannelSyncStatus(String serverId, String deviceId);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -88,6 +89,82 @@ public class RedisRpcDeviceController extends RpcController {
|
||||
return response;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("deviceBasicConfig")
|
||||
public RedisRpcResponse deviceBasicConfig(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
String name = paramJson.getString("configType");
|
||||
String expiration = paramJson.getString("expiration");
|
||||
String heartBeatInterval = paramJson.getString("heartBeatInterval");
|
||||
|
||||
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;
|
||||
}
|
||||
DeferredResult<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);
|
||||
// 手动发送结果
|
||||
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);
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
@RedisRpcMapping("deviceConfigQuery")
|
||||
public RedisRpcResponse deviceConfigQuery(RedisRpcRequest request) {
|
||||
JSONObject paramJson = JSONObject.parseObject(request.getParam().toString());
|
||||
String deviceId = paramJson.getString("deviceId");
|
||||
String channelId = paramJson.getString("channelId");
|
||||
String configType = paramJson.getString("configType");
|
||||
|
||||
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;
|
||||
}
|
||||
DeferredResult<String> deferredResult = deviceService.deviceConfigQuery(device, channelId, configType);
|
||||
deferredResult.onCompletion(() ->{
|
||||
String resultStr = (String)deferredResult.getResult();
|
||||
response.setStatusCode(ErrorCode.SUCCESS.getCode());
|
||||
response.setBody(resultStr);
|
||||
// 手动发送结果
|
||||
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);
|
||||
// 手动发送结果
|
||||
sendResponse(response);
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.redis.RedisRpcConfig;
|
||||
import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest;
|
||||
import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Platform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
|
||||
@@ -263,4 +264,32 @@ public class RedisRpcServiceImpl implements IRedisRpcService {
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 100, TimeUnit.MILLISECONDS);
|
||||
return JSON.parseObject(response.getBody().toString(), SyncStatus.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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());
|
||||
jsonObject.put("channelId", channelId);
|
||||
jsonObject.put("name", name);
|
||||
jsonObject.put("expiration", expiration);
|
||||
jsonObject.put("heartBeatInterval", heartBeatInterval);
|
||||
jsonObject.put("heartBeatCount", heartBeatCount);
|
||||
RedisRpcRequest request = buildRequest("device/deviceBasicConfig", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return response.getBody().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deviceConfigQuery(String serverId, Device device, String channelId, String configType) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("device", device.getDeviceId());
|
||||
jsonObject.put("channelId", channelId);
|
||||
jsonObject.put("configType", configType);
|
||||
RedisRpcRequest request = buildRequest("device/deviceConfigQuery", jsonObject);
|
||||
request.setToId(serverId);
|
||||
RedisRpcResponse response = redisRpcConfig.request(request, 50, TimeUnit.MILLISECONDS);
|
||||
return response.getBody().toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user