优化数据安装性能,更换阿里Json库
This commit is contained in:
parent
707f3b8961
commit
584eea6928
@ -107,6 +107,7 @@ dependencies {
|
||||
// implementation 'javax.xml.stream:stax-api:1.0-2'
|
||||
// implementation 'com.bea.xml.stream:com.bea.xml.stream:1.0.0'
|
||||
implementation 'commons-io:commons-io:2.11.0'
|
||||
implementation 'com.alibaba:fastjson:1.2.73'
|
||||
|
||||
// 读取spatialite文件
|
||||
implementation 'com.github.sevar83:android-spatialite:2.0.1'
|
||||
|
@ -40,6 +40,11 @@ class Constant {
|
||||
*/
|
||||
lateinit var USER_DATA_PATH: String
|
||||
|
||||
/**
|
||||
* 用户数据安装标识
|
||||
*/
|
||||
var INSTALL_DATA: Boolean = false
|
||||
|
||||
/**
|
||||
* 轨迹渲染个数统计
|
||||
*/
|
||||
|
@ -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)
|
||||
|
@ -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
@ -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 {
|
||||
|
@ -120,6 +120,7 @@ dependencies {
|
||||
api 'org.locationtech.jts:jts-core:1.19.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'
|
||||
implementation 'com.squareup.okio:okio:3.3.0'
|
||||
implementation 'com.alibaba:fastjson:1.2.73'
|
||||
|
||||
implementation "com.fasterxml.jackson.core:jackson-annotations:2.9.9"
|
||||
implementation "com.fasterxml.jackson.core:jackson-core:2.9.9"
|
||||
|
@ -1558,11 +1558,6 @@
|
||||
<symbol repeat="false" repeat-start="0" repeat-gap="2000"
|
||||
src="@symbol" symbol-height="24" degree="90"></symbol>
|
||||
</m>
|
||||
<!-- 车信CLM -->
|
||||
<m v="OMDB_CLM_LANEINFO" >
|
||||
<symbol repeat="false" repeat-start="0" repeat-gap="2000"
|
||||
src="@symbol" symbol-height="24" degree="90"></symbol>
|
||||
</m>
|
||||
<!-- 杆状物 -->
|
||||
<m v="OMDB_POLE">
|
||||
<symbol src="assets:omdb/icon_pole_3006.svg" symbol-height="56" symbol-width="56"></symbol>
|
||||
|
@ -25,7 +25,7 @@ open class ReferenceEntity() : RealmObject() {
|
||||
@Ignore
|
||||
lateinit var name: String //要素名
|
||||
lateinit var table: String //要素表名
|
||||
var propertiesDb: ByteArray? = null
|
||||
var propertiesDb: String = ""
|
||||
var code: String = "0" // 要素编码
|
||||
|
||||
@Ignore
|
||||
@ -80,11 +80,11 @@ open class ReferenceEntity() : RealmObject() {
|
||||
@Ignore
|
||||
var properties: RealmDictionary<String> = RealmDictionary()
|
||||
get() {
|
||||
if (propertiesDb!=null && field.isEmpty()) {
|
||||
if (propertiesDb != null && propertiesDb!!.isNotEmpty() && field.isEmpty()) {
|
||||
try {
|
||||
val gson = Gson()
|
||||
val type = object : TypeToken<RealmDictionary<String>>() {}.type
|
||||
field = gson.fromJson(DeflaterUtil.decompress(propertiesDb).toString(), type)
|
||||
field = gson.fromJson(DeflaterUtil.unzipString(propertiesDb), type)
|
||||
} catch (e: Exception) {
|
||||
Log.e("jingo","ReferenceEntity 转 properties $e")
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package com.navinfo.collect.library.data.entity
|
||||
|
||||
import android.os.Parcelable
|
||||
import android.util.Log
|
||||
import com.alibaba.fastjson.JSON
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.navinfo.collect.library.system.Constant
|
||||
import com.navinfo.collect.library.utils.DeflaterUtil
|
||||
import com.navinfo.collect.library.utils.GeometryTools
|
||||
import com.navinfo.collect.library.utils.GeometryToolsKt
|
||||
@ -14,13 +14,8 @@ import io.realm.RealmObject
|
||||
import io.realm.RealmSet
|
||||
import io.realm.annotations.Ignore
|
||||
import io.realm.annotations.Index
|
||||
import io.realm.annotations.PrimaryKey
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.locationtech.jts.geom.Coordinate
|
||||
import org.locationtech.jts.geom.Geometry
|
||||
import org.oscim.core.MercatorProjection
|
||||
import java.util.*
|
||||
import java.util.zip.GZIPInputStream
|
||||
|
||||
/**
|
||||
* 渲染要素对应的实体
|
||||
@ -32,7 +27,7 @@ open class RenderEntity() : RealmObject(), Parcelable {
|
||||
lateinit var name: String //要素名
|
||||
lateinit var table: String //要素表名
|
||||
var code: String = "0" // 要素编码
|
||||
var propertiesDb: ByteArray? = null
|
||||
var propertiesDb: String = ""
|
||||
var geometry: String =
|
||||
"" // 要素渲染参考的geometry,该数据可能会在导入预处理环节被修改,原始geometry会保存在properties的geometry字段下
|
||||
get() {
|
||||
@ -83,11 +78,11 @@ open class RenderEntity() : RealmObject(), Parcelable {
|
||||
@Ignore
|
||||
var properties: RealmDictionary<String> = RealmDictionary()
|
||||
get() {
|
||||
if (propertiesDb != null && field.isEmpty()) {
|
||||
if (propertiesDb != null && propertiesDb!!.isNotEmpty()&& field.isEmpty()) {
|
||||
try {
|
||||
val gson = Gson()
|
||||
val type = object : TypeToken<RealmDictionary<String>>() {}.type
|
||||
field = gson.fromJson(DeflaterUtil.decompress(propertiesDb).toString(), type)
|
||||
field = gson.fromJson(DeflaterUtil.unzipString(propertiesDb), type)
|
||||
} catch (e: Exception) {
|
||||
Log.e("jingo","RenderEntity 转 properties $e")
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class OMDBReferenceDecoder extends TileDecoder {
|
||||
}
|
||||
} else if (geometry instanceof LineString) {
|
||||
//将车道中心进行转化面渲染
|
||||
if(layerName== DataCodeEnum.OMDB_LANE_LINK_LG.name()){
|
||||
if(layerName!=null&&layerName.equals(DataCodeEnum.OMDB_LANE_LINK_LG.name())){
|
||||
Log.e("qj","车道中心线转化开始");
|
||||
processPolygon((Polygon)GeometryTools.createGeometry(GeometryTools.computeLine(0.000035,0.000035,geometry.toString())));
|
||||
Log.e("qj","车道中心线转化结束");
|
||||
|
@ -4,8 +4,18 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
public class DeflaterUtil {
|
||||
/**
|
||||
* DeflaterUtils 压缩字符串
|
||||
*/
|
||||
|
||||
public class DeflaterUtil{
|
||||
|
||||
private DeflaterUtil() {
|
||||
|
||||
@ -13,6 +23,138 @@ public class DeflaterUtil {
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
/**
|
||||
* 压缩
|
||||
*/
|
||||
|
||||
public static String zipString(String unzipString) {
|
||||
|
||||
/*
|
||||
|
||||
* https://www.yiibai.com/javazip/javazip_deflater.html#article-start
|
||||
|
||||
* 0 ~ 9 压缩等级 低到高
|
||||
|
||||
* public static final int BEST_COMPRESSION = 9; 最佳压缩的压缩级别。
|
||||
|
||||
* public static final int BEST_SPEED = 1; 压缩级别最快的压缩。
|
||||
|
||||
* public static final int DEFAULT_COMPRESSION = -1; 默认压缩级别。
|
||||
|
||||
* public static final int DEFAULT_STRATEGY = 0; 默认压缩策略。
|
||||
|
||||
* public static final int DEFLATED = 8; 压缩算法的压缩方法(目前唯一支持的压缩方法)。
|
||||
|
||||
* public static final int FILTERED = 1; 压缩策略最适用于大部分数值较小且数据分布随机分布的数据。
|
||||
|
||||
* public static final int FULL_FLUSH = 3; 压缩刷新模式,用于清除所有待处理的输出并重置拆卸器。
|
||||
|
||||
* public static final int HUFFMAN_ONLY = 2; 仅用于霍夫曼编码的压缩策略。
|
||||
|
||||
* public static final int NO_COMPRESSION = 0; 不压缩的压缩级别。
|
||||
|
||||
* public static final int NO_FLUSH = 0; 用于实现最佳压缩结果的压缩刷新模式。
|
||||
|
||||
* public static final int SYNC_FLUSH = 2; 用于清除所有未决输出的压缩刷新模式; 可能会降低某些压缩算法的压缩率。
|
||||
|
||||
*/
|
||||
|
||||
//使用指定的压缩级别创建一个新的压缩器。
|
||||
|
||||
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
|
||||
|
||||
//设置压缩输入数据。
|
||||
|
||||
deflater.setInput(unzipString.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
//当被调用时,表示压缩应该以输入缓冲区的当前内容结束。
|
||||
|
||||
deflater.finish();
|
||||
|
||||
final byte[] bytes = new byte[256];
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
|
||||
|
||||
while (!deflater.finished()) {
|
||||
|
||||
//压缩输入数据并用压缩数据填充指定的缓冲区。
|
||||
|
||||
int length = deflater.deflate(bytes);
|
||||
|
||||
outputStream.write(bytes, 0, length);
|
||||
|
||||
}
|
||||
|
||||
deflater.end();
|
||||
|
||||
return Base64.encodeBase64String(outputStream.toByteArray());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压缩
|
||||
*/
|
||||
|
||||
public static String unzipString(String zipString) {
|
||||
|
||||
byte[] decode = Base64.decodeBase64(zipString);
|
||||
|
||||
//创建一个新的解压缩器 https://www.yiibai.com/javazip/javazip_inflater.html
|
||||
|
||||
Inflater inflater = new Inflater();
|
||||
|
||||
//设置解压缩的输入数据。
|
||||
|
||||
inflater.setInput(decode);
|
||||
|
||||
final byte[] bytes = new byte[256];
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
|
||||
|
||||
try {
|
||||
|
||||
//finished() 如果已到达压缩数据流的末尾,则返回true。
|
||||
|
||||
while (!inflater.finished()) {
|
||||
|
||||
//将字节解压缩到指定的缓冲区中。
|
||||
|
||||
int length = inflater.inflate(bytes);
|
||||
|
||||
outputStream.write(bytes, 0, length);
|
||||
|
||||
}
|
||||
|
||||
} catch (DataFormatException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
|
||||
} finally {
|
||||
|
||||
//关闭解压缩器并丢弃任何未处理的输入。
|
||||
|
||||
inflater.end();
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
return outputStream.toString("UTF-8");
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
|
Loading…
x
Reference in New Issue
Block a user