RobinTan1024 4 rokov pred
rodič
commit
3d3701f56e

+ 1 - 1
app/src/main/java/com/doverfuelingsolutions/issp/api/FuelInfoApi.kt

@@ -90,7 +90,7 @@ object FuelInfoApi {
             }
 
             override fun onFailure(call: Call<List<ResultAccumulationInfo>>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("FuelInfoApi.accumulationInfo.onFailure", t)
                 it.resume(DFSResult.fail(R.string.fail_get_accumulation))
             }
         })

+ 15 - 13
app/src/main/java/com/doverfuelingsolutions/issp/api/SystemApi.kt

@@ -62,7 +62,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<ResultBarcode>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.barcodeName.onFailure", t)
                 it.resume(DFSResult.fail(t.message.toString()))
             }
         })
@@ -84,7 +84,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<ResultObj<List<ResultPaymentParam>>>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.paymentParam.onFailure", t)
                 it.resume(DFSResult.fail(R.string.fail_get_pay_param))
             }
         })
@@ -106,20 +106,22 @@ object SystemApi {
         clientRingUpPosItem.setFuelItemFdcReleaseTokenAttribute(dc.releaseTokenAttribute.toInt())
         clientRingUpPosItem.setFuelItemOriginalGrossAmount(if (BuildConfig.DEBUG) BigDecimal("0.01") else dc.amount)
         clientPosTrx.addClientRingUpPosItem(clientRingUpPosItem)
+        DFSLog.d(clientPosTrx)
 
-        serviceTrx.reportPaymentOrder(clientPosTrx).enqueue(object : Callback<PosTrx> {
+        serviceTrx.generateOrder(clientPosTrx).enqueue(object : Callback<PosTrx> {
             override fun onResponse(call: Call<PosTrx>, response: Response<PosTrx>) {
                 val code = response.code()
                 val body = response.body()
                 if (code == 200 && body is PosTrx) {
                     it.resume(DFSResult.success(body))
                 } else {
-                    it.resume(DFSResult.fail(R.string.response_null))
+                    DFSLog.i(response.message(), response.body())
+                    it.resume(DFSResult.fail(R.string.fail_request))
                 }
             }
 
             override fun onFailure(call: Call<PosTrx>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.generateOrder.onFailure", t)
                 it.resume(DFSResult.fail(t.message.toString()))
             }
         })
@@ -168,7 +170,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<ResultPayment>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.pay.onFailure", t)
                 it.resume(DFSResult.fail(""))
             }
         })
@@ -178,7 +180,7 @@ object SystemApi {
      * 查询油站联系电话
      */
     suspend fun sessionInfo() = suspendCoroutine<DFSResult<ResultDeviceSessionInfo>> {
-        serviceBase.deviceSessionInfo(GlobalData.serialNumber.get()).enqueue(object : Callback<ResultDeviceSessionInfo> {
+        serviceBase.sessionInfo(GlobalData.serialNumber.get()).enqueue(object : Callback<ResultDeviceSessionInfo> {
             override fun onResponse(call: Call<ResultDeviceSessionInfo>, response: Response<ResultDeviceSessionInfo>) {
                 val code = response.code()
                 val body = response.body()
@@ -190,7 +192,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<ResultDeviceSessionInfo>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.sessionInfo.onFailure", t)
                 it.resume(DFSResult.fail(R.string.return_data_error))
             }
         })
@@ -251,7 +253,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<ResultLogin>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.loginOnly.onFailure", t)
                 it.resume(DFSResult.fail(t.message.toString()))
             }
         })
@@ -272,7 +274,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<Any>, t: Throwable) {
-                DFSLog.e(t)
+                DFSLog.e("SystemApi.notifyTrx.onFailure", t)
                 it.resume(DFSResult.fail(t.message.toString()))
             }
         })
@@ -297,7 +299,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<Array<ResultConfig>>, t: Throwable) {
-                DFSLog.e("WayneApi.serviceConfig.config.onFailure", t)
+                DFSLog.e("SystemApi.config.onFailure", t)
                 it.resume(DFSResult.fail(R.string.req_fail))
             }
         })
