fix(watch-job):

空值报错处理: 在SyncUserStatJob中添加空值检查
数据库规范: "limit 1"替换为"FETCH FIRST 1 ROWS ONLY"
This commit is contained in:
hejiayang
2026-03-18 13:49:08 +08:00
parent 7d3ee66a4b
commit 961dc7c104
2 changed files with 9 additions and 7 deletions
@@ -613,7 +613,7 @@ public class AsyncImportService {
queryWrapper.eq(WatchBindHis::getWatchNo,device.getWatchNo()); queryWrapper.eq(WatchBindHis::getWatchNo,device.getWatchNo());
queryWrapper.isNull(WatchBindHis::getBindEndDate); queryWrapper.isNull(WatchBindHis::getBindEndDate);
queryWrapper.orderByDesc(WatchBindHis::getCreateDate); queryWrapper.orderByDesc(WatchBindHis::getCreateDate);
queryWrapper.last("limit 1"); queryWrapper.last("FETCH FIRST 1 ROWS ONLY");
//解绑 //解绑
WatchBindHis updateHis = watchBindHisMapper.selectOne(queryWrapper); WatchBindHis updateHis = watchBindHisMapper.selectOne(queryWrapper);
//修改绑定用户 //修改绑定用户
@@ -251,7 +251,7 @@ public class SyncUserStatJob {
.isNotNull(WatchDataStepsHf::getStepCount) .isNotNull(WatchDataStepsHf::getStepCount)
.gt(WatchDataStepsHf::getStepCount, 0) .gt(WatchDataStepsHf::getStepCount, 0)
.orderByDesc(WatchDataStepsHf::getStepCount) .orderByDesc(WatchDataStepsHf::getStepCount)
.last("limit 1"); .last("FETCH FIRST 1 ROWS ONLY");
WatchDataStepsHf latest = watchDataStepsHfServiceService.getOne(queryWrapper); WatchDataStepsHf latest = watchDataStepsHfServiceService.getOne(queryWrapper);
if (ObjectUtil.isNull(latest)) { if (ObjectUtil.isNull(latest)) {
return; return;
@@ -306,21 +306,21 @@ public class SyncUserStatJob {
queryWrapper.isNotNull(WatchDataSteps::getDataValue); queryWrapper.isNotNull(WatchDataSteps::getDataValue);
queryWrapper.gt(WatchDataSteps::getDataValue, 0); queryWrapper.gt(WatchDataSteps::getDataValue, 0);
queryWrapper.orderByDesc(WatchDataSteps::getMaxId); queryWrapper.orderByDesc(WatchDataSteps::getMaxId);
queryWrapper.last("limit 1"); queryWrapper.last("FETCH FIRST 1 ROWS ONLY");
WatchDataSteps list = watchDataStepsService.getOne(queryWrapper); WatchDataSteps list = watchDataStepsService.getOne(queryWrapper);
LambdaQueryWrapper<WatchDataDistance> watchDataDistanceQueryWrapper = getQueryWrapper(userId, dateStr); LambdaQueryWrapper<WatchDataDistance> watchDataDistanceQueryWrapper = getQueryWrapper(userId, dateStr);
watchDataDistanceQueryWrapper.gt(WatchDataDistance::getDataValue, 0); watchDataDistanceQueryWrapper.gt(WatchDataDistance::getDataValue, 0);
watchDataDistanceQueryWrapper.isNotNull(WatchDataDistance::getDataValue); watchDataDistanceQueryWrapper.isNotNull(WatchDataDistance::getDataValue);
watchDataDistanceQueryWrapper.orderByDesc(WatchDataDistance::getMaxId); watchDataDistanceQueryWrapper.orderByDesc(WatchDataDistance::getMaxId);
watchDataDistanceQueryWrapper.last("limit 1"); watchDataDistanceQueryWrapper.last("FETCH FIRST 1 ROWS ONLY");
WatchDataDistance watchDataDistanceList = watchDataDistanceService.getOne(watchDataDistanceQueryWrapper); WatchDataDistance watchDataDistanceList = watchDataDistanceService.getOne(watchDataDistanceQueryWrapper);
LambdaQueryWrapper<WatchDataCalorie> watchDataCalorieQueryWrapper = getQueryWrapper(userId, dateStr); LambdaQueryWrapper<WatchDataCalorie> watchDataCalorieQueryWrapper = getQueryWrapper(userId, dateStr);
watchDataCalorieQueryWrapper.gt(WatchDataCalorie::getDataValue, 0); watchDataCalorieQueryWrapper.gt(WatchDataCalorie::getDataValue, 0);
watchDataCalorieQueryWrapper.isNotNull(WatchDataCalorie::getDataValue); watchDataCalorieQueryWrapper.isNotNull(WatchDataCalorie::getDataValue);
watchDataCalorieQueryWrapper.orderByDesc(WatchDataCalorie::getMaxId); watchDataCalorieQueryWrapper.orderByDesc(WatchDataCalorie::getMaxId);
watchDataCalorieQueryWrapper.last("limit 1"); watchDataCalorieQueryWrapper.last("FETCH FIRST 1 ROWS ONLY");
WatchDataCalorie watchDataCalorieList = watchDataCalorieService.getOne(watchDataCalorieQueryWrapper); WatchDataCalorie watchDataCalorieList = watchDataCalorieService.getOne(watchDataCalorieQueryWrapper);
if (ObjectUtil.isNull(list) && ObjectUtil.isNull(watchDataDistanceList) && ObjectUtil.isNull(watchDataCalorieList)) { if (ObjectUtil.isNull(list) && ObjectUtil.isNull(watchDataDistanceList) && ObjectUtil.isNull(watchDataCalorieList)) {
@@ -833,7 +833,9 @@ public class SyncUserStatJob {
rate.setSilenceMinValue((int) silenceMin); rate.setSilenceMinValue((int) silenceMin);
rate.setSilenceAvgValue((int) silenceSize); rate.setSilenceAvgValue((int) silenceSize);
rate.setNewValue(currentDataValue.intValue()); rate.setNewValue(currentDataValue.intValue());
rate.setSilenceNewValue(watchDataHeartRate.getSilenceValue().intValue()); if(watchDataHeartRate.getSilenceValue() != null){
rate.setSilenceNewValue(watchDataHeartRate.getSilenceValue().intValue());
}
rate.setLastUploadTime(watchDataHeartRate.getTimeStamp()); rate.setLastUploadTime(watchDataHeartRate.getTimeStamp());
SyncUserStatJob bean = SpringContextUtils.getBean(SyncUserStatJob.class); SyncUserStatJob bean = SpringContextUtils.getBean(SyncUserStatJob.class);
@@ -928,7 +930,7 @@ public class SyncUserStatJob {
LambdaQueryWrapper<WatchDevice> deviceWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<WatchDevice> deviceWrapper = new LambdaQueryWrapper<>();
deviceWrapper.eq(WatchDevice::getBindUserId, user.getId()); deviceWrapper.eq(WatchDevice::getBindUserId, user.getId());
deviceWrapper.orderByDesc(WatchDevice::getBindDate); deviceWrapper.orderByDesc(WatchDevice::getBindDate);
deviceWrapper.last("limit 1"); deviceWrapper.last("FETCH FIRST 1 ROWS ONLY");
WatchDevice watchDevice = watchDeviceMapper.selectOne(deviceWrapper); WatchDevice watchDevice = watchDeviceMapper.selectOne(deviceWrapper);
if (watchDevice != null) { if (watchDevice != null) {
watchData.setWatchNo(watchDevice.getWatchNo()); watchData.setWatchNo(watchDevice.getWatchNo());