加入失败项目表,所有失败项都记录到这表;然后通过多表查询所对应的记录;还未完善,可以跑
| | |
| | | import safeluck.drive.evaluation.DB.criterias.CriteriaForI; |
| | | import safeluck.drive.evaluation.DB.criterias.CriteriaForIWorker; |
| | | import safeluck.drive.evaluation.DB.criterias.CriteriaIDao; |
| | | import safeluck.drive.evaluation.DB.failitems.FailProjDao; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProjWorker; |
| | | |
| | | |
| | | /** |
| | |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | @Database(entities = {Student.class, CriteriaForI.class},version = 1,exportSchema = false) |
| | | @Database(entities = {Student.class, CriteriaForI.class, FailedProj.class},version = 1,exportSchema = false) |
| | | public abstract class WorkRoomDataBase extends RoomDatabase { |
| | | private static final String TAG = "WorkRoomDataBase"; |
| | | public abstract StudentDao getstudentDao(); |
| | | public abstract CriteriaIDao getCriteriaIDao(); |
| | | public abstract FailProjDao getFailProjDao(); |
| | | private static volatile WorkRoomDataBase workRoomDataBase; |
| | | |
| | | private static final int NUMBER_OF_THREADS = 4; |
| | |
| | | super.onCreate(db); |
| | | OneTimeWorkRequest oneTimeWorkRequest = OneTimeWorkRequest.from(SeedDatabaseWorker.class); |
| | | OneTimeWorkRequest oneTimeWorkRequest1 = OneTimeWorkRequest.from(CriteriaForIWorker.class); |
| | | OneTimeWorkRequest oneTimeWorkRequest2 = OneTimeWorkRequest.from(FailedProjWorker.class); |
| | | Log.i(TAG, "onCreate: 创建数据库后建立数据表插入数据"); |
| | | WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest); |
| | | WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest1); |
| | | WorkManager.getInstance(mContext).enqueue(oneTimeWorkRequest2); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | return workRoomDataBase; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | import androidx.lifecycle.LiveData; |
| | | import androidx.room.Dao; |
| | | import androidx.room.Insert; |
| | | import androidx.room.Query; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/11/26. 18:08:08 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | @Dao |
| | | public interface FailProjDao { |
| | | |
| | | @Insert |
| | | void insert(FailedProj proj); |
| | | |
| | | @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(); |
| | | |
| | | @Query("SELECT COUNT(*) from fail_projects where subject=:subject_id") |
| | | LiveData<Integer> getSubject(int subject_id); |
| | | } |
New file |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | import androidx.room.ColumnInfo; |
| | | import androidx.room.Entity; |
| | | import androidx.room.ForeignKey; |
| | | import androidx.room.Index; |
| | | import androidx.room.PrimaryKey; |
| | | |
| | | import safeluck.drive.evaluation.DB.criterias.CriteriaForI; |
| | | |
| | | import static androidx.room.ForeignKey.CASCADE; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * 失败项目条目 |
| | | * Created by lzw on 2019/11/26. 17:59:20 |
| | | * 邮箱:632393724@qq.com |
| | | * 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")) |
| | | public class FailedProj { |
| | | @PrimaryKey(autoGenerate = true) |
| | | private int id; |
| | | |
| | | @ColumnInfo(name = "subject") |
| | | private int subject; |
| | | |
| | | @ColumnInfo(name = "emp_id") |
| | | private int emp_id;//作为外键,对应I类考场的item_id |
| | | |
| | | public FailedProj(int subject, int emp_id) { |
| | | this.subject = subject; |
| | | this.emp_id = emp_id; |
| | | } |
| | | |
| | | public int getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(int id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public int getSubject() { |
| | | return subject; |
| | | } |
| | | |
| | | public void setSubject(int subject) { |
| | | this.subject = subject; |
| | | } |
| | | |
| | | public int getEmp_id() { |
| | | return emp_id; |
| | | } |
| | | |
| | | public void setEmp_id(int emp_id) { |
| | | this.emp_id = emp_id; |
| | | } |
| | | } |
New file |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | import android.content.Context; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.work.Worker; |
| | | import androidx.work.WorkerParameters; |
| | | |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/11/26. 18:10:32 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class FailedProjWorker extends Worker { |
| | | |
| | | public FailedProjWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { |
| | | super(context, workerParams); |
| | | } |
| | | |
| | | @NonNull |
| | | @Override |
| | | public Result doWork() { |
| | | WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getFailProjDao().insert(new FailedProj(1,5)); |
| | | return Result.success(); |
| | | } |
| | | } |
New file |
| | |
| | | package safeluck.drive.evaluation.DB.failitems; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/11/26. 18:22:03 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class FailedProj_select { |
| | | |
| | | private int emp_id; |
| | | private String item_content; |
| | | private String deducting_reason; |
| | | private int score_deducting; |
| | | |
| | | public int getEmp_id() { |
| | | return emp_id; |
| | | } |
| | | |
| | | public void setEmp_id(int emp_id) { |
| | | this.emp_id = emp_id; |
| | | } |
| | | |
| | | public String getItem_content() { |
| | | return item_content; |
| | | } |
| | | |
| | | public void setItem_content(String item_content) { |
| | | this.item_content = item_content; |
| | | } |
| | | |
| | | public String getDeducting_reason() { |
| | | return deducting_reason; |
| | | } |
| | | |
| | | public void setDeducting_reason(String deducting_reason) { |
| | | this.deducting_reason = deducting_reason; |
| | | } |
| | | |
| | | public int getScore_deducting() { |
| | | return score_deducting; |
| | | } |
| | | |
| | | public void setScore_deducting(int score_deducting) { |
| | | this.score_deducting = score_deducting; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "FailedProj_select{" + |
| | | "emp_id=" + emp_id + |
| | | ", item_content='" + item_content + '\'' + |
| | | ", deducting_reason='" + deducting_reason + '\'' + |
| | | ", score_deducting=" + score_deducting + |
| | | '}'; |
| | | } |
| | | } |
| | |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.Button; |
| | | import android.widget.Toast; |
| | | |
| | | import androidx.appcompat.widget.AppCompatEditText; |
| | | import androidx.lifecycle.LifecycleOwner; |
| | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WokViewModel; |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | import safeluck.drive.evaluation.DB.criterias.CriteriaForI; |
| | | import safeluck.drive.evaluation.DB.criterias.viewmodel.CriteriaIViewModel; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj_select; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.tcp.ConnectThread; |
| | | |
| | |
| | | public void onClick(View v) { |
| | | switch (v.getId()){ |
| | | case R.id.btn_connect: |
| | | String serverIp = ip.getText().toString().trim(); |
| | | String serverPort = port.getText().toString().trim(); |
| | | connectThread = new ConnectThread(serverIp,Integer.parseInt(serverPort)); |
| | | connectThread.start(); |
| | | // String serverIp = ip.getText().toString().trim(); |
| | | // String serverPort = port.getText().toString().trim(); |
| | | // connectThread = new ConnectThread(serverIp,Integer.parseInt(serverPort)); |
| | | // connectThread.start(); |
| | | |
| | | WorkRoomDataBase.dataBaseWriteExecutor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | |
| | | WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().insert(new FailedProj(1,4)); |
| | | } |
| | | }); |
| | | |
| | | break; |
| | | case R.id.btn_send: |
| | |
| | | //// connectThread.sendMessage(sendEditText.getText().toString().trim()); |
| | | //// sendEditText.getText().clear(); |
| | | //// } |
| | | checkCriteria(++item_id); |
| | | |
| | | break; |
| | | } |
| | | } |
| | |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.ListView; |
| | | import android.widget.Toast; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.DB.Student; |
| | | import safeluck.drive.evaluation.DB.WokViewModel; |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase; |
| | | import safeluck.drive.evaluation.DB.failitems.FailedProj_select; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.adapter.ScoreAdapter; |
| | | import safeluck.drive.evaluation.bean.ScoreBean; |
| | |
| | | private static final String TAG = TrainFragment.class.getSimpleName(); |
| | | private ListView mListView ; |
| | | private ScoreAdapter mScoreAdapter; |
| | | |
| | | private int item_id; |
| | | |
| | | private List<ScoreBean> mArrayList = new ArrayList<>(); |
| | | |
| | |
| | | } |
| | | }); |
| | | |
| | | |
| | | 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>>() { |
| | | @Override |
| | | public void onChanged(List<FailedProj_select> failedProj_selects) { |
| | | for (FailedProj_select f : |
| | | failedProj_selects) { |
| | | item_id += f.getScore_deducting(); |
| | | Log.i(TAG, "onChanged: "+f.toString()); |
| | | Toast.makeText(getActivity().getApplicationContext(),"得分"+item_id,Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | Log.i(TAG, "总扣分:"+item_id); |
| | | |
| | | return view; |
| | | } |
| | | private void initView(View view) { |