fix: 修改普通交限入库规则,首尾相接数据不入库

This commit is contained in:
xiaoyan 2023-06-25 16:49:25 +08:00
parent a5e964efbb
commit e9af1785f8
7 changed files with 73 additions and 28 deletions

View File

@ -171,6 +171,12 @@
"code": 4006,
"name": "普通交限",
"transformer": [
{
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "checkCircleRoad()"
},
{
"k": "geometry",
"v": "~",

View File

@ -13,7 +13,7 @@ class ImportConfig {
var checked : Boolean = true
val preProcess: ImportPreProcess = ImportPreProcess()
fun transformProperties(renderEntity: RenderEntity): RenderEntity {
fun transformProperties(renderEntity: RenderEntity): RenderEntity? {
val transformList = tableMap[renderEntity.code.toString()]?.transformer
if (transformList.isNullOrEmpty()) {
return renderEntity
@ -31,6 +31,7 @@ class ImportConfig {
// 如果key和value都为空说明当前数据需要增加一个新字段
if (key.isNullOrEmpty()&&value.isNullOrEmpty()&&!renderEntity.properties.containsKey(keylib)) {
renderEntity.properties[keylib] = valuelib
continue
}
// 开始解析key和value并对数据进行匹配
m@ for (k in processKeyOrValue(key)) {
@ -54,7 +55,12 @@ class ImportConfig {
callByParams[methodParams[index+1]] = value
}
}
method.callBy(callByParams)
when(val result = method.callBy(callByParams)) { // 如果方法返回的数据类型是boolean且返回为false则该数据不处理
is Boolean ->
if (!result) {
return null
}
}
} else {
renderEntity.properties[keylib] = valuelib
}
@ -77,7 +83,12 @@ class ImportConfig {
callByParams[methodParams[index+1]] = value
}
}
method.callBy(callByParams)
when(val result = method.callBy(callByParams)) {
is Boolean ->
if (!result) {
return null
}
}
} else {
renderEntity.properties[keylib] = valuelib
}

View File

@ -146,7 +146,7 @@ class ImportOMDBHelper @AssistedInject constructor(
it.name == currentConfig.table
}
val listResult = mutableListOf<Map<String, Any>>()
val listResult = mutableListOf<RenderEntity>()
currentConfig?.let {
val list = FileIOUtils.readFile2List(txtFile, "UTF-8")
Log.d("ImportOMDBHelper", "开始解析:${txtFile?.name}")
@ -159,33 +159,38 @@ class ImportOMDBHelper @AssistedInject constructor(
map["qi_table"] = currentConfig.table
map["qi_name"] = currentConfig.name
map["qi_code"] = if (currentConfig.code == 0) currentConfig.code else currentEntry.key
listResult.add(map)
// 先查询这个mesh下有没有数据如果有则跳过即可
// val meshEntity = Realm.getDefaultInstance().where(RenderEntity::class.java).equalTo("properties['mesh']", map["mesh"].toString()).findFirst()
val renderEntity = RenderEntity()
renderEntity.code = map["qi_code"].toString().toInt()
renderEntity.name = map["qi_name"].toString()
renderEntity.table = map["qi_table"].toString()
// 其他数据插入到Properties中
renderEntity.geometry = map["geometry"].toString()
for ((key, value) in map) {
when (value) {
is String -> renderEntity.properties.put(key, value)
is Int -> renderEntity.properties.put(key, value.toInt().toString())
is Double -> renderEntity.properties.put(key, value.toDouble().toString())
else -> renderEntity.properties.put(key, value.toString())
}
}
listResult.add(renderEntity)
// 对renderEntity做预处理后再保存
val resultEntity = importConfig.transformProperties(renderEntity)
if (resultEntity!=null) {
Realm.getDefaultInstance().insert(renderEntity)
}
}
}
}
for (map in listResult) { // 每一个map就是Realm的一条数据
// 先查询这个mesh下有没有数据如果有则跳过即可
// val meshEntity = Realm.getDefaultInstance().where(RenderEntity::class.java).equalTo("properties['mesh']", map["mesh"].toString()).findFirst()
val renderEntity = RenderEntity()
renderEntity.code = map["qi_code"].toString().toInt()
renderEntity.name = map["qi_name"].toString()
renderEntity.table = map["qi_table"].toString()
// 其他数据插入到Properties中
renderEntity.geometry = map["geometry"].toString()
for ((key, value) in map) {
when (value) {
is String -> renderEntity.properties.put(key, value)
is Int -> renderEntity.properties.put(key, value.toInt().toString())
is Double -> renderEntity.properties.put(key, value.toDouble().toString())
else -> renderEntity.properties.put(key, value.toString())
}
}
// 对renderEntity做预处理后再保存
importConfig.transformProperties(renderEntity)
Realm.getDefaultInstance().copyToRealm(renderEntity)
}
// 1个文件发送一次flow流
emit("${index + 1}/${importConfig.tableMap.size}")
// 如果当前解析的是OMDB_RD_LINK数据将其缓存在预处理类中以便后续处理其他要素时使用
if (currentConfig.table == "OMDB_RD_LINK") {
importConfig.preProcess.cacheRdLink = listResult.associateBy { it.properties["linkPid"] }
}
}
Realm.getDefaultInstance().commitTransaction()
} catch (e: Exception) {

View File

@ -0,0 +1,5 @@
package com.navinfo.omqs.db
class ImportPreCacheData {
}

View File

@ -1,5 +1,6 @@
package com.navinfo.omqs.db
import android.util.Log
import com.navinfo.collect.library.data.entity.ReferenceEntity
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.utils.GeometryTools
@ -14,6 +15,23 @@ import org.oscim.core.GeoPoint
class ImportPreProcess {
val code2NameMap = Code2NameMap()
lateinit var cacheRdLink: Map<String?, RenderEntity>
fun checkCircleRoad(renderEntity: RenderEntity): Boolean {
val linkInId = renderEntity.properties["linkIn"]
val linkOutId = renderEntity.properties["linkOut"]
// 根据linkIn和linkOut获取对应的link数据
val linkInEntity = cacheRdLink[linkInId]
val linkOutEntity = cacheRdLink[linkOutId]
Log.d("checkCircleRoad", "LinkInEntity: ${linkInId}- ${linkInEntity?.properties?.get("snodePid")}LinkOutEntity: ${linkOutId}- ${linkOutEntity?.properties?.get("enodePid")}")
// 查询linkIn的sNode和linkOut的eNode是否相同如果相同认为数据是环形路口返回false
if (linkInEntity!=null&&linkOutEntity!=null) {
if ((linkInEntity.properties["snodePid"] == linkOutEntity.properties["enodePid"]) || linkInEntity.properties["enodePid"] == linkOutEntity.properties["snodePid"]
|| linkInEntity.properties["snodePid"] == linkOutEntity.properties["snodePid"]|| linkInEntity.properties["enodePid"] == linkOutEntity.properties["enodePid"])
return false
}
return true
}
/**
* 计算指定数据指定方向的坐标
* @param direction 判断当前数据是否为逆向给定的应该是一个a=b的表达式a为对应的properties的keyb为对应的值

View File

@ -112,7 +112,7 @@ class PersonalCenterFragment(private var backListener: (() -> Unit?)? = null) :
viewModel.readRealmData()
// 定位到指定位置
niMapController.mMapView.vtmMap.animator()
.animateTo(GeoPoint( 39.80392140200183, 116.51446703352337 ))
.animateTo(GeoPoint( 39.80130797136839, 116.51808677349096 ))
}
// R.id.personal_center_menu_task_list -> {
// findNavController().navigate(R.id.TaskManagerFragment)

View File

@ -1804,7 +1804,7 @@
</m>
</m>
<!--电子眼-->
<m v="OMDB_RESTRICTION">
<m v="OMDB_ELECTRONICEYE">
<m k="angle">
<symbol repeat="false" repeat-start="0" rotate="false"
src="assets:symbols/volcano.svg" symbol-height="69" symbol-width="69"></symbol>