fix(map): 移除lastSuccessfulTime字段并修复定位上报逻辑

移除客户端lastSuccessfulTime字段以避免序列化格式冲突,改为服务端统一记录。修复错误上报缺失问题,使网页端能展示失败原因。增加上报前空值校验,避免无效请求。
This commit is contained in:
TongTongStudio
2026-08-05 23:15:19 +08:00
parent 257f9435eb
commit f2e22c1fb6
3 changed files with 18 additions and 14 deletions

View File

@@ -5,7 +5,6 @@ import com.google.gson.annotations.SerializedName;
import com.ttstd.dialer.manager.MapManager;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 设备定位信息请求模型
@@ -61,9 +60,6 @@ public class SnLocationReq implements Serializable {
@SerializedName("mapError")
private String mapError;
@SerializedName("lastSuccessfulTime")
private LocalDateTime lastSuccessfulTime;
public SnLocationReq() {
}
@@ -213,12 +209,4 @@ public class SnLocationReq implements Serializable {
public void setMapError(String mapError) {
this.mapError = mapError;
}
public LocalDateTime getLastSuccessfulTime() {
return lastSuccessfulTime;
}
public void setLastSuccessfulTime(LocalDateTime lastSuccessfulTime) {
this.lastSuccessfulTime = lastSuccessfulTime;
}
}

View File

@@ -271,16 +271,25 @@ public class MapManager {
WeatherManager.getInstance().setAdCode(bdLocation.getAdCode());
SnLocationReq snLocation = new SnLocationReq(bdLocation);
// 记录本次定位成功时间由服务端在接收上报时统一写入,移动端不传(避免 LocalDateTime 序列化格式冲突)
snLocation.setMapError("-");
LiveEventBus.get(CommonConfig.LOCATION_CHANGED_KEY)
.post(snLocation);
}
/**
* 存储定位错误信息
* 存储定位错误信息并上报失败原因
* 构造一份仅包含错误信息的定位上报,使网页端能展示失败原因,而非一直停留在旧数据。
*/
private void saveLocationError(String errorMsg) {
mMMKV.encode("MapError", errorMsg);
SnLocationReq snLocation = new SnLocationReq();
snLocation.setMapError(errorMsg);
LiveEventBus.get(CommonConfig.LOCATION_CHANGED_KEY)
.post(snLocation);
}
// 百度定位回调

View File

@@ -1,5 +1,6 @@
package com.ttstd.dialer.service.main;
import android.text.TextUtils;
import android.util.Log;
import androidx.lifecycle.ViewModel;
@@ -9,6 +10,7 @@ import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.ttstd.dialer.bean.BaseResponse;
import com.ttstd.dialer.bean.req.SnLocationReq;
import com.ttstd.dialer.gson.GsonUtils;
import com.ttstd.dialer.network.BaseObserver;
import com.ttstd.dialer.network.OkHttpManager;
@@ -41,7 +43,12 @@ public class MainServiceModel extends ViewModel {
public void uploadLocation(SnLocationReq locationReq) {
Log.e(TAG, "uploadLocation: ");
// 空校验:位置信息缺失时不发起请求,避免后端收到无效数据
if (locationReq == null) {
Log.e(TAG, "uploadLocation: 定位信息为空或缺少 sn已跳过上报");
return;
}
Log.e(TAG, "uploadLocation: " + GsonUtils.toJSONString(locationReq));
OkHttpManager.getInstance().getUploadLocationObservable(locationReq)
.compose(bindToLifecycle())
.subscribe(new BaseObserver<BaseResponse>() {