Browse Source

处理通联非分账传递参数错误问题

Zheng 3 years ago
parent
commit
81f2517bdc

+ 1 - 1
app/build.gradle

@@ -22,7 +22,7 @@ android {
         minSdkVersion 22
         targetSdkVersion 26
         versionCode 7
-        versionName "1.1.20"
+        versionName "1.1.21"
         archivesBaseName = versionName + "." + getTime()
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

+ 4 - 2
app/src/main/java/com/doverfuelingsolutions/issp/api/SystemApi.kt

@@ -1,6 +1,7 @@
 package com.doverfuelingsolutions.issp.api
 
 import android.util.Base64
+import android.util.Log
 import com.doverfuelingsolutions.issp.BuildConfig
 import com.doverfuelingsolutions.issp.DFSApplication
 import com.doverfuelingsolutions.issp.R
@@ -86,8 +87,9 @@ object SystemApi {
                 // 由于实际使用只有两种方案:通联 OR 微信+支付宝,不存在单独使用的情况
                 // 对于微信+支付宝,pay 方法会根据付款码来判断区分究竟是微信还是支付宝,因此本地化一个支付类型
                 body!!.Data.let { channels ->
-                    val combine = channels.find { type -> type.PaymentId == 13 }
-                    val param = combine ?: ResultPaymentParam(0, "移动支付")
+//                    val combine = channels.find { type -> type.PaymentId == 13 }
+//                    val param = combine ?: ResultPaymentParam(0, "移动支付")
+                    val param = if (channels.isNotEmpty()) channels[0] else ResultPaymentParam(0,"移动支付")
                     GlobalData.paymentId.set(param.PaymentId)
                     GlobalData.paymentName.set(param.DispalyName)
                     it.resume(DFSResult.success(param))

+ 75 - 9
app/src/main/java/com/doverfuelingsolutions/issp/fusion/FusionManager.kt

@@ -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) {

+ 8 - 2
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentNozzle.kt

@@ -57,6 +57,7 @@ class FragmentNozzle private constructor() : FragmentBasic(){
             binding.smartRefreshLayout.setOnRefreshListener { handleNozzleRefresh() }
         }
         //刷新页面,因为可能支付完成功后某一把枪没订单了,该枪颜色应变浅色
+        loadListData()
         chooseListAdapter.notifyDataSetChanged()
         return binding.root
     }
@@ -101,15 +102,20 @@ class FragmentNozzle private constructor() : FragmentBasic(){
     }
 
     private suspend fun loadRemoteData() {
+        val colors = arrayListOf<Int>()
         FusionManager.nozzles.forEach {
             val result = FusionManager.getAllUnsettledOrder(it.pumpId)
             if (result.success && result.data != null && result.data.isNotEmpty()) {
-                GlobalData.colorForSignOrder.add(ResourcesCompat.getColor(DFSApplication.instance.applicationContext.resources, R.color.colorPrimary, null))
+                colors.add(ResourcesCompat.getColor(DFSApplication.instance.applicationContext.resources, R.color.colorPrimary, null))
             } else {
-                GlobalData.colorForSignOrder.add(ResourcesCompat.getColor(DFSApplication.instance.applicationContext.resources, R.color.colorPrimaryTransparent, null))
+                colors.add(ResourcesCompat.getColor(DFSApplication.instance.applicationContext.resources, R.color.colorPrimaryTransparent, null))
             }
         }
 
+
+        GlobalData.colorForSignOrder.clear()
+        GlobalData.colorForSignOrder.addAll(colors)
+
         chooseListAdapter.notifyDataSetChanged()
     }