From 6b566cfa3d510c841184ea2328f1e2e2c3e3c788 Mon Sep 17 00:00:00 2001 From: lizhanwei <Dana_Lee1016@126.com> Date: 星期四, 09 四月 2020 15:45:13 +0800 Subject: [PATCH] 移动站服务报错误信息的时候,给ExamOUtWorker设置输入参数,重新发送map和car。 download的时候down那个就发送那个 --- app/src/main/java/safeluck/drive/evaluation/DB/rtktb/RTKConfigUpdateWorker.kt | 275 ++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 173 insertions(+), 102 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 c338d21..aa90196 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 @@ -18,6 +18,7 @@ import retrofit2.Response import safeluck.drive.evaluation.DB.Constant import safeluck.drive.evaluation.DB.WorkRoomDataBase +import safeluck.drive.evaluation.app import safeluck.drive.evaluation.bean.ExamPlatformData import safeluck.drive.evaluation.httpmodule.HttpCarRespBean import safeluck.drive.evaluation.httpmodule.HttpRequetBean @@ -58,109 +59,10 @@ 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") + getMap(sn, "road") + getMap(sn, "yard") + getMap(sn, "car") - jsonObject = JSONObject(str) - val result = jsonObject!!.getBoolean("result") - if (result){ - if (str!!.contains("road")){ - val map = gson.fromJson<HttpRoadMapRsp>(str,HttpRoadMapRsp::class.java) - if (map.isResult){ - if (map.data != null){ - if (map.data.map_json.type.equals("road")){ - ExamPlatformData.getInstance().setNewRoadMapPath(Environment.getExternalStorageDirectory().absolutePath + "/" - + applicationContext.getPackageName() + "/roadmap.json") - CThreadPoolExecutor.runInBackground(Runnable{ - str = gson.toJson(map.data.map_json) - FileUtil.writeTxtFileToSD(applicationContext,"roadmap.json",str,"") - }) - } - - - - } - - - } - }else{ - val yard = gson.fromJson<HttpYardRsp>(str,HttpYardRsp::class.java) - if (yard.isResult){ - if (yard.data !=null){ - Log.i(TAG,"yard====") - ExamPlatformData.getInstance().setNewMapPath(Environment.getExternalStorageDirectory().absolutePath + "/" - + applicationContext.getPackageName() + "/yard.json") - CThreadPoolExecutor.runInBackground(Runnable{ - str = gson.toJson(yard.data.map_json) - FileUtil.writeTxtFileToSD(applicationContext,"yard.json",str,"") - }) - } - } - } - }else{ - Toast.makeText(applicationContext,jsonObject!!.getString("data"),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") - jsonObject = JSONObject(str) - val result = jsonObject!!.getBoolean("result") - if (result){ - val car = gson.fromJson<HttpCarRespBean>(str,HttpCarRespBean::class.java) - - if (car.isResult){ - if (car.data !=null){ - ExamPlatformData.getInstance().carModelPath = Environment.getExternalStorageDirectory().absolutePath + "/" + - applicationContext.getPackageName() + "/car.json" - - Log.i(TAG, "瑙f瀽涔嬪悗鐨勮溅妯″瀷=$str") - CThreadPoolExecutor.runInBackground(Runnable{ - str = gson.toJson(car.data.map_json) - FileUtil.writeTxtFileToSD(applicationContext,"car.json",str,"") - }) - - } - } - }else{ - Toast.makeText(applicationContext,jsonObject!!.getString("data"),Toast.LENGTH_SHORT).show() - } - - } catch (e: IOException) { - e.printStackTrace() - } - - - } - - override fun onFailure(call: Call<ResponseBody>, t: Throwable) { - Log.i(TAG, t.localizedMessage) - } - }) - } MyLog.i(PlatFormConstant.TAG,"閲嶇疆TCP杩炴帴") IMSClientBootstrap.getInstance().resetConnect(); @@ -173,6 +75,124 @@ sendRtkConfigInfo(WorkRoomDataBase.getWorkRoomDataBase(applicationContext).rtkConfigDao._getRtkConfig()) return Result.success() + } + + private fun getMap(sn: String, type: String){ + lateinit var jsonObject1 :JSONObject + lateinit var fileName :String + when(type){ + "road" -> fileName = safeluck.drive.evaluation.Constant.ROAD_MAP + "yard" -> fileName = safeluck.drive.evaluation.Constant.MAP + else -> fileName = safeluck.drive.evaluation.Constant.VEHICLE + } + if (!FileUtil.isMapExist(applicationContext,fileName)) { + getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, type)).enqueue(object : Callback<ResponseBody> { + override fun onFailure(call: Call<ResponseBody>, t: Throwable) { + MyLog.i(PlatFormConstant.HTTPTAG,t.localizedMessage) + } + + override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { + var str: String = response.body()!!.string() + MyLog.i(PlatFormConstant.HTTPTAG,str) + jsonObject1 = JSONObject(str) + val result = jsonObject1!!.getBoolean("result") + if (result) { + when(type){ + "road" ->{ + val map = gson.fromJson<HttpRoadMapRsp>(str, HttpRoadMapRsp::class.java) + if (map.isResult) { + if (map.data != null) { + if (map.data.map_json.type.equals("road")) { + ExamPlatformData.getInstance().setNewRoadMapPath(Environment.getExternalStorageDirectory().absolutePath + "/" + + applicationContext.getPackageName() + "/" + fileName) + CThreadPoolExecutor.runInBackground(Runnable { + str = gson.toJson(map.data.map_json) + FileUtil.writeTxtFileToSD(applicationContext, fileName, str, "") + sendRoadMapInfo() + }) + } + + + } + + + }} + "yard" ->{ + val yard = gson.fromJson<HttpYardRsp>(str,HttpYardRsp::class.java) + if (yard.isResult){ + if (yard.data !=null){ + Log.i(TAG,"yard====") + ExamPlatformData.getInstance().setNewMapPath(Environment.getExternalStorageDirectory().absolutePath + "/" + + applicationContext.getPackageName() + "/"+fileName) + CThreadPoolExecutor.runInBackground(Runnable{ + str = gson.toJson(yard.data.map_json) + FileUtil.writeTxtFileToSD(applicationContext,fileName,str,"") + sendMapInfo() + }) + } + } + } + else ->{ + val car = gson.fromJson<HttpCarRespBean>(str,HttpCarRespBean::class.java) + + if (car.isResult){ + if (car.data !=null){ + ExamPlatformData.getInstance().carModelPath = Environment.getExternalStorageDirectory().absolutePath + "/" + + applicationContext.getPackageName() + "/"+fileName + + Log.i(TAG, "瑙f瀽涔嬪悗鐨勮溅妯″瀷=$str") + CThreadPoolExecutor.runInBackground(Runnable{ + str = gson.toJson(car.data.map_json) + FileUtil.writeTxtFileToSD(applicationContext,fileName,str,"") + sendVehicleInfo() + }) + + } + } + } + } + + } else { + Toast.makeText(applicationContext, jsonObject1!!.getString("data"), Toast.LENGTH_SHORT).show() + } + } + }) + + }else{ + MyLog.i(PlatFormConstant.HTTPTAG,"宸插瓨鍦ㄧ洿鎺ュ彂閫佽溅杈嗗拰鍦板浘") + when(type){ + "road" -> sendRoadMapInfo() + "yard" -> sendMapInfo() + else -> sendVehicleInfo() + } + + } + } + + private fun sendRoadMapInfo(){ + val roadmapPath = ExamPlatformData.getInstance().roadMapPath + + if (!TextUtils.isEmpty(roadmapPath)) { + MyLog.i("璋冪敤鏇存柊RoadMap璺緞鍚庣殑鍦板浘$roadmapPath") + val fileContent = FileUtil.readFile(roadmapPath) + if (fileContent != null) { + val str = String(fileContent) + Log.i(TAG,"鏂囦欢鍐呭锛�$str") + AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_ROAD_MAP_INFO, str) + } else { + MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�", roadmapPath)) + CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), "鏂囦欢锛�" + roadmapPath + "涓嶅瓨鍦�", Toast.LENGTH_SHORT).show() } + } + } else { + val buffer: StringBuffer? + buffer = FileUtil.readAssetTxtFile(applicationContext, safeluck.drive.evaluation.Constant.ROAD_MAP) + if (buffer != null) { + AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_ROAD_MAP_INFO, buffer.toString()) + } else { + MyLog.i(String.format("鍦板浘妯″瀷鏈嫹鍏%s]鐩綍涓�", Environment.getExternalStorageDirectory().absolutePath + "/" + applicationContext.packageName)) + CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), String.format("鍦板浘妯″瀷鏈嫹鍏%s]鐩綍涓�", Environment.getExternalStorageDirectory().absolutePath + "/" + applicationContext.packageName), Toast.LENGTH_SHORT).show() } + } + } } private fun sendRtkConfigInfo(mRTKConfig: RTKConfig) { @@ -195,4 +215,55 @@ } } + + + private fun sendMapInfo(){ + val mapPath = ExamPlatformData.getInstance().mapPath + + + if (!TextUtils.isEmpty(mapPath)) { + MyLog.i("璋冪敤鏇存柊Map璺緞鍚庣殑鍦板浘$mapPath") + val fileContent = FileUtil.readFile(mapPath) + if (fileContent != null) { + val str = String(fileContent) + Log.i(TAG,"鏂囦欢鍐呭锛�$str") + AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_MAP_INFO, str) + } else { + MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�", mapPath)) + CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), "鏂囦欢锛�" + mapPath + "涓嶅瓨鍦�", Toast.LENGTH_SHORT).show() } + } + } else { + MyLog.i("璇诲彇Assert鐩綍涓嬪垵濮嬪寲鐨勫湴鍥�") + var buffer: StringBuffer? + buffer = FileUtil.readAssetTxtFile(applicationContext, safeluck.drive.evaluation.Constant.MAP) + if (buffer != null) { + AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_MAP_INFO, buffer.toString()) + } else { + MyLog.i( String.format("鍦板浘妯″瀷鏈嫹鍏%s]鐩綍涓�", Environment.getExternalStorageDirectory().absolutePath + "/" + applicationContext.packageName)) + CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), String.format("鍦板浘妯″瀷鏈嫹鍏%s]鐩綍涓�", Environment.getExternalStorageDirectory().absolutePath + "/" + applicationContext.packageName), Toast.LENGTH_SHORT).show() } + } + } + } + + private fun sendVehicleInfo(){ + val carPath = ExamPlatformData.getInstance().carModelPath + if (!TextUtils.isEmpty(carPath)) { + MyLog.i("浣跨敤鏇存柊鍚庣殑Car妯″瀷鍦板浘$carPath") + val bytes = FileUtil.readFile(carPath) + if (bytes != null) { + val str = String(bytes) + AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_VECHILE_PROFILE, str) + } else { + MyLog.i(String.format("鏂囦欢:%s涓嶅瓨鍦�", carPath)) + } + } else { + val vebuffer = FileUtil.readAssetTxtFile(applicationContext, safeluck.drive.evaluation.Constant.VEHICLE) + if (vebuffer != null) { + AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_VECHILE_PROFILE, vebuffer.toString()) + } else { + MyLog.i(String.format("杞﹁締妯″瀷妯″瀷鏈嫹鍏%s]鐩綍涓�", Environment.getExternalStorageDirectory().absolutePath + "/" + applicationContext.packageName)) + } + } + } + } \ No newline at end of file -- Gitblit v1.8.0