package com.za.offline

import android.content.Intent
import android.provider.Settings
import androidx.appcompat.app.AlertDialog
import androidx.core.net.toUri
import com.alibaba.fastjson.JSONObject
import com.amap.api.maps.model.LatLng
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.geocoder.GeocodeResult
import com.amap.api.services.geocoder.GeocodeSearch
import com.amap.api.services.geocoder.GeocodeSearch.OnGeocodeSearchListener
import com.amap.api.services.geocoder.RegeocodeQuery
import com.amap.api.services.geocoder.RegeocodeResult
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ToastUtils
import com.za.bean.request.SaveEleOrderRequest
import com.za.bean.request.TaskFinishRequest
import com.za.bean.request.TaskFinishResponse
import com.za.bean.request.UpdateTaskBean
import com.za.bean.request.UpdateTaskRequest
import com.za.common.GlobalData
import com.za.common.log.LogUtil
import com.za.common.util.MapUtil
import com.za.ext.toJson
import com.za.net.BaseObserver
import com.za.net.CommonMethod
import com.za.net.RetrofitHelper
import com.za.room.RoomHelper
import com.za.water_marker.PhotoMarkerManager
import com.za.water_marker.bean.PhotoMarkerInfo
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.io.File
import java.util.concurrent.TimeUnit

interface IOfflineListener {
	fun start()
	fun stop()
	fun uploadSuccess()
	fun uploadFailure(msg : String?)
	fun currentTask(offlineUpdateTaskBean : OfflineUpdateTaskBean)
}

object OfflineManager {
	private const val TAG = "离线任务"
	private var isUploading = false
	private var uploadDispose : Disposable? = null
	private var offlineListener : IOfflineListener? = null
	private var currentTaskId : Int? = null

	fun addOfflineListener(offlineListener : IOfflineListener) {
		this.offlineListener = offlineListener
	}


