InquiryActivity.kt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. package xn.hxp.ui.inquiry
  2. import android.content.IntentFilter
  3. import android.hardware.usb.UsbManager
  4. import android.os.Bundle
  5. import android.os.CountDownTimer
  6. import android.os.Handler
  7. import android.os.Looper
  8. import android.view.KeyEvent
  9. import android.view.LayoutInflater
  10. import android.view.View
  11. import android.widget.AdapterView
  12. import androidx.recyclerview.widget.LinearLayoutManager
  13. import androidx.viewbinding.ViewBinding
  14. import com.blankj.utilcode.util.LogUtils
  15. import com.bumptech.glide.Glide
  16. import com.bumptech.glide.load.engine.DiskCacheStrategy
  17. import com.bumptech.glide.request.RequestOptions
  18. import com.chad.library.adapter.base.util.getItemView
  19. import com.rc.core.ui.activity.BaseActivity
  20. import xn.hxp.app.ChemicalApp
  21. import xn.hxp.R
  22. import xn.hxp.databinding.ActivityInquiryBinding
  23. import xn.hxp.receiver.OnSerialScanListener
  24. import xn.hxp.receiver.PortScanHelper
  25. import xn.hxp.receiver.UsbReceiver
  26. import xn.hxp.ui.adapter.CabinetDoorAdapter
  27. import xn.hxp.ui.adapter.CabinetDoorRighAdapter
  28. import xn.hxp.ui.fragments.QueryOneFragment
  29. import xn.hxp.ui.fragments.QueryTwoFragment
  30. import xn.hxp.ui.login.FacialCardActivity
  31. import xn.hxp.ui.login.FacialLoginActivity
  32. import xn.hxp.ui.login.ScanLoginActivity
  33. import xn.hxp.ui.login.SwipeActivity
  34. import xn.hxp.utils.*
  35. import xn.hxp.weidith.*
  36. import com.rc.httpcore.HttpConfig
  37. import com.rc.httpcore.bean.*
  38. import com.rc.httpcore.client.ApiRepository
  39. import com.rc.httpcore.client.HttpTool
  40. import org.greenrobot.eventbus.EventBus
  41. import org.greenrobot.eventbus.Subscribe
  42. import org.greenrobot.eventbus.ThreadMode
  43. //化学品-查询 已登录-未登录 未登录-扫码弹框提示当前某一个信息 已登陆 显示所有列表
  44. class InquiryActivity : BaseActivity() {
  45. private lateinit var timeUpdater: TimeUpdater
  46. private var logIn = 0 //未登录
  47. private var mUsbReceiver: UsbReceiver? = null // 刷卡广播注册
  48. private var mHandleScanEvent = false //当前是否已经获取过 usb返回的参数
  49. private val mAdapterLeft by lazy { CabinetDoorAdapter(this) } //左边柜子
  50. private val mAdapterRigh by lazy { CabinetDoorRighAdapter(this) } //右边柜子
  51. private lateinit var viewPager: SwipeViewPager
  52. private lateinit var pagerAdapter: TabFragmentPagerAdapter
  53. private var mLeftPosition = 0 //左边柜子信息
  54. private var mCabinetLockVoList: List<LockVoListBean>? = null //柜锁会又多个
  55. private var mLockStr = ArrayList<String>() // 需要打开得柜锁数量
  56. private val handlerUtil = HandlerUtil.getInstance()
  57. private var mCabinetId: String? = null
  58. private var mCabinetName: String? = null
  59. private var mDoorId: String? = null
  60. private var mDoorName: String? = null
  61. private lateinit var faceList: List<String>//人员区间值
  62. private var mLoginType: String? = null //登录方式
  63. lateinit var viewBinding: ActivityInquiryBinding
  64. override fun setViewBinding(): ViewBinding {
  65. viewBinding = ActivityInquiryBinding.inflate(layoutInflater)
  66. return viewBinding
  67. }
  68. override fun onInit() {
  69. logIn = intent.getIntExtra("logIn", 0)
  70. val stringExtra = intent.getStringExtra("cabinetId")
  71. val stringExtra1 = intent.getStringExtra("doorId")
  72. if (!stringExtra.equals("a")) {
  73. mCabinetId = stringExtra
  74. mDoorId = stringExtra1
  75. }
  76. viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
  77. //注册广播
  78. EventBus.getDefault().register(this)
  79. viewBinding.tvOutLogin.setOnClickListener {
  80. HttpTool.logout()
  81. }
  82. if (logIn == 1) {
  83. // mHandleScanEvent = true
  84. //已登录
  85. viewBinding.loggedIn.visibility = View.VISIBLE
  86. viewBinding.tvName.text = "${ChemicalApp.userData!!.userName}"
  87. viewBinding.relOne.visibility = View.GONE
  88. getCabinet(ChemicalApp.subjectId!!)
  89. LogUtils.i("=====$mCabinetId")
  90. LogUtils.i("=====$mDoorId")
  91. fragmentInView()
  92. inAdapter()
  93. viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
  94. } else {
  95. mLoginType = ChemicalApp.confs!!.loginType
  96. //未登录
  97. viewBinding.loggedIn.visibility = View.GONE
  98. viewBinding.tvName.visibility = View.GONE
  99. }
  100. viewBinding.logIn.setOnClickListener {
  101. getUserIds()
  102. }
  103. initTitle()
  104. viewBinding.tvReturn.setOnClickListener {
  105. finish()
  106. }
  107. //校园级管理员-柜门管理员-柜锁管理员-安全负责人-实验室负责人
  108. viewBinding.butOpen.setOnClickListener {
  109. if (ChemicalApp.administrators || ChemicalApp.responsibles) {
  110. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  111. mLockStr.clear()
  112. mCabinetLockVoList!!.forEach { it ->
  113. when (it.unlockingMethod) {
  114. 2 -> { //智能锁
  115. mLockStr.add("${it.lockNum}")
  116. }
  117. }
  118. }
  119. if (mLockStr != null && mLockStr.size > 0) {
  120. openLock(mLockStr)
  121. } else {
  122. //无锁
  123. customDialogView(1, "柜门已开")
  124. }
  125. } else {
  126. //无锁
  127. customDialogView(1, "柜门已开")
  128. }
  129. } else {
  130. showToast("无权限信息")
  131. }
  132. }
  133. val handler = Handler(Looper.getMainLooper())
  134. timeUpdater = TimeUpdater(handler) { currentTime ->
  135. viewBinding.nowTime.text = "$currentTime"
  136. }
  137. // 启动定时更新
  138. timeUpdater.startUpdating()
  139. }
  140. private fun initTitle() {
  141. if (ChemicalApp.userData != null) {
  142. viewBinding.logIn.visibility = View.GONE
  143. viewBinding.tvName.text = ChemicalApp.userData!!.userName
  144. val imageView = viewBinding.imageName
  145. // 使用 Glide 加载网络图片
  146. Glide.with(this)
  147. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.userData!!.avatar}")
  148. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  149. .into(imageView)
  150. }
  151. // 使用 Glide 加载网络图片
  152. viewBinding.deptName.text = "${ChemicalApp.confs!!.deptName}-${ChemicalApp.confs!!.roomNum}"
  153. Glide.with(this)
  154. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.circularLogo}")
  155. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  156. .into(viewBinding.image)
  157. }
  158. private fun fragmentInView() {
  159. val tabArray = mutableListOf(
  160. QueryOneFragment.newInstance(),
  161. QueryTwoFragment.newInstance(),
  162. )
  163. pagerAdapter = TabFragmentPagerAdapter(supportFragmentManager, tabArray)
  164. viewPager = viewBinding.swipePagerView
  165. viewPager.adapter = pagerAdapter
  166. }
  167. private fun inAdapter() {
  168. viewBinding.recyclerViewListLeft?.layoutManager = LinearLayoutManager(this)
  169. viewBinding.recyclerViewListLeft?.adapter = mAdapterLeft
  170. viewBinding.recyclerViewListRight?.layoutManager = LinearLayoutManager(this)
  171. viewBinding.recyclerViewListRight?.adapter = mAdapterRigh
  172. mAdapterLeft.setOnItemClickListener { adapter, view, position ->
  173. mLeftPosition = position
  174. mAdapterLeft.data.forEach { it.isType = false }
  175. mAdapterLeft.data[position].isType = true
  176. mAdapterRigh.data.forEach { it.isType = false } //柜门初始化
  177. mAdapterLeft.notifyDataSetChanged()
  178. if (mAdapterLeft.data[mLeftPosition].cabinetDoorVoList != null) {
  179. mCabinetId = mAdapterLeft.data[mLeftPosition].cabinetId
  180. mCabinetName = mAdapterLeft.data[mLeftPosition].cabinetName
  181. mAdapterRigh.setNewInstance(mAdapterLeft.data[mLeftPosition].cabinetDoorVoList.toMutableList())
  182. }
  183. }
  184. mAdapterRigh.setOnItemClickListener { adapter, view, position ->
  185. mDoorId = mAdapterRigh.data[position].doorUniqueId
  186. mDoorName = mAdapterRigh.data[position].doorName
  187. mCabinetLockVoList = mAdapterRigh.data[position].cabinetLockVoList
  188. mAdapterRigh.data.forEach { it.isType = false }
  189. mAdapterRigh.data[position].isType = true
  190. mAdapterRigh.notifyDataSetChanged()
  191. //第一个页面
  192. goQueryTwoFragment()
  193. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  194. var isLock = false
  195. mCabinetLockVoList!!.forEach { it ->
  196. if (it.unlockingMethod == 2) {
  197. isLock = true
  198. return@forEach
  199. }
  200. }
  201. val userData = ChemicalApp.userData
  202. if (null != userData) {
  203. val userValidation = userData.userValidationBean
  204. if (null != userValidation) {
  205. if (isLock) {
  206. if (userValidation.cabinetAdmin == true || userValidation.safeUser == true || userValidation.adminUser == true) {
  207. viewBinding.butOpen.visibility = View.VISIBLE
  208. } else {
  209. viewBinding.butOpen.visibility = View.GONE
  210. }
  211. } else {
  212. viewBinding.butOpen.visibility = View.GONE
  213. }
  214. }
  215. } else {
  216. if (isLock) {
  217. viewBinding.butOpen.visibility = View.VISIBLE
  218. } else {
  219. viewBinding.butOpen.visibility = View.GONE
  220. }
  221. }
  222. }
  223. }
  224. }
  225. //查询存储位置 默认第一个
  226. private fun getCabinet(subId: String) {
  227. showLoading("查询中...")
  228. val disposable = ApiRepository.getCabinetList(subId)
  229. .subscribe({ data ->
  230. dismissLoading()
  231. mAdapterLeft.setNewInstance(data.toMutableList())
  232. mAdapterRigh.setNewInstance(data[0].cabinetDoorVoList.toMutableList())
  233. if (mCabinetId != null) {
  234. mAdapterLeft.data.forEachIndexed { index, ruleBean ->
  235. if (mCabinetId.equals(ruleBean.cabinetId)) {
  236. mAdapterLeft.data[index].isType = true
  237. mAdapterLeft.data[index].cabinetDoorVoList.forEachIndexed { index, ruleBean ->
  238. if (mDoorId.equals(ruleBean.doorUniqueId)) {
  239. mAdapterRigh.data[index].isType = true
  240. return@forEachIndexed
  241. }
  242. }
  243. return@forEachIndexed
  244. }
  245. }
  246. } else {
  247. //初始化第一把锁
  248. mCabinetId = mAdapterLeft.data[0].cabinetId
  249. mCabinetName = mAdapterLeft.data[0].cabinetName
  250. mAdapterLeft.data[0].isType = true
  251. mDoorId = mAdapterRigh.data[0].doorUniqueId
  252. mDoorName = mAdapterRigh.data[0].doorName
  253. mAdapterRigh.data[0].isType = true
  254. mCabinetLockVoList = mAdapterLeft.data[0].cabinetDoorVoList[0].cabinetLockVoList
  255. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  256. var isLock = false
  257. mCabinetLockVoList!!.forEach { it ->
  258. if (it.unlockingMethod == 2) {
  259. isLock = true
  260. return@forEach
  261. }
  262. }
  263. val userData = ChemicalApp.userData
  264. if (null != userData) {
  265. val userValidation = userData.userValidationBean
  266. if (null != userValidation) {
  267. if (isLock) {
  268. if (userValidation.cabinetAdmin == true || userValidation.safeUser == true || userValidation.adminUser == true) {
  269. viewBinding.butOpen.visibility = View.VISIBLE
  270. } else {
  271. viewBinding.butOpen.visibility = View.GONE
  272. }
  273. } else {
  274. viewBinding.butOpen.visibility = View.GONE
  275. }
  276. }
  277. } else {
  278. if (isLock) {
  279. viewBinding.butOpen.visibility = View.VISIBLE
  280. } else {
  281. viewBinding.butOpen.visibility = View.GONE
  282. }
  283. }
  284. }
  285. }
  286. //第一个页面
  287. goQueryTwoFragment()
  288. }, { throwable ->
  289. dismissLoading()
  290. showNetError(throwable)
  291. })
  292. addDisposable(disposable)
  293. }
  294. fun goQueryTwoFragment(stockId: String, hxpStockWaitListBean: HxpStockWaitListBean) {
  295. val secondFragment = pagerAdapter.getItem(1) as QueryTwoFragment
  296. secondFragment.setData(stockId, hxpStockWaitListBean, mCabinetId, mDoorId)
  297. viewPager.currentItem = 1
  298. }
  299. private fun goQueryTwoFragment() {
  300. val secondFragment = pagerAdapter.getItem(0) as QueryOneFragment
  301. secondFragment.upDatas(mCabinetId, mDoorId)
  302. viewPager.currentItem = 0
  303. }
  304. //=========================刷卡start================
  305. //刷卡信息 调用当前化学品信息 进行归还
  306. private fun handleScanEvent(cont: String) {
  307. if (logIn == 1) {
  308. //已登录
  309. showLoading("查询中...")
  310. val disposable = ApiRepository.getStockDetailsByCode(cont)
  311. .subscribe({ data ->
  312. dismissLoading()
  313. upViewTwo(data)
  314. }, { throwable ->
  315. dismissLoading()
  316. showNetError(throwable)
  317. mHandleScanEvent = false
  318. })
  319. addDisposable(disposable)
  320. } else {
  321. //未登录
  322. showLoading("查询中...")
  323. val disposable = ApiRepository.indexDetailbyRfid(cont)
  324. .subscribe({ data ->
  325. dismissLoading()
  326. upView(data)
  327. }, { throwable ->
  328. dismissLoading()
  329. showNetError(throwable)
  330. mHandleScanEvent = false
  331. })
  332. addDisposable(disposable)
  333. }
  334. }
  335. //未登录
  336. private fun upView(data: UseNoBean) {
  337. val proDialog = PromptDialog(this, data)
  338. if (!this.isFinishing && !this.isDestroyed) {
  339. proDialog.show()
  340. }
  341. mHandleScanEvent = false
  342. }
  343. //已登录
  344. private fun upViewTwo(data: UseNoTwoBean) {
  345. val scanCodeDialog = ScanCodeDialog(this, data)
  346. if (!this.isFinishing && !this.isDestroyed) {
  347. scanCodeDialog.show()
  348. }
  349. mHandleScanEvent = false
  350. }
  351. private val mPortScanHelper by lazy {
  352. PortScanHelper(this, object : OnSerialScanListener {
  353. override fun dispatchScanEvent(type: OnSerialScanListener.ScanType, content: String) {
  354. if (!mHandleScanEvent) {
  355. if (content.isNotBlank()) {
  356. mHandleScanEvent = true
  357. //所有通过查询二维码的参数 需要先判断 http开头的 然后进行截取
  358. if (content.startsWith("http")) {
  359. try {
  360. LogUtils.i("=======查询扫码 $content")
  361. val currentDateTimeString =
  362. BigDecimalUtils.extractParameterValue(content, "code")
  363. LogUtils.i("=======查询扫码 $currentDateTimeString")
  364. handleScanEvent(currentDateTimeString!!)
  365. } catch (e: Exception) {
  366. mHandleScanEvent = false
  367. showToast("扫描异常,请重操作")
  368. }
  369. } else {
  370. handleScanEvent(content)
  371. }
  372. }
  373. }
  374. }
  375. })
  376. }
  377. //刷卡usb链接
  378. private fun registerUsbBroadcast() {
  379. if (null == mUsbReceiver) {
  380. val filter = IntentFilter().apply {
  381. addAction(UsbReceiver.ACTION_USB_PERMISSION)
  382. addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
  383. addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
  384. addAction(UsbReceiver.ACTION_USB_STATE) // usb连接状态广播
  385. }
  386. mUsbReceiver = UsbReceiver()
  387. registerReceiver(mUsbReceiver, filter)
  388. }
  389. }
  390. override fun onResume() {
  391. super.onResume()
  392. mPortScanHelper.onResume()
  393. registerUsbBroadcast()
  394. }
  395. //获取刷卡信息
  396. override fun dispatchKeyEvent(event: KeyEvent): Boolean {
  397. mPortScanHelper.dispatchKeyEvent(event)
  398. return super.dispatchKeyEvent(event)
  399. }
  400. //停止 销毁广播传递
  401. override fun onPause() {
  402. mPortScanHelper.onPause()
  403. super.onPause()
  404. }
  405. override fun onDestroy() {
  406. super.onDestroy()
  407. mPortScanHelper.onPause()
  408. try {
  409. handlerUtil.stopAllTasks()
  410. countdownTimer?.cancel()
  411. } catch (e: Exception) {
  412. }
  413. try {
  414. timeUpdater.stopUpdating()
  415. } catch (e: Exception) {
  416. }
  417. // 停止定时更新
  418. unregisterReceiver(mUsbReceiver)
  419. EventBus.getDefault().unregister(this) //关闭广播
  420. }
  421. override fun cdFinish() {
  422. finish()
  423. }
  424. //必须写这个方法 防止注册失败
  425. @Subscribe(threadMode = ThreadMode.MAIN)
  426. fun onUpdateEventEvent(event: KeyEvent) {
  427. }
  428. //=========================刷卡end==================
  429. override fun onBackPressed() {
  430. super.onBackPressed()
  431. finish()
  432. }
  433. override fun cdTime(cd: Int) {
  434. viewBinding.tvReturn.text = "返回${cd}s"
  435. }
  436. //==========================开锁信息===================
  437. //=================开锁流程================
  438. private fun openLock(mLockStr: ArrayList<String>) {
  439. val map = mutableMapOf<String, Any>()
  440. map["subId"] = ChemicalApp.subjectId!!
  441. map["subName"] = ChemicalApp.subjectName!!
  442. map["cabinetId"] = "$mCabinetId"
  443. map["cabinetName"] = "$mCabinetName"
  444. map["doorId"] = "$mDoorId"
  445. map["doorName"] = "$mDoorName"
  446. map["lockNumList"] = mLockStr
  447. map["operationType"] = 6
  448. if (ChemicalApp.subRoom != null) {
  449. map["subRoom"] = ChemicalApp.subRoom!!
  450. }
  451. map["type"] = true
  452. try {// 从 SharedPreferences 中取出集合
  453. val retrievedList = SharedPreferencesHelper.getList(this)
  454. if (retrievedList != null && retrievedList.size > 0) {
  455. LogUtils.i("从本地取出得双人信息${retrievedList[0].name}")
  456. map["oneUserId"] = "${retrievedList[0].userId}"
  457. map["oneUserName"] = "${retrievedList[0].name}"
  458. map["twoUserId"] = "${retrievedList[1].userId}"
  459. map["twoUserName"] = "${retrievedList[1].name}"
  460. // 清空 SharedPreferences 中的集合
  461. // SharedPreferencesHelper.clearList(this)
  462. }
  463. } catch (e: Exception) {
  464. }
  465. showLoading("加载中...")
  466. val disposable = ApiRepository.lockOperate(map)
  467. .subscribe({ data ->
  468. dismissLoading()
  469. val containsFalse =
  470. mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  471. if (containsFalse) {
  472. showLoading("查询中...")
  473. startCountdownLock()
  474. // 开始执行任务,每 1 秒执行一次
  475. handlerUtil.startTask(task, 1000)
  476. }
  477. }, { throwable ->
  478. dismissLoading()
  479. showNetError(throwable)
  480. })
  481. addDisposable(disposable)
  482. }
  483. private var countdownTimer: CountDownTimer? = null
  484. private fun startCountdownLock() {
  485. val totalTime = 30 * 1000 // 30秒
  486. val interval = 1000 // 每秒更新一次
  487. countdownTimer = object : CountDownTimer(totalTime.toLong(), interval.toLong()) {
  488. override fun onTick(millisUntilFinished: Long) {
  489. val secondsLeft = millisUntilFinished / 1000
  490. println("剩余时间: $secondsLeft 秒")
  491. }
  492. override fun onFinish() {
  493. println("倒计时结束!")
  494. mCabinetLockVoList = null
  495. mLockStr.clear()
  496. showToast("开锁超时,可重新操作")
  497. dismissLoading()
  498. handlerUtil.stopAllTasks()
  499. // 在这里执行合适的操作,比如退出应用程序
  500. }
  501. }
  502. println("倒计时开始...")
  503. countdownTimer?.start()
  504. }
  505. private val task = Runnable {
  506. //判断所有的锁开锁成功
  507. val containsFalse = mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  508. if (containsFalse) {
  509. getLocks()
  510. } else {
  511. dismissLoading()
  512. //开锁成功
  513. customDialogView(1, "柜门已开")
  514. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai)
  515. handlerUtil.stopAllTasks()
  516. countdownTimer?.cancel()
  517. }
  518. }
  519. //查询开锁信息
  520. private fun getLocks() {
  521. mCabinetLockVoList!!.forEachIndexed { index, fruit ->
  522. if (fruit.isOk == false && fruit.unlockingMethod == 2) {
  523. getLocksDate(index, fruit.lockNum)
  524. }
  525. }
  526. }
  527. //查询开锁状态
  528. private fun getLocksDate(index: Int, fruit: String) {
  529. val disposable = ApiRepository.getLocks(ChemicalApp.subjectId!!, fruit)
  530. .subscribe({ data ->
  531. if (data) {
  532. mCabinetLockVoList!![index].isOk = true
  533. }
  534. }, { throwable ->
  535. dismissLoading()
  536. showNetError(throwable)
  537. })
  538. addDisposable(disposable)
  539. }
  540. /**
  541. * 0 没有图标 1 绿色(成功) 2红色(失败)
  542. * 失败或者成功的弹框
  543. */
  544. private fun customDialogView(types: Int, msg: String) {
  545. val customDialog = CustomDialog(this, types, msg)
  546. if (!this.isFinishing && !this.isDestroyed) {
  547. customDialog.show()
  548. }
  549. }
  550. private fun getUserIds() {
  551. if (ChemicalApp.subjectId != null) {
  552. showLoading("查询中...")
  553. val disposable = ApiRepository.getUserIds(ChemicalApp.subjectId!!)
  554. .subscribe({ data ->
  555. dismissLoading()
  556. faceList = data
  557. getLogin()
  558. }, { throwable ->
  559. dismissLoading()
  560. // throwableView(throwable)
  561. })
  562. addDisposable(disposable)
  563. }
  564. }
  565. //登录方式
  566. private fun getLogin() {
  567. if (mLoginType == null) {
  568. customDialogView(2, "登录方式配置有误")
  569. } else {
  570. finish()
  571. if (mLoginType!!.contains("4")) {
  572. //需要刷卡+人脸
  573. UiManager.switcher(this, FacialCardActivity::class.java)
  574. } else {
  575. val map = mutableMapOf<String, String>()
  576. //1人脸 2刷卡 3扫码 4人脸+刷卡
  577. if (mLoginType!!.length == 1) {
  578. when (mLoginType) {
  579. "1" -> {
  580. //人脸
  581. map["faceList"] = faceList.toString()
  582. map["mtypes"] = "1"
  583. UiManager.switcher(this, map, FacialLoginActivity::class.java)
  584. }
  585. "2" -> {
  586. //刷卡
  587. map["mtypes"] = "1"
  588. UiManager.switcher(this, map, SwipeActivity::class.java)
  589. }
  590. else -> {
  591. //扫码
  592. map["mtypes"] = "1"
  593. UiManager.switcher(this, map, ScanLoginActivity::class.java)
  594. }
  595. }
  596. } else {
  597. val array = mLoginType!!.split(",").toTypedArray()
  598. when (array.size) {
  599. 2 -> {
  600. //1-2(人脸+刷卡) 1-3(人脸+扫码) 2-3(刷卡+扫码)
  601. if (mLoginType == "1,2" || mLoginType == "2,1") {
  602. //人脸+刷卡
  603. map["faceList"] = faceList.toString()
  604. map["mtypes"] = "4" //隐藏扫码
  605. UiManager.switcher(this, map, FacialLoginActivity::class.java)
  606. } else if (mLoginType == "1,3" || mLoginType == "3,1") {
  607. //人脸+扫码
  608. map["faceList"] = faceList.toString()
  609. map["mtypes"] = "5" //隐藏刷卡
  610. UiManager.switcher(this, map, FacialLoginActivity::class.java)
  611. } else if (mLoginType == "2,3" || mLoginType == "3,2") {
  612. //刷卡+扫码
  613. map["mtypes"] = "6" //隐藏人脸
  614. UiManager.switcher(this, map, SwipeActivity::class.java)
  615. } else {
  616. showToast("登录方式$mLoginType")
  617. }
  618. }
  619. else -> {
  620. //3条
  621. try {
  622. map["mtypes"] = "0"
  623. map["faceList"] = faceList.toString()
  624. UiManager.switcher(this, map, FacialLoginActivity::class.java)
  625. } catch (e: Exception) {
  626. map["mtypes"] = "0"
  627. UiManager.switcher(this, map, SwipeActivity::class.java)
  628. }
  629. }
  630. }
  631. }
  632. }
  633. }
  634. }
  635. }