Pārlūkot izejas kodu

优化订单获取

Zheng 3 gadi atpakaļ
vecāks
revīzija
dae2bab766

+ 1 - 1
.idea/misc.xml

@@ -5,7 +5,7 @@
       <item index="0" class="java.lang.String" itemvalue="androidx.lifecycle.OnLifecycleEvent" />
       <item index="0" class="java.lang.String" itemvalue="androidx.lifecycle.OnLifecycleEvent" />
     </list>
     </list>
   </component>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   </component>
   <component name="ProjectType">
   <component name="ProjectType">

+ 2 - 2
app/build.gradle

@@ -21,8 +21,8 @@ android {
         applicationId "com.doverfuelingsolutions.issp"
         applicationId "com.doverfuelingsolutions.issp"
         minSdkVersion 22
         minSdkVersion 22
         targetSdkVersion 26
         targetSdkVersion 26
-        versionCode 9
-        versionName "1.1.22"
+        versionCode 12
+        versionName "1.1.25"
         archivesBaseName = versionName + "." + getTime()
         archivesBaseName = versionName + "." + getTime()
 
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

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

@@ -89,7 +89,9 @@ object SystemApi {
                 body!!.Data.let { channels ->
                 body!!.Data.let { channels ->
 //                    val combine = channels.find { type -> type.PaymentId == 13 }
 //                    val combine = channels.find { type -> type.PaymentId == 13 }
 //                    val param = combine ?: ResultPaymentParam(0, "移动支付")
 //                    val param = combine ?: ResultPaymentParam(0, "移动支付")
-                    val param = if (channels.isNotEmpty()) channels[0] else ResultPaymentParam(0,"移动支付")
+//                    val param = if (channels.isNotEmpty()) channels[0] else ResultPaymentParam(0,"移动支付")
+                    val combine = channels.find { type -> type.PaymentId != 3 && type.PaymentId != 2 }
+                    val param = combine ?: ResultPaymentParam(0, "移动支付")
                     GlobalData.paymentId.set(param.PaymentId)
                     GlobalData.paymentId.set(param.PaymentId)
                     GlobalData.paymentName.set(param.DispalyName)
                     GlobalData.paymentName.set(param.DispalyName)
                     it.resume(DFSResult.success(param))
                     it.resume(DFSResult.success(param))
@@ -166,6 +168,8 @@ object SystemApi {
                 posTrx.netAmount.toFloat()
                 posTrx.netAmount.toFloat()
             }
             }
         }
         }
+
+        DFSLog.i("支付类型:${posTrxMop.posMopPaymentId}")
         serviceTrx.pay(posTrx.id, posTrxMop).enqueue(object : Callback<ResultPayment> {
         serviceTrx.pay(posTrx.id, posTrxMop).enqueue(object : Callback<ResultPayment> {
             override fun onResponse(call: Call<ResultPayment>, response: Response<ResultPayment>) {
             override fun onResponse(call: Call<ResultPayment>, response: Response<ResultPayment>) {
                 val body = response.body()
                 val body = response.body()

+ 7 - 8
app/src/main/java/com/doverfuelingsolutions/issp/api/basic/LoggingInterceptor.kt

@@ -13,6 +13,12 @@ class LoggingInterceptor : Interceptor {
 //        val requestBuilder = request.newBuilder()
 //        val requestBuilder = request.newBuilder()
 //        requestBuilder.removeHeader("requestName")
 //        requestBuilder.removeHeader("requestName")
 //        val newRequest = requestBuilder.build()
 //        val newRequest = requestBuilder.build()
+        DFSLog.v(
+            "=====>>>>> request done in ${System.currentTimeMillis() - time}ms",
+            "method: ${request.method()}",
+            "url: ${request.url()}",
+            "request_headers: ${request.headers()}"
+        )
 
 
         val response = chain.proceed(request)
         val response = chain.proceed(request)
         val body = response.body()
         val body = response.body()
@@ -23,14 +29,7 @@ class LoggingInterceptor : Interceptor {
             "url: ${request.url()}",
             "url: ${request.url()}",
             "code: ${response.code()}",
             "code: ${response.code()}",
             "body: $stringBody",
             "body: $stringBody",
-            "request: $request",
-            "request_headers: ${request.headers()}",
-            "request_body: ${request.body()}",
-            "request_cacheControl: ${request.cacheControl()}",
-            "request_url: ${request.url()}",
-            "request_header_DeviceSN: ${request.header("DeviceSN")}",
-            "request_header_Content: ${request.header("Content-Type")}",
-            "request_header_Accept: ${request.header("Accept")}",
+            "request_headers: ${request.headers()}"
         )
         )
         return response
         return response
     }
     }

+ 0 - 1
app/src/main/java/com/doverfuelingsolutions/issp/data/GlobalData.kt

@@ -27,7 +27,6 @@ object GlobalData {
     val paymentId = GlobalDataProvider(-1, SPKeys.PAYMENT_ID)
     val paymentId = GlobalDataProvider(-1, SPKeys.PAYMENT_ID)
     val paymentName = GlobalDataProvider("", SPKeys.PAYMENT_NAME)
     val paymentName = GlobalDataProvider("", SPKeys.PAYMENT_NAME)
 
 
-    val colorForSignOrder = hashMapOf<String,Boolean>() //用于记录油枪是否有订单,有:深色;无:浅色
     fun init() {
     fun init() {
         accessTokenExpire.get().let {
         accessTokenExpire.get().let {
             DFSLog.i(if (it > 0) {
             DFSLog.i(if (it > 0) {

+ 110 - 18
app/src/main/java/com/doverfuelingsolutions/issp/fusion/FusionManager.kt

@@ -126,7 +126,58 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
         }
         }
     }
     }
 
 
-    override fun onServiceResponseReceived(sender: FdcClient?, serviceResponse: ServiceResponse?) {}
+    override fun onServiceResponseReceived(sender: FdcClient?, serviceResponse: ServiceResponse?) {
+//        if (serviceResponse == null) return
+//        HsLogUtils.o(HsLogTagFlag.FDC_TAG, serviceResponse)
+//        HsLogUtils.o(
+//            HsLogTagFlag.FDC_TAG,
+//            "====================================================================================================================================="
+//        )
+//        if ("AuthentificationError" == serviceResponse.overallResult) {
+//            HsLogUtils.o("AuthentificationError", "restart")
+//            coroutineIO.launch {
+//                sender?.restartAsync()
+//            }
+//        }
+//        if (serviceResponse.singleDeviceClass == null) return
+//        when (serviceResponse.requestType) {
+//            "ClearFuelSaleTrx" ->                 //支付成功
+//                if ("Success" == serviceResponse.overallResult) { //清除成功,则移除
+//                    val dc = serviceResponse.singleDeviceClass
+////                    HsSpUtils.removeClearOrders(dc)
+//                    // 支付成功后,移除本地云订单,清单
+//                    GlobalScope.launch(Dispatchers.IO) {
+//                        SPUtil.removeLockOrder(dc)
+//                        val resultClear = clearOrder(dc)
+//                        if (resultClear.success) {
+//                            dc.state = "Cleared"
+//                            SPUtil.removeUnclearedOrder(dc)
+//                            SPUtil.removeWayneOrder(dc)
+//                        } else {
+//                            // 失败则记下来,后续再尝试消单
+//                            SPUtil.addUnclearedOrder(dc)
+//                        }
+//
+//                    }
+//                }
+//            "LockFuelSaleTrx" -> {
+//                //锁定成功
+//                if ("Success" == serviceResponse.overallResult) {
+//                    val dc = serviceResponse.singleDeviceClass
+////                    HsSpUtils.saveLastLockOrder(dc) //当前正在操作的订单,主要怕收到锁命令时把他锁了
+////                    HsSpUtils.saveNeedUnLockOrder(dc)
+//                    SPUtil.addLockOrder(dc)
+//                    return
+//                }
+//            }
+//            "UnlockFuelSaleTrx" -> if ("Success" == serviceResponse.overallResult) {
+//                //解锁成功
+////                HsSpUtils.removeUnLockSuccessOrder(serviceResponse.singleDeviceClass)
+//                val dc = serviceResponse.singleDeviceClass
+//                SPUtil.removeLockOrder(dc)
+//            }
+//        }
+    }
 
 
     override fun onFdcMessageReceived(sender: FdcClient?, fdcMessage: FdcMessage?) {
     override fun onFdcMessageReceived(sender: FdcClient?, fdcMessage: FdcMessage?) {
         if (fdcMessage == null || fdcMessage is FdcMessageHeartbeat
         if (fdcMessage == null || fdcMessage is FdcMessageHeartbeat
@@ -145,34 +196,70 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
                 when (dc.state) {
                 when (dc.state) {
                     "Payable" -> {  // 新的订单,可以支付
                     "Payable" -> {  // 新的订单,可以支付
                         //将订单页面增加此可支付订单
                         //将订单页面增加此可支付订单
-                        onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo,true)
-                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
+//                        DFSLog.i("订单订单订单",dc.toString())
+
+                        //----------------------------------------------------
+                        var isNew = true
+                        val orders = SPUtil.getOrderListByPump(dc.pumpNo)
+                        orders.forEach {
+                            if (it.pumpNo == dc.pumpNo && it.transactionSeqNo == dc.transactionSeqNo) {
+                                it.state = dc.state
+                                isNew = false
+                            }
+                        }
+                        if (isNew) {
+                            //这里获取到的 releaseTokenAttribute 为 null,但其等同于 releaseTokenElement
+                            dc.releaseTokenAttribute = dc.releaseTokenElement
+                            val nozzle = nozzles.find { it.pumpId == dc.pumpNo && it.logicId == dc.nozzleNo }
+                            nozzle?.let {
+                                dc.nozzleNo = it.physicalId
+                                dc.logicNo = it.logicId
+                                dc.productName = it.barcodeName
+                            }
+                            orders.add(0,dc)
 
 
+                            SPUtil.setOrderListByPump(dc.pumpNo, orders)
+                            onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo,orders) //更新订单页面
+                        } else {
+                            SPUtil.setOrderListByPump(dc.pumpNo,orders)
+                            onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo,orders) //更新订单页面
+                        }
+                        onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo, true)//不管是不是新订单,都表示这把枪有单,需高亮显示
+//----------------------------------------------------
+//                        onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo, true)
+//                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
                     }
                     }
                     "Cleared" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { //需要消除的单(一般是已经支付过了,或本机支付的,或其他设备支付的)
                     "Cleared" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { //需要消除的单(一般是已经支付过了,或本机支付的,或其他设备支付的)
-//                        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.removeLockOrder(dc)
                         SPUtil.removeUnclearedOrder(dc)
                         SPUtil.removeUnclearedOrder(dc)
                         SPUtil.removeWayneOrder(dc)
                         SPUtil.removeWayneOrder(dc)
 
 
 
 
                         //将订单页面减去此需消除订单
                         //将订单页面减去此需消除订单
-                        onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo,false)   //枪页面显示浅色
-                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
+                        val orders = SPUtil.getOrderListByPump(dc.pumpNo)
+                        orders.remove(orders.find { it.pumpNo == dc.pumpNo && it.transactionSeqNo == dc.transactionSeqNo })
+                        SPUtil.setOrderListByPump(dc.pumpNo,orders)
+                        onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo, orders.isNotEmpty())   //枪页面显示浅色
+                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo,orders)
+//-----------------------------------------------------------------------------------------------------
+//                        onRefreshNozzleUi?.onRefreshNozzleUi(dc.pumpNo, false)   //枪页面显示浅色
+//                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
 
 
                     }
                     }
                     "Locked" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { // 锁单(被某一设备正在支付),或本机锁,或其他设备锁
                     "Locked" -> if (null != dc.pumpNo && null != dc.transactionSeqNo) { // 锁单(被某一设备正在支付),或本机锁,或其他设备锁
+//                        DFSLog.i("订单订单订单",dc.toString())
+                        //---------------------------------------------------------
 
 
-                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
+                        val order = SPUtil.getOrderListByPump(dc.pumpNo)
+                        order.find { it.pumpNo == dc.pumpNo && it.transactionSeqNo == dc.transactionSeqNo }
+                            ?.state = dc.state
+                        SPUtil.setOrderListByPump(dc.pumpNo, order)
+                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo,order)
 
 
+//---------------------------------------------------------
+//                        onRefreshOrderUi?.onRefreshOrderUi(dc.pumpNo)
                     }
                     }
                 }
                 }
             }
             }
@@ -194,7 +281,7 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
         }
         }
         if (!isExist) pumpSourceOrder.add(dc) //不存在添加
         if (!isExist) pumpSourceOrder.add(dc) //不存在添加
 
 
-        SPUtil.setOrderListByPump(dc.pumpNo,pumpSourceOrder)
+        SPUtil.setOrderListByPump(dc.pumpNo, pumpSourceOrder)
     }
     }
 
 
     @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
     @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