	fun start(taskId : Int?) {
		if (checkOfflineIsComplete(taskId)) {
			return
		}

		if (currentTaskId != null && taskId == currentTaskId && isUploading) {
			LogUtil.print(TAG, "当前任务正在上传中")
			return
		}

		if (! Settings.canDrawOverlays(GlobalData.application)) {
			LogUtil.print(TAG, "开始失败：悬浮窗权限未开启")
			openSystemAlertPermissionDialog()
			return
		}

		stop()
		OfflineService.addListener()
		offlineListener?.start()
		uploadDispose = Observable.interval(0, 5, TimeUnit.SECONDS).subscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread()).subscribe {
				if (! isUploading) {
					val list =
						RoomHelper.db?.offlineTaskDao()?.getOfflineTaskFromTaskId(taskId ?: 0)
					if (list.isNullOrEmpty()) {
						LogUtil.print(TAG, "离线任务为空!!")
						stop()
						ToastUtils.showLong("离线任务上传完成")
						return@subscribe
					}
					doUpload(list[0])
				}
			}
	}

	private fun stop() {
		uploadDispose?.dispose()
		uploadDispose = null
		isUploading = false
		currentTaskId = null
		offlineListener?.stop()
		offlineListener = null
	}


	private fun checkOfflineIsComplete(taskId : Int?) : Boolean {
		val list = RoomHelper.db?.offlineTaskDao()?.getOfflineTaskFromTaskId(taskId ?: 0)
		LogUtil.print("离线任务列表", "${list.toJson()}")
		return list.isNullOrEmpty()
	}

	private fun doUpload(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		offlineListener?.currentTask(offlineUpdateTaskBean)
		currentTaskId = offlineUpdateTaskBean.taskId
		when (offlineUpdateTaskBean.offlineType) {
			1 -> uploadTask(offlineUpdateTaskBean)
			2 -> uploadOrderImage(offlineUpdateTaskBean)
			3 -> uploadEleWorkOrder(offlineUpdateTaskBean)
			4 -> uploadEleDamageImage(offlineUpdateTaskBean)
			5 -> uploadCustomerSignImage(offlineUpdateTaskBean)
			6 -> uploadAcceptPeopleSignImage(offlineUpdateTaskBean)
			7 -> uploadServicePeopleSignImage(offlineUpdateTaskBean)
			8 -> taskFinish(offlineUpdateTaskBean)
		}
	}

	private fun uploadTask(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 uploadTask=${offlineUpdateTaskBean.toJson()}")
		val updateTaskRequest = UpdateTaskRequest(type = offlineUpdateTaskBean.type,
			taskId = offlineUpdateTaskBean.taskId,
			userId = offlineUpdateTaskBean.userId,
			vehicleId = offlineUpdateTaskBean.vehicleId,
			currentState = offlineUpdateTaskBean.currentState,
			operateTime = offlineUpdateTaskBean.operateTime,
			lat = offlineUpdateTaskBean.updateTaskLat,
			lng = offlineUpdateTaskBean.updateTaskLng,
			address = offlineUpdateTaskBean.updateTaskAddress,
			offlineMode = offlineUpdateTaskBean.offlineMode,
			flowType = offlineUpdateTaskBean.flowType,
			success = offlineUpdateTaskBean.success,
			templatePhotoInfoList = offlineUpdateTaskBean.templatePhotoInfoList)

		RetrofitHelper.getDefaultService().updateTask(updateTaskRequest)
			.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
			.subscribe(object : BaseObserver<UpdateTaskBean>() {
				override fun doSuccess(it : UpdateTaskBean?) {
					RoomHelper.db?.offlineTaskDao()
						?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
					isUploading = false
					offlineListener?.uploadSuccess()
					LogUtil.print(TAG, "uploadTask 完成")
				}

				override fun doFailure(code : Int, msg : String?) {
					isUploading = false
					offlineListener?.uploadFailure(msg)
					LogUtil.print(TAG, "uploadTask 失败 $code $msg")
				}
			})
	}

	private fun uploadOrderImage(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 uploadOrderImage=${offlineUpdateTaskBean.toJson()}")
		var file = File(offlineUpdateTaskBean.photoLocalWaterMarkerPath ?: "")
		if (! file.exists()) {
			offlineListener?.uploadFailure("图片未找到！")
			LogUtil.print(TAG, "uploadOrderImage 失败，图片未找到")
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			isUploading = false
			return
		}

		if (offlineUpdateTaskBean.imageAddress.isNullOrBlank() && (offlineUpdateTaskBean.imageLat != null && offlineUpdateTaskBean.imageLat != 0f && offlineUpdateTaskBean.imageLng != null && offlineUpdateTaskBean.imageLng != 0f)) {
			val address = MapUtil.getAddressFromLocation(context = ActivityUtils.getTopActivity(),
				latLng = LatLng(offlineUpdateTaskBean.imageLat.toDouble(),
					offlineUpdateTaskBean.imageLng.toDouble()))
			val photoMarkerInfo = PhotoMarkerInfo(offlineUpdateTaskBean.needWater,
				needShowPhoneBrand = offlineUpdateTaskBean.needPhoneBrand,
				path = offlineUpdateTaskBean.photoLocalWaterMarkerPath,
				from = "（离线）",
				lat = offlineUpdateTaskBean.imageLat.toDouble(),
				lng = offlineUpdateTaskBean.imageLng.toDouble(),
				address = address,
				time = offlineUpdateTaskBean.time,
				driverName = GlobalData.driverInfoBean?.userName,
				taskCode = offlineUpdateTaskBean.taskCode)
			val offlineTemp = offlineUpdateTaskBean.copy(imageAddress = address)
			file = File(PhotoMarkerManager.addPhotoMarker(ActivityUtils.getTopActivity(),
				photoMarkerInfo))
			CommonMethod.uploadImage(file = file, success = {
				val item =
					RoomHelper.db?.offlineTaskDao()?.getRecentOfflineTask(offlineTemp.taskId ?: 0)
						?.get(0)
				if (item == null) {
					offlineListener?.uploadFailure(it)
					isUploading = false
					LogUtil.print(TAG, "离线图片要出插入的节点 未找到")
					return@uploadImage
				}
				LogUtil.print(TAG, "离线图片要出插入的节点 =${item.toJson()}")
				val list = item.templatePhotoInfoList?.toMutableList()
				val jsonObject = JSONObject()
				jsonObject["realTakePhotoTime"] = offlineTemp.realTakePhotoTime ?: ""
				jsonObject["photoSource"] = offlineTemp.photoSource
				jsonObject["path"] = it
				jsonObject["time"] = offlineTemp.time
				jsonObject["lat"] = offlineTemp.imageLat
				jsonObject["sort"] = offlineTemp.sort
				jsonObject["lng"] = offlineTemp.imageLng
				jsonObject["address"] = offlineTemp.imageAddress
				list?.set(offlineTemp.imageIndex ?: 0, jsonObject.toJSONString())
				val temp = item.copy(templatePhotoInfoList = list?.toList())
				RoomHelper.db?.offlineTaskDao()?.update(temp)
				RoomHelper.db?.offlineTaskDao()?.deleteOfflineTaskFromId(offlineTemp.primaryId ?: 0)
				isUploading = false
				offlineListener?.uploadSuccess()
				LogUtil.print(TAG, "离线 uploadOrderImage 成功")
			}, failed = {
				RoomHelper.db?.offlineTaskDao()?.update(offlineTemp)
				offlineListener?.uploadFailure(it)
				isUploading = false
				LogUtil.print(TAG, "uploadOrderImage 失败$it")
			})
		} else {
			CommonMethod.uploadImage(file = file, success = {
				val item = RoomHelper.db?.offlineTaskDao()
					?.getRecentOfflineTask(offlineUpdateTaskBean.taskId ?: 0)?.get(0)
				if (item == null) {
					offlineListener?.uploadFailure(it)
					isUploading = false
					LogUtil.print(TAG, "离线图片要出插入的节点 未找到")
					return@uploadImage
				}
				LogUtil.print(TAG, "离线图片要出插入的节点 =${item.toJson()}")
				val list = item.templatePhotoInfoList?.toMutableList()
				val jsonObject = JSONObject()
				jsonObject["realTakePhotoTime"] = offlineUpdateTaskBean.realTakePhotoTime ?: ""
				jsonObject["photoSource"] = offlineUpdateTaskBean.photoSource
				jsonObject["path"] = it
				jsonObject["sort"] = offlineUpdateTaskBean.sort
				jsonObject["time"] = offlineUpdateTaskBean.time
				jsonObject["lat"] = offlineUpdateTaskBean.imageLat
				jsonObject["lng"] = offlineUpdateTaskBean.imageLng
				jsonObject["address"] = offlineUpdateTaskBean.imageAddress
				list?.set(offlineUpdateTaskBean.imageIndex ?: 0, jsonObject.toJSONString())
				val temp = item.copy(templatePhotoInfoList = list?.toList())

				RoomHelper.db?.offlineTaskDao()?.update(temp)
				RoomHelper.db?.offlineTaskDao()
					?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
				isUploading = false
				offlineListener?.uploadSuccess()
				LogUtil.print(TAG, "离线 uploadOrderImage 成功")
			}, failed = {
				offlineListener?.uploadFailure(it)
				isUploading = false
				LogUtil.print(TAG, "uploadOrderImage  图片上传失败$it")
			})
		}
	}

	private fun uploadEleDamageImage(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 uploadEleDamageImage${offlineUpdateTaskBean.toJson()}")
		val file = File(offlineUpdateTaskBean.imageLocalPath ?: "")
		if (! file.exists()) {
			offlineListener?.uploadFailure("图片未找到！")
			LogUtil.print(TAG, "uploadEleDamageImage  图片未找到")
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			isUploading = false
			return
		}
		CommonMethod.uploadImage(file = file, success = {
			val item = RoomHelper.db?.offlineTaskDao()
				?.getRecentOfflineEle(offlineUpdateTaskBean.taskId ?: 0)?.get(0)
			if (item == null) {
				offlineListener?.uploadFailure(it)
				isUploading = false
				return@uploadImage
			}
			LogUtil.print(TAG, "最近的节点${item.toJson()}")
			val list = item.damageFileList?.toMutableList()
			list?.set(offlineUpdateTaskBean.imageIndex ?: 0, it)
			val temp = item.copy(templatePhotoInfoList = list?.toList())

			RoomHelper.db?.offlineTaskDao()?.update(temp)
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			isUploading = false
			offlineListener?.uploadSuccess()
			LogUtil.print(TAG, "uploadEleDamageImage 成功")
		}, failed = {
			offlineListener?.uploadFailure(it)
			isUploading = false
			LogUtil.print(TAG, "uploadEleDamageImage 失败$it")
		})
	}

	private fun uploadEleWorkOrder(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		LogUtil.print(TAG, "开始 uploadEleWorkOrder ${offlineUpdateTaskBean.toJson()}")
		val saveEleOrderRequest = SaveEleOrderRequest(state = offlineUpdateTaskBean.eleState,
			userOrderId = offlineUpdateTaskBean.userOrderId,
			taskOrderId = offlineUpdateTaskBean.taskId,
			damageFileList = offlineUpdateTaskBean.damageFileList,
			hasDamage = offlineUpdateTaskBean.hasDamage,
			hasSuccess = offlineUpdateTaskBean.hasSuccess,
			customerSignPath = offlineUpdateTaskBean.customerSignPath,
			recipientSignPath = offlineUpdateTaskBean.recipientSignPath,
			waitstaffSignPath = offlineUpdateTaskBean.waitstaffSignPath,
			offlineMode = 1,
			userOrderCode = offlineUpdateTaskBean.userOrderCode,
			lat = offlineUpdateTaskBean.eleLat,
			lng = offlineUpdateTaskBean.eleLng,
			tyreNumber = offlineUpdateTaskBean.tyreNumber,
			isFinish = offlineUpdateTaskBean.isFinish)
		LogUtil.print(TAG, "uploadEleWorkOrder request=${saveEleOrderRequest.toJson()}")
		RetrofitHelper.getDefaultService().saveElectronOrder(saveEleOrderRequest)
			.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
			.subscribe(object : BaseObserver<String>() {
				override fun doSuccess(it : String?) {
					RoomHelper.db?.offlineTaskDao()
						?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
					isUploading = false
					offlineListener?.uploadSuccess()
					LogUtil.print(TAG, "uploadEleWorkOrder 成功")
				}

				override fun doFailure(code : Int, msg : String?) {
					offlineListener?.uploadFailure(msg)
					isUploading = false
					LogUtil.print(TAG, "uploadEleWorkOrder 失败$code $msg")
				}
			})
	}

	private fun uploadCustomerSignImage(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 uploadCustomerSignImage${offlineUpdateTaskBean.toJson()}")
		val file = File(offlineUpdateTaskBean.imageLocalPath ?: "")
		if (! file.exists()) {
			offlineListener?.uploadFailure("图片未找到！")
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			isUploading = false
			LogUtil.print(TAG, "uploadCustomerSignImage  图片未找到")
			return
		}
		CommonMethod.uploadImage(file = file, success = { it ->
			val item = RoomHelper.db?.offlineTaskDao()
				?.getRecentOfflineEle(offlineUpdateTaskBean.taskId ?: 0)?.get(0)
			if (item == null) {
				offlineListener?.uploadFailure(it)
				isUploading = false
				return@uploadImage
			}
			LogUtil.print(TAG, "uploadCustomerSignImage 要插入的接单=${item.toJson()}")
			RoomHelper.db?.offlineTaskDao()?.update(item.copy(customerSignPath = it))
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			RoomHelper.db?.eleWorkOrderDao()?.getEleWorkOrder(offlineUpdateTaskBean.taskId ?: 0)
				?.copy(serverCustomSignPath = it)?.let {
					RoomHelper.db?.eleWorkOrderDao()?.update(it)
				}
			isUploading = false
			offlineListener?.uploadSuccess()
			LogUtil.print(TAG, "uploadCustomerSignImage 成功")
		}, failed = {
			offlineListener?.uploadFailure(it)
			isUploading = false
			LogUtil.print(TAG, "uploadCustomerSignImage 失败$it")
		})
	}

	private fun uploadAcceptPeopleSignImage(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 uploadAcceptPeopleSignImage ${offlineUpdateTaskBean.toJson()}")
		val file = File(offlineUpdateTaskBean.imageLocalPath ?: "")
		if (! file.exists()) {
			offlineListener?.uploadFailure("图片未找到！")
			LogUtil.print(TAG, "uploadAcceptPeopleSignImage 图片未找到")
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			isUploading = false
			return
		}
		CommonMethod.uploadImage(file = file, success = { it ->
			val item = RoomHelper.db?.offlineTaskDao()
				?.getRecentOfflineEle(offlineUpdateTaskBean.taskId ?: 0)?.get(0)
			if (item == null) {
				offlineListener?.uploadFailure(it)
				isUploading = false
				return@uploadImage
			}
			LogUtil.print(TAG, "uploadAcceptPeopleSignImage 要插入的接单=${item.toJson()}")
			RoomHelper.db?.offlineTaskDao()?.update(item.copy(recipientSignPath = it))
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			RoomHelper.db?.eleWorkOrderDao()?.getEleWorkOrder(offlineUpdateTaskBean.taskId ?: 0)
				?.copy(serverAcceptCarSignPath = it)?.let {
					RoomHelper.db?.eleWorkOrderDao()?.update(it)
				}
			isUploading = false
			offlineListener?.uploadSuccess()
			LogUtil.print(TAG, "uploadAcceptPeopleSignImage 成功")
		}, failed = {
			offlineListener?.uploadFailure(it)
			isUploading = false
			LogUtil.print(TAG, "uploadAcceptPeopleSignImage 逆地理失败")
		})
	}

	private fun uploadServicePeopleSignImage(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 uploadServicePeopleSignImage${offlineUpdateTaskBean.toJson()}")
		val file = File(offlineUpdateTaskBean.imageLocalPath ?: "")
		if (! file.exists()) {
			offlineListener?.uploadFailure("图片未找到！")
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			isUploading = false
			LogUtil.print(TAG, "uploadServicePeopleSignImage  图片未找到")
			return
		}
		CommonMethod.uploadImage(file = file, success = { it ->
			val item = RoomHelper.db?.offlineTaskDao()
				?.getRecentOfflineEle(offlineUpdateTaskBean.taskId ?: 0)?.get(0)
			if (item == null) {
				offlineListener?.uploadFailure(it)
				isUploading = false
				return@uploadImage
			}
			LogUtil.print(TAG, "uploadServicePeopleSignImage 要插入的接单=${item.toJson()}")
			RoomHelper.db?.offlineTaskDao()?.update(item.copy(waitstaffSignPath = it))
			RoomHelper.db?.offlineTaskDao()
				?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
			RoomHelper.db?.eleWorkOrderDao()?.getEleWorkOrder(offlineUpdateTaskBean.taskId ?: 0)
				?.copy(serverServicePeopleSignPath = it)?.let {
					RoomHelper.db?.eleWorkOrderDao()?.update(it)
				}

			isUploading = false
			offlineListener?.uploadSuccess()
			LogUtil.print(TAG, "uploadServicePeopleSignImage 成功")
		}, failed = {
			offlineListener?.uploadFailure(it)
			isUploading = false
			LogUtil.print(TAG, "uploadAcceptPeopleSignImage 失败$it")
		})
	}

	private fun taskFinish(offlineUpdateTaskBean : OfflineUpdateTaskBean) {
		isUploading = true
		LogUtil.print(TAG, "开始 taskFinish ${offlineUpdateTaskBean.toJson()}")
		val taskFinishRequest = TaskFinishRequest(
			operateTime = offlineUpdateTaskBean.operateTime?.toLong(),
			lat = offlineUpdateTaskBean.updateTaskLat,
			userOrderId = offlineUpdateTaskBean.userOrderId,
			lng = offlineUpdateTaskBean.updateTaskLng,
		)
		LogUtil.print(TAG, "taskFinish request ${taskFinishRequest.toJson()}")
		RetrofitHelper.getDefaultService().taskFinish(taskFinishRequest)
			.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
			.subscribe(object : BaseObserver<TaskFinishResponse>() {
				override fun doSuccess(it : TaskFinishResponse?) {
					RoomHelper.db?.offlineTaskDao()
						?.deleteOfflineTaskFromId(offlineUpdateTaskBean.primaryId ?: 0)
					isUploading = false
					offlineListener?.uploadSuccess()
					LogUtil.print(TAG, "taskFinish 成功")
				}

				override fun doFailure(code : Int, msg : String?) {
					isUploading = false
					offlineListener?.uploadFailure(msg)
					LogUtil.print(TAG, "taskFinish 失败 $code $msg")
				}
			})
	}
}

