From b5c6c200d60aae805614495512ab24eafcce1fb9 Mon Sep 17 00:00:00 2001
From: lizhanwei <Dana_Lee1016@126.com>
Date: 星期四, 02 四月 2020 17:53:45 +0800
Subject: [PATCH] 摆正考试地图

---
 app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt b/app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt
index 8c0ce4a..cf6a15f 100644
--- a/app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt
+++ b/app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt
@@ -1,20 +1,31 @@
 package safeluck.drive.evaluation.DB.rtktb
 
 import android.content.Context
+import android.os.Looper
 import android.text.TextUtils
 import android.util.Log
+import android.widget.Toast
 import androidx.work.Worker
 import androidx.work.WorkerParameters
 import com.anyun.exam.lib.AYSdk
 import com.anyun.exam.lib.MyLog
 import com.google.gson.Gson
+import okhttp3.ResponseBody
 import org.json.JSONException
 import org.json.JSONObject
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
 import safeluck.drive.evaluation.DB.Constant
 import safeluck.drive.evaluation.DB.WorkRoomDataBase
 import safeluck.drive.evaluation.bean.ExamPlatformData
+import safeluck.drive.evaluation.httpmodule.HttpCarRespBean
+import safeluck.drive.evaluation.httpmodule.HttpRequetBean
+import safeluck.drive.evaluation.httpmodule.RetrofitCreator.Companion.getRestService
 import safeluck.drive.evaluation.im.IMSClientBootstrap
 import safeluck.drive.evaluation.platformMessage.PlatFormConstant
+import safeluck.drive.evaluation.util.FileUtil
+import java.io.IOException
 
 class RTKConfigUpdateWorker(context:Context, workerParams: WorkerParameters) :Worker(context, workerParams){
 
@@ -43,6 +54,59 @@
              */
             phone = sn
             Log.i(TAG,"phone="+phone)
+
+            if (!FileUtil.isMapExist(applicationContext,"map.json")){
+                MyLog.i("鍦板浘鏂囦欢涓嶅瓨鍦紝鍘诲钩鍙板彇")
+                getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, "place")).enqueue(object : Callback<ResponseBody> {
+                    override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
+                        var str: String? = null
+                        try {
+                            str = response.body()!!.string()
+                        } catch (e: IOException) {
+                            e.printStackTrace()
+                        }
+                        Log.i(TAG, "鏈嶅姟鍣ㄨ繑鍥炵殑body=$str")
+                        if (Looper.myLooper() == Looper.getMainLooper()) {
+                            Toast.makeText(applicationContext, "涓荤嚎绋�", Toast.LENGTH_SHORT).show()
+                        }
+                    }
+
+                    override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
+                        Log.i(TAG, t.localizedMessage)
+                    }
+                })
+            }
+            if (!FileUtil.isMapExist(applicationContext,"car.json")){
+                MyLog.i("杞﹁締妯″瀷鏂囦欢涓嶅瓨鍦紝鍘诲钩鍙板彇")
+                getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, "car")).enqueue(object : Callback<ResponseBody> {
+                    override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
+                        var str: String? = null
+                        try {
+                            str = response.body()!!.string()
+                            Log.i(TAG, "鏈嶅姟鍣ㄨ繑鍥炵殑body=$str")
+                            val car = gson.fromJson<HttpCarRespBean>(str,HttpCarRespBean::class.java)
+                            if (car.isResult){
+                                if (car.data !=null){
+                                    str = gson.toJson(car.data.map_json)
+                                    Log.i(TAG, "瑙f瀽涔嬪悗鐨勮溅妯″瀷=$str")
+                                    FileUtil.writeTxtFileToSD(applicationContext,"car.json",str,"")
+                                }
+                            }
+                        } catch (e: IOException) {
+                            e.printStackTrace()
+                        }
+
+                        if (Looper.myLooper() == Looper.getMainLooper()) {
+                            Toast.makeText(applicationContext, "涓荤嚎绋�", Toast.LENGTH_SHORT).show()
+                        }
+                    }
+
+                    override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
+                        Log.i(TAG, t.localizedMessage)
+                    }
+                })
+            }
+
             MyLog.i(PlatFormConstant.TAG,"閲嶇疆TCP杩炴帴")
             IMSClientBootstrap.getInstance().resetConnect();
         }

--
Gitblit v1.8.0