[6.6.0]
[shuttle] [从服务器恢复数据和数据纠错]
This commit is contained in:
@@ -6,6 +6,7 @@ import com.mogo.och.data.bean.BusRoutesResult
|
||||
import com.mogo.och.data.bean.BusStationBean
|
||||
import com.mogo.och.data.bean.LineInfo
|
||||
import com.mogo.och.weaknet.database.bean.TaskSiteDataBean
|
||||
import com.mogo.och.weaknet.database.repository.TaskSiteRepository
|
||||
import java.lang.Boolean
|
||||
import kotlin.String
|
||||
|
||||
@@ -15,11 +16,11 @@ import kotlin.String
|
||||
* @author tongchenfei
|
||||
*/
|
||||
class BusRoutesResponse : BaseData() {
|
||||
var result: BusRoutesResult? = null
|
||||
var data: BusRoutesResult? = null
|
||||
|
||||
override fun toString(): String {
|
||||
return "BusRoutesResponse{" +
|
||||
"data=" + result +
|
||||
"data=" + data +
|
||||
'}'
|
||||
}
|
||||
|
||||
@@ -67,5 +68,29 @@ class BusRoutesResponse : BaseData() {
|
||||
}
|
||||
return Pair(result,currentStationIndex)
|
||||
}
|
||||
fun bean2Db(sites: MutableList<BusStationBean>,lineId:Long,lineName:String?,taskId:Long) {
|
||||
val runnintTaskAndSites = mutableListOf<TaskSiteDataBean>()
|
||||
sites.forEach {
|
||||
val temp = TaskSiteDataBean()
|
||||
temp.taskId = taskId
|
||||
temp.lineId = lineId
|
||||
temp.siteId = it.siteId.toLong()
|
||||
temp.lineName = lineName
|
||||
temp.name = it.name
|
||||
temp.nameKr = it.nameKr
|
||||
temp.seq = it.seq
|
||||
temp.gcjLat = it.gcjLat
|
||||
temp.gcjLon = it.gcjLon
|
||||
temp.lon = it.lon
|
||||
temp.lat = it.lat
|
||||
temp.drivingStatus = it.drivingStatus
|
||||
temp.leaving = it.isLeaving
|
||||
temp.introduction = it.introduction
|
||||
temp.isPlayTts = it.isPlayTts
|
||||
runnintTaskAndSites.add(temp)
|
||||
}
|
||||
TaskSiteRepository.addOrUpdate(*runnintTaskAndSites.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,7 @@ interface EventDataDao {
|
||||
@Query("SELECT * FROM ${EventDataBean.evnetDataTable} WHERE update_status = ${EventDataBean.notUpdate} and event_save_time > :zeroTime GROUP by task_start_time")
|
||||
fun queryWaitUploadInfo(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): Observable<List<EventDataBean>?>
|
||||
|
||||
@Query("SELECT * FROM ${EventDataBean.evnetDataTable} order by event_save_time LIMIT 5 OFFSET 0")
|
||||
fun queryLastDataByWaritData():List<EventDataBean>?
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,7 @@ interface LineDataDao {
|
||||
@Query("SELECT * FROM ${LineDataBean.lineDataTable} WHERE line_get_time > :zeroTime")
|
||||
fun loadData(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): List<LineDataBean>?
|
||||
|
||||
@Query("SELECT * FROM ${LineDataBean.lineDataTable} WHERE line_id = :lineId")
|
||||
fun queryByLineId(lineId: Int) : List<LineDataBean>?
|
||||
|
||||
}
|
||||
|
||||
@@ -44,4 +44,23 @@ object ContraiRepository {
|
||||
return contrailDao?.queryContrailByLineIdOne(lineId)
|
||||
}
|
||||
|
||||
fun saveRunningInfo(
|
||||
lineId: Int,
|
||||
csvFileMd5: String?,
|
||||
csvFileUrl: String?,
|
||||
txtFileUrl: String?,
|
||||
txtFileMd5: String?,
|
||||
contrailSaveTime: Long
|
||||
) {
|
||||
val runningLine = ContrailDataBean(
|
||||
lineId = lineId.toLong(),
|
||||
csvFileUrl = csvFileUrl,
|
||||
csvFileMd5 = csvFileMd5,
|
||||
txtFileUrl = txtFileUrl,
|
||||
txtFileMd5 = txtFileMd5,
|
||||
contrailSaveTime = contrailSaveTime
|
||||
)
|
||||
addOrUpdate(mutableListOf(runningLine))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -104,6 +104,14 @@ object EventRepository {
|
||||
return eventDataDao?.queryEventByStatusWithPage()
|
||||
}
|
||||
|
||||
fun queryLastData(): EventDataBean? {
|
||||
val queryLastDataByWaritData = eventDataDao?.queryLastDataByWaritData()
|
||||
if(queryLastDataByWaritData.isNullOrEmpty()){
|
||||
return null
|
||||
}
|
||||
return queryLastDataByWaritData.first()
|
||||
}
|
||||
|
||||
fun saveUpdateSuccess(waitUpdateEvent: List<EventDataBean>) {
|
||||
eventDataDao?.insert(*waitUpdateEvent.toTypedArray())
|
||||
}
|
||||
|
||||
@@ -79,5 +79,15 @@ object LineRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有线路就插入线路
|
||||
*/
|
||||
fun saveRunningInfo(lineId: Int, lineName: String?, endStationName: String?) {
|
||||
val queryByLineId = lineDao?.queryByLineId(lineId)
|
||||
if(queryByLineId.isNullOrEmpty()){
|
||||
lineDao?.insert(LineDataBean(lineId = lineId.toLong(), lineName = lineName, endStationName = endStationName))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.TAG
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.weaknet.database.MyDataBase
|
||||
import com.mogo.och.weaknet.database.bean.TaskDataBean
|
||||
import com.mogo.och.weaknet.database.dao.TaskDataDao
|
||||
@@ -19,6 +20,10 @@ object TaskRepository {
|
||||
taskDataDao = MyDataBase.instance.taskDataDao
|
||||
}
|
||||
|
||||
fun addOrUpdate(vararg lineDataBean: TaskDataBean){
|
||||
taskDataDao?.insert(*lineDataBean)
|
||||
}
|
||||
|
||||
fun addOrUpdate(serverDateList: List<TaskDataBean>, lineId: Long?) {
|
||||
val runable = object :Runnable {
|
||||
override fun run() {
|
||||
@@ -133,6 +138,21 @@ object TaskRepository {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveRunningInfo(lineId: Int, taskId: Int, taskTime: Long) {
|
||||
val runningTask = taskDataDao?.queryTaskByTaskIdOne(taskId.toLong())
|
||||
if (runningTask==null) {
|
||||
val taskDataBean = TaskDataBean()
|
||||
taskDataBean.taskId = taskId.toLong()
|
||||
taskDataBean.lineId = lineId.toLong()
|
||||
taskDataBean.taskStartTime = taskTime
|
||||
taskDataBean.taskDate = DateTimeUtil.getCurrentDateZero()
|
||||
taskDataBean.status = TaskDataBean.useing
|
||||
taskDataDao?.insert(taskDataBean)
|
||||
}else{
|
||||
runningTask.status = TaskDataBean.useing
|
||||
taskDataDao?.insert(runningTask)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface TaskStatusCallback{
|
||||
|
||||
@@ -264,12 +264,12 @@ object BusLineModel {
|
||||
|
||||
if (runningTaskInfo.isNullOrEmpty()) {
|
||||
// 本地没有进行中的任务
|
||||
// todo: 尝试加载远程数据
|
||||
CallerLogger.d(TAG,"没有查询到正在运行的任务")
|
||||
loadServerRuningTask()
|
||||
} else if (runningTaskInfo.size > 1) {
|
||||
// 本地有多条正在进行的任务 需要check event
|
||||
// TODO:1 比对event表 1 清理错误数据 2 加载后台数据
|
||||
// 1 比对event表 1 清理错误数据 2 加载后台数据
|
||||
selectRightData(runningTaskInfo)
|
||||
} else {
|
||||
// 只有一条进行中的任务
|
||||
currentTask = runningTaskInfo.first()
|
||||
@@ -293,12 +293,53 @@ object BusLineModel {
|
||||
}
|
||||
}
|
||||
|
||||
private fun selectRightData(runningTaskInfo: List<TaskDataBean>) {
|
||||
// 查找最新已经上报的任务
|
||||
val sorted = runningTaskInfo.sortedBy {
|
||||
it.startTime
|
||||
}
|
||||
val tempList = sorted.toMutableList()
|
||||
val possible = tempList.removeFirst()
|
||||
val queryLastData = EventRepository.queryLastData()
|
||||
if(queryLastData!=null){
|
||||
if(possible.taskId==queryLastData.taskId){
|
||||
// 最后一个事件和最新的task一直 恢复数据
|
||||
tempList.forEach {
|
||||
it.status = TaskDataBean.used
|
||||
}
|
||||
TaskRepository.addOrUpdate(*tempList.toTypedArray())
|
||||
OrderModel.queryBusRoutes()
|
||||
return
|
||||
}
|
||||
}
|
||||
// 全部置为已使用 通过接口恢复数据
|
||||
runningTaskInfo.forEach {
|
||||
it.status = TaskDataBean.used
|
||||
}
|
||||
TaskRepository.addOrUpdate(*runningTaskInfo.toTypedArray())
|
||||
loadServerRuningTask()
|
||||
}
|
||||
|
||||
private fun loadServerRuningTask() {
|
||||
mContext?.let {
|
||||
OrderServiceManager.queryBusRoutes(it,object :OchCommonServiceCallback<BusRoutesResponse>{
|
||||
override fun onSuccess(data: BusRoutesResponse?) {
|
||||
data?.result?.let {
|
||||
it.sites
|
||||
mContext?.let { contextit ->
|
||||
OrderServiceManager.queryBusRoutes(contextit,object :OchCommonServiceCallback<BusRoutesResponse>{
|
||||
override fun onSuccess(response: BusRoutesResponse?) {
|
||||
response?.data?.let {
|
||||
if (!it.sites.isNullOrEmpty()&&it.sites.size>1) {
|
||||
OchChainLogManager.writeChainLogDb("业务数据","本地没有正在运行的数据,服务器端有")
|
||||
LineRepository.saveRunningInfo(it.lineId,it.name,it.sites.last().name)
|
||||
TaskRepository.saveRunningInfo(it.lineId,it.taskId,it.taskTime)
|
||||
ContraiRepository.saveRunningInfo(
|
||||
it.lineId,
|
||||
it.csvFileMd5,
|
||||
it.csvFileUrl,
|
||||
it.txtFileUrl,
|
||||
it.txtFileMd5,
|
||||
it.contrailSaveTime
|
||||
)
|
||||
BusRoutesResponse.bean2Db(it.sites,it.lineId.toLong(),it.name,it.taskId.toLong())
|
||||
OrderModel.queryBusRoutes()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ object OrderServiceManager {
|
||||
SharedPrefsMgr.getInstance().token,
|
||||
BusQueryLineStationsRequest()
|
||||
)
|
||||
.transformTry()
|
||||
.transformIoTry()
|
||||
.subscribe(OchCommonSubscribeImpl(context, callback, "queryBusRoutes"))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user