提交失败项目相关数据库表;目前FailProj会导致崩溃
| | |
| | | @Insert |
| | | void insert(FailedProj proj); |
| | | |
| | | /** |
| | | * 查询 科目二 I类考场的失败项目 (多表查询) |
| | | * 如果要添加 科目二II III类考场失败项目,需要建立相应的评判标准表数据表 |
| | | * @return |
| | | */ |
| | | @Query("SELECT emp_id,deducting_reason,score_deducting,item_content from criteria_one INNER JOIN fail_projects ON criteria_one.item_id=fail_projects.emp_id") |
| | | LiveData<List<FailedProj_select>> getFailedProjects(); |
| | | |
| | | /** |
| | | * 获取失败项目条数 |
| | | * @param subject_id |
| | | * @return |
| | | */ |
| | | @Query("SELECT COUNT(*) from fail_projects where subject=:subject_id") |
| | | LiveData<Integer> getSubject(int subject_id); |
| | | } |
| | |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | @Entity(tableName = "fail_projects",foreignKeys = @ForeignKey(entity = CriteriaForI.class, |
| | | parentColumns = "item_id",childColumns = "emp_id",onDelete = CASCADE),indices=@Index(value="emp_id")) |
| | | parentColumns = "item_id",childColumns = "emp_id")) |
| | | public class FailedProj { |
| | | @PrimaryKey(autoGenerate = true) |
| | | private int id; |
| | | |
| | | |
| | | |
| | | @ColumnInfo(name = "subject") |
| | | private int subject; |
| | | |
| | | //作为外键,对应I类考场的item_id |
| | | @ColumnInfo(name = "emp_id") |
| | | private int emp_id;//作为外键,对应I类考场的item_id |
| | | private int emp_id; |
| | | |
| | | public FailedProj(int subject, int emp_id) { |
| | | this.subject = subject; |
| | | this.emp_id = emp_id; |
| | | } |
| | | |
| | | |
| | | |
| | | public int getId() { |
| | | return id; |
| | | } |
New file |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | import android.app.Application; |
| | | |
| | | import androidx.lifecycle.LiveData; |
| | | |
| | | import java.util.List; |
| | | |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/11/27. 10:43:21 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class FailedProjRepository { |
| | | |
| | | |
| | | private FailProjDao failProjDao; |
| | | |
| | | public FailedProjRepository(Application application) { |
| | | WorkRoomDataBase dataBase = WorkRoomDataBase.getWorkRoomDataBase(application); |
| | | failProjDao = dataBase.getFailProjDao(); |
| | | } |
| | | |
| | | |
| | | public void insert(final FailedProj proj){ |
| | | WorkRoomDataBase.dataBaseWriteExecutor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | |
| | | failProjDao.insert(proj); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public LiveData<List<FailedProj_select>> getFailedProjects() { |
| | | return failProjDao.getFailedProjects(); |
| | | } |
| | | } |
New file |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | import android.app.Application; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.lifecycle.AndroidViewModel; |
| | | import androidx.lifecycle.LiveData; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/11/27. 10:42:32 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class FailedProjViewModel extends AndroidViewModel { |
| | | |
| | | FailedProjRepository failedProjRepository; |
| | | |
| | | public FailedProjViewModel(@NonNull Application application) { |
| | | super(application); |
| | | failedProjRepository = new FailedProjRepository(application); |
| | | } |
| | | |
| | | public LiveData<List<FailedProj_select>> getFailedProjects(){ |
| | | return failedProjRepository.getFailedProjects(); |
| | | } |
| | | public void insert(FailedProj proj){ |
| | | failedProjRepository.insert(proj); |
| | | } |
| | | } |
| | |
| | | import androidx.work.Worker; |
| | | import androidx.work.WorkerParameters; |
| | | |
| | | import com.anyun.exam.lib.MyLog; |
| | | |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | |
| | | /** |
| | |
| | | */ |
| | | public class FailedProjWorker extends Worker { |
| | | |
| | | |
| | | private static final String TAG= "FailedProjWorker"; |
| | | |
| | | public FailedProjWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { |
| | | super(context, workerParams); |
| | | } |
| | |
| | | @NonNull |
| | | @Override |
| | | public Result doWork() { |
| | | MyLog.i(TAG,"预置一条失败项目"); |
| | | WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getFailProjDao().insert(new FailedProj(1,5)); |
| | | return Result.success(); |
| | | } |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | import androidx.room.ColumnInfo; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/11/26. 18:22:03 |
| | |
| | | */ |
| | | public class FailedProj_select { |
| | | |
| | | @ColumnInfo(name = "emp_id") |
| | | private int emp_id; |
| | | private String item_content; |
| | | private String deducting_reason; |
| | |
| | | import com.google.android.material.textfield.TextInputEditText; |
| | | |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | |
| | | @Override |
| | | public void run() { |
| | | |
| | | WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().insert(new FailedProj(1,4)); |
| | | WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().insert(new FailedProj(1, new Random(30).nextInt()+1)); |
| | | } |
| | | }); |
| | | |
| | |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WokViewModel; |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProjViewModel; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj_select; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.adapter.ScoreAdapter; |
| | |
| | | |
| | | @Nullable |
| | | @Override |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | View view = inflater.inflate(R.layout.layout_train_fragment,container,false); |
| | | initView(view); |
| | | |
| | |
| | | }); |
| | | |
| | | |
| | | WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getSubject(1).observe(this, new Observer<Integer>() { |
| | | @Override |
| | | public void onChanged(Integer integers) { |
| | | item_id = 0; |
| | | WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getFailedProjects().observe(TrainFragment.this, new Observer<List<FailedProj_select>>() { |
| | | FailedProjViewModel failedProjViewModel =ViewModelProviders.of(this).get(FailedProjViewModel.class); |
| | | failedProjViewModel.getFailedProjects().observe(this, new Observer<List<FailedProj_select>>() { |
| | | @Override |
| | | public void onChanged(List<FailedProj_select> failedProj_selects) { |
| | | item_id = 0; |
| | | for (FailedProj_select f : |
| | | failedProj_selects) { |
| | | item_id += f.getScore_deducting(); |
| | |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | Log.i(TAG, "总扣分:"+item_id); |
| | | |
| | | return view; |
| | | } |