lizhanwei
2020-03-28 babb05583f59eb5e2c853168490f54fc7261e84a
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
package safeluck.drive.evaluation.DB.criterias;
 
import android.content.Context;
 
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 com.google.gson.stream.JsonReader;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.List;
 
import safeluck.drive.evaluation.DB.Constant;
import safeluck.drive.evaluation.DB.WorkRoomDataBase;
 
/**
 * MyApplication2
 * Created by lzw on 2019/11/26. 11:59:25
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class CriteriaForIWorker extends Worker {
 
    private static final String TAG = "CriteriaForIWorker";
 
    public CriteriaForIWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }
 
    @NonNull
    @Override
    public Result doWork() {
        InputStream inputStream = null;
        try {
            inputStream = getApplicationContext().getAssets()
                    .open(Constant.CRITERIAFOR_I_JSON);
        } catch (IOException e) {
            e.printStackTrace();
        }
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        JsonReader jsonReader = new JsonReader(inputStreamReader);
        Gson gson = new Gson();
        Type type = new TypeToken<List<CriteriaForI>>(){}.getType();
 
        List<CriteriaForI> criteriaForIS = gson.fromJson(jsonReader,type);
        MyLog.i(TAG,"插入科目二,I类考场评判表");
        WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getCriteriaIDao().insertAllCriteriaI(criteriaForIS);
        return Result.success();
    }
}