Commit 90dd3290 authored by YONG-LIN SU's avatar YONG-LIN SU

修正case讀取邏輯添加過濾機制

parent 786930c0
......@@ -7,10 +7,12 @@ import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import java.util.Date;
import java.util.List;
import ecom.android.newparkapp.entity.Case;
import ecom.android.newparkapp.entity.CaseAndAllCasePhoto;
import ecom.android.newparkapp.entity.Shift;
@Dao
public interface CaseDao {
......@@ -18,6 +20,9 @@ public interface CaseDao {
@Query("SELECT * FROM `case`")
List<CaseAndAllCasePhoto> getAllWithCasePhoto();
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId")
List<CaseAndAllCasePhoto> getAllWithCasePhotoByShitAndUserId(Shift shift, int userId);
@Query("SELECT * FROM `case` WHERE space_id=:spaceId")
List<CaseAndAllCasePhoto> getAllWithCasePhotoBySpace(String spaceId);
......@@ -27,6 +32,24 @@ public interface CaseDao {
@Query("SELECT * FROM `case`")
LiveData<List<Case>> getAllLiveData();
@Query("SELECT * FROM `case` WHERE shift=:shift")
List<Case> getAllByShift(Shift shift);
@Query("SELECT * FROM `case` WHERE shift=:shift")
LiveData<List<Case>> getAllByShiftLiveData(Shift shift);
@Query("SELECT * FROM `case` WHERE shift=:shift AND case_time>=:date")
List<Case> getAllByShiftAndDate(Shift shift, Date date);
@Query("SELECT * FROM `case` WHERE shift=:shift AND case_time>=:date")
LiveData<List<Case>> getAllByShiftAndDateLiveData(Shift shift, Date date);
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId")
List<Case> getAllByShiftAndUser(Shift shift, int userId);
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId")
LiveData<List<Case>> getAllByShiftAndUserLiveData(Shift shift, int userId);
@Query("SELECT * FROM `case` WHERE billingNumber2 IN (:billingNumber2s)")
List<Case> loadAllByIds(String[] billingNumber2s);
@Insert
......
......@@ -548,6 +548,10 @@ public class T02StartActivity extends AppCompatActivity {
private void btnInventoryOnClicked() {
Intent intent = new Intent();
intent.setClass(this, T03ListFilesActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("UserId", currentUser.id);
bundle.putParcelable("Shift", shift);
intent.putExtras(bundle);
inventoryActivityResultLauncher.launch(intent);
}
......
......@@ -14,6 +14,7 @@ import ecom.android.newparkapp.adapter.CaseListAdapter;
import ecom.android.newparkapp.databinding.ActivityT03ListFilesBinding;
import ecom.android.newparkapp.entity.Case;
import ecom.android.newparkapp.entity.CaseAndAllCasePhoto;
import ecom.android.newparkapp.entity.Shift;
import ecom.android.newparkapp.repository.InfoRepository;
public class T03ListFilesActivity extends AppCompatActivity {
......@@ -22,9 +23,15 @@ public class T03ListFilesActivity extends AppCompatActivity {
private InfoRepository infoRepository;
private List<CaseAndAllCasePhoto> caseAndAllCasePhotos;
private int userId;
private Shift shift;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
shift = bundle.getParcelable("Shift");
userId = bundle.getInt("UserId");
dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_t03_list_files);
caseListAdapter = new CaseListAdapter(new CaseListAdapter.OnItemClickListener() {
@Override
......@@ -46,7 +53,7 @@ public class T03ListFilesActivity extends AppCompatActivity {
}
});
infoRepository = new InfoRepository(getApplication());
caseAndAllCasePhotos = infoRepository.caseDao.getAllWithCasePhoto();
caseAndAllCasePhotos = infoRepository.caseDao.getAllWithCasePhotoByShitAndUserId(shift, userId);
caseListAdapter.submitList(caseAndAllCasePhotos);
......
......@@ -77,12 +77,12 @@ public class T02StartViewModel extends AndroidViewModel {
vehicleTypes = infoRepository.vehicleTypeDao.getAllLiveData();
roads = infoRepository.roadDao.getAllLiveData();
spaces = infoRepository.spaceDao.getAllLiveData();
cases = infoRepository.caseDao.getAll();
for (int i = 0; i < cases.size(); i ++){
cases.get(i).caseStatus = CaseStatus.LIST;
}
caseCursor.setValue(cases.size());
// cases = infoRepository.caseDao.getAll();
// for (int i = 0; i < cases.size(); i ++){
// cases.get(i).caseStatus = CaseStatus.LIST;
// }
//
// caseCursor.setValue(cases.size());
initALPR();
......@@ -619,6 +619,17 @@ public class T02StartViewModel extends AndroidViewModel {
*/
public void setShift(Shift shift) {
this.shift.setValue(shift);
// 取得該 人員 該時段 的案件
User user = currentUser.getValue();
if (user == null){
return;
}
cases = infoRepository.caseDao.getAllByShiftAndUser(shift, user.id);
for (int i = 0; i < cases.size(); i ++){
cases.get(i).caseStatus = CaseStatus.LIST;
}
caseCursor.setValue(cases.size());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment