fix: 解决导入数据时将int类型转换为Double的问题
This commit is contained in:
@@ -111,47 +111,53 @@ class ImportOMDBHelper @AssistedInject constructor(@Assisted("context") val cont
|
||||
unZipFolder.mkdirs()
|
||||
// 开始解压zip文件
|
||||
val unZipFiles = ZipUtils.unzipFile(omdbZipFile, unZipFolder)
|
||||
// 将listResult数据插入到Realm数据库中
|
||||
Realm.getDefaultInstance().beginTransaction()
|
||||
// 遍历解压后的文件,读取该数据返回
|
||||
for ((index, currentConfig) in importConfig.tables.withIndex()) {
|
||||
val txtFile = unZipFiles.find {
|
||||
it.name == currentConfig.table
|
||||
}
|
||||
|
||||
val listResult: MutableList<Map<String, Any>> = mutableListOf()
|
||||
val listResult = mutableListOf<Map<String, Any?>>()
|
||||
currentConfig?.let {
|
||||
val list = FileIOUtils.readFile2List(txtFile, "UTF-8")
|
||||
if (list!=null) {
|
||||
// 将list数据转换为map
|
||||
for (line in list) {
|
||||
val map = gson.fromJson<Map<String, Any>>(line, object : TypeToken<MutableMap<String, Any>>() {}.type)
|
||||
val map = gson.fromJson<Map<String, Any?>>(line, object:TypeToken<Map<String, Any?>>(){}.getType())
|
||||
.toMutableMap()
|
||||
map["QItable"] = currentConfig.table
|
||||
map["QIname"] = currentConfig.name
|
||||
map["QIcode"] = currentConfig.code
|
||||
map["qi_table"] = currentConfig.table
|
||||
map["qi_name"] = currentConfig.name
|
||||
map["qi_code"] = currentConfig.code
|
||||
listResult.add(map)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将listResult数据插入到Realm数据库中
|
||||
Realm.getDefaultInstance().beginTransaction()
|
||||
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["QIcode"].toString().toInt()
|
||||
renderEntity.name = map["QIname"].toString()
|
||||
renderEntity.table = map["QItable"].toString()
|
||||
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 (entry in map) {
|
||||
renderEntity.properties[entry.key] = entry.value.toString()
|
||||
for ((key, value) in map) {
|
||||
when (value) {
|
||||
is String -> renderEntity.properties[key.toString()] = value
|
||||
is Int -> renderEntity.properties[key.toString()] = value.toInt().toString()
|
||||
is Double -> renderEntity.properties[key.toString()] = value.toDouble().toString()
|
||||
else -> renderEntity.properties[key.toString()] = value.toString()
|
||||
}
|
||||
}
|
||||
Realm.getDefaultInstance().insert(renderEntity)
|
||||
}
|
||||
Realm.getDefaultInstance().commitTransaction()
|
||||
// 1个文件发送一次flow流
|
||||
emit("${index+1}/${importConfig.tables.size}")
|
||||
}
|
||||
Realm.getDefaultInstance().commitTransaction()
|
||||
emit("finish")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user