Zheng 3 lat temu
rodzic
commit
c213de378e

+ 49 - 19
app/src/main/java/com/doverfuelingsolutions/issp/fusion/FusionManager.kt

@@ -24,6 +24,7 @@ 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
@@ -125,7 +126,6 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
     override fun onServiceResponseReceived(sender: FdcClient?, serviceResponse: ServiceResponse?) {}
 
     override fun onFdcMessageReceived(sender: FdcClient?, fdcMessage: FdcMessage?) {
-        /**
         if (fdcMessage == null || fdcMessage is FdcMessageHeartbeat
             || fdcMessage is FdcMessageFuelPointCurrentFuellingStatus
             || fdcMessage is FdcMessageFPStateChange
@@ -136,27 +136,35 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
             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)
+//                        if (f.isHaveNoPayOrderDetailAndChange(
+//                                dc.pumpNo,
+//                                dc.transactionSeqNo,
+//                                dc.state
+//                            )
+//                        ) return  //代表已经有该订单了
+//                        f.addNewAvailableFuelSaleTrxs(dc)
+
+                        updateLocalOrder(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)) //油品选择
+//                        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)) //油品选择
+
+                        SPUtil.removeLockOrder(dc)
+                        SPUtil.removeUnclearedOrder(dc)
+                        SPUtil.removeWayneOrder(dc)
+                        //将订单页面减去此需消除订单
                     }
                     "Locked" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { // 锁单(被某一设备正在支付),或本机锁,或其他设备锁
 //                            DeviceClass lastLockOrder = HsSpUtils.getLastLockOrder();
@@ -167,12 +175,34 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
 //                                    return;
 //                                }
 //                            }
-                        f.isHaveNoPayOrderDetailAndChange(dc.pumpNo, dc.transactionSeqNo, dc.state)
+//                        f.isHaveNoPayOrderDetailAndChange(dc.pumpNo, dc.transactionSeqNo, dc.state)
+
+                        if (!SPUtil.isLockByThis(dc)) {  // 若是其他设备的锁单,更新这边订单的锁单情况
+                            val pumpSourceOrder = SPUtil.getOrderListByPump(dc.pumpNo)
+                            pumpSourceOrder.forEach{
+                                
+                            }
+                        }
                     }
                 }
             }
         }
-        */
+    }
+
+    // 更新本地订单存储
+    private fun updateLocalOrder(dc: DeviceClass){
+        val pumpSourceOrder = SPUtil.getOrderListByPump(dc.pumpNo)
+
+        var isExist = false
+        pumpSourceOrder.forEach {
+            if (it.transactionSeqNo.equals(dc.transactionSeqNo)) { //存在更新数据
+                isExist = true
+                it.state = dc.state
+            }
+        }
+        if (!isExist) pumpSourceOrder.add(dc) //不存在添加
+
+        SPUtil.setOrderListByPump(dc.pumpNo,pumpSourceOrder)
     }
 
     @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)