@@ -322,7 +324,7 @@ object SystemApi {
                             file.writeBytes(Base64.decode(body[0].value, Base64.DEFAULT))
                             it.resume(DFSResult.success(body[0].name))
                         } catch (e: Exception) {
-                            DFSLog.e("WayneApi.file.save", e)
+                            DFSLog.e("SystemApi.file.save", e)
                             it.resume(DFSResult.fail(R.string.fail_save_file))
                         }
                     }
@@ -330,7 +332,7 @@ object SystemApi {
             }
 
             override fun onFailure(call: Call<Array<ResultFile>>, t: Throwable) {
-                DFSLog.e("WayneApi.serviceConfig.file", t)
+                DFSLog.e("SystemApi.serviceConfig.file", t)
                 it.resume(DFSResult.fail(R.string.req_fail))
             }
         })

+ 17 - 11
app/src/main/java/com/doverfuelingsolutions/issp/api/basic/LoggingInterceptor.kt

@@ -1,28 +1,34 @@
 package com.doverfuelingsolutions.issp.api.basic
 
 import com.doverfuelingsolutions.issp.utils.log.DFSLog
-import com.google.gson.Gson
 import okhttp3.Interceptor
 import okhttp3.Response
-import java.util.*
 
 class LoggingInterceptor : Interceptor {
 
-    private var index = 1
-
     override fun intercept(chain: Interceptor.Chain): Response {
-        if (index >= 1000) index = 1
-        val currentIndex = index
-        index++
-
         val request = chain.request()
         val time = System.currentTimeMillis()
-        DFSLog.v("=====>>>>> request[$currentIndex]: ${request.method()} ${request.url()}")
 
-        val response = chain.proceed(request)
+        val requestName = request.header("requestName")
+        val requestBuilder = request.newBuilder()
+        requestBuilder.removeHeader("requestName")
+        val newRequest = requestBuilder.build()
+
+        DFSLog.v("=====>>>>> request[$requestName]: ${newRequest.method()} ${newRequest.url()}")
+        val response = chain.proceed(newRequest)
         val body = response.body()
         val stringBody = if (body == null) "null" else response.peekBody(Long.MAX_VALUE).string()
-        DFSLog.v("=====>>>>> response[$currentIndex]: ${System.currentTimeMillis() - time}ms", "code = ${response.code()}", "body = $stringBody")
+        DFSLog.v(
+            "=====>>>>> request[$requestName] done: ${System.currentTimeMillis() - time}ms",
+            "code = ${response.code()}",
+            "body = ${
+                stringBody.replace(
+                    "\n",
+                    ""
+                ).replace(" ", "")
+            }"
+        )
         return response
     }
 }

+ 3 - 1
app/src/main/java/com/doverfuelingsolutions/issp/api/service/ServiceBase.kt

@@ -9,9 +9,11 @@ import retrofit2.http.*
 
 interface ServiceBase {
 
+    @Headers("requestName: sessionInfo")
     @GET(WayneApiConfig.PATH_BASE_DEVICE_SESSION)
-    fun deviceSessionInfo(@Query("deviceSN") sn: String): Call<ResultDeviceSessionInfo>
+    fun sessionInfo(@Query("deviceSN") sn: String): Call<ResultDeviceSessionInfo>
 
+    @Headers("requestName: barcodeInfo")
     @GET(WayneApiConfig.PATH_BARCODE)
     fun barcodeInfo(@Path("id") id: Int): Call<ResultBarcode>
 }

+ 3 - 0
app/src/main/java/com/doverfuelingsolutions/issp/api/service/ServiceConfig.kt

@@ -5,13 +5,16 @@ import com.doverfuelingsolutions.issp.api.dto.ResultConfig
 import com.doverfuelingsolutions.issp.api.dto.ResultFile
 import retrofit2.Call
 import retrofit2.http.GET
+import retrofit2.http.Headers
 import retrofit2.http.Query
 
 interface ServiceConfig {
 
+    @Headers("requestName: config")
     @GET(WayneApiConfig.PATH_CONFIG_DESC)
     fun config(@Query("configOwnerIds") buId: String, @Query("configName") type: String): Call<Array<ResultConfig>>
 
+    @Headers("requestName: file")
     @GET(WayneApiConfig.PATH_CONFIG_FILE)
     fun file(@Query("configFileIds") id: String): Call<Array<ResultFile>>
 }

