优化数据库查询

This commit is contained in:
squallzhjch 2023-10-20 16:30:27 +08:00
parent 7a99a9d0fb
commit 51c44f00b1
8 changed files with 746 additions and 739 deletions

View File

@ -1,7 +1,16 @@
[ [
{ {
"tableGroupName": "普通图层", "tableGroupName": "普通图层",
"tableMap" : { "tableMap": {
"2001": {
"table": "OMDB_RD_LINK",
"code": 2001,
"name": "道路线",
"zoomMin": 15,
"zoomMax": 17,
"catch": true,
"checkLinkId": false
},
"1007": { "1007": {
"table": "OMDB_NODE_FORM", "table": "OMDB_NODE_FORM",
"code": 1007, "code": 1007,
@ -24,19 +33,10 @@
"table": "OMDB_CHECKPOINT", "table": "OMDB_CHECKPOINT",
"code": 1012, "code": 1012,
"name": "检查点", "name": "检查点",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20 "zoomMax": 20
}, },
"2001": {
"table": "OMDB_RD_LINK",
"code": 2001,
"name": "道路线",
"zoomMin": 15,
"zoomMax": 17,
"catch":true,
"checkLinkId": false
},
"2002": { "2002": {
"table": "OMDB_RD_LINK_FUNCTION_CLASS", "table": "OMDB_RD_LINK_FUNCTION_CLASS",
"code": 2002, "code": 2002,
@ -50,7 +50,7 @@
"name": "道路种别", "name": "道路种别",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"catch":false, "catch": false,
"checkLinkId": false "checkLinkId": false
}, },
"2010": { "2010": {
@ -93,7 +93,7 @@
"zoomMax": 20, "zoomMax": 20,
"checkLinkId": false, "checkLinkId": false,
"filterData": true, "filterData": true,
"catch":true, "catch": true,
"transformer": [ "transformer": [
{ {
"k": "geometry", "k": "geometry",
@ -107,7 +107,7 @@
"table": "OMDB_LINK_CONSTRUCTION", "table": "OMDB_LINK_CONSTRUCTION",
"code": 2017, "code": 2017,
"name": "道路施工", "name": "道路施工",
"catch":true, "catch": true,
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
@ -133,12 +133,12 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
}, },
"2041":{ "2041": {
"table": "OMDB_LANE_NUM", "table": "OMDB_LANE_NUM",
"code": 2041, "code": 2041,
"name": "车道数" "name": "车道数"
}, },
"2083":{ "2083": {
"table": "OMDB_RDBOUND_BOUNDARYTYPE", "table": "OMDB_RDBOUND_BOUNDARYTYPE",
"code": 2083, "code": 2083,
"name": "道路边界类型", "name": "道路边界类型",
@ -146,22 +146,22 @@
"filterData": true, "filterData": true,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"catch":true "catch": true
}, },
"2090":{ "2090": {
"table": "OMDB_LANE_CONSTRUCTION", "table": "OMDB_LANE_CONSTRUCTION",
"code": 2090, "code": 2090,
"name": "车道施工", "name": "车道施工",
"existSubCode": true, "existSubCode": true,
"catch":true, "catch": true,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20 "zoomMax": 20
}, },
"2201":{ "2201": {
"table": "OMDB_BRIDGE", "table": "OMDB_BRIDGE",
"code": 2201, "code": 2201,
"name": "桥", "name": "桥",
"catch":true, "catch": true,
"existSubCode": true, "existSubCode": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
@ -174,13 +174,13 @@
} }
] ]
}, },
"2202":{ "2202": {
"table": "OMDB_TUNNEL", "table": "OMDB_TUNNEL",
"code": 2202, "code": 2202,
"name": "隧道", "name": "隧道",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"catch":true, "catch": true,
"transformer": [ "transformer": [
{ {
"k": "geometry", "k": "geometry",
@ -190,13 +190,13 @@
} }
] ]
}, },
"3001":{ "3001": {
"table": "OMDB_OBJECT_OH_STRUCT", "table": "OMDB_OBJECT_OH_STRUCT",
"code": 3001, "code": 3001,
"name": "上方障碍物", "name": "上方障碍物",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"catch":true, "catch": true,
"checkLinkId": false, "checkLinkId": false,
"transformer": [ "transformer": [
{ {
@ -207,34 +207,34 @@
} }
] ]
}, },
"3002":{ "3002": {
"table": "OMDB_OBJECT_TEXT", "table": "OMDB_OBJECT_TEXT",
"code": 3002, "code": 3002,
"name": "文字", "name": "文字",
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"catch":true, "catch": true,
"checkLinkId": false, "checkLinkId": false,
"transformer": [] "transformer": []
}, },
"3003":{ "3003": {
"table": "OMDB_OBJECT_SYMBOL", "table": "OMDB_OBJECT_SYMBOL",
"code": 3003, "code": 3003,
"name": "符号", "name": "符号",
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"catch":true, "catch": true,
"transformer": [] "transformer": []
}, },
"3004":{ "3004": {
"table": "OMDB_OBJECT_ARROW", "table": "OMDB_OBJECT_ARROW",
"code": 3004, "code": 3004,
"name": "箭头", "name": "箭头",
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"catch":true, "catch": true,
"transformer": [ "transformer": [
{ {
"k": "geometry", "k": "geometry",
@ -244,14 +244,14 @@
} }
] ]
}, },
"3005":{ "3005": {
"table": "OMDB_TRAFFIC_SIGN", "table": "OMDB_TRAFFIC_SIGN",
"code": 3005, "code": 3005,
"name": "交通标牌", "name": "交通标牌",
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
"is3D": true, "is3D": true,
"catch":true, "catch": true,
"transformer": [ "transformer": [
{ {
"k": "geometry", "k": "geometry",
@ -261,12 +261,12 @@
} }
] ]
}, },
"3006":{ "3006": {
"table": "OMDB_POLE", "table": "OMDB_POLE",
"code": 3006, "code": 3006,
"name": "杆状物", "name": "杆状物",
"is3D": true, "is3D": true,
"catch":true, "catch": true,
"filterData": true, "filterData": true,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
@ -279,39 +279,39 @@
} }
] ]
}, },
"3012":{ "3012": {
"table": "OMDB_FILL_AREA", "table": "OMDB_FILL_AREA",
"code": 3012, "code": 3012,
"name": "导流区", "name": "导流区",
"catch":true, "catch": true,
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20 "zoomMax": 20
}, },
"3014":{ "3014": {
"table": "OMDB_CROSS_WALK", "table": "OMDB_CROSS_WALK",
"code": 3014, "code": 3014,
"name": "人行横道", "name": "人行横道",
"catch":true, "catch": true,
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20 "zoomMax": 20
}, },
"3016":{ "3016": {
"table": "OMDB_OBJECT_STOPLOCATION", "table": "OMDB_OBJECT_STOPLOCATION",
"code": 3016, "code": 3016,
"name": "停止位置", "name": "停止位置",
"checkLinkId": false, "checkLinkId": false,
"filterData": true, "filterData": true,
"zoomMin": 18, "zoomMin": 18,
"catch":true, "catch": true,
"zoomMax": 20 "zoomMax": 20
}, },
"3027":{ "3027": {
"table": "OMDB_OBJECT_REFUGE_ISLAND", "table": "OMDB_OBJECT_REFUGE_ISLAND",
"code": 3027, "code": 3027,
"name": "路口内交通岛", "name": "路口内交通岛",
"catch":true, "catch": true,
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20 "zoomMax": 20
@ -322,7 +322,7 @@
"name": "路口", "name": "路口",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"catch":true, "catch": true,
"transformer": [ "transformer": [
{ {
"k": "geometry", "k": "geometry",
@ -336,7 +336,7 @@
"table": "OMDB_SPEEDLIMIT", "table": "OMDB_SPEEDLIMIT",
"code": 4002, "code": 4002,
"name": "常规点限速", "name": "常规点限速",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -354,11 +354,11 @@
} }
] ]
}, },
"4003":{ "4003": {
"table": "OMDB_SPEEDLIMIT_COND", "table": "OMDB_SPEEDLIMIT_COND",
"code": 4003, "code": 4003,
"name": "条件点限速", "name": "条件点限速",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -370,11 +370,11 @@
} }
] ]
}, },
"4004":{ "4004": {
"table": "OMDB_SPEEDLIMIT_VAR", "table": "OMDB_SPEEDLIMIT_VAR",
"code": 4004, "code": 4004,
"name": "可变点限速", "name": "可变点限速",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -404,8 +404,8 @@
"name": "普通交限", "name": "普通交限",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"filterData":true, "filterData": true,
"catch":true, "catch": true,
"transformer": [ "transformer": [
{ {
"k": "geometry", "k": "geometry",
@ -439,11 +439,11 @@
} }
] ]
}, },
"4009":{ "4009": {
"table": "OMDB_WARNINGSIGN", "table": "OMDB_WARNINGSIGN",
"code": 4009, "code": 4009,
"name": "警示信息", "name": "警示信息",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -473,11 +473,11 @@
} }
] ]
}, },
"4010":{ "4010": {
"table": "OMDB_ELECTRONICEYE", "table": "OMDB_ELECTRONICEYE",
"code": 4010, "code": 4010,
"name": "电子眼", "name": "电子眼",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -511,7 +511,7 @@
"table": "OMDB_TRAFFICLIGHT", "table": "OMDB_TRAFFICLIGHT",
"code": 4022, "code": 4022,
"name": "交通灯", "name": "交通灯",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -521,17 +521,17 @@
"table": "OMDB_TOLLGATE", "table": "OMDB_TOLLGATE",
"code": 4023, "code": 4023,
"name": "收费站", "name": "收费站",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
] ]
}, },
"4601":{ "4601": {
"table": "OMDB_LANEINFO", "table": "OMDB_LANEINFO",
"code": 4601, "code": 4601,
"name": "车信", "name": "车信",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"transformer": [ "transformer": [
@ -555,11 +555,11 @@
} }
] ]
}, },
"5001":{ "5001": {
"table": "OMDB_LANE_LINK_LG", "table": "OMDB_LANE_LINK_LG",
"code": 5001, "code": 5001,
"name": "车道中心线", "name": "车道中心线",
"catch":false, "catch": false,
"checkLinkId": false, "checkLinkId": false,
"zoomMin": 18, "zoomMin": 18,
"zoomMax": 20, "zoomMax": 20,
@ -576,13 +576,13 @@
}, },
{ {
"tableGroupName": "道路形态", "tableGroupName": "道路形态",
"tableMap" : { "tableMap": {
"2004": { "2004": {
"table": "OMDB_LINK_ATTRIBUTE", "table": "OMDB_LINK_ATTRIBUTE",
"code": 2004, "code": 2004,
"name": "道路属性", "name": "道路属性",
"existSubCode": true, "existSubCode": true,
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 20, "zoomMax": 20,
"transformer": [ "transformer": [
@ -616,17 +616,17 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
}, },
"2204":{ "2204": {
"table": "OMDB_ROUNDABOUT", "table": "OMDB_ROUNDABOUT",
"code": 2204, "code": 2204,
"name": "环岛", "name": "环岛",
"catch":true, "catch": true,
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"transformer": [ "transformer": [
] ]
}, },
"2205":{ "2205": {
"table": "OMDB_LINK_FORM1", "table": "OMDB_LINK_FORM1",
"code": 2205, "code": 2205,
"name": "道路形态1", "name": "道路形态1",
@ -634,7 +634,7 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
}, },
"2206":{ "2206": {
"table": "OMDB_LINK_FORM2", "table": "OMDB_LINK_FORM2",
"code": 2206, "code": 2206,
"existSubCode": true, "existSubCode": true,
@ -642,7 +642,6 @@
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17 "zoomMax": 17
} }
} }
} }
] ]

