12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556 |
- package xn.hxp.ui.warehousing
- import android.os.Bundle
- import android.os.CountDownTimer
- import android.os.Handler
- import android.os.Looper
- import android.view.KeyEvent
- import android.view.LayoutInflater
- import android.view.View
- import android.widget.EditText
- import android.widget.Toast
- import androidx.core.content.ContextCompat
- import androidx.lifecycle.lifecycleScope
- import androidx.recyclerview.widget.LinearLayoutManager
- import androidx.viewbinding.ViewBinding
- import com.blankj.utilcode.util.LogUtils
- import com.bumptech.glide.Glide
- import com.bumptech.glide.load.engine.DiskCacheStrategy
- import com.bumptech.glide.request.RequestOptions
- import com.rc.core.ui.activity.BaseActivity
- import com.rc.httpcore.HttpConfig
- import com.rc.httpcore.bean.*
- import com.rc.httpcore.client.ApiRepository
- import com.rc.httpcore.client.HttpTool
- import com.rc.httpcore.exception.NetException
- import com.sun.jna.Pointer
- import kotlinx.coroutines.*
- import retrofit2.HttpException
- import xn.hxp.R
- import xn.hxp.app.ChemicalApp
- import xn.hxp.blu.BluetoothConnectionManager
- import xn.hxp.comm.Constants
- import xn.hxp.databinding.ActivityWarehousingBinding
- import xn.hxp.ui.PrintBean
- import xn.hxp.ui.adapter.ChemicalsAdapter
- import xn.hxp.ui.adapter.InventoryListAdapter
- import xn.hxp.ui.verify.TwoVerificationActivity
- import xn.hxp.utils.*
- import xn.hxp.utils.bluetooth.BluetoothTool
- import xn.hxp.utils.bluetooth.BluetoothTool.BluetoothCallBack
- import xn.hxp.weidith.*
- import java.lang.Runnable
- import java.math.BigDecimal
- import java.net.ConnectException
- import java.net.SocketTimeoutException
- import java.nio.charset.StandardCharsets
- //待入库
- class WarehousingActivity : BaseActivity() {
- private val mAdapter by lazy { InventoryListAdapter(this) }
- private val mAdapterChemicals by lazy { ChemicalsAdapter(this) }
- private var mChemicalInfoBean: ChemicalInfoBean? = null //实验室信息
- private var mListData: List<RuleBean>? = null //柜子信息
- private var mLabelDialog: LabelDialog? = null //化学品信息生成
- // private var jobTow: Job? = null
- private var mWeighingValue: EditText? = null
- private var mStockModeBean = StockModeBean(mutableListOf())
- private var mStockModelList = mutableListOf<StockModel>()
- private lateinit var timeUpdater: TimeUpdater
- private var mWeighDialog: WeighDialog? = null
- private var mCabinetId = "" //柜子id
- private var mCabinetName = "" //柜子名称
- private var mDoorName = "" //柜门名称
- private var mDoorId: String = ""
- private lateinit var mUnifiedVerBean: UnifiedVerBean //当前是否需要双人认证
- private var mLayers = 1 //柜子层数
- private var mLayersTow = 1 //柜子选择层数
- private var mCabinetLockVoList: List<LockVoListBean>? = null //柜锁会又多个
- private var mLockStr = ArrayList<String>() // 需要打开得柜锁数量
- private val handlerUtil = HandlerUtil.getInstance()
- private var mJoinType = 1 //称重方式 1 称重,2 录入
- private var mPages = 1 //总页码
- private var mDataPage = -1 //返回得总条数
- private var page = 1
- private var pageSize = 10
- private var mPrintTag = 0 //需要打印得内容条数
- private var mStockDetailsModel: MutableList<StockDetailsModel>? = null
- private var mLayer: Int = -1
- private val handlerPrint = HandlerUtil.getInstance()
- private var h = Pointer.NULL
- private var pritBot = false
- private var isClisLit = false //是否点击称重关闭按钮
- // private lateinit var mChemicalConfsBean: ChemicalConfsBean //获取化学品的称重超过比例or
- lateinit var viewBinding: ActivityWarehousingBinding
- override fun setViewBinding(): ViewBinding {
- viewBinding = ActivityWarehousingBinding.inflate(layoutInflater)
- return viewBinding
- }
- override fun onInit() {
- initTitle()
- initAdapter()
- viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
- viewBinding.tvReturn.setOnClickListener {
- finish()
- }
- viewBinding.tvOutLogin.setOnClickListener {
- HttpTool.logout()
- }
- //查询后根据返回集合数量 判断当天的显示
- viewBinding.options.setOnClickListener {
- //类别获取
- getOptions()
- }
- viewBinding.reSou.setOnClickListener {
- page = 1
- waitList()
- }
- //选择柜子信息
- viewBinding.imgPosition.setOnClickListener {
- // mType = 1, 可以选择柜层
- val storageDialog =
- StorageDialog(ct = this,
- listData = mListData!!,
- lint = object : StorageDialog.IonClickListener {
- override fun onClick(
- cabinetId: String,
- cabinetName: String,
- doorName: String,
- doorId: String,
- cabinetLockVoList: List<LockVoListBean>,
- layers: Int,
- lockNum: String
- ) {
- mCabinetId = cabinetId
- mCabinetName = cabinetName
- mDoorName = doorName
- mDoorId = doorId
- mCabinetLockVoList = cabinetLockVoList
- viewBinding.cabinet.text = "存储位置:${cabinetName}-${doorName}"
- viewBinding.cabinet.tag = "$doorId"
- mLayers = layers //当前需要显示得层数
- if (mStockModelList != null && mStockModelList.size > 0) {
- mStockModelList.forEach {
- it.cabinetId = mCabinetId
- it.cabinetName = mCabinetName
- it.doorId = mDoorId
- it.doorName = mDoorName
- it.layers = mLayers
- }
- }
- //
- mAdapterChemicals.updateData(mLayers)
- }
- override fun onClose() {
- }
- })
- storageDialog.show()
- }
- viewBinding.butOpen.setOnClickListener {
- if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
- mLockStr.clear()
- mCabinetLockVoList!!.forEach { it ->
- when (it.unlockingMethod) {
- 2 -> { //智能锁
- mLockStr.add("${it.lockNum}")
- }
- }
- }
- if (mLockStr != null && mLockStr.size > 0) {
- openLock(mLockStr)
- } else {
- subAddData(0)
- }
- } else {
- subAddData(0)
- }
- }
- //待入库 确认入库
- // viewBinding.subAdd.setOnClickListener {
- ButtonDebouncer.setDebouncedOnClickListener(viewBinding.subAdd, 500L) {
- if (mAdapterChemicals.data.size > 0) {
- if (mUnifiedVerBean.verify) {
- //需要双人认证 1人脸 2刷卡 3扫码 获取基础信息配置
- if (ChemicalApp.confs!!.verifyType.length == 1) {
- val map = mutableMapOf<String, Any>()
- var chemicalLevel = 2
- val dataList = mAdapterChemicals.data
- dataList.forEach {
- if (it.chemicalLevel == 1) {
- chemicalLevel = it.chemicalLevel!!
- return@forEach
- }
- }
- map["chemicalLevel"] = chemicalLevel //管控类型
- map["doorId"] = "${viewBinding.cabinet.tag}" //柜子id
- map["mTag"] = 2
- when (ChemicalApp.confs!!.verifyType) {
- "1" -> {//人脸
- map["mVerTyps"] = 1
- }
- "2" -> {//刷卡
- map["mVerTyps"] = 2
- }
- "3" -> {//扫码
- map["mVerTyps"] = 3
- }
- }
- UiManager.switcher(
- this,
- map,
- TwoVerificationActivity::class.java
- )
- // map["hides"] = 4 //隐藏扫码
- // when (ChemicalApp.confs!!.verifyType) {
- // "1" -> {//人脸
- // UiManager.switcher(
- // this,
- // map,
- // TwoPersonActivity::class.java,
- // Constants.REQUEST_CODE
- // )
- // }
- //
- // "2" -> {//刷卡
- // UiManager.switcher(
- // this,
- // map,
- // SwipeCodeTwoActivity::class.java,
- // Constants.REQUEST_CODE
- // )
- //
- // }
- // "3" -> {//扫码
- // UiManager.switcher(
- // this,
- // map,
- // ScanCodeTwoActivity::class.java,
- // Constants.REQUEST_CODE
- // )
- // }
- // }
- } else {
- verifyChecking()
- }
- } else {
- if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
- mLockStr.clear()
- mCabinetLockVoList!!.forEach { it ->
- when (it.unlockingMethod) {
- 2 -> { //智能锁
- mLockStr.add("${it.lockNum}")
- }
- }
- }
- if (mLockStr != null && mLockStr.size > 0) {
- openLock(mLockStr)
- } else {
- subAddData(0)
- }
- } else {
- subAddData(0)
- }
- }
- } else {
- showToast("缺少录入信息")
- }
- }
- viewBinding.butUpper.setOnClickListener {
- //上一页
- if (mDataPage != 0) {
- if (page != 1) {
- page--
- getRelList() //刷新页面
- }
- }
- }
- viewBinding.butNext.setOnClickListener {
- //下一页
- if (mDataPage != 0) {
- if (mDataPage != page) {
- page++
- getRelList() //刷新页面
- }
- }
- }
- val handler = Handler(Looper.getMainLooper())
- timeUpdater = TimeUpdater(handler) { currentTime ->
- viewBinding.nowTime.text = "$currentTime"
- }
- // 启动定时更新
- timeUpdater.startUpdating()
- getRelList()//获取实验室 信息
- }
- //验证方式
- private fun verifyChecking() {
- val map = mutableMapOf<String, Any>()
- var chemicalLevel = 2
- val dataList = mAdapterChemicals.data
- dataList.forEach {
- if (it.chemicalLevel == 1) {
- chemicalLevel = it.chemicalLevel!!
- return@forEach
- }
- }
- map["chemicalLevel"] = chemicalLevel //管控类型
- map["doorId"] = "${viewBinding.cabinet.tag}" //柜子id
- map["mTag"] = 2
- map["mVerTyps"] = 0
- if (ChemicalApp.confs!!.verifyType == "1,2" || ChemicalApp.confs!!.verifyType == "2,1") {
- //人脸+刷卡
- map["hides"] = 1 //隐藏扫码
- // UiManager.switcher(this, map, TwoPersonActivity::class.java)
- } else if (ChemicalApp.confs!!.verifyType == "1,3" || ChemicalApp.confs!!.verifyType == "3,1") {
- //人脸+扫码
- map["hides"] = 2 //隐藏刷卡
- // UiManager.switcher(this, map, TwoPersonActivity::class.java)
- } else if (ChemicalApp.confs!!.verifyType == "2,3" || ChemicalApp.confs!!.verifyType == "3,2") {
- map["hides"] = 3 //隐藏扫码
- // UiManager.switcher(this, map, SwipeCodeTwoActivity::class.java)
- } else {
- //人脸+刷卡+扫码
- map["hides"] = 4
- // UiManager.switcher(this, map, TwoPersonActivity::class.java)
- }
- UiManager.switcher(
- this,
- map,
- TwoVerificationActivity::class.java,
- Constants.REQUEST_CODE
- )
- }
- private fun initTitle() {
- viewBinding.tvName.text = ChemicalApp.userData!!.userName
- val imageView = viewBinding.imageName
- // 使用 Glide 加载网络图片
- Glide.with(this)
- .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.userData!!.avatar}")
- .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
- .into(imageView)
- // 使用 Glide 加载网络图片
- viewBinding.deptName.text = "${ChemicalApp.confs!!.deptName}-${ChemicalApp.confs!!.roomNum}"
- Glide.with(this)
- .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.circularLogo}")
- .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
- .into(viewBinding.image)
- }
- override fun onBackPressed() {
- super.onBackPressed()
- finish()
- }
- override fun cdTime(cd: Int) {
- viewBinding.tvReturn.text = "返回${cd}s"
- }
- private fun initAdapter() {
- //入库列表信息
- viewBinding.rvInventory?.layoutManager = LinearLayoutManager(this)
- viewBinding.rvInventory?.adapter = mAdapter
- //待入库清单
- viewBinding.recyclerViewList?.layoutManager = LinearLayoutManager(this)
- viewBinding.recyclerViewList?.adapter = mAdapterChemicals
- mAdapterChemicals.setOnItemChildClickListener { adapter, view, position ->
- // 在这里处理子View的点击事件
- when (view.id) {
- R.id.imgDelete -> {
- mAdapterChemicals.data.removeAt(position)
- mStockModelList = mAdapterChemicals.data
- LogUtils.i("=======删除前${mStockModeBean.stockModelList.size}")
- mStockModeBean.stockModelList = mStockModelList
- if (mAdapterChemicals.data.size == 0) {
- viewBinding.imgPosition.visibility = View.VISIBLE
- }
- LogUtils.i("=======删除后${mStockModeBean.stockModelList.size}")
- mAdapterChemicals.notifyItemRemoved(position)
- }
- }
- }
- //列表信息点击
- mAdapter.setOnItemClickListener { adapter, view, position ->
- mAdapter.data.forEach { it.isType = false }
- mAdapter.data[position].isType = true
- mAdapter.notifyDataSetChanged()
- getStockWait(mAdapter.data[position].waitId, mAdapter.data[position])
- }
- }
- private fun getStockWait(waitId: String, hxpStockWaitListBean: HxpStockWaitListBean) {
- showLoading("查询中...")
- val disposable = ApiRepository.getStockWaitDetails(waitId)
- .subscribe({ data ->
- dismissLoading()
- mUnifiedVerBean = data
- //当前需要生成的化学品信息
- modelA = hxpStockWaitListBean
- putDateInfo()
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- private fun subAddData(types: Int) {
- try {// 从 SharedPreferences 中取出集合
- val retrievedList =
- SharedPreferencesHelper.getList(this@WarehousingActivity)
- if (retrievedList != null && retrievedList.size > 0) {
- SharedPreferencesHelper.clearList(this@WarehousingActivity)
- }
- } catch (e: Exception) {
- }
- showLoading("入库中...")
- val disposable = ApiRepository.stockWaitAdd(mStockModeBean)
- .subscribe({ data ->
- dismissLoading()
- if (types == 0) {
- MediaPlayerHelper.playRawMp3(this, R.raw.qingjianghuaxuekaimen)
- customDialogView(1, "请将化学品放入化学品柜")
- } else {
- MediaPlayerHelper.playRawMp3(this, R.raw.guimenyikai)
- customDialogView(1, "柜门已开,请将化学品放入化学品柜")
- }
- mAdapterChemicals.data.clear()
- mStockModelList.clear()
- viewBinding.lintView.visibility = View.VISIBLE
- viewBinding.imgPosition.visibility = View.VISIBLE
- mAdapterChemicals.notifyDataSetChanged()
- getRelList() //刷新页面
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- private var modelA: HxpStockWaitListBean? = null
- private var mHandler: Handler = Handler(Looper.getMainLooper())
- private fun putDateInfo() {
- // val netContent = modelA!!.chemicalDensity * modelA!!.normsNum // 净量 = 密度*规格
- var density = "${modelA!!.normsNum}${modelA!!.normsUnit}/${modelA!!.applyUnit}"
- mLabelDialog =
- LabelDialog(
- this,
- "${modelA!!.applyNum.subtract(BigDecimal(modelA!!.stockNum!!))}",
- mLayers,
- density,
- modelA!!.chemicalName,
- object : LabelDialog.IRfidClick {
- override fun onItemClick(
- modelList: MutableList<StockDetailsModel>?,
- layer: Int
- ) {
- mStockDetailsModel = modelList
- mLayersTow = layer
- if (modelList == null) {
- //取消
- } else {
- //确定 链接蓝牙
- mWeighDialog = WeighDialog(this@WarehousingActivity, density,
- object : WeighDialog.IViewLint {
- override fun weighingView(weighingValue: EditText) {
- // showLoading("蓝牙连接中...")
- mWeighingValue = weighingValue
- LogUtils.i("========${mWeighingValue!!.isEnabled}")
- if (mWeighingValue!!.isEnabled) {
- // EditText允许输入
- // 在这里执行相应的操作
- weiView()
- } else {
- // EditText禁止输入
- // 在这里执行相应的操作
- // connectToDeviceWithTimeout()
- isClisLit = false
- lifecycleScope.launch {
- connectToDeviceWithTimeout()
- }
- }
- mWeighingValue!!.setOnEditorActionListener { v, actionId, event ->
- if (event?.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER) {
- // 确认是否触发了"actionDone"
- true
- } else {
- closEnd()
- false
- }
- }
- }
- //关闭
- override fun viewCloses() {
- isClisLit = true
- closEndTwo()
- }
- override fun onMovement() {
- weiView()
- }
- override fun onTimerReply() {
- }
- })
- mWeighDialog!!.show()
- mHandler.postDelayed({
- }, 1000 * 60) // 60秒后关闭对话框
- }
- }
- override fun onPrint(
- tagCode: String,
- wxCode: String,
- rfidCode: String,
- position: Int
- ) {
- LogUtils.i("=======打印标记${mUnifiedVerBean.qrCodePrint} $position")
- getCheckRfids(rfidCode, tagCode, wxCode, position)
- }
- override fun opTageCode(data: MutableList<StockDetailsModel>, layer: Int) {
- if (mUnifiedVerBean.qrCodePrint) {
- showLoading("打印中,请稍等")
- mStockDetailsModel = data
- mLayer = layer
- mPrintTag = mStockDetailsModel!!.size
- handlerPrint.startTask(taskPrint, 3000)
- } else {
- //打印完成
- mLabelDialog!!.printingCom()
- }
- }
- })
- mLabelDialog!!.show()
- }
- private fun weiView() {
- showToast("请手动输入")
- mJoinType = 2
- mWeighingValue!!.isEnabled = true
- mWeighingValue!!.requestFocus()
- }
- private suspend fun connectToDeviceWithTimeout() {
- showToast("连接中...", Toast.LENGTH_SHORT)
- lifecycleScope.launch {
- val deviceAddress = withContext(Dispatchers.IO) {
- BluetoothConnectionManager.getDeviceAddress()
- }
- if (deviceAddress != null) {
- val socket = withContext(Dispatchers.IO) {
- BluetoothConnectionManager.connectToDevice(deviceAddress)
- }
- if (socket != null) {
- // 连接成功后的处理逻辑
- // 在这里使用返回的 BluetoothSocket 对象进行后续操作
- MediaPlayerHelper.playRawMp3(this@WarehousingActivity, R.raw.qing_zheng_zhong)
- // 连接成功后的处理逻辑
- withContext(Dispatchers.Main) {
- do {
- // try {
- val inputStream = socket!!.inputStream
- val bt = ByteArray(1024)
- val content = inputStream!!.read(bt)
- if (content != null && content > 0) {
- val contents = String(
- bt,
- 0,
- content,
- StandardCharsets.UTF_8
- )
- val split = contents.split("\n")
- val weight = split[0].trim()
- LogUtils.i("===================称重未处理之前=======$contents")
- LogUtils.i("===================weight=======$weight")
- LogUtils.i("=====称重数据$weight $taskStarted ${mWeighingValue!!.text.toString()}")
- if (weight.toDouble() > 2999) {
- turnOffWeighing()
- } else {
- if (weight.toDouble() > 0) {
- if (mWeighingValue!!.text.toString().trim()
- .isNotEmpty()
- ) {
- if (weight.toDouble() == mWeighingValue!!.text.toString()
- .trim().toDouble()
- ) {
- if (taskStarted == false) {
- taskStarted = true
- LogUtils.i("=====执行了")
- socket.close()
- delayedTaskToUpdateUI()
- break
- }
- }
- }
- mWeighingValue!!.setText("$weight")
- } else {
- mWeighingValue!!.setText("")
- }
- }
- delay(200)
- } else {
- // jobTow?.cancel()
- showToast("请手动输入")
- weiView()
- break
- }
- // } catch (e: Exception) {
- // jobTow?.cancel()
- // weiView()
- // break
- // }
- } while (mWeighDialog != null && mWeighDialog!!.isShowing)
- }
- } else {
- // 连接失败的处理逻辑
- showToast("连接失败或超时", Toast.LENGTH_SHORT)
- weiView()
- }
- } else {
- // 根据设备名称获取的设备地址为空,处理无法找到设备的情况
- showToast("找不到设备", Toast.LENGTH_SHORT)
- weiView()
- }
- }
- }
- private fun showToast(message: String, duration: Int) {
- Toast.makeText(this, message, duration).show()
- }
- private fun closEndTwo() {
- // jobTow?.cancel()
- mWeighDialog!!.dismiss()
- }
- private fun closEnd() {
- // jobTow?.cancel()
- mWeighDialog!!.dismiss()
- val weigh =
- mWeighingValue!!.text.toString().trim() //称重后的重量
- if (weigh.isEmpty()) {
- showToast("未称重")
- return
- }
- if (weigh.toDouble() <= 0) {
- showToast("当前重量有误")
- return
- }
- val netContent =
- modelA!!.chemicalDensity * modelA!!.normsNum // 净含量=密度*规格
- var belongId = ""
- var belongName = ""
- var belongType = 2
- if (modelA!!.topicGroup) {
- belongId = modelA!!.topicGroupId
- belongName = modelA!!.topicGroupName
- belongType = 1
- } else {
- belongId = modelA!!.applyUserId
- belongName = modelA!!.applyUserName
- }
- if (mListData != null && mListData!!.size == 0) {
- showToast("化学品柜 未到找")
- return
- }
- var model = StockModel(
- belongId,
- belongName,
- belongType, //死值
- modelA!!.buildId,
- modelA!!.buildName,
- mCabinetId, //柜子信息
- mCabinetName,
- modelA!!.casNum,
- modelA!!.chemicalCategory.toInt(),
- modelA!!.chemicalId, //化学品id
- modelA!!.chemicalLevel,
- modelA!!.chemicalName,
- "${mStockDetailsModel!!.size}",
- modelA!!.chemicalPurity,
- modelA!!.deptId,
- modelA!!.deptName,
- viewBinding.cabinet.tag.toString(),
- mDoorName,
- modelA!!.factory,
- modelA!!.floorId,
- modelA!!.floorName,
- true, //11
- mJoinType, //入库方式1 称重,2 录入
- "", //视频地址
- mLayersTow, //当前选择得
- mLayers, //一共几层
- modelA!!.applyNum,
- modelA!!.applyUnit,
- modelA!!.normsNum,
- modelA!!.normsUnit,
- mStockDetailsModel, //每一条信息
- 2,
- modelA!!.subId,
- modelA!!.subName,
- modelA!!.roomNum,
- modelA!!.waitId,
- mWeighingValue!!.text.toString().toDouble(),
- netContent,
- expireTime = modelA!!.expireTime
- )
- verificationData(model)
- }
- //校验当前数据是否合理
- private fun verificationData(model: StockModel) {
- showLoading("查询中...")
- val disposable = ApiRepository.addStockCheck(model)
- .subscribe({ data ->
- dismissLoading()
- mStockModelList.add(model)
- mStockModeBean = StockModeBean(mStockModelList)
- //创建需要提交的数据源
- mAdapterChemicals.updateData(mLayers)
- //创建需要提交的数据源
- if (mAdapterChemicals.data != null && mAdapterChemicals.data.size > 0) {
- mAdapterChemicals.setList(mStockModelList)
- } else {
- viewBinding.lintView.visibility = View.GONE
- mAdapterChemicals.setNewInstance(mStockModelList.toMutableList())
- }
- viewBinding.imgPosition.visibility = View.GONE
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- // private fun getControlConfigs(chemicalNumber: String) {
- // showLoading("提交中...")
- // val disposable = ApiRepository.controlConfigs(modelA.chemicalLevel)
- // .subscribe({ data ->
- // dismissLoading()
- // mChemicalConfsBean = data
- // }, { throwable ->
- // showNetError(throwable)
- // dismissLoading()
- // })
- // addDisposable(disposable)
- // }
- private fun getCheckRfids(
- rfid: String,
- tagCode: String,
- wxCode: String,
- position: Int
- ) {
- showLoading("查询标签...")
- val disposable = ApiRepository.checkRfids(rfid)
- .subscribe({ data ->
- dismissLoading()
- LogUtils.i("===========查询成功$data")
- if (data) {
- customDialogView(2, "rfid标签不能重复,请重新扫描")
- mLabelDialog!!.getRfidTag(position)
- } else {
- if (mUnifiedVerBean.qrCodePrint) {
- //需要打印
- val print = PrintBean()
- print.tag = tagCode //化学品编码
- print.wxCode = wxCode
- print.name = modelA!!.chemicalName!! //化学品名称
- if (modelA!!.casNum != null) {
- print.casNo = modelA!!.casNum!! //cas号
- } else {
- print.casNo = ""
- }
- if (modelA!!.topicGroup) {
- print.person = modelA!!.topicGroupName //归属人
- } else {
- print.person = modelA!!.applyUserName //归属人
- }
- //管控 1 非管控 2
- if (modelA!!.chemicalLevel == 1) {
- print.level = "管控"
- } else {
- print.level = "非管控"
- }
- //
- print.types = "${modelA!!.chemicalCategoryName}"
- PrintTool.INSTANCE.print(!modelA!!.topicGroup, print)
- }
- }
- }, { throwable ->
- showNetError(throwable)
- mLabelDialog!!.getRfidTag(position)
- dismissLoading()
- })
- addDisposable(disposable)
- }
- private
- val taskPrint = Runnable {
- if (mPrintTag == 0) {
- //全部打印完成 关闭 并且调用下一步业务
- LogUtils.i("=====csd====打印完成$mPrintTag")
- dismissLoading()
- handlerPrint.stopAllTasks()
- //打印完成
- mLabelDialog!!.printingCom()
- } else {
- val print = PrintBean()
- print.tag = mStockDetailsModel!![mPrintTag - 1].tagCode!! //化学品编码
- print.wxCode = mStockDetailsModel!![mPrintTag - 1].wxCode!! //化学品编码
- print.name = modelA!!.chemicalName!! //化学品名称
- if (modelA!!.casNum != null) {
- print.casNo = modelA!!.casNum!! //cas号
- } else {
- print.casNo = ""
- }
- if (modelA!!.topicGroup) {
- print.person = modelA!!.topicGroupName //归属人
- } else {
- print.person = modelA!!.applyUserName //归属人
- }
- //管控 1 非管控 2
- if (modelA!!.chemicalLevel == 1) {
- print.level = "管控"
- } else {
- print.level = "非管控"
- }
- //
- print.types = "${modelA!!.chemicalCategoryName}"
- PrintTool.INSTANCE.print(!modelA!!.topicGroup, print)
- }
- mPrintTag--
- }
- //查询存储位置 默认第一个
- private fun getCabinet(subId: String) {
- showLoading("查询中...")
- val disposable = ApiRepository.getCabinetList(subId)
- .subscribe({ data ->
- dismissLoading()
- mListData = data
- viewBinding.cabinet.text =
- "存储位置:${mListData!![0].cabinetName}-${mListData!![0].cabinetDoorVoList[0].doorName}"
- viewBinding.cabinet.tag =
- "${mListData!![0].cabinetDoorVoList[0].doorUniqueId}"
- mCabinetId = mListData!![0].cabinetId
- mCabinetName = mListData!![0].cabinetName
- mDoorName = mListData!![0].cabinetDoorVoList[0].doorName
- mDoorId = mListData!![0].cabinetDoorVoList[0].doorUniqueId
- mCabinetLockVoList =
- mListData!![0].cabinetDoorVoList[0].cabinetLockVoList
- mLayers = mListData!![0].cabinetDoorVoList[0].doorLayers //当前柜子一共几层
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- var taskStarted = false
- // 声明一个全局的 Handler 变量
- private var mHandlerTime: Handler? = null
- // 在需要执行任务的地方调用这个函数
- private fun delayedTaskToUpdateUI() {
- // 初始化 Handler,并关联到主线程 Looper
- if (isClisLit == false) {
- mHandlerTime = Handler(Looper.getMainLooper())
- // 定义一个延迟执行的任务
- val updateUITask = Runnable {
- LogUtils.i("=====执行了")
- // 在这里执行更新 UI 的操作
- // 例如,更新 TextView 的文本
- // textView.text = "Updated text"
- closEnd()
- taskStarted = false
- // 执行完更新操作后,可以关闭 Handler
- mHandlerTime?.removeCallbacksAndMessages(null)
- mHandlerTime = null
- }
- // 延迟 3 秒执行任务
- mHandlerTime?.postDelayed(updateUITask, 3300)
- }
- }
- //超过量程
- private fun turnOffWeighing() {
- showToast("超过量程,手动输入")
- mJoinType = 2
- mWeighingValue!!.isEnabled = true
- }
- // 获取实验室基本信息
- private fun getRelList() {
- val disposable = ApiRepository.getRelList(ChemicalApp.subjectId!!)
- .subscribe({ data ->
- mChemicalInfoBean = data
- getCabinet(mChemicalInfoBean!!.subId)
- waitList()
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- //化学品/cas搜索
- private fun waitList() {
- val map = mutableMapOf<String, Any>()
- map["subId"] = mChemicalInfoBean!!.subId
- val searchValue = viewBinding.searchValue.text.toString() //输入内容
- if (searchValue.isNotEmpty()) {
- map["searchValue"] = searchValue
- }
- try {
- val tag = viewBinding.value.tag //类别id
- if (tag != null) {
- map["chemicalCategory"] = tag
- }
- } catch (e: Exception) {
- }
- map["page"] = page
- map["pageSize"] = pageSize
- showLoading("加载中...")
- val disposable =
- ApiRepository.waitList(map)
- .subscribe({ data ->
- dismissLoading()
- // current 当前页 pages 共计多少页
- mDataPage = data.pages //总页
- if (data.records != null && data.records.size == 0) {
- mAdapter.data.clear()
- mAdapter.notifyDataSetChanged()
- initPagesView(data.pages)
- }
- LogUtils.i("===条==${data.pages} ===条==${data.current}")
- if (data.pages != 0) {
- if (data.pages > 1 && data.current > 1) {
- //当前需要更新页码
- upPagesView(data.pages, data.current)
- mAdapter.setList(data.records.toMutableList())
- } else {
- mAdapter.setNewInstance(data.records.toMutableList())
- initPagesView(data.pages)
- }
- }
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- /**
- * 总页码 当前页 初始化
- */
- private fun initPagesView(pages: Int) {
- mPages = pages
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.one.setTextColor(ContextCompat.getColor(this, R.color.white))
- viewBinding.two.setTextColor(ContextCompat.getColor(this, R.color.black))
- when (pages) {
- 1 -> {
- viewBinding.one.visibility = View.VISIBLE
- }
- 2 -> {
- viewBinding.two.visibility = View.VISIBLE
- }
- 3 -> {
- viewBinding.two.visibility = View.VISIBLE
- viewBinding.three.visibility = View.VISIBLE
- }
- else -> {
- viewBinding.two.visibility = View.VISIBLE
- viewBinding.three.visibility = View.VISIBLE
- viewBinding.drop.visibility = View.VISIBLE
- viewBinding.many.visibility = View.VISIBLE
- viewBinding.many.text = "$pages"
- }
- }
- if (pages == 1 || pages == 0) {
- viewBinding.two.visibility = View.GONE
- viewBinding.three.visibility = View.GONE
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- if (pages < 4) {
- when (pages) {
- 1 -> {
- viewBinding.two.visibility = View.GONE
- viewBinding.three.visibility = View.GONE
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- 2 -> {
- viewBinding.three.visibility = View.GONE
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- 3 -> {
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- }
- }
- }
- //更新页码
- private fun upPagesView(pages: Int, current: Int) {
- LogUtils.i("======2")
- if (pages < 4) {
- // viewBinding.one.visibility = View.VISIBLE
- when (pages) {
- 1 -> {
- viewBinding.two.visibility = View.GONE
- viewBinding.three.visibility = View.GONE
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- 2 -> {
- viewBinding.three.visibility = View.GONE
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- 3 -> {
- viewBinding.many.visibility = View.GONE
- viewBinding.drop.visibility = View.GONE
- }
- }
- when (current) {
- 1 -> {
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- }
- 2 -> {
- // viewBinding.two.visibility = View.VISIBLE
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- }
- 3 -> {
- // viewBinding.three.visibility = View.VISIBLE
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
- }
- }
- } else {
- // viewBinding.many.visibility = View.VISIBLE
- viewBinding.three.text = "3"
- when (current) {
- 1 -> {
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- }
- 2 -> {
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- }
- 3 -> {
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
- }
- else -> {
- viewBinding.three.text = "$current"
- if (pages == current) {
- viewBinding.three.text = "${current - 1}"
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.many.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_page)
- } else {
- viewBinding.one.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.two.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.three.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.white
- )
- )
- viewBinding.many.setTextColor(
- ContextCompat.getColor(
- this,
- R.color.black
- )
- )
- viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
- viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
- }
- }
- }
- }
- }
- private fun getOptions() {
- showLoading("查询中...")
- val disposable = ApiRepository.getOptions("chemicals_category")
- .subscribe({ data ->
- dismissLoading()
- val chemDialog = ChemicalTypeDialog(
- this,
- data.toMutableList(),
- object : ChemicalTypeDialog.IonClickListener {
- override fun onClick(data: ChemicalTypeBean) {
- viewBinding.value.text = "${data.label}"
- viewBinding.value.tag = "${data.value}"
- }
- })
- if (!chemDialog.isShowing) {
- chemDialog.show()
- }
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- private fun openLock(mLockStr: ArrayList<String>) {
- val map = mutableMapOf<String, Any>()
- map["subId"] = ChemicalApp.subjectId!!
- map["subName"] = ChemicalApp.subjectName!!
- map["cabinetId"] = "$mCabinetId"
- map["cabinetName"] = "$mCabinetName"
- map["doorId"] = "$mDoorId"
- map["doorName"] = "$mDoorName"
- // map["lockNum"] = "$mLockNum"
- // map["lockNum"] = "guisuo001"
- map["lockNumList"] = mLockStr
- map["operationType"] = 2
- if (ChemicalApp.subRoom != null) {
- map["subRoom"] = ChemicalApp.subRoom!!
- }
- map["type"] = true
- try {// 从 SharedPreferences 中取出集合
- val retrievedList = SharedPreferencesHelper.getList(this)
- if (retrievedList != null && retrievedList.size > 0) {
- LogUtils.i("从本地取出得双人信息${retrievedList[0].name}")
- map["oneUserId"] = "${retrievedList[0].userId}"
- map["oneUserName"] = "${retrievedList[0].name}"
- map["twoUserId"] = "${retrievedList[1].userId}"
- map["twoUserName"] = "${retrievedList[1].name}"
- // 清空 SharedPreferences 中的集合
- // SharedPreferencesHelper.clearList(this)
- }
- } catch (e: Exception) {
- }
- showLoading("加载中...")
- val disposable = ApiRepository.lockOperate(map)
- .subscribe({ data ->
- dismissLoading()
- val containsFalse =
- mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
- if (containsFalse) {
- showLoading("查询中...")
- startCountdownLock()
- handlerUtil.startTask(task, 1000)
- } else {
- dismissLoading()
- //开锁成功
- subAddData(1)
- handlerUtil.stopAllTasks()
- countdownTimer?.cancel()
- }
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- private var countdownTimer: CountDownTimer? = null
- private fun startCountdownLock() {
- val totalTime = 30 * 1000 // 30秒
- val interval = 1000 // 每秒更新一次
- if (countdownTimer != null) {
- countdownTimer!!.cancel()
- }
- countdownTimer = object : CountDownTimer(totalTime.toLong(), interval.toLong()) {
- override fun onTick(millisUntilFinished: Long) {
- val secondsLeft = millisUntilFinished / 1000
- println("剩余时间: $secondsLeft 秒")
- }
- override fun onFinish() {
- println("倒计时结束!")
- // mCabinetLockVoList = null
- // mLockStr.clear()
- viewBinding.butOpen.visibility = View.VISIBLE
- showToast("开锁超时,可重新操作")
- dismissLoading()
- handlerUtil.stopAllTasks()
- // 在这里执行合适的操作,比如退出应用程序
- }
- }
- println("倒计时开始...")
- countdownTimer?.start()
- }
- override fun onResume() {
- super.onResume()
- try {
- if (Constants.AUTHENTICATION) {
- try {// 从 SharedPreferences 中取出集合
- val retrievedList =
- SharedPreferencesHelper.getList(this@WarehousingActivity)
- if (retrievedList != null && retrievedList.size > 0) {
- LogUtils.i("===a===${retrievedList[0].userId}")
- if (mStockModelList != null && mStockModelList.size > 0) {
- mStockModelList.forEach {
- it.oneUserId = "${retrievedList[0].userId}"
- it.oneUserName = "${retrievedList[0].name}"
- it.twoUserId = "${retrievedList[1].userId}"
- it.twoUserName = "${retrievedList[1].name}"
- }
- }
- // // 清空 SharedPreferences 中的集合
- // SharedPreferencesHelper.clearList(this@WarehousingActivity)
- }
- } catch (e: Exception) {
- }
- if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
- mCabinetLockVoList!!.forEach { it ->
- mLockStr.clear()
- when (it.unlockingMethod) {
- 2 -> { //智能锁
- mLockStr.add("${it.lockNum}")
- }
- }
- }
- } else {
- mLockStr.clear()
- }
- if (mLockStr != null && mLockStr.size > 0) {
- openLock(mLockStr)
- } else {
- subAddData(0)
- }
- }
- Constants.AUTHENTICATION = false
- } catch (e: Exception) {
- Constants.AUTHENTICATION = false
- }
- }
- override fun onDestroy() {
- super.onDestroy()
- try {
- handlerUtil.stopAllTasks()
- mHandler.removeCallbacksAndMessages(null)
- countdownTimer?.cancel()
- } catch (e: Exception) {
- }
- try {
- timeUpdater.stopUpdating()
- } catch (e: Exception) {
- }
- }
- override fun cdFinish() {
- finish()
- }
- //=================开锁流程================
- private val task = Runnable {
- //判断所有的锁开锁成功
- val containsFalse =
- mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
- LogUtils.i("=======查询调用开锁状态====$containsFalse")
- if (containsFalse) {
- getLocks()
- } else {
- dismissLoading()
- //开锁成功
- subAddData(1)
- handlerUtil.stopAllTasks()
- countdownTimer?.cancel()
- }
- }
- //查询开锁信息
- private fun getLocks() {
- mCabinetLockVoList!!.forEachIndexed { index, fruit ->
- if (!fruit.isOk && fruit.unlockingMethod == 2) {
- getLocksDate(index, fruit.lockNum)
- }
- }
- }
- //查询开锁状态
- private fun getLocksDate(index: Int, fruit: String) {
- val disposable = ApiRepository.getLocks(ChemicalApp.subjectId!!, fruit)
- .subscribe({ data ->
- if (data) {
- mCabinetLockVoList!![index].isOk = true
- }
- }, { throwable ->
- dismissLoading()
- showNetError(throwable)
- })
- addDisposable(disposable)
- }
- /**
- * 0 没有图标 1 绿色(成功) 2红色(失败)
- * 失败或者成功的弹框
- */
- private fun customDialogView(types: Int, msg: String) {
- if (!this.isFinishing && !this.isDestroyed) {
- val customDialog = CustomDialog(this, types, msg)
- customDialog.show()
- }
- }
- /**
- * 异常处理
- */
- private fun throwableView(throwable: Throwable) {
- when (throwable) {
- is NetException -> {
- if (throwable.message.isNullOrEmpty()) {
- "接口请求失败(${throwable.code})"
- } else {
- throwable.message!!
- }
- }
- is SocketTimeoutException -> "请求超时,请稍后重试"
- is ConnectException -> "无法连接服务器,请检查网络"
- is HttpException -> "服务器繁忙,请稍后重试"
- else -> null
- }?.let { customDialogView(2, "$it") }
- }
- }
|