1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.miya.fastcashier.viewmodel
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.fastcashier.lib_common.function.pay.MiYaPayPlantformPayWayEnum
import com.fastcashier.lib_common.util.DateUtils
import com.fastcashier.lib_common.util.isEmpty
import com.miya.fastcashier.dao.DatabaseKeeper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import com.miya.fastcashier.dao.ViewPayOrderData as ViewPayOrderData1
class SearchOrderViewModel : ViewModel() {
val payDataLiveData: MutableLiveData<Result<List<ViewPayOrderData1>>> = MutableLiveData()
/**
* 获取所有订单,分页处理
*/
fun getPayData(payType: MiYaPayPlantformPayWayEnum.MiyaPayType, currentSize: Int) {
viewModelScope.launch(Dispatchers.IO) {
try {
val list =
DatabaseKeeper.payDatabase.payDataDao()
.queryWithType(payType = payType.code, currentSize)
payDataLiveData.postValue(Result.success(list))
} catch (e: Exception) {
e.printStackTrace()
payDataLiveData.postValue(Result.failure(e))
}
}
}
/**
* 根据时间、用户获取订单,不分页
*/
fun getPayDataByTimeAndUser(
payType: MiYaPayPlantformPayWayEnum.MiyaPayType,
userName: String,
limitTime: Long
) {
viewModelScope.launch(Dispatchers.IO) {
try {
val list = DatabaseKeeper.payDatabase.payDataDao()
.queryAllWithTypeAndName(payType = payType.code, userName)
if (limitTime == 0L) {
payDataLiveData.postValue(Result.success(list))
return@launch
}
val destList: MutableList<ViewPayOrderData1> = arrayListOf()
if (!isEmpty(list)) {
for (order in list) {
val tradeDate: String = order.chanelOrderTradeTime
if (!TextUtils.isEmpty(tradeDate) &&
DateUtils.stringToLong(
tradeDate,
DateUtils.DF_YYYY_MM_DDHHMMSS
) > limitTime
) {
destList.add(order)
}
}
}
payDataLiveData.postValue(Result.success(destList))
} catch (e: Exception) {
e.printStackTrace()
payDataLiveData.postValue(Result.failure(e))
}
}
}
}