Merge pull request '修复切换基站bug' (#17) from feature/backup-basestation into develop
Reviewed-on: #17
This commit is contained in:
commit
4ceac73519
@ -17,7 +17,7 @@ public interface RtcmClient {
|
|||||||
@GetMapping(value = "/get_device_info")
|
@GetMapping(value = "/get_device_info")
|
||||||
public HttpResp getDeviceInfo(@RequestParam(name = "deviceId") String deviceId, @RequestParam(name = "cmd") String cmd);
|
public HttpResp getDeviceInfo(@RequestParam(name = "deviceId") String deviceId, @RequestParam(name = "cmd") String cmd);
|
||||||
@PostMapping("/device_param_changed")
|
@PostMapping("/device_param_changed")
|
||||||
HttpResp deviceParamChanged(@RequestParam(name = "deviceId") String deviceId,@RequestParam(name = "oldParentId") String oldParentId);
|
HttpResp deviceParamChanged(@RequestParam(name = "deviceId") String deviceId,@RequestParam(name = "oldParentId") String oldParentId,@RequestParam(name = "oldParentId1") String oldParentId1);
|
||||||
|
|
||||||
@PostMapping("/group_param_changed")
|
@PostMapping("/group_param_changed")
|
||||||
HttpResp groupParamChanged();
|
HttpResp groupParamChanged();
|
||||||
|
|||||||
@ -58,15 +58,28 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
|||||||
String id = message.getId();
|
String id = message.getId();
|
||||||
// 补齐tenantId
|
// 补齐tenantId
|
||||||
Device deviceBs = deviceService.findByDeviceId(id);
|
Device deviceBs = deviceService.findByDeviceId(id);
|
||||||
if(deviceBs == null || deviceBs.getOpMode() == GnssDevice.OP_MODE_UNUSE) return null;
|
if(deviceBs == null || deviceBs.getOpMode() == GnssDevice.OP_MODE_UNUSE || deviceBs.getOpMode() == GnssDevice.OP_MODE_CHECK) {
|
||||||
|
logger.warn("基站 {} 不存在或未启用 (opMode: {})",
|
||||||
|
id, deviceBs != null ? deviceBs.getOpMode() : "null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 推送基站数据
|
// 推送基站数据
|
||||||
if(deviceBs.getOpMode() == GnssDevice.OP_MODE_USE) {
|
if(deviceBs.getOpMode() == GnssDevice.OP_MODE_USE || deviceBs.getOpMode() == null) {
|
||||||
byte[] forwardBytes = message.getSrcData();
|
byte[] forwardBytes = message.getSrcData();
|
||||||
// 获取使用该基站(包括作为主基站和备选基站)的所有测站
|
// 获取使用该基站(包括作为主基站和备选基站)的所有测站
|
||||||
List<Device> primaryDevices = deviceService.findByParentId(id);
|
List<Device> primaryDevices = deviceService.findByParentId(id);
|
||||||
List<Device> backupDevices = deviceService.findByParentId1(id);
|
List<Device> backupDevices = deviceService.findByParentId1(id);
|
||||||
|
|
||||||
|
// 添加调试日志
|
||||||
|
logger.info("基站 {} 状态: opMode={}, lastRxTime={}, d3xxCount={}",
|
||||||
|
id, deviceBs.getOpMode(), deviceBs.getLastRxTime(), deviceBs.getD3xxCount());
|
||||||
|
|
||||||
|
if (!primaryDevices.isEmpty() || !backupDevices.isEmpty()) {
|
||||||
|
logger.debug("基站 {} 关联的主站设备数: {}, 备站设备数: {}",
|
||||||
|
id, primaryDevices.size(), backupDevices.size());
|
||||||
|
}
|
||||||
|
|
||||||
// 合并两个列表
|
// 合并两个列表
|
||||||
List<Device> allDevices = new ArrayList<>();
|
List<Device> allDevices = new ArrayList<>();
|
||||||
allDevices.addAll(primaryDevices);
|
allDevices.addAll(primaryDevices);
|
||||||
@ -87,22 +100,37 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
|||||||
String primaryBaseId = device.getParentId();
|
String primaryBaseId = device.getParentId();
|
||||||
String backupBaseId = device.getParentId1();
|
String backupBaseId = device.getParentId1();
|
||||||
|
|
||||||
|
// 添加调试日志
|
||||||
|
logger.info("测站 {} 配置信息: 主基站={}, 备用基站={}, 当前数据来自基站={}",
|
||||||
|
deviceId, primaryBaseId, backupBaseId, id);
|
||||||
|
|
||||||
// 如果当前基站是该设备的备选基站,需要检查主基站是否离线
|
// 如果当前基站是该设备的备选基站,需要检查主基站是否离线
|
||||||
if (id.equals(backupBaseId)) {
|
if (id.equals(backupBaseId)) {
|
||||||
Device primaryBase = deviceService.findByDeviceId(primaryBaseId);
|
Device primaryBase = deviceService.findByDeviceId(primaryBaseId);
|
||||||
|
// 添加调试日志
|
||||||
|
if (primaryBase != null) {
|
||||||
|
logger.info("测站 {} 的主基站 {} 状态: lastRxTime={}, opMode={}",
|
||||||
|
deviceId, primaryBaseId,
|
||||||
|
primaryBase.getLastRxTime(),
|
||||||
|
primaryBase.getOpMode());
|
||||||
|
} else {
|
||||||
|
logger.warn("测站 {} 的主基站 {} 未找到或已删除", deviceId, primaryBaseId);
|
||||||
|
}
|
||||||
|
|
||||||
// 如果主基站仍然在线,则跳过备选基站的数据
|
// 如果主基站仍然在线,则跳过备选基站的数据
|
||||||
if (primaryBase != null && isBaseStationOnline(primaryBase)) {
|
if (primaryBase != null && isBaseStationOnline(primaryBase)) {
|
||||||
if(deviceBackupStatus.remove(deviceId) != null){
|
if(deviceBackupStatus.remove(deviceId) != null){
|
||||||
logger.info("设备 {} 从备用基站 {} 切换回主基站 {}",
|
logger.info("设备 {} 从备用基站 {} 切换回主基站 {}",
|
||||||
deviceId, id, primaryBaseId);
|
deviceId, id, primaryBaseId);
|
||||||
}
|
}
|
||||||
|
logger.debug("主基站在线,跳过备用基站数据");
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
String hexPrimaryBase = String.format("%06x",Integer.parseInt(primaryBaseId));
|
String hexPrimaryBase = String.format("%06x",Integer.parseInt(primaryBaseId));
|
||||||
if(deviceBackupStatus.putIfAbsent(deviceId,true) == null){
|
if(deviceBackupStatus.putIfAbsent(deviceId,true) == null){
|
||||||
logger.info("设备 {} 从主基站 {} 切换到备用基站 {}",
|
logger.info("设备 {} 从主基站 {} 切换到备用基站 {} (原因: {})",
|
||||||
deviceId, primaryBaseId, id);
|
deviceId, primaryBaseId, id,
|
||||||
|
primaryBase == null ? "主基站不存在" : "主基站离线");
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] modifyData = forwardBytes.clone();
|
byte[] modifyData = forwardBytes.clone();
|
||||||
@ -111,9 +139,18 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
|||||||
modifyData[7] = (byte) Integer.parseInt(hexPrimaryBase.substring(4,6),16);
|
modifyData[7] = (byte) Integer.parseInt(hexPrimaryBase.substring(4,6),16);
|
||||||
|
|
||||||
forwardBytes = modifyData;
|
forwardBytes = modifyData;
|
||||||
|
logger.debug("使用备用基站数据,但保持主基站ID: {}", primaryBaseId);
|
||||||
|
}
|
||||||
|
} else if (id.equals(primaryBaseId)) {
|
||||||
|
// 如果是主基站,确保清除备用状态
|
||||||
|
if(deviceBackupStatus.remove(deviceId) != null) {
|
||||||
|
logger.info("设备 {} 恢复使用主基站 {}", deviceId, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加日志显示当前测站使用的基站
|
||||||
|
logger.info("测站 {} 当前使用的基站: {}", deviceId, id);
|
||||||
|
|
||||||
// 获取设备通道并发送数据
|
// 获取设备通道并发送数据
|
||||||
if(device.getDataChannelType() == Device.CHANNEL_TYPE_UDP) {
|
if(device.getDataChannelType() == Device.CHANNEL_TYPE_UDP) {
|
||||||
deviceChannel = OnlineChannels.INSTANCE.getDataChannel(deviceId);
|
deviceChannel = OnlineChannels.INSTANCE.getDataChannel(deviceId);
|
||||||
@ -352,7 +389,7 @@ public class D331RtcmMessageExecutor implements Executor<D331RtcmMessage, Void>
|
|||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
return baseStation.getLastRxTime() != null &&
|
return baseStation.getLastRxTime() != null &&
|
||||||
baseStation.getLastRxTime().isAfter(now.minusMinutes(30));
|
baseStation.getLastRxTime().isAfter(now.minusMinutes(5)); // 从30分钟改为5分钟
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,7 @@ public class LocalDeviceServiceImpl implements DeviceService {
|
|||||||
device.setEcefy(gnssDevice.getEcefy());
|
device.setEcefy(gnssDevice.getEcefy());
|
||||||
device.setEcefz(gnssDevice.getEcefz());
|
device.setEcefz(gnssDevice.getEcefz());
|
||||||
device.setLoggingmode(gnssDevice.getLoggingmode());
|
device.setLoggingmode(gnssDevice.getLoggingmode());
|
||||||
|
device.setParentId1(gnssDevice.getParentid1());
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,11 +93,12 @@ public class LocalDeviceServiceImpl implements DeviceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> findByParentId(String parentId) {
|
public List<Device> findByParentId(String parentId) {
|
||||||
List<Device> devices = subDeviceCache.getIfPresent(parentId);
|
String cacheKey = "PARENTID_" + parentId;
|
||||||
|
List<Device> devices = subDeviceCache.getIfPresent(cacheKey);
|
||||||
if (devices == null) {
|
if (devices == null) {
|
||||||
devices = getDeviceListFromDBByParentId(parentId);
|
devices = getDeviceListFromDBByParentId(parentId);
|
||||||
if (devices != null) {
|
if (devices != null) {
|
||||||
subDeviceCache.put(parentId, devices);
|
subDeviceCache.put(cacheKey, devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
@ -104,23 +106,30 @@ public class LocalDeviceServiceImpl implements DeviceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Device> findByParentId1(String parentId1) {
|
public List<Device> findByParentId1(String parentId1) {
|
||||||
List<Device> devices = subDeviceCache.getIfPresent(parentId1);
|
String cacheKey = "PARENTID1_" + parentId1;
|
||||||
|
List<Device> devices = subDeviceCache.getIfPresent(cacheKey);
|
||||||
if (devices == null) {
|
if (devices == null) {
|
||||||
devices = getDeviceListFromDBByParentId1(parentId1);
|
devices = getDeviceListFromDBByParentId1(parentId1);
|
||||||
if (devices != null) {
|
if (devices != null) {
|
||||||
subDeviceCache.put(parentId1, devices);
|
subDeviceCache.put(cacheKey, devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(String deviceId, String oldParentId){
|
public void refresh(String deviceId, String oldParentId, String oldParentId1){
|
||||||
Device device = deviceCache.getIfPresent(deviceId);
|
Device device = deviceCache.getIfPresent(deviceId);
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
if(device.getParentId()!=null) {
|
if(device.getParentId()!=null) {
|
||||||
subDeviceCache.invalidate(device.getParentId());
|
subDeviceCache.invalidate("PARENTID_" + device.getParentId());
|
||||||
if(oldParentId!=null && !oldParentId.equals(device.getParentId())){
|
if(oldParentId!=null && !oldParentId.equals(device.getParentId())){
|
||||||
subDeviceCache.invalidate(oldParentId);
|
subDeviceCache.invalidate("PARENTID_" + oldParentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(device.getParentId1()!=null) {
|
||||||
|
subDeviceCache.invalidate("PARENTID1_" + device.getParentId1());
|
||||||
|
if(oldParentId1!=null && !oldParentId1.equals(device.getParentId1())){
|
||||||
|
subDeviceCache.invalidate("PARENTID1_" + oldParentId1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deviceCache.invalidate(deviceId);
|
deviceCache.invalidate(deviceId);
|
||||||
|
|||||||
@ -154,9 +154,9 @@ public class ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/device_param_changed")
|
@PostMapping("/device_param_changed")
|
||||||
public HttpResp deviceParamChanged(String deviceId, String oldParentId) {
|
public HttpResp deviceParamChanged(String deviceId, String oldParentId, String oldParentId1) {
|
||||||
// 更新设备缓存
|
// 更新设备缓存
|
||||||
localDeviceService.refresh(deviceId, oldParentId);
|
localDeviceService.refresh(deviceId, oldParentId, oldParentId1);
|
||||||
calcService.refreshDeviceCalc(deviceId);
|
calcService.refreshDeviceCalc(deviceId);
|
||||||
|
|
||||||
HttpResp resp = new HttpResp();
|
HttpResp resp = new HttpResp();
|
||||||
|
|||||||
@ -287,7 +287,7 @@ public class GnssDeviceController extends BasicController{
|
|||||||
} else {
|
} else {
|
||||||
// 更新组参数的关联个数
|
// 更新组参数的关联个数
|
||||||
updateBasicGroupAssociatedNum(device,old_device);
|
updateBasicGroupAssociatedNum(device,old_device);
|
||||||
rtcmClient.deviceParamChanged(device.getDeviceid(), device.getParentid());
|
rtcmClient.deviceParamChanged(device.getDeviceid(), old_device != null ? old_device.getParentid() : null, old_device != null ? old_device.getParentid1() : null);
|
||||||
return HttpResult.ok();
|
return HttpResult.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -409,7 +409,7 @@ public class GnssDeviceController extends BasicController{
|
|||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
return HttpResult.failed();
|
return HttpResult.failed();
|
||||||
} else{
|
} else{
|
||||||
rtcmClient.deviceParamChanged(del_id, null);
|
rtcmClient.deviceParamChanged(del_id, null, null);
|
||||||
return HttpResult.ok();
|
return HttpResult.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user