View File

@ -37,7 +37,9 @@ import org.locationtech.jts.geom.LineString
import org.locationtech.jts.geom.MultiLineString import org.locationtech.jts.geom.MultiLineString
import org.spatialite.database.SQLiteDatabase import org.spatialite.database.SQLiteDatabase
import java.io.File import java.io.File
import java.util.*
import javax.inject.Inject import javax.inject.Inject
import kotlin.collections.HashMap
import kotlin.streams.toList import kotlin.streams.toList
/** /**
@ -155,7 +157,7 @@ class ImportOMDBHelper @AssistedInject constructor(
.directory(currentInstallTaskFolder) .directory(currentInstallTaskFolder)
.name("OMQS.realm") .name("OMQS.realm")
.encryptionKey(Constant.PASSWORD) .encryptionKey(Constant.PASSWORD)
.allowQueriesOnUiThread(true) // .allowQueriesOnUiThread(true)
.schemaVersion(2) .schemaVersion(2)
.build() .build()
val unZipFolder = File(omdbZipFile.parentFile, "result") val unZipFolder = File(omdbZipFile.parentFile, "result")
@ -181,28 +183,27 @@ class ImportOMDBHelper @AssistedInject constructor(
var tableImportTime = System.currentTimeMillis() var tableImportTime = System.currentTimeMillis()
//总表要素统计时间 //总表要素统计时间
var dataImportTime = System.currentTimeMillis() var dataImportTime = System.currentTimeMillis()
val realm = Realm.getInstance(currentInstallTaskConfig)
Realm.getInstance(currentInstallTaskConfig).beginTransaction() realm.beginTransaction()
for (importConfig in importConfigList) { for (importConfig in importConfigList) {
tableNum += importConfig.tableMap.size tableNum += importConfig.tableMap.size
} }
//缓存任务link信息便于下面与数据进行任务link匹配 //缓存任务link信息便于下面与数据进行任务link匹配
val hashMap: HashMap<Long, HadLinkDvoBean> = HashMap<Long, HadLinkDvoBean>() val hashMap: HashMap<Long, HadLinkDvoBean> = HashMap<Long, HadLinkDvoBean>()
val lineList = arrayOfNulls<LineString>(task.hadLinkDvoList.size) // val lineList = arrayOfNulls<LineString>(task.hadLinkDvoList.size)
var index = 0 // var index = 0
task.hadLinkDvoList.forEach { task.hadLinkDvoList.forEach {
hashMap[it.linkPid.toLong()] = it hashMap[it.linkPid.toLong()] = it
lineList[index] = GeometryTools.createGeometry(it.geometry) as LineString // lineList[index] = GeometryTools.createGeometry(it.geometry) as LineString
index++ // index++
} }
val resHashMap: HashMap<String, RenderEntity> = val resHashMap: HashMap<String, RenderEntity> =
HashMap<String, RenderEntity>() //define empty hashmap HashMap<String, RenderEntity>() //define empty hashmap
try { try {
var multipLine = MultiLineString(lineList, GeometryFactory()) // var multipLine = MultiLineString(lineList, GeometryFactory())
// 遍历解压后的文件,读取该数据返回 // 遍历解压后的文件,读取该数据返回
@ -259,13 +260,14 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.zoomMin = map["qi_zoomMin"].toString().toInt() renderEntity.zoomMin = map["qi_zoomMin"].toString().toInt()
renderEntity.zoomMax = map["qi_zoomMax"].toString().toInt() renderEntity.zoomMax = map["qi_zoomMax"].toString().toInt()
// 在外层记录当前数据的linkPid // 在外层记录当前数据的linkPid
if (renderEntity.properties.containsKey("linkPid")) { if (map.containsKey("linkPid")) {
renderEntity.linkPid = renderEntity.linkPid =
renderEntity.properties["linkPid"]?.split(",")?.get(0) map["linkPid"].toString().split(",")
?.get(0)
.toString() .toString()
} else if (renderEntity.properties.containsKey("linkList")){ } else if (map.containsKey("linkList")) {
val linkList = val linkList =
renderEntity.properties["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,
@ -774,13 +776,18 @@ class ImportOMDBHelper @AssistedInject constructor(
if (renderEntity.linkRelation == null) { if (renderEntity.linkRelation == null) {
renderEntity.linkRelation = LinkRelation() renderEntity.linkRelation = LinkRelation()
} }
renderEntity.linkRelation!!.sNodeId = renderEntity.properties["snodePid"] renderEntity.linkRelation!!.sNodeId =
renderEntity.linkRelation!!.eNodeId = renderEntity.properties["enodePid"] renderEntity.properties["snodePid"]
renderEntity.linkRelation!!.eNodeId =
renderEntity.properties["enodePid"]
// 同时尝试更新RD_link的relation记录中的名称字段
renderEntity.linkRelation!!.linkPid =
renderEntity.properties["linkPid"]
?: UUID.randomUUID().toString()
} }
Log.d("ImportOMDBHelper", "解析===1insert") Log.d("ImportOMDBHelper", "解析===1insert")
Realm.getInstance(currentInstallTaskConfig) realm.insert(renderEntity)
.insert(renderEntity)
Log.d("ImportOMDBHelper", "解析===2insert") Log.d("ImportOMDBHelper", "解析===2insert")
} }
if (currentConfig.code == DataCodeEnum.OMDB_RD_LINK.code.toInt()) { if (currentConfig.code == DataCodeEnum.OMDB_RD_LINK.code.toInt()) {
@ -805,30 +812,33 @@ class ImportOMDBHelper @AssistedInject constructor(
) )
elementIndex = 0 elementIndex = 0
tableImportTime = System.currentTimeMillis() tableImportTime = System.currentTimeMillis()
if (insertIndex % 20000 == 0) { if (insertIndex % 20000 == 0 || currentEntry.value.table == DataCodeEnum.OMDB_RD_LINK.name) {
Log.d( Log.d(
"ImportOMDBHelper", "ImportOMDBHelper",
"表解析===结束用时时间===事物开始" "表解析===结束用时时间===事物开始"
) )
Realm.getInstance(currentInstallTaskConfig).commitTransaction() realm.commitTransaction()
Realm.getInstance(currentInstallTaskConfig).beginTransaction() realm.refresh()
realm.beginTransaction()
Log.d( Log.d(
"ImportOMDBHelper", "ImportOMDBHelper",
"表解析===结束用时时间===事物结束" "表解析===结束用时时间===事物结束"
) )
} }
} }
} }
Realm.getInstance(currentInstallTaskConfig).commitTransaction() realm.commitTransaction()
Realm.getInstance(currentInstallTaskConfig).close() realm.close()
Log.d( Log.d(
"ImportOMDBHelper", "ImportOMDBHelper",
"表解析===结束用时时间${(System.currentTimeMillis() - dataImportTime)}===$dataIndex===插入$insertIndex" "表解析===结束用时时间${(System.currentTimeMillis() - dataImportTime)}===$dataIndex===插入$insertIndex"
) )
Log.e("qj", "安装结束") Log.e("qj", "安装结束")
} catch (e: Exception) { } catch (e: Exception) {
if (Realm.getInstance(currentInstallTaskConfig).isInTransaction) { if (realm.isInTransaction) {
Realm.getInstance(currentInstallTaskConfig).cancelTransaction() realm.cancelTransaction()
realm.close()
} }
throw e throw e
} }

View File

@ -15,6 +15,7 @@ import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.io.WKTWriter import org.locationtech.jts.io.WKTWriter
import org.oscim.core.GeoPoint import org.oscim.core.GeoPoint
import java.util.*
class ImportPreProcess { class ImportPreProcess {
@ -582,13 +583,6 @@ class ImportPreProcess {
} else { } else {
renderEntity.properties["name"] = "" renderEntity.properties["name"] = ""
} }
// 同时尝试更新RD_link的relation记录中的名称字段
val rdLinkEntity = queryRdLink(renderEntity.properties["linkPid"]!!)
if (rdLinkEntity?.linkRelation == null) {
rdLinkEntity?.linkRelation = LinkRelation()
}
rdLinkEntity?.linkRelation?.linkName = renderEntity.properties["name"]
Realm.getInstance(Constant.currentInstallTaskConfig).insertOrUpdate(rdLinkEntity)
} }
/** /**

View File

@ -178,7 +178,8 @@ class RealmOperateHelper() {
) )
val realm = getRealmDefaultInstance() val realm = getRealmDefaultInstance()
try { try {
val realmList = realm.where(HadLinkDvoBean::class.java).equalTo("taskId", taskId).findAll() val realmList =
realm.where(HadLinkDvoBean::class.java).equalTo("taskId", taskId).findAll()
var linkBean: HadLinkDvoBean? = null var linkBean: HadLinkDvoBean? = null
var nearLast: Double = 99999.99 var nearLast: Double = 99999.99
for (link in realmList) { for (link in realmList) {
@ -333,7 +334,7 @@ class RealmOperateHelper() {
val result = mutableListOf<RenderEntity>() val result = mutableListOf<RenderEntity>()
val realmList = getSelectTaskRealmTools(realm, RenderEntity::class.java, false) val realmList = getSelectTaskRealmTools(realm, RenderEntity::class.java, false)
.notEqualTo("table", DataCodeEnum.OMDB_RD_LINK.name) .notEqualTo("table", DataCodeEnum.OMDB_RD_LINK.name)
.equalTo("properties['${LinkTable.linkPid}']", linkPid) .equalTo("linkPid", linkPid)
.findAll() .findAll()
result.addAll(realm.copyFromRealm(realmList)) result.addAll(realm.copyFromRealm(realmList))
return result return result

View File

@ -816,8 +816,12 @@ class MainViewModel @Inject constructor(
val newLineString = GeometryTools.createLineString(linePoints) val newLineString = GeometryTools.createLineString(linePoints)
linkId?.let { linkId?.let {
val time = System.currentTimeMillis()
val elementList = realmOperateHelper.queryLinkByLinkPid(realm, it) val elementList = realmOperateHelper.queryLinkByLinkPid(realm, it)
Log.e("jingo", "捕捉到数据 ${elementList.size}") Log.e(
"jingo",
"捕捉到数据 ${elementList.size}${System.currentTimeMillis() - time}"
)
for (element in elementList) { for (element in elementList) {
if (element.code == DataCodeEnum.OMDB_LINK_NAME.code) { if (element.code == DataCodeEnum.OMDB_LINK_NAME.code) {
hisRoadName = true hisRoadName = true

View File

@ -81,11 +81,11 @@ class NaviEngine(
/** /**
* 要查询的link基本信息列表 * 要查询的link基本信息列表
*/ */
private val QUERY_KEY_LINK_INFO_LIST = arrayOf( // private val QUERY_KEY_LINK_INFO_LIST = arrayOf(
DataCodeEnum.OMDB_RD_LINK.name, // DataCodeEnum.OMDB_RD_LINK.name,
DataCodeEnum.OMDB_LINK_DIRECT.name, // DataCodeEnum.OMDB_LINK_DIRECT.name,
DataCodeEnum.OMDB_LINK_NAME.name, // DataCodeEnum.OMDB_LINK_NAME.name,
) // )
// /** // /**
// * 偏离距离 单位:米 // * 偏离距离 单位:米
@ -215,62 +215,56 @@ class NaviEngine(
) )
route.pointList = GeometryTools.getGeoPoints(link.geometry) route.pointList = GeometryTools.getGeoPoints(link.geometry)
var time = System.currentTimeMillis()
val res = realm.where(RenderEntity::class.java)
.equalTo("table", DataCodeEnum.OMDB_RD_LINK.name).equalTo("linkPid", link.linkPid)
.findFirst()
val res = realm.where(RenderEntity::class.java).`in`("table", QUERY_KEY_LINK_INFO_LIST) Log.e("jingo","查询link时间 ${System.currentTimeMillis() - time}")
.equalTo("properties['linkPid']", link.linkPid).findAll()
var bHasNode = false if (res?.linkRelation != null) {
var bHasDir = false if (res.linkRelation!!.sNodeId == null) {
var bHasName = false callback.planningPathStatus(
if (res != null) { NaviStatus.NAVI_STATUS_PATH_ERROR_NODE
for (entity in res) { )
when (entity.code) { return
DataCodeEnum.OMDB_RD_LINK.code -> {
bHasNode = true
val snodePid = entity.properties["snodePid"]
if (snodePid != null) {
route.sNode = snodePid
} else { } else {
bHasNode = false route.sNode = res.linkRelation!!.sNodeId!!
} }
val enodePid = entity.properties["enodePid"] if (res.linkRelation!!.eNodeId == null) {
if (enodePid != null) { callback.planningPathStatus(
route.eNode = enodePid NaviStatus.NAVI_STATUS_PATH_ERROR_NODE
)
return
} else { } else {
bHasNode = false route.eNode = res.linkRelation!!.eNodeId!!
} }
}
DataCodeEnum.OMDB_LINK_DIRECT.code -> { route.direct = res.linkRelation!!.direct
val direct = entity.properties["direct"] // route.name = res.linkRelation!!.linkName
if (direct != null) { time = System.currentTimeMillis()
bHasDir = true val otherLinks = realm.where(RenderEntity::class.java)
route.direct = direct.toInt() .equalTo("table", DataCodeEnum.OMDB_RD_LINK.name)
} .notEqualTo("linkPid", route.linkId).beginGroup()
} .`in`("linkRelation.sNodeId", arrayOf(route.sNode, route.eNode)).or()
DataCodeEnum.OMDB_LINK_NAME.code -> { .`in`("linkRelation.eNodeId", arrayOf(route.sNode, route.eNode)).endGroup()
bHasName = true .findAll()
route.name = realm.copyFromRealm(entity) Log.e("jingo","拓扑道路时间 ${System.currentTimeMillis() - time}${otherLinks.size}")
} } else {
}
}
}
if (!bHasNode) {
callback.planningPathStatus( callback.planningPathStatus(
NaviStatus.NAVI_STATUS_PATH_ERROR_NODE NaviStatus.NAVI_STATUS_PATH_ERROR_NODE
) )
return return
} }
if (!bHasDir) {
callback.planningPathStatus(
NaviStatus.NAVI_STATUS_PATH_ERROR_DIRECTION
)
return
}
pathList.add(route) pathList.add(route)
} }
//用来存储最终的导航路径 //用来存储最终的导航路径
val newRouteList = mutableListOf<NaviRoute>() val newRouteList = mutableListOf<NaviRoute>()
//比对路径排序用的 //比对路径排序用的
val tempRouteList = pathList.toMutableList() val tempRouteList = pathList.toMutableList()
//先找到一根有方向的link确定起终点 //先找到一根有方向的link确定起终点
var routeStart: NaviRoute? = null var routeStart: NaviRoute? = null
for (i in tempRouteList.indices) { for (i in tempRouteList.indices) {
@ -290,7 +284,7 @@ class NaviEngine(
var sNode = "" var sNode = ""
var eNode = "" var eNode = ""
//如果sNodeeNode是顺方向geometry 不动,否则反转 //如果sNodeeNode是顺方向geometry 不动,否则反转
if (routeStart.direct == 3) { if (routeStart.direct == 3) {
routeStart.pointList.reverse() routeStart.pointList.reverse()
sNode = routeStart.eNode sNode = routeStart.eNode
@ -355,14 +349,13 @@ class NaviEngine(
} }
val itemMap: MutableMap<GeoPoint, MutableList<RenderEntity>> = mutableMapOf() val itemMap: MutableMap<GeoPoint, MutableList<RenderEntity>> = mutableMapOf()
//查询每根link上的关联要素 //查询每根link上的关联要素
for (route in newRouteList) { for (route in newRouteList) {
itemMap.clear() itemMap.clear()
//常规点限速 //常规点限速
val res = realm.where(RenderEntity::class.java) val res =
.equalTo("properties['linkPid']", route.linkId).and().`in`( realm.where(RenderEntity::class.java).equalTo("linkPid", route.linkId).and().`in`(
"table", "table", QUERY_KEY_ITEM_LIST
QUERY_KEY_ITEM_LIST
).findAll() ).findAll()
if (res.isNotEmpty()) { if (res.isNotEmpty()) {
// Log.e("jingo", "道路查询预警要素 ${route.linkId} ${res.size}条数据") // Log.e("jingo", "道路查询预警要素 ${route.linkId} ${res.size}条数据")
@ -541,8 +534,7 @@ class NaviEngine(
// if (route.itemList != null) { // if (route.itemList != null) {
// Log.e("jingo", "${route.linkId}我有${route.itemList!!.size}个要素 ") // Log.e("jingo", "${route.linkId}我有${route.itemList!!.size}个要素 ")
// } // }
if (route.indexInPath < routeIndex) if (route.indexInPath < routeIndex) continue
continue
if (route.indexInPath == routeIndex) { if (route.indexInPath == routeIndex) {
currentRoute = route currentRoute = route
} }

View File

@ -8,6 +8,7 @@ import io.realm.RealmDictionary
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmSet import io.realm.RealmSet
import io.realm.annotations.Ignore import io.realm.annotations.Ignore
import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import org.locationtech.jts.geom.Coordinate import org.locationtech.jts.geom.Coordinate
@ -21,10 +22,12 @@ import java.util.*
@Parcelize @Parcelize
open class LinkRelation() : RealmObject(), Parcelable { open class LinkRelation() : RealmObject(), Parcelable {
@PrimaryKey @PrimaryKey
var id: String = UUID.randomUUID().toString() // id var linkPid:String = UUID.randomUUID().toString()
@Index
var sNodeId: String? = null var sNodeId: String? = null
@Index
var eNodeId: String? = null var eNodeId: String? = null
var linkName: String? = null
var direct: Int = 0 var direct: Int = 0
constructor(direct: Int) : this() { constructor(direct: Int) : this() {

View File

@ -8,6 +8,7 @@ import io.realm.RealmDictionary
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmSet import io.realm.RealmSet
import io.realm.annotations.Ignore import io.realm.annotations.Ignore
import io.realm.annotations.Index
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import org.locationtech.jts.geom.Coordinate import org.locationtech.jts.geom.Coordinate
@ -56,13 +57,16 @@ open class RenderEntity() : RealmObject(), Parcelable {
return field return field
} }
var properties: RealmDictionary<String> = RealmDictionary() var properties: RealmDictionary<String> = RealmDictionary()
@Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
@Ignore
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码 var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
var taskId: Int = 0 //任务ID var taskId: Int = 0 //任务ID
var zoomMin: Int = 18 //显示最小级别 var zoomMin: Int = 18 //显示最小级别
var zoomMax: Int = 23 //显示最大级别 var zoomMax: Int = 23 //显示最大级别
var enable:Int = 0 // 默认0不是显示 1为渲染显示 2为常显 var enable:Int = 0 // 默认0不是显示 1为渲染显示 2为常显
var catchEnable:Int = 0 // 0不捕捉 1捕捉 var catchEnable:Int = 0 // 0不捕捉 1捕捉
@Index
lateinit var linkPid: String // RenderEntity关联的linkPid集合(可能会关联多个) lateinit var linkPid: String // RenderEntity关联的linkPid集合(可能会关联多个)
var linkRelation: LinkRelation? = null var linkRelation: LinkRelation? = null