Commit 52208a37 authored by zhaopengxiang's avatar zhaopengxiang

优化本地关键数据存储

parent 0f9ad7f3
...@@ -18,6 +18,7 @@ import com.blankj.utilcode.util.ToastUtils ...@@ -18,6 +18,7 @@ import com.blankj.utilcode.util.ToastUtils
import com.miya.fastcashier.databinding.ActivityLoginBinding import com.miya.fastcashier.databinding.ActivityLoginBinding
import com.miya.fastcashier.service.AccountService import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.viewmodel.LoginViewModel import com.miya.fastcashier.viewmodel.LoginViewModel
import com.permissionx.guolindev.PermissionX import com.permissionx.guolindev.PermissionX
import com.permissionx.guolindev.callback.RequestCallback import com.permissionx.guolindev.callback.RequestCallback
...@@ -71,6 +72,8 @@ class LoginActivity : AppCompatActivity() { ...@@ -71,6 +72,8 @@ class LoginActivity : AppCompatActivity() {
AccountService.setUserName(username.text.toString()) AccountService.setUserName(username.text.toString())
AccountService.setAccountInfo(it1) AccountService.setAccountInfo(it1)
//根据本地存储时间,MMKV初始化合理的结算时间
LocalKeyDataMKManageKit.handleCompliantBalanceDate()
val intent = Intent() val intent = Intent()
intent.setClass(this@LoginActivity, MainActivity::class.java) intent.setClass(this@LoginActivity, MainActivity::class.java)
......
...@@ -18,6 +18,7 @@ import com.miya.fastcashier.ui.dialog.CommonDialog ...@@ -18,6 +18,7 @@ import com.miya.fastcashier.ui.dialog.CommonDialog
import com.miya.fastcashier.ui.dialog.MessageDialog import com.miya.fastcashier.ui.dialog.MessageDialog
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.DateSelectHelper import com.miya.fastcashier.utils.DateSelectHelper
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.utils.manage.AccountPasswordManageKit import com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
...@@ -84,9 +85,14 @@ class MainActivity : BaseActivity() { ...@@ -84,9 +85,14 @@ class MainActivity : BaseActivity() {
binding.llBalance.clickWithTrigger { binding.llBalance.clickWithTrigger {
//上次记录的时间,或者当天0点 //上次记录的时间,或者当天0点
val timeMillis = LocalKeyDataMKManageKit.getBalanceDate() var timeMillis = LocalKeyDataMKManageKit.getBalanceDate()
if (timeMillis > 0L && timeMillis <= System.currentTimeMillis()) { if (timeMillis > 0L && timeMillis <= System.currentTimeMillis()) {
viewModel.orderStatistics(Date(timeMillis), Date(), true) val currentDate = Date()
var daysAgoCurrent: Long = DateUtils.getDaysAgoCurrent(currentDate, 3)
if (timeMillis <= daysAgoCurrent) {
timeMillis = daysAgoCurrent
}
viewModel.orderStatistics(Date(timeMillis), currentDate, true)
} else { } else {
val startDate = Calendar.getInstance() val startDate = Calendar.getInstance()
startDate.set( startDate.set(
...@@ -101,6 +107,10 @@ class MainActivity : BaseActivity() { ...@@ -101,6 +107,10 @@ class MainActivity : BaseActivity() {
} }
} }
binding.tvStoreName.clickWithTrigger{
LocalKeyDataMKManageKit.putBalanceDate(2)
}
initData() initData()
checkAccountPassword() checkAccountPassword()
OrderRecordManageKit.clearOrderDataYeaterday() OrderRecordManageKit.clearOrderDataYeaterday()
......
...@@ -166,6 +166,13 @@ public class DateUtils { ...@@ -166,6 +166,13 @@ public class DateUtils {
return calendar.getTime().getTime(); return calendar.getTime().getTime();
} }
/**
* 获取某天的n天以前的当前时间
*/
public static long getDaysAgoCurrent(Date date, int daysAgoNum) {
return date.getTime() - daysAgoNum * 24 * 3600 * 1000;
}
/** /**
* 得到前一天 * 得到前一天
*/ */
......
...@@ -41,7 +41,7 @@ class LocalKeyDataMKManageKit { ...@@ -41,7 +41,7 @@ class LocalKeyDataMKManageKit {
* 结算时间合规化处理,适用于登录时 * 结算时间合规化处理,适用于登录时
* 策略: * 策略:
* ①当获取的结算时间=0(证明本地未存储过,第一次登陆)存储为当前时间 * ①当获取的结算时间=0(证明本地未存储过,第一次登陆)存储为当前时间
* ②当获取的结算时间小于三天前的当前时间,则将结算时间重置为两天前的零点 * ②当获取的结算时间小于三天前的当前时间,则将结算时间重置为3天前的时间
*/ */
fun handleCompliantBalanceDate() { fun handleCompliantBalanceDate() {
LogUtils.e(BALANCEDATE_ID, "handleCompliantBalanceDate") LogUtils.e(BALANCEDATE_ID, "handleCompliantBalanceDate")
...@@ -54,9 +54,8 @@ class LocalKeyDataMKManageKit { ...@@ -54,9 +54,8 @@ class LocalKeyDataMKManageKit {
var minimumTime: Long = System.currentTimeMillis() - 3 * 24 * 3600 * 1000 var minimumTime: Long = System.currentTimeMillis() - 3 * 24 * 3600 * 1000
if (balanceTime <= minimumTime){ if (balanceTime <= minimumTime){
val daysAgoMillions = DateUtils.getDaysAgo(Date(), 2) putBalanceDate(minimumTime)
putBalanceDate(daysAgoMillions) LogUtils.e(BALANCEDATE_ID, "minimumTime:${DateUtils.format18(Date(minimumTime))}")
LogUtils.e(BALANCEDATE_ID, "daysAgoMillions:${DateUtils.format18(Date(daysAgoMillions))}")
} }
} }
......
...@@ -34,8 +34,6 @@ class LoginViewModel : ViewModel() { ...@@ -34,8 +34,6 @@ class LoginViewModel : ViewModel() {
// LocalKeyDataMKManageKit.putBalanceDate(System.currentTimeMillis()) // LocalKeyDataMKManageKit.putBalanceDate(System.currentTimeMillis())
// } // }
loginLiveData.postValue(result) loginLiveData.postValue(result)
//根据本地存储时间,MMKV初始化合理的结算时间
LocalKeyDataMKManageKit.handleCompliantBalanceDate()
} catch (e: Exception) { } catch (e: Exception) {
loginLiveData.postValue(Result.failure(e)) loginLiveData.postValue(Result.failure(e))
} }
......
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