endian11
2020-12-04 8ee5db35d4b70cd13ca31d3783f427208aa8c0a4
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
package safeluck.drive.evaluation.DB;
 
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
 
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
 
import com.anyun.basecommonlib.MyLog;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.bean.ExamPlatformData;
 
public class StudentInfoUpdateWork extends Worker {
 
    private static final String TAG = "StudentInfoUpdateWork";
    public StudentInfoUpdateWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }
 
    @NonNull
    @Override
    public Result doWork() {
        String str = getInputData().getString(Constant.STU_INFO_PLATFORM);
        if (!TextUtils.isEmpty(str)){
            Log.i(TAG, "doWork: "+str);
            JSONObject jsonObject = null;
 
            try {
                jsonObject = new JSONObject(str);
                int  personType = jsonObject.getInt("personType");
                String  id = jsonObject.getString("ID");
                String  name = jsonObject.getString("name");
                String  head_url = jsonObject.getString("head_url");
                int sex = 2;//默认是女生
                if (id!=null&&id.length()>=18){
                    sex = Integer.parseInt(id.substring(id.length()-2,id.length()-1));
                    Log.i(TAG,"sex="+sex);
                    if ( sex%2==0){
                        Log.i(TAG,"偶数是女生");
                        sex =2;
                    }else{
                        sex = 1;
                    }
                }
                Student student = new Student();
                switch (personType){
                    case ExamPlatformData
                            .PERSON_TYPE_COACH:
                        //教练
                        student.setStu_id(ExamPlatformData
                                .COACH_ID);
//                        ExamPlatformData.getInstance().setCoachSign(false);
                        break;
                    case ExamPlatformData
                            .PERSON_TYPE_STU:
                        //学员
                        student.setStu_id(ExamPlatformData
                                .STU_ID);
//                        ExamPlatformData.getInstance().setStuSign(false);
                        break;
                        default:break;
                }
                student.setName(name);
                student.setSex(sex);
                student.setID(id);
                student.setHead_url(head_url);
                student.setPersonType(personType);
                MyLog.i("更新签到人员信息:"+student.toString());
                WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getstudentDao().insert(student);
                return Result.success();
            } catch (JSONException e) {
                e.printStackTrace();
                return Result.failure();
            }
        }
        return Result.success();
    }
}