[算路]
[离线数据保存]
This commit is contained in:
yangyakun
2025-08-01 19:32:46 +08:00
parent cac4c5e633
commit 0559d7c536
15 changed files with 1039 additions and 17 deletions

View File

@@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 6,
"identityHash": "9da3a45e98fe1252081e52f5fbc864be",
"identityHash": "d0c810058283199a6d02e82906b6139a",
"entities": [
{
"tableName": "contrail_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `csv_file_url` TEXT, `csv_file_md5` TEXT, `txt_file_url` TEXT, `txt_file_md5` TEXT, `contrail_save_time` INTEGER, `md5` TEXT)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `contrail_id` INTEGER, `csv_file_url` TEXT, `csv_file_md5` TEXT, `txt_file_url` TEXT, `txt_file_md5` TEXT, `contrail_save_time` INTEGER, `md5` TEXT, `source` INTEGER)",
"fields": [
{
"fieldPath": "id",
@@ -20,6 +20,12 @@
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "contrailId",
"columnName": "contrail_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "csvFileUrl",
"columnName": "csv_file_url",
@@ -55,13 +61,19 @@
"columnName": "md5",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "source",
"columnName": "source",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [
{
@@ -133,10 +145,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [
{
@@ -241,10 +253,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [
{
@@ -394,10 +406,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@@ -450,10 +462,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [
{
@@ -481,7 +493,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9da3a45e98fe1252081e52f5fbc864be')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd0c810058283199a6d02e82906b6139a')"
]
}
}

View File

@@ -0,0 +1,573 @@
{
"formatVersion": 1,
"database": {
"version": 7,
"identityHash": "b58ea76c5ce6f4b721e3fcd4d8945496",
"entities": [
{
"tableName": "contrail_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `contrail_id` INTEGER, `csv_file_url` TEXT, `csv_file_md5` TEXT, `txt_file_url` TEXT, `txt_file_md5` TEXT, `contrail_save_time` INTEGER, `md5` TEXT, `source` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lineId",
"columnName": "line_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "contrailId",
"columnName": "contrail_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "csvFileUrl",
"columnName": "csv_file_url",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "csvFileMd5",
"columnName": "csv_file_md5",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "txtFileUrl",
"columnName": "txt_file_url",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "txtFileMd5",
"columnName": "txt_file_md5",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "contrailSaveTime",
"columnName": "contrail_save_time",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "md5",
"columnName": "md5",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "source",
"columnName": "source",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_contrail_data_table_line_id",
"unique": false,
"columnNames": [
"line_id"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_contrail_data_table_line_id` ON `${TABLE_NAME}` (`line_id`)"
},
{
"name": "index_contrail_data_table_md5",
"unique": false,
"columnNames": [
"md5"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_contrail_data_table_md5` ON `${TABLE_NAME}` (`md5`)"
}
],
"foreignKeys": []
},
{
"tableName": "line_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `line_name` TEXT, `end_station_name` TEXT, `tenant_id` INTEGER, `project_name` TEXT, `line_get_time` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lineId",
"columnName": "line_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "lineName",
"columnName": "line_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "endStationName",
"columnName": "end_station_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "tenantId",
"columnName": "tenant_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "projectName",
"columnName": "project_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "linegetTime",
"columnName": "line_get_time",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_line_data_table_line_id",
"unique": false,
"columnNames": [
"line_id"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_line_data_table_line_id` ON `${TABLE_NAME}` (`line_id`)"
}
],
"foreignKeys": []
},
{
"tableName": "site_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `site_id` INTEGER, `line_id` INTEGER, `name` TEXT, `name_kr` TEXT, `seq` INTEGER, `gcj_lon` REAL, `gcj_lat` REAL, `lon` REAL, `lat` REAL, `introduction` TEXT, `is_play_tts` INTEGER, `md5` TEXT, `videoList` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "siteId",
"columnName": "site_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "lineId",
"columnName": "line_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "nameKr",
"columnName": "name_kr",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "seq",
"columnName": "seq",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "gcjLon",
"columnName": "gcj_lon",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "gcjLat",
"columnName": "gcj_lat",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "lon",
"columnName": "lon",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "lat",
"columnName": "lat",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "introduction",
"columnName": "introduction",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isPlayTts",
"columnName": "is_play_tts",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "md5",
"columnName": "md5",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "videoListDB",
"columnName": "videoList",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_site_data_table_site_id",
"unique": false,
"columnNames": [
"site_id"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_site_data_table_site_id` ON `${TABLE_NAME}` (`site_id`)"
},
{
"name": "index_site_data_table_line_id",
"unique": false,
"columnNames": [
"line_id"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_site_data_table_line_id` ON `${TABLE_NAME}` (`line_id`)"
}
],
"foreignKeys": []
},
{
"tableName": "used_line_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task_id` INTEGER, `line_id` INTEGER, `site_id` INTEGER, `line_name` TEXT, `name` TEXT, `name_kr` TEXT, `seq` INTEGER, `gcj_lon` REAL, `gcj_lat` REAL, `lon` REAL, `lat` REAL, `driving_status` INTEGER, `leaving` INTEGER, `arrived_time` INTEGER, `leave_time` INTEGER, `introduction` TEXT, `is_play_tts` INTEGER, `event_save_time` INTEGER NOT NULL, `videoList` TEXT)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "taskId",
"columnName": "task_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "lineId",
"columnName": "line_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "siteId",
"columnName": "site_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "lineName",
"columnName": "line_name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "nameKr",
"columnName": "name_kr",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "seq",
"columnName": "seq",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "gcjLon",
"columnName": "gcj_lon",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "gcjLat",
"columnName": "gcj_lat",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "lon",
"columnName": "lon",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "lat",
"columnName": "lat",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "drivingStatus",
"columnName": "driving_status",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "leaving",
"columnName": "leaving",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "arrivedTime",
"columnName": "arrived_time",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "leaveTime",
"columnName": "leave_time",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "introduction",
"columnName": "introduction",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "isPlayTts",
"columnName": "is_play_tts",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "eventSaveTime",
"columnName": "event_save_time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "videoList",
"columnName": "videoList",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "temp_task_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `task_id` INTEGER, `line_id` INTEGER, `start_time` INTEGER NOT NULL, `end_time` INTEGER, `task_get_time` INTEGER NOT NULL, `status` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "taskId",
"columnName": "task_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "lineId",
"columnName": "line_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "startTime",
"columnName": "start_time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "endtime",
"columnName": "end_time",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "taskgetTime",
"columnName": "task_get_time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "status",
"columnName": "status",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [
{
"name": "index_temp_task_data_table_task_id",
"unique": false,
"columnNames": [
"task_id"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_temp_task_data_table_task_id` ON `${TABLE_NAME}` (`task_id`)"
},
{
"name": "index_temp_task_data_table_line_id",
"unique": false,
"columnNames": [
"line_id"
],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_temp_task_data_table_line_id` ON `${TABLE_NAME}` (`line_id`)"
}
],
"foreignKeys": []
},
{
"tableName": "point_data_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `contrail_id` INTEGER, `site_id` INTEGER, `md5` TEXT, `seq` INTEGER, `point_type` INTEGER, `longitude` REAL, `latitude` REAL, `sub_seq` INTEGER)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lineId",
"columnName": "line_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "contrailId",
"columnName": "contrail_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "siteId",
"columnName": "site_id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "md5",
"columnName": "md5",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "seq",
"columnName": "seq",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "pointType",
"columnName": "point_type",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "longitude",
"columnName": "longitude",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "latitude",
"columnName": "latitude",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "subSeq",
"columnName": "sub_seq",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'b58ea76c5ce6f4b721e3fcd4d8945496')"
]
}
}

View File

@@ -33,11 +33,14 @@ import com.mogo.och.offline.model.OrderModel.isGoingToNextStation
import com.mogo.och.offline.repository.RepositoryManager
import com.mogo.och.offline.repository.db.bean.TaskDataBean
import com.mogo.och.offline.repository.db.bean.TaskSiteDataBean
import com.mogo.och.offline.repository.db.repository.PointDb
import com.mogo.och.offline.repository.db.repository.SiteDb
import com.mogo.och.offline.repository.db.repository.TaskDb
import com.mogo.och.offline.repository.db.repository.TaskSiteDb
import com.mogo.och.offline.repository.exception.DataException
import com.mogo.och.offline.repository.net.OrderServiceManager
import com.mogo.och.offline.repository.net.bean.BindLineListResponse
import com.mogo.och.offline.repository.net.bean.PointResponse
import com.mogo.och.offline.util.ShuttleVoiceManager
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
@@ -205,6 +208,71 @@ object LineModel {
})
}
private val waitSysData = mutableSetOf<Long>()
private val isRequestingContrainInfo = AtomicBoolean(false)
fun synContraiInfo(needUpdatePoint: MutableList<Long>) {
waitSysData.addAll(needUpdatePoint)
if(isRequestingContrainInfo.get()){
// 正在请求
OchChainLogManager.writeChainLogNet(false,"同步轨迹","正在同步轨迹请稍等 ")
return
}
isRequestingContrainInfo.set(true)
val lines = mutableListOf<Long>()
waitSysData.forEach {
lines.add(it)
}
OchChainLogManager.writeChainLogNet(false,"同步轨迹","轨迹变更需同步禁行点和途径点 线路:${lines}")
OrderServiceManager.queryPointsByLinesId(lines)
?.subscribeOn(Schedulers.io())
?.observeOn(Schedulers.io())
?.subscribe(object : Observer<List<PointResponse>> {
override fun onSubscribe(d: Disposable) {
d(TAG, "queryPointsByLinesId onSubscribe")
}
override fun onError(e: Throwable) {
d(TAG, "同步轨迹 onError${e.printStackTrace()} 同步轨迹失败 5s种后重试 线路:${lines}")
OchChainLogManager.writeChainLogNet(false,"同步轨迹","同步轨迹失败 5s种后重试 线路:${lines}")
RxUtils.createSubscribe(5_000){
synContraiInfo(needUpdatePoint)
}
isRequestingContrainInfo.set(false)
}
override fun onComplete() {
d(TAG, "endTask onComplete")
}
override fun onNext(data: List<PointResponse>) {
try {
PointDb.addOrUpdate(data)
for (datum in data) {
waitSysData.remove(datum.lineId)
}
isRequestingContrainInfo.set(false)
if(waitSysData.isNotEmpty()){
synContraiInfo(needUpdatePoint)
}
OchChainLogManager.writeChainLogNet(false,"同步轨迹","网络请求重构 轨迹信息${data}")
d(TAG, "同步轨迹网络成功")
}catch (e:Exception){
OchChainLogManager.writeChainLogDb("同步轨迹","同步轨迹时报错 轨迹信息${data} 错误信息${e.message}")
synContraiInfo(needUpdatePoint)
}
}
})
}
/**
* 开始任务
*/

View File

@@ -3,6 +3,8 @@ package com.mogo.och.offline.repository.db
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.env.Project
@@ -18,12 +20,14 @@ import com.mogo.och.offline.repository.db.dao.LineDataDao
import com.mogo.och.offline.repository.db.dao.SiteDataDao
import com.mogo.och.offline.repository.db.dao.TaskDataDao
import com.mogo.och.offline.repository.db.dao.TaskSiteDataDao
import com.mogo.och.offline.repository.db.bean.PointDataBean
import com.mogo.och.offline.repository.db.dao.PointDataDao
//注解Database告诉系统这是Room数据库对象
//entities指定该数据库有哪些表多张表就逗号分隔
//version指定数据库版本号升级时需要用到
//数据库继承自RoomDatabase
@Database(entities = [ContrailDataBean::class, LineDataBean::class, SiteDataBean::class, TaskSiteDataBean::class, TaskDataBean::class], version = 6)
@Database(entities = [ContrailDataBean::class, LineDataBean::class, SiteDataBean::class, TaskSiteDataBean::class, TaskDataBean::class,PointDataBean::class], version = 7)
abstract class MyDataBase : RoomDatabase() {
private val dbRepositorys = mutableListOf<IDbRepository>()
@@ -43,12 +47,20 @@ abstract class MyDataBase : RoomDatabase() {
abstract val contrailDataDao: ContrailDataDao?
abstract val lineDataDao: LineDataDao?
abstract val siteDataDao: SiteDataDao?
abstract val pointDataDao: PointDataDao?
abstract val taskDataDao: TaskDataDao?
abstract val taskSiteDataDao: TaskSiteDataDao?
companion object {
private val MIGRATION_6_7 = object : Migration(6, 7) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `${PointDataBean.tableName}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `contrail_id` INTEGER, `site_id` INTEGER, `md5` TEXT, `seq` INTEGER, `point_type` INTEGER, `longitude` REAL, `latitude` REAL, `sub_seq` INTEGER)")
database.execSQL("ALTER TABLE ${ContrailDataBean.tableName} ADD COLUMN contrail_id INTEGER")
database.execSQL("ALTER TABLE ${ContrailDataBean.tableName} ADD COLUMN source INTEGER")
}
}
fun getDBName():MyDataBase{
val roomName = when (ProjectUtils.getProjectType()) {
Project.SAAS -> {
@@ -69,6 +81,7 @@ abstract class MyDataBase : RoomDatabase() {
MyDataBase::class.java,
dbFile.path
)
.addMigrations(MIGRATION_6_7)
.fallbackToDestructiveMigration()
.build()
}

View File

@@ -18,6 +18,13 @@ data class ContrailDataBean(
@ColumnInfo(name = "line_id", typeAffinity = ColumnInfo.INTEGER, index = true)
var lineId: Long? = null,
/**
* 轨迹id
*/
@ColumnInfo(name = "contrail_id", typeAffinity = ColumnInfo.INTEGER)
var contrailId: Long? = null,
/**
* csv格式的轨迹文件
*/
@@ -54,6 +61,14 @@ data class ContrailDataBean(
@ColumnInfo(name = "md5", typeAffinity = ColumnInfo.TEXT, index = true)
var md5: String? = null,
/**
* 轨迹id
*/
@ColumnInfo(name = "source", typeAffinity = ColumnInfo.INTEGER)
var source: Int? = null,
) {
companion object {
const val tableName: String = "contrail_data_table"

View File

@@ -0,0 +1,87 @@
package com.mogo.och.offline.repository.db.bean
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.mogo.och.data.bean.BusStationBean
@Entity(tableName = PointDataBean.tableName)
data class PointDataBean(
@PrimaryKey(autoGenerate = true) var id: Int = 0,
/**
* 点所属线路Id
*/
@ColumnInfo(name = "line_id", typeAffinity = ColumnInfo.INTEGER)
var lineId: Long? = null,
/**
* 轨迹id
*/
@ColumnInfo(name = "contrail_id", typeAffinity = ColumnInfo.INTEGER)
var contrailId: Long? = null,
/**
* A--B--C--D
* A--B 的途径点 siteId = B.id
* B--C 的途径点 siteId = C.id
* C--D 的途径点 siteId = D.id
*/
@ColumnInfo(name = "site_id", typeAffinity = ColumnInfo.INTEGER)
var siteId: Long? = null,
/**
* ContrailDataBean 表格中的md5值
*/
@ColumnInfo(name = "md5", typeAffinity = ColumnInfo.TEXT)
var md5: String? = null,
/**
* 排队组
*/
@ColumnInfo(name = "seq", typeAffinity = ColumnInfo.INTEGER)
var seq: Int? = null,
/**
* 点的类型
*/
@ColumnInfo(name = "point_type", typeAffinity = ColumnInfo.INTEGER)
var pointType: Int? = null,
/**
* 高精坐标
*/
@ColumnInfo(name = "longitude", typeAffinity = ColumnInfo.REAL)
var longitude: Double? = null,
/**
* 高精坐标
*/
@ColumnInfo(name = "latitude", typeAffinity = ColumnInfo.REAL)
var latitude: Double? = null,
/**
* 组内排序
*/
@ColumnInfo(name = "sub_seq", typeAffinity = ColumnInfo.INTEGER)
var subSeq: Int? = null,
) {
fun toStation(): BusStationBean {
val temp = BusStationBean()
temp.lat = latitude?:0.0
temp.lon = longitude?:0.0
temp.pointType = pointType?:pointTypePass
temp.isLeaving = true
return temp
}
companion object {
const val tableName = "point_data_table"
const val pointTypePass = 1
const val pointTypeBlack = 2
}
}

View File

@@ -39,6 +39,9 @@ interface ContrailDataDao {
}
}
@Query("UPDATE ${ContrailDataBean.tableName} SET contrail_id = :contrailId ,source = :source WHERE line_id = :lineId")
fun updateIdAndSource(contrailId: Long, source: Int, lineId: Long)
}

View File

@@ -0,0 +1,39 @@
package com.mogo.och.offline.repository.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.mogo.och.offline.repository.db.bean.PointDataBean
@Dao
interface PointDataDao {
//插入数据
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg lineDataBean: PointDataBean)
//插入数据
@Transaction
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertTra(vararg lineDataBean: PointDataBean)
//删除数据
@Delete
fun delete(vararg lineDataBean: PointDataBean)
// 线路删除时同步删除所属轨迹信息
@Transaction
@Query("DELETE FROM ${PointDataBean.tableName} WHERE line_id in (:lineId)")
fun deleteByLineIdTra(lineId: List<Long>)
@Transaction
@Query("DELETE FROM ${PointDataBean.tableName} WHERE line_id in (:lineId)")
fun deleteByLineId(lineId: List<Long>)
@Query("SELECT * FROM ${PointDataBean.tableName} WHERE line_id = :lineId")
fun queryPointByLineId(lineId: Long) : List<PointDataBean>?
}

View File

@@ -2,6 +2,7 @@ package com.mogo.och.offline.repository.db.repository
import com.mogo.eagle.core.network.utils.digest.DigestUtils
import com.mogo.och.common.module.manager.loop.BizLoopManager
import com.mogo.och.offline.model.LineModel
import com.mogo.och.offline.repository.db.bean.ContrailDataBean
import com.mogo.och.offline.repository.db.IDbRepository
import com.mogo.och.offline.repository.db.MyDataBase
@@ -26,6 +27,7 @@ object ContraiDb : IDbRepository {
val runnable = Runnable {
// 校验数据个数
contrailDao?.let { contrailDao->
val needUpdatePoint = mutableListOf<Long>()
contrailDatalist.forEach {
val md5Source = it.toString()
val md5Hex = DigestUtils.md5Hex(md5Source)
@@ -33,6 +35,7 @@ object ContraiDb : IDbRepository {
if(queryContrailByMd5.isNullOrEmpty()){// 没有值或者值有变化
val needUpdate = contrailDao.queryContrailByLineIdOne(it.lineId!!)
it.md5 = md5Hex
needUpdatePoint.add(it.lineId!!)
if(needUpdate!=null){// 更新
it.id = needUpdate.id
contrailDao.update(it.csvFileUrl?:"",it.csvFileMd5?:"",it.txtFileUrl?:"",it.txtFileMd5?:"",System.currentTimeMillis(),md5Hex,needUpdate.id)
@@ -41,7 +44,12 @@ object ContraiDb : IDbRepository {
}
}
}
if(needUpdatePoint.isNotEmpty()){
LineModel.synContraiInfo(needUpdatePoint)
}
}
}
BizLoopManager.runInIoThread(runnable)
}
@@ -74,4 +82,11 @@ object ContraiDb : IDbRepository {
)
addOrUpdate(mutableListOf(runningLine))
}
fun upDateIdAndsource(contrailId: Long?, source: Int?, lineId: Long?) {
if(contrailId!=null&&source!=null&&lineId!=null){
contrailDao?.updateIdAndSource(contrailId,source,lineId)
}
}
}

View File

@@ -0,0 +1,111 @@
package com.mogo.och.offline.repository.db.repository
import com.mogo.och.offline.repository.db.IDbRepository
import com.mogo.och.offline.repository.db.MyDataBase
import com.mogo.och.offline.repository.db.bean.ContrailDataBean
import com.mogo.och.offline.repository.db.bean.PointDataBean
import com.mogo.och.offline.repository.db.dao.PointDataDao
import com.mogo.och.offline.repository.net.bean.PointResponse
object PointDb: IDbRepository {
private var pointDao: PointDataDao?=null
get() {
if(field==null){
field = MyDataBase.instance?.pointDataDao
register()
}
return field
}
override fun release() {
pointDao = null
}
fun queryPointByLineId(lineId: Long?): List<PointDataBean>? {
lineId?.let {
return pointDao?.queryPointByLineId(lineId)
}
return null
}
fun addOrUpdate(serverDataList:List<PointResponse>) {
val contaiBeans = mutableListOf<PointDataBean>()
val needDelete = mutableListOf<Long>()
val needUpdateLineInfos = mutableListOf<ContrailDataBean>()
serverDataList.forEach { contrailInfo ->
val lineId = contrailInfo.lineId
val siteList = SiteDb.querySiteByLineId(lineId)
val contraiBean = ContraiDb.queryAutopilotInfoByLineid(lineId)
contraiBean?.let {
contraiBean.source = contrailInfo.source
contraiBean.contrailId = contrailInfo.contrailId
needUpdateLineInfos.add(contraiBean)
}
val segmentPointList = contrailInfo.segmentPointList
needDelete.add(lineId)
segmentPointList.forEachIndexed { index, segmentPoint ->
val siteIndex = segmentPoint.segment
siteList?.let { siteListTemp->
siteIndex?.let {siteIndexTemp->
// 途径点和禁行点所有站点
val siteDataBean = siteListTemp[siteIndexTemp]
segmentPoint.pointList?.forEachIndexed { index, point ->
val pointTemp = PointDataBean()
pointTemp.lineId = lineId
pointTemp.contrailId = contrailInfo.contrailId
pointTemp.siteId = siteDataBean.siteId
pointTemp.md5 = contraiBean?.md5?:""
pointTemp.seq = siteIndex
pointTemp.pointType = PointDataBean.pointTypePass
pointTemp.longitude = point.longitude
pointTemp.latitude = point.latitude
pointTemp.subSeq = index
contaiBeans.add(pointTemp)
}
segmentPoint.blackList?.forEachIndexed { index, black ->
val pointTemp = PointDataBean()
pointTemp.lineId = lineId
pointTemp.contrailId = contrailInfo.contrailId
pointTemp.siteId = siteDataBean.siteId
pointTemp.md5 = contraiBean?.md5?:""
pointTemp.seq = siteIndex
pointTemp.pointType = PointDataBean.pointTypeBlack
pointTemp.longitude = black.longitude
pointTemp.latitude = black.latitude
pointTemp.subSeq = index
contaiBeans.add(pointTemp)
}
}
}
}
if(needUpdateLineInfos.size<100){
needUpdateLineInfos.forEach {
ContraiDb.upDateIdAndsource(it.contrailId,it.source,it.lineId)
}
}else{
MyDataBase.instance?.runInTransaction{
needUpdateLineInfos.forEach {
ContraiDb.upDateIdAndsource(it.contrailId,it.source,it.lineId)
}
}
}
if(needDelete.size<100) {
pointDao?.deleteByLineId(needDelete)
}else{
pointDao?.deleteByLineIdTra(needDelete)
}
if(contaiBeans.size<100) {
pointDao?.insert(*contaiBeans.toTypedArray())
}else{
pointDao?.insertTra(*contaiBeans.toTypedArray())
}
}
}
}

View File

@@ -1,9 +1,14 @@
package com.mogo.och.offline.repository.net;
import com.mogo.och.offline.repository.net.bean.BindLineListResponse;
import com.mogo.och.offline.repository.net.bean.PointsResponse;
import com.mogo.och.offline.repository.net.bean.QueryPointRequest;
import io.reactivex.Observable;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
/**
@@ -28,5 +33,9 @@ public interface IBascApiService {
@GET("/och-shuttle-cabin/api/business/v1/driver/queryBindLineListBySn")
Observable<BindLineListResponse> daliQueryBindLineListBySn(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
@Headers( {"Content-Type:application/json;charset=UTF-8"} )
@POST( "/och-contrail/contrail/queryCabinContrailByLines" )
Observable<PointsResponse> queryCabinContrailByLines(@Header ("appId") String appId, @Header("ticket") String ticket, @Body QueryPointRequest request);
}

View File

@@ -5,11 +5,17 @@ import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.env.ProjectUtils
import com.mogo.eagle.core.network.MoGoRetrofitFactory
import com.mogo.commons.storage.SharedPrefsMgr
import com.mogo.och.common.module.biz.login.LoginStatusManager
import com.mogo.och.common.module.constant.OchCommonConst
import com.mogo.och.common.module.network.OchCommonNet
import com.mogo.och.common.module.network.OchCommonServiceCallback
import com.mogo.och.common.module.network.OchCommonSubscribeImpl
import com.mogo.och.common.module.network.interceptor.transformIoTry
import com.mogo.och.offline.repository.net.bean.BindLineListResponse
import com.mogo.och.offline.repository.net.bean.PointResponse
import com.mogo.och.offline.repository.net.bean.QueryPointRequest
import com.zhidao.thirdlogin.LoginManager
import io.reactivex.Observable
/**
* @author: wangmingjun
@@ -55,4 +61,23 @@ object OrderServiceManager {
)
}
}
fun queryPointsByLinesId(
data: MutableList<Long>
): Observable<MutableList<PointResponse>>? {
val request = QueryPointRequest(LoginStatusManager.getOchBizInfo()?.businessType ?: 11, data)
return mService.queryCabinContrailByLines(
MoGoAiCloudClientConfig.getInstance().serviceAppId,
SharedPrefsMgr.getInstance().token,
request,
)
.transformIoTry()
.flatMap(OchCommonNet("queryPointsByLinesId",false))
.flatMap {
Observable.just(it.data?: mutableListOf())
}
}
}

View File

@@ -0,0 +1,42 @@
package com.mogo.och.offline.repository.net.bean
import com.mogo.eagle.core.data.BaseData
class PointsResponse : BaseData() {
var data: MutableList<PointResponse>?=null
}
data class Point(
val latitude: Double,
val longitude: Double,
val pointType: Int,
val segment: Int
)
data class Black(
val latitude: Double,
val longitude: Double,
val pointType: Int,
val segment: Int
)
data class PointResponse(
val businessType: Int,
val contrailId: Long,
val contrailSaveTime: Long,
val csvFileMd5: String,
val csvFileUrl: String,
val lineId: Long,
val lineName: String,
val segmentPointList: List<SegmentPoint>,
val source: Int,
val txtFileMd5: String,
val txtFileUrl: String
)
data class SegmentPoint(
val blackList: List<Black>,
val pointList: List<Point>,
val segment: Int?
)

View File

@@ -0,0 +1,10 @@
package com.mogo.och.offline.repository.net.bean
/**
* 通过lineid 获取轨迹id
*/
data class QueryPointRequest(val businessType: Int,val lineIds:MutableList<Long>){
companion object{
}
}

View File

@@ -110,8 +110,8 @@ abstract class MyDataBase : RoomDatabase() {
private val MIGRATION_6_7 = object : Migration(6, 7) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS `${PointDataBean.tableName}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `line_id` INTEGER, `contrail_id` INTEGER, `site_id` INTEGER, `md5` TEXT, `seq` INTEGER, `point_type` INTEGER, `longitude` REAL, `latitude` REAL, `sub_seq` INTEGER)")
database.execSQL("ALTER TABLE ${PointDataBean.tableName} ADD COLUMN contrail_id INTEGER")
database.execSQL("ALTER TABLE ${PointDataBean.tableName} ADD COLUMN source INTEGER")
database.execSQL("ALTER TABLE ${ContrailDataBean.tableName} ADD COLUMN contrail_id INTEGER")
database.execSQL("ALTER TABLE ${ContrailDataBean.tableName} ADD COLUMN source INTEGER")
}
}