Merge branch 'master' of gitlab.navinfo.com:CollectVehicle/OneMapQS

This commit is contained in:
squallzhjch 2023-05-23 09:48:21 +08:00
commit 6d0f36068d
11 changed files with 205 additions and 66 deletions

View File

@ -106,6 +106,9 @@ dependencies {
implementation 'com.github.sevar83:android-spatialite:2.0.1'
//fragment
implementation "androidx.navigation:navigation-ui-ktx:2.5.3"
//kotlin反射
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.7.0"
}
//
kapt {

View File

@ -1,44 +0,0 @@
{
"tables" : [
{
"table": "OMDB_RD_LINK",
"code": 2001,
"name": "道路线"
},
{
"table": "OMDB_RD_LINK_KIND",
"code": 2008,
"name": "道路种别"
},
{
"table": "OMDB_LINK_DIRECT",
"code": 2010,
"name": "道路方向"
},
{
"table": "OMDB_SPEEDLIMIT",
"code": 4002,
"name": "常规点限速"
},
{
"table": "OMDB_SPEEDLIMIT_COND",
"code": 4003,
"name": "条件点限速"
},
{
"table": "OMDB_SPEEDLIMIT_VAR",
"code": 4004,
"name": "可变点限速"
},
{
"table": "OMDB_LANE_LINK_LG",
"code": 5001,
"name": "车道中心线"
},
{
"table": "OMDB_LANE_NUM",
"code": 2041,
"name": "车道数"
}
]
}

View File

@ -0,0 +1,88 @@
{
"tableMap" : {
"2001": {
"table": "OMDB_RD_LINK",
"code": 2001,
"name": "道路线"
},
"2008": {
"table": "OMDB_RD_LINK_KIND",
"code": 2008,
"name": "道路种别"
},
"2010": {
"table": "OMDB_LINK_DIRECT",
"code": 2010,
"name": "道路方向"
},
"4002": {
"table": "OMDB_SPEEDLIMIT",
"code": 4002,
"name": "常规点限速",
"transformer": [
{
"k": "maxSpeed",
"v": "0",
"klib": "maxSpeed",
"vlib": "限"
}
]
},
"4003":{
"table": "OMDB_SPEEDLIMIT_COND",
"code": 4003,
"name": "条件点限速",
"transformer": [
{
"k": "maxSpeed",
"v": "0|",
"klib": "maxSpeed",
"vlib": "限"
}
]
},
"4004":{
"table": "OMDB_SPEEDLIMIT_VAR",
"code": 4004,
"name": "可变点限速",
"transformer": [
{
"k": "location",
"v": "1",
"klib": "location",
"vlib": "左"
},
{
"k": "location",
"v": "2",
"klib": "locationlib",
"vlib": "右"
},
{
"k": "location",
"v": "3",
"klib": "location",
"vlib": "上"
}
]
},
"5001":{
"table": "OMDB_LANE_LINK_LG",
"code": 5001,
"name": "车道中心线"
},
"2041":{
"table": "OMDB_LANE_NUM",
"code": 2041,
"name": "车道数",
"transformer": [
{
"k": "laneS2e",
"v": "~",
"klib": "left_00",
"vlib": "laneNumLeft00()"
}
]
}
}
}

View File

@ -1,7 +1,5 @@
package com.navinfo.omqs
import io.realm.Realm
class Constant {
companion object {
/**
@ -76,7 +74,7 @@ class Constant {
//选择拍照或者录像
const val SELECT_TAKEPHOTO_OR_RECORD = "select_takephoto_or_record"
const val OMDB_CONFIG = "omdb.config"
const val OMDB_CONFIG = "omdb_config.json"
const val OTHER_CONFIG = "other.config"
val OMDB_LAYER_VISIBLE_LIST: MutableList<String> = mutableListOf() // 记录OMDB数据显示的图层名称列表

View File

@ -1,10 +1,68 @@
package com.navinfo.omqs.bean
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.omqs.db.ImportPreProcess
import kotlin.reflect.full.declaredMemberFunctions
class ImportConfig {
var tables: MutableList<TableInfo> = mutableListOf()
var tableMap: MutableMap<String, TableInfo> = mutableMapOf()
val tableGroupName: String = "OMDB数据"
var checked : Boolean = true
val preProcess: ImportPreProcess = ImportPreProcess()
fun transformProperties(renderEntity: RenderEntity): RenderEntity {
val transformList = tableMap[renderEntity.code.toString()]?.transformer
if (transformList.isNullOrEmpty()) {
return renderEntity
}
for (transform in transformList) {
// 开始执行转换
val key:String = transform.k
val value = transform.v
val keylib = transform.klib
val valuelib = transform.vlib
// 如果key是以_开头的则预处理时忽略
if (key.startsWith("_")) {
continue
}
// 如果key和value都为空说明当前数据需要增加一个新字段
if (key.isNullOrEmpty()&&value.isNullOrEmpty()&&!renderEntity.properties.containsKey(keylib)) {
renderEntity.properties[keylib] = valuelib
}
// 开始解析key和value并对数据进行匹配
m@ for (k in processKeyOrValue(key)) {
for (v in processKeyOrValue(value)) {
if ("~" == v &&renderEntity.properties.containsKey(k)) { // ~符可以匹配任意元素
if (valuelib.endsWith("()")) { // 以()结尾说明该value配置是一个function需要通过反射调用指定方法
val method = preProcess::class.declaredMemberFunctions.first { it.name == valuelib.replace("()", "") }
method.call(preProcess, renderEntity)
} else {
renderEntity.properties[keylib] = valuelib
}
break@m
} else if (renderEntity.properties[k] == v) {
if (valuelib.endsWith("()")) { // 以()结尾说明该value配置是一个function需要通过反射调用指定方法
val method = preProcess::class.declaredMemberFunctions.first { it.name == valuelib.replace("()", "") }
method.call(preProcess, renderEntity)
} else {
renderEntity.properties[keylib] = valuelib
}
break@m
}
}
}
}
return renderEntity
}
/**
* 处理配置的key
*/
private fun processKeyOrValue(key: String): List<String> {
val keys = key.split("|").filter { it.isNotBlank() }
return keys
}
}
class TableInfo {
@ -12,4 +70,12 @@ class TableInfo {
val code: Int = 0
val name: String = ""
var checked : Boolean = true
var transformer: MutableList<Transform> = mutableListOf()
}
class Transform {
var k: String = ""
var v: String = ""
var klib: String = ""
var vlib: String = ""
}

View File

@ -2,7 +2,9 @@ package com.navinfo.omqs.db
import android.content.Context
import android.database.Cursor.*
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.database.getBlobOrNull
import androidx.core.database.getFloatOrNull
import androidx.core.database.getIntOrNull
@ -14,6 +16,7 @@ import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.omqs.Constant
import com.navinfo.omqs.bean.ImportConfig
import com.navinfo.omqs.bean.Transform
import com.navinfo.omqs.hilt.ImportOMDBHiltFactory
import com.navinfo.omqs.hilt.OMDBDataBaseHiltFactory
import dagger.assisted.Assisted
@ -50,6 +53,10 @@ class ImportOMDBHelper @AssistedInject constructor(
private val configFile: File =
File("${Constant.USER_DATA_PATH}", Constant.OMDB_CONFIG)
private val importConfig by lazy {
openConfigFile()
}
/**
* 读取config的配置文件
* */
@ -61,6 +68,7 @@ class ImportOMDBHelper @AssistedInject constructor(
/**
* 读取指定数据表的数据集
* */
@RequiresApi(Build.VERSION_CODES.N)
suspend fun getOMDBTableData(table: String): Flow<List<Map<String, Any>>> =
withContext(Dispatchers.IO) {
val listResult: MutableList<Map<String, Any>> = mutableListOf()
@ -120,7 +128,6 @@ class ImportOMDBHelper @AssistedInject constructor(
* @param configFile 对应的配置文件
* */
suspend fun importOmdbZipFile(omdbZipFile: File): Flow<String> = withContext(Dispatchers.IO) {
val importConfig = openConfigFile()
val unZipFolder = File(omdbZipFile.parentFile, "result")
flow {
if (unZipFolder.exists()) {
@ -133,7 +140,8 @@ class ImportOMDBHelper @AssistedInject constructor(
try {
Realm.getDefaultInstance().beginTransaction()
// 遍历解压后的文件,读取该数据返回
for ((index, currentConfig) in importConfig.tables.withIndex()) {
for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) {
val currentConfig = currentEntry.value
val txtFile = unZipFiles.find {
it.name == currentConfig.table
}
@ -150,7 +158,7 @@ class ImportOMDBHelper @AssistedInject constructor(
.toMutableMap()
map["qi_table"] = currentConfig.table
map["qi_name"] = currentConfig.name
map["qi_code"] = currentConfig.code
map["qi_code"] = if (currentConfig.code == 0) currentConfig.code else currentEntry.key
listResult.add(map)
}
}
@ -172,10 +180,12 @@ class ImportOMDBHelper @AssistedInject constructor(
else -> renderEntity.properties.put(key, value.toString())
}
}
// 对renderEntity做预处理后再保存
importConfig.transformProperties(renderEntity)
Realm.getDefaultInstance().copyToRealm(renderEntity)
}
// 1个文件发送一次flow流
emit("${index + 1}/${importConfig.tables.size}")
emit("${index + 1}/${importConfig.tableMap.size}")
}
Realm.getDefaultInstance().commitTransaction()
} catch (e: Exception) {
@ -217,10 +227,4 @@ class ImportOMDBHelper @AssistedInject constructor(
cursor.close()
return columns
}
/**
* 预处理渲染要素某些要素需要对数据做二次处理
* */
fun performRenderEntity(renderEntity: RenderEntity) {
}
}

View File

@ -0,0 +1,14 @@
package com.navinfo.omqs.db
import com.navinfo.collect.library.data.entity.RenderEntity
class ImportPreProcess {
/**
* 预处理所需要的函数
* */
fun foo(renderEntity: RenderEntity): RenderEntity {
println("foo")
renderEntity.properties["foo"] = "bar"
return renderEntity
}
}

View File

@ -0,0 +1,5 @@
package com.navinfo.omqs.rule
class LeftPanel {
}

View File

@ -386,9 +386,12 @@ class MainViewModel @Inject constructor(
if (layerConfigList != null && !layerConfigList.isEmpty()) {
val omdbVisibleList = layerConfigList.filter { importConfig ->
importConfig.tableGroupName == "OMDB数据"
}.first().tables.filter { tableInfo ->
}.first().tableMap.filter {
entry ->
val tableInfo = entry.value
!tableInfo.checked
}.map { tableInfo ->
}.map { entry ->
val tableInfo = entry.value
tableInfo.table
}.toList()
com.navinfo.collect.library.system.Constant.HAD_LAYER_INVISIABLE_ARRAY =

View File

@ -17,7 +17,7 @@ class LayerManagerExpandableListAdapter(private val context: Context, val parent
}
override fun getChildrenCount(groupPosition: Int): Int {
return parentItems[groupPosition].tables.size
return parentItems[groupPosition].tableMap.size
}
@ -25,8 +25,8 @@ class LayerManagerExpandableListAdapter(private val context: Context, val parent
return parentItems[groupPosition]
}
override fun getChild(groupPosition: Int, childPosition: Int): Any {
return parentItems[groupPosition].tables[childPosition]
override fun getChild(groupPosition: Int, childPosition: Int): TableInfo? {
return parentItems[groupPosition].tableMap[parentItems[groupPosition].tableMap.keys.elementAt(childPosition)]
}
override fun getGroupId(groupPosition: Int): Long = groupPosition.toLong()
@ -58,7 +58,7 @@ class LayerManagerExpandableListAdapter(private val context: Context, val parent
viewHolder.parentCheckBox.isChecked = parentItem.checked
viewHolder.parentCheckBox.setOnClickListener {
parentItem.checked = !parentItem.checked
parentItem.tables.forEach { it.checked = parentItem.checked }
parentItem.tableMap.forEach { it.value.checked = parentItem.checked }
notifyDataSetChanged()
}
if (isExpanded) {
@ -93,7 +93,7 @@ class LayerManagerExpandableListAdapter(private val context: Context, val parent
viewHolder.childCheckBox.isChecked = childItem.checked
viewHolder.childCheckBox.setOnClickListener {
childItem.checked = !childItem.checked
parentItems[groupPosition].checked = parentItems[groupPosition].tables.all { it.checked }
parentItems[groupPosition].checked = parentItems[groupPosition].tableMap.all { it.value.checked }
notifyDataSetChanged()
}

View File

@ -1859,9 +1859,11 @@
<m v="OMDB_LINK_DIRECT">
<m k="direct">
<m v="2">
<lineSymbol src="assets:omdb/oneway_right.svg"></lineSymbol>
<!-- <lineSymbol src="assets:omdb/oneway_right.svg"></lineSymbol>-->
<symbol src="assets:omdb/oneway_right.svg" repeat-start="99.9" repeat="false" ></symbol>
</m>
<m v="3">
<!-- <lineSymbol src="assets:omdb/oneway_left.svg"></lineSymbol>-->
<lineSymbol src="assets:omdb/oneway_left.svg"></lineSymbol>
</m>
</m>