Merge branch 'hotfix/1.0.7'
diff --git a/Makefile b/Makefile
index a5586c3..83637bb 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
 
 apk:
 	@echo "build app apk!"
-	gradlew assembleRelease
+	gradlew app:assembleRelease
 	@echo "build android sign apk"
 	java -jar signapk.jar platform.x509.pem platform.pk8 $(APPPATH)/$(BUILDAPK) $(APPPATH)/$(SIGNAPK)
 	@echo "build upgrade zip"
diff --git a/app/build.gradle b/app/build.gradle
index dc77cf8..d919594 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -53,7 +53,8 @@
 
 dependencies {
 //    implementation fileTree(dir: 'libs', include: ['*.jar'])
-    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61'
+    implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.61'
     implementation 'com.android.support:appcompat-v7:28.0.0'
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     testImplementation 'junit:junit:4.12'
@@ -61,18 +62,18 @@
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
 
 //    compile 'com.alibaba:fastjson:1.1.70.android'
-    compile 'com.google.code.gson:gson:2.8.5'
-    compile 'com.nineoldandroids:parent:2.4.0'
-    compile 'com.squareup.okhttp3:okhttp:3.10.0'
-    compile 'net.java.dev.jna:jna:4.5.0@aar'
-    compile 'com.koushikdutta.async:androidasync:2.2.1'
-    compile group: 'com.android.support', name: 'recyclerview-v7', version: '28.0.0'
-    compile 'org.apache.commons:commons-lang3:3.7'
-    compile 'com.android.support:multidex:1.0.3'
-    compile 'org.jetbrains.kotlin:kotlin-reflect:1.3.41'
-    compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
-    compile 'org.apache.httpcomponents:httpcore:4.4.10'
-    compile("com.beust:klaxon:0.30") {
+    implementation 'com.google.code.gson:gson:2.8.6'
+    implementation 'com.nineoldandroids:parent:2.4.0'
+    implementation 'com.squareup.okhttp3:okhttp:4.2.2'
+    implementation 'net.java.dev.jna:jna:5.5.0@aar'
+    implementation 'com.koushikdutta.async:androidasync:2.2.1'
+    implementation group: 'com.android.support', name: 'recyclerview-v7', version: '28.0.0'
+    implementation 'org.apache.commons:commons-lang3:3.9'
+    implementation 'com.android.support:multidex:1.0.3'
+    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.61'
+    implementation 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
+    implementation 'org.apache.httpcomponents:httpcore:4.4.13'
+    implementation("com.beust:klaxon:0.30") {
         exclude group: 'org.jetbrains'
     }
     compile files('libs/zxinglibsl.jar')
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 363ff7f..e7a96e8 100644
--- a/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/consume/ConsumeActivity.kt
@@ -388,6 +388,7 @@
         AuxScreenController.getInstance().refreshContent(Arrays.asList(" 欢迎光临!", " 请刷卡..."))
 
         periodFixPayEnable = false
+        dialogPurchase?.dismiss()
         pos.getControlPara(PublicDef.CONTROL_FIXAMT)?.also { mode ->
             when {
                 mode.paraval == PayMode.HOTKEY.desc -> {
diff --git a/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt b/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt
index eaf5482..7ce5604 100644
--- a/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt
+++ b/app/src/main/java/com/supwisdom/activities/consumeMode/ConsumeModeActivity.kt
@@ -11,7 +11,6 @@
 import com.supwisdom.activities.BaseActivity
 import com.supwisdom.activities.SPApplication
 import com.supwisdom.activities.consume.PayMode
-import com.supwisdom.activities.menu.MenuActivity
 import com.supwisdom.auxscreen.AuxScreenController
 import com.supwisdom.entity.HotKeyPayRecord
 import com.supwisdom.entity.PeriodFixPayRecord
@@ -31,7 +30,8 @@
     private lateinit var vSpecialDesc: TextView
     private lateinit var rbHotkeyMode: RadioButton
     private lateinit var rbPeriodMode: RadioButton
-    private lateinit var rgSpecialMode: RadioGroup
+    private lateinit var rbNormalMode: RadioButton
+    private lateinit var rbFixMode: RadioButton
     private lateinit var llSpecialList: LinearLayout
     private lateinit var llFixMode: LinearLayout
     private lateinit var llSpecialMode: LinearLayout
@@ -41,6 +41,7 @@
     private var specialMode = false
     private var tmpPwd = ""
     private var configMode = ConfigMode.NORMAL_FIX
+    private val MAX_CHILD_COUNT = 6
 
 
     override fun onCreate(savedInstanceState: Bundle?) {
@@ -58,42 +59,74 @@
         vPayamt = findViewById<TextView>(R.id.tv_consume_mode_payamt)
         llSpecialList = findViewById<LinearLayout>(R.id.ll_special_list)
         this.findViewById<TextView>(R.id.tv_hot_add).setOnClickListener {
-            if (llSpecialList.childCount >= 9) {
+            if (!shoppwdPass) {
+                return@setOnClickListener
+            }
+            if (llSpecialList.childCount >= MAX_CHILD_COUNT) {
+                SWToast.show(
+                    applicationContext,
+                    "最大支持${MAX_CHILD_COUNT}条规则",
+                    PublicDef.TOAST_SHOW_DOUBT
+                )
                 return@setOnClickListener
             }
             if (configMode == ConfigMode.PERIOD_FIX) {
                 addPeriodFixRule()
-            } else {
+            } else if (configMode == ConfigMode.HOT_KEY) {
                 addHotkeyRule()
             }
         }
-        this.findViewById<TextView>(R.id.tv_hot_save).setOnClickListener {
-            if (llSpecialList.childCount == 0) {
-                SWToast.show(applicationContext, "请先添加规则", PublicDef.TOAST_SHOW_DOUBT)
+        this.findViewById<TextView>(R.id.tv_save).setOnClickListener {
+            if (!shoppwdPass) {
                 return@setOnClickListener
             }
-            if (configMode == ConfigMode.PERIOD_FIX) {
-                if (!savePeriodFixRule()) {
-                    return@setOnClickListener
+            when (configMode) {
+                ConfigMode.PERIOD_FIX -> {
+                    if (llSpecialList.childCount == 0) {
+                        SWToast.show(applicationContext, "请先添加波段规则", PublicDef.TOAST_SHOW_DOUBT)
+                        return@setOnClickListener
+                    }
+                    if (!savePeriodFixRule()) {
+                        return@setOnClickListener
+                    }
                 }
-            } else {
-                if (!saveHotkeyRule()) {
-                    return@setOnClickListener
+                ConfigMode.HOT_KEY -> {
+                    if (llSpecialList.childCount == 0) {
+                        SWToast.show(applicationContext, "请先添加热键规则", PublicDef.TOAST_SHOW_DOUBT)
+                        return@setOnClickListener
+                    }
+                    if (!saveHotkeyRule()) {
+                        return@setOnClickListener
+                    }
+                }
+                ConfigMode.NORMAL_FIX -> {
+                    pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, getFixAmount())
+                }
+                ConfigMode.NORMAL -> {
+                    pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.NORMAL.desc)
                 }
             }
             finish()
         }
         this.findViewById<TextView>(R.id.tv_return).setOnClickListener {
-            showCurrentMode(ConfigMode.NORMAL_FIX)
-            refreshToSetAmount()
+            //showCurrentMode(ConfigMode.NORMAL_FIX)
+            //refreshToSetAmount()
+            finish()
         }
-        rgSpecialMode = this.findViewById<RadioGroup>(R.id.rg_special_mode)
-        rgSpecialMode.setOnCheckedChangeListener { _, checkedId ->
-            when (checkedId) {
-                R.id.rb_hot_mode -> showCurrentMode(ConfigMode.HOT_KEY)
-                R.id.rb_period_fix_mode -> showCurrentMode(ConfigMode.PERIOD_FIX)
+        this.findViewById<RadioGroup>(R.id.rg_special_mode)
+            .setOnCheckedChangeListener { _, checkedId ->
+                if (!shoppwdPass) {
+                    return@setOnCheckedChangeListener
+                }
+                when (checkedId) {
+                    R.id.rb_normal -> showCurrentMode(ConfigMode.NORMAL)
+                    R.id.rb_normal_fix -> showCurrentMode(ConfigMode.NORMAL_FIX)
+                    R.id.rb_hot_mode -> showCurrentMode(ConfigMode.HOT_KEY)
+                    R.id.rb_period_fix_mode -> showCurrentMode(ConfigMode.PERIOD_FIX)
+                }
             }
-        }
+        rbNormalMode = this.findViewById<RadioButton>(R.id.rb_normal)
+        rbFixMode = this.findViewById<RadioButton>(R.id.rb_normal_fix)
         rbPeriodMode = this.findViewById<RadioButton>(R.id.rb_period_fix_mode)
         rbHotkeyMode = this.findViewById<RadioButton>(R.id.rb_hot_mode)
 
@@ -141,7 +174,8 @@
             var temp = item.findViewById<TextView>(R.id.tv_hot_key)
             record.key = Integer.parseInt(temp.text.toString())
             temp = item.findViewById<EditText>(R.id.tv_hot_amount)
-            record.amount = CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
+            record.amount =
+                CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
             list.add(record)
         }
         pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, PayMode.HOTKEY.desc)
@@ -157,10 +191,12 @@
         for (loop in 0 until llSpecialList.childCount) {
             val record = PeriodFixPayRecord()
             val item = llSpecialList.getChildAt(loop)
-            record.beginTime = CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_start))
+            record.beginTime =
+                CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_start))
             record.endTime = CommonUtil.getEditView(item.findViewById<EditText>(R.id.tv_period_end))
             val temp = item.findViewById<EditText>(R.id.tv_amount)
-            record.amount = CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
+            record.amount =
+                CommonUtil.YuanToFen(java.lang.Double.parseDouble(CommonUtil.getEditView(temp)))
             if (TextUtils.isEmpty(record.beginTime) || TextUtils.isEmpty(record.endTime)) {
                 SWToast.show(applicationContext, "时间段不为空", PublicDef.TOAST_SHOW_CRY)
                 return false
@@ -257,7 +293,6 @@
         when (mode) {
             ConfigMode.HOT_KEY -> {
                 specialMode = true
-                rgSpecialMode.visibility = View.VISIBLE
                 rbHotkeyMode.isChecked = true
                 llFixMode.visibility = View.GONE
                 llSpecialMode.visibility = View.VISIBLE
@@ -267,14 +302,19 @@
             ConfigMode.PERIOD_FIX -> {
                 specialMode = true
                 rbPeriodMode.isChecked = true
-                rgSpecialMode.visibility = View.VISIBLE
                 llFixMode.visibility = View.GONE
                 llSpecialMode.visibility = View.VISIBLE
                 vSpecialDesc.text = "设置波段定额(单位:元)"
                 loadPeriodFixRule()
             }
+            ConfigMode.NORMAL_FIX -> {
+                specialMode = false
+                rbFixMode.isChecked = true
+                llSpecialMode.visibility = View.GONE
+                llFixMode.visibility = View.VISIBLE
+            }
             else -> {
-                rgSpecialMode.visibility = View.GONE
+                rbNormalMode.isChecked = true
                 llSpecialMode.visibility = View.GONE
                 llFixMode.visibility = View.VISIBLE
                 specialMode = false
@@ -300,12 +340,18 @@
                         shoppwdPass = true
                         refreshToSetAmount()
                     } else {
-                        AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请输入商户密码:", "密码错误"))
+                        AuxScreenController.getInstance()
+                            .refreshContent(Arrays.asList<String>("请输入商户密码:", "密码错误"))
                     }
                     tmpPwd = ""
                 } else {
                     AuxScreenController.getInstance()
-                        .refreshContent(Arrays.asList("请输入商户密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+                        .refreshContent(
+                            Arrays.asList(
+                                "请输入商户密码:",
+                                CommonUtil.getPasswordStar(tmpPwd.length)
+                            )
+                        )
                 }
             }
             KeyEvent.KEYCODE_DEL -> {
@@ -315,12 +361,22 @@
                     len == 1 -> {
                         tmpPwd = ""
                         AuxScreenController.getInstance()
-                            .refreshContent(Arrays.asList("请输入商户密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+                            .refreshContent(
+                                Arrays.asList(
+                                    "请输入商户密码:",
+                                    CommonUtil.getPasswordStar(tmpPwd.length)
+                                )
+                            )
                     }
                     len > 1 -> {
                         tmpPwd = tmpPwd.substring(0, len - 1)
                         AuxScreenController.getInstance()
-                            .refreshContent(Arrays.asList("请输入商户密码:", CommonUtil.getPasswordStar(tmpPwd.length)))
+                            .refreshContent(
+                                Arrays.asList(
+                                    "请输入商户密码:",
+                                    CommonUtil.getPasswordStar(tmpPwd.length)
+                                )
+                            )
                     }
                     else -> finish()
                 }
@@ -353,7 +409,8 @@
             KeyEvent.KEYCODE_PERIOD -> addDotToEdit()
             KeyEvent.KEYCODE_ENTER -> {
                 pos.replaceControlPara(PublicDef.CONTROL_FIXAMT, getFixAmount())
-                jumpActivity(MenuActivity::class.java)
+//                jumpActivity(MenuActivity::class.java)
+                finish()
             }
             KeyEvent.KEYCODE_DPAD_LEFT -> {
                 //F1
@@ -379,14 +436,19 @@
                 }
                 PayMode.HOTKEY.desc == it.paraval -> {
                     showCurrentMode(ConfigMode.HOT_KEY)
-                    AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请到大屏设置"))
+                    AuxScreenController.getInstance()
+                        .refreshContent(Arrays.asList<String>("请到大屏设置"))
                     return
                 }
                 PayMode.PERIODFIX.desc == it.paraval -> {
                     showCurrentMode(ConfigMode.PERIOD_FIX)
-                    AuxScreenController.getInstance().refreshContent(Arrays.asList<String>("请到大屏设置"))
+                    AuxScreenController.getInstance()
+                        .refreshContent(Arrays.asList<String>("请到大屏设置"))
                     return
                 }
+                PayMode.NORMAL.desc == it.paraval -> {
+
+                }
             }
         } ?: screenShowAmt()
     }
@@ -468,7 +530,10 @@
         counter!!.start()
     }
 
-    private inner class ContinuePressTimer internal constructor(millisInFuture: Long, countDownInterval: Long) :
+    private inner class ContinuePressTimer internal constructor(
+        millisInFuture: Long,
+        countDownInterval: Long
+    ) :
         CountDownTimer(millisInFuture, countDownInterval) {
 
         override fun onTick(millisUntilFinished: Long) {
@@ -482,6 +547,7 @@
 }
 
 enum class ConfigMode {
+    NORMAL,
     NORMAL_FIX,
     HOT_KEY,
     PERIOD_FIX,
diff --git a/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt b/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
index 8765a41..008eeaf 100644
--- a/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
+++ b/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
@@ -2,14 +2,15 @@
 
 import android.text.TextUtils
 import okhttp3.*
+import okhttp3.MediaType.Companion.toMediaTypeOrNull
 import java.io.IOException
 import java.io.UnsupportedEncodingException
-import java.security.SecureRandom
+import java.security.*
 import java.security.cert.CertificateException
 import java.security.cert.X509Certificate
+import java.util.*
 import java.util.concurrent.TimeUnit
 import javax.net.ssl.*
-import com.supwisdom.okhttp.ICallBackok as ICallBack1
 
 /**
  ** create by zzq on 2019/7/24
@@ -33,13 +34,39 @@
 
     private var client: OkHttpClient? = null
     private var clientLong: OkHttpClient
-    private val JSON = MediaType.parse("application/json; charset=utf-8")
-    private val FORM_ENCODE = MediaType.parse("application/x-www-form-urlencoded;charset=utf-8")
+    private val JSON = "application/json; charset=utf-8".toMediaTypeOrNull()
+    private val FORM_ENCODE = "application/x-www-form-urlencoded;charset=utf-8".toMediaTypeOrNull()
     private var commTime = 5
     private var clientId: String? = null
     private var jwt: String? = null
+    private var sslSocketFactory: SSLSocketFactory? = null
+    private var trustManager: X509TrustManager? = null
 
     init {
+        try {
+            val trustManagerFactory =
+                TrustManagerFactory.getInstance(
+                    TrustManagerFactory.getDefaultAlgorithm()
+                )
+            trustManagerFactory.init(null as KeyStore?)
+            val trustManagers =
+                trustManagerFactory.trustManagers
+            check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) {
+                ("Unexpected default trust managers:"
+                        + Arrays.toString(trustManagers))
+            }
+            trustManager = trustManagers[0] as X509TrustManager
+            val sslContext = SSLContext.getInstance("TLS")
+            sslContext.init(null, arrayOf<TrustManager?>(trustManager), null)
+            sslSocketFactory = sslContext.socketFactory
+        } catch (e: NoSuchAlgorithmException) {
+            e.printStackTrace()
+        } catch (e: KeyManagementException) {
+            e.printStackTrace()
+        } catch (e: KeyStoreException) {
+            e.printStackTrace()
+        }
+
         client = OkHttpClient()
             .newBuilder()
             .retryOnConnectionFailure(false)
@@ -47,7 +74,7 @@
             .writeTimeout(1, TimeUnit.SECONDS)
             .connectTimeout(commTime.toLong(), TimeUnit.SECONDS)
             .hostnameVerifier(TrustAllHostnameVerifier())
-            .sslSocketFactory(createSSLSocketFactory()!!)
+            .sslSocketFactory(sslSocketFactory!!, trustManager!!)
             .build()
         clientLong = OkHttpClient()
             .newBuilder()
@@ -56,7 +83,7 @@
             .writeTimeout(1, TimeUnit.SECONDS)
             .connectTimeout(3, TimeUnit.SECONDS)
             .hostnameVerifier(TrustAllHostnameVerifier())
-            .sslSocketFactory(createSSLSocketFactory())
+            .sslSocketFactory(sslSocketFactory!!, trustManager!!)
             .build()
 
     }
@@ -71,7 +98,7 @@
                 .writeTimeout(1, TimeUnit.SECONDS)
                 .connectTimeout(commTime.toLong(), TimeUnit.SECONDS)
                 .hostnameVerifier(TrustAllHostnameVerifier())
-                .sslSocketFactory(createSSLSocketFactory())
+                .sslSocketFactory(sslSocketFactory!!, trustManager!!)
                 .build()
         }
     }
@@ -88,46 +115,20 @@
         }
     }
 
-    private class TrustAllCerts : X509TrustManager {
-        @Throws(CertificateException::class)
-        override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
-        }
-
-        @Throws(CertificateException::class)
-        override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
-        }
-
-        override fun getAcceptedIssuers(): Array<X509Certificate> {
-            return arrayOf<X509Certificate>()
-        }
-    }
-
     private class TrustAllHostnameVerifier : HostnameVerifier {
         override fun verify(hostname: String, session: SSLSession): Boolean {
             return true
         }
     }
 
-    private fun createSSLSocketFactory(): SSLSocketFactory? {
-        var ssfFactory: SSLSocketFactory? = null
-        try {
-            val sc = SSLContext.getInstance("TLS")
-            sc.init(null, arrayOf<TrustManager>(TrustAllCerts()), SecureRandom())
-            ssfFactory = sc.socketFactory
-        } catch (e: Exception) {
-        }
-
-        return ssfFactory
-    }
-
     private fun addExtentHeader(request: Request.Builder): Request.Builder {
         request.addHeader("Accept", "application/json; q=0.5")
             .addHeader("Connection", "close")
         if (!TextUtils.isEmpty(clientId)) {
-            request.addHeader("X-TENANT-ID", clientId)
+            request.addHeader("X-TENANT-ID", clientId!!)
         }
         if (!TextUtils.isEmpty(jwt)) {
-            request.addHeader("Authorization", jwt)
+            request.addHeader("Authorization", jwt!!)
         }
         return request
     }
@@ -148,8 +149,8 @@
 
             override fun onResponse(call: Call, response: Response) {
                 try {
-                    val content = response.body()!!.string()
-                    val resp = TransResp(response.code(), response.message())
+                    val content = response.body!!.string()
+                    val resp = TransResp(response.code, response.message)
                     if (response.isSuccessful) {
                         resp.retjson = content
                     }
@@ -205,8 +206,8 @@
 
             override fun onResponse(call: Call, response: Response) {
                 try {
-                    val content = response.body()!!.string()
-                    val resp = TransResp(response.code(), response.message())
+                    val content = response.body!!.string()
+                    val resp = TransResp(response.code, response.message)
                     if (response.isSuccessful) {
                         resp.retjson = content
                     }
@@ -223,8 +224,8 @@
         return try {
             val response = clientLong.newCall(request).execute()
             /*响应主体只能被消耗一次*/
-            val content = response.body()!!.string()
-            val resp = TransResp(response.code(), response.message())
+            val content = response.body!!.string()
+            val resp = TransResp(response.code, response.message)
             if (response.isSuccessful) {
                 resp.retjson = content
             }
@@ -240,8 +241,8 @@
         return try {
             val response = client!!.newCall(request).execute()
             /*响应主体只能被消耗一次*/
-            val content = response.body()!!.string()
-            val resp = TransResp(response.code(), response.message())
+            val content = response.body!!.string()
+            val resp = TransResp(response.code, response.message)
             if (response.isSuccessful) {
                 resp.retjson = content
             }
diff --git a/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt b/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt
index 4405f38..3eb31d2 100644
--- a/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt
+++ b/app/src/main/java/com/supwisdom/service/BackgroundTaskService.kt
@@ -85,8 +85,11 @@
     }
 
     private fun refreshJwt() {
-        val jwtExpire = pos.getDynamicPara()?.jwtExpire ?: "0"
-        if (jwtExpire < DateUtil.getNowDateTimeNoFormat()) {
+        val dyRecord = pos.getDynamicPara()
+        val jwtExpire = dyRecord!!.jwtExpire ?: "0"
+        if (jwtExpire < DateUtil.getNowDateTimeNoFormat() ||
+            dyRecord.jwt == null
+        ) {
             autoAuth()
         } else {
             AuthEpay().refresh()
@@ -106,7 +109,7 @@
     }
 
     private fun clearTransdtl() {
-        val date = DateUtil.getDayDateNoFormatBefore(100)
+        val date = DateUtil.getDayDateNoFormatBefore(180)
         if (date == transdtlClearDate) {
             /*每天清除流水一次*/
             return
@@ -118,7 +121,7 @@
 
         /*删除15天前的日志*/
         FileUtil.removeLogFile(15)
-        FileUtil.removeCrashFile(15)
+        FileUtil.removeCrashFile(30)
         FileUtil.removeDtlFile(15)
     }
 }
\ No newline at end of file
diff --git a/app/src/main/java/com/supwisdom/service/EpayApiImpl.kt b/app/src/main/java/com/supwisdom/service/EpayApiImpl.kt
index b198613..06e9154 100644
--- a/app/src/main/java/com/supwisdom/service/EpayApiImpl.kt
+++ b/app/src/main/java/com/supwisdom/service/EpayApiImpl.kt
@@ -38,6 +38,11 @@
         val resp = YktSession.getInstance().sendYktRequestPost("/api/pos/heartbeat", "", params)
             ?: throw HeartBeatError("请求超时")
         if (resp.retcode != HttpStatus.SC_OK) {
+            if (resp.retcode == HttpStatus.SC_UNAUTHORIZED) {
+                /**防止后台重启,终端需要及时更新JWT**/
+                dyRecord.jwt = null
+                pos.replaceDynamicPara(dyRecord)
+            }
             throw HeartBeatError("错误码=${resp.retcode}")
         }
         val retBean = try {
diff --git a/app/src/main/res/layout/activity_consume_mode.xml b/app/src/main/res/layout/activity_consume_mode.xml
index befd0cf..84fae2b 100644
--- a/app/src/main/res/layout/activity_consume_mode.xml
+++ b/app/src/main/res/layout/activity_consume_mode.xml
@@ -1,47 +1,87 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              style="@style/head_title_out_style">
+        style="@style/head_title_out_style">
 
     <LinearLayout style="@style/head_title_inner_style">
 
         <TextView
                 style="@style/head_title_text_style"
-                android:text="消费模式"/>
+                android:text="消费模式" />
+
         <RadioGroup
                 android:id="@+id/rg_special_mode"
-                android:visibility="gone"
-                android:layout_height="wrap_content"
-                android:weightSum="2"
                 android:layout_width="match_parent"
-                android:orientation="horizontal">
+                android:layout_height="wrap_content"
+                android:orientation="vertical"
+                android:visibility="visible">
+
+            <RadioButton
+                    android:id="@+id/rb_normal"
+                    style="@style/consume_mode_rb_style"
+                    android:text="普通消费" />
+
+            <RadioButton
+                    android:id="@+id/rb_normal_fix"
+                    style="@style/consume_mode_rb_style"
+                    android:text="定额消费" />
+
             <RadioButton
                     android:id="@+id/rb_hot_mode"
-                    android:text="按键便捷消费"
-                    style="@style/consume_mode_rb_style"/>
+                    style="@style/consume_mode_rb_style"
+                    android:text="按键便捷消费" />
+
             <RadioButton
                     android:id="@+id/rb_period_fix_mode"
-                    android:text="波段定额消费"
-                    style="@style/consume_mode_rb_style"/>
+                    style="@style/consume_mode_rb_style"
+                    android:text="波段定额消费" />
         </RadioGroup>
+
+        <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="center"
+                android:orientation="horizontal"
+                android:padding="10dp">
+
+            <TextView
+                    android:id="@+id/tv_return"
+                    style="@style/consume_mode_save_style"
+                    android:text="返回" />
+
+            <TextView
+                    android:id="@+id/tv_save"
+                    style="@style/consume_mode_save_style"
+                    android:layout_marginStart="80dp"
+                    android:text="保存" />
+
+            <TextView
+                    android:id="@+id/tv_hot_add"
+                    style="@style/consume_mode_save_style"
+                    android:layout_marginStart="80dp"
+                    android:text="添加" />
+        </LinearLayout>
+
         <LinearLayout
                 android:id="@+id/ll_fix_mode"
-                android:visibility="gone"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
                 android:orientation="vertical"
                 android:padding="10dp"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent">
+                android:visibility="gone">
+
             <TextView
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:text="普通消费(none)"
                     android:textColor="@color/light_blue2"
-                    android:textSize="20sp"/>
+                    android:textSize="20sp" />
+
             <TextView
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:text="定额消费(单位:元)"
                     android:textColor="@color/light_blue2"
-                    android:textSize="20sp"/>
+                    android:textSize="20sp" />
 
             <LinearLayout
                     android:layout_width="match_parent"
@@ -53,7 +93,7 @@
                         android:layout_height="wrap_content"
                         android:text="金额: "
                         android:textColor="@color/light_blue2"
-                        android:textSize="30sp"/>
+                        android:textSize="30sp" />
 
                 <TextView
                         android:id="@+id/tv_consume_mode_payamt"
@@ -62,63 +102,31 @@
                         android:maxLength="8"
                         android:text="0"
                         android:textColor="@color/light_blue2"
-                        android:textSize="30sp"/>
+                        android:textSize="30sp" />
             </LinearLayout>
         </LinearLayout>
+
         <LinearLayout
                 android:id="@+id/ll_hot_mode"
-                android:orientation="vertical"
-                android:padding="10dp"
                 android:layout_width="match_parent"
-                android:layout_height="match_parent">
-            <LinearLayout
-                    android:orientation="horizontal"
-                    android:gravity="center"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content">
-                <TextView
-                        android:id="@+id/tv_return"
-                        android:textSize="25sp"
-                        android:text="返回"
-                        android:background="@drawable/corner_bg_blue"
-                        android:padding="10dp"
-                        android:textColor="@color/white"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"/>
-                <TextView
-                        android:id="@+id/tv_hot_save"
-                        android:textSize="25sp"
-                        android:layout_marginStart="50dp"
-                        android:text="保存"
-                        android:background="@drawable/corner_bg_blue"
-                        android:padding="10dp"
-                        android:textColor="@color/white"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"/>
-                <TextView
-                        android:id="@+id/tv_hot_add"
-                        android:textSize="25sp"
-                        android:text="添加"
-                        android:layout_marginStart="50dp"
-                        android:background="@drawable/corner_bg_blue"
-                        android:padding="10dp"
-                        android:textColor="@color/white"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"/>
-            </LinearLayout>
+                android:layout_height="match_parent"
+                android:orientation="vertical"
+                android:padding="10dp">
+
             <TextView
                     android:id="@+id/tv_special_desc"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:text="快捷消费(单位:元)"
                     android:layout_marginTop="10dp"
+                    android:text="快捷消费(单位:元)"
                     android:textColor="@color/light_blue2"
-                    android:textSize="20sp"/>
+                    android:textSize="20sp" />
+
             <LinearLayout
                     android:id="@+id/ll_special_list"
                     android:layout_width="match_parent"
-                    android:orientation="vertical"
-                    android:layout_height="match_parent"/>
+                    android:layout_height="match_parent"
+                    android:orientation="vertical" />
         </LinearLayout>
     </LinearLayout>
 </LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index a1088c5..1133656 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -428,11 +428,20 @@
     </style>
     <style name="consume_mode_rb_style">
         <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_width">0dp</item>
-        <item name="android:layout_weight">1</item>
+        <item name="android:layout_width">match_parent</item>
         <item name="android:textSize">25sp</item>
+        <item name="android:textStyle">bold</item>
         <item name="android:textColor">@color/light_blue2</item>
     </style>
+    <style name="consume_mode_save_style">
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:layout_width">wrap_content</item>
+        <item name="android:background">@drawable/corner_bg_blue</item>
+        <item name="android:padding">10dp</item>
+        <item name="android:textStyle">bold</item>
+        <item name="android:textSize">30sp</item>
+        <item name="android:textColor">@color/white</item>
+    </style>
     <style name="consume_pay_way_text_style">
         <item name="android:layout_height">wrap_content</item>
         <item name="android:layout_width">match_parent</item>
diff --git a/build.gradle b/build.gradle
index 3b61f16..fd516ef 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,14 +1,15 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 
 buildscript {
-    ext.kotlin_version = '1.3.31'
+    ext.kotlin_version = '1.3.21'
     repositories {
         google()
         jcenter()
-        
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.4.0'
+        classpath 'com.android.tools.build:gradle:3.4.2'
+        classpath 'me.tatarka:gradle-retrolambda:3.7.0'
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
@@ -17,9 +18,12 @@
 
 allprojects {
     repositories {
+        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
+        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
+        maven { url 'https://maven.google.com' }
         google()
         jcenter()
-        
+        mavenCentral()
     }
 }