//打开系统悬浮窗权限
private fun openSystemAlertPermissionDialog() {
	val context = ActivityUtils.getTopActivity()
	val alertdialog = AlertDialog.Builder(ActivityUtils.getTopActivity()).setTitle("提示")
		.setMessage("当前应用缺少【悬浮窗】必要权限。\n\n请点击\"设置\"-\"权限\"-打开所需权限。")
		.setCancelable(false).setPositiveButton("设置") { _, _ ->
			val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
				"package:${context.packageName}".toUri())
			intent.data = ("package:" + ActivityUtils.getTopActivity().packageName).toUri()
			ActivityUtils.getTopActivity().startActivity(intent)
		}
	alertdialog.show()
}

//逆地址编码
private fun geoCoder(lat : Double,
	lng : Double,
	success : (String) -> Unit,
	failed : (String) -> Unit = {}) {
	val geocoderSearch = GeocodeSearch(ActivityUtils.getTopActivity().application)
	val query = RegeocodeQuery(LatLonPoint(lat, lng), 200f, GeocodeSearch.AMAP)
	geocoderSearch.getFromLocationAsyn(query)
	geocoderSearch.setOnGeocodeSearchListener(object : OnGeocodeSearchListener {
		override fun onRegeocodeSearched(regeocodeResult : RegeocodeResult, i : Int) {
			if (i == 1000) {
				success(regeocodeResult.regeocodeAddress.formatAddress)
				LogUtil.print("离线任务 singleLocation 逆地理编码",
					regeocodeResult.regeocodeAddress.formatAddress)
			} else {
				failed("地址获取失败")
				LogUtil.print("离线任务 逆地理失败 ", regeocodeResult.toString())
			}
		}

		override fun onGeocodeSearched(geocodeResult : GeocodeResult, i : Int) {}
	})
}