Merge branch 'master' of gitlab.navinfo.com:CollectVehicle/OneMapQS

 Conflicts:
	collect-library/src/main/java/com/navinfo/collect/FlutterBaseActivity.kt
	settings.gradle
This commit is contained in:
squallzhjch
2023-03-22 10:05:24 +08:00
19 changed files with 35 additions and 1106 deletions

View File

@@ -1,224 +0,0 @@
package com.navinfo.collect.library.data
import android.graphics.Point
import android.graphics.Rect
import android.util.Log
import android.view.WindowInsetsAnimation.Bounds
import com.baidu.ai.edge.ui.view.model.BasePolygonResultModel
import com.baidu.ai.edge.ui.view.model.OcrViewResultModel
import com.navinfo.collect.library.data.entity.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import org.json.JSONArray
import org.json.JSONObject
import java.io.BufferedWriter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.io.OutputStreamWriter
/**
* 和flutter层进行数据传递时的数据格式转换
*/
class DataConversion {
companion object {
/**
* 将数据转成map形式-传给flutter使用
*/
fun toElementMapList(list: List<Element>): List<Map<*, *>> {
val newList = mutableListOf<Map<*, *>>()
for (element in list) {
newList.add(element.toMap())
}
return newList
}
/**
* json转数据图层自定义子表的所有字段对象列表
* (现在用于从数据库中提取数据图层自定义表所有字段信息时,主要用于原生层)
*/
fun jsonToLayerItemsList(json: String): List<CustomLayerItem> {
val list = mutableListOf<CustomLayerItem>()
try {
val jsonArray = JSONArray(json)
for (i in 0 until jsonArray.length()) {
val itemObject = jsonArray.getJSONObject(i)
val itemMap = jsonToCustomLayerItem(itemObject)
list.add(itemMap);
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
}
return list
}
/**
* 数据图层子表字段配置转Map
* (主要原生层使用)
*/
fun customLayerItemsToMapList(list: List<CustomLayerItem>?): List<Map<*, *>> {
var newList = mutableListOf<Map<*, *>>()
if (list == null) {
return newList
}
for (item in list) {
newList.add(item.toMap())
}
return newList
}
/**
* 数据图层子表字段配置 json形式的数据 转成对象形式
* 原生层主要用json所以主要原生层使用
*/
private fun jsonToCustomLayerItem(itemObject: JSONObject): CustomLayerItem {
return CustomLayerItem(
key = itemObject.optString("key"),
title = itemObject.optString("title"),
type = DataLayerItemType.values()[itemObject.optInt("type")],
// nullable = itemObject.optBoolean("nullable"),
// primaryKey = itemObject.optBoolean("primaryKey"),
// value = itemObject.opt("value"),
// selectOptions = itemObject.optString("selectOptions"),
// isMainName = itemObject.optBoolean("isMainName"),
describe = itemObject.optString("describe"),
// checkManagerList = mutableListOf()
itemBean = ""
)
}
/**
* 数据图层子表字段配置转Map
* flutter层喜欢用map所以主要用于flutter和原生交互使用
*/
private fun jsonToCustomLayerItem(itemMap: Map<*, *>): CustomLayerItem {
val checkMapList = itemMap["checkMangerList"] as List<Map<*, *>>
val checkManagerList = mutableListOf<CheckManager>()
for (c in checkMapList) {
checkManagerList.add(
CheckManager(
id = (c["id"] as Int).toLong(),
type = c["type"] as Int,
tag = c["tag"] as String,
regexStr = c["regexStr"] as String
)
)
}
return CustomLayerItem(
key = itemMap["key"] as String,
title = itemMap["title"] as String,
type = DataLayerItemType.values()[itemMap["type"] as Int],
// nullable = itemMap["nullable"] as Boolean,
// primaryKey = itemMap["primaryKey"] as Boolean,
// value = itemMap["value"] as Any,
// selectOptions = itemMap["selectOptions"] as String,
// isMainName = itemMap["isMainName"] as Boolean,
describe = itemMap["describe"] as String,
// checkManagerList = checkManagerList
itemBean = ""
)
}
/**
* 数据图层 map形式的字段数据集合转成对象集合
* 主要用于flutter层与原生层数据交互时
*/
fun listMapToCustomLayerItemsList(itemList: List<Map<*, *>>): List<CustomLayerItem> {
val list = mutableListOf<CustomLayerItem>()
for (itemMap in itemList) {
list.add(jsonToCustomLayerItem(itemMap));
}
return list
}
// /**
// * layerManager转化成map
// */
// fun layerManagerToMap(
// layerManager: LayerManager,
// itemsMap: List<Map<String, *>>
// ): Map<*, *> {
// return mapOf("layerManager" to layerManager.toMap(), "itemsList" to itemsMap);
// }
/**
* 检查项转map给flutter
*/
fun toCheckManagerMapList(list: List<CheckManager>): List<Map<*, *>> {
val newList = mutableListOf<Map<*, *>>()
for (check in list) {
newList.add(
check.toMap()
)
}
return newList
}
fun toOcrList(
path: String,
basePolygonResultModels: List<BasePolygonResultModel>
): Map<*, *> {
val newList = mutableMapOf<String, Any>()
newList["photo_path"] = path
val list = mutableListOf<String>();
for (model in basePolygonResultModels) {
list.add(model.name)
}
newList["result"] = list
return newList
}
/**
* 将ocr识别结果返回给flutter
*/
suspend fun toFlutterOcrList(
list: List<Map<String, Any>>,
): List<Any> {
val listR = mutableListOf<Any>()
val job = MainScope().async(Dispatchers.IO) {
Log.e("jingo", "OCR图像识别写CSV文件 ${Thread.currentThread().name}")
for (item in list) {
if (item is Map) {
val map1 = mutableMapOf<String, Any>()
map1["path"] = item["path"]!!
map1["width"] = item["width"]!!
map1["height"] = item["height"]!!
var data = item["data"]
if (data is List<*>) {
val dataList = mutableListOf<Any>()
for (v in data) {
val map = mutableMapOf<String, Any>()
map["index"] = (v as OcrViewResultModel).index
map["bounds"] = rectToMap(v.bounds)
map["text"] = v.name
map["confidence"] = v.confidence
dataList.add(map)
}
map1["data"] = dataList
}
listR.add(map1)
}
}
}
job.await()
Log.e("jingo", "ORC 识别结果 ${listR.toString()}")
return listR
}
private fun rectToMap(list: List<Point>): List<List<Int>> {
val pointList = mutableListOf<List<Int>>()
for (point in list) {
val l = mutableListOf<Int>()
l.add(point.x)
l.add(point.y)
pointList.add(l)
}
return pointList
}
}
}

View File

@@ -1,33 +0,0 @@
package com.navinfo.collect.library.data
import android.content.Context
import com.navinfo.collect.FlutterBaseActivity
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
import com.navinfo.collect.library.data.handler.DataLayerHandler
import com.navinfo.collect.library.system.Constant
/**
* 地图控制器
*/
open class NIDataController(
context: Context,
activity: FlutterBaseActivity,
) {
protected val mContext = context
protected val mActivity = activity
internal val mDateBase: MapLifeDataBase = MapLifeDataBase.getDatabase(
context, "${Constant.ROOT_PATH}/coremap.db"
)
init {
RealmUtils.getInstance().init(mContext, Constant.ROOT_PATH, "hd-data")
}
protected val dataHandler: DataLayerHandler = DataLayerHandler(mContext, mDateBase);
open fun release() {
mDateBase.close()
}
}

View File

@@ -27,7 +27,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
* */
override fun parserGisFile(file: File): List<GeometryFeatureEntity> {
val geometryEntityList = ArrayList<GeometryFeatureEntity>()
if (!file?.isFile || !file.exists()) {
if (!file.isFile || !file.exists()) {
return geometryEntityList;
}
// 解析pbf文件
@@ -63,7 +63,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
* */
private fun parserRoadLink(roadLinkList: List<Roadlink.RoadLink>, file: File, layerName: String= "道路线", layerTableName: String = "ROAD_LINK"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (roadLinkList?.isEmpty()) {
if (roadLinkList.isEmpty()) {
return featureEntityList
}
for (roadLink in roadLinkList) {
@@ -81,7 +81,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
* */
private fun parserHadLaneLink(hadLaneLinkList: List<Hadlanelink.HadLaneLink>, file: File, layerName: String= "车道中心线", layerTableName: String = "HAD_LANE_LINK"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (hadLaneLinkList?.isEmpty()) {
if (hadLaneLinkList.isEmpty()) {
return featureEntityList
}
for (hadLaneLink in hadLaneLinkList) {
@@ -98,7 +98,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
* */
private fun parserSpeedLimitGen(speedLimitGenList: List<Rdspeedlimitgen.RdSpeedlimitGen>, file: File, layerName: String= "固定限速", layerTableName: String = "SPEED_LIMIT_GEN"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (speedLimitGenList?.isEmpty()) {
if (speedLimitGenList.isEmpty()) {
return featureEntityList
}
for (speedLimitGen in speedLimitGenList) {
@@ -116,7 +116,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
* */
private fun parserSpeedLimitDepend(speedLimitDenpendList: List<Rdspeedlimitdepend.RdSpeedlimitDepend>, file: File, layerName: String= "条件限速", layerTableName: String = "SPEED_LIMIT_DEPEND"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (speedLimitDenpendList?.isEmpty()) {
if (speedLimitDenpendList.isEmpty()) {
return featureEntityList
}
for (speedLimitDepend in speedLimitDenpendList) {
@@ -135,7 +135,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserSpeedLimitVar(speedLimitVarList: List<Rdspeedlimitvar.RdSpeedlimitVar>, file: File,
layerName: String= "可变限速", layerTableName: String = "SPEED_LIMIT_VAR"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (speedLimitVarList?.isEmpty()) {
if (speedLimitVarList.isEmpty()) {
return featureEntityList
}
for (speedLimitVar in speedLimitVarList) {
@@ -154,7 +154,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserHadLaneMarkLink(hadLaneMarkLinkList: List<Hadlanemarklink.HadLaneMarkLink>, file: File,
layerName: String= "车道边线", layerTableName: String = "HAD_LANE_MARK_LINK"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (hadLaneMarkLinkList?.isEmpty()) {
if (hadLaneMarkLinkList.isEmpty()) {
return featureEntityList
}
for (hadLaneMarkLink in hadLaneMarkLinkList) {
@@ -172,7 +172,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserHadLaneMarkLinkTraversal(hadLaneMarkLinkList: List<Hadlanemarklink.HadLaneMarkLink>, file: File,
layerName: String= "车道边线可跨越性", layerTableName: String = "HAD_LANE_MARK_LINK_TRAVERSAL"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (hadLaneMarkLinkList?.isEmpty()) {
if (hadLaneMarkLinkList.isEmpty()) {
return featureEntityList
}
// 解析道路边线可跨越性
@@ -206,7 +206,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserHadLaneMarkLinkBoundary(hadLaneMarkLinkList: List<Hadlanemarklink.HadLaneMarkLink>, file: File,
layerName: String= "车道边线非标线类型", layerTableName: String = "HAD_LANE_MARK_LINK_BOUNDARY"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (hadLaneMarkLinkList?.isEmpty()) {
if (hadLaneMarkLinkList.isEmpty()) {
return featureEntityList
}
// 解析道路边线可跨越性
@@ -253,7 +253,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserRoadDirect(roadLinkList: List<Roadlink.RoadLink>, file: File,
layerName: String= "道路方向", layerTableName: String = "ROAD_LINK_DIRECT"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (roadLinkList?.isEmpty()) {
if (roadLinkList.isEmpty()) {
return featureEntityList
}
for (roadLink in roadLinkList) {
@@ -279,7 +279,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserRoadBrunnel(roadLinkList: List<Roadlink.RoadLink>, file: File,
layerName: String= "桥隧道", layerTableName: String = "ROAD_LINK_BRUNNEL"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (roadLinkList?.isEmpty()) {
if (roadLinkList.isEmpty()) {
return featureEntityList
}
for (roadLink in roadLinkList) {
@@ -303,7 +303,7 @@ class NavinfoPbfFileUtils: GisFileUtils {
private fun parserRoadMovBrg(roadLinkList: List<Roadlink.RoadLink>, file: File,
layerName: String= "移动式桥", layerTableName: String = "ROAD_LINK_MOVBRG"): List<GeometryFeatureEntity> {
val featureEntityList = ArrayList<GeometryFeatureEntity>()
if (roadLinkList?.isEmpty()) {
if (roadLinkList.isEmpty()) {
return featureEntityList
}
for (roadLink in roadLinkList) {

View File

@@ -1,141 +0,0 @@
package com.navinfo.collect.library.data.flutter
import android.content.Context
import com.navinfo.collect.FlutterBaseActivity
import com.navinfo.collect.library.data.NIDataController
import com.navinfo.collect.library.data.flutter.flutterhandler.*
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
class FlutterDataController(
id: Int,
context: Context,
binaryMessenger: BinaryMessenger,
activity: FlutterBaseActivity,
) : NIDataController(context, activity), MethodChannel.MethodCallHandler {
private val mMethodChannel: MethodChannel = MethodChannel(
binaryMessenger,
"com.navinfo.collect/data_$id"
)
private val flutterDataLayerHandler: FlutterDataLayerHandler
private val flutterDataElementHandler: FlutterDataElementHandler
private val flutterDataProjectHandler: FlutterDataProjectHandler
private val flutterDataNiLocationHandler: FlutterDataNiLocationHandler
val flutterDataCameraHandler: FlutterDataCameraHandler
init {
mMethodChannel.setMethodCallHandler(this)
flutterDataLayerHandler = FlutterDataLayerHandler(mContext, mDateBase)
flutterDataElementHandler = FlutterDataElementHandler(mContext, mMethodChannel, mDateBase)
flutterDataProjectHandler = FlutterDataProjectHandler(mContext, mDateBase)
flutterDataNiLocationHandler = FlutterDataNiLocationHandler(mContext, mDateBase)
flutterDataCameraHandler =
FlutterDataCameraHandler(mContext, mMethodChannel, activity, mDateBase)
}
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
when (call.method) {
/**
* 数据图层操作部分
*/
//创建数据图层
FlutterDataProtocolKeys.DateLayerProtocol.kDataCreateDataLayer -> {
flutterDataLayerHandler.createDataLayerTable(call, result);
}
//获取所有数据图层
FlutterDataProtocolKeys.DateLayerProtocol.kDataGetDataLayerList -> {
flutterDataLayerHandler.getDataLayerList(call, result);
}
//获取某个数据图层
FlutterDataProtocolKeys.DateLayerProtocol.kDataGetDataLayer -> {
flutterDataLayerHandler.getDataLayer(call, result);
}
/**
* 数据操作部分
*/
//保存数据
FlutterDataProtocolKeys.DataElementProtocol.kDataSaveElementData -> {
flutterDataElementHandler.saveElementData(call, result)
}
//删除数据
FlutterDataProtocolKeys.DataElementProtocol.kDataDeleteElementData -> {
flutterDataElementHandler.deleteElementData(call, result)
}
//捕捉数据
FlutterDataProtocolKeys.DataElementProtocol.kDataSnapElementDataList -> {
flutterDataElementHandler.snapElementDataList(call, result)
}
// 导入Pbf数据
FlutterDataProtocolKeys.DataElementProtocol.kImportPbfData -> {
flutterDataElementHandler.importPbfData2Realm(call, result)
}
//查询数据详细信息模板
FlutterDataProtocolKeys.DataElementProtocol.kDataQueryElementDeepInfo -> {
flutterDataElementHandler.queryElementDeepInfo(call, result)
}
//数据搜索
FlutterDataProtocolKeys.DataElementProtocol.kDataSearchData -> {
flutterDataElementHandler.searchData(call, result)
}
/**
* 项目管理
*/
//获取项目列表
FlutterDataProtocolKeys.DataProjectProtocol.kDataGetDataProjectList -> {
flutterDataProjectHandler.getProjectList(call, result);
}
//保存项目
FlutterDataProtocolKeys.DataProjectProtocol.kDataSaveDataProject -> {
flutterDataProjectHandler.saveProject(call, result);
}
/**
* 轨迹操作部分
*/
//保存轨迹数据
FlutterDataProtocolKeys.DataNiLocationProtocol.kDataSaveNiLocationData -> {
flutterDataNiLocationHandler.saveNiLocationData(call, result)
}
/**
* 检查项部分
*/
//获取所有检查项
FlutterDataProtocolKeys.DataCheckProtocol.kDataGetCheckManagerList -> {
flutterDataElementHandler.queryCheckManagerList(call, result)
}
//根据id获取检查项
FlutterDataProtocolKeys.DataCheckProtocol.kDataGetCheckManagerListByIds -> {
flutterDataElementHandler.queryCheckManagerListByIds(call, result)
}
//打开摄像头
FlutterDataProtocolKeys.DataCameraProtocol.kDataOpenCamera -> {
flutterDataCameraHandler.openCamera(call, result)
}
///ocr批量识别
FlutterDataProtocolKeys.DataCameraProtocol.kDataOCRBatchResults -> {
flutterDataCameraHandler.ocrBatch(call, result)
}
}
}
override fun release() {
super.release()
mMethodChannel.setMethodCallHandler(null)
}
}

View File

@@ -1,94 +0,0 @@
package com.navinfo.collect.library.data.flutter
object FlutterDataProtocolKeys {
/**
* 数据图层管理
*/
object DateLayerProtocol {
/**
* 获取数据层列表
*/
const val kDataGetDataLayerList = "flutter_nimap/DataLayer/getDataLayerList";
/**
* 获取某个数据层列表
*/
const val kDataGetDataLayer = "flutter_nimap/DataLayer/getDataLayer";
/**
* 创建数据层
*/
const val kDataCreateDataLayer = "flutter_nimap/DataLayer/createDataLayer";
}
/**
* 数据操作
*/
object DataElementProtocol {
//保存数据
const val kDataSaveElementData = "flutter_nimap/ElementData/saveElementData";
///删除数据
const val kDataDeleteElementData = "flutter_nimap/ElementData/deleteElementData";
//查询数据
const val kDataSnapElementDataList = "flutter_nimap/ElementData/snapElementDataList";
// 导入pbf数据
const val kImportPbfData = "flutter_nimap/HDData/importPBF";
//查询数据详细信息
const val kDataQueryElementDeepInfo = "flutter_nimap/ElementData/queryElementDeepInfo";
///按名称搜索数据
const val kDataSearchData = "flutter_nimap/ElementData/queryElementByName"
}
/**
* 数据操作
*/
object DataNiLocationProtocol {
//保存数据
const val kDataSaveNiLocationData = "flutter_nimap/NiLocationData/saveNiLocationData";
///删除数据
const val kDataDeleteNiLocationData = "flutter_nimap/NiLocationData/deleteNiLocationData";
}
object DataProjectProtocol {
/**
* 获取项目列表
*/
const val kDataGetDataProjectList = "flutter_nimap/Project/getDataProjectList";
/**
* 保存项目
*/
const val kDataSaveDataProject = "flutter_nimap/Project/saveDataProject";
}
object DataCheckProtocol {
///获取检查项列表
const val kDataGetCheckManagerList = "flutter_nimap/CheckManager/getDataCheckManagerList";
///根据id获取检查项列表
const val kDataGetCheckManagerListByIds =
"flutter_nimap/CheckManager/getDataCheckManagerListByIds";
}
object DataCameraProtocol {
const val kDataOpenCamera = "flutter_nimap/openCamera";
const val kDataOCRResults = "flutter_nimap/ocrResults";
///批量识别
const val kDataOCRBatchResults = "flutter_nimap/ocrBatch";
///ocr 批量回调进度
const val kDataOCRBatchProgress = "flutter_nimap/ocrBatchProgress";
}
}

View File

@@ -1,67 +0,0 @@
package com.navinfo.collect.library.data.flutter.flutterhandler
import android.content.Context
import android.util.Log
import com.baidu.ai.edge.ui.view.model.BasePolygonResultModel
import com.baidu.ai.edge.ui.view.model.OcrViewResultModel
import com.navinfo.collect.FlutterBaseActivity
import com.navinfo.collect.library.data.DataConversion
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
import com.navinfo.collect.library.data.flutter.FlutterDataProtocolKeys
import com.navinfo.collect.library.data.handler.DataCameraHandler
import com.navinfo.collect.library.data.handler.OnOCRBatchListener
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
class FlutterDataCameraHandler(
context: Context,
methodChannel: MethodChannel,
activity: FlutterBaseActivity,
dataBase: MapLifeDataBase
) :
DataCameraHandler(context, activity, dataBase) {
private val _methodChannel = methodChannel
fun openCamera(call: MethodCall, result: MethodChannel.Result) {
super.openCamera()
result.success(true)
}
fun sendOcrResults(path: String, basePolygonResultModels: List<BasePolygonResultModel>) {
_methodChannel.invokeMethod(
FlutterDataProtocolKeys.DataCameraProtocol.kDataOCRResults,
DataConversion.toOcrList(path, basePolygonResultModels)
)
}
fun ocrBatch(call: MethodCall, result: MethodChannel.Result) {
if (call.arguments is String) {
super.ocrBatch(
call.arguments as String,
object : OnOCRBatchListener {
override fun onProgress(total: Int, current: Int) {
Log.e("jingo", "OCRManager 线程名称2 ${Thread.currentThread().name}")
Log.e("jingo", "OCR识别 当前第 $current 张,总共 $total");
val map = mutableMapOf<String, Int>()
map["total"] = total
map["current"] = current + 1
_methodChannel.invokeMethod(
FlutterDataProtocolKeys.DataCameraProtocol.kDataOCRBatchProgress,
map
)
}
override suspend fun onResult(list: List<Map<String, Any>>) {
Log.e("jingo", "OCRManager 线程名称2 ${Thread.currentThread().name}")
_methodChannel.invokeMethod(
FlutterDataProtocolKeys.DataCameraProtocol.kDataOCRBatchResults,
DataConversion.toFlutterOcrList(list)
)
}
}
)
}
result.success(true)
}
}

View File

@@ -1,245 +0,0 @@
package com.navinfo.collect.library.data.flutter.flutterhandler
import android.content.Context
import android.util.Log
import com.navinfo.collect.library.data.DataConversion
import com.navinfo.collect.library.data.RealmUtils
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
import com.navinfo.collect.library.data.entity.Element
import com.navinfo.collect.library.data.entity.LayerManager
import com.navinfo.collect.library.data.entity.Project
import com.navinfo.collect.library.data.flutter.FlutterDataProtocolKeys
import com.navinfo.collect.library.data.handler.DataElementHandler
import com.navinfo.collect.library.data.search.*
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import org.json.JSONObject
/**
* 数据操作
*/
class FlutterDataElementHandler(
context: Context,
methodChannel: MethodChannel,
dataBase: MapLifeDataBase
) :
DataElementHandler(context, dataBase), OnGetSearchDataResultListener {
val _methodChannel = methodChannel
init {
setListener(this)
}
/**
* 保存数据
*/
fun saveElementData(call: MethodCall, result: MethodChannel.Result) = try {
if (call.arguments is Map<*, *>) {
val element = Element.fromMap(call.arguments as MutableMap<String, Any>?);
val valueMap = call.argument<Map<String, Any>>("values")
saveData(element, valueMap) { res, error ->
if (res) {
result.success("$res")
} else {
result.success(error)
}
}
} else {
result.success("数据格式错误")
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
Log.e("jingo", e.toString())
result.success("数据格式错误")
}
/**
* 删除数据
*/
fun deleteElementData(call: MethodCall, result: MethodChannel.Result) = try {
if (call.arguments is Map<*, *>) {
val element = Element()
element.layerId = call.argument("layerId")
element.id = call.argument("uuid")
element.geometry = call.argument("geometry")
element.displayText = call.argument("displayText")
element.displayStyle = call.argument("displayStyle")
element.operationTime = call.argument("tOperateDate")
element.tLifecycle = call.argument<Int>("tLifecycle")!!
element.tStatus = call.argument<Int>("tStatus")!!
deleteData(element) { res, message ->
if (res) {
result.success("success")
} else {
result.success(message)
}
};
} else {
result.success("数据格式错误")
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
Log.e("jingo", e.toString())
result.success("数据格式错误")
}
/**
* 复制数据
*/
fun copyElementData(call: MethodCall, result: MethodChannel.Result) = try {
if (call.arguments is Map<*, *>) {
} else {
result.success("数据格式错误")
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
Log.e("jingo", e.toString())
result.success("数据格式错误")
}
fun importPbfData2Realm(call: MethodCall, result: MethodChannel.Result) {
if (call.arguments is List<*>) {
val pbfFiles: List<String> = call.arguments as List<String>
try {
val importResult = RealmUtils.getInstance().importPbfData(pbfFiles)
result.success(importResult)
} catch (exeception: Exception) {
result.error("-1", exeception.message, exeception)
}
}
}
/**
* 捕捉数据
*/
fun snapElementDataList(call: MethodCall, result: MethodChannel.Result) {
if (call.arguments is String) {
snapElementDataList(call.arguments as String) {
result.success(DataConversion.toElementMapList(it))
}
}
}
/**
* 查询数据深度信息模板
*/
fun queryElementDeepInfo(call: MethodCall, result: MethodChannel.Result) {
if (call.arguments is Map<*, *>) {
val id = call.argument<String>("id")
val layerId = call.argument<String>("layerId")
if (id != null && layerId != null) {
queryElementDeepInfo(id, layerId) { layerManager, itemList ->
if (layerManager != null) {
val map = layerManager.toMap()
map["layerItems"] = DataConversion.customLayerItemsToMapList(itemList)
result.success(map)
} else {
result.error("-1","没有这条数据的拓展模板","")
}
}
}
}
}
/**
* 根据渲染名称查询数据
*/
fun searchData(call: MethodCall, result: MethodChannel.Result) {
if (call.arguments is String) {
try {
val jsonObject = JSONObject(call.arguments as String)
val keyword = jsonObject.getString("keyword")
val pageNum = jsonObject.getInt("pageNum")
val pageCapacity = jsonObject.getInt("pageCapacity")
val startTime = jsonObject.getInt("startTime")
val endTime = jsonObject.getInt("endTime")
val projectArray = jsonObject.getJSONArray("projectItemList")
val layerArray = jsonObject.getJSONArray("layerItemList")
val fieldArray = jsonObject.getJSONArray("fieldItemList")
val projectItemList = ArrayList<OptionProjectItem>()
val layerItemList = ArrayList<OptionLayerItem>()
val fieldItemList = ArrayList<OptionFieldItem>()
for (i in 0 until projectArray.length()) {
val item = OptionProjectItem(projectArray.getString(i))
projectItemList.add(item)
}
for (i in 0 until layerArray.length()) {
val layerObject = layerArray.getJSONObject(i)
val item = OptionLayerItem(
layerObject.optString("projectId"),
layerObject.optString("layerId")
)
layerItemList.add(item)
}
for (i in 0 until fieldArray.length()) {
val fieldObject = fieldArray.getJSONObject(i)
val item = OptionFieldItem(
fieldObject.optString("projectId"),
fieldObject.optString("layerId"),
fieldObject.optString("fieldName")
)
fieldItemList.add(item)
}
val option =
SearchDataOption.Builder().setKeyword(keyword).setStartTime(startTime)
.setEndTime(endTime).setFieldItems(fieldItemList)
.setLayerItems(layerItemList).setProjectItems(projectItemList)
.setPageNum(pageNum).setPageCapacity(pageCapacity).build()
searchData(option) {
// result.success(DataConversion.toElementMapList(it))
}
result.success("");
} catch (e: Exception) {
println("$e")
result.error("-1", "查询参数解析错误", "$e")
}
}
}
/**
* 获取检查项列表
*/
fun queryCheckManagerList(call: MethodCall, result: MethodChannel.Result) {
queryCheckManagerList() { list ->
result.success(DataConversion.toCheckManagerMapList(list));
}
}
/**
* 根据id获取检查项列表
*/
fun queryCheckManagerListByIds(call: MethodCall, result: MethodChannel.Result) {
queryCheckManagerList() { list ->
result.success(DataConversion.toCheckManagerMapList(list));
}
}
override fun onGetElementResult(elementList: List<Element>) {
_methodChannel.invokeMethod(
FlutterDataProtocolKeys.DataElementProtocol.kDataSearchData,
DataConversion.toElementMapList(elementList)
)
}
override fun onGetLayerResult(layer: LayerManager) {
}
override fun onGetProjectResult(project: Project) {
}
override fun onError(msg: String, keyword: String) {
}
}

View File

@@ -1,114 +0,0 @@
package com.navinfo.collect.library.data.flutter.flutterhandler
import android.content.Context
import android.util.Log
import com.navinfo.collect.library.data.DataConversion
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
import com.navinfo.collect.library.data.entity.CustomLayerItem
import com.navinfo.collect.library.data.entity.DataLayerItemType
import com.navinfo.collect.library.data.handler.DataLayerHandler
import com.navinfo.collect.library.data.entity.LayerManager
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import org.json.JSONArray
import org.json.JSONObject
/**
* 数据图层管理
*/
class FlutterDataLayerHandler(context: Context, dataBase: MapLifeDataBase) :
DataLayerHandler(context, dataBase) {
fun createDataLayerTable(call: MethodCall, result: MethodChannel.Result) {
try {
if (call.arguments is String) {
val jsonObject = JSONObject(call.arguments as String)
val layer = LayerManager()
layer.id = jsonObject.optString("uuid")
layer.projectId = jsonObject.optString("projectId")
layer.geometryType = jsonObject.optInt("geometryType")
layer.layerName = jsonObject.optString("layerName")
layer.style = jsonObject.optString("style")
layer.importTime = jsonObject.optString("import_time")
layer.describe = jsonObject.optString("describe")
layer.visibility = jsonObject.optBoolean("visibility")
val jsonArrayItems = JSONArray(jsonObject.optString("layerItems"))
layer.bundle = jsonArrayItems.toString()
var itemList = mutableListOf<CustomLayerItem>();
for (i in 0 until jsonArrayItems.length()) {
val jsonObjectItem: JSONObject = jsonArrayItems[i] as JSONObject;
val item = CustomLayerItem(
key = jsonObjectItem.optString("key"),
type = DataLayerItemType.values()[jsonObjectItem.optInt("type")],
title = jsonObjectItem.optString("title"),
describe = jsonObjectItem.optString("describe"),
itemBean = jsonObjectItem.optString("itemBean"),
)
itemList.add(item)
}
// val list = DataConversion.listMapToCustomLayerItemsList(itemList)
createTable(layer, itemList) { res, _ ->
result.success(res)
}
} else {
result.success(false)
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
Log.e("jingo", e.toString())
result.success(false)
}
}
/**
* 获取全部数据图层信息
*/
fun getDataLayerList(call: MethodCall, result: MethodChannel.Result) {
getDataLayerList { list ->
val newList = mutableListOf<Map<*, *>>()
for (item in list) {
val map = mapOf(
"uuid" to item.id,
"projectId" to item.projectId,
"geometryType" to item.geometryType,
"layerName" to item.layerName,
"import_time" to item.importTime,
"describe" to item.describe,
"visibility" to item.visibility,
"layerItems" to item.bundle,
"style" to item.style
)
newList.add(map)
}
result.success(newList)
}
}
/**
* 获取某个数据图层
*/
fun getDataLayer(call: MethodCall, result: MethodChannel.Result) {
if (call.arguments is String) {
getDataLayer(call.arguments as String) { layer ->
result.success(
mapOf(
"uuid" to layer.id,
"projectId" to layer.projectId,
"geometryType" to layer.geometryType,
"layerName" to layer.layerName,
"import_time" to layer.importTime,
"describe" to layer.describe,
"visibility" to layer.visibility,
"layerItems" to layer.bundle,
"style" to layer.style
)
)
}
} else {
result.success("false")
}
}
}

View File

@@ -1,92 +0,0 @@
package com.navinfo.collect.library.data.flutter.flutterhandler
import android.content.Context
import android.util.Log
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
import com.navinfo.collect.library.data.entity.NiLocation
import com.navinfo.collect.library.data.handler.DataNiLocationHandler
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import java.text.SimpleDateFormat
import java.util.*
/**
* 数据操作
*/
class FlutterDataNiLocationHandler(context: Context, dataBase: MapLifeDataBase) :
DataNiLocationHandler(context, dataBase) {
/**
* 保存数据
*/
fun saveNiLocationData(call: MethodCall, result: MethodChannel.Result) = try {
if (call.arguments is Map<*, *>) {
val niLocation = NiLocation()
niLocation.id = call.argument("uuid")
niLocation.longitude = call.argument<Double>("longitude")!!
niLocation.latitude = call.argument<Double>("latitude")!!
niLocation.altitude = call.argument<Double>("altitude")!!
niLocation.radius = call.argument<Double>("radius")!!
niLocation.direction = call.argument<Double>("direction")!!
niLocation.time = call.argument("time")!!
if(niLocation.time.length==19){
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val dDate: Date = simpleDateFormat.parse(niLocation.time)
niLocation.time = dDate.time.toString()
}
niLocation.speed = call.argument<Float>("speed")!!
niLocation.country = call.argument("country")
niLocation.province = call.argument("province")
niLocation.city = call.argument("city")
niLocation.district = call.argument("district")
niLocation.street = call.argument("street")
niLocation.town = call.argument("town")
niLocation.adCode = call.argument("adCode")
niLocation.cityCode = call.argument("cityCode")
niLocation.streetNumber = call.argument("streetNumber")
niLocation.errorCode = call.argument<String?>("errorCode").toString()
niLocation.errorInfo = call.argument("errorInfo")
saveDataNiLocation(niLocation) { res, error ->
if (res) {
result.success("$res")
} else {
result.success(error)
}
}
} else {
result.success("数据格式错误")
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
Log.e("jingo", e.toString())
result.success("数据格式错误")
}
/**
* 删除数据
*/
fun deleteNiLocationData(call: MethodCall, result: MethodChannel.Result) = try {
if (call.arguments is Map<*, *>) {
val niLocation = NiLocation()
niLocation.id = call.argument("uuid")
deleteData(niLocation) { res, message ->
if (res) {
result.success("success")
} else {
result.success(message)
}
};
} else {
result.success("数据格式错误")
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) }
Log.e("jingo", e.stackTraceToString())
Log.e("jingo", e.toString())
result.success("数据格式错误")
}
}

View File

@@ -1,64 +0,0 @@
package com.navinfo.collect.library.data.flutter.flutterhandler
import android.content.Context
import android.util.Log
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
import com.navinfo.collect.library.data.handler.DataProjectHandler
import com.navinfo.collect.library.data.entity.Project
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
/**
* 项目管理
*/
class FlutterDataProjectHandler(context: Context, dataBase: MapLifeDataBase) :
DataProjectHandler(context, dataBase) {
fun saveProject(call: MethodCall, result: MethodChannel.Result) {
try {
if (call.arguments is Map<*, *>) {
// "style": style,
val project = Project();
//项目名称
project.id = call.argument("uuid")
project.name = call.argument("name")
project.createTime = call.argument("createTime")
project.describe = call.argument("describe")
project.visibility = call.argument<Boolean>("visibility") == false
project.geometry = call.argument("geometry")
project.geometryVisibility = call.argument<Boolean>("geometryVisibility") == false
saveProject(project) { res, _ ->
result.success(res)
};
} else {
result.success(false)
}
} catch (e: Throwable) {
e.message?.let { Log.e("jingo", it) };
Log.e("jingo", e.stackTraceToString());
Log.e("jingo", e.toString());
result.success(false)
}
}
fun getProjectList(call: MethodCall, result: MethodChannel.Result) {
getProjectList { list ->
val newList = mutableListOf<Map<*, *>>()
for (item in list) {
val map = mapOf(
"uuid" to item.id,
"name" to item.name,
"createTime" to item.createTime,
"describe" to item.describe,
"visibility" to item.visibility,
"geometry" to item.geometry,
"geometryVisibility" to item.geometryVisibility
)
newList.add(map)
}
result.success(newList)
};
}
}