+ 2 - 0
app/src/main/java/com/doverfuelingsolutions/issp/api/service/ServiceLogin.kt

@@ -5,10 +5,12 @@ import com.doverfuelingsolutions.issp.api.dto.ResultLogin
 import retrofit2.Call
 import retrofit2.http.Field
 import retrofit2.http.FormUrlEncoded
+import retrofit2.http.Headers
 import retrofit2.http.POST
 
 interface ServiceLogin {
 
+    @Headers("requestName: login")
     @FormUrlEncoded
     @POST(WayneApiConfig.PATH_BASE_TOKEN)
     fun login(

+ 2 - 1
app/src/main/java/com/doverfuelingsolutions/issp/api/service/ServiceStation.kt

@@ -10,11 +10,12 @@ import retrofit2.http.POST
 
 interface ServiceStation {
 
+    @Headers("requestName: getNozzleInfo")
     @POST("u/?mn=GetPumpsLayout&pn=fdcServerApp&en=Applications.FDC.FdcServerHostApp")
     fun getNozzleInfo(@Body params: DefaultParams = DefaultParams(emptyList())): Call<Array<ResultPumpInfo>>
 
 
     @POST("u/?mn=GetFuelSaleTrxDetailsAsync&pn=fdcServerApp&en=Applications.FDC.FdcServerHostApp")
-    @Headers("Content-Type: application/json", "Accept: application/json")
+    @Headers("requestName: accumulationInfo", "Content-Type: application/json", "Accept: application/json")
     fun accumulationInfo(@Body params: DefaultParams): Call<List<ResultAccumulationInfo>>
 }

+ 6 - 5
app/src/main/java/com/doverfuelingsolutions/issp/api/service/ServiceTrx.kt

@@ -8,22 +8,23 @@ import com.wayne.www.waynelib.webservice.entity.ClientPosTrx
 import com.wayne.www.waynelib.webservice.entity.PosTrx
 import com.wayne.www.waynelib.webservice.entity.PosTrxMop
 import retrofit2.Call
-import retrofit2.http.Body
-import retrofit2.http.GET
-import retrofit2.http.POST
-import retrofit2.http.Path
+import retrofit2.http.*
 
 interface ServiceTrx {
 
+    @Headers("requestName: report")
     @POST(WayneApiConfig.PATH_TRX_TRANS)
     fun report(@Body trx: Any): Call<Any>
 
+    @Headers("requestName: paymentParam")
     @GET(WayneApiConfig.PATH_TRX_PAY_PARAM)
     fun paymentParam(): Call<ResultObj<List<ResultPaymentParam>>>
 
+    @Headers("requestName: generateOrder")
     @POST(WayneApiConfig.PATH_TRX_TRANS)
-    fun reportPaymentOrder(@Body clientPosTrx: ClientPosTrx): Call<PosTrx>
+    fun generateOrder(@Body clientPosTrx: ClientPosTrx): Call<PosTrx>
 
+    @Headers("requestName: pay")
     @POST(WayneApiConfig.PATH_PAY_BY_ID)
     fun pay(@Path("id") id: String, @Body posTrxMop: PosTrxMop): Call<ResultPayment>
 }

+ 7 - 4
app/src/main/java/com/doverfuelingsolutions/issp/data/GlobalData.kt

@@ -27,10 +27,13 @@ object GlobalData {
     val paymentName = GlobalDataProvider("", SPKeys.PAYMENT_NAME)
 
     fun init() {
-        val localTokenExpireMoment = accessTokenExpire.get()
-        if (localTokenExpireMoment > 0) {
-            DFSLog.d("loginToken will expire at ${TimeUtil.dateFormat(localTokenExpireMoment)}")
+        accessTokenExpire.get().let {
+            DFSLog.i(if (it > 0) {
+                "loginToken will expire at ${TimeUtil.dateFormat(it)}"
+            } else {
+                "loginToken does not exist"
+            })
+            isLogin = System.currentTimeMillis() < it
         }
-        isLogin = System.currentTimeMillis() < localTokenExpireMoment
     }
 }

+ 132 - 81
app/src/main/java/com/doverfuelingsolutions/issp/fusion/FusionManager.kt

@@ -21,6 +21,7 @@ import com.wayne.www.waynelib.fdc.OnFdcMessageReceivedListener
 import com.wayne.www.waynelib.fdc.OnFdcServiceResponseReceivedListener
 import com.wayne.www.waynelib.fdc.message.*
 import kotlinx.coroutines.*
+import java.util.*
 import kotlin.coroutines.resume
 import kotlin.coroutines.suspendCoroutine
 
@@ -29,7 +30,7 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
     OnFdcMessageReceivedListener {
 
     var stateFusion: FdcClient.FdcClientState = FdcClient.FdcClientState.Stopped
-    private const val timeoutMax = 4000
+    private const val timeoutMax = 8000
     var firstLink = false
         private set
     private var isLogin = false
@@ -40,7 +41,7 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
     var onFusionEvent: OnFusionEvent? = null
 
     override fun onFdcClientStateChanged(sender: FdcClient?, state: FdcClient.FdcClientState?) {
-        DFSLog.i("Fusion: state = ${state?.name}")
+        DFSLog.d("Fusion: state = ${state?.name?.toLowerCase(Locale.CHINA)}")
         if (sender == null || state == null) return
 
         stateFusion = state
@@ -53,12 +54,16 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
             FdcClient.FdcClientState.Connecting -> onFusionEvent?.onFusionReconnect()
             FdcClient.FdcClientState.MyAddReConnect -> {
                 if (!firstLink) {
-                    onFusionEvent?.onFusionInit(FusionError.WrongAddress, StringUtil.get(R.string.wrong_fusion_address))
+                    onFusionEvent?.onFusionInit(
+                        FusionError.WrongAddress,
+                        StringUtil.get(R.string.wrong_fusion_address)
+                    )
                 } else {
                     onFusionEvent?.onFusionReconnect()
                 }
             }
-            else -> {}
+            else -> {
+            }
         }
     }
 
@@ -90,7 +95,10 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
         coroutineIO.launch {
             delay(12000)
             if (stateFusion == FdcClient.FdcClientState.Stopped) {
-                onFusionEvent?.onFusionInit(FusionError.Timeout, StringUtil.get(R.string.connect_timeout))
+                onFusionEvent?.onFusionInit(
+                    FusionError.Timeout,
+                    StringUtil.get(R.string.connect_timeout)
+                )
             }
         }
     }
@@ -130,7 +138,10 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
                 }
                 if (!success) {
                     isLogin = false
-                    onFusionEvent?.onFusionInit(FusionError.Login, StringUtil.get(R.string.login_fail))
+                    onFusionEvent?.onFusionInit(
+                        FusionError.Login,
+                        StringUtil.get(R.string.login_fail)
+                    )
                     return@launch
                 } else {
                     isLogin = true
@@ -143,7 +154,10 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
                 pumpList.addAll(resultPumpList.data)
                 onFusionEvent?.onFusionInit(FusionError.Success)
             } else {
-                onFusionEvent?.onFusionInit(FusionError.GetNozzleInfo, StringUtil.get(R.string.fail_get_nozzle))
+                onFusionEvent?.onFusionInit(
+                    FusionError.GetNozzleInfo,
+                    StringUtil.get(R.string.fail_get_nozzle)
+                )
             }
         }
     }
