package safeluck.drive.evaluation.DB.exam_status; import android.content.Context; import android.text.TextUtils; import androidx.annotation.NonNull; import androidx.work.WorkManager; 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; import safeluck.drive.evaluation.DB.WorkRoomDataBase; public class ExamStatusWoker extends Worker { public ExamStatusWoker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); } @NonNull @Override public Result doWork() { String str = getInputData().getString(Constant.exam_enter_exitdata); MyLog.i("考试状态更新,插入数据库="+str); if (!TextUtils.isEmpty(str)){ JSONObject jsonObject = null; try { jsonObject = new JSONObject(str); int mapId = jsonObject.getInt("map_id"); int enter = jsonObject.getInt("enter"); int type = jsonObject.getInt("type"); ExamStatus examStatus = new ExamStatus(); examStatus.setEnter(enter); examStatus.setMap_id(mapId); examStatus.setMap_item(type); WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getExamStatusDao().insert(examStatus); return Result.success(); } catch (JSONException e) { e.printStackTrace(); return Result.failure(); } } return Result.success(); } }