lizhanwei
2020-03-16 6e512f99ae6d56f52cd79ff7ea7245a431be4dbb
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
package safeluck.drive.evaluation.DB.appstatusdb;
 
import android.content.Context;
import android.util.Log;
 
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
 
import com.anyun.exam.lib.MyLog;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import java.lang.reflect.Type;
 
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.DB.WorkRoomDataBase;
import safeluck.drive.evaluation.platformMessage.PlatFormConstant;
 
public class AppStatusWorker extends Worker {
 
    private static final String TAG = "AppStatusWorker";
    private AppStatusDao appStatusDao;
 
 
    public AppStatusWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
        MyLog.i("初始化AppStatusWorker");
        appStatusDao = WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getAppStatusDao();
    }
 
    @NonNull
    @Override
    public Result doWork() {
        String[] str = getInputData().getStringArray(Constant.APP_STATUS);
        JSONObject jsonObject = null;
        MyLog.i("AppStatusWorker:"+str[0]+": "+str[1]);
        try {
            jsonObject = new JSONObject(str[1]);
            switch (str[0]) {
                case Constant.RTK_LOGIN_CODE_COLUMN:
                    int login =jsonObject.getInt("login_code");
                            appStatusDao.updateRTKLoginCode(login);
                    break;
                case Constant.RTK_CONN_STATUS_COLUMN:
                    int conn =jsonObject.getInt("connected");
                    appStatusDao.updateRTKConnectStatus(conn);
                    break;
                case Constant.WORK_PLATFORM_STATUS_COLUMN:
                    int workconn =jsonObject.getInt("work_platform");
                    appStatusDao.updatework_platformStatus(workconn);
                    break;
 
                case Constant.RTK_INFO_SAT_QF:
                    int qf = jsonObject.getInt("qf");
                    int satNum = jsonObject.getInt("sat_num");
 
                        appStatusDao.updatedQf(qf);
 
                        appStatusDao.updatedSatNum(satNum);
 
 
                    break;
 
            }
 
            return Result.success();
        } catch (JSONException e) {
            e.printStackTrace();
            return Result.failure();
        }
 
    }
}