@@ -153,66 +167,84 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
      * @param pumpId -1表示全部FP,其他代表某个FP
      */
     suspend fun getAllUnsettledOrder(pumpId: Int = -1) = suspendCoroutine<DFSResult<List<DeviceClass>>> {
-        ThreadUtil.io {
-            FdcClient.getDefault().sendGetAvailableFuelSaleTrxs(pumpId, { _, 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 {
-                        DFSLog.v("uncleared orders of pump $pumpId", response.singleFdcData.deviceClasses)
-                        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 =
-                                    pumpList.find { pump -> pump.pumpId == it.data?.pumpNo }?.oilName
-                                        ?: ""
-                                it.data
-                            }
-                        it.resume(DFSResult.success(resultDetailList))
+            ThreadUtil.io {
+                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
+                    )
+                    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 resultDetailList = unsettledList
+                                .map { dc -> async { getOrderDetail(dc) } }
+                                .map { deferred -> deferred.await() }
+                                .filter { it.success }
+                                .mapNotNull {
+                                    it.data?.productName =
+                                        pumpList.find { pump -> pump.pumpId == it.data?.pumpNo }?.oilName
+                                            ?: ""
+                                    it.data
+                                }
+                            val time3 = System.currentTimeMillis()
+                            DFSLog.v("fetch uncleared orders detail cost ${time3 - time2}ms")
+                            it.resume(DFSResult.success(resultDetailList))
+                        }
                     }
-                }
-            }, 4000)
+                }, timeoutMax)
+            }
         }
