[charter m1]增加订单轮询

This commit is contained in:
wangmingjun
2023-03-01 21:33:06 +08:00
parent 84c5a4b664
commit 979789b7e8
7 changed files with 120 additions and 28 deletions

View File

@@ -0,0 +1,36 @@
package com.magic.mogo.och.charter
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotControlManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
/**
* @author: wangmingjun
* @date: 2022/10/24
*/
object CharterSendTripInfoManager{
const val START_TRIP = 1
const val END_TRIP = 2
const val LEAVE_STATION = 3
const val ARRIVE_STATION = 4
/**
* 行程信息
* @param type 事件类型, 1:行程开始, 2:行程结束, 3:出站, 4:进站, 5:城市占道施工预警
* @param lineName 路线名, for type 1, 2
* @param departureStopName 出站站点名, for type 3, 4
* @param arrivalStopName 下一站到达站点名, for type 3, 4
* @param isLastStop 是否终点站(下一站或者要到达站)
* @return
*/
fun sendCharterTripInfo(type: Int, lineName: String,
departureStopName: String,
arrivalStopName: String,
isLastStop: Boolean) {
d(SceneConstant.M_BUS + "CharterSendTripInfoManager", "type: "+ type
+", lineName: "+ lineName +", departureStopName: "+ departureStopName
+ ", arrivalStopName: "+arrivalStopName+", isLastStop: "+isLastStop)
CallerAutoPilotControlManager.sendTripInfo(type,lineName,departureStopName, arrivalStopName, isLastStop)
}
}

View File

@@ -1,13 +1,22 @@
package com.magic.mogo.och.charter.bean
import com.mogo.eagle.core.data.BaseData
import java.util.*
/**
* @author: wangmingjun
* @date: 2023/2/24
*/
data class QueryBusinessStatusResponse(var data: Result):BaseData(){
data class Result(var orderNo: String, var businessStatus: Int)
data class Result(var orderNo: String, var businessStatus: Int){
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
val result = o as Result
return Objects.equals(orderNo ,result.orderNo)
&& businessStatus == result.businessStatus
}
}
//1: 闲置 2:orderNo = "" 当前并没有核销的订单, orderNo != "" 当前车辆需还车状态
}

View File