@@ -298,10 +385,10 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
                         val resultDetailList = arrayListOf<DeviceClass>()
                         val resultDetailList = arrayListOf<DeviceClass>()
                         unsettledList.forEach {
                         unsettledList.forEach {
                             val detail = getOrderDetail(it)
                             val detail = getOrderDetail(it)
-                            if(detail.success) {
+                            if (detail.success) {
                                 detail.data?.productName =
                                 detail.data?.productName =
                                     nozzles.find { n -> n.pumpId == detail.data?.pumpNo && detail.data.nozzleNo == n.physicalId }?.barcodeName
                                     nozzles.find { n -> n.pumpId == detail.data?.pumpNo && detail.data.nozzleNo == n.physicalId }?.barcodeName
-                                        ?:""
+                                        ?: ""
                                 detail.data?.let { it1 -> resultDetailList.add(it1) }
                                 detail.data?.let { it1 -> resultDetailList.add(it1) }
                             }
                             }
                         }
                         }
@@ -414,6 +501,11 @@ object FusionManager : LifecycleObserver, OnFdcClientStateChangedListener,
                             "Success",
                             "Success",
                             true
                             true
                         )) {
                         )) {
+                            SPUtil.addLockOrder(DeviceClass().apply {
+                                this.pumpNo = pumpId
+                                this.transactionSeqNo = transactionNo
+                                this.releaseTokenAttribute = token.toString()
+                            })
                         it.resume(DFSResult.success(true))
                         it.resume(DFSResult.success(true))
                     } else {
                     } else {
                         it.resume(
                         it.resume(

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

@@ -8,6 +8,7 @@ class SPKeys {
     companion object {
     companion object {
 
 
         val FIRST_LAUNCH = StringUtil.get(R.string.sp_first_launch)
         val FIRST_LAUNCH = StringUtil.get(R.string.sp_first_launch)
+        val FIRST_LAUNCH_ORDER = StringUtil.get(R.string.sp_first_launch_order)
 
 
         val ACCOUNT_NAME: String = StringUtil.get(R.string.sp_account_name)
         val ACCOUNT_NAME: String = StringUtil.get(R.string.sp_account_name)
         val PASSWORD: String = StringUtil.get(R.string.sp_password)
         val PASSWORD: String = StringUtil.get(R.string.sp_password)

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

@@ -117,10 +117,11 @@ object SPUtil {
      * 订单列表:存储
      * 订单列表:存储
      */
      */
     fun setOrderListByPump(pumpId: Int, orderList: List<DeviceClass>) {
     fun setOrderListByPump(pumpId: Int, orderList: List<DeviceClass>) {
+        DFSLog.v("set order_unsettled-$pumpId")
         setObject("${SPKeys.ORDER_UNSETTLED}-$pumpId", ArrayList(orderList))
         setObject("${SPKeys.ORDER_UNSETTLED}-$pumpId", ArrayList(orderList))
     }
     }
     /**
     /**
-     * 订单列表:分 pump 存储
+     * 订单列表:分 pump 存储REMOVE ORDER_LOCK START
      */
      */
     fun setAllOrderList(orderList: List<DeviceClass>) {
     fun setAllOrderList(orderList: List<DeviceClass>) {
         val map = HashMap<Int, ArrayList<DeviceClass>>()
         val map = HashMap<Int, ArrayList<DeviceClass>>()
@@ -162,6 +163,8 @@ object SPUtil {
             posTrx,
             posTrx,
             System.currentTimeMillis()
             System.currentTimeMillis()
         ))
         ))
+        val symbol = getDeviceClassSymbol(dc)
+        DFSLog.v("add order_generated:$symbol")
         setObject(SPKeys.ORDER_GENERATED, orderList)
         setObject(SPKeys.ORDER_GENERATED, orderList)
     }
     }
     /**
     /**
@@ -174,7 +177,9 @@ object SPUtil {
     fun removeWayneOrder(symbol: String) {
     fun removeWayneOrder(symbol: String) {
         val orderList = getWayneOrderList()
         val orderList = getWayneOrderList()
         val order = orderList.find { it.dc == symbol }
         val order = orderList.find { it.dc == symbol }
+        DFSLog.v("REMOVE ORDER_GENERATED START $symbol")
         if (order != null) {
         if (order != null) {
+            DFSLog.v("remove order_generated $symbol")
             orderList.remove(order)
             orderList.remove(order)
             setObject(SPKeys.ORDER_GENERATED, orderList)
             setObject(SPKeys.ORDER_GENERATED, orderList)
         }
         }
@@ -205,6 +210,7 @@ object SPUtil {
             }
             }
         }
         }
         if (orderList.size != notExpireList.size) {
         if (orderList.size != notExpireList.size) {
+            DFSLog.v("remove expired order_generated")
             setObject(SPKeys.ORDER_GENERATED, notExpireList)
             setObject(SPKeys.ORDER_GENERATED, notExpireList)
         }
         }
     }
     }
@@ -221,7 +227,9 @@ object SPUtil {
     fun addLockOrder(dc: DeviceClass) {
     fun addLockOrder(dc: DeviceClass) {
         val symbol = getDeviceClassSymbol(dc)
         val symbol = getDeviceClassSymbol(dc)
         val list = getLockOrderList()
         val list = getLockOrderList()
+        DFSLog.v("ADD ORDER_LOCK START $symbol")
         if (!list.contains(symbol)) {
         if (!list.contains(symbol)) {
+            DFSLog.v("add order_lock $symbol")
             list.add(symbol)
             list.add(symbol)
             setObject(SPKeys.ORDER_LOCK, list)
             setObject(SPKeys.ORDER_LOCK, list)
         }
         }
@@ -232,7 +240,9 @@ object SPUtil {
     fun removeLockOrder(dc: DeviceClass) = removeLockOrder(getDeviceClassSymbol(dc))
     fun removeLockOrder(dc: DeviceClass) = removeLockOrder(getDeviceClassSymbol(dc))
     private fun removeLockOrder(symbol: String) {
     private fun removeLockOrder(symbol: String) {
         val list = getLockOrderList()
         val list = getLockOrderList()
+        DFSLog.v("REMOVE ORDER_LOCK START $symbol")
         if (list.isNotEmpty() && list.contains(symbol)) {
         if (list.isNotEmpty() && list.contains(symbol)) {
+            DFSLog.v("remove order_lock $symbol")
             list.remove(symbol)
             list.remove(symbol)
             setObject(SPKeys.ORDER_LOCK, list)
             setObject(SPKeys.ORDER_LOCK, list)
         }
         }
@@ -249,6 +259,7 @@ object SPUtil {
      * 订单锁定:新的锁定订单列表
      * 订单锁定:新的锁定订单列表
      */
      */
     fun replaceLockOrderList(orderList: List<String>) {
     fun replaceLockOrderList(orderList: List<String>) {
+        DFSLog.v("replace lock")
         setObject(SPKeys.ORDER_LOCK, ArrayList(orderList))
         setObject(SPKeys.ORDER_LOCK, ArrayList(orderList))
     }
     }
     fun replaceLockOrderListByDC(orderList: List<DeviceClass>) {
     fun replaceLockOrderListByDC(orderList: List<DeviceClass>) {

+ 7 - 1
app/src/main/java/com/doverfuelingsolutions/issp/utils/thread/DFSThreadFactory.kt

@@ -8,5 +8,11 @@ class DFSThreadFactory(private val basicName: String) : ThreadFactory {
         private var count = 0
         private var count = 0
     }
     }
 
 
-    override fun newThread(r: Runnable): Thread = Thread(r, "dfs.$basicName.${count++}")
+    override fun newThread(r: Runnable): Thread{
+        val thread = Thread(r, "dfs.$basicName.${count++}")
+
+        if (thread.isDaemon) thread.isDaemon = false //这里改成创建非守护线程
+
+        return thread
+    }
 }
 }

+ 38 - 14
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentNozzle.kt

@@ -14,6 +14,7 @@ import com.doverfuelingsolutions.issp.databinding.FragmentNozzleBinding
 import com.doverfuelingsolutions.issp.fusion.FusionManager
 import com.doverfuelingsolutions.issp.fusion.FusionManager
 import com.doverfuelingsolutions.issp.utils.DFSToastUtil
 import com.doverfuelingsolutions.issp.utils.DFSToastUtil
 import com.doverfuelingsolutions.issp.utils.StringUtil
 import com.doverfuelingsolutions.issp.utils.StringUtil
+import com.doverfuelingsolutions.issp.utils.sp.SPKeys
 import com.doverfuelingsolutions.issp.utils.sp.SPUtil
 import com.doverfuelingsolutions.issp.utils.sp.SPUtil
 import com.doverfuelingsolutions.issp.view.MainActivity
 import com.doverfuelingsolutions.issp.view.MainActivity
 import com.doverfuelingsolutions.issp.view.adapter.ChooseListAdapter
 import com.doverfuelingsolutions.issp.view.adapter.ChooseListAdapter
@@ -22,6 +23,7 @@ import com.scwang.smart.refresh.header.ClassicsHeader
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.GlobalScope
 import kotlinx.coroutines.async
 import kotlinx.coroutines.async
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
+import java.io.IOException
 
 
 class FragmentNozzle private constructor() : FragmentBasic(),RefreshNozzle{
 class FragmentNozzle private constructor() : FragmentBasic(),RefreshNozzle{
 
 
@@ -37,6 +39,7 @@ class FragmentNozzle private constructor() : FragmentBasic(),RefreshNozzle{
 
 
 //    private val colorForSignOrder = arrayListOf<Int>() // 用于标记该油枪是否有订单,有:深色 ; 无:浅色
 //    private val colorForSignOrder = arrayListOf<Int>() // 用于标记该油枪是否有订单,有:深色 ; 无:浅色
 
 
+    private var isRefreshing: Boolean = false
     private lateinit var binding: FragmentNozzleBinding
     private lateinit var binding: FragmentNozzleBinding
     private val isExistOrderMap = hashMapOf<String,Boolean>()
     private val isExistOrderMap = hashMapOf<String,Boolean>()
     private val chooseListAdapter = ChooseListAdapter(FusionManager.nozzles.map { it.physicalId.toString() },
     private val chooseListAdapter = ChooseListAdapter(FusionManager.nozzles.map { it.physicalId.toString() },
@@ -68,12 +71,12 @@ class FragmentNozzle private constructor() : FragmentBasic(),RefreshNozzle{
             val resultNozzles = FusionManager.getPumpInfo()
             val resultNozzles = FusionManager.getPumpInfo()
             if (resultNozzles.success && resultNozzles.data != null) {
             if (resultNozzles.success && resultNozzles.data != null) {
                 binding.nozzleList.adapter?.notifyDataSetChanged()
                 binding.nozzleList.adapter?.notifyDataSetChanged()
+                loadRemoteData()
                 binding.smartRefreshLayout.finishRefresh(200, true, false)
                 binding.smartRefreshLayout.finishRefresh(200, true, false)
             } else {
             } else {
                 binding.smartRefreshLayout.finishRefresh(200, false, true)
                 binding.smartRefreshLayout.finishRefresh(200, false, true)
             }
             }
 
 
-            loadRemoteData()
         }
         }
     }
     }
 
 
@@ -93,36 +96,57 @@ class FragmentNozzle private constructor() : FragmentBasic(),RefreshNozzle{
 
 
     private fun loadListData(){
     private fun loadListData(){
         lifecycleScope.launchWhenStarted {
         lifecycleScope.launchWhenStarted {
-            val loadingDialog = loading(R.string.in_get_nozzle)
+            if (SPUtil.getString(SPKeys.FIRST_LAUNCH_ORDER).isBlank()) {
+                val loadingDialog = loading(R.string.first_get_nozzle)
+                loadRemoteData()
+                loadingDialog.dismiss()
+                SPUtil.putString(SPKeys.FIRST_LAUNCH_ORDER,"false")
+            } else {
+                val loadingDialog = loading(R.string.in_get_nozzle)
+
+                FusionManager.nozzles.forEach {
+                    val orders = SPUtil.getOrderListByPump(it.pumpId)
+                    isExistOrderMap[it.pumpId.toString()] = orders.isNotEmpty()
+                }
+                chooseListAdapter.notifyDataSetChanged()
 
 
-            loadRemoteData()
 
 
-            loadingDialog.dismiss()
+                loadingDialog.dismiss()
+            }
+
 
 
         }
         }
     }
     }
 
 
     private suspend fun loadRemoteData() {
     private suspend fun loadRemoteData() {
+//        if(isRefreshing) return
+//
+//        isRefreshing = true
         FusionManager.nozzles.forEach {
         FusionManager.nozzles.forEach {
             val result = FusionManager.getAllUnsettledOrder(it.pumpId)
             val result = FusionManager.getAllUnsettledOrder(it.pumpId)
-            isExistOrderMap[it.pumpId.toString()] = result.success && result.data != null && result.data.isNotEmpty()
+            if (result.success && result.data != null) {
+                isExistOrderMap[it.pumpId.toString()] = result.data.isNotEmpty()
+                SPUtil.setOrderListByPump(it.pumpId,result.data)
+            }
         }
         }
 
 
         chooseListAdapter.notifyDataSetChanged()
         chooseListAdapter.notifyDataSetChanged()
+//        isRefreshing = false
     }
     }
 
 
     override fun onRefreshNozzleUi(pump: Int,isExist: Boolean) {
     override fun onRefreshNozzleUi(pump: Int,isExist: Boolean) {
         lifecycleScope.launchWhenStarted {
         lifecycleScope.launchWhenStarted {
-            if (isExist) {
-                isExistOrderMap[pump.toString()] = isExist
-            } else {  // false 表示有消单,还需检测是否此 pump 已无订单
-                val result = FusionManager.getAllUnsettledOrder(pump)
-                isExistOrderMap[pump.toString()] = result.success && result.data != null && result.data.isNotEmpty()
-            }
-            chooseListAdapter.notifyDataSetChanged()
-
-//            isExistOrderMap[pump.toString()] = isExist
+//            if (isExist) {
+//                isExistOrderMap[pump.toString()] = isExist
+//            } else {  // false 表示有消单,还需检测是否此 pump 已无订单
+//                val result = FusionManager.getAllUnsettledOrder(pump)
+//                isExistOrderMap[pump.toString()] = result.success && result.data != null && result.data.isNotEmpty()
+//            }
 //            chooseListAdapter.notifyDataSetChanged()
 //            chooseListAdapter.notifyDataSetChanged()
+
+
+            isExistOrderMap[pump.toString()] = isExist
+            chooseListAdapter.notifyDataSetChanged()
         }
         }
     }
     }
 
 

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

@@ -16,6 +16,7 @@ import com.doverfuelingsolutions.issp.databinding.FragmentNozzleOrdersBinding
 import com.doverfuelingsolutions.issp.fusion.FusionManager
 import com.doverfuelingsolutions.issp.fusion.FusionManager
 import com.doverfuelingsolutions.issp.utils.DFSToastUtil
 import com.doverfuelingsolutions.issp.utils.DFSToastUtil
 import com.doverfuelingsolutions.issp.utils.StringUtil
 import com.doverfuelingsolutions.issp.utils.StringUtil
+import com.doverfuelingsolutions.issp.utils.log.DFSLog
 import com.doverfuelingsolutions.issp.utils.sp.SPUtil
 import com.doverfuelingsolutions.issp.utils.sp.SPUtil
 import com.doverfuelingsolutions.issp.view.MainActivity
 import com.doverfuelingsolutions.issp.view.MainActivity
 import com.doverfuelingsolutions.issp.view.adapter.ChooseListAdapter
 import com.doverfuelingsolutions.issp.view.adapter.ChooseListAdapter
@@ -23,8 +24,6 @@ import com.doverfuelingsolutions.issp.view.adapter.OrderListAdapter
 import com.doverfuelingsolutions.issp.view.fragment.callback.RefreshOrder
 import com.doverfuelingsolutions.issp.view.fragment.callback.RefreshOrder
 import com.scwang.smart.refresh.header.ClassicsHeader
 import com.scwang.smart.refresh.header.ClassicsHeader
 import com.wayne.www.waynelib.fdc.message.DeviceClass
 import com.wayne.www.waynelib.fdc.message.DeviceClass
-import kotlinx.coroutines.async
-import kotlinx.coroutines.launch
 
 
 class FragmentOrderList private constructor() : FragmentBasic(),RefreshOrder {
 class FragmentOrderList private constructor() : FragmentBasic(),RefreshOrder {
 
 
@@ -114,6 +113,7 @@ class FragmentOrderList private constructor() : FragmentBasic(),RefreshOrder {
                         if (result.success) {
                         if (result.success) {
                             dc.state = "Payable"
                             dc.state = "Payable"
                             orderListAdapter.notifyItemChanged(position)
                             orderListAdapter.notifyItemChanged(position)
+                            SPUtil.removeLockOrder(dc)
                             DFSToastUtil.success(R.string.unlock_order_success)
                             DFSToastUtil.success(R.string.unlock_order_success)
                         } else {
                         } else {
                             DFSToastUtil.fail(R.string.fail_unlock_order)
                             DFSToastUtil.fail(R.string.fail_unlock_order)
@@ -167,7 +167,7 @@ class FragmentOrderList private constructor() : FragmentBasic(),RefreshOrder {
             orderListAdapter.notifyDataSetChanged()
             orderListAdapter.notifyDataSetChanged()
 
 
             // remote data
             // remote data
-            loadRemoteData()
+//            loadRemoteData()
             dialog.dismiss()
             dialog.dismiss()
             (requireActivity() as MainActivity).fragmentRouter.resumeFragmentToolbarTimer()
             (requireActivity() as MainActivity).fragmentRouter.resumeFragmentToolbarTimer()
         }
         }
@@ -187,6 +187,7 @@ class FragmentOrderList private constructor() : FragmentBasic(),RefreshOrder {
             } else {
             } else {
                 orderList.clear()
                 orderList.clear()
                 orderList.addAll(result.data)
                 orderList.addAll(result.data)
+                if (orderList.isNotEmpty())  DFSLog.i("订单订单订单",orderList[0].toString())
                 filterOrderListByOilName()
                 filterOrderListByOilName()
                 orderListAdapter.notifyDataSetChanged()
                 orderListAdapter.notifyDataSetChanged()
             }
             }
@@ -203,9 +204,15 @@ class FragmentOrderList private constructor() : FragmentBasic(),RefreshOrder {
         val isNozzle = MutableLiveData(true)
         val isNozzle = MutableLiveData(true)
     }
     }
 
 
-    override fun onRefreshOrderUi(pump: Int) {
+    override fun onRefreshOrderUi(pump: Int,orders: List<DeviceClass>) {
         lifecycleScope.launchWhenStarted {
         lifecycleScope.launchWhenStarted {
-            loadRemoteData()
+//            loadRemoteData()
+            if (pump == pumpId) {
+                orderList.clear()
+                orderList.addAll(orders)
+                orderListAdapter.notifyDataSetChanged()
+            }
+
         }
         }
 
 
 
 

+ 4 - 20
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/FragmentPayScanCode.kt

@@ -114,6 +114,10 @@ class FragmentPayScanCode private constructor() : FragmentBasic() {
             val result = SystemApi.pay(posTrx, scanValue)
             val result = SystemApi.pay(posTrx, scanValue)
             dialog.dismiss()
             dialog.dismiss()
 
 
+            //恒达、永佳有出现程序执行到这没继续走下去的,尽管已经支付成功,不知道为什么,而且程序的走势很奇怪
+            /**20211227 判断是线程池的原因,使用了 ThreadUtil.io{XXX},线程池创建的都是守护线程,可能是这个原因,
+             *  现改成非守护线程再观察(原先锁单完成后没及时将锁定订单保存至本地估计也是这个原因)
+             */
             if ((result.success && result.data != null) || (!result.success && result.message == "此订单已支付,请勿重复支付")) {
             if ((result.success && result.data != null) || (!result.success && result.message == "此订单已支付,请勿重复支付")) {
                 // 支付成功后,移除本地云订单,清单
                 // 支付成功后,移除本地云订单,清单
                 GlobalScope.launch(Dispatchers.IO) {
                 GlobalScope.launch(Dispatchers.IO) {
@@ -130,26 +134,6 @@ class FragmentPayScanCode private constructor() : FragmentBasic() {
 
 
                 }
                 }
 
 
-//                //查找该 pumpIP 是否还有订单,更新 GlobalData.colorForSignOrder
-//                val unsettledResult = FusionManager.getAllUnsettledOrder(dc.pumpNo)
-//                val copyList = IntArray(GlobalData.colorForSignOrder.size)
-//                GlobalData.colorForSignOrder.forEachIndexed { index, i ->
-//                    copyList[index] = i
-//                }
-//                if (unsettledResult.success && unsettledResult.data != null && unsettledResult.data.isEmpty()) { //若为空
-//
-//                    /**   eg:
-//                     * pumpID:                                    | 1 | 4 | 2 | 3 |
-//                     * SiteLevelNozzleId / nozzleNo / physicalId:| 1 | 2 | 3 | 4 |
-//                     * 下标:                                     | 0 | 1 | 2 | 3 |
-//                     * */
-//                    copyList[dc.nozzleNo - 1] = ResourcesCompat.getColor(  //colorForSignOrder对应的颜色顺序会与油枪列表的顺序对应
-//                        DFSApplication.instance.applicationContext.resources, R.color.colorPrimaryTransparent, null)
-//
-//                }
-//                GlobalData.colorForSignOrder.clear()
-//                GlobalData.colorForSignOrder.addAll(copyList.toList())
-
                 // 获取加油员名称
                 // 获取加油员名称
                 val resultInfo = SystemApi.getPosTicketInfo(posTrx.id)
                 val resultInfo = SystemApi.getPosTicketInfo(posTrx.id)
 
 

+ 2 - 1
app/src/main/java/com/doverfuelingsolutions/issp/view/fragment/callback/RefreshOrder.kt

@@ -1,7 +1,8 @@
 package com.doverfuelingsolutions.issp.view.fragment.callback
 package com.doverfuelingsolutions.issp.view.fragment.callback
 
 
+import com.wayne.www.waynelib.fdc.message.DeviceClass
 import com.wayne.www.waynelib.fdc.model.Pump
 import com.wayne.www.waynelib.fdc.model.Pump
 
 
 interface RefreshOrder {
 interface RefreshOrder {
-    fun onRefreshOrderUi(pump: Int)
+    fun onRefreshOrderUi(pump: Int,orders:List<DeviceClass>)
 }
 }

+ 1 - 0
app/src/main/res/values/keys.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
 <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
     <string name="sp_first_launch">first_launch</string>
     <string name="sp_first_launch">first_launch</string>
+    <string name="sp_first_launch_order">first_launch_order</string>
     <string name="sp_account_name">account_name</string>
     <string name="sp_account_name">account_name</string>
     <string name="sp_password">password</string>
     <string name="sp_password">password</string>
     <string name="sp_access_token">access_token</string>
     <string name="sp_access_token">access_token</string>

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

@@ -108,6 +108,7 @@
     <string name="amount_rmb">¥%1$s</string>
     <string name="amount_rmb">¥%1$s</string>
     <string name="volume_l">%1$sL</string>
     <string name="volume_l">%1$sL</string>
 
 
+    <string name="first_get_nozzle">首次安装,加载订单中,请稍候</string>
     <string name="in_get_nozzle">正在获取油枪页面</string>
     <string name="in_get_nozzle">正在获取油枪页面</string>
     <string name="end_get_nozzle">获取油枪页面成功</string>
     <string name="end_get_nozzle">获取油枪页面成功</string>
 
 

+ 29 - 1
app/src/test/java/com/doverfuelingsolutions/issp/ExampleUnitTest.kt

@@ -1,8 +1,14 @@
 package com.doverfuelingsolutions.issp
 package com.doverfuelingsolutions.issp
 
 
+import androidx.lifecycle.lifecycleScope
+import com.doverfuelingsolutions.issp.utils.thread.ThreadUtil
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
 import org.junit.Test
 import org.junit.Test
 
 
 import org.junit.Assert.*
 import org.junit.Assert.*
+import kotlin.coroutines.resume
+import kotlin.coroutines.suspendCoroutine
 
 
 /**
 /**
  * Example local unit test, which will execute on the development machine (host).
  * Example local unit test, which will execute on the development machine (host).
@@ -12,6 +18,28 @@ import org.junit.Assert.*
 class ExampleUnitTest {
 class ExampleUnitTest {
     @Test
     @Test
     fun addition_isCorrect() {
     fun addition_isCorrect() {
-        assertEquals(4, 2 + 2)
+
+    }
+
+    suspend fun fun1() = suspendCoroutine<String>{
+        Thread.sleep(3000)
+        it.resume("执行完毕")
+    }
+
+    @Test
+    fun fun2() {
+        val list = arrayListOf<Int>(1,2,3,4,5)
+        println(list)
+        list.add(0,0)
+        println(list)
+    }
+
+    @Test
+    fun test_thread(){
+        val thread = Thread()
+
+        println(thread.isDaemon)
+        println(thread.priority)
+        println(thread.threadGroup)
     }
     }
 }
 }

+ 55 - 0
waynelib_/src/main/java/com/wayne/www/waynelib/fdc/message/DeviceClass.java

@@ -584,4 +584,59 @@ public class DeviceClass implements Serializable {
         return null != getState() && getState().equals("Cleared");
         return null != getState() && getState().equals("Cleared");
     }
     }
 
 
+    @Override
+    public String toString() {
+        return "DeviceClass{" +
+                "type='" + type + '\'' +
+                ", transactionSeqNo='" + transactionSeqNo + '\'' +
+                ", errorCode='" + errorCode + '\'' +
+                ", pumpNo=" + pumpNo +
+                ", nozzleNo=" + nozzleNo +
+                ", state='" + state + '\'' +
+                ", releaseTokenElement='" + releaseTokenElement + '\'' +
+                ", completionReason='" + completionReason + '\'' +
+                ", amount=" + amount +
+                ", volume=" + volume +
+                ", unitPrice=" + unitPrice +
+                ", nozzleNoInElement=" + nozzleNoInElement +
+                ", volumeProduct1='" + volumeProduct1 + '\'' +
+                ", volumeProduct2='" + volumeProduct2 + '\'' +
+                ", productNo1_diff='" + productNo1_diff + '\'' +
+                ", productNo2_diff='" + productNo2_diff + '\'' +
+                ", productNo1='" + productNo1 + '\'' +
+                ", productNo2='" + productNo2 + '\'' +
+                ", productUM='" + productUM + '\'' +
+                ", productName='" + productName + '\'' +
+                ", blendRatio=" + blendRatio +
+                ", lockingApplicationSender='" + lockingApplicationSender + '\'' +
+                ", authorisationApplicationSender='" + authorisationApplicationSender + '\'' +
+                ", dSPFields='" + dSPFields + '\'' +
+                ", cRCMode='" + cRCMode + '\'' +
+                ", startTimeStamp='" + startTimeStamp + '\'' +
+                ", endTimeStamp='" + endTimeStamp + '\'' +
+                ", maxTrxAmount=" + maxTrxAmount +
+                ", maxTrxVolume=" + maxTrxVolume +
+                ", lockFuelSaleTrx='" + lockFuelSaleTrx + '\'' +
+                ", deviceId='" + deviceId + '\'' +
+                ", releaseTokenAttribute='" + releaseTokenAttribute + '\'' +
+                ", deviceState='" + deviceState + '\'' +
+                ", nozzles=" + nozzles +
+                ", errorID='" + errorID + '\'' +
+                ", errorDescription='" + errorDescription + '\'' +
+                ", fuleMode=" + fuleMode +
+                ", releasedProducts=" + releasedProducts +
+                ", products=" + products +
+                ", deviceClasses=" + deviceClasses +
+                ", reservingDeviceIdField='" + reservingDeviceIdField + '\'' +
+                ", fuellingType='" + fuellingType + '\'' +
+                ", payTypeField='" + payTypeField + '\'' +
+                ", deviceSubState='" + deviceSubState + '\'' +
+                ", typeElement='" + typeElement + '\'' +
+                ", myLogicNo=" + myLogicNo +
+                ", myProductName='" + myProductName + '\'' +
+                ", amountTotalizer=" + amountTotalizer +
+                ", volumeTotalizer=" + volumeTotalizer +
+                ", SaleEndTime='" + SaleEndTime + '\'' +
+                '}';
+    }
 }
 }