[6.8.0]
[fea] [核销、未通知小程序]
This commit is contained in:
@@ -2,4 +2,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.mogo.och.shuttle.weaknet.passenger">
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
</manifest>
|
||||
@@ -1,9 +1,17 @@
|
||||
package com.mogo.och.shuttle.weaknet.passenger.model
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.eagle.core.utilcode.util.RegexUtils
|
||||
import com.mogo.och.common.module.manager.bluetooth.BleDevItem
|
||||
import com.mogo.och.common.module.manager.bluetooth.BleManager
|
||||
import com.mogo.och.common.module.manager.bluetooth.BleManager.BleDevListener
|
||||
import com.mogo.och.common.module.manager.bluetooth.OchBluetoothGattCallback.ConnectListener
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
|
||||
import com.mogo.och.common.module.manager.scnner.ScannerManager
|
||||
import com.mogo.och.common.module.manager.scnner.StateChangeListener
|
||||
@@ -11,31 +19,92 @@ import com.mogo.och.common.module.manager.socket.lan.ILanMessageListener
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.DPMsgType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.WriteOffDetialMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.WriteOffResultMsg
|
||||
import com.mogo.och.common.module.utils.RxUtils
|
||||
import java.net.URLDecoder
|
||||
|
||||
object TicketModel : StateChangeListener {
|
||||
|
||||
private const val TAG = "TicketModel"
|
||||
|
||||
// 等待链接
|
||||
private val waitConnectDev = mutableListOf<BleDevItem>()
|
||||
private val waitConnectDevNameList = mutableListOf<String>()
|
||||
|
||||
private val connectListener: ConnectListener = object : ConnectListener {
|
||||
override fun sendDataSuccessAndCloseListener(device: BluetoothDevice) {
|
||||
waitConnectDev.forEach {
|
||||
if(it.dev==device){
|
||||
waitConnectDev.remove(it)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
private val writeOffResultMsg = object : ILanMessageListener<WriteOffResultMsg> {
|
||||
override fun targetLan(): Class<WriteOffResultMsg> = WriteOffResultMsg::class.java
|
||||
|
||||
override fun onLanMsgReceived(obj: WriteOffResultMsg?) {
|
||||
// 收到核销结果扫描蓝牙并写会核销结果
|
||||
findDeviceConnectAndSendData(obj,1)
|
||||
}
|
||||
}
|
||||
@SuppressLint("MissingPermission")
|
||||
private fun findDeviceConnectAndSendData(obj: WriteOffResultMsg?,count:Int){
|
||||
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","去连接蓝牙并发送数据 次数:${count}")
|
||||
// 收到核销结果扫描蓝牙并写会核销结果
|
||||
obj?.phone?.let {phone->
|
||||
var haveDevices = false
|
||||
waitConnectDev.forEach {
|
||||
if(it.dev.name== getBleName(phone)){
|
||||
haveDevices = true
|
||||
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","找到设备")
|
||||
it.gattcallback.connectGatt()
|
||||
it.gattcallback.connectListener = connectListener
|
||||
}
|
||||
}
|
||||
if(!haveDevices&&count<6){
|
||||
RxUtils.createSubscribe {
|
||||
OchChainLogManager.writeChainLogWriteOff("司机端核销成功","2s后重试")
|
||||
findDeviceConnectAndSendData(obj,count+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val bleDevs = object : BleDevListener{
|
||||
@SuppressLint("MissingPermission")
|
||||
@Synchronized
|
||||
override fun dataChange(scanList: MutableList<BleDevItem>) {
|
||||
val tempList = mutableListOf<String>()
|
||||
waitConnectDevNameList.forEach { waitConnectName->
|
||||
scanList.forEach {
|
||||
if(it.dev.name==waitConnectName){
|
||||
waitConnectDev.add(it)
|
||||
tempList.add(waitConnectName)
|
||||
}
|
||||
}
|
||||
}
|
||||
waitConnectDevNameList.removeAll(tempList)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun load(){
|
||||
OchChainLogManager.writeChainLogInit("初始化信息","核销功能初始化")
|
||||
ScannerManager.addStateChangeListener(TAG, this)
|
||||
// 核销信息
|
||||
LanSocketManager.registerSocketMessageListener(DPMsgType.TYPE_WRITEOFF_INFO_RESULT.type,writeOffResultMsg)
|
||||
|
||||
BleManager.listener = bleDevs
|
||||
}
|
||||
fun release(){
|
||||
ScannerManager.removeListener(TAG)
|
||||
LanSocketManager.unRegisterSocketMessageListener(DPMsgType.TYPE_WRITEOFF_INFO_RESULT.type,writeOffResultMsg)
|
||||
BleManager.listener = null
|
||||
}
|
||||
|
||||
override fun parseData(params: MutableMap<String, String>, payload: String?) {
|
||||
@@ -43,7 +112,7 @@ object TicketModel : StateChangeListener {
|
||||
val bookingTime = params["bookingTime"]
|
||||
val businessType = params["businessType"]
|
||||
val lineId = params["lineId"]
|
||||
val remainingTimes = params["remainingTimes"]
|
||||
val availableTimes = params["availableTimes"]
|
||||
val orderNo = params["orderNo"]
|
||||
val uid = params["uid"]
|
||||
val phone = params["phone"]
|
||||
@@ -67,12 +136,12 @@ object TicketModel : StateChangeListener {
|
||||
bookingTime?.toLong()?:0,
|
||||
businessType?.toInt()?:0,
|
||||
lineId?.toLong()?:0,
|
||||
remainingTimes?.toInt()?:0,
|
||||
availableTimes?.toInt()?:0,
|
||||
orderNo,
|
||||
uid,
|
||||
phoneNum,
|
||||
ticketSize?.toInt()?:0,
|
||||
ticketName,
|
||||
URLDecoder.decode(ticketName,"UTF-8"),
|
||||
type,
|
||||
pipe,
|
||||
startStationId?.toLong()?:0,
|
||||
@@ -80,6 +149,8 @@ object TicketModel : StateChangeListener {
|
||||
)
|
||||
CallerLogger.d(M_BUS_P + TAG, "sendTaskDetailsToClients = " + GsonUtils.toJson(writeOffDetail))
|
||||
LanSocketManager.sendMsgToServer(writeOffDetail)
|
||||
addWaitConnectDevName(phone)
|
||||
scanBle()
|
||||
}catch (e:Exception){
|
||||
e.printStackTrace()
|
||||
CallerLogger.d(M_BUS_P + TAG, "")
|
||||
@@ -95,4 +166,32 @@ object TicketModel : StateChangeListener {
|
||||
LanSocketManager.sendMsgToServer(writeOffDetail)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addWaitConnectDevName(phone: String?) {
|
||||
var tempPhone = phone
|
||||
tempPhone?.let {
|
||||
waitConnectDevNameList.add( getBleName(it))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun getBleName(phone: String):String{
|
||||
var tempPhone = phone
|
||||
tempPhone.let {
|
||||
if (it.length > 8) {
|
||||
//截取电话号码前三位
|
||||
val phoneNumPre = it.substring(0, 3)
|
||||
//截取电话号码后四位
|
||||
val phoneNumFix = it.substring(7)
|
||||
tempPhone = "mogo${phoneNumPre}$phoneNumFix"
|
||||
}
|
||||
}
|
||||
return tempPhone
|
||||
}
|
||||
|
||||
private fun scanBle() {
|
||||
BizLoopManager.runInMainThread{
|
||||
BleManager.scanLeDevice()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user