@@ -1,6 +1,7 @@
package com.magic.mogo.och.charter.bean
import com.mogo.eagle.core.data.BaseData
import java.util.*
/**
* @author: wangmingjun
@@ -13,7 +14,7 @@ data class QueryCurrentOrderResponse(var data: Result):BaseData(){ //线路id ,
var orderNo: String,
var lineId: Int,
var lineName: String,
var startSiteId: String,
var startSiteId: Int,
var startSiteName: String,
var siteId: Int,
var siteName: String,
@@ -27,16 +28,16 @@ data class QueryCurrentOrderResponse(var data: Result):BaseData(){ //线路id ,
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
val result = o as Result
return orderNo == result.orderNo
&& sn == result.sn
return Objects.equals(orderNo ,result.orderNo)
&& Objects.equals(sn ,result.sn)
&& lineId == result.lineId
&& startSiteId == result.startSiteId
&& startSiteName == result.startSiteName
&& Objects.equals(startSiteName ,result.startSiteName)
&& siteId == result.siteId
&& siteName == result.siteName
&& Objects.equals(siteName , result.siteName)
&& wgs84Lon == result.wgs84Lon
&& wgs84Lon == result.wgs84Lon
&& passengerPhone == result.passengerPhone
&& Objects.equals(passengerPhone , result.passengerPhone)
}
}
}

View File

@@ -25,13 +25,13 @@ object DriverM1LooperManager {
CallerLogger.i(SceneConstant.M_CHARTER_D + TAG, "startQueryDriverLineLoop()")
mQueryLineDisposable = Observable.interval(
CharterConst.LOOP_DELAY,
CharterConst.LOOP_2S, TimeUnit.MILLISECONDS
CharterConst.LOOP_PERIOD_2S, TimeUnit.MILLISECONDS
)
.map { aLong: Long -> aLong + 1 }
.subscribeOn(Schedulers.io())
.subscribe { aLong: Long? ->
aLong?.let {
DriverM1Model.get().queryCurrentServiceStatus()
DriverM1Model.get().queryCurrentOrder()
}
}
}

View File

@@ -7,6 +7,10 @@ import com.alibaba.android.arouter.utils.TextUtils
import com.amap.api.maps.model.LatLng
import com.elegant.network.utils.GsonUtil
import com.magic.mogo.och.charter.CharterAnalyticsManager
import com.magic.mogo.och.charter.CharterSendTripInfoManager
import com.magic.mogo.och.charter.CharterSendTripInfoManager.ARRIVE_STATION
import com.magic.mogo.och.charter.CharterSendTripInfoManager.END_TRIP
import com.magic.mogo.och.charter.CharterSendTripInfoManager.START_TRIP
import com.magic.mogo.och.charter.R
import com.magic.mogo.och.charter.bean.CheckOrderCountDownResponse
import com.magic.mogo.och.charter.bean.QueryBusinessStatusResponse
@@ -76,6 +80,8 @@ class DriverM1Model {
private var mCurrentOrder: QueryCurrentOrderResponse.Result? = null
private var mCurrentBusinessStatus: QueryBusinessStatusResponse.Result? = null
private var currentChangeDestMsg: ChangeDestMsg? = null
private var mCurrentRoute: QueryRoutesResponse.Result? = null
@@ -362,7 +368,10 @@ class DriverM1Model {
private fun onArriveAt() {
isArrivedStation = true
// todo 需要告诉前后外屏到站
d(SceneConstant.M_CHARTER_D + TAG, "onArriveAt = " + GsonUtil.jsonFromObject(mCurrentOrder))
if (mCurrentOrder == null) return
CharterSendTripInfoManager.sendCharterTripInfo(ARRIVE_STATION,mCurrentOrder?.lineName!!
,mCurrentOrder?.startSiteName!!,mCurrentOrder?.siteName!!,false)
}
/**
@@ -493,6 +502,14 @@ class DriverM1Model {
DriverM1LooperManager.stopQueryDriverLineLoop()
}
private fun startOrStopCheckCountDown(start: Boolean) {
if (start){
DriverM1LooperManager.starCountDownLoop()
}else{
DriverM1LooperManager.stopCountDownLoop()
}
}
/**
* 司机端发送消息给乘客屏
*/
@@ -530,23 +547,27 @@ class DriverM1Model {
DriverM1ServiceManager.queryCurrentServiceStatus(mContext
,object: OchCommonServiceCallback<QueryBusinessStatusResponse>{
override fun onSuccess(data: QueryBusinessStatusResponse?) {
if (data == null || data.code != 0){
if (data == null || data.code != 0 || data.data.equals(mCurrentBusinessStatus)){
d(SceneConstant.M_CHARTER_D + TAG, "data is null or data not change" )
return
}
stopQueryCurrentOrder()
mCurrentBusinessStatus = data.data
d(SceneConstant.M_CHARTER_D + TAG, "queryCurrentServiceStatus success = "
+ GsonUtils.toJson(data.data))
if (data.data.businessStatus == 2){//订单为空,则是要换车状态
if (TextUtils.isEmpty(data.data.orderNo)){//还未换车,显示还车状态
mOrderCallback?.updateReturnCarStatus(false)
mCurrentOrder == null
sendCharterEndTripInfo()
startOrStopCheckCountDown(false)
}else{ // 订单不为空,有服务中订单,去查询订单
mOrderCallback?.updateReturnCarStatus(true)
queryCurrentOrder()
startQueryCurrentOrder()
}
}else{ //车辆无订单,闲置状态
clearAutopilotControlParameters()
mCurrentOrder = null
startOrStopCheckCountDown(false)
}
}
@@ -561,14 +582,34 @@ class DriverM1Model {
DriverM1ServiceManager.queryCurrentOrder(mContext
,object: OchCommonServiceCallback<QueryCurrentOrderResponse>{
override fun onSuccess(data: QueryCurrentOrderResponse?) {
if (data == null || data.code != 0 || data.data.equals(mCurrentOrder)){
if (data == null || data.code != 0){
isArrivedStation = false
return
}
if (data.data == null){
d(SceneConstant.M_CHARTER_D + TAG, "data.data is null")
isArrivedStation = false
mCurrentOrder = null
queryCurrentServiceStatus()
stopQueryCurrentOrder()
return
}
if (data.data.equals(mCurrentOrder)){
d(SceneConstant.M_CHARTER_D + TAG, "data not change")
return
}
d(SceneConstant.M_CHARTER_D + TAG, "queryCurrentOrder order =" +
GsonUtils.toJson(data.data))
mCurrentOrder = data.data
if (TextUtils.isEmpty(data.data.lineName)){
d(SceneConstant.M_CHARTER_D + TAG, "lineName = null")
return
}
mOrderCallback?.updateOrderUI(data.data)
//给工控机发轨迹
checkoutContrail()
@@ -576,6 +617,8 @@ class DriverM1Model {
startOrStopCheckCountDown(true)
//鹰眼存参数
updateAutopilotControlParameters()
//给前后屏发数据
sendCharterStartTripInfo()
}
override fun onFail(code: Int, msg: String?) {
@@ -584,12 +627,19 @@ class DriverM1Model {
})
}
private fun startOrStopCheckCountDown(start: Boolean) {
if (start){
DriverM1LooperManager.starCountDownLoop()
}else{
DriverM1LooperManager.stopCountDownLoop()
}
/**
* 发送数据给前后屏幕
*/
private fun sendCharterStartTripInfo() {
if (mCurrentOrder == null) return
CharterSendTripInfoManager.sendCharterTripInfo(START_TRIP,mCurrentOrder?.lineName!!
,"","",false)
}
private fun sendCharterEndTripInfo() {
if (mCurrentOrder == null) return
CharterSendTripInfoManager.sendCharterTripInfo(END_TRIP,mCurrentOrder?.lineName!!
,"","",false)
}
fun checkOrderCountDown() {

View File

@@ -66,16 +66,12 @@ class DriverM1Presenter(view: DriverM1Fragment?) :
override fun loginSuccess(data: DriverStatusQueryRespBean?) {
d(SceneConstant.M_BUS + TAG, " loginStatus =" + isLogin())
if (isLogin()) {
// 查询服务状态
DriverM1Model.get().queryCurrentServiceStatus()
} else {
DriverM1Model.get().startQueryCurrentOrder()
}
// 查询服务状态
DriverM1Model.get().queryCurrentServiceStatus()
}
override fun loginFail(isLogin: Boolean) {
DriverM1Model.get().startQueryCurrentOrder()
DriverM1Model.get().stopQueryCurrentOrder()
}
// 登出

View File

@@ -13,7 +13,7 @@ class CharterConst {
const val LOOP_PERIOD_60S = 60 * 1000L
// 开始服务启动自动驾驶等待时间(埋点上传)
const val LOOP_PERIOD_15S = 15 * 1000L
const val LOOP_PERIOD_1S = 1 * 1000L
const val LOOP_PERIOD_2S = 2 * 1000L
const val LOOP_DELAY = 100L
// 下发给MEC轨迹信息间隔时间 10秒