优化数据安装性能,更换阿里Json库

This commit is contained in:
qiji4215
2023-10-30 16:40:27 +08:00
parent 707f3b8961
commit 584eea6928
12 changed files with 191 additions and 43 deletions

View File

@@ -40,6 +40,11 @@ class Constant {
*/
lateinit var USER_DATA_PATH: String
/**
* 用户数据安装标识
*/
var INSTALL_DATA: Boolean = false
/**
* 轨迹渲染个数统计
*/

View File

@@ -3,6 +3,7 @@ package com.navinfo.omqs.db
import android.content.Context
import android.database.Cursor.*
import android.util.Log
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.ZipUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
@@ -31,6 +32,7 @@ import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.sync.Mutex
import org.spatialite.database.SQLiteDatabase
import sun.misc.BASE64Encoder
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
@@ -192,6 +194,8 @@ class ImportOMDBHelper @AssistedInject constructor(
//协程池
val listJob = mutableListOf<Job>()
try {
CMLog.writeLogtoFile(ImportOMDBHelper::class.java.name, "数据安装", "开始安装数据")
Constant.INSTALL_DATA = true
for (importConfig in importConfigList) {
for ((index, currentEntry) in importConfig.tableMap.entries.withIndex()) {
if (currentEntry.value.isDependOnOtherTable) {
@@ -240,9 +244,14 @@ class ImportOMDBHelper @AssistedInject constructor(
)
}
Log.e("jingo", "安装结束")
CMLog.writeLogtoFile(ImportOMDBHelper::class.java.name, "数据安装", "安装结束")
} catch (e: Exception) {
Log.e("jingo", "安装报错1 ${e.message}")
return false
}finally {
Constant.INSTALL_DATA = false
}
return true
}
@@ -261,11 +270,9 @@ class ImportOMDBHelper @AssistedInject constructor(
//单个表要素统计
var elementIndex = 0
val currentConfig = currentEntry.value
// CMLog.writeLogtoFile(
// ImportOMDBHelper::class.java.name,
// "importOmdbZipFile",
// "${currentConfig.table}开始"
// )
CMLog.writeLogtoFile(ImportOMDBHelper::class.java.name, "importOmdbZipFile", "${currentConfig.table}开始")
try {
var realm: Realm? = null
if (!isEmit) {
@@ -687,7 +694,7 @@ class ImportOMDBHelper @AssistedInject constructor(
renderEntity.properties.remove("shapeList")
}
renderEntity.propertiesDb = DeflaterUtil.compress(gson.toJson(renderEntity.properties).toByteArray())
renderEntity.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(renderEntity.properties))
listRenderEntity.add(renderEntity)
}
@@ -712,11 +719,8 @@ class ImportOMDBHelper @AssistedInject constructor(
}
line = bufferedReader.readLine()
}
// CMLog.writeLogtoFile(
// ImportOMDBHelper::class.java.name,
// "importOmdbZipFile",
// "结束===总量$elementIndex"
// )
CMLog.writeLogtoFile(ImportOMDBHelper::class.java.name, "importOmdbZipFile", "${currentConfig.table}结束===总量$elementIndex")
if (isEmit) {
f.send(listRenderEntity)

View File

@@ -1,6 +1,7 @@
package com.navinfo.omqs.db
import android.util.Log
import com.alibaba.fastjson.JSON
import com.google.gson.Gson
import com.navinfo.collect.library.data.entity.LinkRelation
import com.navinfo.collect.library.data.entity.ReferenceEntity
@@ -240,7 +241,7 @@ class ImportPreProcess {
startEndReference.properties["qi_table"] = renderEntity.table
startEndReference.properties["type"] = "s_2_e"
val listResult = mutableListOf<ReferenceEntity>()
startEndReference.propertiesDb = DeflaterUtil.compress(gson.toJson(startEndReference.properties).toByteArray())
startEndReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(startEndReference.properties))
listResult.add(startEndReference)
insertData(listResult)
}
@@ -342,7 +343,7 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===${startReference.geometry}")
startReference.properties["geometry"] = startReference.geometry
startReference.propertiesDb = DeflaterUtil.compress(gson.toJson(startReference.properties).toByteArray())
startReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(startReference.properties))
listResult.add(startReference)
Log.e("qj", "generateS2EReferencePoint===1")
@@ -377,7 +378,7 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===e_2_p${renderEntity.name}")
}
endReference.properties["geometry"] = endReference.geometry
endReference.propertiesDb = DeflaterUtil.compress(gson.toJson(endReference.properties).toByteArray())
endReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(endReference.properties))
listResult.add(endReference)
Log.e("qj", "generateS2EReferencePoint===4")
insertData(listResult)
@@ -475,9 +476,7 @@ class ImportPreProcess {
WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd)))
angleReference.properties["qi_table"] = renderEntity.table
angleReference.properties["type"] = "angle"
angleReference.propertiesDb = DeflaterUtil.compress(
gson.toJson(angleReference.properties).toByteArray()
)
angleReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(angleReference.properties))
listResult.add(angleReference)
}
insertData(listResult)
@@ -634,7 +633,7 @@ class ImportPreProcess {
referenceEntity.properties["symbol"] =
"assets:omdb/4601/${type}/1301_${referenceEntity.properties["currentDirect"]}.svg"
Log.d("unpackingLaneInfo", referenceEntity.properties["symbol"].toString())
referenceEntity.propertiesDb = DeflaterUtil.compress(gson.toJson(referenceEntity.properties).toByteArray())
referenceEntity.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(referenceEntity.properties))
listResult.add(referenceEntity)
}
insertData(listResult)
@@ -744,7 +743,7 @@ class ImportPreProcess {
angleReference.taskId = renderEntity.taskId
angleReference.enable = renderEntity.enable
val listResult = mutableListOf<ReferenceEntity>()
angleReference.propertiesDb = DeflaterUtil.compress(gson.toJson(angleReference.properties).toByteArray())
angleReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(angleReference.properties))
listResult.add(angleReference)
insertData(listResult)
}
@@ -775,7 +774,7 @@ class ImportPreProcess {
GeometryTools.createGeometry(nodeJSONObject["geometry"].toString()).toString()
intersectionReference.properties["qi_table"] = renderEntity.table
intersectionReference.properties["type"] = "node"
intersectionReference.propertiesDb = DeflaterUtil.compress(gson.toJson(intersectionReference.properties).toByteArray())
intersectionReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(intersectionReference.properties))
listResult.add(intersectionReference)
}
insertData(listResult)
@@ -944,7 +943,7 @@ class ImportPreProcess {
dynamicSrcReference.properties["type"] = "dynamicSrc"
val code = renderEntity.properties[codeName]
dynamicSrcReference.properties["src"] = "${prefix}${code}${suffix}"
dynamicSrcReference.propertiesDb = DeflaterUtil.compress(gson.toJson(dynamicSrcReference.properties).toByteArray())
dynamicSrcReference.propertiesDb = DeflaterUtil.zipString(JSON.toJSONString(dynamicSrcReference.properties))
listResult.add(dynamicSrcReference)
}
insertData(listResult)

File diff suppressed because one or more lines are too long

View File

@@ -292,6 +292,10 @@ class MainViewModel @Inject constructor(
object : OnGeoPointClickListener {
override fun onMapClick(tag: String, point: GeoPoint) {
if (tag == TAG) {
//数据安装时不允许操作数据
if(Constant.INSTALL_DATA){
return
}
if (bMeasuringTool) {
mapController.measureLayerHandler.addPoint(measuringType, point)
} else {