package safeluck.drive.evaluation.bean;
|
|
import android.os.Environment;
|
import android.renderscript.Element;
|
import android.text.TextUtils;
|
import android.util.Log;
|
import android.widget.Toast;
|
|
import com.anyun.basecommonlib.MyLog;
|
import com.anyun.exam.lib.AYSdk;
|
import com.google.gson.Gson;
|
|
import org.json.JSONObject;
|
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLDecoder;
|
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executors;
|
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.TimeUnit;
|
|
import okhttp3.ResponseBody;
|
import retrofit2.Call;
|
import retrofit2.Callback;
|
import retrofit2.Response;
|
import safeluck.drive.evaluation.Constant;
|
import safeluck.drive.evaluation.app;
|
import safeluck.drive.evaluation.httpmodule.HttpCarRespBean;
|
import safeluck.drive.evaluation.httpmodule.HttpRequetBean;
|
import safeluck.drive.evaluation.httpmodule.HttpRoadMapRsp;
|
import safeluck.drive.evaluation.httpmodule.HttpYardRsp;
|
import safeluck.drive.evaluation.httpmodule.RetrofitCreator;
|
import safeluck.drive.evaluation.platformMessage.PlatFormConstant;
|
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
|
import safeluck.drive.evaluation.util.DataInitKt;
|
import safeluck.drive.evaluation.util.FileUtil;
|
|
import static safeluck.drive.evaluation.util.DataInitKt.sendJudgeArgs;
|
|
/**
|
* DriveJudge
|
* Created by lzw on 2020/12/3. 15:45:26
|
* 邮箱:632393724@qq.com
|
* All Rights Saved! Chongqing AnYun Tech co. LTD
|
*/
|
public class AbsInitialData {
|
private UserOpStatus userOpStatus = UserOpStatus.getInstance();
|
private static boolean hasSend = false;
|
|
public static AbsInitialData getInstance(){
|
return new AbsInitialData();
|
}
|
|
private boolean checkPermission(){
|
return ExamPlatformData.getInstance().isCanWriteSD();
|
}
|
|
/***
|
* 如果服务异常死亡,可以置hasSend为false,然后sendINintdata
|
*/
|
public void resethasSendInitData(){
|
hasSend = false;
|
}
|
|
/**********f发送灯光考试项和考试状态**********/
|
private void sendLightsAndExamStatus(){
|
DataInitKt.sendExamLightsAndExamStatus(app.getAppContext());
|
}
|
|
private void sendCarModelFile(){
|
if (userOpStatus.getCarFileSelectState()== UserOpStatus.State.SELECT_CAR_FILE_STATE){
|
MyLog.i("用户在设置里面选择车模型文件");
|
DataInitKt.sendVehicleInfo();
|
}else{
|
MyLog.i("用户没有在设置里面选择车模型文件,则进行htp请求(先检查sn是否为空)");
|
if (ExamPlatformData.getInstance().getMcuSN() != null){
|
DataInitKt.getMap(ExamPlatformData.getInstance().getMcuSN(),"car");
|
}else{
|
MyLog.i("sn为空,不能请求http下载车模型");
|
}
|
}
|
|
}
|
private void sendRoadMapFile(){
|
if (userOpStatus.getRoadFileSelectState()== UserOpStatus.State.SELECT_ROAD_MAP_STATE){
|
MyLog.i("用户在设置里面选择车模型文件");
|
DataInitKt.sendRoadMapInfo();
|
}else{
|
MyLog.i("用户没有在设置里面选择车模型文件,则进行htp请求(先检查sn是否为空)");
|
if (ExamPlatformData.getInstance().getMcuSN() != null){
|
DataInitKt.getMap(ExamPlatformData.getInstance().getMcuSN(),"road");
|
}else{
|
MyLog.i("sn为空,不能请求http下载道路");
|
}
|
}
|
}
|
|
|
private void sendItemsMapFile(){
|
|
if (userOpStatus.getItemsFileSelectState()== UserOpStatus.State.SELECT_ITEMS_MAP_STATE){
|
MyLog.i("用户在设置里面选择场地文件");
|
DataInitKt.sendMapInfo();
|
}else{
|
MyLog.i("用户没有在设置里面选择场地文件,则进行htp请求(先检查sn是否为空)");
|
if (ExamPlatformData.getInstance().getMcuSN() != null){
|
DataInitKt.getMap(ExamPlatformData.getInstance().getPhone(),"yard");
|
}else{
|
MyLog.i("sn为空,不能请求http下载场地");
|
}
|
}
|
}
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
public synchronized void sendInitialData(){
|
if (checkPermission() && !hasSend){
|
/**********只有权限满足(读写SD卡权限)和没有发送过的情况下才进行以下操作*********/
|
hasSend = true;
|
sendCarModelFile();
|
sendRoadMapFile();
|
sendItemsMapFile();
|
sendJudgeArgs();
|
//需要延迟发送,因为前面有http请求
|
executorService.schedule(()->{
|
Log.i("AYJiaKao","延迟发送");
|
sendLightsAndExamStatus();},1, TimeUnit.SECONDS);
|
|
|
}else{
|
MyLog.i(hasSend?"已经发送过了初始数据":"权限不允许,不能发送初始数据");
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|