-    }
 
     /**
      * 挂起函数:获取订单详情
      */
     private suspend fun getOrderDetail(deviceClass: DeviceClass) = suspendCoroutine<DFSResult<DeviceClass>> {
-        getOrderDetailAsync(deviceClass) { asyncResult ->
-            it.resume(asyncResult)
+            getOrderDetailAsync(deviceClass) { asyncResult ->
+                it.resume(asyncResult)
+            }
         }
-    }
 
     /**
      * 获取订单详情
      */
     private fun getOrderDetailAsync(dcRaw: DeviceClass, callback: (result: DFSResult<DeviceClass>) -> Unit) {
         ThreadUtil.io {
-            FdcClient.getDefault().sendGetFuelSalesTrxDetailsRequestAsync(dcRaw.pumpNo, dcRaw.transactionSeqNo, dcRaw.releaseTokenAttribute, { _, 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 {
-                    val dc = response.fdcData[0].deviceClasses[0]
-                    // 迷惑的数据需要 hack 一下
-                    dc.releaseTokenAttribute = dcRaw.releaseTokenAttribute
-                    val correctNozzle = pumpList.find {
-                        it.pumpId == dc.pumpNo
-                    }?.nozzleList?.find {
-                        it.logicId == dc.nozzleNo
-                    }
-                    correctNozzle?.let {
-                        dc.nozzleNo = it.physicalId
-                        dc.logicNo = it.logicId
+            FdcClient.getDefault().sendGetFuelSalesTrxDetailsRequestAsync(
+                dcRaw.pumpNo,
+                dcRaw.transactionSeqNo,
+                dcRaw.releaseTokenAttribute,
+                { _, 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 {
+                        val dc = response.fdcData[0].deviceClasses[0]
+                        // 迷惑的数据需要 hack 一下
+                        dc.releaseTokenAttribute = dcRaw.releaseTokenAttribute
+                        val correctNozzle = pumpList.find {
+                            it.pumpId == dc.pumpNo
+                        }?.nozzleList?.find {
+                            it.logicId == dc.nozzleNo
+                        }
+                        correctNozzle?.let {
+                            dc.nozzleNo = it.physicalId
+                            dc.logicNo = it.logicId
+                        }
+                        callback(DFSResult.success(dc))
                     }
-                    callback(DFSResult.success(dc))
-                }
-            }, 3000)
+                },
+                3000
+            )
         }
     }
 
@@ -229,19 +261,25 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
             clearOrder(dc.pumpNo, dc.transactionSeqNo, dc.releaseTokenAttribute.toInt())
         }
     }
