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.exam.lib.MyLog;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import safeluck.drive.evaluation.Constant;
|
|
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);
|
String headUrl = jsonObject.getString("head_url");
|
String id = jsonObject.getString("ID");
|
String name = jsonObject.getString("name");
|
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(1001,name,id,sex);
|
student.setHead_url(headUrl);
|
MyLog.i("更新签到人员信息:"+student.toString());
|
WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getstudentDao().insert(student);
|
return Result.success();
|
} catch (JSONException e) {
|
e.printStackTrace();
|
return Result.failure();
|
}
|
}
|
return Result.success();
|
}
|
}
|