1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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?"已经发送过了初始数据":"权限不允许,不能发送初始数据");
        }
 
    }
 
 
 
 
 
 
 
 
 
}