This commit is contained in:
zhongchao
2022-03-22 10:07:10 +08:00
parent 3a14b5e37d
commit a39f310331
42 changed files with 1317 additions and 201 deletions

View File

@@ -1,11 +1,7 @@
package com.mogo.eagle.core.function.v2x.events.network;
import android.content.Context;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.network.MoGoRetrofitFactory;
import com.mogo.module.common.constants.HostConst;
import com.mogo.service.network.IMogoNetwork;
/**
* 应对不同接口对应不同服务域名的工厂累
@@ -16,54 +12,52 @@ public class V2XApiServiceFactory {
private static V2XApiService mGeoFenceCarServiceApiService;
private static V2XApiService mRealtimeLocationApiService;
private static V2XApiService mDataServiceApiService;
/**
* 获取指定域名下的 API 服务
*/
public static V2XApiService getApiService(Context context, String netHost) {
IMogoNetwork network = (IMogoNetwork) ARouter.getInstance()
.build(MogoServicePaths.PATH_SERVICES_NETWORK)
.navigation(context);
return network.create(V2XApiService.class, netHost);
public static V2XApiService getApiService(String netHost) {
return MoGoRetrofitFactory.getInstance(netHost).create(V2XApiService.class);
}
public static V2XApiService getDevaApiService(Context context) {
public static V2XApiService getDevaApiService() {
if (mDevaApiService == null) {
synchronized (V2XApiServiceFactory.class) {
if (mDevaApiService == null) {
mDevaApiService = getApiService(context, HostConst.DEVA_HOST);
mDevaApiService = getApiService(HostConst.DEVA_HOST);
}
}
}
return mDevaApiService;
}
public static V2XApiService getGeoFenceCarServiceApiService(Context context) {
public static V2XApiService getGeoFenceCarServiceApiService() {
if (mGeoFenceCarServiceApiService == null) {
synchronized (V2XApiServiceFactory.class) {
if (mGeoFenceCarServiceApiService == null) {
mGeoFenceCarServiceApiService = getApiService(context, HostConst.GEOFENCE_HOST);
mGeoFenceCarServiceApiService = getApiService(HostConst.GEOFENCE_HOST);
}
}
}
return mGeoFenceCarServiceApiService;
}
public static V2XApiService getRealtimeLocationApiService(Context context) {
public static V2XApiService getRealtimeLocationApiService() {
if (mRealtimeLocationApiService == null) {
synchronized (V2XApiServiceFactory.class) {
if (mRealtimeLocationApiService == null) {
mRealtimeLocationApiService = getApiService(context, HostConst.REALTIME_LOCATION_HOST);
mRealtimeLocationApiService = getApiService(HostConst.REALTIME_LOCATION_HOST);
}
}
}
return mRealtimeLocationApiService;
}
public static V2XApiService getStrategyPushApiService(Context context) {
public static V2XApiService getStrategyPushApiService() {
if (mDataServiceApiService == null) {
synchronized (V2XApiServiceFactory.class) {
if (mDataServiceApiService == null) {
mDataServiceApiService = getApiService(context, HostConst.STRATEGY_PUSH_HOST);
mDataServiceApiService = getApiService(HostConst.STRATEGY_PUSH_HOST);
}
}
}

View File

@@ -57,7 +57,7 @@ public class V2XRefreshModel {
public void giveLikeLiveVideo(final V2XRefreshCallback callback, String snStr) {
final Map<String, Object> query = new ParamsProvider.Builder(mContext).build();
query.put("data", "{\"sn\":" + snStr + "}");
V2XApiServiceFactory.getGeoFenceCarServiceApiService(mContext).giveLikeLiveVideo(query)
V2XApiServiceFactory.getGeoFenceCarServiceApiService().giveLikeLiveVideo(query)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {
@@ -92,7 +92,7 @@ public class V2XRefreshModel {
okhttp3.MediaType.parse("application/json; charset=utf-8"),
"{\"sn\":\"" + sn + "\"}");
V2XApiServiceFactory.getRealtimeLocationApiService(mContext).queryUserInfoBySn(body)
V2XApiServiceFactory.getRealtimeLocationApiService().queryUserInfoBySn(body)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<V2XUserInfoRes>(RequestOptions.create(mContext)) {
@@ -142,7 +142,7 @@ public class V2XRefreshModel {
dataStr.append("}");
query.put("data", dataStr.toString());
V2XApiServiceFactory.getRealtimeLocationApiService(mContext).queryNearbyVehicleLiveByLocation(query)
V2XApiServiceFactory.getRealtimeLocationApiService().queryNearbyVehicleLiveByLocation(query)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<V2XLiveCarRes>(RequestOptions.create(mContext)) {
@@ -182,7 +182,7 @@ public class V2XRefreshModel {
.append(0)
.append("}").toString();
map.put("data", json);
V2XApiServiceFactory.getRealtimeLocationApiService(mContext).sendHelpSignal(map).subscribeOn(Schedulers.io())
V2XApiServiceFactory.getRealtimeLocationApiService().sendHelpSignal(map).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {
@Override
@@ -225,7 +225,7 @@ public class V2XRefreshModel {
.append("\"sn\":").append(MoGoAiCloudClientConfig.getInstance().getSn())
.append("}").toString();
map.put("data", json);
V2XApiServiceFactory.getDevaApiService(mContext).addPoiInfoFabulous(map).subscribeOn(Schedulers.io())
V2XApiServiceFactory.getDevaApiService().addPoiInfoFabulous(map).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {
@Override
@@ -263,7 +263,7 @@ public class V2XRefreshModel {
.append("\"enthusiasticSn\":").append(MoGoAiCloudClientConfig.getInstance().getSn())
.append("}").toString();
map.put("data", json);
V2XApiServiceFactory.getDevaApiService(mContext).respondingToHelp(map).subscribeOn(Schedulers.io())
V2XApiServiceFactory.getDevaApiService().respondingToHelp(map).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {
@Override
@@ -290,7 +290,7 @@ public class V2XRefreshModel {
final Map<String, Object> map = new ParamsProvider.Builder(mContext).build();
String json = "{" + "\"id\":\"" + id + "\"," + "\"sn\":\"" + MoGoAiCloudClientConfig.getInstance().getSn() + "\"," + "\"status\":" + status + "," + "\"helpId\":\"" + helpId + "\"}";
map.put("data", json);
V2XApiServiceFactory.getDevaApiService(mContext).manualMarkingTrafficJam(map).subscribeOn(Schedulers.io())
V2XApiServiceFactory.getDevaApiService().manualMarkingTrafficJam(map).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {
@Override
@@ -309,7 +309,7 @@ public class V2XRefreshModel {
* 根据名称获取策略详情
*/
public void getStrategyPush(V2XRefreshCallback<V2XStrategyPushRes> callback) {
V2XApiServiceFactory.getStrategyPushApiService(mContext).getStrategyPush().subscribeOn(Schedulers.io())
V2XApiServiceFactory.getStrategyPushApiService().getStrategyPush().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<V2XStrategyPushRes>(RequestOptions.create(mContext)) {
@Override
@@ -341,7 +341,7 @@ public class V2XRefreshModel {
public void getHelpSignal(V2XRefreshCallback<V2XSeekHelpRes> callback) {
final Map<String, Object> map = new ParamsProvider.Builder(mContext).build();
map.put("sn", MoGoAiCloudClientConfig.getInstance().getSn());
V2XApiServiceFactory.getRealtimeLocationApiService(mContext).queryHelpSignal(map).subscribeOn(Schedulers.io())
V2XApiServiceFactory.getRealtimeLocationApiService().queryHelpSignal(map).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<V2XSeekHelpRes>(RequestOptions.create(mContext)) {
@Override

View File

@@ -104,7 +104,7 @@ public class V2XShareNetworkModel {
builder.append("data", GsonUtil.jsonFromObject(hashMap));
Map<String, Object> parameters = builder.build();
//热心指数
V2XApiServiceFactory.getDevaApiService(mContext).getEnthusiasmIndex(parameters)
V2XApiServiceFactory.getDevaApiService().getEnthusiasmIndex(parameters)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create((mContext))) {
@@ -148,7 +148,7 @@ public class V2XShareNetworkModel {
builder.append("data", GsonUtil.jsonFromObject(hashMap));
Map<String, Object> parameters = builder.build();
V2XApiServiceFactory.getDevaApiService(mContext).getShareEventList(parameters)
V2XApiServiceFactory.getDevaApiService().getShareEventList(parameters)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(mContext)) {

View File

@@ -4,19 +4,17 @@ import com.google.gson.Gson
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.eagle.core.data.BaseResponse
import com.mogo.eagle.core.data.trafficlight.*
import com.mogo.eagle.core.network.MoGoRetrofitFactory
import com.mogo.eagle.core.network.apiCall
import com.mogo.eagle.core.network.cancel
import com.mogo.eagle.core.network.request
import com.mogo.module.common.MogoApisHandler
import com.mogo.module.common.constants.HostConst.CITY_HOST
class TrafficLightNetWorkModel {
private fun getNetWorkApi(baseUrl: String = CITY_HOST): TrafficLightApiService {
return MogoApisHandler.getInstance().apis.networkApi.createNoCallAdapter(
TrafficLightApiService::class.java, baseUrl
)
return MoGoRetrofitFactory.getInstanceNoCallAdapter(baseUrl)
.create(TrafficLightApiService::class.java)
}
fun requestRoadID(
@@ -86,10 +84,10 @@ class TrafficLightNetWorkModel {
}
}
onSuccess {
if(it.result!=null){
if (it.result != null) {
onSuccess.invoke(it.result)
}else{
onError.invoke(it.msg?:"返回result数据为null")
} else {
onError.invoke(it.msg ?: "返回result数据为null")
}
}
onError {
@@ -115,7 +113,8 @@ class TrafficLightNetWorkModel {
request<BaseResponse<Any>> {
val map = hashMapOf<String, String>()
start {
val trafficLightRequestData = ChangeLightRequestData(lightId, crossingNo, heading, controlTime)
val trafficLightRequestData =
ChangeLightRequestData(lightId, crossingNo, heading, controlTime)
map["sn"] = MoGoAiCloudClientConfig.getInstance().sn
map["data"] = Gson().toJson(trafficLightRequestData)
}

View File

@@ -3,18 +3,17 @@ package com.mogo.eagle.core.function.v2x.vip.network
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.eagle.core.data.BaseResponse
import com.mogo.eagle.core.data.v2x.VipRequest
import com.mogo.eagle.core.network.MoGoRetrofitFactory
import com.mogo.eagle.core.network.apiCall
import com.mogo.eagle.core.network.request
import com.mogo.module.common.MogoApisHandler
import com.mogo.module.common.constants.HostConst.DATA_SERVICE_HOST
class VipNetWorkModel {
private fun getNetWorkApi(baseUrl: String = DATA_SERVICE_HOST): VipApiService {
return MogoApisHandler.getInstance().apis.networkApi.createNoCallAdapter(
VipApiService::class.java, baseUrl
)
return MoGoRetrofitFactory.getInstanceNoCallAdapter(baseUrl)
.create(VipApiService::class.java)
}
fun requestVip(onSuccess: ((VipRequest) -> Unit), onError: ((String) -> Unit)) {