修改多线程安装

This commit is contained in:
squallzhjch 2023-10-26 14:28:58 +08:00
parent ed116d2acd
commit 459970d01b
7 changed files with 1457 additions and 1565 deletions

View File

@ -453,6 +453,7 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"filterData": true, "filterData": true,
"isDependOnOtherTable": true,
"catch": true, "catch": true,
"transformer": [ "transformer": [
{ {
@ -690,7 +691,6 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
} }
} }
} }
] ]

View File

@ -144,7 +144,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,46 +2,34 @@ 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.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 dagger.assisted.Assisted 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.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.withContext
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数据的帮助类
@ -54,11 +42,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 {
@ -80,79 +69,85 @@ 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
): Flow<String> =
flow {
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()
@ -162,8 +157,6 @@ class ImportOMDBHelper @AssistedInject constructor(
// .allowQueriesOnUiThread(true) // .allowQueriesOnUiThread(true)
.schemaVersion(2).build() .schemaVersion(2).build()
val unZipFolder = File(omdbZipFile.parentFile, "result") val unZipFolder = File(omdbZipFile.parentFile, "result")
flow {
if (unZipFolder.exists()) { if (unZipFolder.exists()) {
unZipFolder.deleteRecursively() unZipFolder.deleteRecursively()
} }
@ -173,20 +166,14 @@ 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 tableImportTime = System.currentTimeMillis()
//总表要素统计时间 //总表要素统计时间
// var dataImportTime = System.currentTimeMillis() // var dataImportTime = System.currentTimeMillis()
// Realm.compactRealm(currentInstallTaskConfig) // 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,28 +189,49 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap val resHashMap: HashMap<String, RenderEntity> = HashMap() //define empty hashmap
val listRenderEntity = mutableListOf<RenderEntity>()
val listDependOnEntry = mutableListOf<MutableMap.MutableEntry<String, TableInfo>>()
val listJob = mutableListOf<Job>()
try { try {
// var multipLine = MultiLineString(lineList, GeometryFactory())
// 遍历解压后的文件,读取该数据返回
// Log.d("ImportOMDBHelper", "表解析===开始时间$dataImportTime===")
for (importConfig in importConfigList) { for (importConfig in importConfigList) {
for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) { for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) {
if (currentEntry.value.isDependOnOtherTable) {
listDependOnEntry.add(currentEntry)
continue
}
val job = scope.async {
importData(unZipFiles, currentEntry, task,importConfig)
}
listJob.add(job)
processIndex += 1 processIndex += 1
// Log.d( // 1个文件发送一次flow流
// "ImportOMDBHelper", emit("${processIndex}/${tableNum}")
// "表解析===开始时间$tableImportTime===${currentEntry.value.table}" }
// ) }
// Log.d(
// "ImportOMDBHelper", Log.e("qj", "安装结束")
// "表解析===processIndex${processIndex}====${processIndex}/${tableNum}" } catch (e: Exception) {
// ) Log.e("jingo", "安装报错 ${e.message}")
// val listResult = mutableListOf<RenderEntity>() throw e
}
emit("finish")
}
private suspend fun importData(
unZipFiles: List<File>,
currentEntry: MutableMap.MutableEntry<String, TableInfo>,
task: TaskBean,
importConfig:ImportConfig
) {
val listRenderEntity = mutableListOf<RenderEntity>()
//下载数据统计
var dataIndex = 0
//数据库插入的统计
var insertIndex = 0
//单个表要素统计
var elementIndex = 0
var realm = Realm.getInstance(currentInstallTaskConfig)
val currentConfig = currentEntry.value val currentConfig = currentEntry.value
val txtFile = unZipFiles.find { val txtFile = unZipFiles.find {
it.name == currentConfig.table it.name == currentConfig.table
@ -232,6 +240,7 @@ class ImportOMDBHelper @AssistedInject constructor(
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()
realm.beginTransaction()
while (line != null) { while (line != null) {
if (line == null || line.trim() == "") { if (line == null || line.trim() == "") {
line = bufferedReader.readLine() line = bufferedReader.readLine()
@ -239,7 +248,6 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
elementIndex += 1 elementIndex += 1
dataIndex += 1 dataIndex += 1
// Log.d("ImportOMDBHelper", "解析第:${index + 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()
@ -304,8 +312,6 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.geometry = newGeometry.toString() renderEntity.geometry = newGeometry.toString()
} }
}*/ }*/
// Log.d("ImportOMDBHelper", "解析===2处理3D")
// Log.d("ImportOMDBHelper", "解析===1处理属性")
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
@ -318,14 +324,10 @@ class ImportOMDBHelper @AssistedInject constructor(
else -> renderEntity.properties[key] = value.toString() else -> renderEntity.properties[key] = value.toString()
} }
} }
// Log.d("ImportOMDBHelper", "解析===2处理属性")
// Log.d("ImportOMDBHelper", "解析===1处理name")
// 如果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.d("ImportOMDBHelper", "解析===2处理name")
// Log.d("ImportOMDBHelper", "解析===1处理杆状物")
if (currentConfig.filterData) { if (currentConfig.filterData) {
when (renderEntity.code.toInt()) { when (renderEntity.code.toInt()) {
@ -346,10 +348,6 @@ class ImportOMDBHelper @AssistedInject constructor(
when (boundaryType.toInt()) { when (boundaryType.toInt()) {
0, 1, 6, 8, 9 -> { 0, 1, 6, 8, 9 -> {
renderEntity.enable = 0 renderEntity.enable = 0
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
@ -364,10 +362,6 @@ class ImportOMDBHelper @AssistedInject constructor(
when (boundaryType.toInt()) { when (boundaryType.toInt()) {
0, 1, 3, 4, 5, 7, 9 -> { 0, 1, 3, 4, 5, 7, 9 -> {
renderEntity.enable = 0 renderEntity.enable = 0
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
@ -382,10 +376,6 @@ class ImportOMDBHelper @AssistedInject constructor(
when (locationType.toInt()) { when (locationType.toInt()) {
3, 4 -> { 3, 4 -> {
renderEntity.enable = 0 renderEntity.enable = 0
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
@ -403,10 +393,6 @@ class ImportOMDBHelper @AssistedInject constructor(
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)) {
// Log.e(
// "qj",
// "${renderEntity.name}==过滤交限linkin与linkout相同且存在多条数据"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} else { } else {
@ -419,9 +405,6 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
// Log.d("ImportOMDBHelper", "解析===2处理杆状物")
// Log.d("ImportOMDBHelper", "解析===1任务路线匹配")
//遍历判断只显示与任务Link相关的任务数据 //遍历判断只显示与任务Link相关的任务数据
if (currentConfig.checkLinkId) { if (currentConfig.checkLinkId) {
@ -429,29 +412,15 @@ class ImportOMDBHelper @AssistedInject constructor(
val currentLinkPid = renderEntity.linkPid val currentLinkPid = renderEntity.linkPid
// Log.d(
// "ImportOMDBHelper",
// "解析===1任务路线匹配${currentLinkPid}"
// )
if (!currentLinkPid.isNullOrEmpty() && currentLinkPid != "null") { if (!currentLinkPid.isNullOrEmpty() && currentLinkPid != "null") {
val list = currentLinkPid.split(",") val list = currentLinkPid.split(",")
if (list.isNotEmpty()) { if (list.isNotEmpty()) {
// Log.d(
// "ImportOMDBHelper",
// "解析===1任务路线匹配${list.size}"
// )
m@ for (linkPid in list) { m@ for (linkPid in list) {
if (hashMap.containsKey(linkPid.toLong())) { if (hashMap.containsKey(linkPid.toLong())) {
renderEntity.enable = 1 renderEntity.enable = 1
// Log.e(
// "qj",
// "${renderEntity.name}==包括任务link"
// )
break@m break@m
} }
} }
@ -465,20 +434,9 @@ class ImportOMDBHelper @AssistedInject constructor(
if (renderEntity.properties["linkList"] != null) { if (renderEntity.properties["linkList"] != null) {
// Log.e(
// "qj",
// "linkList==开始${renderEntity.name}==${renderEntity.properties["linkList"]}}"
// )
val linkList = renderEntity.properties["linkList"] val linkList = renderEntity.properties["linkList"]
if (!linkList.isNullOrEmpty() && linkList != "null") { if (!linkList.isNullOrEmpty() && linkList != "null") {
// Log.e(
// "qj",
// "linkList==${renderEntity.name}==${renderEntity.properties["linkList"]}}"
// )
val list: List<LinkList> = gson.fromJson( val list: List<LinkList> = gson.fromJson(
linkList, linkList,
object : TypeToken<List<LinkList>>() {}.type object : TypeToken<List<LinkList>>() {}.type
@ -487,10 +445,6 @@ class ImportOMDBHelper @AssistedInject constructor(
m@ for (link in list) { m@ for (link in list) {
if (hashMap.containsKey(link.linkPid.toLong())) { if (hashMap.containsKey(link.linkPid.toLong())) {
renderEntity.enable = 1 renderEntity.enable = 1
// Log.e(
// "qj",
// "${renderEntity.name}==包括任务link"
// )
break@m break@m
} }
} }
@ -503,10 +457,6 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
//过滤掉非任务路线上的数据 //过滤掉非任务路线上的数据
if (renderEntity.enable != 1) { if (renderEntity.enable != 1) {
// Log.e(
// "qj",
// "${renderEntity.name}==过滤不包括任务路线上的数据"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
@ -539,30 +489,22 @@ class ImportOMDBHelper @AssistedInject constructor(
// 对renderEntity做预处理后再保存 // 对renderEntity做预处理后再保存
val resultEntity = val resultEntity =
importConfig.transformProperties(renderEntity, realm) importConfig.transformProperties(renderEntity, realm)
// Log.d("ImportOMDBHelper", "解析===2预处理")
if (resultEntity != null) { if (resultEntity != null) {
// Log.d("ImportOMDBHelper", "解析===1子code处理")
//对code编码需要特殊处理 存在多个属性值时渲染优先级SA>PA,存在多个属性值时渲染优先级FRONTAGE>MAIN_SIDE_A CCESS //对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() -> {
// Log.e("qj", "道路属性===0")
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
// Log.e("qj", "道路属性===1")
} else { } else {
type = renderEntity.properties["pa"] type = renderEntity.properties["pa"]
if (type != null && type == "1") { if (type != null && type == "1") {
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_LINK_ATTRIBUTE_PA.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_PA.code
// Log.e("qj", "道路属性===2")
} else { } else {
type = type =
renderEntity.properties["frontage"] renderEntity.properties["frontage"]
@ -571,7 +513,6 @@ class ImportOMDBHelper @AssistedInject constructor(
DataCodeEnum.OMDB_LINK_ATTRIBUTE_FORNTAGE.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_FORNTAGE.code
renderEntity.zoomMin = 15 renderEntity.zoomMin = 15
renderEntity.zoomMax = 17 renderEntity.zoomMax = 17
// Log.e("qj", "道路属性===3")
} else { } else {
type = type =
renderEntity.properties["mainSideAccess"] renderEntity.properties["mainSideAccess"]
@ -580,16 +521,10 @@ class ImportOMDBHelper @AssistedInject constructor(
DataCodeEnum.OMDB_LINK_ATTRIBUTE_MAIN_SIDE_ACCESS.code DataCodeEnum.OMDB_LINK_ATTRIBUTE_MAIN_SIDE_ACCESS.code
renderEntity.zoomMin = 15 renderEntity.zoomMin = 15
renderEntity.zoomMax = 17 renderEntity.zoomMax = 17
// Log.e("qj", "道路属性===4")
} else { } else {
renderEntity.enable = 0 renderEntity.enable = 0
renderEntity.zoomMin = 15 renderEntity.zoomMin = 15
renderEntity.zoomMax = 17 renderEntity.zoomMax = 17
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
// Log.e("qj", "道路属性===5")
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
@ -658,10 +593,6 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
DataCodeEnum.OMDB_LINK_FORM2.code.toInt() -> { DataCodeEnum.OMDB_LINK_FORM2.code.toInt() -> {
// Log.e(
// "qj",
// "道路形态2${renderEntity.properties["formOfWay"]}"
// )
/*道路形态2*/ /*道路形态2*/
val formWay = val formWay =
renderEntity.properties["formOfWay"] renderEntity.properties["formOfWay"]
@ -728,10 +659,6 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_NODE_FORM.code DataCodeEnum.OMDB_NODE_FORM.code
} else { } else {
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
@ -744,19 +671,13 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.code = renderEntity.code =
DataCodeEnum.OMDB_NODE_PA.code DataCodeEnum.OMDB_NODE_PA.code
} else { } else {
// Log.e(
// "qj",
// "过滤不显示数据${renderEntity.table}"
// )
line = bufferedReader.readLine() line = bufferedReader.readLine()
continue continue
} }
} }
} }
// Log.d("ImportOMDBHelper", "解析===2子code处理")
++insertIndex ++insertIndex
Log.e("qj", "统计==${insertIndex}")
//移除该字段,减少数据量 //移除该字段,减少数据量
if (renderEntity.properties.containsKey("geometry")) { if (renderEntity.properties.containsKey("geometry")) {
@ -787,7 +708,6 @@ class ImportOMDBHelper @AssistedInject constructor(
listRenderEntity.add(renderEntity) listRenderEntity.add(renderEntity)
} }
if (listRenderEntity.size > 10000) { if (listRenderEntity.size > 10000) {
Log.e( Log.e(
"jingo", "10000刷新" "jingo", "10000刷新"
@ -797,7 +717,6 @@ class ImportOMDBHelper @AssistedInject constructor(
realm.close() realm.close()
listRenderEntity.clear() listRenderEntity.clear()
insertIndex = 0 insertIndex = 0
// Realm.compactRealm(currentInstallTaskConfig)
realm = Realm.getInstance(currentInstallTaskConfig) realm = Realm.getInstance(currentInstallTaskConfig)
realm.beginTransaction() realm.beginTransaction()
} }
@ -805,40 +724,13 @@ class ImportOMDBHelper @AssistedInject constructor(
} }
bufferedReader.close() bufferedReader.close()
} }
// 1个文件发送一次flow流
emit("${processIndex}/${tableNum}")
// Log.d("ImportOMDBHelper", "表解析===2${currentConfig.table}")
// Log.d(
// "ImportOMDBHelper",
// "表解析===结束用时时间${(System.currentTimeMillis() - tableImportTime)}===${currentEntry.value.table}===$elementIndex"
// )
elementIndex = 0
// tableImportTime = System.currentTimeMillis()
}
}
realm.copyToRealm(listRenderEntity) realm.copyToRealm(listRenderEntity)
realm.commitTransaction() realm.commitTransaction()
realm.close() realm.close()
listRenderEntity.clear() listRenderEntity.clear()
// Log.d(
// "ImportOMDBHelper",
// "表解析===结束用时时间${(System.currentTimeMillis() - dataImportTime)}===$dataIndex===插入$insertIndex"
// )
Log.e("qj", "安装结束")
} catch (e: Exception) {
if (realm.isInTransaction) {
realm.cancelTransaction()
realm.close()
}
throw e
}
emit("finish")
}
} }
// 获取指定数据表的列名 // 获取指定数据表的列名
fun getColumns(db: SQLiteDatabase, tableName: String): List<String> { fun getColumns(db: SQLiteDatabase, tableName: String): List<String> {
val columns = mutableListOf<String>() val columns = mutableListOf<String>()

View File

@ -155,7 +155,7 @@ class TaskDownloadScope(
fileNew fileNew
) )
if (task != null) { if (task != null) {
importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task).collect { importOMDBHelper.importOmdbZipFile(importOMDBHelper.omdbFile, task, this).collect {
Log.e("jingo", "数据安装 $it") Log.e("jingo", "数据安装 $it")
if (it == "finish") { if (it == "finish") {
change(FileDownloadStatus.DONE) change(FileDownloadStatus.DONE)

View File

@ -78,30 +78,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

@ -37,119 +37,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,13 +158,14 @@ 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).collect {
Log.d("importOMDBData", it) 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)
.collect {
Log.d("importOMDBData", it) Log.d("importOMDBData", it)
} }
} }

View File

@ -38,7 +38,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