添加拥堵自动上报接口实现
This commit is contained in:
@@ -20,15 +20,16 @@ import com.mogo.utils.logger.Logger
|
||||
@Route(path = MogoServicePaths.PATH_STRATEGY_SHARE)
|
||||
class StrategyShareProvider : IProvider {
|
||||
private lateinit var blockStrategy: BlockStrategy
|
||||
override fun init(context: Context?) {
|
||||
override fun init(context: Context) {
|
||||
Logger.d(S_TAG, "策略上报Provider初始化====")
|
||||
val apis = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context) as IMogoServiceApis
|
||||
blockStrategy = BlockStrategy(apis)
|
||||
blockStrategy = BlockStrategy(context, apis)
|
||||
// 注册事故
|
||||
apis.getSocketManagerApi(context).registerOnMessageListener(ACCIDENT_STRATEGY_SHARE_PUSH_TYPE, AccidentStrategyReceiver(apis))
|
||||
apis.registerCenterApi.registerMogoLocationListener(MogoServicePaths.PATH_STRATEGY_SHARE){
|
||||
// Logger.d(S_TAG,"定位发生变化,准备记录速度: ${it.speed}")
|
||||
blockStrategy.recordSpeed(it.speed)
|
||||
|
||||
blockStrategy.recordSpeed(it.speed * 3.6F)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.mogo.module.share.bean
|
||||
|
||||
import com.mogo.commons.data.BaseData
|
||||
|
||||
data class AverateSpeedResponse(var result:Result):BaseData()
|
||||
data class Result(var upload:Boolean)
|
||||
@@ -1,4 +1,8 @@
|
||||
package com.mogo.module.share.constant
|
||||
|
||||
const val S_TAG = "StrategyShare"
|
||||
|
||||
/**
|
||||
* 目前两个策略上报(事故,拥堵)都是走的这个push
|
||||
*/
|
||||
const val ACCIDENT_STRATEGY_SHARE_PUSH_TYPE = 401013
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.module.share.net
|
||||
|
||||
import com.mogo.commons.data.BaseData
|
||||
import com.mogo.module.share.bean.AverateSpeedResponse
|
||||
import io.reactivex.Observable
|
||||
import retrofit2.http.*
|
||||
|
||||
@@ -18,6 +19,6 @@ interface ShareApiService {
|
||||
/**
|
||||
* 拥堵策略,上报平均速度
|
||||
*/
|
||||
@POST("")
|
||||
fun sendAverageSpeedForBlockStrategy(@FieldMap param:Map<String,String>):Observable<BaseData>
|
||||
@POST("/deva/car/path/no/poiStrategyCheck/v1")
|
||||
fun sendAverageSpeedForBlockStrategy(@FieldMap param:Map<String,String>):Observable<AverateSpeedResponse>
|
||||
}
|
||||
@@ -1,11 +1,26 @@
|
||||
package com.mogo.module.share.strategyreceiver
|
||||
|
||||
|
||||
|
||||
data class AccidentStrategyPushWrapper(
|
||||
/**
|
||||
* 策略类型,1代表事故
|
||||
* 策略类型,[TYPE_ACCIDENT],[TYPE_BLOCK]
|
||||
*/
|
||||
val type: Int,
|
||||
/**
|
||||
* 触发点的事件id
|
||||
*/
|
||||
val id: Long, val lat: Double, val lon: Double)
|
||||
val id: Long, val lat: Double, val lon: Double){
|
||||
|
||||
companion object{
|
||||
/**
|
||||
* 服务端下发push,通知收集事故视频
|
||||
*/
|
||||
const val TYPE_ACCIDENT = 1
|
||||
|
||||
/**
|
||||
* 服务端下发push,通知收集拥堵
|
||||
*/
|
||||
const val TYPE_BLOCK = 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.mogo.module.share.strategyreceiver
|
||||
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.module.share.constant.S_TAG
|
||||
import com.mogo.module.share.strategyreceiver.AccidentStrategyPushWrapper.Companion.TYPE_ACCIDENT
|
||||
import com.mogo.module.share.strategyreceiver.AccidentStrategyPushWrapper.Companion.TYPE_BLOCK
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.connection.IMogoOnMessageListener
|
||||
import com.mogo.service.tanlu.IMogoTanluProvider
|
||||
@@ -12,14 +14,22 @@ import com.mogo.utils.logger.Logger
|
||||
* 车辆经过事故事件,上报视频
|
||||
* @author tong
|
||||
*/
|
||||
class AccidentStrategyReceiver(private val apis: IMogoServiceApis):IMogoOnMessageListener<AccidentStrategyPushWrapper> {
|
||||
class AccidentStrategyReceiver(private val apis: IMogoServiceApis) : IMogoOnMessageListener<AccidentStrategyPushWrapper> {
|
||||
override fun target(): Class<AccidentStrategyPushWrapper> = AccidentStrategyPushWrapper::class.java
|
||||
|
||||
override fun onMsgReceived(obj: AccidentStrategyPushWrapper?) {
|
||||
obj?.let {
|
||||
Logger.d(S_TAG, "Accident strategy share onMessageReceived: $obj")
|
||||
// 调用探路接口上报,现在只接入了事故事件上报这一种策略上报,所以poiType固定为TypeAccident
|
||||
apis.tanluApi.uploadRoadCondition(TanluUploadParams(IMogoTanluProvider.TYPE_ACCIDENT, IMogoTanluProvider.UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO, it.id, MogoLatLng(it.lat, it.lon)))
|
||||
when (obj.type) {
|
||||
TYPE_ACCIDENT -> {
|
||||
// 收集事故视频
|
||||
apis.tanluApi.uploadRoadCondition(TanluUploadParams(IMogoTanluProvider.TYPE_ACCIDENT, IMogoTanluProvider.UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO, it.id, MogoLatLng(it.lat, it.lon)))
|
||||
}
|
||||
TYPE_BLOCK -> {
|
||||
// 收集拥堵视频
|
||||
apis.tanluApi.uploadRoadCondition(TanluUploadParams(IMogoTanluProvider.TYPE_BLOCK, IMogoTanluProvider.UPLOAD_FROM_STRATEGY_CLOUD_CHECK, it.id, MogoLatLng(it.lat, it.lon)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.mogo.module.share.strategyreceiver
|
||||
|
||||
import android.content.Context
|
||||
import android.os.SystemClock
|
||||
import android.util.ArrayMap
|
||||
import com.mogo.commons.network.SubscribeImpl
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.module.share.bean.AverateSpeedResponse
|
||||
import com.mogo.module.share.constant.HttpConstant
|
||||
import com.mogo.module.share.manager.ServiceApisManager
|
||||
import com.mogo.module.share.net.ShareApiService
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.tanlu.IMogoTanluProvider
|
||||
import com.mogo.service.tanlu.TanluUploadParams
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.mogo.utils.network.RequestOptions
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,7 +30,7 @@ private const val TAG = "BlockUploadStrategy"
|
||||
/**
|
||||
* 用于计算拥堵策略
|
||||
*/
|
||||
class BlockStrategy(private val apis: IMogoServiceApis) {
|
||||
class BlockStrategy(private val context: Context, private val apis: IMogoServiceApis) {
|
||||
private var startRecordTime: Long = 0
|
||||
private var speedCacheList = ArrayList<Float>()
|
||||
|
||||
@@ -58,13 +64,13 @@ class BlockStrategy(private val apis: IMogoServiceApis) {
|
||||
|
||||
if (speed == 0F) {
|
||||
stopFlag++
|
||||
}else{
|
||||
} else {
|
||||
stopFlag = 0
|
||||
}
|
||||
|
||||
if (current - startRecordTime >= SPEED_RECORD_TIME_INTERVAL) {
|
||||
// 到达时间限制,上报速度,数据清空
|
||||
if(stopFlag < STOP_FLAG_THRESHOLD) {
|
||||
if (stopFlag < STOP_FLAG_THRESHOLD) {
|
||||
// 停车标志位小于阈值,判定不是停车,计算平均值,进行上报
|
||||
var sum = 0F
|
||||
speedCacheList.forEach {
|
||||
@@ -74,8 +80,8 @@ class BlockStrategy(private val apis: IMogoServiceApis) {
|
||||
Logger.d(TAG, "平均速度为: $ave")
|
||||
// 上报平均速度
|
||||
uploadAverageSpeed(ave)
|
||||
}else{
|
||||
Logger.d(TAG,"判定为停车,不进行上报")
|
||||
} else {
|
||||
Logger.d(TAG, "判定为停车,不进行上报")
|
||||
}
|
||||
startRecordTime = 0
|
||||
}
|
||||
@@ -83,11 +89,23 @@ class BlockStrategy(private val apis: IMogoServiceApis) {
|
||||
|
||||
private fun uploadAverageSpeed(average: Float) {
|
||||
val params = ArrayMap<String, String>()
|
||||
params["aveSpeed"] = average.toString()
|
||||
val disposable = apis.networkApi.create(ShareApiService::class.java, HttpConstant.getNetHost()).sendAverageSpeedForBlockStrategy(params).subscribe {
|
||||
// todo 收到服务端回调,视情况进行视频上报
|
||||
val p = TanluUploadParams(IMogoTanluProvider.TYPE_BLOCK, IMogoTanluProvider.UPLOAD_FROM_STRATEGY_BLOCK_AUTO)
|
||||
apis.tanluApi.uploadRoadCondition(p)
|
||||
}
|
||||
params["speed"] = average.toString()
|
||||
val disposable = apis.networkApi.create(ShareApiService::class.java, HttpConstant.getNetHost()).sendAverageSpeedForBlockStrategy(params).subscribe(object : SubscribeImpl<AverateSpeedResponse>(RequestOptions.create(context)) {
|
||||
override fun onSuccess(response: AverateSpeedResponse?) {
|
||||
super.onSuccess(response)
|
||||
response?.let {
|
||||
Logger.d(TAG, "收到服务端返回结果: $it")
|
||||
// 收到服务端回调,视情况进行视频上报
|
||||
if (it.result.upload) {
|
||||
val p = TanluUploadParams(IMogoTanluProvider.TYPE_BLOCK, IMogoTanluProvider.UPLOAD_FROM_STRATEGY_BLOCK_AUTO)
|
||||
val location = ServiceApisManager.serviceApis.mapServiceApi.getSingletonLocationClient(context).lastKnowLocation
|
||||
val latLon = MogoLatLng(location.latitude, location.longitude)
|
||||
p.location = latLon
|
||||
apis.tanluApi.uploadRoadCondition(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user