|
@@ -15,6 +15,8 @@ import com.doverfuelingsolutions.issp.utils.log.DFSLog
|
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPKeys
|
|
|
import com.doverfuelingsolutions.issp.utils.sp.SPUtil
|
|
|
import com.doverfuelingsolutions.issp.utils.thread.ThreadUtil
|
|
|
+import com.doverfuelingsolutions.issp.view.fragment.callback.RefreshNozzle
|
|
|
+import com.doverfuelingsolutions.issp.view.fragment.callback.RefreshOrder
|
|
|
import com.wayne.www.waynelib.fdc.FdcClient
|
|
|
import com.wayne.www.waynelib.fdc.OnFdcClientStateChangedListener
|
|
|
import com.wayne.www.waynelib.fdc.OnFdcMessageReceivedListener
|
|
@@ -24,7 +26,6 @@ import com.wayne.www.waynelib.util.HsLogTagFlag
|
|
|
import com.wayne.www.waynelib.util.HsLogUtils
|
|
|
import kotlinx.coroutines.*
|
|
|
import java.util.*
|
|
|
-import kotlin.collections.ArrayList
|
|
|
import kotlin.coroutines.resume
|
|
|
import kotlin.coroutines.suspendCoroutine
|
|
|
import kotlin.math.min
|
|
@@ -49,6 +50,8 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
private var jobRestart: Job? = null
|
|
|
|
|
|
var onFusionStatus: OnFusionStatus? = null
|
|
|
+ var onRefreshNozzleUi: RefreshNozzle? = null
|
|
|
+ var onRefreshOrderUi: RefreshOrder? = null
|
|
|
|
|
|
override fun onFdcClientStateChanged(sender: FdcClient?, state: FdcClient.FdcClientState?) {
|
|
|
DFSLog.d("Fusion state changed: ${state?.name?.toLowerCase(Locale.CHINESE)}")
|
|
@@ -141,48 +144,35 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
if (null != dc.state) {
|
|
|
when (dc.state) {
|
|
|
"Payable" -> { // 新的订单,可以支付
|
|
|
-// if (f.isHaveNoPayOrderDetailAndChange(
|
|
|
-// dc.pumpNo,
|
|
|
-// dc.transactionSeqNo,
|
|
|
-// dc.state
|
|
|
-// )
|
|
|
-// ) return //代表已经有该订单了
|
|
|
-// f.addNewAvailableFuelSaleTrxs(dc)
|
|
|
-
|
|
|
- updateLocalOrder(dc)
|
|
|
//将订单页面增加此可支付订单
|
|
|
+ onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo,true)
|
|
|
+ onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
|
|
|
|
|
|
}
|
|
|
"Cleared" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { //需要消除的单(一般是已经支付过了,或本机支付的,或其他设备支付的)
|
|
|
-// HsSpUtils.removeUnLockSuccessOrder(dc)
|
|
|
-// HsSpUtils.removePayOrderDatas(dc)
|
|
|
-// HsSpUtils.removeLocalPumpNoPayOrder(dc.pumpNo, dc.transactionSeqNo)
|
|
|
-// HsSpUtils.removeLocalProductNoPayOrder(dc.productNo1, dc.transactionSeqNo)
|
|
|
-// BaseEventBusUtils.post(DcDetailEvent(true, dc)) //主要通知如果处于订单界面移除
|
|
|
-// BaseEventBusUtils.post(DcToOilEvent(true, dc)) //油品选择
|
|
|
-
|
|
|
+// val sourceOrder = SPUtil.getOrderListByPump(dc.pumpNo)
|
|
|
+// if (sourceOrder.isNotEmpty()){
|
|
|
+// sourceOrder.remove(sourceOrder.find { it.pumpNo == dc.pumpNo && it.transactionSeqNo == dc. transactionSeqNo})
|
|
|
+// SPUtil.setOrderListByPump(dc.pumpNo,sourceOrder)
|
|
|
+//
|
|
|
+// if (sourceOrder.isEmpty()) {
|
|
|
+// onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo,false) //枪页面显示浅色
|
|
|
+// }
|
|
|
+// }
|
|
|
SPUtil.removeLockOrder(dc)
|
|
|
SPUtil.removeUnclearedOrder(dc)
|
|
|
SPUtil.removeWayneOrder(dc)
|
|
|
+
|
|
|
+
|
|
|
//将订单页面减去此需消除订单
|
|
|
+ onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo,false) //枪页面显示浅色
|
|
|
+ onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
|
|
|
+
|
|
|
}
|
|
|
"Locked" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { // 锁单(被某一设备正在支付),或本机锁,或其他设备锁
|
|
|
-// DeviceClass lastLockOrder = HsSpUtils.getLastLockOrder();
|
|
|
-// if (null != lastLockOrder) {
|
|
|
-// if (lastLockOrder.isThis(dc)) {
|
|
|
-// //当前订单在此台设备做支付时无需处理锁定操作
|
|
|
-// HsSpUtils.saveLastLockOrder(null);//移掉(如果他只发一次过来的话肯定没问题)
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// f.isHaveNoPayOrderDetailAndChange(dc.pumpNo, dc.transactionSeqNo, dc.state)
|
|
|
|
|
|
- if (!SPUtil.isLockByThis(dc)) { // 若是其他设备的锁单,更新这边订单的锁单情况
|
|
|
- val pumpSourceOrder = SPUtil.getOrderListByPump(dc.pumpNo)
|
|
|
- pumpSourceOrder.forEach{
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -198,6 +188,8 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
if (it.transactionSeqNo.equals(dc.transactionSeqNo)) { //存在更新数据
|
|
|
isExist = true
|
|
|
it.state = dc.state
|
|
|
+ it.releaseTokenAttribute = dc.releaseTokenAttribute
|
|
|
+ it.releaseTokenElement = dc.releaseTokenElement
|
|
|
}
|
|
|
}
|
|
|
if (!isExist) pumpSourceOrder.add(dc) //不存在添加
|
|
@@ -293,16 +285,26 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
val unsettledList =
|
|
|
response.singleFdcData.deviceClasses.filter { !it.isClear }
|
|
|
|
|
|
- val resultDetailList = unsettledList
|
|
|
- .map { dc -> async { getOrderDetail(dc) } }
|
|
|
- .map { deferred -> deferred.await() }
|
|
|
- .filter { it.success }
|
|
|
- .mapNotNull {
|
|
|
- it.data?.productName =
|
|
|
- nozzles.find { n -> n.pumpId == it.data?.pumpNo && it.data.nozzleNo == n.physicalId }?.barcodeName
|
|
|
- ?: ""
|
|
|
- it.data
|
|
|
+// val resultDetailList = unsettledList
|
|
|
+// .map { dc -> async { getOrderDetail(dc) } }
|
|
|
+// .map { deferred -> deferred.await() }
|
|
|
+// .filter { it.success }
|
|
|
+// .mapNotNull {
|
|
|
+// it.data?.productName =
|
|
|
+// nozzles.find { n -> n.pumpId == it.data?.pumpNo && it.data.nozzleNo == n.physicalId }?.barcodeName
|
|
|
+// ?: ""
|
|
|
+// it.data
|
|
|
+// }
|
|
|
+ val resultDetailList = arrayListOf<DeviceClass>()
|
|
|
+ unsettledList.forEach {
|
|
|
+ val detail = getOrderDetail(it)
|
|
|
+ if(detail.success) {
|
|
|
+ detail.data?.productName =
|
|
|
+ nozzles.find { n -> n.pumpId == detail.data?.pumpNo && detail.data.nozzleNo == n.physicalId }?.barcodeName
|
|
|
+ ?:""
|
|
|
+ detail.data?.let { it1 -> resultDetailList.add(it1) }
|
|
|
}
|
|
|
+ }
|
|
|
val time3 = System.currentTimeMillis()
|
|
|
DFSLog.v("fetch uncleared orders detail cost ${time3 - time2}ms")
|
|
|
it.resume(DFSResult.success(resultDetailList))
|