数据线程安全locker
This commit is contained in:
parent
ab540875e6
commit
3fa2c5638f
|
|
@ -10,7 +10,6 @@ import com.gamedog.vididin.VidiConst
|
||||||
import com.gamedog.vididin.VidiConst.ZEROBUY_SECRET
|
import com.gamedog.vididin.VidiConst.ZEROBUY_SECRET
|
||||||
import com.gamedog.vididin.VididinEvents
|
import com.gamedog.vididin.VididinEvents
|
||||||
import com.gamedog.vididin.beans.ZeroBuyItem
|
import com.gamedog.vididin.beans.ZeroBuyItem
|
||||||
import com.gamedog.vididin.beans.ZeroBuyResp
|
|
||||||
import com.gamedog.vididin.beans.ZeroBuyWithdrawResp
|
import com.gamedog.vididin.beans.ZeroBuyWithdrawResp
|
||||||
import com.gamedog.vididin.core.login.login.AccountManager
|
import com.gamedog.vididin.core.login.login.AccountManager
|
||||||
import com.gamedog.vididin.features.withdraw.dialogs.WithdrawBindBankDialog
|
import com.gamedog.vididin.features.withdraw.dialogs.WithdrawBindBankDialog
|
||||||
|
|
@ -27,7 +26,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
import kotlin.Int
|
import kotlin.Int
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -50,6 +49,8 @@ class ZeroManager private constructor() {
|
||||||
SpUtil.instance().getList<WinZeroWithdrawInfoItem>(SpUtil.KEY_ZEROBUY_WIN_ITEMS).toMutableList()
|
SpUtil.instance().getList<WinZeroWithdrawInfoItem>(SpUtil.KEY_ZEROBUY_WIN_ITEMS).toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val mRecordLocker = ReentrantLock()
|
||||||
|
|
||||||
private fun saveWinWithdrawInfos() {
|
private fun saveWinWithdrawInfos() {
|
||||||
SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_WIN_ITEMS, mWinZeroList)
|
SpUtil.instance().putList(SpUtil.KEY_ZEROBUY_WIN_ITEMS, mWinZeroList)
|
||||||
notifyChangeUpdate()
|
notifyChangeUpdate()
|
||||||
|
|
@ -69,6 +70,8 @@ class ZeroManager private constructor() {
|
||||||
if (it.contains(userId) && zeroItem.completed) {
|
if (it.contains(userId) && zeroItem.completed) {
|
||||||
var alreadyExist = false
|
var alreadyExist = false
|
||||||
|
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
mWinZeroList.forEach {
|
mWinZeroList.forEach {
|
||||||
if (it.purchase_id == zeroItem.id) {
|
if (it.purchase_id == zeroItem.id) {
|
||||||
alreadyExist = true
|
alreadyExist = true
|
||||||
|
|
@ -80,18 +83,28 @@ class ZeroManager private constructor() {
|
||||||
mWinZeroList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price))
|
mWinZeroList.add(WinZeroWithdrawInfoItem(zeroItem.id, zeroItem.title, zeroItem.price))
|
||||||
saveWinWithdrawInfos()
|
saveWinWithdrawInfos()
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getZeroWithdrawItem(zeroItem: ZeroBuyItem): WinZeroWithdrawInfoItem {
|
fun getZeroWithdrawItem(zeroItem: ZeroBuyItem): WinZeroWithdrawInfoItem {
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
return mWinZeroList.filter { zeroItem.id == it.purchase_id }[0]
|
return mWinZeroList.filter { zeroItem.id == it.purchase_id }[0]
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun couldStartWithdraw(zeroItem: ZeroBuyItem): Boolean {
|
fun couldStartWithdraw(zeroItem: ZeroBuyItem): Boolean {
|
||||||
val userId = AccountManager.getAccount().userId
|
val userId = AccountManager.getAccount().userId
|
||||||
zeroItem.winners?.let {
|
zeroItem.winners?.let {
|
||||||
if (it.contains(userId) && zeroItem.completed) {
|
if (it.contains(userId) && zeroItem.completed) {
|
||||||
|
try {
|
||||||
|
mRecordLocker.lock()
|
||||||
mWinZeroList.forEach {
|
mWinZeroList.forEach {
|
||||||
if (it.purchase_id == zeroItem.id) {
|
if (it.purchase_id == zeroItem.id) {
|
||||||
return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL
|
return it.withdrawState == TRANSACTION_STATE_UNSTART || it.withdrawState == TRANSACTION_STATE_FAIL
|
||||||
|
|
@ -99,33 +112,15 @@ class ZeroManager private constructor() {
|
||||||
}
|
}
|
||||||
addWinWithdrawItem(zeroItem)
|
addWinWithdrawItem(zeroItem)
|
||||||
return true
|
return true
|
||||||
|
} finally {
|
||||||
|
mRecordLocker.unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startWithdrawForWinPurchase(zeroItem: ZeroBuyItem) {
|
|
||||||
if (couldStartWithdraw(zeroItem)) {
|
|
||||||
/*when (it.withdrawState) {
|
|
||||||
TRANSACTION_STATE_UNSTART -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TRANSACTION_STATE_ONGOING -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TRANSACTION_STATE_SUCCESS -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TRANSACTION_STATE_FAIL -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun requestWithdrawZeroReward(zeroWithdrawItem: WinZeroWithdrawInfoItem) {
|
private fun requestWithdrawZeroReward(zeroWithdrawItem: WinZeroWithdrawInfoItem) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue