Conflicts:
	app/src/main/java/com/navinfo/omqs/db/ImportOMDBHelper.kt
	app/src/main/java/com/navinfo/omqs/db/ImportPreProcess.kt
This commit is contained in:
qiji4215 2023-10-30 10:34:42 +08:00
commit db2ecd45be
11 changed files with 1521 additions and 1547 deletions

View File

@ -83,6 +83,7 @@
"name": "车道边界类型", "name": "车道边界类型",
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"isDependOnOtherTable": true,
"checkLinkId": false, "checkLinkId": false,
"filterData": true, "filterData": true,
"catch": true, "catch": true,
@ -125,11 +126,6 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
}, },
"2097":{
"table": "OMDB_PHY_LANENUM",
"code": 2097,
"name": "物理车道数"
},
"2083": { "2083": {
"table": "OMDB_RDBOUND_BOUNDARYTYPE", "table": "OMDB_RDBOUND_BOUNDARYTYPE",
"code": 2083, "code": 2083,
@ -145,7 +141,6 @@
"code": 2090, "code": 2090,
"name": "车道施工", "name": "车道施工",
"existSubCode": true, "existSubCode": true,
"checkLinkId": false,
"catch": true, "catch": true,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20 "zoomMax": 20
@ -155,6 +150,7 @@
"code": 2092, "code": 2092,
"name": "车道类型", "name": "车道类型",
"catch": true, "catch": true,
"isDependOnOtherTable": true,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -166,12 +162,18 @@
} }
] ]
}, },
"2097": {
"table": "OMDB_PHY_LANENUM",
"code": 2097,
"name": "物理车道数"
},
"2201": { "2201": {
"table": "OMDB_BRIDGE", "table": "OMDB_BRIDGE",
"code": 2201, "code": 2201,
"name": "桥", "name": "桥",
"catch": true, "catch": true,
"existSubCode": true, "existSubCode": true,
"isDependOnOtherTable": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -348,6 +350,7 @@
"code": 4001, "code": 4001,
"name": "路口", "name": "路口",
"zoomMin": 15, "zoomMin": 15,
"isDependOnOtherTable": true,
"zoomMax": 17, "zoomMax": 17,
"catch": true, "catch": true,
"transformer": [ "transformer": [
@ -449,6 +452,7 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"filterData": true, "filterData": true,
"isDependOnOtherTable": true,
"catch": true, "catch": true,
"transformer": [ "transformer": [
{ {
@ -488,6 +492,7 @@
"code": 4009, "code": 4009,
"name": "警示信息", "name": "警示信息",
"catch": true, "catch": true,
"isDependOnOtherTable": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -576,6 +581,7 @@
"code": 4601, "code": 4601,
"name": "车信", "name": "车信",
"catch": true, "catch": true,
"isDependOnOtherTable": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"transformer": [ "transformer": [
@ -604,6 +610,7 @@
"code": 5001, "code": 5001,
"name": "车道中心线", "name": "车道中心线",
"catch": false, "catch": false,
"isDependOnOtherTable": true,
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
@ -686,7 +693,6 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
} }
} }
} }
] ]

View File

@ -20,14 +20,12 @@ class ImportConfig {
@Expose @Expose
var checked: Boolean = true var checked: Boolean = true
val preProcess: ImportPreProcess = ImportPreProcess() val preProcess: ImportPreProcess = ImportPreProcess()
fun transformProperties(renderEntity: RenderEntity, realm: Realm): RenderEntity? { fun transformProperties(renderEntity: RenderEntity, realm: Realm?): RenderEntity? {
preProcess.realm = realm preProcess.realm = realm
val transformList = tableMap[renderEntity.code.toString()]?.transformer val transformList = tableMap[renderEntity.code.toString()]?.transformer
if (transformList.isNullOrEmpty()) { if (transformList.isNullOrEmpty()) {
Log.e("qj", "子表转换为空===${renderEntity.code}")
return renderEntity return renderEntity
} }
Log.e("qj", "子表转换不为空===${renderEntity.code}")
for (transform in transformList) { for (transform in transformList) {
// 开始执行转换 // 开始执行转换
val key: String = transform.k val key: String = transform.k
@ -144,7 +142,7 @@ class TableInfo {
val checkLinkId: Boolean = true//是否需要校验linkid val checkLinkId: Boolean = true//是否需要校验linkid
val filterData: Boolean = false//是否需要过滤数据 val filterData: Boolean = false//是否需要过滤数据
val existSubCode: Boolean = false//是否存在子编码 val existSubCode: Boolean = false//是否存在子编码
val isDependOnOtherTable = false//是否依赖其他表
val catch: Boolean = val catch: Boolean =
false//是否需要捕捉 // 需要根据丹丹提供的捕捉原则进行设置参考文档W行设置条件https://navinfo.feishu.cn/sheets/shtcnfsxKZhekU26ezBcHgl7aWh?sheet=BZd6yM false//是否需要捕捉 // 需要根据丹丹提供的捕捉原则进行设置参考文档W行设置条件https://navinfo.feishu.cn/sheets/shtcnfsxKZhekU26ezBcHgl7aWh?sheet=BZd6yM
val name: String = "" val name: String = ""

View File

@ -2,24 +2,19 @@ package com.navinfo.omqs.db
import android.content.Context import android.content.Context
import android.database.Cursor.* import android.database.Cursor.*
import android.os.Build
import android.provider.ContactsContract.Data
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import com.blankj.utilcode.util.FileIOUtils
import com.blankj.utilcode.util.ZipUtils import com.blankj.utilcode.util.ZipUtils
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.data.entity.* import com.navinfo.collect.library.data.entity.*
import com.navinfo.collect.library.enums.DataCodeEnum import com.navinfo.collect.library.enums.DataCodeEnum
import com.navinfo.collect.library.utils.DeflaterUtil
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.StrZipUtil import com.navinfo.collect.library.utils.StrZipUtil
import com.navinfo.omqs.Constant import com.navinfo.omqs.Constant
import com.navinfo.omqs.Constant.Companion.currentInstallTaskConfig import com.navinfo.omqs.Constant.Companion.currentInstallTaskConfig
import com.navinfo.omqs.Constant.Companion.currentInstallTaskFolder import com.navinfo.omqs.Constant.Companion.currentInstallTaskFolder
import com.navinfo.omqs.Constant.Companion.installTaskid import com.navinfo.omqs.Constant.Companion.installTaskid
import com.navinfo.omqs.bean.ImportConfig import com.navinfo.omqs.bean.ImportConfig
import com.navinfo.omqs.bean.TableInfo
import com.navinfo.omqs.db.deep.LinkList import com.navinfo.omqs.db.deep.LinkList
import com.navinfo.omqs.hilt.OMDBDataBaseHiltFactory import com.navinfo.omqs.hilt.OMDBDataBaseHiltFactory
import com.navinfo.omqs.util.CMLog import com.navinfo.omqs.util.CMLog
@ -27,23 +22,19 @@ import dagger.assisted.Assisted
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.*
import kotlinx.coroutines.delay import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.withContext import kotlinx.coroutines.sync.Mutex
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.GeometryFactory
import org.locationtech.jts.geom.LineString
import org.locationtech.jts.geom.MultiLineString
import org.spatialite.database.SQLiteDatabase import org.spatialite.database.SQLiteDatabase
import java.io.BufferedReader import java.io.BufferedReader
import java.io.File import java.io.File
import java.io.FileReader import java.io.FileReader
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
import kotlin.collections.HashMap
import kotlin.streams.toList
/** /**
* 导入omdb数据的帮助类 * 导入omdb数据的帮助类
@ -56,11 +47,12 @@ class ImportOMDBHelper @AssistedInject constructor(
@Inject @Inject
lateinit var gson: Gson lateinit var gson: Gson
private val database by lazy {
omdbHiltFactory.obtainOmdbDataBaseHelper( // private val database by lazy {
context, omdbFile.absolutePath, 1 // omdbHiltFactory.obtainOmdbDataBaseHelper(
).writableDatabase // context, omdbFile.absolutePath, 1
} // ).writableDatabase
// }
private val configFile: File = File("${Constant.USER_DATA_PATH}", Constant.OMDB_CONFIG) private val configFile: File = File("${Constant.USER_DATA_PATH}", Constant.OMDB_CONFIG)
private val importConfigList by lazy { private val importConfigList by lazy {
@ -82,90 +74,94 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
} }
/** // /**
* 读取指定数据表的数据集 // * 读取指定数据表的数据集
* */ // * */
@RequiresApi(Build.VERSION_CODES.N) // @RequiresApi(Build.VERSION_CODES.N)
suspend fun getOMDBTableData(table: String): Flow<List<Map<String, Any>>> = // suspend fun getOMDBTableData(table: String): Flow<List<Map<String, Any>>> =
withContext(Dispatchers.IO) { // withContext(Dispatchers.IO) {
val listResult: MutableList<Map<String, Any>> = mutableListOf() // val listResult: MutableList<Map<String, Any>> = mutableListOf()
flow<List<Map<String, Any>>> { // flow<List<Map<String, Any>>> {
if (database.isOpen) { // if (database.isOpen) {
val comumns = mutableListOf<String>() // val comumns = mutableListOf<String>()
// 获取要读取的列名 // // 获取要读取的列名
val columns = getColumns(database, table) // val columns = getColumns(database, table)
// 处理列名如果列名是GEOMETRY则使用spatialite函数ST_AsText读取blob数据 // // 处理列名如果列名是GEOMETRY则使用spatialite函数ST_AsText读取blob数据
val finalColumns = columns.stream().map { // val finalColumns = columns.stream().map {
val column = it.replace("\"", "", true) // val column = it.replace("\"", "", true)
if ("GEOMETRY".equals(column, ignoreCase = true)) { // if ("GEOMETRY".equals(column, ignoreCase = true)) {
"ST_AsText($column)" // "ST_AsText($column)"
} else { // } else {
column // column
} // }
}.toList() // }.toList()
//
// val cursor = database.query(
// table,
// finalColumns.toTypedArray(),
// "1=1",
// mutableListOf<String>().toTypedArray(),
// null,
// null,
// null,
// null
// )
// with(cursor) {
// if (moveToFirst()) {
// while (moveToNext()) {
// val rowMap = mutableMapOf<String, Any>()
// for (columnIndex in 0 until columnCount) {
// var columnName = getColumnName(columnIndex)
// if (columnName.startsWith("ST_AsText(")) {
// columnName = columnName.replace("ST_AsText(", "")
// .substringBeforeLast(")")
// }
// when (getType(columnIndex)) {
// FIELD_TYPE_NULL -> rowMap[columnName] = ""
// FIELD_TYPE_INTEGER -> rowMap[columnName] =
// getInt(columnIndex)
//
// FIELD_TYPE_FLOAT -> rowMap[columnName] =
// getFloat(columnIndex)
//
// FIELD_TYPE_BLOB -> rowMap[columnName] =
// String(getBlob(columnIndex), Charsets.UTF_8)
//
// else -> rowMap[columnName] = getString(columnIndex)
// }
// }
// listResult.add(rowMap)
// }
// }
// }
// emit(listResult)
// cursor.close()
// }
// }
// }
val cursor = database.query(
table,
finalColumns.toTypedArray(),
"1=1",
mutableListOf<String>().toTypedArray(),
null,
null,
null,
null
)
with(cursor) {
if (moveToFirst()) {
while (moveToNext()) {
val rowMap = mutableMapOf<String, Any>()
for (columnIndex in 0 until columnCount) {
var columnName = getColumnName(columnIndex)
if (columnName.startsWith("ST_AsText(")) {
columnName = columnName.replace("ST_AsText(", "")
.substringBeforeLast(")")
}
when (getType(columnIndex)) {
FIELD_TYPE_NULL -> rowMap[columnName] = ""
FIELD_TYPE_INTEGER -> rowMap[columnName] =
getInt(columnIndex)
FIELD_TYPE_FLOAT -> rowMap[columnName] =
getFloat(columnIndex)
FIELD_TYPE_BLOB -> rowMap[columnName] =
String(getBlob(columnIndex), Charsets.UTF_8)
else -> rowMap[columnName] = getString(columnIndex)
}
}
listResult.add(rowMap)
}
}
}
emit(listResult)
cursor.close()
}
}
}
/** /**
* 从zip文件中导入数据到Realm中 * 从zip文件中导入数据到Realm中
* @param omdbZipFile omdb数据抽取生成的Zip文件 * @param omdbZipFile omdb数据抽取生成的Zip文件
* @param configFile 对应的配置文件 * @param configFile 对应的配置文件
* */ * */
suspend fun importOmdbZipFile(omdbZipFile: File, task: TaskBean): Flow<String> = suspend fun importOmdbZipFile(
withContext(Dispatchers.IO) { omdbZipFile: File, task: TaskBean, scope: CoroutineScope
): Boolean {
val channel = Channel<List<RenderEntity>>(Channel.RENDEZVOUS)
installTaskid = task.id.toString() installTaskid = task.id.toString()
currentInstallTaskFolder = File(Constant.USER_DATA_PATH + "/$installTaskid") currentInstallTaskFolder = File(Constant.USER_DATA_PATH + "/$installTaskid")
if (!currentInstallTaskFolder.exists()) currentInstallTaskFolder.mkdirs() if (!currentInstallTaskFolder.exists()) currentInstallTaskFolder.mkdirs()
currentInstallTaskConfig = currentInstallTaskConfig =
RealmConfiguration.Builder().directory(currentInstallTaskFolder).name("OMQS.realm") RealmConfiguration.Builder().directory(currentInstallTaskFolder)
.name("OMQS.realm")
.encryptionKey(Constant.PASSWORD) .encryptionKey(Constant.PASSWORD)
// .allowQueriesOnUiThread(true) // .allowQueriesOnUiThread(true)
.schemaVersion(2).build() .schemaVersion(2).build()
val unZipFolder = File(omdbZipFile.parentFile, "result")
flow { val unZipFolder = File(omdbZipFile.parentFile, "result")
if (unZipFolder.exists()) { if (unZipFolder.exists()) {
unZipFolder.deleteRecursively() unZipFolder.deleteRecursively()
} }
@ -175,20 +171,7 @@ class ImportOMDBHelper @AssistedInject constructor(
// 先获取当前配置的所有图层的个数,方便后续计算数据解析进度 // 先获取当前配置的所有图层的个数,方便后续计算数据解析进度
var tableNum = 0 var tableNum = 0
var processIndex = 0 var processIndex = 0
//下载数据统计
var dataIndex = 0
//数据库插入的统计
var insertIndex = 0
//单个表要素统计
var elementIndex = 0
//单个表要素时间统计
// var tableImportTime = System.currentTimeMillis()
//总表要素统计时间
// var dataImportTime = System.currentTimeMillis()
// Realm.compactRealm(currentInstallTaskConfig)
var realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction()
for (importConfig in importConfigList) { for (importConfig in importConfigList) {
tableNum += importConfig.tableMap.size tableNum += importConfig.tableMap.size
} }
@ -202,53 +185,113 @@ class ImportOMDBHelper @AssistedInject constructor(
// lineList[index] = GeometryTools.createGeometry(it.geometry) as LineString // lineList[index] = GeometryTools.createGeometry(it.geometry) as LineString
// index++ // index++
} }
//需要关联查询的表
val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap val listDependOnEntry =
val listRenderEntity = mutableListOf<RenderEntity>() mutableMapOf<MutableMap.MutableEntry<String, TableInfo>, ImportConfig>()
//协程池
val listJob = mutableListOf<Job>()
try { try {
// var multipLine = MultiLineString(lineList, GeometryFactory())
// 遍历解压后的文件,读取该数据返回
// Log.d("ImportOMDBHelper", "表解析===开始时间$dataImportTime===")
CMLog.writeLogtoFile(
ImportOMDBHelper::class.java.name,
"importOmdbZipFile",
"开始"
)
for (importConfig in importConfigList) { for (importConfig in importConfigList) {
for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) { for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) {
processIndex += 1 if (currentEntry.value.isDependOnOtherTable) {
listDependOnEntry[currentEntry] = importConfig
val currentConfig = currentEntry.value continue
}
CMLog.writeLogtoFile( val job = scope.launch(Dispatchers.IO) {
ImportOMDBHelper::class.java.name, importData(
"importOmdbZipFile", channel,
"${currentConfig.table}开始" unZipFiles,
currentEntry,
task,
importConfig,
hashMap
) )
}
listJob.add(job)
}
}
val channelJob = scope.launch(Dispatchers.IO) {
val iterator = channel.iterator()
while (iterator.hasNext()) {
val next = iterator.next()
val realm = Realm.getInstance(currentInstallTaskConfig)
realm.executeTransaction {
it.copyToRealm(next)
}
realm.close()
}
}
listJob.joinAll()
channel.close()
channelJob.join()
Log.e("jingo", "channel close 等待结束")
for ((currentEntry, importConfig) in listDependOnEntry) {
importData(
channel,
unZipFiles,
currentEntry,
task,
importConfig,
hashMap,
false
)
}
Log.e("jingo", "安装结束")
} catch (e: Exception) {
Log.e("jingo", "安装报错1 ${e.message}")
return false
}
return true
}
private suspend fun importData(
f: Channel<List<RenderEntity>>,
unZipFiles: List<File>,
currentEntry: MutableMap.MutableEntry<String, TableInfo>,
task: TaskBean,
importConfig: ImportConfig,
hashMap: HashMap<Long, HadLinkDvoBean>,
isEmit: Boolean = true
) {
val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap
var listRenderEntity = mutableListOf<RenderEntity>()
//单个表要素统计
var elementIndex = 0
val currentConfig = currentEntry.value
// CMLog.writeLogtoFile(
// ImportOMDBHelper::class.java.name,
// "importOmdbZipFile",
// "${currentConfig.table}开始"
// )
try {
var realm: Realm? = null
if (!isEmit) {
realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction()
}
val txtFile = unZipFiles.find { val txtFile = unZipFiles.find {
it.name == currentConfig.table it.name == currentConfig.table
} }
Log.e("qj", "开始遍历文件==${currentConfig.table}")
if (txtFile != null && txtFile.exists()) { if (txtFile != null && txtFile.exists()) {
try {
Log.e("qj", "开始遍历文件1")
val fileReader = FileReader(txtFile) val fileReader = FileReader(txtFile)
val bufferedReader = BufferedReader(fileReader) val bufferedReader = BufferedReader(fileReader)
var line: String? = bufferedReader.readLine() var line: String? = bufferedReader.readLine()
var time = System.currentTimeMillis()
var newTime = 0L
while (line != null) { while (line != null) {
if (line == null || line.trim() == "") { if (line == null || line.trim() == "") {
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
newTime = System.currentTimeMillis()
Log.e(
"jingo",
"安装数据 ${currentConfig.table} $elementIndex ${listRenderEntity.size} ${newTime - time}"
)
time = newTime
elementIndex += 1 elementIndex += 1
dataIndex += 1
val map = gson.fromJson<Map<String, Any>>( val map = gson.fromJson<Map<String, Any>>(
line, object : TypeToken<Map<String, Any>>() {}.type line, object : TypeToken<Map<String, Any>>() {}.type
).toMutableMap() ).toMutableMap()
@ -270,54 +313,40 @@ class ImportOMDBHelper @AssistedInject constructor(
// 在外层记录当前数据的linkPid // 在外层记录当前数据的linkPid
if (map.containsKey("linkPid")) { if (map.containsKey("linkPid")) {
renderEntity.linkPid = renderEntity.linkPid = map["linkPid"].toString().split(",")[0]
map["linkPid"].toString().split(",")[0]
} else if (map.containsKey("linkList")) { } else if (map.containsKey("linkList")) {
val linkList = map["linkList"].toString() val linkList = map["linkList"].toString()
if (!linkList.isNullOrEmpty() && linkList != "null") { if (!linkList.isNullOrEmpty() && linkList != "null") {
val list: List<LinkList> = gson.fromJson( val list: List<LinkList> = gson.fromJson(
linkList, linkList, object : TypeToken<List<LinkList>>() {}.type
object : TypeToken<List<LinkList>>() {}.type
) )
renderEntity.linkPid = list[0].linkPid renderEntity.linkPid = list[0].linkPid
} }
} }
Log.e(
"jingo",
"安装数据 ${renderEntity.table} ${renderEntity.linkPid} $elementIndex $insertIndex"
)
renderEntity.geometry = map["geometry"].toString() renderEntity.geometry = map["geometry"].toString()
Log.e("jingo", "map解析开始")
for ((key, value) in map) { for ((key, value) in map) {
when (value) { when (value) {
is String -> renderEntity.properties[key] = value is String -> renderEntity.properties[key] = value
is Int -> renderEntity.properties[key] = is Int -> renderEntity.properties[key] = value.toInt().toString()
value.toInt().toString()
is Double -> renderEntity.properties[key] = is Double -> renderEntity.properties[key] =
value.toDouble().toString() value.toDouble().toString()
else -> renderEntity.properties[key] = else -> renderEntity.properties[key] = value.toString()
value.toString()
} }
} }
// 如果properties中不包含name那么自动将要素名称添加进properties中 // 如果properties中不包含name那么自动将要素名称添加进properties中
if (!renderEntity.properties.containsKey("name")) { if (!renderEntity.properties.containsKey("name")) {
renderEntity.properties["name"] = renderEntity.name; renderEntity.properties["name"] = renderEntity.name;
} }
Log.e("jingo", "map解析结束")
if (currentConfig.filterData) { if (currentConfig.filterData) {
when (renderEntity.code.toInt()) { when (renderEntity.code.toInt()) {
DataCodeEnum.OMDB_POLE.code.toInt() -> { DataCodeEnum.OMDB_POLE.code.toInt() -> {
//过滤树类型的杆状物,无需导入到数据库中 //过滤树类型的杆状物,无需导入到数据库中
val poleType = val poleType = renderEntity.properties["poleType"]
renderEntity.properties["poleType"]
if (poleType != null && poleType.toInt() == 2) { if (poleType != null && poleType.toInt() == 2) {
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
@ -325,8 +354,7 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
DataCodeEnum.OMDB_LANE_MARK_BOUNDARYTYPE.code.toInt() -> { DataCodeEnum.OMDB_LANE_MARK_BOUNDARYTYPE.code.toInt() -> {
val boundaryType = val boundaryType = renderEntity.properties["boundaryType"]
renderEntity.properties["boundaryType"]
if (boundaryType != null) { if (boundaryType != null) {
when (boundaryType.toInt()) { when (boundaryType.toInt()) {
0, 1, 6, 8, 9 -> { 0, 1, 6, 8, 9 -> {
@ -339,8 +367,7 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
DataCodeEnum.OMDB_RDBOUND_BOUNDARYTYPE.code.toInt() -> { DataCodeEnum.OMDB_RDBOUND_BOUNDARYTYPE.code.toInt() -> {
val boundaryType = val boundaryType = renderEntity.properties["boundaryType"]
renderEntity.properties["boundaryType"]
if (boundaryType != null) { if (boundaryType != null) {
when (boundaryType.toInt()) { when (boundaryType.toInt()) {
0, 1, 3, 4, 5, 7, 9 -> { 0, 1, 3, 4, 5, 7, 9 -> {
@ -353,8 +380,7 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
DataCodeEnum.OMDB_OBJECT_STOPLOCATION.code.toInt() -> { DataCodeEnum.OMDB_OBJECT_STOPLOCATION.code.toInt() -> {
val locationType = val locationType = renderEntity.properties["locationType"]
renderEntity.properties["locationType"]
if (locationType != null) { if (locationType != null) {
when (locationType.toInt()) { when (locationType.toInt()) {
3, 4 -> { 3, 4 -> {
@ -371,10 +397,8 @@ class ImportOMDBHelper @AssistedInject constructor(
"linkOut" "linkOut"
) )
) { ) {
val linkIn = val linkIn = renderEntity.properties["linkIn"]
renderEntity.properties["linkIn"] val linkOut = renderEntity.properties["linkOut"]
val linkOut =
renderEntity.properties["linkOut"]
if (linkIn != null && linkOut != null) { if (linkIn != null && linkOut != null) {
val checkMsg = "$linkIn$linkOut" val checkMsg = "$linkIn$linkOut"
if (resHashMap.containsKey(checkMsg)) { if (resHashMap.containsKey(checkMsg)) {
@ -396,7 +420,6 @@ class ImportOMDBHelper @AssistedInject constructor(
val currentLinkPid = renderEntity.linkPid val currentLinkPid = renderEntity.linkPid
if (!currentLinkPid.isNullOrEmpty() && currentLinkPid != "null") { if (!currentLinkPid.isNullOrEmpty() && currentLinkPid != "null") {
val list = currentLinkPid.split(",") val list = currentLinkPid.split(",")
@ -419,15 +442,11 @@ class ImportOMDBHelper @AssistedInject constructor(
if (renderEntity.properties["linkList"] != null) { if (renderEntity.properties["linkList"] != null) {
val linkList = val linkList = renderEntity.properties["linkList"]
renderEntity.properties["linkList"]
if (!linkList.isNullOrEmpty() && linkList != "null") { if (!linkList.isNullOrEmpty() && linkList != "null") {
val list: List<LinkList> = gson.fromJson( val list: List<LinkList> = gson.fromJson(
linkList, linkList, object : TypeToken<List<LinkList>>() {}.type
object :
TypeToken<List<LinkList>>() {}.type
) )
m@ for (link in list) { m@ for (link in list) {
@ -459,15 +478,16 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.catchEnable = 0 renderEntity.catchEnable = 0
} }
var resultEntity = importConfig.transformProperties(renderEntity, realm) // 对renderEntity做预处理后再保存
val resultEntity = importConfig.transformProperties(renderEntity, realm)
if (resultEntity != null) { if (resultEntity != null) {
//对code编码需要特殊处理 存在多个属性值时渲染优先级SA>PA,存在多个属性值时渲染优先级FRONTAGE>MAIN_SIDE_A CCESS
if (currentConfig.existSubCode) { if (currentConfig.existSubCode) {
when (renderEntity.code.toInt()) { when (renderEntity.code.toInt()) {
DataCodeEnum.OMDB_LINK_ATTRIBUTE.code.toInt() -> { DataCodeEnum.OMDB_LINK_ATTRIBUTE.code.toInt() -> {
var type = renderEntity.properties["sa"]
var type = renderEntity.properties["sa"]
if (type != null && type == "1") { if (type != null && type == "1") {
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_LINK_ATTRIBUTE_SA.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_SA.code
@ -477,16 +497,14 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_LINK_ATTRIBUTE_PA.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_PA.code
} else { } else {
type = type = renderEntity.properties["frontage"]
renderEntity.properties["frontage"]
if (type != null && type == "1") { if (type != null && type == "1") {
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_LINK_ATTRIBUTE_FORNTAGE.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_FORNTAGE.code
renderEntity.zoomMin = 15 renderEntity.zoomMin = 15
renderEntity.zoomMax = 17 renderEntity.zoomMax = 17
} else { } else {
type = type = renderEntity.properties["mainSideAccess"]
renderEntity.properties["mainSideAccess"]
if (type != null && type == "1") { if (type != null && type == "1") {
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_LINK_ATTRIBUTE_MAIN_SIDE_ACCESS.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_MAIN_SIDE_ACCESS.code
@ -496,8 +514,7 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.enable = 0 renderEntity.enable = 0
renderEntity.zoomMin = 15 renderEntity.zoomMin = 15
renderEntity.zoomMax = 17 renderEntity.zoomMax = 17
line = line = bufferedReader.readLine()
bufferedReader.readLine()
continue continue
} }
} }
@ -509,18 +526,16 @@ class ImportOMDBHelper @AssistedInject constructor(
when (renderEntity.properties["bridgeType"]) { when (renderEntity.properties["bridgeType"]) {
"1" -> renderEntity.code = "1" -> renderEntity.code =
DataCodeEnum.OMDB_BRIDGE_1.code DataCodeEnum.OMDB_BRIDGE_1.code
"2" -> renderEntity.code = "2" -> renderEntity.code =
DataCodeEnum.OMDB_BRIDGE_2.code DataCodeEnum.OMDB_BRIDGE_2.code
// "3" -> renderEntity.code = DataCodeEnum.OMDB_BRIDGE_3.code
else -> DataCodeEnum.OMDB_BRIDGE.code else -> DataCodeEnum.OMDB_BRIDGE.code
} }
} }
DataCodeEnum.OMDB_RAMP.code.toInt() -> { DataCodeEnum.OMDB_RAMP.code.toInt() -> {
//*匝道*//* /*匝道*/
val formWay = val formWay = renderEntity.properties["formOfWay"]
renderEntity.properties["formOfWay"]
if (formWay != null) { if (formWay != null) {
when (formWay.toInt()) { when (formWay.toInt()) {
93 -> renderEntity.code = 93 -> renderEntity.code =
@ -548,9 +563,8 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
DataCodeEnum.OMDB_LINK_FORM1.code.toInt() -> { DataCodeEnum.OMDB_LINK_FORM1.code.toInt() -> {
//*道路形态1*//* /*道路形态1*/
val formWay = val formWay = renderEntity.properties["formOfWay"]
renderEntity.properties["formOfWay"]
if (formWay != null) { if (formWay != null) {
when (formWay.toInt()) { when (formWay.toInt()) {
35 -> renderEntity.code = 35 -> renderEntity.code =
@ -566,9 +580,8 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
DataCodeEnum.OMDB_LINK_FORM2.code.toInt() -> { DataCodeEnum.OMDB_LINK_FORM2.code.toInt() -> {
//*道路形态2*//* /*道路形态2*/
val formWay = val formWay = renderEntity.properties["formOfWay"]
renderEntity.properties["formOfWay"]
if (formWay != null) { if (formWay != null) {
when (formWay.toInt()) { when (formWay.toInt()) {
10 -> renderEntity.code = 10 -> renderEntity.code =
@ -615,35 +628,29 @@ class ImportOMDBHelper @AssistedInject constructor(
DataCodeEnum.OMDB_LANE_CONSTRUCTION.code.toInt() -> { DataCodeEnum.OMDB_LANE_CONSTRUCTION.code.toInt() -> {
//特殊处理空数据,渲染原则使用 //特殊处理空数据,渲染原则使用
val startTime = val startTime = renderEntity.properties["startTime"]
renderEntity.properties["startTime"]
if (startTime == null || startTime == "") { if (startTime == null || startTime == "") {
renderEntity.properties["startTime"] = renderEntity.properties["startTime"] = "null"
"null"
} }
} }
} }
if (renderEntity.table == DataCodeEnum.OMDB_NODE_FORM.name) {//特殊处理因为code相同使用表名判断 if (renderEntity.table == DataCodeEnum.OMDB_NODE_FORM.name) {//特殊处理因为code相同使用表名判断
//过滤不需要渲染的要素 //过滤不需要渲染的要素
val formOfWay = val formOfWay = renderEntity.properties["formOfWay"]
renderEntity.properties["formOfWay"]
if (formOfWay != null && formOfWay.toInt() == 30) { if (formOfWay != null && formOfWay.toInt() == 30) {
renderEntity.enable = 2 renderEntity.enable = 2
renderEntity.code = renderEntity.code = DataCodeEnum.OMDB_NODE_FORM.code
DataCodeEnum.OMDB_NODE_FORM.code
} else { } else {
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
} else if (renderEntity.table == DataCodeEnum.OMDB_NODE_PA.name) {//特殊处理因为code相同使用表名判断 } else if (renderEntity.table == DataCodeEnum.OMDB_NODE_PA.name) {//特殊处理因为code相同使用表名判断
//过滤不需要渲染的要素 //过滤不需要渲染的要素
val attributeType = val attributeType = renderEntity.properties["attributeType"]
renderEntity.properties["attributeType"]
if (attributeType != null && attributeType.toInt() == 30) { if (attributeType != null && attributeType.toInt() == 30) {
renderEntity.enable = 2 renderEntity.enable = 2
renderEntity.code = renderEntity.code = DataCodeEnum.OMDB_NODE_PA.code
DataCodeEnum.OMDB_NODE_PA.code
} else { } else {
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
@ -651,7 +658,6 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
} }
++insertIndex
//移除该字段,减少数据量 //移除该字段,减少数据量
if (renderEntity.properties.containsKey("geometry")) { if (renderEntity.properties.containsKey("geometry")) {
@ -668,8 +674,7 @@ class ImportOMDBHelper @AssistedInject constructor(
if (renderEntity.linkRelation == null) { if (renderEntity.linkRelation == null) {
renderEntity.linkRelation = LinkRelation() renderEntity.linkRelation = LinkRelation()
} }
renderEntity.linkRelation!!.linkPid = renderEntity.linkRelation!!.linkPid = renderEntity.linkPid
renderEntity.linkPid
renderEntity.linkRelation!!.sNodeId = renderEntity.linkRelation!!.sNodeId =
renderEntity.properties["snodePid"] renderEntity.properties["snodePid"]
renderEntity.linkRelation!!.eNodeId = renderEntity.linkRelation!!.eNodeId =
@ -681,102 +686,88 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.properties.remove("shapeList") renderEntity.properties.remove("shapeList")
} }
var gsonStr = gson.toJson(renderEntity.properties).toByteArray() renderEntity.propertiesDb = StrZipUtil.compress(
gson.toJson(renderEntity.properties).toString()
renderEntity.propertiesDb = DeflaterUtil.compress(gsonStr)//StrZipUtil.compress(gsonStr) )
listRenderEntity.add(renderEntity) listRenderEntity.add(renderEntity)
} }
if (listRenderEntity.size > 50000) { if (listRenderEntity.size > 20000) {
Log.e("jingo", "50000刷新") Log.e(
realm.copyToRealmOrUpdate(listRenderEntity) "jingo",
realm.commitTransaction() "安装数据 ${currentConfig.table} $elementIndex ${listRenderEntity.size}"
realm.close() )
listRenderEntity.clear() if (isEmit) {
insertIndex = 0 f.send(listRenderEntity)
delay(20)
} else {
realm!!.copyToRealm(listRenderEntity)
realm!!.commitTransaction()
realm!!.close()
realm = Realm.getInstance(currentInstallTaskConfig) realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction() realm.beginTransaction()
} }
listRenderEntity = mutableListOf()
//
}
line = bufferedReader.readLine() line = bufferedReader.readLine()
} }
// CMLog.writeLogtoFile(
// ImportOMDBHelper::class.java.name,
// "importOmdbZipFile",
// "结束===总量$elementIndex"
// )
if (isEmit) {
f.send(listRenderEntity)
delay(20)
bufferedReader.close()
} catch (e: Exception) {
CMLog.writeLogtoFile(
ImportOMDBHelper::class.java.name,
"importOmdbZipFile",
"${currentConfig.table}安装异常"
)
}
} else { } else {
CMLog.writeLogtoFile( bufferedReader.close()
ImportOMDBHelper::class.java.name, realm!!.copyToRealm(listRenderEntity)
"importOmdbZipFile", realm!!.commitTransaction()
"文件不存在"
)
}
// 1个文件发送一次flow流
emit("${processIndex}/${tableNum}")
CMLog.writeLogtoFile(
ImportOMDBHelper::class.java.name,
"importOmdbZipFile",
"${currentConfig.table}结束==$elementIndex"
)
elementIndex = 0
} }
} }
CMLog.writeLogtoFile( if (!isEmit) {
ImportOMDBHelper::class.java.name, realm!!.close()
"importOmdbZipFile", }
"结束===总量$dataIndex"
)
realm.copyToRealmOrUpdate(listRenderEntity)
realm.commitTransaction()
realm.close()
listRenderEntity.clear()
Log.e("qj", "安装结束")
} catch (e: Exception) { } catch (e: Exception) {
if (realm.isInTransaction) { Log.e("jingo", "安装报错 ${currentConfig.table} ${elementIndex} ${e.message}")
realm.cancelTransaction()
realm.close()
}
throw e throw e
} }
emit("finish") Log.e("jingo", "完成 ${currentConfig.table}")
}
} }
// 获取指定数据表的列名
fun getColumns(db: SQLiteDatabase, tableName: String): List<String> {
val columns = mutableListOf<String>()
// 查询 sqlite_master 表获取指定数据表的元数据信息 // // 获取指定数据表的列名
val cursor = db.query( // fun getColumns(db: SQLiteDatabase, tableName: String): List<String> {
"sqlite_master", // val columns = mutableListOf<String>()
arrayOf("sql"), //
"type='table' AND name=?", // // 查询 sqlite_master 表获取指定数据表的元数据信息
arrayOf(tableName), // val cursor = db.query(
null, // "sqlite_master",
null, // arrayOf("sql"),
null // "type='table' AND name=?",
) // arrayOf(tableName),
// null,
// 从元数据信息中解析出列名 // null,
if (cursor.moveToFirst()) { // null
val sql = cursor.getString(0) // )
val startIndex = sql.indexOf("(") + 1 //
val endIndex = sql.lastIndexOf(")") // // 从元数据信息中解析出列名
val columnDefs = sql.substring(startIndex, endIndex).split(",") // if (cursor.moveToFirst()) {
for (columnDef in columnDefs) { // val sql = cursor.getString(0)
val columnName = columnDef.trim().split(" ")[0] // val startIndex = sql.indexOf("(") + 1
if (!columnName.startsWith("rowid", true)) { // 排除 rowid 列 // val endIndex = sql.lastIndexOf(")")
columns.add(columnName) // val columnDefs = sql.substring(startIndex, endIndex).split(",")
} // for (columnDef in columnDefs) {
} // val columnName = columnDef.trim().split(" ")[0]
} // if (!columnName.startsWith("rowid", true)) { // 排除 rowid 列
cursor.close() // columns.add(columnName)
return columns // }
} // }
// }
// cursor.close()
// return columns
// }
} }

View File

@ -728,6 +728,7 @@ class ImportPreProcess {
* 生成车道中心线面宽度 * 生成车道中心线面宽度
* */ * */
fun generateAddWidthLine(renderEntity: RenderEntity) { fun generateAddWidthLine(renderEntity: RenderEntity) {
var newTime = 0L
// 添加车道中心面渲染原则,根据车道宽度进行渲染 // 添加车道中心面渲染原则,根据车道宽度进行渲染
val angleReference = ReferenceEntity() val angleReference = ReferenceEntity()
// angleReference.renderEntityId = renderEntity.id // angleReference.renderEntityId = renderEntity.id
@ -952,11 +953,8 @@ class ImportPreProcess {
private fun insertData(list: List<RealmModel>) { private fun insertData(list: List<RealmModel>) {
realm?.let { realm?.let {
Log.e("qj", "子表插入==")
if (list != null && list.isNotEmpty()) { if (list != null && list.isNotEmpty()) {
Log.e("qj", "子表插入开始==")
it.copyToRealm(list) it.copyToRealm(list)
Log.e("qj", "子表插入结束==")
} }
} }
} }

View File

@ -155,9 +155,8 @@ class TaskDownloadScope(
fileNew fileNew
) )
if (task != null) { if (task != null) {
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task).collect { if (importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task, this)) {
Log.e("jingo", "数据安装 $it") // if (it == "finish") {
if (it == "finish") {
change(FileDownloadStatus.DONE) change(FileDownloadStatus.DONE)
Log.e("jingo", "数据安装结束") Log.e("jingo", "数据安装结束")
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -167,9 +166,9 @@ class TaskDownloadScope(
} }
} }
} else { } else {
change(FileDownloadStatus.IMPORTING, it) change(FileDownloadStatus.IMPORTING, "anzhuang")
}
} }
// }
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e("jingo", "数据安装失败 ${e.toString()}") Log.e("jingo", "数据安装失败 ${e.toString()}")

View File

@ -81,30 +81,30 @@ class PersonalCenterFragment(private var indoorDataListener: ((Boolean) -> Unit?
R.id.personal_center_menu_offline_map -> R.id.personal_center_menu_offline_map ->
findNavController().navigate(R.id.OfflineMapFragment) findNavController().navigate(R.id.OfflineMapFragment)
R.id.personal_center_menu_obtain_data -> { // 生成数据根据sqlite文件生成对应的zip文件 // R.id.personal_center_menu_obtain_data -> { // 生成数据根据sqlite文件生成对应的zip文件
fileChooser.openChooseFileDialog(object : FileChooserCallback() { // fileChooser.openChooseFileDialog(object : FileChooserCallback() {
override fun onCancel(reason: String) { // override fun onCancel(reason: String) {
} // }
//
@RequiresApi(Build.VERSION_CODES.N) // @RequiresApi(Build.VERSION_CODES.N)
override fun onResult(uri: Uri) { // override fun onResult(uri: Uri) {
val file = UriUtils.uri2File(uri) // val file = UriUtils.uri2File(uri)
// 开始导入数据 // // 开始导入数据
// 656e6372797000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 // // 656e6372797000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
CoroutineUtils.launchWithLoading( // CoroutineUtils.launchWithLoading(
requireContext(), // requireContext(),
loadingMessage = "生成数据..." // loadingMessage = "生成数据..."
) { // ) {
val importOMDBHelper: ImportOMDBHelper = // val importOMDBHelper: ImportOMDBHelper =
importOMDBHiltFactory.obtainImportOMDBHelper( // importOMDBHiltFactory.obtainImportOMDBHelper(
requireContext(), // requireContext(),
file // file
) // )
viewModel.obtainOMDBZipData(importOMDBHelper) // viewModel.obtainOMDBZipData(importOMDBHelper)
} // }
} // }
}) // })
} // }
R.id.personal_center_menu_import_data -> { // 导入zip数据 R.id.personal_center_menu_import_data -> { // 导入zip数据
fileChooser.openChooseFileDialog(object : FileChooserCallback() { fileChooser.openChooseFileDialog(object : FileChooserCallback() {

View File

@ -1,17 +1,12 @@
package com.navinfo.omqs.ui.fragment.personalcenter package com.navinfo.omqs.ui.fragment.personalcenter
import android.net.Uri import android.net.Uri
import android.os.Build
import android.util.Log import android.util.Log
import androidx.annotation.RequiresApi
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.FileIOUtils
import com.blankj.utilcode.util.UriUtils import com.blankj.utilcode.util.UriUtils
import com.blankj.utilcode.util.ZipUtils import com.navinfo.collect.library.data.entity.TaskBean
import com.google.gson.Gson
import com.navinfo.collect.library.data.entity.*
import com.navinfo.omqs.bean.ScProblemTypeBean import com.navinfo.omqs.bean.ScProblemTypeBean
import com.navinfo.omqs.bean.ScRootCauseAnalysisBean import com.navinfo.omqs.bean.ScRootCauseAnalysisBean
import com.navinfo.omqs.bean.ScWarningCodeBean import com.navinfo.omqs.bean.ScWarningCodeBean
@ -24,7 +19,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.apache.commons.io.input.BOMInputStream import org.apache.commons.io.input.BOMInputStream
import java.io.* import java.io.*
import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -37,119 +31,119 @@ class PersonalCenterViewModel @Inject constructor(
val liveDataMessage = MutableLiveData<String>() val liveDataMessage = MutableLiveData<String>()
/** // /**
* 导入OMDB数据 // * 导入OMDB数据
* */ // * */
@RequiresApi(Build.VERSION_CODES.N) // @RequiresApi(Build.VERSION_CODES.N)
suspend fun obtainOMDBZipData(importOMDBHelper: ImportOMDBHelper) { // suspend fun obtainOMDBZipData(importOMDBHelper: ImportOMDBHelper) {
Log.d("OMQSApplication", "开始生成数据") // Log.d("OMQSApplication", "开始生成数据")
val gson = Gson() // val gson = Gson()
val hadLinkFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_LINK.txt") // val hadLinkFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_LINK.txt")
val hadLinkKindFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_LINK_KIND.txt") // val hadLinkKindFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_LINK_KIND.txt")
val hadLinkDirectFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_LINK_DIRECT.txt") // val hadLinkDirectFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_LINK_DIRECT.txt")
val hadSpeedLimitFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_SPEEDLIMIT.txt") // val hadSpeedLimitFile = File(importOMDBHelper.omdbFile.parentFile, "HAD_SPEEDLIMIT.txt")
val hadSpeedLimitCondFile = // val hadSpeedLimitCondFile =
File(importOMDBHelper.omdbFile.parentFile, "HAD_SPEEDLIMIT_COND.txt") // File(importOMDBHelper.omdbFile.parentFile, "HAD_SPEEDLIMIT_COND.txt")
val hadSpeedLimitVarFile = // val hadSpeedLimitVarFile =
File(importOMDBHelper.omdbFile.parentFile, "HAD_SPEEDLIMIT_VAR.txt") // File(importOMDBHelper.omdbFile.parentFile, "HAD_SPEEDLIMIT_VAR.txt")
//
for (tableName in listOf<String>( // for (tableName in listOf<String>(
"HAD_LINK", "HAD_SPEEDLIMIT", "HAD_SPEEDLIMIT_COND", "HAD_SPEEDLIMIT_VAR" // "HAD_LINK", "HAD_SPEEDLIMIT", "HAD_SPEEDLIMIT_COND", "HAD_SPEEDLIMIT_VAR"
)/*listOf<String>("HAD_LINK")*/) { // )/*listOf<String>("HAD_LINK")*/) {
importOMDBHelper.getOMDBTableData(tableName).collect { // importOMDBHelper.getOMDBTableData(tableName).collect {
for (map in it) { // for (map in it) {
if ("HAD_LINK" == tableName) { // if ("HAD_LINK" == tableName) {
// 根据HAD_Link生成json文件 // // 根据HAD_Link生成json文件
val hadLink = HAD_LINK() // val hadLink = HAD_LINK()
hadLink.LINK_PID = map["LINK_PID"].toString() // hadLink.LINK_PID = map["LINK_PID"].toString()
hadLink.MESH = map["MESH"].toString() // hadLink.MESH = map["MESH"].toString()
hadLink.S_NODE_PID = map["S_NODE_PID"].toString() // hadLink.S_NODE_PID = map["S_NODE_PID"].toString()
hadLink.E_NODE_PID = map["E_NODE_PID"].toString() // hadLink.E_NODE_PID = map["E_NODE_PID"].toString()
hadLink.GEOMETRY = map["GEOMETRY"].toString() // hadLink.GEOMETRY = map["GEOMETRY"].toString()
// 将该数据写入到对应的txt文件 // // 将该数据写入到对应的txt文件
FileIOUtils.writeFileFromString( // FileIOUtils.writeFileFromString(
hadLinkFile, gson.toJson(hadLink) + "\r", true // hadLinkFile, gson.toJson(hadLink) + "\r", true
) // )
//
val hadLinkDirect = HAD_LINK_DIRECT() // val hadLinkDirect = HAD_LINK_DIRECT()
hadLinkDirect.LINK_PID = map["LINK_PID"].toString() // hadLinkDirect.LINK_PID = map["LINK_PID"].toString()
hadLinkDirect.MESH = map["MESH"].toString() // hadLinkDirect.MESH = map["MESH"].toString()
hadLinkDirect.DIRECT = map["DIRECT"].toString().toInt() // hadLinkDirect.DIRECT = map["DIRECT"].toString().toInt()
hadLinkDirect.GEOMETRY = map["GEOMETRY"].toString() // hadLinkDirect.GEOMETRY = map["GEOMETRY"].toString()
// 将该数据写入到对应的txt文件 // // 将该数据写入到对应的txt文件
FileIOUtils.writeFileFromString( // FileIOUtils.writeFileFromString(
hadLinkDirectFile, gson.toJson(hadLinkDirect) + "\r", true // hadLinkDirectFile, gson.toJson(hadLinkDirect) + "\r", true
) // )
//
val hadLinkKind = HAD_LINK_KIND() // val hadLinkKind = HAD_LINK_KIND()
hadLinkKind.LINK_PID = map["LINK_PID"].toString() // hadLinkKind.LINK_PID = map["LINK_PID"].toString()
hadLinkKind.MESH = map["MESH"].toString() // hadLinkKind.MESH = map["MESH"].toString()
hadLinkKind.KIND = map["KIND"].toString().toInt() // hadLinkKind.KIND = map["KIND"].toString().toInt()
hadLinkKind.GEOMETRY = map["GEOMETRY"].toString() // hadLinkKind.GEOMETRY = map["GEOMETRY"].toString()
// 将该数据写入到对应的txt文件 // // 将该数据写入到对应的txt文件
FileIOUtils.writeFileFromString( // FileIOUtils.writeFileFromString(
hadLinkKindFile, gson.toJson(hadLinkKind) + "\r", true // hadLinkKindFile, gson.toJson(hadLinkKind) + "\r", true
) // )
} else if ("HAD_SPEEDLIMIT" == tableName) { // } else if ("HAD_SPEEDLIMIT" == tableName) {
val hadSpeedlimit = HAD_SPEEDLIMIT() // val hadSpeedlimit = HAD_SPEEDLIMIT()
hadSpeedlimit.SPEED_ID = map["SPEED_ID"].toString() // hadSpeedlimit.SPEED_ID = map["SPEED_ID"].toString()
hadSpeedlimit.MESH = map["MESH"].toString() // hadSpeedlimit.MESH = map["MESH"].toString()
hadSpeedlimit.LINK_PID = map["LINK_PID"].toString() // hadSpeedlimit.LINK_PID = map["LINK_PID"].toString()
hadSpeedlimit.GEOMETRY = map["GEOMETRY"].toString() // hadSpeedlimit.GEOMETRY = map["GEOMETRY"].toString()
hadSpeedlimit.DIRECT = map["DIRECT"].toString().toInt() // hadSpeedlimit.DIRECT = map["DIRECT"].toString().toInt()
hadSpeedlimit.SPEED_FLAG = map["SPEED_FLAG"].toString().toInt() // hadSpeedlimit.SPEED_FLAG = map["SPEED_FLAG"].toString().toInt()
hadSpeedlimit.MAX_SPEED = map["MAX_SPEED"].toString().toInt() // hadSpeedlimit.MAX_SPEED = map["MAX_SPEED"].toString().toInt()
hadSpeedlimit.MIN_SPEED = map["MIN_SPEED"].toString().toInt() // hadSpeedlimit.MIN_SPEED = map["MIN_SPEED"].toString().toInt()
// 将该数据写入到对应的txt文件 // // 将该数据写入到对应的txt文件
FileIOUtils.writeFileFromString( // FileIOUtils.writeFileFromString(
hadSpeedLimitFile, gson.toJson(hadSpeedlimit) + "\r", true // hadSpeedLimitFile, gson.toJson(hadSpeedlimit) + "\r", true
) // )
} else if ("HAD_SPEEDLIMIT_COND" == tableName) { // } else if ("HAD_SPEEDLIMIT_COND" == tableName) {
val hadSpeedlimitCond = HAD_SPEEDLIMIT_COND() // val hadSpeedlimitCond = HAD_SPEEDLIMIT_COND()
hadSpeedlimitCond.SPEED_COND_ID = map["SPEED_COND_ID"].toString() // hadSpeedlimitCond.SPEED_COND_ID = map["SPEED_COND_ID"].toString()
hadSpeedlimitCond.MESH = map["MESH"].toString() // hadSpeedlimitCond.MESH = map["MESH"].toString()
hadSpeedlimitCond.LINK_PID = map["LINK_PID"].toString() // hadSpeedlimitCond.LINK_PID = map["LINK_PID"].toString()
hadSpeedlimitCond.GEOMETRY = map["GEOMETRY"].toString() // hadSpeedlimitCond.GEOMETRY = map["GEOMETRY"].toString()
hadSpeedlimitCond.DIRECT = map["DIRECT"].toString().toInt() // hadSpeedlimitCond.DIRECT = map["DIRECT"].toString().toInt()
hadSpeedlimitCond.SPEED_FLAG = map["SPEED_FLAG"].toString().toInt() // hadSpeedlimitCond.SPEED_FLAG = map["SPEED_FLAG"].toString().toInt()
hadSpeedlimitCond.MAX_SPEED = map["MAX_SPEED"].toString().toInt() // hadSpeedlimitCond.MAX_SPEED = map["MAX_SPEED"].toString().toInt()
hadSpeedlimitCond.SPEED_DEPENDENT = // hadSpeedlimitCond.SPEED_DEPENDENT =
map["SPEED_DEPENDENT"].toString().toInt() // map["SPEED_DEPENDENT"].toString().toInt()
hadSpeedlimitCond.VEHICLE_TYPE = map["VEHICLE_TYPE"].toString().toInt() // hadSpeedlimitCond.VEHICLE_TYPE = map["VEHICLE_TYPE"].toString().toInt()
hadSpeedlimitCond.VALID_PERIOD = map["VALID_PERIOD"].toString() // hadSpeedlimitCond.VALID_PERIOD = map["VALID_PERIOD"].toString()
// 将该数据写入到对应的txt文件 // // 将该数据写入到对应的txt文件
FileIOUtils.writeFileFromString( // FileIOUtils.writeFileFromString(
hadSpeedLimitCondFile, gson.toJson(hadSpeedlimitCond) + "\r", true // hadSpeedLimitCondFile, gson.toJson(hadSpeedlimitCond) + "\r", true
) // )
} else if ("HAD_SPEEDLIMIT_VAR" == tableName) { // } else if ("HAD_SPEEDLIMIT_VAR" == tableName) {
val hadSpeedlimitVar = HAD_SPEEDLIMIT_VAR() // val hadSpeedlimitVar = HAD_SPEEDLIMIT_VAR()
hadSpeedlimitVar.SPEED_VAR_ID = map["SPEED_ID"].toString() // hadSpeedlimitVar.SPEED_VAR_ID = map["SPEED_ID"].toString()
hadSpeedlimitVar.MESH = map["MESH"].toString() // hadSpeedlimitVar.MESH = map["MESH"].toString()
hadSpeedlimitVar.LINK_PID = map["LINK_PID"].toString() // hadSpeedlimitVar.LINK_PID = map["LINK_PID"].toString()
hadSpeedlimitVar.GEOMETRY = map["GEOMETRY"].toString() // hadSpeedlimitVar.GEOMETRY = map["GEOMETRY"].toString()
hadSpeedlimitVar.DIRECT = map["DIRECT"].toString().toInt() // hadSpeedlimitVar.DIRECT = map["DIRECT"].toString().toInt()
hadSpeedlimitVar.LOCATION = map["LOCATION"].toString() // hadSpeedlimitVar.LOCATION = map["LOCATION"].toString()
// 将该数据写入到对应的txt文件 // // 将该数据写入到对应的txt文件
FileIOUtils.writeFileFromString( // FileIOUtils.writeFileFromString(
hadSpeedLimitVarFile, gson.toJson(hadSpeedlimitVar) + "\r", true // hadSpeedLimitVarFile, gson.toJson(hadSpeedlimitVar) + "\r", true
) // )
} // }
} // }
} // }
} // }
ZipUtils.zipFiles( // ZipUtils.zipFiles(
mutableListOf( // mutableListOf(
hadLinkFile, // hadLinkFile,
hadLinkKindFile, // hadLinkKindFile,
hadLinkDirectFile, // hadLinkDirectFile,
hadSpeedLimitFile, // hadSpeedLimitFile,
hadSpeedLimitCondFile, // hadSpeedLimitCondFile,
hadSpeedLimitVarFile // hadSpeedLimitVarFile
), File(importOMDBHelper.omdbFile.parentFile, "output.zip") // ), File(importOMDBHelper.omdbFile.parentFile, "output.zip")
) // )
//
Log.d("OMQSApplication", "生成数据完成") // Log.d("OMQSApplication", "生成数据完成")
} // }
/** /**
* 导入OMDB数据 * 导入OMDB数据
@ -158,15 +152,12 @@ class PersonalCenterViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
Log.d("OMQSApplication", "开始导入数据") Log.d("OMQSApplication", "开始导入数据")
if (task != null) { if (task != null) {
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task).collect { importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task, this)
Log.d("importOMDBData", it)
}
} else { } else {
val newTask = TaskBean() val newTask = TaskBean()
newTask.id = -1 newTask.id = -1
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, newTask).collect { importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, newTask, this)
Log.d("importOMDBData", it)
}
} }
Log.d("OMQSApplication", "导入数据完成") Log.d("OMQSApplication", "导入数据完成")
} }

View File

@ -214,7 +214,7 @@ public class CMLog {
if (!flag&&MYLOG_WRITE_TO_FILE) { if (!flag&&MYLOG_WRITE_TO_FILE) {
flag = true; flag = true;
try { try {
Log.e("jingo", "日志写入0"); Log.e("qj", "日志写入0");
// 新建或打开日志文件 // 新建或打开日志文件
Date nowtime = new Date(); Date nowtime = new Date();
String needWriteFiel = logfile.format(nowtime); String needWriteFiel = logfile.format(nowtime);
@ -232,11 +232,11 @@ public class CMLog {
new File(Constant.USER_DATA_LOG_PATH).mkdirs(); new File(Constant.USER_DATA_LOG_PATH).mkdirs();
} }
File file = new File(Constant.USER_DATA_LOG_PATH, needWriteFiel + MYLOGFILEName); File file = new File(Constant.USER_DATA_LOG_PATH, needWriteFiel + MYLOGFILEName);
Log.e("jingo", "日志写入1"); Log.e("qj", "日志写入1");
if (!file.exists()) if (!file.exists())
file.createNewFile(); file.createNewFile();
Log.e("jingo", "日志写入2"); Log.e("qj", "日志写入2");
FileWriter filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据不进行覆盖 FileWriter filerWriter = new FileWriter(file, true);//后面这个参数代表是不是要接上文件中原来的数据不进行覆盖
BufferedWriter bufWriter = new BufferedWriter(filerWriter); BufferedWriter bufWriter = new BufferedWriter(filerWriter);
@ -244,7 +244,7 @@ public class CMLog {
bufWriter.newLine(); bufWriter.newLine();
bufWriter.close(); bufWriter.close();
filerWriter.close(); filerWriter.close();
Log.e("jingo", "日志写入结束"); Log.e("qj", "日志写入结束");
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

View File

@ -1,20 +1,14 @@
package com.navinfo.omqs.util package com.navinfo.omqs.util
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.navinfo.collect.library.data.entity.HadLinkDvoBean import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.collect.library.data.entity.NiLocation import com.navinfo.collect.library.data.entity.NiLocation
import com.navinfo.collect.library.data.entity.RenderEntity import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.data.entity.TaskBean import com.navinfo.collect.library.data.entity.TaskBean
import com.navinfo.collect.library.enums.DataCodeEnum import com.navinfo.collect.library.enums.DataCodeEnum
import com.navinfo.collect.library.utils.FootAndDistance
import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.omqs.db.RealmOperateHelper import com.navinfo.omqs.db.RealmOperateHelper
import io.realm.Realm import io.realm.Realm
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
import java.time.LocalDate
import java.time.LocalDateTime
class NaviEngineNew( class NaviEngineNew(
private val realmOperateHelper: RealmOperateHelper, private val realmOperateHelper: RealmOperateHelper,
@ -38,7 +32,6 @@ class NaviEngineNew(
geoPoint: GeoPoint, geoPoint: GeoPoint,
realm:Realm realm:Realm
) { ) {
// val geoPoint = GeoPoint(niLocation.latitude, niLocation.longitude)
var latestRoute: HadLinkDvoBean? = null var latestRoute: HadLinkDvoBean? = null
var lastDis = -1.0 var lastDis = -1.0

View File

@ -49,7 +49,6 @@ class GeometryToolsKt {
} }
} }
} }
println("YGeometry-time:" + (System.currentTimeMillis() - startTime))
} }
/** /**
@ -93,7 +92,6 @@ class GeometryToolsKt {
} }
} }
} }
println("XGeometry-time:" + (System.currentTimeMillis() - startTime))
} }
fun getMasterPoint(wkt: String): String { fun getMasterPoint(wkt: String): String {

2
vtm

@ -1 +1 @@
Subproject commit 9e0cc6dcdce04d1082ed6459e8810d6329e8cfdc Subproject commit c046e788f5c739612a31c308639fca2de639669a