Commit ca126615 authored by YONG-LIN SU's avatar YONG-LIN SU

修正部分案件查詢帶入當天日期

parent 20f3f571
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
</deviceKey> </deviceKey>
</Target> </Target>
</runningDeviceTargetSelectedWithDropDown> </runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-08-23T05:10:09.651008900Z" /> <timeTargetWasSelectedWithDropDown value="2022-08-23T06:16:20.971608400Z" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -23,9 +23,15 @@ public interface CaseDao { ...@@ -23,9 +23,15 @@ public interface CaseDao {
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId") @Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId")
List<CaseAndAllCasePhoto> getAllWithCasePhotoByShitAndUserId(Shift shift, int userId); List<CaseAndAllCasePhoto> getAllWithCasePhotoByShitAndUserId(Shift shift, int userId);
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId AND case_time>=:startDate AND case_time<=:endDate")
List<CaseAndAllCasePhoto> getAllWithCasePhotoByShitAndUserIdInDay(Shift shift, int userId, Date startDate, Date endDate);
@Query("SELECT * FROM `case` WHERE space_id=:spaceId") @Query("SELECT * FROM `case` WHERE space_id=:spaceId")
List<CaseAndAllCasePhoto> getAllWithCasePhotoBySpace(String spaceId); List<CaseAndAllCasePhoto> getAllWithCasePhotoBySpace(String spaceId);
@Query("SELECT * FROM `case` WHERE space_id=:spaceId AND shift=:shift AND user_id=:userId AND case_time>=:startDate AND case_time<=:endDate")
List<CaseAndAllCasePhoto> getAllWithCasePhotoBySpaceAndShiftAndUserIdInDay(String spaceId, Shift shift, int userId, Date startDate, Date endDate);
@Query("SELECT * FROM `case`") @Query("SELECT * FROM `case`")
List<Case> getAll(); List<Case> getAll();
...@@ -47,6 +53,9 @@ public interface CaseDao { ...@@ -47,6 +53,9 @@ public interface CaseDao {
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId") @Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId")
List<Case> getAllByShiftAndUser(Shift shift, int userId); List<Case> getAllByShiftAndUser(Shift shift, int userId);
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId AND case_time>=:startDate AND case_time<=:endDate")
List<Case> getAllByShiftAndUserInDay(Shift shift, int userId,Date startDate, Date endDate);
@Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId") @Query("SELECT * FROM `case` WHERE shift=:shift AND user_id=:userId")
LiveData<List<Case>> getAllByShiftAndUserLiveData(Shift shift, int userId); LiveData<List<Case>> getAllByShiftAndUserLiveData(Shift shift, int userId);
......
...@@ -2,6 +2,10 @@ package ecom.android.newparkapp.repository; ...@@ -2,6 +2,10 @@ package ecom.android.newparkapp.repository;
import android.app.Application; import android.app.Application;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -18,6 +22,9 @@ import ecom.android.newparkapp.dao.VehicleBrandDao; ...@@ -18,6 +22,9 @@ import ecom.android.newparkapp.dao.VehicleBrandDao;
import ecom.android.newparkapp.dao.VehicleColorDao; import ecom.android.newparkapp.dao.VehicleColorDao;
import ecom.android.newparkapp.dao.VehicleTypeDao; import ecom.android.newparkapp.dao.VehicleTypeDao;
import ecom.android.newparkapp.database.InfoDatabase; import ecom.android.newparkapp.database.InfoDatabase;
import ecom.android.newparkapp.entity.Case;
import ecom.android.newparkapp.entity.CaseAndAllCasePhoto;
import ecom.android.newparkapp.entity.Shift;
public class InfoRepository { public class InfoRepository {
private InfoDatabase infoDatabase; private InfoDatabase infoDatabase;
...@@ -38,6 +45,8 @@ public class InfoRepository { ...@@ -38,6 +45,8 @@ public class InfoRepository {
public CaseDao caseDao; public CaseDao caseDao;
public CasePhotoDao casePhotoDao; public CasePhotoDao casePhotoDao;
private Date startDate, endDate = new Date();
public InfoRepository(Application application) { public InfoRepository(Application application) {
infoDatabase = InfoDatabase.getInstance(application); infoDatabase = InfoDatabase.getInstance(application);
...@@ -57,4 +66,35 @@ public class InfoRepository { ...@@ -57,4 +66,35 @@ public class InfoRepository {
executorService = Executors.newFixedThreadPool(application.getResources().getInteger(R.integer.number_db_thread_pool)); executorService = Executors.newFixedThreadPool(application.getResources().getInteger(R.integer.number_db_thread_pool));
} }
public List<Case> getAllCaseByShiftAndUserToday(Shift shift, int userId){
getStartEndToday();
return caseDao.getAllByShiftAndUserInDay(shift, userId, startDate, endDate);
}
public List<CaseAndAllCasePhoto> getAllCaseWithCasePhotoByShiftAndUserToday(Shift shift, int userId){
getStartEndToday();
return caseDao.getAllWithCasePhotoByShitAndUserIdInDay(shift, userId, startDate, endDate);
}
public List<CaseAndAllCasePhoto> getAllWithCasePhotoBySpaceAndShiftAndUserIdToday(String spaceId, Shift shift, int userId){
getStartEndToday();
return caseDao.getAllWithCasePhotoBySpaceAndShiftAndUserIdInDay(spaceId, shift, userId, startDate, endDate);
}
private void getStartEndToday()
{
Calendar calendar = Calendar.getInstance(Locale.getDefault());
calendar.set(Calendar.HOUR_OF_DAY,0); // HOUR_OF_DAY 才是24小時制
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
startDate = calendar.getTime();
calendar.set(Calendar.HOUR_OF_DAY,23); // HOUR_OF_DAY 才是24小時制
calendar.set(Calendar.MINUTE,59);
calendar.set(Calendar.SECOND,59);
calendar.set(Calendar.MILLISECOND,999);
endDate = calendar.getTime();
}
} }
...@@ -705,7 +705,7 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -705,7 +705,7 @@ public class T02StartActivity extends AppCompatActivity {
private void btnSearchingParkingSpaceOnClicked(){ private void btnSearchingParkingSpaceOnClicked(){
Case tempCase = t02StartViewModel.getCurrentCase().getValue(); Case tempCase = t02StartViewModel.getCurrentCase().getValue();
if (tempCase == null){ if (tempCase == null || tempCase.caseStatus != CaseStatus.NEW){
return; return;
} }
if (tempCase.space != null) if (tempCase.space != null)
...@@ -715,6 +715,8 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -715,6 +715,8 @@ public class T02StartActivity extends AppCompatActivity {
intent.setClass(this, T03SearchingParkingSpaceActivity.class); intent.setClass(this, T03SearchingParkingSpaceActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable("Space", tempCase.space); bundle.putParcelable("Space", tempCase.space);
bundle.putInt("UserId", currentUser.id);
bundle.putParcelable("Shift", shift);
intent.putExtras(bundle); intent.putExtras(bundle);
searchingParkingSpaceActivityResultLauncher.launch(intent); searchingParkingSpaceActivityResultLauncher.launch(intent);
......
...@@ -53,7 +53,8 @@ public class T03ListFilesActivity extends AppCompatActivity { ...@@ -53,7 +53,8 @@ public class T03ListFilesActivity extends AppCompatActivity {
} }
}); });
infoRepository = new InfoRepository(getApplication()); infoRepository = new InfoRepository(getApplication());
caseAndAllCasePhotos = infoRepository.caseDao.getAllWithCasePhotoByShitAndUserId(shift, userId); // caseAndAllCasePhotos = infoRepository.caseDao.getAllWithCasePhotoByShitAndUserId(shift, userId);
caseAndAllCasePhotos = infoRepository.getAllCaseWithCasePhotoByShiftAndUserToday(shift, userId);
caseListAdapter.submitList(caseAndAllCasePhotos); caseListAdapter.submitList(caseAndAllCasePhotos);
......
...@@ -16,6 +16,7 @@ import ecom.android.newparkapp.adapter.LargeCaseListAdapter; ...@@ -16,6 +16,7 @@ import ecom.android.newparkapp.adapter.LargeCaseListAdapter;
import ecom.android.newparkapp.databinding.ActivityT03SearchingParkingSpaceBinding; import ecom.android.newparkapp.databinding.ActivityT03SearchingParkingSpaceBinding;
import ecom.android.newparkapp.entity.Case; import ecom.android.newparkapp.entity.Case;
import ecom.android.newparkapp.entity.CaseAndAllCasePhoto; import ecom.android.newparkapp.entity.CaseAndAllCasePhoto;
import ecom.android.newparkapp.entity.Shift;
import ecom.android.newparkapp.entity.Space; import ecom.android.newparkapp.entity.Space;
import ecom.android.newparkapp.repository.InfoRepository; import ecom.android.newparkapp.repository.InfoRepository;
...@@ -24,9 +25,16 @@ public class T03SearchingParkingSpaceActivity extends AppCompatActivity { ...@@ -24,9 +25,16 @@ public class T03SearchingParkingSpaceActivity extends AppCompatActivity {
private Space selectedSpace; private Space selectedSpace;
private LargeCaseListAdapter largeCaseListAdapter; private LargeCaseListAdapter largeCaseListAdapter;
private InfoRepository infoRepository; private InfoRepository infoRepository;
private int userId;
private Shift shift;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
shift = bundle.getParcelable("Shift");
userId = bundle.getInt("UserId");
dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_t03_searching_parking_space); dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_t03_searching_parking_space);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null){ if (actionBar != null){
...@@ -59,7 +67,8 @@ public class T03SearchingParkingSpaceActivity extends AppCompatActivity { ...@@ -59,7 +67,8 @@ public class T03SearchingParkingSpaceActivity extends AppCompatActivity {
} }
}); });
List<CaseAndAllCasePhoto> caseAndAllCasePhotos = infoRepository.caseDao.getAllWithCasePhotoBySpace(selectedSpace.id); //List<CaseAndAllCasePhoto> caseAndAllCasePhotos = infoRepository.caseDao.getAllWithCasePhotoBySpace(selectedSpace.id);
List<CaseAndAllCasePhoto> caseAndAllCasePhotos = infoRepository.getAllWithCasePhotoBySpaceAndShiftAndUserIdToday(selectedSpace.id, shift, userId);
if (caseAndAllCasePhotos.size() == 0){ if (caseAndAllCasePhotos.size() == 0){
emptyResult(); emptyResult();
} }
......
...@@ -140,7 +140,7 @@ public class T04RenewListActivity extends AppCompatActivity { ...@@ -140,7 +140,7 @@ public class T04RenewListActivity extends AppCompatActivity {
} }
private void updateData(boolean isNear){ private void updateData(boolean isNear){
cases = infoRepository.caseDao.getAllByShiftAndUser(shift, userId); cases = infoRepository.getAllCaseByShiftAndUserToday(shift, userId);
Map<String, List<Case>> casesGroupByRoad = cases.stream().collect(Collectors.groupingBy(c->c.space.road.getCombineInfo())); Map<String, List<Case>> casesGroupByRoad = cases.stream().collect(Collectors.groupingBy(c->c.space.road.getCombineInfo()));
Location location = fusedGpsViewModel.getLocation().getValue(); Location location = fusedGpsViewModel.getLocation().getValue();
...@@ -196,7 +196,7 @@ public class T04RenewListActivity extends AppCompatActivity { ...@@ -196,7 +196,7 @@ public class T04RenewListActivity extends AppCompatActivity {
private class NotifyNestedReNewTimerTask extends TimerTask { private class NotifyNestedReNewTimerTask extends TimerTask {
@Override @Override
public void run() { public void run() {
List<Case> caseList = infoRepository.caseDao.getAllByShiftAndUser(shift, userId); List<Case> caseList = infoRepository.getAllCaseByShiftAndUserToday(shift, userId);
Location location = fusedGpsViewModel.getLocation().getValue(); Location location = fusedGpsViewModel.getLocation().getValue();
boolean isNeedNotify = false; boolean isNeedNotify = false;
for (Case c: caseList) { for (Case c: caseList) {
......
...@@ -116,6 +116,9 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -116,6 +116,9 @@ public class T02StartViewModel extends AndroidViewModel {
public void setSpace(Space space){ public void setSpace(Space space){
Case tempCase = currentCase.getValue(); Case tempCase = currentCase.getValue();
if (tempCase.caseStatus != CaseStatus.NEW){
return;
}
tempCase.space = space; tempCase.space = space;
// 取得車格後,更新費用及時間 // 取得車格後,更新費用及時間
...@@ -624,7 +627,9 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -624,7 +627,9 @@ public class T02StartViewModel extends AndroidViewModel {
if (user == null){ if (user == null){
return; return;
} }
cases = infoRepository.caseDao.getAllByShiftAndUser(shift, user.id); //cases = infoRepository.caseDao.getAllByShiftAndUser(shift, user.id);
cases = infoRepository.getAllCaseByShiftAndUserToday(shift, user.id);
for (int i = 0; i < cases.size(); i ++){ for (int i = 0; i < cases.size(); i ++){
cases.get(i).caseStatus = CaseStatus.LIST; cases.get(i).caseStatus = CaseStatus.LIST;
} }
......
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