Merge remote-tracking branch 'origin/dev_robotaxi-d_240227_6.3.0' into dev_robotaxi-d_240227_6.3.0
This commit is contained in:
@@ -67,6 +67,7 @@ import com.mogo.och.common.module.manager.distancemamager.ITrajectoryListener;
|
||||
import com.mogo.och.common.module.manager.distancemamager.TrajectoryAndDistanceManager;
|
||||
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil;
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil;
|
||||
import com.mogo.och.common.module.utils.MultiRequestLimitChecker;
|
||||
import com.mogo.och.common.module.utils.NumberFormatUtil;
|
||||
import com.mogo.och.common.module.utils.PinYinUtil;
|
||||
import com.mogo.och.common.module.utils.ToastUtilsOch;
|
||||
@@ -705,6 +706,13 @@ public class OrderModel {
|
||||
String departureStopName = stationList.get(backgroundCurrentStationIndex).getName();
|
||||
CallerLogger.d(M_BUS + TAG, "arriveSiteStation-currentStationIndex = " + arrivedStationIndex);
|
||||
|
||||
String requestId = MultiRequestLimitChecker.Companion.generateRequestId(TAG + "-arriveSiteStation"
|
||||
, String.valueOf(stationList.get(arrivedStationIndex).getSiteId())
|
||||
, String.valueOf(currentTaskId));
|
||||
if (!MultiRequestLimitChecker.Companion.getInstance().canMakeRequest(requestId, 5)) {
|
||||
CallerLogger.d(M_BUS + TAG, "arriveSiteStation-MultiRequestLimitChecker: 超过最大请求数,本次请求return");
|
||||
return;
|
||||
}
|
||||
OrderServiceManager.arriveSiteStation(mContext,
|
||||
stationList.get(arrivedStationIndex).getSeq(),
|
||||
stationList.get(arrivedStationIndex).getSiteId(),
|
||||
@@ -713,6 +721,7 @@ public class OrderModel {
|
||||
@Override
|
||||
public void onSuccess(BaseData o) {
|
||||
CallerLogger.d(M_BUS + TAG, "行程日志-arriveSiteStation success");
|
||||
MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId);
|
||||
if (o != null && o.code == 0){
|
||||
queryBusRoutes();
|
||||
isArrivedStation = true;
|
||||
@@ -726,6 +735,7 @@ public class OrderModel {
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId);
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext.getString(R.string.network_error_tip));
|
||||
} else {
|
||||
@@ -735,6 +745,7 @@ public class OrderModel {
|
||||
|
||||
@Override
|
||||
public void onFail(int code, String failMsg) {
|
||||
MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId);
|
||||
if (ToastUtilsOch.isCustomFastClick(5000)) {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort("网络异常,请稍后重试");
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.mogo.och.common.module.utils
|
||||
|
||||
import android.text.TextUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.mogo.eagle.core.utilcode.util.EncryptUtils
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* 网络请求时最大请求数的检查类
|
||||
* 使用:建议在Model中离请求最近的地方来判断
|
||||
* 场景:如判断是否到站点(高频率坐标回调时在弱网情况下会产生大量同一参数的网络请求,
|
||||
* 当网络恢复时会造成同一时间的大量并发请求拉爆服务端)
|
||||
*/
|
||||
class MultiRequestLimitChecker private constructor() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "MultiRequestLimitChecker"
|
||||
|
||||
private val multiRequestLimitChecker: MultiRequestLimitChecker by lazy { MultiRequestLimitChecker() }
|
||||
|
||||
fun getInstance(): MultiRequestLimitChecker {
|
||||
return multiRequestLimitChecker
|
||||
}
|
||||
|
||||
fun generateRequestId(tag: String, vararg businessParams: String): String {
|
||||
require(tag.isNotBlank()) {
|
||||
Logger.e(TAG, "generateRequestId, Tag cannot be blank")
|
||||
return "Tag cannot be blank"
|
||||
}
|
||||
|
||||
// 将tag和业务参数映射为唯一字符串
|
||||
val combinedString = tag + stringifyBusinessParams(*businessParams)
|
||||
|
||||
// 计算MD5哈希
|
||||
return EncryptUtils.encryptMD5ToString(combinedString)
|
||||
}
|
||||
|
||||
private fun stringifyBusinessParams(vararg businessParams: String): String {
|
||||
return businessParams.joinToString(";")
|
||||
}
|
||||
}
|
||||
|
||||
private val requestCheckers: MutableMap<String, RequestLimitChecker> = ConcurrentHashMap()
|
||||
|
||||
@Synchronized
|
||||
fun canMakeRequest(requestId: String, maxRequests: Int): Boolean {
|
||||
if (TextUtils.isEmpty(requestId)) {
|
||||
Logger.e(TAG, "canMakeRequest requestId为空,return")
|
||||
return false
|
||||
}
|
||||
var requestChecker = requestCheckers[requestId]
|
||||
|
||||
if (requestChecker == null) {
|
||||
// 如果不存在对应请求的 RequestLimitChecker,创建一个并添加到 Map 中
|
||||
requestChecker = RequestLimitChecker(maxRequests)
|
||||
requestCheckers[requestId] = requestChecker
|
||||
}
|
||||
|
||||
return requestChecker.canMakeRequest()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun decreaseRequestCount(requestId: String) {
|
||||
if (TextUtils.isEmpty(requestId)) {
|
||||
Logger.e(TAG, "decreaseRequestCount requestId为空,return")
|
||||
return
|
||||
}
|
||||
val requestChecker = requestCheckers[requestId]
|
||||
requestChecker?.decreaseRequestCount()
|
||||
}
|
||||
}
|
||||
|
||||
class RequestLimitChecker(private val maxRequests: Int) {
|
||||
private var requestCount = 0
|
||||
|
||||
@Synchronized
|
||||
fun canMakeRequest(): Boolean {
|
||||
// 判断是否达到最大请求次数
|
||||
return if (requestCount < maxRequests) {
|
||||
requestCount++
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun decreaseRequestCount() {
|
||||
// 减小请求计数器,用于处理取消或失败的请求
|
||||
if (requestCount > 0) {
|
||||
requestCount--
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import com.mogo.och.common.module.bean.dpmsg.DPMsgType;
|
||||
import com.mogo.och.common.module.bean.dpmsg.LoginCacheStatus;
|
||||
import com.mogo.och.common.module.bean.dpmsg.TaskDetailsMsg;
|
||||
import com.mogo.och.common.module.biz.constant.LoginStatusManager;
|
||||
import com.mogo.och.common.module.utils.MultiRequestLimitChecker;
|
||||
import com.mogo.och.data.bean.BusStationBean;
|
||||
import com.mogo.och.common.module.biz.common.socketmessage.data.SystemMsg;
|
||||
import com.mogo.och.common.module.biz.constant.OchCommonConst;
|
||||
@@ -666,6 +667,13 @@ public class OrderModel {
|
||||
arriveStationSuccess(arrivedStationIndex, departureStopName,
|
||||
arriveStation,arriveStationKr,writeVersion);
|
||||
|
||||
String requestId = MultiRequestLimitChecker.Companion.generateRequestId(TAG + "-arriveSiteStation"
|
||||
, String.valueOf(stationList.get(arrivedStationIndex).getSiteId())
|
||||
, String.valueOf(busRoutesResult.getTaskId()));
|
||||
if (!MultiRequestLimitChecker.Companion.getInstance().canMakeRequest(requestId, 5)) {
|
||||
CallerLogger.d(M_BUS + TAG, "arriveSiteStation-MultiRequestLimitChecker: 超过最大请求数,本次请求return");
|
||||
return;
|
||||
}
|
||||
OrderServiceManager.arriveSiteStation(mContext,
|
||||
stationList.get(arrivedStationIndex).getSeq(),
|
||||
stationList.get(arrivedStationIndex).getSiteId(),
|
||||
@@ -674,14 +682,17 @@ public class OrderModel {
|
||||
@Override
|
||||
public void onSuccess(BaseData o) {
|
||||
CallerLogger.d(M_BUS + TAG, "行程日志-arriveSiteStation success");
|
||||
MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(int code, String failMsg) {
|
||||
MultiRequestLimitChecker.Companion.getInstance().decreaseRequestCount(requestId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1260,8 +1260,11 @@ internal class DebugSettingView @JvmOverloads constructor(
|
||||
CallerAutoPilotControlManager.recordPackage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//是否启用证书认证
|
||||
cbSsl.isChecked = SharedPrefsMgr.getInstance().getBoolean(MoGoConfig.AUTOPILOT_CERTIFICATION,false)
|
||||
cbSsl.setOnCheckedChangeListener { _, isChecked ->
|
||||
SharedPrefsMgr.getInstance().putBoolean(MoGoConfig.AUTOPILOT_CERTIFICATION,isChecked)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -900,12 +900,50 @@
|
||||
app:layout_constraintTop_toTopOf="@id/btnSetAutopilotIP" />
|
||||
|
||||
<View
|
||||
android:id="@+id/autopilotIPDivider"
|
||||
android:id="@+id/sslDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="#F0F0F0"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnSetAutopilotIP" />
|
||||
|
||||
<View
|
||||
android:id="@+id/hintView"
|
||||
android:layout_width="5dp"
|
||||
android:layout_height="1dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/sslDivider" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbSsl"
|
||||
style="@style/DebugSettingText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="false"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:scaleX="1.3"
|
||||
android:scaleY="1.3"
|
||||
android:text="证书认证"
|
||||
app:layout_constraintStart_toEndOf="@id/hintView"
|
||||
app:layout_constraintTop_toBottomOf="@id/sslDivider" />
|
||||
|
||||
<TextView
|
||||
style="@style/DebugSettingText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="(此状态会保存,更改后下次连接生效)"
|
||||
app:layout_constraintBottom_toBottomOf="@id/cbSsl"
|
||||
app:layout_constraintStart_toEndOf="@id/cbSsl"
|
||||
app:layout_constraintTop_toTopOf="@id/cbSsl" />
|
||||
|
||||
<View
|
||||
android:id="@+id/autopilotIPDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="#F0F0F0"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSsl" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnRecordPackage"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -11,6 +11,8 @@ object MoGoConfig {
|
||||
|
||||
// 域控制器 IP地址
|
||||
const val AUTOPILOT_IP = "AUTOPILOT_IP"
|
||||
//调试窗控制连接域控时是否启用认证存储key
|
||||
const val AUTOPILOT_CERTIFICATION = "AUTOPILOT_CERTIFICATION"
|
||||
|
||||
// CMD全量日志抓取
|
||||
const val CATCH_LOG = "CATCH_LOG"
|
||||
|
||||
Reference in New Issue
Block a user