|
@@ -7,7 +7,6 @@ import com.doverfuelingsolutions.issp.R
|
|
|
import com.doverfuelingsolutions.issp.api.FuelInfoApi
|
|
|
import com.doverfuelingsolutions.issp.api.dto.DFSResult
|
|
|
import com.doverfuelingsolutions.issp.api.entity.NozzleInfo
|
|
|
-import com.doverfuelingsolutions.issp.api.entity.PumpInfo
|
|
|
import com.doverfuelingsolutions.issp.data.GlobalData
|
|
|
import com.doverfuelingsolutions.issp.fusion.callback.OnFusionStatus
|
|
|
import com.doverfuelingsolutions.issp.utils.StringUtil
|
|
@@ -21,9 +20,10 @@ import com.wayne.www.waynelib.fdc.OnFdcClientStateChangedListener
|
|
|
import com.wayne.www.waynelib.fdc.OnFdcMessageReceivedListener
|
|
|
import com.wayne.www.waynelib.fdc.OnFdcServiceResponseReceivedListener
|
|
|
import com.wayne.www.waynelib.fdc.message.*
|
|
|
+import com.wayne.www.waynelib.util.HsLogTagFlag
|
|
|
+import com.wayne.www.waynelib.util.HsLogUtils
|
|
|
import kotlinx.coroutines.*
|
|
|
import java.util.*
|
|
|
-import java.util.concurrent.CopyOnWriteArrayList
|
|
|
import kotlin.coroutines.resume
|
|
|
import kotlin.coroutines.suspendCoroutine
|
|
|
import kotlin.math.min
|
|
@@ -124,7 +124,56 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
|
|
|
override fun onServiceResponseReceived(sender: FdcClient?, serviceResponse: ServiceResponse?) {}
|
|
|
|
|
|
- override fun onFdcMessageReceived(sender: FdcClient?, fdcMessage: FdcMessage?) {}
|
|
|
+ override fun onFdcMessageReceived(sender: FdcClient?, fdcMessage: FdcMessage?) {
|
|
|
+ /**
|
|
|
+ if (fdcMessage == null || fdcMessage is FdcMessageHeartbeat
|
|
|
+ || fdcMessage is FdcMessageFuelPointCurrentFuellingStatus
|
|
|
+ || fdcMessage is FdcMessageFPStateChange
|
|
|
+ ) return
|
|
|
+ HsLogUtils.o(HsLogTagFlag.FDC_TAG, fdcMessage.toString())
|
|
|
+ HsLogUtils.o(HsLogTagFlag.FDC_TAG, fdcMessage)
|
|
|
+ if (fdcMessage.messageType == "FuelSaleTrx" && fdcMessage is FdcMessageFuelSaleTrx) {
|
|
|
+ val ffst = fdcMessage as FdcMessageFuelSaleTrx
|
|
|
+ if (ffst.singleDeviceClass == null) return
|
|
|
+ val dc = ffst.singleDeviceClass
|
|
|
+ // 到这获取到更新的订单,或全新,或旧订单更新,或旧订单删除
|
|
|
+// if (findFragment(MainFragment::class.java) == null) return
|
|
|
+// val f: MainFragment = findFragment(MainFragment::class.java)
|
|
|
+ if (null != dc.state) {
|
|
|
+ when (dc.state) {
|
|
|
+ "Payable" -> { // 新的订单,可以支付
|
|
|
+ if (f.isHaveNoPayOrderDetailAndChange(
|
|
|
+ dc.pumpNo,
|
|
|
+ dc.transactionSeqNo,
|
|
|
+ dc.state
|
|
|
+ )
|
|
|
+ ) return //代表已经有该订单了
|
|
|
+ f.addNewAvailableFuelSaleTrxs(dc)
|
|
|
+ }
|
|
|
+ "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)) //油品选择
|
|
|
+ }
|
|
|
+ "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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+ }
|
|
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
|
fun initialize() {
|
|
@@ -201,14 +250,18 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
val time1 = System.currentTimeMillis()
|
|
|
FdcClient.getDefault().sendGetAvailableFuelSaleTrxs(pumpId, { _, response ->
|
|
|
val time2 = System.currentTimeMillis()
|
|
|
- DFSLog.v("fetch uncleared orders of pump $pumpId (cost ${time2 - time1}ms)", response)
|
|
|
+ DFSLog.v(
|
|
|
+ "fetch uncleared orders of pump $pumpId (cost ${time2 - time1}ms)",
|
|
|
+ response
|
|
|
+ )
|
|
|
coroutineIO.launch {
|
|
|
if (response == null || response !is ServiceResponseGetAvailableFuelSaleTrxs) {
|
|
|
it.resume(DFSResult.fail(R.string.fail_get_order))
|
|
|
} else if (response.singleFdcData == null || response.singleDeviceClass == null) {
|
|
|
it.resume(DFSResult.success(emptyList()))
|
|
|
} else {
|
|
|
- val unsettledList = response.singleFdcData.deviceClasses.filter { !it.isClear }
|
|
|
+ val unsettledList =
|
|
|
+ response.singleFdcData.deviceClasses.filter { !it.isClear }
|
|
|
|
|
|
val resultDetailList = unsettledList
|
|
|
.map { dc -> async { getOrderDetail(dc) } }
|
|
@@ -241,14 +294,20 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
/**
|
|
|
* Fetch order detail.
|
|
|
*/
|
|
|
- private fun getOrderDetailAsync(dcRaw: DeviceClass, callback: (result: DFSResult<DeviceClass>) -> Unit) {
|
|
|
+ private fun getOrderDetailAsync(
|
|
|
+ dcRaw: DeviceClass,
|
|
|
+ callback: (result: DFSResult<DeviceClass>) -> Unit
|
|
|
+ ) {
|
|
|
ThreadUtil.io {
|
|
|
FdcClient.getDefault().sendGetFuelSalesTrxDetailsRequestAsync(
|
|
|
dcRaw.pumpNo,
|
|
|
dcRaw.transactionSeqNo,
|
|
|
dcRaw.releaseTokenAttribute,
|
|
|
{ _, response ->
|
|
|
- DFSLog.v("fetch order detail of ${dcRaw.pumpNo}-${dcRaw.transactionSeqNo}", response)
|
|
|
+ DFSLog.v(
|
|
|
+ "fetch order detail of ${dcRaw.pumpNo}-${dcRaw.transactionSeqNo}",
|
|
|
+ response
|
|
|
+ )
|
|
|
if (response == null || response !is ServiceResponseGetFuelSalesTrxDetails || response.fdcData.isEmpty() || response.fdcData[0].deviceClasses.isEmpty()) {
|
|
|
callback(DFSResult.fail(R.string.fail_get_order_detail))
|
|
|
} else {
|
|
@@ -319,10 +378,17 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
|
|
|
ThreadUtil.io {
|
|
|
val callback = OnFdcServiceResponseReceivedListener { _, response ->
|
|
|
DFSLog.v("Fusion.lockOrder($pumpId, $transactionNo, $token, $lock)", response)
|
|
|
- if (response != null && response.singleDeviceClass != null && response.overallResult.equals("Success", true)) {
|
|
|
+ if (response != null && response.singleDeviceClass != null && response.overallResult.equals(
|
|
|
+ "Success",
|
|
|
+ true
|
|
|
+ )) {
|
|
|
it.resume(DFSResult.success(true))
|
|
|
} else {
|
|
|
- it.resume(DFSResult.fail(response?.overallResult ?: StringUtil.get(R.string.fail_operate)))
|
|
|
+ it.resume(
|
|
|
+ DFSResult.fail(
|
|
|
+ response?.overallResult ?: StringUtil.get(R.string.fail_operate)
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
if (lock) {
|