[6.9.0]
[fea] [dao 不能混用]
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
package com.mogo.och.data.db.repository
|
||||
|
||||
import com.mogo.eagle.core.network.utils.digest.DigestUtils
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.ContrailDataBean
|
||||
import com.mogo.och.data.db.dao.ContrailDataDao
|
||||
|
||||
abstract class BaseContraiDb {
|
||||
|
||||
open var contrailDao: ContrailDataDao?=null
|
||||
|
||||
fun addOrUpdate(contrailDatalist:List<ContrailDataBean>){
|
||||
val runnable = Runnable {
|
||||
// 校验数据个数
|
||||
contrailDao?.let { contrailDao->
|
||||
contrailDatalist.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
val queryContrailByMd5 = contrailDao.queryContrailByMd5(md5Hex)
|
||||
if(queryContrailByMd5.isNullOrEmpty()){// 没有值或者值有变化
|
||||
val needUpdate = contrailDao.queryContrailByLineIdOne(it.lineId!!)
|
||||
it.md5 = md5Hex
|
||||
if(needUpdate!=null){// 更新
|
||||
it.id = needUpdate.id
|
||||
contrailDao.update(it.csvFileUrl?:"",it.csvFileMd5?:"",it.txtFileUrl?:"",it.txtFileMd5?:"",System.currentTimeMillis(),md5Hex,needUpdate.id)
|
||||
}else{// 插入新的
|
||||
contrailDao.insert(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BizLoopManager.runInIoThread(runnable)
|
||||
}
|
||||
|
||||
fun deleteByLineId(lineId: Long) {
|
||||
contrailDao?.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
fun queryAutopilotInfoByLineid(lineId: Long): ContrailDataBean? {
|
||||
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))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package com.mogo.och.data.db.repository
|
||||
|
||||
import androidx.room.Transaction
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.LineDataBean
|
||||
import com.mogo.och.data.db.dao.LineDataDao
|
||||
import io.reactivex.Observable
|
||||
|
||||
abstract class BaseLineDb {
|
||||
|
||||
open var lineDao: LineDataDao?=null
|
||||
|
||||
|
||||
fun cleanWeltData(){
|
||||
lineDao?.deleteWeltData()
|
||||
}
|
||||
|
||||
fun queryCanUserLine(): List<LineDataBean>? {
|
||||
return lineDao?.loadData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取可用线路
|
||||
*/
|
||||
fun queryCanUseLineRx(): Observable<List<LineDataBean>?>? {
|
||||
return lineDao?.loadDataRx()
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台line 删除 需要连带着把轨迹信息、站点信息和任务信息删除
|
||||
*/
|
||||
abstract fun deleteSitesTaskAndContraiDb(lineId:Long)
|
||||
|
||||
fun checkAndUpdate(serverDatalist:List<LineDataBean>){
|
||||
val runable = object :Runnable{
|
||||
@Transaction
|
||||
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去
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
lineDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
lineDao.delete(*needMinusDatas.toTypedArray())
|
||||
needMinusDatas.forEach { minusLine->
|
||||
minusLine.lineId?.let { lineId->
|
||||
// 删除线路对应的站点
|
||||
deleteSitesTaskAndContraiDb(lineId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 交集 服务器端
|
||||
val needUpdateByMd5 = serverDatalist-needAddDatas
|
||||
// 交集 本地数据库
|
||||
val oldDataList = loadData-needMinusDatas
|
||||
|
||||
val needDelete = mutableListOf<LineDataBean>()
|
||||
val needUpDate = mutableListOf<LineDataBean>()
|
||||
|
||||
needUpdateByMd5.forEach {
|
||||
val oldList = oldDataList.filter { local -> local.lineId == it.lineId }
|
||||
if(oldList.isNotEmpty()){
|
||||
oldList.forEachIndexed { index, lineBean ->
|
||||
if(index==0){
|
||||
if (lineBean.lineName == it.lineName && lineBean.endStationName == it.endStationName) {
|
||||
// 数据没有变化
|
||||
}else{
|
||||
it.id = lineBean.id
|
||||
needUpDate.add(it)
|
||||
}
|
||||
}else{
|
||||
// 站点多了 需要删除
|
||||
needDelete.add(lineBean)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lineDao.delete(*needDelete.toTypedArray())
|
||||
|
||||
needUpDate.forEach { updateItem->
|
||||
// 跟新数据
|
||||
lineDao.updateInfo(updateItem.lineName,updateItem.endStationName,updateItem.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BizLoopManager.runInIoThread(runable)
|
||||
}
|
||||
|
||||
fun deleteObsoleteData(){
|
||||
lineDao?.deleteObsoleteData()?.let {
|
||||
OchChainLogManager.writeChainLogDb("删除临时数据","Line删除数量:${it}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有线路就插入线路
|
||||
*/
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package com.mogo.och.data.db.repository
|
||||
|
||||
import androidx.room.Transaction
|
||||
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.TAG
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.SiteDataBean
|
||||
import com.mogo.och.data.db.dao.SiteDataDao
|
||||
|
||||
open class BaseSiteDb {
|
||||
|
||||
open var siteDataDao: SiteDataDao? = null
|
||||
|
||||
fun addOrUpdate(serverDataList: List<SiteDataBean>) {
|
||||
val runnable = object :Runnable {
|
||||
@Transaction
|
||||
override fun run() {
|
||||
siteDataDao?.let { siteDataDao ->
|
||||
val localAllSites = siteDataDao.queryAllSites()
|
||||
if (localAllSites.isNullOrEmpty()) {
|
||||
// 插入新数据
|
||||
siteDataDao.insert(*serverDataList.toTypedArray())
|
||||
return
|
||||
}
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDataList-localAllSites
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = localAllSites - serverDataList
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
needAddDatas.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
it.md5 = md5Hex
|
||||
}
|
||||
// 新增插入新数据
|
||||
siteDataDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
siteDataDao.deleteById(*needMinusDatas.toTypedArray())
|
||||
}
|
||||
|
||||
// 交集 服务器端
|
||||
val needUpdateByMd5 = serverDataList-needAddDatas
|
||||
// 交集 本地数据库
|
||||
val oldDataList = localAllSites-needMinusDatas
|
||||
|
||||
val needDelete = mutableListOf<SiteDataBean>()
|
||||
val needUpDate = mutableListOf<SiteDataBean>()
|
||||
|
||||
|
||||
needUpdateByMd5.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
val oldList =
|
||||
oldDataList.filter { local -> local.siteId == it.siteId && local.lineId == it.lineId }
|
||||
if(oldList.isNotEmpty()){
|
||||
oldList.forEachIndexed { index, siteDataBean ->
|
||||
if(index==0){
|
||||
if (siteDataBean.md5 == md5Hex) {
|
||||
// 数据没有变化
|
||||
}else{
|
||||
it.id = siteDataBean.id
|
||||
it.md5 = md5Hex
|
||||
needUpDate.add(it)
|
||||
|
||||
}
|
||||
}else{
|
||||
needDelete.add(siteDataBean)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
needUpDate.forEach {updateDateItem->
|
||||
siteDataDao.updateInfo(updateDateItem.siteId,updateDateItem.lineId,updateDateItem.name,updateDateItem.nameKr,
|
||||
updateDateItem.seq,updateDateItem.gcjLon,updateDateItem.gcjLat,updateDateItem.lon,updateDateItem.lat,
|
||||
updateDateItem.introduction,updateDateItem.isPlayTts,updateDateItem.md5,updateDateItem.videoListDB,updateDateItem.id)
|
||||
}
|
||||
siteDataDao.deleteById(*needDelete.toTypedArray())
|
||||
checkData()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BizLoopManager.runInIoThread(runnable)
|
||||
}
|
||||
|
||||
fun checkData() {
|
||||
CallerLogger.d(TAG,"检测站点数据")
|
||||
siteDataDao?.checkData()?.let { list ->
|
||||
list.forEach {
|
||||
siteDataDao?.deleteById(it)
|
||||
}
|
||||
if (list.isNotEmpty()) {
|
||||
OchChainLogManager.writeChainLogDb("数据检测", "有重复数据${list}")
|
||||
checkData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteByLineId(lineId: Long) {
|
||||
siteDataDao?.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
fun querySiteByLineId(lineId:Long):List<SiteDataBean>?{
|
||||
siteDataDao?.let { siteDataDao->
|
||||
return siteDataDao.querySitesByLineId(lineId)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -33,9 +33,9 @@ import com.mogo.och.offline.R
|
||||
import com.mogo.och.offline.constant.BusConst
|
||||
import com.mogo.och.offline.repository.RepositoryManager
|
||||
import com.mogo.och.offline.repository.db.bean.TaskSiteDataBean
|
||||
import com.mogo.och.offline.util.OffLineTrajectoryManager
|
||||
import com.mogo.och.offline.util.ShuttleVoiceManager
|
||||
import com.mogo.och.offline.repository.exception.DataException
|
||||
import com.mogo.och.offline.util.OffLineTrajectoryManager
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
||||
@@ -11,10 +11,11 @@ import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.och.data.db.bean.ContrailDataBean
|
||||
import com.mogo.och.data.db.bean.LineDataBean
|
||||
import com.mogo.och.data.db.bean.SiteDataBean
|
||||
import com.mogo.och.data.db.dao.ContrailDataDao
|
||||
import com.mogo.och.data.db.dao.LineDataDao
|
||||
import com.mogo.och.data.db.dao.SiteDataDao
|
||||
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.dao.ContrailDataDao
|
||||
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
|
||||
|
||||
@@ -22,7 +23,7 @@ import com.mogo.och.offline.repository.db.dao.TaskSiteDataDao
|
||||
//entities指定该数据库有哪些表,多张表就逗号分隔
|
||||
//version指定数据库版本号,升级时需要用到
|
||||
//数据库继承自RoomDatabase
|
||||
@Database(entities = [ContrailDataBean::class, LineDataBean::class, SiteDataBean::class, TaskSiteDataBean::class], version = 6)
|
||||
@Database(entities = [ContrailDataBean::class, LineDataBean::class, SiteDataBean::class, TaskSiteDataBean::class, TaskDataBean::class], version = 6)
|
||||
abstract class MyDataBase : RoomDatabase() {
|
||||
|
||||
override fun getOpenHelper(): SupportSQLiteOpenHelper {
|
||||
|
||||
@@ -37,6 +37,14 @@ data class TaskDataBean(
|
||||
@ColumnInfo(name = "end_time", typeAffinity = ColumnInfo.INTEGER)
|
||||
var endtime: Long? = null,
|
||||
|
||||
|
||||
/**
|
||||
* 任务保存到数据库的时间 用来第二天删除前几天的任务
|
||||
*/
|
||||
@ColumnInfo(name = "task_get_time", typeAffinity = ColumnInfo.INTEGER)
|
||||
var taskgetTime: Long = System.currentTimeMillis(),
|
||||
|
||||
|
||||
/**
|
||||
* 任务状态 (0 未使用) (1 运行中) (2 已使用)
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.och.data.db.dao
|
||||
package com.mogo.och.offline.repository.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.och.data.db.dao
|
||||
package com.mogo.och.offline.repository.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mogo.och.data.db.dao
|
||||
package com.mogo.och.offline.repository.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
@@ -44,7 +44,7 @@ interface TaskDataDao {
|
||||
@Query("SELECT * FROM ${TaskDataBean.tableName} WHERE task_get_time > :zeroTime and status = ${TaskDataBean.useing}")
|
||||
fun queryRunningTaskByStatus(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): List<TaskDataBean>?
|
||||
|
||||
@Query("SELECT * FROM ${TaskDataBean.tableName} WHERE task_get_time > :zeroTime and status = ${TaskDataBean.unUse} and line_id = :lineId order by task_start_time")
|
||||
@Query("SELECT * FROM ${TaskDataBean.tableName} WHERE task_get_time > :zeroTime and status = ${TaskDataBean.unUse} and line_id = :lineId order by task_get_time")
|
||||
fun queryUnuseTask(
|
||||
lineId: Long,
|
||||
zeroTime: Long = DateTimeUtil.getCurrentDateZero()
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.mogo.och.offline.repository.db.repository
|
||||
|
||||
import com.mogo.och.data.db.dao.ContrailDataDao
|
||||
import com.mogo.och.data.db.repository.BaseContraiDb
|
||||
import com.mogo.eagle.core.network.utils.digest.DigestUtils
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.ContrailDataBean
|
||||
import com.mogo.och.offline.repository.db.IDbRepository
|
||||
import com.mogo.och.offline.repository.db.MyDataBase
|
||||
import com.mogo.och.offline.repository.db.dao.ContrailDataDao
|
||||
|
||||
object ContraiDb : IDbRepository, BaseContraiDb() {
|
||||
object ContraiDb : IDbRepository {
|
||||
|
||||
override var contrailDao: ContrailDataDao?=null
|
||||
var contrailDao: ContrailDataDao?=null
|
||||
get() {
|
||||
if(field==null){
|
||||
field = MyDataBase.instance?.contrailDataDao
|
||||
@@ -20,6 +22,56 @@ object ContraiDb : IDbRepository, BaseContraiDb() {
|
||||
contrailDao = null
|
||||
}
|
||||
|
||||
fun addOrUpdate(contrailDatalist:List<ContrailDataBean>){
|
||||
val runnable = Runnable {
|
||||
// 校验数据个数
|
||||
contrailDao?.let { contrailDao->
|
||||
contrailDatalist.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
val queryContrailByMd5 = contrailDao.queryContrailByMd5(md5Hex)
|
||||
if(queryContrailByMd5.isNullOrEmpty()){// 没有值或者值有变化
|
||||
val needUpdate = contrailDao.queryContrailByLineIdOne(it.lineId!!)
|
||||
it.md5 = md5Hex
|
||||
if(needUpdate!=null){// 更新
|
||||
it.id = needUpdate.id
|
||||
contrailDao.update(it.csvFileUrl?:"",it.csvFileMd5?:"",it.txtFileUrl?:"",it.txtFileMd5?:"",System.currentTimeMillis(),md5Hex,needUpdate.id)
|
||||
}else{// 插入新的
|
||||
contrailDao.insert(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BizLoopManager.runInIoThread(runnable)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun deleteByLineId(lineId: Long) {
|
||||
contrailDao?.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
fun queryAutopilotInfoByLineid(lineId: Long): ContrailDataBean? {
|
||||
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))
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.mogo.och.offline.repository.db.repository
|
||||
|
||||
import com.mogo.och.data.db.dao.LineDataDao
|
||||
import com.mogo.och.data.db.repository.BaseLineDb
|
||||
import androidx.room.Transaction
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.LineDataBean
|
||||
import com.mogo.och.offline.repository.db.IDbRepository
|
||||
import com.mogo.och.offline.repository.db.MyDataBase
|
||||
import com.mogo.och.offline.repository.db.dao.LineDataDao
|
||||
import io.reactivex.Observable
|
||||
|
||||
object LineDb: IDbRepository, BaseLineDb() {
|
||||
object LineDb: IDbRepository {
|
||||
|
||||
override var lineDao: LineDataDao?=null
|
||||
private var lineDao: LineDataDao?=null
|
||||
get() {
|
||||
if(field==null){
|
||||
field = MyDataBase.instance?.lineDataDao
|
||||
@@ -16,13 +20,116 @@ object LineDb: IDbRepository, BaseLineDb() {
|
||||
return field
|
||||
}
|
||||
|
||||
override fun deleteSitesTaskAndContraiDb(lineId: Long) {
|
||||
SiteDb.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
|
||||
override fun release() {
|
||||
lineDao = null
|
||||
}
|
||||
|
||||
|
||||
fun cleanWeltData(){
|
||||
lineDao?.deleteWeltData()
|
||||
}
|
||||
|
||||
fun queryCanUserLine(): List<LineDataBean>? {
|
||||
return lineDao?.loadData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取可用线路
|
||||
*/
|
||||
fun queryCanUseLineRx(): Observable<List<LineDataBean>?>? {
|
||||
return lineDao?.loadDataRx()
|
||||
}
|
||||
|
||||
fun checkAndUpdate(serverDatalist:List<LineDataBean>){
|
||||
val runable = object :Runnable{
|
||||
@Transaction
|
||||
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去
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
lineDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
lineDao.delete(*needMinusDatas.toTypedArray())
|
||||
needMinusDatas.forEach { minusLine->
|
||||
minusLine.lineId?.let { lineId->
|
||||
// 删除线路对应的站点
|
||||
SiteDb.deleteByLineId(lineId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 交集 服务器端
|
||||
val needUpdateByMd5 = serverDatalist-needAddDatas
|
||||
// 交集 本地数据库
|
||||
val oldDataList = loadData-needMinusDatas
|
||||
|
||||
val needDelete = mutableListOf<LineDataBean>()
|
||||
val needUpDate = mutableListOf<LineDataBean>()
|
||||
|
||||
needUpdateByMd5.forEach {
|
||||
val oldList = oldDataList.filter { local -> local.lineId == it.lineId }
|
||||
if(oldList.isNotEmpty()){
|
||||
oldList.forEachIndexed { index, lineBean ->
|
||||
if(index==0){
|
||||
if (lineBean.lineName == it.lineName && lineBean.endStationName == it.endStationName) {
|
||||
// 数据没有变化
|
||||
}else{
|
||||
it.id = lineBean.id
|
||||
needUpDate.add(it)
|
||||
}
|
||||
}else{
|
||||
// 站点多了 需要删除
|
||||
needDelete.add(lineBean)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lineDao.delete(*needDelete.toTypedArray())
|
||||
|
||||
needUpDate.forEach { updateItem->
|
||||
// 跟新数据
|
||||
lineDao.updateInfo(updateItem.lineName,updateItem.endStationName,updateItem.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BizLoopManager.runInIoThread(runable)
|
||||
}
|
||||
|
||||
fun deleteObsoleteData(){
|
||||
lineDao?.deleteObsoleteData()?.let {
|
||||
OchChainLogManager.writeChainLogDb("删除临时数据","Line删除数量:${it}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有线路就插入线路
|
||||
*/
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.mogo.och.offline.repository.db.repository
|
||||
|
||||
import com.mogo.och.data.db.dao.SiteDataDao
|
||||
import com.mogo.och.data.db.repository.BaseSiteDb
|
||||
import androidx.room.Transaction
|
||||
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.TAG
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.SiteDataBean
|
||||
import com.mogo.och.offline.repository.db.IDbRepository
|
||||
import com.mogo.och.offline.repository.db.MyDataBase
|
||||
import com.mogo.och.offline.repository.db.dao.SiteDataDao
|
||||
|
||||
object SiteDb: IDbRepository, BaseSiteDb() {
|
||||
object SiteDb: IDbRepository {
|
||||
|
||||
override var siteDataDao: SiteDataDao? = null
|
||||
private var siteDataDao: SiteDataDao? = null
|
||||
get() {
|
||||
if(field==null){
|
||||
field = MyDataBase.instance?.siteDataDao
|
||||
@@ -20,4 +26,107 @@ object SiteDb: IDbRepository, BaseSiteDb() {
|
||||
siteDataDao = null
|
||||
}
|
||||
|
||||
fun addOrUpdate(serverDataList: List<SiteDataBean>) {
|
||||
val runnable = object :Runnable {
|
||||
@Transaction
|
||||
override fun run() {
|
||||
siteDataDao?.let { siteDataDao ->
|
||||
val localAllSites = siteDataDao.queryAllSites()
|
||||
if (localAllSites.isNullOrEmpty()) {
|
||||
// 插入新数据
|
||||
siteDataDao.insert(*serverDataList.toTypedArray())
|
||||
return
|
||||
}
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDataList-localAllSites
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = localAllSites - serverDataList
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
needAddDatas.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
it.md5 = md5Hex
|
||||
}
|
||||
// 新增插入新数据
|
||||
siteDataDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
siteDataDao.deleteById(*needMinusDatas.toTypedArray())
|
||||
}
|
||||
|
||||
// 交集 服务器端
|
||||
val needUpdateByMd5 = serverDataList-needAddDatas
|
||||
// 交集 本地数据库
|
||||
val oldDataList = localAllSites-needMinusDatas
|
||||
|
||||
val needDelete = mutableListOf<SiteDataBean>()
|
||||
val needUpDate = mutableListOf<SiteDataBean>()
|
||||
|
||||
|
||||
needUpdateByMd5.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
val oldList =
|
||||
oldDataList.filter { local -> local.siteId == it.siteId && local.lineId == it.lineId }
|
||||
if(oldList.isNotEmpty()){
|
||||
oldList.forEachIndexed { index, siteDataBean ->
|
||||
if(index==0){
|
||||
if (siteDataBean.md5 == md5Hex) {
|
||||
// 数据没有变化
|
||||
}else{
|
||||
it.id = siteDataBean.id
|
||||
it.md5 = md5Hex
|
||||
needUpDate.add(it)
|
||||
|
||||
}
|
||||
}else{
|
||||
needDelete.add(siteDataBean)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
needUpDate.forEach {updateDateItem->
|
||||
siteDataDao.updateInfo(updateDateItem.siteId,updateDateItem.lineId,updateDateItem.name,updateDateItem.nameKr,
|
||||
updateDateItem.seq,updateDateItem.gcjLon,updateDateItem.gcjLat,updateDateItem.lon,updateDateItem.lat,
|
||||
updateDateItem.introduction,updateDateItem.isPlayTts,updateDateItem.md5,updateDateItem.videoListDB,updateDateItem.id)
|
||||
}
|
||||
siteDataDao.deleteById(*needDelete.toTypedArray())
|
||||
checkData()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BizLoopManager.runInIoThread(runnable)
|
||||
}
|
||||
|
||||
fun checkData() {
|
||||
CallerLogger.d(TAG,"检测站点数据")
|
||||
siteDataDao?.checkData()?.let { list ->
|
||||
list.forEach {
|
||||
siteDataDao?.deleteById(it)
|
||||
}
|
||||
if (list.isNotEmpty()) {
|
||||
OchChainLogManager.writeChainLogDb("数据检测", "有重复数据${list}")
|
||||
checkData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteByLineId(lineId: Long) {
|
||||
siteDataDao?.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
fun querySiteByLineId(lineId:Long):List<SiteDataBean>?{
|
||||
siteDataDao?.let { siteDataDao->
|
||||
return siteDataDao.querySitesByLineId(lineId)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,15 +4,16 @@ import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
|
||||
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.CallerLogger.e
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.och.bridge.autopilot.line.LineManager
|
||||
import com.mogo.och.bridge.autopilot.trajectory.TrajectoryManager
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusManager.isLogin
|
||||
import com.mogo.och.bridge.autopilot.trajectory.ITrajectoryListListener
|
||||
import com.mogo.och.bridge.autopilot.trajectory.TrajectoryManager
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager.writeChainLog
|
||||
import com.mogo.och.offline.constant.BusConst
|
||||
import com.mogo.och.offline.model.OrderModel
|
||||
import com.mogo.och.offline.model.LineModel.currentTask
|
||||
import com.mogo.och.offline.model.OrderModel.isGoingToNextStation
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
@@ -24,36 +25,44 @@ import java.util.concurrent.TimeUnit
|
||||
* Bus轨迹管理:给MEC下发用于轨迹下载的信息
|
||||
* Created on 2022/6/23
|
||||
*/
|
||||
object OffLineTrajectoryManager : com.mogo.och.bridge.autopilot.trajectory.ITrajectoryListListener {
|
||||
object OffLineTrajectoryManager : ITrajectoryListListener {
|
||||
|
||||
private val TAG: String = M_BUS + OffLineTrajectoryManager::class.java.simpleName
|
||||
|
||||
private var mAutopilotControlParameters: AutopilotControlParameters? = null
|
||||
private var mSendReqDisposable: Disposable? = null
|
||||
|
||||
private val TAG: String = OffLineTrajectoryManager::class.java.simpleName
|
||||
|
||||
init {
|
||||
|
||||
mAutopilotControlParameters = AutopilotControlParameters()
|
||||
}
|
||||
|
||||
fun load(){
|
||||
TrajectoryManager.addListener(TAG,this)
|
||||
fun load() {
|
||||
TrajectoryManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
fun release(){
|
||||
fun release() {
|
||||
TrajectoryManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 同步Bus路线信息
|
||||
*/
|
||||
fun syncTrajectoryInfo() {
|
||||
val routesResult = OrderModel.getInstance().busRoutesResult
|
||||
if (isLogin() && routesResult != null && OrderModel.getInstance().currentStationIndex == 0 && !OrderModel.getInstance().isGoingToNextStation) {
|
||||
d(SceneConstant.M_BUS + TAG, "syncTrajectoryInfo() start.")
|
||||
if (mAutopilotControlParameters == null || mAutopilotControlParameters!!.autoPilotLine == null) {
|
||||
OchChainLogManager.writeChainLogTrajectory("轨迹监控", "开始或者结束下发轨迹 轨迹id:-1")
|
||||
} else {
|
||||
OchChainLogManager.writeChainLogTrajectory(
|
||||
"轨迹监控",
|
||||
"开始或者结束下发轨迹 轨迹id:${mAutopilotControlParameters!!.autoPilotLine!!.lineId}"
|
||||
)
|
||||
}
|
||||
if (isLogin() && currentTask != null && !isGoingToNextStation) {
|
||||
d(TAG, "syncTrajectoryInfo() start.")
|
||||
startTrajReqLoop()
|
||||
} else {
|
||||
// 无路线信息or当前未在始发站
|
||||
d(SceneConstant.M_BUS + TAG, "syncTrajectoryInfo() stop.")
|
||||
d(TAG, "syncTrajectoryInfo() stop.")
|
||||
stopTrajReqLoop()
|
||||
}
|
||||
}
|
||||
@@ -67,18 +76,15 @@ object OffLineTrajectoryManager : com.mogo.och.bridge.autopilot.trajectory.ITraj
|
||||
}
|
||||
|
||||
override fun onDownLoadReady(lineId: Long) {
|
||||
// 收到ssm的自动驾驶变为ready,再次下发轨迹下载.解决:域控重启,或者102域控启动太早,107节点初始化未完成导致的轨迹未进行下载。
|
||||
syncTrajectoryInfo()
|
||||
}
|
||||
|
||||
private fun setupAutoPilotLine() {
|
||||
val routesResult = OrderModel.getInstance().busRoutesResult
|
||||
if (routesResult == null) {
|
||||
if (LineManager.contraiInfo == null || LineManager.lineInfos == null) {
|
||||
e(
|
||||
SceneConstant.M_BUS + TAG,
|
||||
"setupAutoPilotLine(): routesResult is null."
|
||||
TAG,
|
||||
"下发轨迹报错:没有轨迹或线路信息 contraiInfo:${LineManager.contraiInfo} lineInfos:${LineManager.lineInfos}"
|
||||
)
|
||||
return
|
||||
} else {
|
||||
mAutopilotControlParameters = LineManager.initAutopilotControlParameters()
|
||||
}
|
||||
@@ -90,52 +96,72 @@ object OffLineTrajectoryManager : com.mogo.och.bridge.autopilot.trajectory.ITraj
|
||||
}
|
||||
|
||||
private fun startTrajReqLoop() {
|
||||
if (mAutopilotControlParameters == null || mAutopilotControlParameters!!.autoPilotLine == null) {
|
||||
OchChainLogManager.writeChainLogTrajectory("轨迹监控", "开始下发轨迹 轨迹id:-1")
|
||||
} else {
|
||||
OchChainLogManager.writeChainLogTrajectory(
|
||||
"轨迹监控",
|
||||
"开始下发轨迹 轨迹id:${mAutopilotControlParameters?.autoPilotLine?.lineId}"
|
||||
)
|
||||
}
|
||||
if (mSendReqDisposable != null && !mSendReqDisposable!!.isDisposed) {
|
||||
return
|
||||
}
|
||||
d(SceneConstant.M_BUS + TAG, "startTrajReqLoop()")
|
||||
d(TAG, "startTrajReqLoop()")
|
||||
setupAutoPilotLine()
|
||||
mSendReqDisposable = Observable.interval(
|
||||
BusConst.LOOP_DELAY,
|
||||
BusConst.LOOP_PERIOD_10S, TimeUnit.MILLISECONDS
|
||||
)
|
||||
.map((Function { aLong: Long -> aLong + 1 }))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { aLong: Long ->
|
||||
BusConst.LOOP_DELAY, BusConst.LOOP_PERIOD_10S, TimeUnit.MILLISECONDS
|
||||
).map((Function { aLong: Long -> aLong + 1 })).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread()).subscribe { aLong: Long ->
|
||||
if (aLong > BusConst.LOOP_SEND_TRAJ_TIMES) {
|
||||
stopTrajReqLoop()
|
||||
return@subscribe
|
||||
}
|
||||
d(SceneConstant.M_BUS + TAG, "loop sendTrajectoryReq: $aLong")
|
||||
d(TAG, "loop sendTrajectoryReq: $aLong")
|
||||
sendTrajectoryReq()
|
||||
}
|
||||
}
|
||||
|
||||
fun stopTrajReqLoop() {
|
||||
if (mAutopilotControlParameters == null || mAutopilotControlParameters!!.autoPilotLine == null) {
|
||||
OchChainLogManager.writeChainLogTrajectory("轨迹监控", "结束下发轨迹 轨迹id:-1")
|
||||
} else {
|
||||
OchChainLogManager.writeChainLogTrajectory(
|
||||
"轨迹监控",
|
||||
"结束下发轨迹 轨迹id:${mAutopilotControlParameters!!.autoPilotLine!!.lineId}"
|
||||
)
|
||||
}
|
||||
if (mSendReqDisposable != null) {
|
||||
d(SceneConstant.M_BUS + TAG, "stopTrajReqLoop()")
|
||||
d(TAG, "stopTrajReqLoop()")
|
||||
mSendReqDisposable!!.dispose()
|
||||
mSendReqDisposable = null
|
||||
clearAutoPilotLine()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* download 加orderid
|
||||
* fsm 回传orderid
|
||||
* 下载轨迹 添加回执超时处理
|
||||
*/
|
||||
private fun sendTrajectoryReq() {
|
||||
if (mAutopilotControlParameters == null||mAutopilotControlParameters!!.autoPilotLine==null) {
|
||||
e(SceneConstant.M_BUS + TAG, "sendTrajectoryReq(): mAutoPilotLine is null!!!")
|
||||
return
|
||||
if (mAutopilotControlParameters == null || mAutopilotControlParameters!!.autoPilotLine == null || mAutopilotControlParameters!!.autoPilotLine!!.lineId == -1L) {
|
||||
e(TAG, "下发轨迹报错:自己参数:${mAutopilotControlParameters}")
|
||||
setupAutoPilotLine()
|
||||
if (mAutopilotControlParameters == null || mAutopilotControlParameters!!.autoPilotLine == null || mAutopilotControlParameters!!.autoPilotLine!!.lineId == -1L) {
|
||||
return
|
||||
}
|
||||
}
|
||||
writeChainLog(
|
||||
"轨迹监控",
|
||||
"sendTrajectoryReq() 下发轨迹 轨迹id" + mAutopilotControlParameters!!.autoPilotLine!!.lineId,
|
||||
true,
|
||||
OchChainLogManager.EVENT_KEY_INFE_WITH_TRAJECTORY
|
||||
)
|
||||
CallerAutoPilotControlManager.sendTrajectoryDownloadReq(mAutopilotControlParameters!!.autoPilotLine!!,0,mAutopilotControlParameters!!.orderId)
|
||||
d(
|
||||
SceneConstant.M_BUS + TAG, "sendTrajectoryReq(): "
|
||||
+ GsonUtils.toJson(mAutopilotControlParameters)
|
||||
)
|
||||
mAutopilotControlParameters?.let {
|
||||
OchChainLogManager.writeChainLogTrajectory(
|
||||
"轨迹监控",
|
||||
"sendTrajectoryReq() 下发轨迹 轨迹id:${it.autoPilotLine!!.lineId}"
|
||||
)
|
||||
CallerAutoPilotControlManager.sendTrajectoryDownloadReq(it.autoPilotLine!!, 0,
|
||||
it.orderId)
|
||||
}
|
||||
|
||||
d(TAG, "sendTrajectoryReq(): " + GsonUtils.toJson(mAutopilotControlParameters))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg
|
||||
import com.mogo.och.common.module.utils.ResourcesUtils
|
||||
import com.mogo.och.common.module.voice.VoiceNotice
|
||||
import com.mogo.och.shuttle.weaknet.R
|
||||
import com.mogo.och.offline.R
|
||||
import com.mogo.skin.utils.SkinResources
|
||||
import com.mogo.tts.base.LangTtsEntity
|
||||
import com.mogo.tts.base.LanguageType
|
||||
@@ -26,15 +26,15 @@ object ShuttleVoiceManager {
|
||||
val list: MutableList<LangTtsEntity> = ArrayList()
|
||||
siteNameCN?.let {
|
||||
val chineseTTS = LangTtsEntity(
|
||||
context.getString(R.string.bus_arrived_station_tip, it),
|
||||
context.getString(R.string.offline_arrived_station_tip, it),
|
||||
LanguageType.CHINESE
|
||||
)
|
||||
val engTTS = LangTtsEntity(
|
||||
context.getString(R.string.bus_arrived_station_english_tip, it),
|
||||
context.getString(R.string.offline_arrived_station_english_tip, it),
|
||||
LanguageType.ENGLISH
|
||||
)
|
||||
val koreanTTS = LangTtsEntity(
|
||||
context.getString(R.string.bus_arrived_station_korean_tip, siteNameKR?:it),
|
||||
context.getString(R.string.offline_arrived_station_korean_tip, siteNameKR?:it),
|
||||
LanguageType.KOREAN
|
||||
)
|
||||
list.add(chineseTTS)
|
||||
@@ -56,7 +56,7 @@ object ShuttleVoiceManager {
|
||||
val arrivedMsg = AppConnectMsg(
|
||||
isViewShow = false,
|
||||
isPlay = true,
|
||||
msg = ResourcesUtils.getString(R.string.bus_arrived_station_tip,arriveStation),
|
||||
msg = ResourcesUtils.getString(R.string.offline_arrived_station_tip,arriveStation),
|
||||
)
|
||||
LanSocketManager.sendMsgToClient(arrivedMsg)
|
||||
}
|
||||
@@ -66,18 +66,18 @@ object ShuttleVoiceManager {
|
||||
val context = AbsMogoApplication.getApp()
|
||||
siteNameCN?.let {
|
||||
val chineseTTS = LangTtsEntity(
|
||||
context.getString(R.string.bus_leave_station_tip, it),
|
||||
context.getString(R.string.offline_leave_station_tip, it),
|
||||
LanguageType.CHINESE
|
||||
)
|
||||
val engTTS = LangTtsEntity(
|
||||
context.getString(R.string.bus_leave_station_english_tip, it),
|
||||
context.getString(R.string.offline_leave_station_english_tip, it),
|
||||
LanguageType.ENGLISH
|
||||
)
|
||||
list.add(chineseTTS)
|
||||
list.add(engTTS)
|
||||
|
||||
val koreanTTS = LangTtsEntity(
|
||||
context.getString(R.string.bus_leave_station_korean_tip, siteNameKR ?: it),
|
||||
context.getString(R.string.offline_leave_station_korean_tip, siteNameKR ?: it),
|
||||
LanguageType.KOREAN
|
||||
)
|
||||
|
||||
@@ -97,7 +97,7 @@ object ShuttleVoiceManager {
|
||||
val startMsg = AppConnectMsg(
|
||||
isViewShow = false,
|
||||
isPlay = true,
|
||||
msg = ResourcesUtils.getString(R.string.bus_leave_station_tip,nextStation),
|
||||
msg = ResourcesUtils.getString(R.string.offline_leave_station_tip,nextStation),
|
||||
)
|
||||
LanSocketManager.sendMsgToClient(startMsg)
|
||||
}
|
||||
@@ -105,9 +105,9 @@ object ShuttleVoiceManager {
|
||||
fun endOrderBus() {
|
||||
val context = AbsMogoApplication.getApp()
|
||||
val list: MutableList<LangTtsEntity> = ArrayList()
|
||||
val chineseTTS = LangTtsEntity(SkinResources.getInstance().getString(R.string.bus_end_task_tip), LanguageType.CHINESE)
|
||||
val engTTS = LangTtsEntity(context.getString(R.string.bus_end_task_english_tip), LanguageType.ENGLISH)
|
||||
val koreanTTS = LangTtsEntity(context.getString(R.string.bus_end_task_korean_tip), LanguageType.KOREAN)
|
||||
val chineseTTS = LangTtsEntity(SkinResources.getInstance().getString(R.string.offline_end_task_tip), LanguageType.CHINESE)
|
||||
val engTTS = LangTtsEntity(context.getString(R.string.offline_end_task_english_tip), LanguageType.ENGLISH)
|
||||
val koreanTTS = LangTtsEntity(context.getString(R.string.offline_end_task_korean_tip), LanguageType.KOREAN)
|
||||
list.add(chineseTTS)
|
||||
list.add(engTTS)
|
||||
list.add(koreanTTS)
|
||||
@@ -124,7 +124,7 @@ object ShuttleVoiceManager {
|
||||
val endMsg = AppConnectMsg(
|
||||
isViewShow = false,
|
||||
isPlay = true,
|
||||
msg = SkinResources.getInstance().getString(R.string.bus_end_task_tip),
|
||||
msg = SkinResources.getInstance().getString(R.string.offline_end_task_tip),
|
||||
)
|
||||
LanSocketManager.sendMsgToClient(endMsg)
|
||||
}
|
||||
|
||||
@@ -21,4 +21,19 @@
|
||||
|
||||
<string name="m2_voice_out_arrive_station">蘑菇小巴正在进站</string>
|
||||
<string name="m2_voice_out_autopilot_start_in15m">蘑菇小巴出发咯</string>
|
||||
|
||||
|
||||
<!-- region tts -->
|
||||
<string name="offline_arrived_station_tip">已到达%1$s,带好随身物品,下车请注意安全。</string>
|
||||
<string name="offline_arrived_station_english_tip">We are arriving at %1$s ,get off with your belongings</string>
|
||||
<string name="offline_arrived_station_korean_tip">%1$s 역에 도착했습니다 , 소지품 챙겨서 내리세요</string>
|
||||
|
||||
<string name="offline_leave_station_tip">车辆起步,请扶稳坐好,前方到站是%1$s,请下车的乘客做好准备。</string>
|
||||
<string name="offline_leave_station_english_tip">The next station is %1$s ,please get ready for your arrival</string>
|
||||
<string name="offline_leave_station_korean_tip">전방에서 역에 도착하는 %1$s ,차에서 내리는 승객은 준비하세요</string>
|
||||
|
||||
<string name="offline_end_task_tip">感谢您体验\'蘑菇车联\'自动驾驶小巴车,我们下次再见。</string>
|
||||
<string name="offline_end_task_english_tip">Thank you for experiencing the self-driving minibus. See you next time</string>
|
||||
<string name="offline_end_task_korean_tip">자율주행 버스를 체험해 주셔서 감사합니다. 다음에 또 뵙겠습니다</string>
|
||||
<!-- endregion -->
|
||||
</resources>
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.mogo.och.data.db.bean.SiteDataBean
|
||||
import com.mogo.och.weaknet.repository.db.bean.TaskDataBean
|
||||
import com.mogo.och.weaknet.repository.db.bean.TaskSiteDataBean
|
||||
import com.mogo.och.weaknet.repository.db.bean.WriteOffDataBean
|
||||
import com.mogo.och.data.db.dao.ContrailDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.EventDataDao
|
||||
import com.mogo.och.data.db.dao.LineDataDao
|
||||
import com.mogo.och.data.db.dao.SiteDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.ContrailDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.LineDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.SiteDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.TaskDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.TaskSiteDataDao
|
||||
import com.mogo.och.weaknet.repository.db.dao.WriteOffDataDao
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.mogo.och.weaknet.repository.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.mogo.och.data.db.bean.ContrailDataBean
|
||||
|
||||
@Dao
|
||||
interface ContrailDataDao {
|
||||
|
||||
//插入轨迹信息
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg contrailDataBean: ContrailDataBean)
|
||||
|
||||
@Query("UPDATE ${ContrailDataBean.tableName} SET csv_file_url = :csv_file_url ,csv_file_md5 = :csv_file_md5 ,txt_file_url = :txt_file_url " +
|
||||
",txt_file_md5 = :txt_file_md5 ,contrail_save_time = :contrail_save_time,md5 = :md5 WHERE id = :id")
|
||||
fun update(csv_file_url: String,csv_file_md5: String,txt_file_url: String,txt_file_md5: String,contrail_save_time: Long,md5: String,id:Int)
|
||||
|
||||
// 线路删除时同步删除所属轨迹信息
|
||||
@Query("DELETE FROM ${ContrailDataBean.tableName} WHERE line_id = :lineId")
|
||||
fun deleteByLineId(lineId: Long)
|
||||
|
||||
//查询线路对应的轨迹信息
|
||||
@Query("SELECT * FROM ${ContrailDataBean.tableName} WHERE line_id = :lineId")
|
||||
fun queryContrailByLineId(lineId:Long): List<ContrailDataBean>?
|
||||
|
||||
//查询线路对应的轨迹信息
|
||||
@Query("SELECT * FROM ${ContrailDataBean.tableName} WHERE md5 = :md5")
|
||||
fun queryContrailByMd5(md5:String): List<ContrailDataBean>?
|
||||
|
||||
//查询线路对应的轨迹信息 只要一个结果
|
||||
fun queryContrailByLineIdOne(lineId: Long): ContrailDataBean?{
|
||||
val queryContrailByLineId = queryContrailByLineId(lineId)
|
||||
return if(queryContrailByLineId.isNullOrEmpty()){
|
||||
null
|
||||
}else{
|
||||
queryContrailByLineId.first()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.mogo.och.weaknet.repository.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.data.db.bean.LineDataBean
|
||||
import io.reactivex.Observable
|
||||
|
||||
@Dao
|
||||
interface LineDataDao {
|
||||
//插入数据
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg lineDataBean: LineDataBean)
|
||||
|
||||
//删除数据
|
||||
@Delete
|
||||
fun delete(vararg lineDataBean: LineDataBean)
|
||||
|
||||
@Query("UPDATE ${LineDataBean.tableName} SET line_name = :lineName ,end_station_name = :endStationName WHERE id = :id")
|
||||
fun updateInfo(lineName: String?, endStationName: String?, id: Long)
|
||||
|
||||
// 删除过时数据
|
||||
@Query("DELETE FROM ${LineDataBean.tableName} WHERE line_get_time < :zeroTime")
|
||||
fun deleteObsoleteData(zeroTime: Long = DateTimeUtil.getCurrentDateZero()):Int
|
||||
|
||||
|
||||
//删除非昨天添加的数据
|
||||
@Query("DELETE FROM ${LineDataBean.tableName} WHERE line_get_time < :zeroTime")
|
||||
fun deleteWeltData(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): Int
|
||||
|
||||
//查询当天插入的所有数据
|
||||
@Query("SELECT * FROM ${LineDataBean.tableName} WHERE line_get_time > :zeroTime")
|
||||
fun loadDataRx(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): Observable<List<LineDataBean>?>
|
||||
|
||||
//查询当天插入的所有数据
|
||||
@Query("SELECT * FROM ${LineDataBean.tableName} WHERE line_get_time > :zeroTime")
|
||||
fun loadData(zeroTime: Long = DateTimeUtil.getCurrentDateZero()): List<LineDataBean>?
|
||||
|
||||
@Query("SELECT * FROM ${LineDataBean.tableName} WHERE line_id = :lineId")
|
||||
fun queryByLineId(lineId: Int) : List<LineDataBean>?
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.mogo.och.weaknet.repository.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.mogo.och.data.db.bean.SiteDataBean
|
||||
|
||||
@Dao
|
||||
interface SiteDataDao {
|
||||
//插入数据
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(vararg lineDataBean: SiteDataBean)
|
||||
|
||||
@Delete()
|
||||
fun deleteById(vararg siteDataBean: SiteDataBean)
|
||||
|
||||
@Query("UPDATE ${SiteDataBean.tableName} SET site_id = :site_id ,line_id = :lineId,name = :name,name_kr = :nameKr,seq = :seq," +
|
||||
"gcj_lon = :gcjLon,gcj_lat = :gcjLat,lon = :lon,lat = :lat,introduction = :introduction," +
|
||||
"is_play_tts = :isPlayTts,md5 = :md5,videoList = :videoListDB WHERE id = :id")
|
||||
fun updateInfo(site_id: Long?, lineId: Long?, name: String?,nameKr:String?,seq:Int?,
|
||||
gcjLon:Double?, gcjLat:Double?,lon:Double?,lat:Double?,introduction:String?,
|
||||
isPlayTts:Boolean?,md5:String?,videoListDB:String?,id:Int
|
||||
)
|
||||
|
||||
|
||||
// 线路删除时同步删除所属站点
|
||||
@Query("DELETE FROM ${SiteDataBean.tableName} WHERE line_id = :lineId")
|
||||
fun deleteByLineId(lineId: Long)
|
||||
|
||||
//查询线路对应的轨迹信息
|
||||
@Query("SELECT * FROM ${SiteDataBean.tableName} WHERE md5 = :md5")
|
||||
fun querySitesByMd5(md5:String): List<SiteDataBean>?
|
||||
|
||||
//查询线路对应的轨迹信息
|
||||
@Query("SELECT * FROM ${SiteDataBean.tableName}")
|
||||
fun queryAllSites(): List<SiteDataBean>?
|
||||
|
||||
|
||||
@Query("SELECT * FROM ${SiteDataBean.tableName} WHERE line_id = :lineId and site_id = :siteId")
|
||||
fun querySitesByLineIdAndSiteId(lineId: Long,siteId:Long):List<SiteDataBean>?
|
||||
|
||||
@Query("SELECT * FROM ${SiteDataBean.tableName} WHERE line_id = :lineId")
|
||||
fun querySitesByLineId(lineId: Long):List<SiteDataBean>?
|
||||
|
||||
@Query("SELECT * FROM ${SiteDataBean.tableName} GROUP by md5 HAVING count(1) > 1")
|
||||
fun checkData():List<SiteDataBean>?
|
||||
|
||||
fun querySiteByLineIdAndSiteId(lineId: Long,siteId:Long): SiteDataBean?{
|
||||
val queryContrailByLineId = querySitesByLineIdAndSiteId(lineId,siteId)
|
||||
return if(queryContrailByLineId.isNullOrEmpty()){
|
||||
null
|
||||
}else{
|
||||
queryContrailByLineId.first()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.mogo.och.weaknet.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.data.db.bean.ContrailDataBean
|
||||
import com.mogo.och.weaknet.repository.db.IDbRepository
|
||||
import com.mogo.och.weaknet.repository.db.MyDataBase
|
||||
import com.mogo.och.data.db.dao.ContrailDataDao
|
||||
import com.mogo.och.data.db.repository.BaseContraiDb
|
||||
import com.mogo.och.weaknet.repository.db.dao.ContrailDataDao
|
||||
|
||||
object ContraiDb : IDbRepository, BaseContraiDb() {
|
||||
object ContraiDb : IDbRepository {
|
||||
|
||||
override var contrailDao: ContrailDataDao?=null
|
||||
private var contrailDao: ContrailDataDao?=null
|
||||
get() {
|
||||
if(field==null){
|
||||
field = MyDataBase.instance?.contrailDataDao
|
||||
@@ -20,6 +22,57 @@ object ContraiDb : IDbRepository, BaseContraiDb() {
|
||||
contrailDao = null
|
||||
}
|
||||
|
||||
fun addOrUpdate(contrailDatalist:List<ContrailDataBean>){
|
||||
val runnable = Runnable {
|
||||
// 校验数据个数
|
||||
contrailDao?.let { contrailDao->
|
||||
contrailDatalist.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
val queryContrailByMd5 = contrailDao.queryContrailByMd5(md5Hex)
|
||||
if(queryContrailByMd5.isNullOrEmpty()){// 没有值或者值有变化
|
||||
val needUpdate = contrailDao.queryContrailByLineIdOne(it.lineId!!)
|
||||
it.md5 = md5Hex
|
||||
if(needUpdate!=null){// 更新
|
||||
it.id = needUpdate.id
|
||||
contrailDao.update(it.csvFileUrl?:"",it.csvFileMd5?:"",it.txtFileUrl?:"",it.txtFileMd5?:"",System.currentTimeMillis(),md5Hex,needUpdate.id)
|
||||
}else{// 插入新的
|
||||
contrailDao.insert(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BizLoopManager.runInIoThread(runnable)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun deleteByLineId(lineId: Long) {
|
||||
contrailDao?.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
fun queryAutopilotInfoByLineid(lineId: Long): ContrailDataBean? {
|
||||
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))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.mogo.och.weaknet.repository.db.repository
|
||||
|
||||
import androidx.room.Transaction
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.LineDataBean
|
||||
import com.mogo.och.weaknet.repository.db.IDbRepository
|
||||
import com.mogo.och.weaknet.repository.db.MyDataBase
|
||||
import com.mogo.och.data.db.dao.LineDataDao
|
||||
import com.mogo.och.data.db.repository.BaseLineDb
|
||||
import com.mogo.och.weaknet.repository.db.dao.LineDataDao
|
||||
import io.reactivex.Observable
|
||||
|
||||
object LineDb: IDbRepository, BaseLineDb() {
|
||||
object LineDb: IDbRepository {
|
||||
|
||||
override var lineDao: LineDataDao?=null
|
||||
private var lineDao: LineDataDao?=null
|
||||
get() {
|
||||
if(field==null){
|
||||
field = MyDataBase.instance?.lineDataDao
|
||||
@@ -17,19 +20,123 @@ object LineDb: IDbRepository, BaseLineDb() {
|
||||
return field
|
||||
}
|
||||
|
||||
override fun deleteSitesTaskAndContraiDb(lineId: Long) {
|
||||
SiteDb.deleteByLineId(lineId)
|
||||
val runingTask = TaskDb.queryRunningTaskByLineId(lineId)
|
||||
if(runingTask.isNullOrEmpty()){
|
||||
// 删除线路对应的自驾信息
|
||||
ContraiDb.deleteByLineId(lineId)
|
||||
TaskDb.deleteByLineId(lineId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun release() {
|
||||
lineDao = null
|
||||
}
|
||||
|
||||
|
||||
fun cleanWeltData(){
|
||||
lineDao?.deleteWeltData()
|
||||
}
|
||||
|
||||
fun queryCanUserLine(): List<LineDataBean>? {
|
||||
return lineDao?.loadData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取可用线路
|
||||
*/
|
||||
fun queryCanUseLineRx(): Observable<List<LineDataBean>?>? {
|
||||
return lineDao?.loadDataRx()
|
||||
}
|
||||
|
||||
fun checkAndUpdate(serverDatalist:List<LineDataBean>){
|
||||
val runable = object :Runnable{
|
||||
@Transaction
|
||||
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去
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
lineDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
lineDao.delete(*needMinusDatas.toTypedArray())
|
||||
needMinusDatas.forEach { minusLine->
|
||||
minusLine.lineId?.let { lineId->
|
||||
// 删除线路对应的站点
|
||||
SiteDb.deleteByLineId(lineId)
|
||||
val runingTask = TaskDb.queryRunningTaskByLineId(lineId)
|
||||
if(runingTask.isNullOrEmpty()){
|
||||
// 删除线路对应的自驾信息
|
||||
ContraiDb.deleteByLineId(lineId)
|
||||
TaskDb.deleteByLineId(lineId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 交集 服务器端
|
||||
val needUpdateByMd5 = serverDatalist-needAddDatas
|
||||
// 交集 本地数据库
|
||||
val oldDataList = loadData-needMinusDatas
|
||||
|
||||
val needDelete = mutableListOf<LineDataBean>()
|
||||
val needUpDate = mutableListOf<LineDataBean>()
|
||||
|
||||
needUpdateByMd5.forEach {
|
||||
val oldList = oldDataList.filter { local -> local.lineId == it.lineId }
|
||||
if(oldList.isNotEmpty()){
|
||||
oldList.forEachIndexed { index, lineBean ->
|
||||
if(index==0){
|
||||
if (lineBean.lineName == it.lineName && lineBean.endStationName == it.endStationName) {
|
||||
// 数据没有变化
|
||||
}else{
|
||||
it.id = lineBean.id
|
||||
needUpDate.add(it)
|
||||
}
|
||||
}else{
|
||||
// 站点多了 需要删除
|
||||
needDelete.add(lineBean)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lineDao.delete(*needDelete.toTypedArray())
|
||||
|
||||
needUpDate.forEach { updateItem->
|
||||
// 跟新数据
|
||||
lineDao.updateInfo(updateItem.lineName,updateItem.endStationName,updateItem.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BizLoopManager.runInIoThread(runable)
|
||||
}
|
||||
|
||||
fun deleteObsoleteData(){
|
||||
lineDao?.deleteObsoleteData()?.let {
|
||||
OchChainLogManager.writeChainLogDb("删除临时数据","Line删除数量:${it}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有线路就插入线路
|
||||
*/
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package com.mogo.och.weaknet.repository.db.repository
|
||||
|
||||
import androidx.room.Transaction
|
||||
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.TAG
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.data.db.bean.SiteDataBean
|
||||
import com.mogo.och.weaknet.repository.db.IDbRepository
|
||||
import com.mogo.och.weaknet.repository.db.MyDataBase
|
||||
import com.mogo.och.data.db.dao.SiteDataDao
|
||||
import com.mogo.och.data.db.repository.BaseSiteDb
|
||||
import com.mogo.och.weaknet.repository.db.dao.SiteDataDao
|
||||
|
||||
object SiteDb: IDbRepository, BaseSiteDb() {
|
||||
object SiteDb: IDbRepository {
|
||||
|
||||
override var siteDataDao: SiteDataDao? = null
|
||||
private var siteDataDao: SiteDataDao? = null
|
||||
get() {
|
||||
if(field==null){
|
||||
field = MyDataBase.instance?.siteDataDao
|
||||
@@ -20,4 +26,107 @@ object SiteDb: IDbRepository, BaseSiteDb() {
|
||||
siteDataDao = null
|
||||
}
|
||||
|
||||
fun addOrUpdate(serverDataList: List<SiteDataBean>) {
|
||||
val runnable = object :Runnable {
|
||||
@Transaction
|
||||
override fun run() {
|
||||
siteDataDao?.let { siteDataDao ->
|
||||
val localAllSites = siteDataDao.queryAllSites()
|
||||
if (localAllSites.isNullOrEmpty()) {
|
||||
// 插入新数据
|
||||
siteDataDao.insert(*serverDataList.toTypedArray())
|
||||
return
|
||||
}
|
||||
// 后台新增数据
|
||||
val needAddDatas = serverDataList-localAllSites
|
||||
// 后台没有本地数据库有的未分配线路
|
||||
val needMinusDatas = localAllSites - serverDataList
|
||||
|
||||
if (needAddDatas.isNotEmpty()) {
|
||||
// 新增线路
|
||||
needAddDatas.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
it.md5 = md5Hex
|
||||
}
|
||||
// 新增插入新数据
|
||||
siteDataDao.insert(*needAddDatas.toTypedArray())
|
||||
}
|
||||
|
||||
if (needMinusDatas.isNotEmpty()) {
|
||||
// 删除线路
|
||||
siteDataDao.deleteById(*needMinusDatas.toTypedArray())
|
||||
}
|
||||
|
||||
// 交集 服务器端
|
||||
val needUpdateByMd5 = serverDataList-needAddDatas
|
||||
// 交集 本地数据库
|
||||
val oldDataList = localAllSites-needMinusDatas
|
||||
|
||||
val needDelete = mutableListOf<SiteDataBean>()
|
||||
val needUpDate = mutableListOf<SiteDataBean>()
|
||||
|
||||
|
||||
needUpdateByMd5.forEach {
|
||||
val md5Source = it.toString()
|
||||
val md5Hex = DigestUtils.md5Hex(md5Source)
|
||||
val oldList =
|
||||
oldDataList.filter { local -> local.siteId == it.siteId && local.lineId == it.lineId }
|
||||
if(oldList.isNotEmpty()){
|
||||
oldList.forEachIndexed { index, siteDataBean ->
|
||||
if(index==0){
|
||||
if (siteDataBean.md5 == md5Hex) {
|
||||
// 数据没有变化
|
||||
}else{
|
||||
it.id = siteDataBean.id
|
||||
it.md5 = md5Hex
|
||||
needUpDate.add(it)
|
||||
|
||||
}
|
||||
}else{
|
||||
needDelete.add(siteDataBean)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
needUpDate.forEach {updateDateItem->
|
||||
siteDataDao.updateInfo(updateDateItem.siteId,updateDateItem.lineId,updateDateItem.name,updateDateItem.nameKr,
|
||||
updateDateItem.seq,updateDateItem.gcjLon,updateDateItem.gcjLat,updateDateItem.lon,updateDateItem.lat,
|
||||
updateDateItem.introduction,updateDateItem.isPlayTts,updateDateItem.md5,updateDateItem.videoListDB,updateDateItem.id)
|
||||
}
|
||||
siteDataDao.deleteById(*needDelete.toTypedArray())
|
||||
checkData()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BizLoopManager.runInIoThread(runnable)
|
||||
}
|
||||
|
||||
fun checkData() {
|
||||
CallerLogger.d(TAG,"检测站点数据")
|
||||
siteDataDao?.checkData()?.let { list ->
|
||||
list.forEach {
|
||||
siteDataDao?.deleteById(it)
|
||||
}
|
||||
if (list.isNotEmpty()) {
|
||||
OchChainLogManager.writeChainLogDb("数据检测", "有重复数据${list}")
|
||||
checkData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteByLineId(lineId: Long) {
|
||||
siteDataDao?.deleteByLineId(lineId)
|
||||
}
|
||||
|
||||
fun querySiteByLineId(lineId:Long):List<SiteDataBean>?{
|
||||
siteDataDao?.let { siteDataDao->
|
||||
return siteDataDao.querySitesByLineId(lineId)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class TaskRunningAdapter(
|
||||
|
||||
private val argbEvaluator: ArgbEvaluator = ArgbEvaluator()
|
||||
private val startColor = ResourcesUtils.getColor(R.color.shuttle_driver_1970FF)
|
||||
private val endColor = ResourcesUtils.getColor(R.color.shuttle_driver_19FF7F)
|
||||
private val endColor = ResourcesUtils.getColor(R.color.common_19FF7F)
|
||||
private val heightItem = 100f
|
||||
private val halfHeight = 16.5f
|
||||
private var totalHeight = 0f
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<com.mogo.och.offline.ui.switchline.SwitchLineView
|
||||
<com.mogo.och.weaknet.ui.switchline.SwitchLineView
|
||||
android:id="@+id/swtichLine"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
@@ -61,7 +61,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<com.mogo.och.offline.ui.taskrunning.TaskRunningView
|
||||
<com.mogo.och.weaknet.ui.taskrunning.TaskRunningView
|
||||
android:id="@+id/taskRunning"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
|
||||
Reference in New Issue
Block a user