[fea]
[任务网络错误]
This commit is contained in:
yangyakun
2024-09-23 19:49:45 +08:00
parent e4f281cafc
commit dcdce2f6cc
21 changed files with 181 additions and 62 deletions

View File

@@ -29,4 +29,6 @@ public interface IBusLinesCallback {
default void onArriveStationSuccess(){}
default void onCompleteTask(){}
default void onBusLineTasksError(){}
}

View File

@@ -33,10 +33,13 @@ import com.mogo.och.weaknet.repository.db.repository.LineDb
import com.mogo.och.weaknet.repository.db.repository.TaskDb
import com.mogo.och.weaknet.repository.db.repository.TaskSiteDb
import com.mogo.och.weaknet.repository.net.RepositoryManager
import com.mogo.och.weaknet.repository.net.impl.shuttle.ShuttleRepository
import com.mogo.och.weaknet.repository.net.exception.DataException
import com.mogo.och.weaknet.repository.net.impl.shuttlesaas.OrderServiceManager
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.net.UnknownHostException
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean
@@ -208,6 +211,8 @@ object LineModel {
@JvmStatic
fun queryBusLineTasksById(lineId: Long) {
RepositoryManager.queryCanUserTask(lineId)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<List<TaskDataBean?>?> {
override fun onSubscribe(d: Disposable) {
d(TAG, "onSubscribe")
@@ -215,6 +220,9 @@ object LineModel {
override fun onError(e: Throwable) {
d(TAG, "onError${e.printStackTrace()}")
mBusLinesCallbackMap.forEach {
it.value.onBusLineTasksError()
}
}
override fun onComplete() {
@@ -237,26 +245,38 @@ object LineModel {
fun commitSwitchLineId(task: TaskDataBean, line: LineDataBean) {
line.getLineIdAndName { lineId, lineName ->
task.getLineIdAndName { taskId, taskTime ->
TaskDb.startTask(
taskId,
lineId,
lineName,
object : TaskDb.TaskStatusCallback {
override fun startSuccess() {
EventDb.saveEventTaskStart(taskId,lineId,taskTime,lineName)
OrderModel.queryBusRoutes()
mBusLinesCallbackMap.forEach {
it.value.onChangeLineIdSuccess()
RepositoryManager.startTask(taskId, lineId, taskTime, lineName)
?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<Boolean> {
override fun onSubscribe(d: Disposable) {
d(TAG, "onSubscribe")
}
override fun onError(e: Throwable) {
d(TAG, "onError${e.printStackTrace()}")
if (e is DataException) {
OchChainLogManager.writeChainLog("开始任务", "${e.message}")
ToastUtils.showShort("选择任务失败:${e.message}")
mBusLinesCallbackMap.forEach {
it.value.onChangeLineIdFail()
}
}
}
override fun startFail(msg: String) {
ToastUtils.showShort("选择任务失败:$msg")
mBusLinesCallbackMap.forEach {
it.value.onChangeLineIdFail()
}
override fun onComplete() {
d(TAG, "onComplete")
}
override fun onNext(data: Boolean) {
if (data) {
EventDb.saveEventTaskStart(taskId, lineId, taskTime, lineName)
OrderModel.queryBusRoutes()
mBusLinesCallbackMap.forEach {
it.value.onChangeLineIdSuccess()
}
}
}
})
}
}

View File

@@ -1,6 +1,6 @@
package com.mogo.och.weaknet.repository.db.exception
class DataException: RuntimeException {
class DbException: RuntimeException {
constructor() : super()
constructor(message: String?) : super(message)
}

View File

@@ -9,7 +9,8 @@ import com.mogo.och.common.module.utils.DateTimeUtil
import com.mogo.och.weaknet.repository.db.MyDataBase
import com.mogo.och.weaknet.repository.db.bean.TaskDataBean
import com.mogo.och.weaknet.repository.db.dao.TaskDataDao
import com.mogo.och.weaknet.repository.db.exception.DataException
import com.mogo.och.weaknet.repository.db.exception.DbException
import com.mogo.och.weaknet.repository.net.exception.DataException
import io.reactivex.Observable
object TaskDb {
@@ -70,8 +71,9 @@ object TaskDb {
return null
}
fun startTask(taskId: Long, lineId: Long,lineName:String,callback: TaskStatusCallback){
BizLoopManager.postDelayed({
fun startTask(taskId: Long, lineId: Long,lineName:String): Observable<Boolean>? {
return Observable.just(taskId)
.flatMap {
var updateCount:Int? = 0
var startTime = System.currentTimeMillis()
try {
@@ -89,7 +91,7 @@ object TaskDb {
OchChainLogManager.writeChainLogDb("开始任务", "把正在使用的数据更新到RunningTask表格一共${updateCount}行数据")
CallerLogger.d(TAG,"插入正在运行的线路用时:${System.currentTimeMillis()-startTime}")
} catch (e: Exception) {
if (e is DataException) {
if (e is DbException) {
println("数据不全")
// 恢复数据
taskDataDao?.queryTaskByTaskIdOne(taskId)?.let {
@@ -100,21 +102,19 @@ object TaskDb {
OchChainLogManager.writeChainLogDb("开始任务", "异常情况${lineId}_${lineName}_task:${taskId} 为未使用的状态 原因:${e.message}")
}
}
updateCount = null
callback.startFail("错误信息:${e.message}")
}finally {
updateCount?.let {
if(it<=0){
// 插入失败
callback.startFail("未插入数据")
}else{
// 开始任务成功
callback.startSuccess()
}
}
return@flatMap Observable.error(DataException(DataException.startTaskErrorCode,e.message))
}
},0)
updateCount?.let {
if(it<=0){
// 插入失败
return@flatMap Observable.error(DataException(DataException.startTaskErrorCode,"未插入数据"))
}else{
// 开始任务成功
return@flatMap Observable.just(true)
}
}
}
}
fun queryRunningTaskByLineId(lineId: Long): List<TaskDataBean>? {

View File

@@ -7,8 +7,7 @@ import com.mogo.och.common.module.manager.loop.BizLoopManager
import com.mogo.och.weaknet.repository.db.MyDataBase
import com.mogo.och.weaknet.repository.db.bean.TaskSiteDataBean
import com.mogo.och.weaknet.repository.db.dao.TaskSiteDataDao
import com.mogo.och.weaknet.repository.db.exception.DataException
import com.mogo.och.weaknet.repository.db.exception.NetDataException
import com.mogo.och.weaknet.repository.db.exception.DbException
object TaskSiteDb {
@@ -28,7 +27,7 @@ object TaskSiteDb {
var startTime = System.currentTimeMillis()
val querySites = SiteDb.querySiteByLineId(linId)
if(querySites.isNullOrEmpty()){
throw DataException("没有站点数据")
throw DbException("没有站点数据")
}
CallerLogger.d(TAG,"查询站点用时:${System.currentTimeMillis()-startTime}")
startTime = System.currentTimeMillis()
@@ -39,7 +38,7 @@ object TaskSiteDb {
)
CallerLogger.d(TAG,"数据转换用时:${System.currentTimeMillis()-startTime}")
if(toTaskSiteDatas.size<2){
throw DataException("站点数据不全请稍后再试")
throw DbException("站点数据不全请稍后再试")
}
// 把线路所有的站点搬迁到运行中表格中
startTime = System.currentTimeMillis()

View File

@@ -8,4 +8,6 @@ interface IRepository {
fun queryCanUseLine(): Observable<List<LineDataBean>?>?
fun queryCanUserTask(lineId:Long): Observable<List<TaskDataBean>?>?
fun startTask(taskId:Long,lineId:Long,taskTime:Long,lineName:String): Observable<Boolean>?
}

View File

@@ -20,7 +20,7 @@ object RepositoryManager {
init {
if(ProjectUtils.isSaas()){
if(AppIdentityModeUtils.isShuttle(FunctionBuildConfig.appIdentityMode)) {
repository = ShuttleSaasRepository()
repository = ShuttleRepository()
}else if(AppIdentityModeUtils.isBus(FunctionBuildConfig.appIdentityMode)) {
repository = BusSaasRepository()
}
@@ -41,5 +41,8 @@ object RepositoryManager {
return repository.queryCanUserTask(lineId)
}
fun startTask(taskId:Long,lineId:Long,taskTime:Long,lineName:String): Observable<Boolean>? {
return repository.startTask(taskId,lineId,taskTime,lineName)
}
}

View File

@@ -9,10 +9,10 @@ import com.mogo.och.common.module.utils.DateTimeUtil;
*/
public class BusResetDrivingLineRequest {
public String sn;
public int taskId; //切换到的线路id
public Long taskId; //切换到的线路id
public long writeVersion; //更新时间戳
public BusResetDrivingLineRequest(int taskId) {
public BusResetDrivingLineRequest(Long taskId) {
this.sn = SharedPrefsMgr.getInstance().getSn();
this.taskId = taskId;
this.writeVersion = DateTimeUtil.getCurrentTimeStamp();

View File

@@ -0,0 +1,9 @@
package com.mogo.och.weaknet.repository.net.exception
class DataException: RuntimeException {
constructor() : super()
constructor(code:Int,message: String?) : super("${code}_${message}")
companion object{
val startTaskErrorCode = 10010
}
}

View File

@@ -28,5 +28,14 @@ class BusRepository: IRepository {
TODO("Not yet implemented")
}
override fun startTask(
taskId: Long,
lineId: Long,
taskTime: Long,
lineName: String
): Observable<Boolean>? {
TODO("Not yet implemented")
}
}

View File

@@ -60,7 +60,7 @@ object OrderServiceManager {
@JvmStatic
fun switchLine(
context: Context,
taskId: Int,
taskId: Long,
callback: OchCommonServiceCallback<BusRoutesResponse>?
) {
M_SERVICE.switchLine(

View File

@@ -28,5 +28,14 @@ class BusSaasRepository: IRepository {
TODO("Not yet implemented")
}
override fun startTask(
taskId: Long,
lineId: Long,
taskTime: Long,
lineName: String
): Observable<Boolean>? {
TODO("Not yet implemented")
}
}

View File

@@ -57,7 +57,7 @@ object OrderServiceManager {
@JvmStatic
fun switchLine(
context: Context,
taskId: Int,
taskId: Long,
callback: OchCommonServiceCallback<BusRoutesResponse>?
) {
M_SAAS_SERVICE.switchLine(

View File

@@ -42,7 +42,7 @@ public interface IBascApiService {
*/
@Headers( {"Content-Type:application/json;charset=UTF-8"} )
@POST( "/och-shuttle-cabin/api/flow/v1/driver/startTask" )
Observable<BusRoutesResponse> switchLine(@Header ("appId") String appId, @Header("ticket") String ticket, @Body BusResetDrivingLineRequest request);
Observable<BaseData> switchLine(@Header ("appId") String appId, @Header("ticket") String ticket, @Body BusResetDrivingLineRequest request);
/**
* 离站,通知服务器

View File

@@ -59,17 +59,17 @@ object OrderServiceManager {
*/
@JvmStatic
fun switchLine(
context: Context,
taskId: Int,
callback: OchCommonServiceCallback<BusRoutesResponse>?
) {
mService.switchLine(
taskId: Long,
): Observable<Boolean>? {
return mService.switchLine(
MoGoAiCloudClientConfig.getInstance().serviceAppId,
SharedPrefsMgr.getInstance().token,
BusResetDrivingLineRequest(taskId)
)
.transformTry()
.subscribe(OchCommonSubscribeImpl(context, callback, "switchLine"))
) .transformTry()
.flatMap(OchCommonNet("switchLine",false))
.flatMap {
Observable.just(true)
}
}
/**
@@ -184,7 +184,7 @@ object OrderServiceManager {
SharedPrefsMgr.getInstance().token,
lineId
) .transformTry()
.flatMap(OchCommonNet<BusQueryLineTaskResponse>("queryBusLines",false))
.flatMap(OchCommonNet("queryBusLines",false))
.flatMap {
Observable.just(it.data)
}

View File

@@ -7,10 +7,6 @@ import io.reactivex.Observable
class ShuttleRepository: IRepository {
init {
}
override fun queryCanUseLine(): Observable<List<LineDataBean>?> {
return OrderServiceManager.queryBusLines()
}
@@ -19,8 +15,8 @@ class ShuttleRepository: IRepository {
return OrderServiceManager.queryBusTaskByLineId(lineId)
}
companion object{
override fun startTask(taskId: Long, lineId: Long, taskTime: Long, lineName: String): Observable<Boolean>? {
return OrderServiceManager.switchLine(taskId)
}
}

View File

@@ -17,4 +17,8 @@ class ShuttleSaasRepository: IRepository {
return TaskDb.queryCanUserTask(lineId)
}
override fun startTask(taskId:Long,lineId:Long,taskTime:Long,lineName:String): Observable<Boolean>? {
return TaskDb.startTask(taskId, lineId, lineName)
}
}

View File

@@ -17,12 +17,13 @@ import com.mogo.och.weaknet.repository.db.bean.LineDataBean
import com.mogo.och.weaknet.repository.db.bean.TaskDataBean
import com.mogo.och.weaknet.ui.bizswitch.SwtichBizeModel
import com.mogo.och.weaknet.ui.switchtask.SwitchLineTaskAdapter.TaskItemClickListener
import kotlinx.android.synthetic.main.shuttle_weak_error_view.view.tv_error_msg
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.actvLineEndStationName
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.actv_cancle_task
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.actv_submit_task
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.busLineName
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.cl_submit_task
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.include_empty
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.include_error
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.loading_start_line
import kotlinx.android.synthetic.main.shuttle_weak_switch_task.view.rv_switch_task
import me.jessyan.autosize.utils.AutoSizeUtils
@@ -84,6 +85,11 @@ class SwitchTaskView: WindowRelativeLayout, SwtichTaskModel.SwtichLineViewCallba
actv_cancle_task.onClick {
viewbizModel?.showSwitchLineInfo()
}
tv_error_msg.onClick {
viewModel?.tasksBelongLine?.let {
viewbizModel?.loadingSwitchTask(it)
}
}
}
override fun onAttachedToWindow() {
@@ -121,6 +127,7 @@ class SwitchTaskView: WindowRelativeLayout, SwtichTaskModel.SwtichLineViewCallba
actv_submit_task.isEnabled = true
rv_switch_task.visibility = VISIBLE
include_empty.visibility = GONE
include_error.visibility = GONE
}
override fun showLoading(){
loading_start_line.visibility = VISIBLE
@@ -138,11 +145,22 @@ class SwitchTaskView: WindowRelativeLayout, SwtichTaskModel.SwtichLineViewCallba
viewbizModel?.showRunningTaskView()
}
override fun showErrorInfo() {
tv_error_msg.text = "发生错误点击重试"
actv_submit_task.setTextColor(ResourcesUtils.getColor(R.color.bus_color_66666))
actv_submit_task.isEnabled = false
include_error.visibility = VISIBLE
rv_switch_task.visibility = GONE
include_empty.visibility = GONE
viewbizModel?.showSwitchTaskInfo()
}
private fun showEmptyView(){
actv_submit_task.setTextColor(ResourcesUtils.getColor(R.color.bus_color_66666))
actv_submit_task.isEnabled = false
rv_switch_task.visibility = GONE
include_empty.visibility = VISIBLE
include_error.visibility = GONE
}
}

View File

@@ -22,7 +22,7 @@ class SwtichTaskModel : ViewModel(), IBusLinesCallback {
private var viewCallback:SwtichLineViewCallback?=null
private var tasksBelongLine: LineDataBean? = null
var tasksBelongLine: LineDataBean? = null
private var subscribe: Disposable? = null
@@ -46,12 +46,17 @@ class SwtichTaskModel : ViewModel(), IBusLinesCallback {
fun showLoading()
fun hideLoading()
fun startTaskSuccess()
fun showErrorInfo()
}
override fun onBusLineTasks(o: MutableList<TaskDataBean>?) {
viewCallback?.showTaskByLineIdResult(o)
}
override fun onBusLineTasksError() {
viewCallback?.showErrorInfo()
}
override fun onRefreshSuccess(currentTimeStamp: Long) {
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:background="@color/bus_switch_line_bg"
android:id="@+id/no_order_data_view">
<ImageView
android:id="@+id/no_order_data_iv"
android:layout_width="@dimen/dp_198"
android:layout_height="@dimen/dp_158"
android:src="@drawable/shuttle_weak_empty"
android:scaleType="fitXY"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<TextView
android:id="@+id/tv_error_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/bus_color_B3FFFFFF"
android:textSize="@dimen/dp_40"
android:gravity="center"
android:layout_marginTop="@dimen/dp_31"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/no_order_data_iv"
android:text="@string/bus_no_task"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -112,4 +112,15 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
android:id="@+id/include_error"
layout="@layout/shuttle_weak_error_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>