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();
|
}
|
}
|