-    suspend fun clearOrder(pumpId: Int, transactionNo: String, token: Int,) = suspendCoroutine<DFSResult<Boolean>> {
-        ThreadUtil.io {
-            FdcClient.getDefault().sendClearFuelSaleTrxRequestAsync(pumpId, transactionNo, token, { _, response ->
-                if (response != null && response.singleDeviceClass != null && response.overallResult.equals("Success", true)) {
-                    DFSLog.i("clear order[$pumpId-$transactionNo-$token] succeed")
-                    it.resume(DFSResult.success(true))
-                } else {
-                    DFSLog.e("FusionManager.clearOrder failed", response)
-                    it.resume(DFSResult.fail(R.string.fail_lock_order))
-                }
-            },4000)
+
+    suspend fun clearOrder(pumpId: Int, transactionNo: String, token: Int) = suspendCoroutine<DFSResult<Boolean>> {
+            ThreadUtil.io {
+                FdcClient.getDefault()
+                    .sendClearFuelSaleTrxRequestAsync(pumpId, transactionNo, token, { _, response ->
+                        if (response != null && response.singleDeviceClass != null && response.overallResult.equals(
+                                "Success",
+                                true
+                            )
+                        ) {
+                            DFSLog.i("clear order[$pumpId-$transactionNo-$token] succeed")
+                            it.resume(DFSResult.success(true))
+                        } else {
+                            DFSLog.e("FusionManager.clearOrder failed", response)
+                            it.resume(DFSResult.fail(R.string.fail_lock_order))
+                        }
+                    }, 4000)
+            }
         }
-    }
 
     /**
      * 锁定/解锁订单
@@ -255,37 +293,50 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
             lockOrder(dc.pumpNo, dc.transactionSeqNo, dc.releaseTokenAttribute.toInt(), lock)
         }
     }
+
     suspend fun lockOrder(pumpId: Int, transactionNo: String, token: Int, lock: Boolean) = suspendCoroutine<DFSResult<Boolean>> {
-        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)) {
-                    it.resume(DFSResult.success(true))
+            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)) {
+                        it.resume(DFSResult.success(true))
+                    } else {
+                        it.resume(DFSResult.fail(response?.overallResult ?: StringUtil.get(R.string.fail_operate)))
+                    }
+                }
+                if (lock) {
+                    FdcClient.getDefault().sendLockFuelSaleTrxRequestAsync(
+                        pumpId,
+                        transactionNo,
+                        token,
+                        callback,
+                        4000
+                    )
                 } else {
-                    it.resume(DFSResult.fail(response?.overallResult ?: StringUtil.get(R.string.fail_operate)))
+                    FdcClient.getDefault().sendUnLockFuelSaleTrxRequestAsync(
+                        pumpId,
+                        transactionNo,
+                        token,
+                        callback,
+                        4000
+                    )
                 }
             }
-            if (lock) {
-                FdcClient.getDefault().sendLockFuelSaleTrxRequestAsync(pumpId, transactionNo, token, callback, 4000)
-            } else {
-                FdcClient.getDefault().sendUnLockFuelSaleTrxRequestAsync(pumpId, transactionNo, token, callback, 4000)
-            }
         }
-    }
 
     suspend fun requestPumpInfo() = FuelInfoApi.requestPumpInfo()
 
     private suspend fun login() = suspendCoroutine<Boolean> {
         val port = SPUtil.getString(SPKeys.MIDDLE_PORT).toInt()
         FdcClient.getDefault().sendLogonRequestAsync(port, port, "00.07", { _, response ->
+            DFSLog.v("Fusion: login response", response)
             if (response != null && response is ServiceResponseLogOn) {
                 val status = response.singleFdcData.fdcStatus
-                DFSLog.v("Fusion: try login response = $status")
                 if (status.equals(FusionConstants.CODE_SUCCESS, true)) {
-                    DFSLog.d("Fusion: login succeeded")
+                    DFSLog.i("Fusion: login succeeded")
                     it.resume(true)
                 } else {
-                    DFSLog.d("Fusion: login failed")
+                    DFSLog.e("Fusion: login failed")
                     it.resume(false)
                 }
             }
@@ -297,10 +348,10 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
             val status = response?.singleFdcData?.fdcStatus
             DFSLog.v("Fusion: try logout response = $status")
             if (status != null && status.equals(FusionConstants.CODE_SUCCESS, true)) {
-                DFSLog.d("Fusion: logout succeeded")
+                DFSLog.i("Fusion: logout succeeded")
                 it.resume(true)
             } else {
-                DFSLog.d("Fusion: logout failed")
+                DFSLog.e("Fusion: logout failed")
                 it.resume(false)
             }
         }, timeoutMax)

+ 1 - 1
app/src/main/java/com/doverfuelingsolutions/issp/utils/sp/SPUtil.kt

@@ -91,7 +91,7 @@ object SPUtil {
     /**
      * DC 类的唯一标识,用于标记订单(而非存下整个 DC),目的是节省存储空间和提高速度
      */
-    private fun getDeviceClassSymbol(dc: DeviceClass): String = "${dc.pumpNo}-${dc.transactionSeqNo}-${dc.releaseTokenAttribute}-${dc.releaseTokenElement}"
+    private fun getDeviceClassSymbol(dc: DeviceClass): String = "${dc.pumpNo}-${dc.transactionSeqNo}-${dc.releaseTokenAttribute}"
 
     /**
      * 订单列表:读取

+ 4 - 12
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentOrderList.kt

@@ -154,22 +154,14 @@ class FragmentOrderList private constructor(private val pumpId: Int) : FragmentB
                 DFSToastUtil.info(R.string.no_unpaid_order)
                 back()
             } else {
-                if (orderList.size != result.data.size || getOrderListHash(orderList) != getOrderListHash(result.data)) {
-                    if (orderList.isNotEmpty()) orderList.clear()
-                    orderList.addAll(result.data)
-                    filterOrderListByOilName()
-                    orderListAdapter.notifyDataSetChanged()
-
-                    DFSToastUtil.success(R.string.data_refresh)
-                }
+                if (orderList.isNotEmpty()) orderList.clear()
+                orderList.addAll(result.data)
+                filterOrderListByOilName()
+                orderListAdapter.notifyDataSetChanged()
             }
         }
     }
 
-    private fun getOrderListHash(list: List<DeviceClass>): String {
-        return list.joinToString(",") { "${it.pumpNo}-${it.transactionSeqNo}" }
-    }
-
     private fun filterOrderListByOilName() {
         if (orderListAfterFilter.isNotEmpty()) orderListAfterFilter.clear()
         orderListAfterFilter.addAll(orderList.filter { it.productName == selectedName })

+ 2 - 3
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentPayType.kt

@@ -76,16 +76,15 @@ class FragmentPayType private constructor(private val dc: DeviceClass): Fragment
                     DFSToastUtil.fail(StringUtil.get(R.string.fail_behave_reason, StringUtil.get(R.string.make_cloud_order), resultReportPayment.message))
                 }
             }
-            // 删除过期云订单
-            ThreadUtil.io { SPUtil.removeExpiredWayneOrder() }
 
             // 锁定订单
+            if (posTrx == null) return@launch
             val resultLock = FusionManager.lockOrder(dc, true)
             hideLoading()
             if (resultLock.success) {
                 dc.state = "Locked"
                 SPUtil.addLockOrder(dc)
-                (activity as MainActivity).setFragment(FragmentPayScanCode.build(dc, posTrx!!), true)
+                (activity as MainActivity).setFragment(FragmentPayScanCode.build(dc, posTrx), true)
             } else {
                 DFSToastUtil.fail(StringUtil.get(R.string.fail_behave_reason, StringUtil.get(R.string.lock_order), resultLock.message))
             }

+ 2 - 0
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentSelect.kt

@@ -140,6 +140,8 @@ class FragmentSelect : Fragment(),
                 }.filterNotNull()
                 SPUtil.replaceUnclearedOrderList(remainLockList)
             }
+            // 删除过期云订单
+            SPUtil.removeExpiredWayneOrder()
         }
     }
 

+ 2 - 1
app/src/main/res/values/strings.xml

@@ -22,6 +22,7 @@
     <string name="response_null">响应为空</string>
     <string name="network_error_host_error">网络异常或者域名不正确</string>
     <string name="data_null">数据为空</string>
+    <string name="fail_request">请求失败</string>
 
     <string name="fail_behave_reason">%1$s失败:%2$s</string>
 
@@ -95,7 +96,7 @@
     <string name="fail_pay">支付失败</string>
     <string name="wrong_order_info">订单信息错误</string>
     <string name="in_process_order">正在处理订单&#8230;</string>
-    <string name="in_get_order">正在获取订单数据&#8230;</string>
+    <string name="in_get_order">正在获取最新的订单数据&#8230;</string>
     <string name="fail_unlock_order">解锁订单失败</string>
     <string name="fail_clear_order">消单失败</string>
     <string name="fail_lock_order">锁单失败</string>