[6.6.0]
[模拟保存 线路和任务信息、并保存到数据库]
This commit is contained in:
@@ -58,6 +58,7 @@ dependencies {
|
||||
|
||||
implementation rootProject.ext.dependencies.rxjava
|
||||
implementation rootProject.ext.dependencies.rxandroid
|
||||
implementation rootProject.ext.dependencies.roomRxjava
|
||||
implementation rootProject.ext.dependencies.androidxrecyclerview
|
||||
kapt rootProject.ext.dependencies.recyclerviewadapterhelper
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package com.mogo.och.weaknet.bean;
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData;
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil;
|
||||
import com.mogo.och.weaknet.database.bean.LineDataBean;
|
||||
import com.mogo.och.weaknet.database.bean.TaskDataBean;
|
||||
import com.mogo.och.weaknet.database.repository.TaskRepository;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -12,8 +19,24 @@ public class BusQueryLineTaskResponse extends BaseData {
|
||||
|
||||
public List<Result> data;
|
||||
|
||||
public static void save2Db(@NotNull BusQueryLineTaskResponse data,long lineId) {
|
||||
List<TaskDataBean> save2Db = new ArrayList<>();
|
||||
TaskDataBean temp = null;
|
||||
for (Result datum : data.data) {
|
||||
temp = new TaskDataBean();
|
||||
temp.setLineId((long)lineId);
|
||||
temp.setTaskId((long)datum.id);
|
||||
temp.setTaskDate(DateTimeUtil.getCurrentDateZero());
|
||||
temp.setTaskStartTime(datum.taskStartTime);
|
||||
temp.setTaskgetTime(DateTimeUtil.getCurrentTimeStamp());
|
||||
temp.setStatus(TaskDataBean.unUse);
|
||||
save2Db.add(temp);
|
||||
}
|
||||
TaskRepository.INSTANCE.addOrUpdate(save2Db,(long)lineId);
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
public int id;
|
||||
public long id;
|
||||
public long taskStartTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.mogo.och.weaknet.bean;
|
||||
|
||||
import com.mogo.eagle.core.data.BaseData;
|
||||
import com.mogo.och.weaknet.database.bean.LineDataBean;
|
||||
import com.mogo.och.weaknet.database.repository.LineRepository;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -11,9 +16,21 @@ import java.util.List;
|
||||
public class BusQueryLinesResponse extends BaseData {
|
||||
public List<Result> data;
|
||||
|
||||
public static void save2Db(@NotNull BusQueryLinesResponse data) {
|
||||
List<LineDataBean> save2Db = new ArrayList<>();
|
||||
LineDataBean temp = null;
|
||||
for (Result datum : data.data) {
|
||||
temp = new LineDataBean();
|
||||
temp.setLineId((long)datum.lineId);
|
||||
temp.setLineName(datum.name);
|
||||
save2Db.add(temp);
|
||||
}
|
||||
LineRepository.INSTANCE.checkAndUpdate(save2Db);
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
|
||||
public int lineId;//线路id
|
||||
public long lineId;//线路id
|
||||
public String name;//线路名字
|
||||
public int choose; // 1:绑定 2:未被绑定
|
||||
public String startSiteName;//始发站名称
|
||||
@@ -24,4 +41,6 @@ public class BusQueryLinesResponse extends BaseData {
|
||||
|
||||
public List<BusQueryLineTaskResponse.Result> taskList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -3,12 +3,14 @@ package com.mogo.och.weaknet.callback;
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse;
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/2/9
|
||||
*/
|
||||
public interface IBusLinesCallback {
|
||||
void onBusLinesChange(BusQueryLinesResponse lines);
|
||||
void onBusLinesChange(List<BusQueryLinesResponse.Result> data);
|
||||
void onChangeLineIdSuccess();
|
||||
void onBusLineTasks(BusQueryLineTaskResponse o, int position,boolean autoRefresh);
|
||||
void onBusLineTasks(List<BusQueryLineTaskResponse.Result> o, int position,boolean autoRefresh);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class TaskDataBean(
|
||||
var lineId: Long? = null,
|
||||
|
||||
/**
|
||||
* 任务安排的时间
|
||||
* 任务安排的日期
|
||||
*/
|
||||
@ColumnInfo(name = "task_data", typeAffinity = ColumnInfo.INTEGER)
|
||||
var taskDate: Long? = null,
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.weaknet.database.bean.LineDataBean
|
||||
import io.reactivex.Observable
|
||||
|
||||
@Dao
|
||||
interface LineDataDao {
|
||||
@@ -22,6 +23,10 @@ interface LineDataDao {
|
||||
@Query("DELETE FROM ${LineDataBean.lineDataTable} WHERE line_get_time < :zeroTime")
|
||||
fun deleteWeltData(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): Int
|
||||
|
||||
//查询当天插入的所有数据
|
||||
@Query("SELECT * FROM ${LineDataBean.lineDataTable} WHERE line_get_time > :zeroTime")
|
||||
fun loadDataRx(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): Observable<List<LineDataBean>?>
|
||||
|
||||
//查询当天插入的所有数据
|
||||
@Query("SELECT * FROM ${LineDataBean.lineDataTable} WHERE line_get_time > :zeroTime")
|
||||
fun loadData(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): List<LineDataBean>?
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.weaknet.database.bean.TaskDataBean
|
||||
import io.reactivex.Observable
|
||||
|
||||
@Dao
|
||||
interface TaskDataDao {
|
||||
@@ -31,7 +32,7 @@ interface TaskDataDao {
|
||||
fun queryRunningTastByLineId(lineId: Long,zeroTime:Long = DateTimeUtil.getCurrentDateZero()): List<TaskDataBean>?
|
||||
|
||||
@Query("SELECT * FROM ${TaskDataBean.taskDataTable} WHERE task_get_time > :zeroTime and status = ${TaskDataBean.unUse} and line_id = :lineId")
|
||||
fun queryUnuseTask(lineId: Long,zeroTime:Long = DateTimeUtil.getCurrentDateZero()): List<TaskDataBean>?
|
||||
fun queryUnuseTask(lineId: Long,zeroTime:Long = DateTimeUtil.getCurrentDateZero()): Observable<List<TaskDataBean>?>
|
||||
|
||||
@Query("DELETE FROM ${TaskDataBean.taskDataTable} WHERE task_get_time > :zeroTime and line_id = :lineId")
|
||||
fun deleteByLineId(lineId: Long,zeroTime:Long = DateTimeUtil.getCurrentDateZero())
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mogo.och.weaknet.database.repository
|
||||
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
|
||||
object DbThreadUtils {
|
||||
fun runInIoThread(runable:Runnable){
|
||||
if(ThreadUtils.isMainThread()){
|
||||
ThreadUtils.getIoPool().submit(runable)
|
||||
}else{
|
||||
runable.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.och.weaknet.database.MyDataBase
|
||||
import com.mogo.och.weaknet.database.bean.LineDataBean
|
||||
import com.mogo.och.weaknet.database.dao.LineDataDao
|
||||
import io.reactivex.Observable
|
||||
import rx.Single
|
||||
|
||||
object LineRepository {
|
||||
|
||||
@@ -22,50 +24,56 @@ object LineRepository {
|
||||
/**
|
||||
* 读取可用线路
|
||||
*/
|
||||
fun queryCanUseLine(): List<LineDataBean>? {
|
||||
return lineDao?.loadData()
|
||||
fun queryCanUseLine(): Observable<List<LineDataBean>?>? {
|
||||
return lineDao?.loadDataRx()
|
||||
}
|
||||
|
||||
fun checkAndUpdate(serverDatalist:List<LineDataBean>){
|
||||
// 校验数据个数
|
||||
lineDao?.let { lineDao->
|
||||
val loadData = lineDao.loadData()
|
||||
if(loadData.isNullOrEmpty()){
|
||||
lineDao.insert(*serverDatalist.toTypedArray())
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
return
|
||||
}
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDatalist-loadData
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = loadData-serverDatalist
|
||||
val runable = object :Runnable{
|
||||
override fun run() {
|
||||
// 校验数据个数
|
||||
lineDao?.let { lineDao->
|
||||
val loadData = lineDao.loadData()
|
||||
if(loadData.isNullOrEmpty()){
|
||||
lineDao.insert(*serverDatalist.toTypedArray())
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
return
|
||||
}
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDatalist-loadData
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = loadData-serverDatalist
|
||||
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
lineDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
lineDao.delete(*needMinusDatas.toTypedArray())
|
||||
needMinusDatas.forEach { minusLine->
|
||||
minusLine.lineId?.let { lineId->
|
||||
// 删除线路对应的站点
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
lineDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
lineDao.delete(*needMinusDatas.toTypedArray())
|
||||
needMinusDatas.forEach { minusLine->
|
||||
minusLine.lineId?.let { lineId->
|
||||
// 删除线路对应的站点
|
||||
|
||||
SiteRepository.deleteByLineId(lineId)
|
||||
val runingTask = TaskRepository.queryRunningTastByLineId(lineId)
|
||||
if(runingTask.isNullOrEmpty()){
|
||||
// 删除线路对应的自驾信息
|
||||
SiteRepository.deleteByLineId(lineId)
|
||||
val runingTask = TaskRepository.queryRunningTastByLineId(lineId)
|
||||
if(runingTask.isNullOrEmpty()){
|
||||
// 删除线路对应的自驾信息
|
||||
|
||||
ContraiRepository.deleteByLineId(lineId)
|
||||
ContraiRepository.deleteByLineId(lineId)
|
||||
|
||||
TaskRepository.deleteByLineId(lineId)
|
||||
TaskRepository.deleteByLineId(lineId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DbThreadUtils.runInIoThread(runable)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.mogo.och.weaknet.database.bean.LineDataBean
|
||||
import com.mogo.och.weaknet.database.bean.TaskDataBean
|
||||
import com.mogo.och.weaknet.database.dao.TaskDataDao
|
||||
import com.mogo.och.weaknet.database.exception.DataException
|
||||
import io.reactivex.Observable
|
||||
|
||||
object TaskRepository {
|
||||
|
||||
@@ -19,41 +20,47 @@ object TaskRepository {
|
||||
}
|
||||
|
||||
fun addOrUpdate(serverDateList: List<TaskDataBean>, lineId: Long?) {
|
||||
taskDataDao?.let { taskDataDao ->
|
||||
val localTasks = taskDataDao.querySitesByLineId(lineId)
|
||||
if(localTasks==null){
|
||||
taskDataDao.insert(*serverDateList.toTypedArray())
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
return
|
||||
}
|
||||
val runable = object :Runnable {
|
||||
override fun run() {
|
||||
taskDataDao?.let { taskDataDao ->
|
||||
val localTasks = taskDataDao.querySitesByLineId(lineId)
|
||||
if(localTasks==null){
|
||||
taskDataDao.insert(*serverDateList.toTypedArray())
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
return
|
||||
}
|
||||
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDateList - localTasks
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = localTasks - serverDateList
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDateList - localTasks
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = localTasks - serverDateList
|
||||
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
// TODO: Ui展示需要动态刷新UI去
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增任务
|
||||
taskDataDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除任务
|
||||
taskDataDao.delete(*needMinusDatas.toTypedArray())
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增任务
|
||||
taskDataDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除任务
|
||||
taskDataDao.delete(*needMinusDatas.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DbThreadUtils.runInIoThread(runable)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取线路可用的任务
|
||||
*/
|
||||
fun queryCanUserTask(lineId:Long):List<TaskDataBean>?{
|
||||
fun queryCanUserTask(lineId:Long): Observable<List<TaskDataBean>?>? {
|
||||
taskDataDao?.let { taskDataDao->
|
||||
// 查询当天未使用的任务
|
||||
val unUseTaskS = taskDataDao.queryUnuseTask(lineId)
|
||||
// 过滤调任务时间和当前时间相差10分钟的任务
|
||||
return unUseTaskS?.filter { (System.currentTimeMillis()-it.taskStartTime!!)<10*60*1000 }
|
||||
return taskDataDao.queryUnuseTask(lineId).map {
|
||||
it.filter { (System.currentTimeMillis()-it.taskStartTime!!)<10*60*1000 }
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.mogo.och.weaknet.database.transform
|
||||
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClient
|
||||
import com.mogo.eagle.core.data.BaseData
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusEnum
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusManager
|
||||
import com.mogo.och.common.module.network.interceptor.FRetryWithTime
|
||||
import com.mogo.och.common.module.network.interceptor.OchCommonRetryException
|
||||
import com.mogo.och.common.module.network.interceptor.RetryWithTime
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse
|
||||
import com.mogo.och.weaknet.database.bean.LineDataBean
|
||||
import com.mogo.och.weaknet.database.bean.TaskDataBean
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.ObservableSource
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.Function
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
fun <T,V> Observable<T>.transform4DataBase(transfor:Function<T, ObservableSource<V>>): Observable<V> {
|
||||
return flatMap(transfor)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
class FRetryWithTime11 : Function<List<LineDataBean>?, ObservableSource<List<BusQueryLinesResponse.Result>>> {
|
||||
override fun apply(baseData: List<LineDataBean>): ObservableSource<List<BusQueryLinesResponse.Result>> {
|
||||
val result = mutableListOf<BusQueryLinesResponse.Result>()
|
||||
var temp:BusQueryLinesResponse.Result? = null
|
||||
baseData.forEach {
|
||||
temp = BusQueryLinesResponse.Result()
|
||||
temp?.lineId = it.lineId
|
||||
temp?.name = it.lineName
|
||||
result.add(temp!!)
|
||||
}
|
||||
return Observable.just(result)
|
||||
}
|
||||
}
|
||||
|
||||
class TransformTask : Function<List<TaskDataBean>?, ObservableSource<List<BusQueryLineTaskResponse.Result>>> {
|
||||
override fun apply(baseData: List<TaskDataBean>): ObservableSource<List<BusQueryLineTaskResponse.Result>> {
|
||||
val result = mutableListOf<BusQueryLineTaskResponse.Result>()
|
||||
var temp:BusQueryLineTaskResponse.Result? = null
|
||||
baseData.forEach {
|
||||
temp = BusQueryLineTaskResponse.Result()
|
||||
temp?.id = it.taskId
|
||||
temp?.taskStartTime = it.taskStartTime
|
||||
result.add(temp!!)
|
||||
}
|
||||
return Observable.just(result)
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,36 @@ import android.content.Context
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.network.utils.digest.DigestUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.manager.loop.LoopInfo
|
||||
import com.mogo.och.common.module.network.OchCommonServiceCallback
|
||||
import com.mogo.och.common.module.network.OchCommonSubscribeImpl
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse
|
||||
import com.mogo.och.weaknet.bean.BusRoutesResponse
|
||||
import com.mogo.och.weaknet.bean.CarExecutableTaskResponse
|
||||
import com.mogo.och.weaknet.callback.IBusLinesCallback
|
||||
import com.mogo.och.weaknet.database.bean.LineDataBean
|
||||
import com.mogo.och.weaknet.database.repository.LineRepository
|
||||
import com.mogo.och.weaknet.database.repository.TaskRepository
|
||||
import com.mogo.och.weaknet.database.transform.FRetryWithTime11
|
||||
import com.mogo.och.weaknet.database.transform.TransformTask
|
||||
import com.mogo.och.weaknet.database.transform.transform4DataBase
|
||||
import com.mogo.och.weaknet.net.OrderServiceManager
|
||||
import com.mogo.och.weaknet.net.OrderServiceManager.queryBusLines
|
||||
import com.mogo.och.weaknet.net.OrderServiceManager.queryBusTaskByLineId
|
||||
import com.mogo.och.weaknet.net.OrderServiceManager.switchLine
|
||||
import com.mogo.och.weaknet.ui.BusSwitchLineActivity
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
@@ -83,34 +95,60 @@ object BusLineModel {
|
||||
|
||||
@JvmStatic
|
||||
fun queryBusLines() {
|
||||
queryBusLines(mContext!!, object : OchCommonServiceCallback<BusQueryLinesResponse> {
|
||||
override fun onSuccess(data: BusQueryLinesResponse) {
|
||||
if (null == data && mBusLinesCallback != null) {
|
||||
mBusLinesCallback!!.onBusLinesChange(null)
|
||||
return
|
||||
|
||||
LineRepository.queryCanUseLine()
|
||||
?.transform4DataBase(FRetryWithTime11())
|
||||
?.subscribe(object : Observer<List<BusQueryLinesResponse.Result>> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
CallerLogger.d(TAG, "onSubscribe")
|
||||
}
|
||||
|
||||
if (mBusLinesCallback != null) {
|
||||
mBusLinesCallback!!.onBusLinesChange(data)
|
||||
override fun onError(e: Throwable) {
|
||||
CallerLogger.d(TAG, "onError${e.printStackTrace()}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
} else {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
override fun onComplete() {
|
||||
CallerLogger.d(TAG, "onComplete")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, failMsg: String) {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort("网络异常,请稍后重试")
|
||||
} else {
|
||||
ToastUtils.showShort("查询所有绑定路线失败:$failMsg")
|
||||
override fun onNext(data: List<BusQueryLinesResponse.Result>) {
|
||||
if (mBusLinesCallback != null) {
|
||||
mBusLinesCallback!!.onBusLinesChange(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
// queryBusLines(mContext!!, object : OchCommonServiceCallback<BusQueryLinesResponse> {
|
||||
// override fun onSuccess(data: BusQueryLinesResponse) {
|
||||
// if (null == data && mBusLinesCallback != null) {
|
||||
// mBusLinesCallback!!.onBusLinesChange(null)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if (mBusLinesCallback != null) {
|
||||
// mBusLinesCallback!!.onBusLinesChange(data)
|
||||
// }
|
||||
//
|
||||
// BusQueryLinesResponse.save2Db(data)
|
||||
// }
|
||||
//
|
||||
// override fun onError() {
|
||||
// if (!NetworkUtils.isConnected(mContext)) {
|
||||
// ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
// } else {
|
||||
// ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFail(code: Int, failMsg: String) {
|
||||
// if (!NetworkUtils.isConnected(mContext)) {
|
||||
// ToastUtils.showShort("网络异常,请稍后重试")
|
||||
// } else {
|
||||
// ToastUtils.showShort("查询所有绑定路线失败:$failMsg")
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,44 +157,69 @@ object BusLineModel {
|
||||
* @param position 位置
|
||||
*/
|
||||
@JvmStatic
|
||||
fun queryBusLineTasksById(lineId: Int, position: Int, autoRefresh: Boolean) {
|
||||
queryBusTaskByLineId(
|
||||
mContext!!,
|
||||
lineId.toString(),
|
||||
object : OchCommonServiceCallback<BusQueryLineTaskResponse> {
|
||||
override fun onSuccess(data: BusQueryLineTaskResponse) {
|
||||
if (null == data && mBusLinesCallback != null) {
|
||||
mBusLinesCallback!!.onBusLineTasks(null, position, autoRefresh)
|
||||
return
|
||||
}
|
||||
fun queryBusLineTasksById(lineId: Long, position: Int, autoRefresh: Boolean) {
|
||||
|
||||
|
||||
TaskRepository.queryCanUserTask(lineId)
|
||||
?.transform4DataBase(TransformTask())
|
||||
?.subscribe(object : Observer<List<BusQueryLineTaskResponse.Result>> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
CallerLogger.d(TAG, "onSubscribe")
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
CallerLogger.d(TAG, "onError${e.printStackTrace()}")
|
||||
}
|
||||
|
||||
override fun onComplete() {
|
||||
CallerLogger.d(TAG, "onComplete")
|
||||
}
|
||||
|
||||
override fun onNext(data: List<BusQueryLineTaskResponse.Result>) {
|
||||
if (mBusLinesCallback != null) {
|
||||
mBusLinesCallback!!.onBusLineTasks(data, position, autoRefresh)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError() {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
} else {
|
||||
ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(code: Int, failMsg: String) {
|
||||
if (!NetworkUtils.isConnected(mContext)) {
|
||||
ToastUtils.showShort("网络异常,请稍后重试")
|
||||
} else {
|
||||
ToastUtils.showShort("查询所有绑定路线失败:$failMsg")
|
||||
}
|
||||
}
|
||||
})
|
||||
// queryBusTaskByLineId(
|
||||
// mContext!!,
|
||||
// lineId.toString(),
|
||||
// object : OchCommonServiceCallback<BusQueryLineTaskResponse> {
|
||||
// override fun onSuccess(data: BusQueryLineTaskResponse) {
|
||||
// if (null == data && mBusLinesCallback != null) {
|
||||
// mBusLinesCallback!!.onBusLineTasks(null, position, autoRefresh)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if (mBusLinesCallback != null) {
|
||||
// mBusLinesCallback!!.onBusLineTasks(data, position, autoRefresh)
|
||||
// }
|
||||
// BusQueryLineTaskResponse.save2Db(data,lineId)
|
||||
// }
|
||||
//
|
||||
// override fun onError() {
|
||||
// if (!NetworkUtils.isConnected(mContext)) {
|
||||
// ToastUtils.showShort(mContext!!.getString(R.string.network_error_tip))
|
||||
// } else {
|
||||
// ToastUtils.showShort(mContext!!.getString(R.string.request_error_tip))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFail(code: Int, failMsg: String) {
|
||||
// if (!NetworkUtils.isConnected(mContext)) {
|
||||
// ToastUtils.showShort("网络异常,请稍后重试")
|
||||
// } else {
|
||||
// ToastUtils.showShort("查询所有绑定路线失败:$failMsg")
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
}
|
||||
@JvmStatic
|
||||
fun commitSwitchLineId(taskId: Int, lineId: Int) {
|
||||
fun commitSwitchLineId(taskId: Long, lineId: Long) {
|
||||
switchLine(mContext!!, taskId, object : OchCommonServiceCallback<BusRoutesResponse> {
|
||||
override fun onSuccess(o: BusRoutesResponse) {
|
||||
SharedPrefsMgr.getInstance().putInt(BusSwitchLineActivity.LASTCOMMITLINEID, lineId)
|
||||
SharedPrefsMgr.getInstance().putLong(BusSwitchLineActivity.LASTCOMMITLINEID, lineId)
|
||||
if (mBusLinesCallback != null) {
|
||||
mBusLinesCallback!!.onChangeLineIdSuccess()
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ import com.mogo.och.data.bean.BusStationBean;
|
||||
import com.mogo.och.data.bean.BusTransferData;
|
||||
import com.mogo.och.data.manager.cache.CacheDataManager;
|
||||
import com.mogo.och.weaknet.constant.BusConst;
|
||||
import com.mogo.och.weaknet.database.repository.SiteRepository;
|
||||
import com.mogo.och.weaknet.net.OrderServiceManager;
|
||||
import com.mogo.och.weaknet.util.BusSendTripInfoManager;
|
||||
import com.mogo.och.weaknet.util.ShuttleVoiceManager;
|
||||
|
||||
@@ -57,7 +57,7 @@ object OrderServiceManager {
|
||||
@JvmStatic
|
||||
fun switchLine(
|
||||
context: Context,
|
||||
taskId: Int,
|
||||
taskId: Long,
|
||||
callback: OchCommonServiceCallback<BusRoutesResponse>?
|
||||
) {
|
||||
mService.switchLine(
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mogo.och.weaknet.model.BusLineModel;
|
||||
import com.mogo.och.weaknet.model.OrderModel;
|
||||
import com.mogo.och.weaknet.ui.BusSwitchLineView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
@@ -42,15 +43,10 @@ public class BusLinePresenter extends Presenter<BusSwitchLineView> implements IB
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBusLinesChange(BusQueryLinesResponse lines) {
|
||||
UiThreadHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(mView!=null) {
|
||||
mView.onBusLinesChange(lines);
|
||||
}
|
||||
}
|
||||
}, UiThreadHandler.MODE.QUEUE);
|
||||
public void onBusLinesChange(List<BusQueryLinesResponse.Result> data) {
|
||||
if(mView!=null) {
|
||||
mView.onBusLinesChange(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +66,7 @@ public class BusLinePresenter extends Presenter<BusSwitchLineView> implements IB
|
||||
BusLineModel.queryBusLines();
|
||||
}
|
||||
|
||||
public void queryBusLineTasks(int lineId, int position,boolean close){
|
||||
public void queryBusLineTasks(long lineId, int position,boolean close){
|
||||
if(subscribe!=null&&!subscribe.isDisposed()){
|
||||
subscribe.dispose();
|
||||
}
|
||||
@@ -83,7 +79,7 @@ public class BusLinePresenter extends Presenter<BusSwitchLineView> implements IB
|
||||
});
|
||||
}
|
||||
|
||||
public void commitSwitchLineId(int taskId,int lineId){
|
||||
public void commitSwitchLineId(long taskId,long lineId){
|
||||
BusLineModel.commitSwitchLineId(taskId,lineId);
|
||||
}
|
||||
|
||||
@@ -105,7 +101,7 @@ public class BusLinePresenter extends Presenter<BusSwitchLineView> implements IB
|
||||
|
||||
|
||||
@Override
|
||||
public void onBusLineTasks(BusQueryLineTaskResponse o, int position, boolean autoRefresh) {
|
||||
public void onBusLineTasks(List<BusQueryLineTaskResponse.Result> o, int position, boolean autoRefresh) {
|
||||
if(mView!=null) {
|
||||
mView.onBusLineTasks(o,position,autoRefresh);
|
||||
}
|
||||
|
||||
@@ -113,16 +113,16 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
* 查询返回绑定路线集合
|
||||
* @param data
|
||||
*/
|
||||
override fun onBusLinesChange(data: BusQueryLinesResponse?) {
|
||||
if (null == data) {
|
||||
override fun onBusLinesChange(data: MutableList<BusQueryLinesResponse.Result>?) {
|
||||
if (data.isNullOrEmpty()) {
|
||||
showNoData(true)
|
||||
return
|
||||
}
|
||||
val lastCommitLineid = SharedPrefsMgr.getInstance().getInt(LASTCOMMITLINEID, -1)
|
||||
if (data.data != null && data.data.size > 0) {
|
||||
val lastCommitLineid = SharedPrefsMgr.getInstance().getLong(LASTCOMMITLINEID, -1)
|
||||
if (data.size > 0) {
|
||||
showNoData(false)
|
||||
mData.clear()
|
||||
mData.addAll(data.data)
|
||||
mData.addAll(data)
|
||||
mAdapter.notifyDataSetChanged()
|
||||
if(lastCommitLineid>0){
|
||||
mData.forEachIndexed { index, line ->
|
||||
@@ -146,7 +146,7 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onBusLineTasks(lineTaskInfo: BusQueryLineTaskResponse?, position: Int, autoRefresh:Boolean) {
|
||||
override fun onBusLineTasks(lineTaskInfo: List<BusQueryLineTaskResponse.Result>, position: Int, autoRefresh:Boolean) {
|
||||
val result = mData[position]
|
||||
if (result.taskList == null) {
|
||||
result.taskList = ArrayList()
|
||||
@@ -156,17 +156,16 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
// 打开操作
|
||||
mAdapter.notifyItemChanged(position)
|
||||
} else {
|
||||
if (lineTaskInfo.data == null || lineTaskInfo.data.isEmpty()) {
|
||||
if ( lineTaskInfo.isEmpty()) {
|
||||
result.haveTask = true
|
||||
lineTaskInfo.data = ArrayList()
|
||||
}
|
||||
if (lineTaskInfo.data.size != result.taskList.size) { // 不相等有变动 重新赋值
|
||||
if (lineTaskInfo.size != result.taskList.size) { // 不相等有变动 重新赋值
|
||||
result.taskList.clear()
|
||||
result.taskList.addAll(lineTaskInfo.data)
|
||||
result.taskList.addAll(lineTaskInfo)
|
||||
if(autoRefresh) {
|
||||
mAdapter.checkTaskId = -1
|
||||
mAdapter.checkLineId = -1
|
||||
lineTaskInfo.data.forEach {
|
||||
lineTaskInfo.forEach {
|
||||
if (it.id == mAdapter.checkTaskId) {
|
||||
mAdapter.checkTaskId = it.id
|
||||
mAdapter.checkLineId = result.lineId
|
||||
@@ -177,7 +176,7 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
mAdapter.notifyItemChanged(position)
|
||||
linearLayoutManager.stackFromEnd = (position==mData.size-1||position==mData.size-2)&&mData.size>6
|
||||
mLinesListView.smoothScrollToPosition(position)
|
||||
}else if(lineTaskInfo.data.isEmpty()){
|
||||
}else if(lineTaskInfo.isEmpty()){
|
||||
mAdapter.notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
@@ -207,7 +206,7 @@ class BusSwitchLineActivity : MvpActivity<BusSwitchLineView?, BusLinePresenter?>
|
||||
}
|
||||
//切换路线提交
|
||||
if (v.id == R.id.switch_line_btn_commit) {
|
||||
if(mAdapter.checkLineId!=-1&&mAdapter.checkTaskId!=-1){
|
||||
if(mAdapter.checkLineId!=-1L&&mAdapter.checkTaskId!=-1L){
|
||||
mPresenter?.commitSwitchLineId(mAdapter.checkTaskId,mAdapter.checkLineId)
|
||||
}else{
|
||||
ToastUtils.showLong("请选择任务")
|
||||
|
||||
@@ -4,15 +4,17 @@ import com.mogo.commons.mvp.IView;
|
||||
import com.mogo.och.weaknet.bean.BusQueryLineTaskResponse;
|
||||
import com.mogo.och.weaknet.bean.BusQueryLinesResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/2/10
|
||||
*/
|
||||
public interface BusSwitchLineView extends IView {
|
||||
|
||||
void onBusLinesChange(BusQueryLinesResponse data);
|
||||
void onBusLinesChange(List<BusQueryLinesResponse.Result> data);
|
||||
void onChangeLineIdSuccess();
|
||||
|
||||
void onBusLineTasks(BusQueryLineTaskResponse o, int position,boolean autoRefresh);
|
||||
void onBusLineTasks(List<BusQueryLineTaskResponse.Result> o, int position,boolean autoRefresh);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ class SwitchLineAdapter(
|
||||
}
|
||||
// RecyclerView设置点击事件
|
||||
private var mItemClickListener: LineItemClickListener? = null
|
||||
var checkLineId:Int = -1
|
||||
var checkTaskId:Int = -1
|
||||
var checkLineId:Long = -1
|
||||
var checkTaskId:Long = -1
|
||||
override fun onCreateViewHolder(
|
||||
parent: ViewGroup,
|
||||
viewType: Int
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.mogo.och.shuttle.weaknet.R
|
||||
*/
|
||||
class SwitchLineTaskAdapter(
|
||||
private val mContext: Context,
|
||||
private var checkTaskId:Int,
|
||||
private var checkTaskId:Long,
|
||||
private val mData: List<BusQueryLineTaskResponse.Result>?,
|
||||
private val mTaskItemClickListener: TaskItemClickListener?
|
||||
) : RecyclerView.Adapter<SwitchLineTaskViewHolder>() {
|
||||
|
||||
Reference in New Issue
Block a user