交易超时查询业务
diff --git a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
index 33632de..5a07853 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
@@ -83,10 +83,14 @@
         presenter.start()
         beepManager = BeepManager(this)
         dialogPurchase = DialogPurchase(this, object : DialogPurchase.ICallBack {
-            override fun callback(isManualCancel: Boolean) {
-                presenter.clickNoPay()
-                amountTxt.text = ""
-                AuxScreenController.getInstance().refreshContent(Arrays.asList(" 欢迎光临!", " 请刷卡..."))
+            override fun callback(isManualCancel: Boolean, isPaying: Boolean) {
+                if (isPaying) {
+                    presenter.clickToInterrupt()
+                } else {
+                    presenter.clickNoPay()
+                    amountTxt.text = ""
+                    AuxScreenController.getInstance().refreshContent(Arrays.asList(" 欢迎光临!", " 请刷卡..."))
+                }
             }
 
             override fun callback(code: String) {
@@ -349,14 +353,21 @@
     }
 
     override fun showConsumeQuery(hint: String) {
-        dialogPurchase!!.showProcess(hint, "请耐心等待")
+        dialogPurchase!!.showQueryProcess(hint, "请耐心等待")
         AuxScreenController.getInstance().refreshContent(Arrays.asList(hint, "请耐心等待"))
     }
 
+    override fun showConsumeInterrupt(info: CardUserInfoBean) {
+        showPayInterrupt(info.cardno)
+        dialogPurchase!!.showPayInterrupt()
+        AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("交易取消", "以银行交易为准"))
+        SoundUtil.playMusic(applicationContext, R.raw.pay_cancel)
+    }
+
     override fun showConsumeFail(info: CardUserInfoBean) {
         dialogPurchase!!.showPayFail(info)
-        SoundUtil.playMusic(applicationContext, R.raw.consume_fail)
         AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("消费失败", "原因:", info.retmsg))
+        SoundUtil.playMusic(applicationContext, R.raw.consume_fail)
         refreshRecentDtl(info)
     }
 
@@ -370,8 +381,8 @@
 
     override fun showReverseFail(info: CardUserInfoBean) {
         dialogPurchase!!.showReverseFail(info)
-        SoundUtil.playMusic(applicationContext, R.raw.reversal_fail)
         AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("冲正失败", "原因:", info.retmsg))
+        SoundUtil.playMusic(applicationContext, R.raw.reversal_fail)
         refreshRecentDtl(info)
     }
 
