1、微服务间调用加异常捕获

This commit is contained in:
weidong 2024-02-22 16:28:25 +08:00
parent eb0e0e9453
commit 5501f0bb05
7 changed files with 74 additions and 23 deletions

View File

@ -271,7 +271,7 @@ public class Forwarder {
} }
void insertData(GnssStatus offDevice,GnssStatus refDevice){ void insertData(GnssStatus offDevice,GnssStatus refDevice){
logger.info("insertData"); logger.info("insertData based on {}",refDevice.getDeviceid());
QueryWrapper<GnssCalcData> queryWrapper = new QueryWrapper<>(); QueryWrapper<GnssCalcData> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("deviceid",refDevice.getDeviceid()); queryWrapper.eq("deviceid",refDevice.getDeviceid());
queryWrapper.eq("enabled",true); queryWrapper.eq("enabled",true);

View File

@ -26,6 +26,8 @@ public class GNSSCalcFilterService {
private GnssGroupCalcMapper groupCalcMapper; private GnssGroupCalcMapper groupCalcMapper;
@Autowired @Autowired
private GnssCalcDataMapper repository; private GnssCalcDataMapper repository;
@Autowired
private GnssMsgMapper msgMapper;
public static final int FILTER_MIN_CYCLE_HOUR = 2; public static final int FILTER_MIN_CYCLE_HOUR = 2;
public static final int FILTER_DEFAULT_CYCLE_HOUR = 8; public static final int FILTER_DEFAULT_CYCLE_HOUR = 8;
@ -107,10 +109,10 @@ public class GNSSCalcFilterService {
query.orderByDesc("createtime"); query.orderByDesc("createtime");
List<GnssCalcData> gnssDeviceLocationRecords = repository.selectList(query); List<GnssCalcData> gnssDeviceLocationRecords = repository.selectList(query);
logger.info(deviceId + " select records from "+filterAfterTime.format(dateFormatter)+ /* logger.debug(deviceId + " select records from "+filterAfterTime.format(dateFormatter)+
" to "+newRecordTime.format(dateFormatter)+ " to "+newRecordTime.format(dateFormatter)+
", record num:"+gnssDeviceLocationRecords.size()); ", record num:"+gnssDeviceLocationRecords.size());
*/
if(gnssDeviceLocationRecords.size() == 0){ if(gnssDeviceLocationRecords.size() == 0){
//第一个点无参考当作坏点处理 //第一个点无参考当作坏点处理
newRecord.setEnabled(false); newRecord.setEnabled(false);
@ -162,7 +164,7 @@ public class GNSSCalcFilterService {
} }
} }
} }
logger.info(deviceId + " filter records num: " + count+", min cycle num: "+minCount); logger.debug("{} filter records num: {}",deviceId,count);
if (count >= FILTER_MIN_RECORD_NUM) { if (count >= FILTER_MIN_RECORD_NUM) {
newRecord.setRpose(NumberUtils.scaleTwo(sumE / count)); newRecord.setRpose(NumberUtils.scaleTwo(sumE / count));
newRecord.setRposn(NumberUtils.scaleTwo(sumN / count)); newRecord.setRposn(NumberUtils.scaleTwo(sumN / count));
@ -198,7 +200,8 @@ public class GNSSCalcFilterService {
varyCycle.startTime = now; varyCycle.startTime = now;
varyCycle.filterCycleHour = groupCalc.getFilter_min_hour(); varyCycle.filterCycleHour = groupCalc.getFilter_min_hour();
autoCycleDevices.put(deviceId, varyCycle); autoCycleDevices.put(deviceId, varyCycle);
logger.info(deviceId + ": filter cycle change to " + varyCycle.filterCycleHour); saveMsg(deviceId, curCalcData.getTenantid(),
"filter cycle changed to"+varyCycle.filterCycleHour,now);
} }
else { else {
VaryFilterCycle varyCycle = autoCycleDevices.get(deviceId); VaryFilterCycle varyCycle = autoCycleDevices.get(deviceId);
@ -211,7 +214,8 @@ public class GNSSCalcFilterService {
if (now.isAfter(varyCycle.startTime.plusHours(1))) { if (now.isAfter(varyCycle.startTime.plusHours(1))) {
varyCycle.filterCycleHour++; varyCycle.filterCycleHour++;
varyCycle.startTime = now; varyCycle.startTime = now;
logger.info(deviceId + ": refresh filter cycle "+varyCycle.filterCycleHour); saveMsg(deviceId, curCalcData.getTenantid(),
"filter cycle changed to"+varyCycle.filterCycleHour,now);
} }
} }
} }
@ -242,8 +246,25 @@ public class GNSSCalcFilterService {
groupCalc.getXy_threshold(), groupCalc.getZ_threshold(), groupCalc.getAdv_filter()); groupCalc.getXy_threshold(), groupCalc.getZ_threshold(), groupCalc.getAdv_filter());
repository.updateById(calcData); repository.updateById(calcData);
lastTime = calcData.getCreatetime(); lastTime = calcData.getCreatetime();
logger.info(deviceId + " update rpos"); //logger.info(deviceId + " update rpos");
} }
return lastTime; return lastTime;
} }
void saveMsg(String deviceId, Integer tenantId, String content, LocalDateTime time){
GnssMsg gnssMsg = new GnssMsg();
gnssMsg.setTenantid(tenantId);
gnssMsg.setCreatetime(time);
gnssMsg.setDeviceid(deviceId);
gnssMsg.setMsgtype(0);
gnssMsg.setMsglen(content.length());
gnssMsg.setTx(false);
if(content.length()<=128) {
gnssMsg.setContent(content);
}
else{
gnssMsg.setContent(content.substring(0,120)+"...");
}
msgMapper.insert(gnssMsg);
}
} }