@@ -380,18 +391,20 @@
         if (info != null) {
             val showtime: Long = 30 * 1000
             lastPayInfo = info
+            if (lastShowRecentTime == null) {
+                if (info.transtime != null) {
+                    val paytime = DateUtil.timeFormatConvertToLong(info.transtime!!)
+                    val nowtime = DateUtil.timeFormatConvertToLong(DateUtil.getNowTimeNoFormat())
+                    if (nowtime - paytime > showtime) {
+                        return
+                    }
+                }
+            }
             //已显示过不在显示
             if (lastShowRecentTime == info.transtime) {
                 return
             }
             lastShowRecentTime = info.transtime
-            if (info.transtime != null) {
-                val paytime = DateUtil.timeFormatConvertToLong(info.transtime!!)
-                val nowtime = DateUtil.timeFormatConvertToLong(DateUtil.getNowTimeNoFormat())
-                if (nowtime - paytime > showtime) {
-                    return
-                }
-            }
 
             if (info.status == PayStatus.SUC) {
                 when {
@@ -429,6 +442,17 @@
         }
     }
 
+    private fun showPayInterrupt(cardno: String?) {
+        vLastResult.text = "交易取消"
+        vLastPayFailll.visibility = View.VISIBLE
+        vLastPayamtll.visibility = View.GONE
+        vLastPayFailreason.text = "以银行交易为准"
+        vLastCardno.text = cardno
+        vLastPayway.text = "card"
+        vLastPaytime.text = DateUtil.getNowTime()
+        resetPayShowCounter(30 * 1000)
+    }
+
     private fun delValueToEdit() {
         presenter.clickNoPay()
         val str = amountTxt.text.toString()
diff --git a/app/src/main/java/com/supwisdom/activities/consume/ConsumePresenter.kt b/app/src/main/java/com/supwisdom/activities/consume/ConsumePresenter.kt
index fd4a90d..b5aeb03 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/ConsumePresenter.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/ConsumePresenter.kt
@@ -48,6 +48,11 @@
                         LogUtil.d(TAG, "pay fail,reason=${ret.retmsg}")
                         iConsumeView.showConsumeFail(ret)
                     }
+                    PublicDef.MSG_PAYING_INTERRUPT -> {
+                        val ret = msg.obj as CardUserInfoBean
+                        LogUtil.d(TAG, "pay interrupt,reason=${ret.retmsg}")
+                        iConsumeView.showConsumeInterrupt(ret)
+                    }
                     PublicDef.MSG_CARD_REVERSE_FAIL -> {
                         val ret = msg.obj as CardUserInfoBean
                         LogUtil.d(TAG, "reverse fail,reason=${ret.retmsg}")
@@ -82,6 +87,10 @@
         cardPayService.clickToReverse(amount)
     }
 
+    fun clickToInterrupt() {
+        cardPayService.clickToInterrupt()
+    }
+
     fun codeToPay(code: String, amount: Int) {
         this.code = code
         this.amount = amount
diff --git a/app/src/main/java/com/supwisdom/activities/consume/IConsumeView.kt b/app/src/main/java/com/supwisdom/activities/consume/IConsumeView.kt
index 64249c9..608ff3f 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/IConsumeView.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/IConsumeView.kt
@@ -19,6 +19,8 @@
 
     fun showConsumeQuery(hint: String)
 
+    fun showConsumeInterrupt(info: CardUserInfoBean)
+
     fun showConsumeFail(info: CardUserInfoBean)
 
     fun showReverseSuc(info: CardUserInfoBean)
diff --git a/app/src/main/java/com/supwisdom/activities/consume/mode/CardPayService.kt b/app/src/main/java/com/supwisdom/activities/consume/mode/CardPayService.kt
index af02d37..0f2d57d 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/mode/CardPayService.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/mode/CardPayService.kt
@@ -10,6 +10,7 @@
 import com.supwisdom.exception.CardNotFoundError
 import com.supwisdom.exception.CardPayCancelFailError
 import com.supwisdom.exception.CardPayFailError
+import com.supwisdom.exception.CardPayInterruptError
 import com.supwisdom.okhttp.TransResp
 import com.supwisdom.service.EpayApiImpl
 import com.supwisdom.utils.*
@@ -32,6 +33,8 @@
     private var clickStat = ClickStat.INIT
     @Volatile
     private var amount: Int = 0
+    @Volatile
+    private var payQueryConfirm = false
     private var thread: Thread? = null
     private lateinit var cardBean: CardBean
 
@@ -64,6 +67,11 @@
         this.amount = amount
     }
 
+    fun clickToInterrupt() {
+        clickStat = ClickStat.INIT
+        payQueryConfirm = false
+    }
+
     private inner class CardPayRunnable : Runnable {
         private lateinit var onlRecord: TransdtlOnlineRecord
         private lateinit var onlRvsRecord: TransdtlOnlineRecord
@@ -98,6 +106,8 @@
                                 doConsume()
                             } catch (ex: CardPayFailError) {
                                 sendMsg(PublicDef.MSG_CARD_PAY_FAIL, getErrorInfo(ex.message))
+                            } catch (ex: CardPayInterruptError) {
+                                sendMsg(PublicDef.MSG_PAYING_INTERRUPT, getErrorInfo(ex.message))
                             } catch (ex: Exception) {
                                 ex.printStackTrace()
                                 LogUtil.d(
@@ -328,7 +338,9 @@
             }
             resp = consumeApi.payConfirm(onlRecord)
             result = parseConfirmResult(resp)
+            payQueryConfirm = false
             if (!result) {
+                payQueryConfirm = true
                 result = doOnlineConsumeQuery()
             }
             updateTransdtlOnline(result)
@@ -341,7 +353,7 @@
         private fun doOnlineConsumeQuery(): Boolean {
             var queryCnt = 1
             sleepWithCancel(1000)
-            while (clickStat == ClickStat.PAY) {
+            while (payQueryConfirm) {
                 sendMsg(PublicDef.MSG_CARD_PAY_QUERY, "消费确认中[$queryCnt]")
                 val resp = consumeApi.payQuery(onlRecord)
                 val result = parseConfirmResult(resp)
@@ -351,12 +363,16 @@
                 queryCnt += 1
                 sleepWithCancel(3000)
             }
-            return false
+            /**
+             * 手动取消交易
+             */
+            LogUtil.e(TAG, "manual cancel pay,cardphyid=[${onlRecord.cardphyid}],billno=[${onlRecord.billno}]")
+            throw CardPayInterruptError("交易取消")
         }
 
         private fun sleepWithCancel(ms: Long) {
             var time = 0
-            while (clickStat == ClickStat.PAY) {
+            while (payQueryConfirm) {
                 CommonUtil.doSleep(20)
                 time += 20
                 if (time > ms) {
diff --git a/app/src/main/java/com/supwisdom/activities/consume/mode/CodePayService.kt b/app/src/main/java/com/supwisdom/activities/consume/mode/CodePayService.kt
index 486ff10..08b68c1 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/mode/CodePayService.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/mode/CodePayService.kt
@@ -62,7 +62,7 @@
     }
 
     private fun payResultQuery(): Boolean {
-        sendMsg(PublicDef.MSG_CODE_PAYING_CANCEL, "谨慎操作查询取消")
+        sendMsg(PublicDef.MSG_PAYING_QUERY, "谨慎操作查询取消")
         LogUtil.d(TAG, "扫码消费确认超时,进行查询操作:billno=${codeRecord.billno}")
         sleepWithCancel(1500)
         var searchCnt = 1
diff --git a/app/src/main/java/com/supwisdom/exception/CardPayInterruptError.kt b/app/src/main/java/com/supwisdom/exception/CardPayInterruptError.kt
new file mode 100644
index 0000000..b69aa91
--- /dev/null
+++ b/app/src/main/java/com/supwisdom/exception/CardPayInterruptError.kt
@@ -0,0 +1,13 @@
+package com.supwisdom.exception
+
+/**
+ ** create by zzq on 2019/8/2
+ ** @desc 交易取消
+ **/
+class CardPayInterruptError : Exception {
+    constructor(message: String, ex: Exception) : super(message + ex.message)
+
+    constructor(message: String) : super(message)
+
+    constructor(ex: Exception) : super(ex.message)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/utils/PublicDef.kt b/app/src/main/java/com/supwisdom/utils/PublicDef.kt
index d55fa9f..551a3ac 100644
--- a/app/src/main/java/com/supwisdom/utils/PublicDef.kt
+++ b/app/src/main/java/com/supwisdom/utils/PublicDef.kt
@@ -31,7 +31,8 @@
     const val MSG_USER_INFO_SHOW = 17
     const val MSG_USER_INFO_CLEAR = 18
     const val MSG_LINK_STATUS = 19
-    const val MSG_CODE_PAYING_CANCEL = 20
+    const val MSG_PAYING_QUERY = 20
+    const val MSG_PAYING_INTERRUPT = 21
     /*************************不能重复*****************************/
     /**
      * 卡消费标志(1 byte)
diff --git a/app/src/main/java/com/supwisdom/view/DialogPurchase.kt b/app/src/main/java/com/supwisdom/view/DialogPurchase.kt
index f0611f4..a03f510 100644
--- a/app/src/main/java/com/supwisdom/view/DialogPurchase.kt
+++ b/app/src/main/java/com/supwisdom/view/DialogPurchase.kt
@@ -29,6 +29,7 @@
     private var posDec: PosDecoder? = null
     private var lastFixpayDecoderOpenTime: Long = 0
     private val waitTime = 60
+    private var payQueryConfirm = false
     var codePayingNoCancelEnable = false
     var codePaying = false
     var isFixPay = false
@@ -66,7 +67,11 @@
             }
             when (event.keyCode) {
                 KeyEvent.KEYCODE_DEL -> {
-                    finish(true)
+                    if (payQueryConfirm) {
+                        finish(isManualCancel = true, isPaying = true)
+                    } else {
+                        finish(isManualCancel = true, isPaying = false)
+                    }
                 }
             }
         }
@@ -85,6 +90,11 @@
         resetCounter(waitTime)
     }
 
+    fun showQueryProcess(hint: String, amount: String) {
+        payQueryConfirm = true
+        showProcess(hint, amount)
+    }
+
     fun showProcess(hint: String, amount: String) {
         vPayhint.text = hint
         vPayhint.setTextColor(Color.RED)
@@ -106,6 +116,16 @@
         resetCounter(info.showtime)
     }
 
+    fun showPayInterrupt() {
+        vPayhint.text = "交易取消"
+        vPayhint.setTextColor(Color.RED)
+        vPayamt.text = "以银行交易为准"
+        vPayamt.visibility = View.VISIBLE
+        vUsername.visibility = View.GONE
+        show()
+        resetCounter(3)
+    }
+
     fun showPayFail(info: CardUserInfoBean) {
         vPayhint.text = "消费失败"
         vPayhint.setTextColor(Color.RED)
@@ -177,11 +197,12 @@
         }
     }
 
-    private fun finish(isManualCancel: Boolean) {
+    private fun finish(isManualCancel: Boolean, isPaying: Boolean) {
         codePaying = false
         codePayingNoCancelEnable = false
+        payQueryConfirm = false
         dismiss()
-        callBack.callback(isManualCancel)
+        callBack.callback(isManualCancel, isPaying)
         asyncCloseDecoder()
     }
 
@@ -208,12 +229,12 @@
         }
 
         override fun onFinish() {
-            finish(false)
+            finish(false, false)
         }
     }
 
     interface ICallBack {
-        fun callback(isManualCancel: Boolean)
+        fun callback(isManualCancel: Boolean, isPaying: Boolean)
 
         fun callback(code: String)
     }
diff --git a/app/src/main/res/raw/pay_cancel.wav b/app/src/main/res/raw/pay_cancel.wav
new file mode 100644
index 0000000..21c72d9
--- /dev/null
+++ b/app/src/main/res/raw/pay_cancel.wav
Binary files differ