View File

@ -64,7 +64,12 @@ public class MultiLineGNSSCalcService {
lastD342Time = new D342Time(); lastD342Time = new D342Time();
deviceMap.put(deviceId, lastD342Time); deviceMap.put(deviceId, lastD342Time);
// 产生断点补传通知 // 产生断点补传通知
beidouClient.onGnssUpload(deviceId, d342Message.getTenantId(), msgTime, "session begin"); try {
beidouClient.onGnssUpload(deviceId, d342Message.getTenantId(), msgTime, "session begin");
}
catch (Exception e){
}
GnssStatus gnssStatus = dataPersistService.getDeviceState(deviceId); GnssStatus gnssStatus = dataPersistService.getDeviceState(deviceId);
if (gnssStatus != null) { if (gnssStatus != null) {
gnssStatus.setUpdatetime(LocalDateTime.now()); gnssStatus.setUpdatetime(LocalDateTime.now());
@ -93,7 +98,12 @@ public class MultiLineGNSSCalcService {
void d342SessionDone(String deviceId, Integer tenantId, LocalDateTime lastDate){ void d342SessionDone(String deviceId, Integer tenantId, LocalDateTime lastDate){
//补传结束指示 //补传结束指示
logger.info(deviceId + " d342 session done! "+lastDate); logger.info(deviceId + " d342 session done! "+lastDate);
beidouClient.onGnssUploadComplete(deviceId,tenantId, lastDate); try {
beidouClient.onGnssUploadComplete(deviceId, tenantId, lastDate);
}
catch (Exception e){
}
// 计算上轮结果 // 计算上轮结果
calcService.calSingleDone(deviceId, tenantId, lastDate); calcService.calSingleDone(deviceId, tenantId, lastDate);
// 重算最近的 // 重算最近的

View File

@ -28,7 +28,13 @@ public class D31xConfigAckMessageExecutor implements Executor<D31xConfigAckMessa
if(device == null) return null; if(device == null) return null;
message.setTenantId(device.getTenantId()); message.setTenantId(device.getTenantId());
// 转发应答 // 转发应答
beidouClient.onConfigAck(message.getId(), device.getTenantId(), ByteUtil.bytesToHexString(message.getSrcData())); try {
beidouClient.onConfigAck(message.getId(), device.getTenantId(),
ByteUtil.bytesToHexString(message.getSrcData()));
}
catch (Exception e){
}
return null; return null;
} }

View File

@ -43,12 +43,17 @@ public class D3F0SelfCheckMessageExecutor implements Executor<D3F0SelfCheckMessa
ThreadManager.getFixedThreadPool().submit(() -> { ThreadManager.getFixedThreadPool().submit(() -> {
GnssStatus lastGnssStatus = dataPersistService.getDeviceState(message.getId()); GnssStatus lastGnssStatus = dataPersistService.getDeviceState(message.getId());
if(lastGnssStatus!=null && lastGnssStatus.getState() == GnssStatus.STATE_OFFLINE){ try {
beidouClient.onLine(lastGnssStatus.getDeviceid(), lastGnssStatus.getTenantid(), lastGnssStatus.getUpdatetime()); if (lastGnssStatus != null && lastGnssStatus.getState() == GnssStatus.STATE_OFFLINE) {
beidouClient.onLine(lastGnssStatus.getDeviceid(),
lastGnssStatus.getTenantid(), lastGnssStatus.getUpdatetime());
} else {
// 通知beidou服务设备上线
beidouClient.onDeviceActive(message.getId(), device.getTenantId());
}
} }
else{ catch (Exception e){
// 通知beidou服务设备上线
beidouClient.onDeviceActive(message.getId(), device.getTenantId());
} }
dataPersistService.saveDeviceState(message); dataPersistService.saveDeviceState(message);
}); });

View File

@ -60,12 +60,17 @@ public class D3F2StopIndicationMessageExecutor implements Executor<D3F2StopIndic
device.getDeviceId(), device.getTenantId()); device.getDeviceId(), device.getTenantId());
dataPersistService.saveDeviceTrxStat(message, (uploadTime!=null), device); dataPersistService.saveDeviceTrxStat(message, (uploadTime!=null), device);
// 通知beidou服务设备休眠 // 通知beidou服务设备休眠
beidouClient.onDeviceStop(deviceId,device.getTenantId()); try {
if(uploadTime!=null){ beidouClient.onDeviceStop(deviceId, device.getTenantId());
String info = "d342 num:"+device.getD342Count()+ if (uploadTime != null) {
", bytes:"+device.getD342Bytes()+ String info = "d342 num:" + device.getD342Count() +
", d341 included:"+device.getD341In42Count(); ", bytes:" + device.getD342Bytes() +
beidouClient.onGnssUpload(deviceId,device.getTenantId(),uploadTime,info); ", d341 included:" + device.getD341In42Count();
beidouClient.onGnssUpload(deviceId, device.getTenantId(), uploadTime, info);
}
}
catch (Exception e){
} }
// 检查告警 // 检查告警
if(device.getDeviceType() == Device.DEVICE_BASE_STATION) { if(device.getDeviceType() == Device.DEVICE_BASE_STATION) {

View File

@ -129,8 +129,12 @@ public class DataPersistServiceImpl implements DataPersistService {
gnssMsg.setMsgtype(message.getHeader()); gnssMsg.setMsgtype(message.getHeader());
gnssMsg.setMsglen(message.getLen()); gnssMsg.setMsglen(message.getLen());
gnssMsg.setTx(false); gnssMsg.setTx(false);
if(content!=null && content.length()<=128) { if(content!=null) {
gnssMsg.setContent(content); if (content.length() <= 128) {
gnssMsg.setContent(content);
} else {
gnssMsg.setContent(content.substring(0, 120) + "...");
}
} }
msgMapper.insert(gnssMsg); msgMapper.insert(gnssMsg);
} }