ChemicalLabelingActivity.kt 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. package xn.hxp.ui.warehousing
  2. import android.os.CountDownTimer
  3. import android.os.Handler
  4. import android.os.Looper
  5. import android.view.KeyEvent
  6. import android.view.View
  7. import android.widget.AdapterView
  8. import androidx.core.content.ContextCompat
  9. import androidx.recyclerview.widget.LinearLayoutManager
  10. import androidx.viewbinding.ViewBinding
  11. import com.blankj.utilcode.util.LogUtils
  12. import com.bumptech.glide.Glide
  13. import com.bumptech.glide.load.engine.DiskCacheStrategy
  14. import com.bumptech.glide.request.RequestOptions
  15. import com.rc.core.ui.activity.BaseActivity
  16. import com.rc.httpcore.HttpConfig
  17. import com.rc.httpcore.bean.LockVoListBean
  18. import com.rc.httpcore.bean.ReturnDetailsBean
  19. import com.rc.httpcore.client.ApiRepository
  20. import com.rc.httpcore.client.HttpTool
  21. import com.sun.jna.Pointer
  22. import xn.hxp.R
  23. import xn.hxp.app.ChemicalApp
  24. import xn.hxp.comm.Constants
  25. import xn.hxp.databinding.ActivityChemicalLabelingBinding
  26. import xn.hxp.receiver.UhfRfidManager
  27. import xn.hxp.ui.PrintBean
  28. import xn.hxp.ui.adapter.ChemicalLabelingAdapter
  29. import xn.hxp.ui.adapter.CustomSpinnerTwoAdapter
  30. import xn.hxp.ui.verify.TwoVerificationActivity
  31. import xn.hxp.utils.AudioPlayer
  32. import xn.hxp.utils.HandlerUtil
  33. import xn.hxp.utils.PrintTool
  34. import xn.hxp.utils.SharedPreferencesHelper
  35. import xn.hxp.utils.TimeUpdater
  36. import xn.hxp.utils.UiManager
  37. import xn.hxp.weidith.AirBottleDialog
  38. import xn.hxp.weidith.AirBottleNewDialog
  39. import xn.hxp.weidith.CustomDialog
  40. import xn.hxp.weidith.StorageDialog
  41. import xn.hxp.weidith.TextTool
  42. //标签列表
  43. class ChemicalLabelingActivity : BaseActivity() {
  44. private val mAdapter by lazy { ChemicalLabelingAdapter(this) }
  45. private lateinit var timeUpdater: TimeUpdater
  46. private lateinit var mData: ReturnDetailsBean
  47. private var mCabinetId: String? = null
  48. private var mDoorId: String? = null
  49. private val sPrinDate: MutableList<String> = mutableListOf()
  50. private var mCabinetLockVoList: List<LockVoListBean>? = null //柜锁会又多个
  51. private var mLockStr = ArrayList<String>() // 需要打开得柜锁数量
  52. private val handlerUtil = HandlerUtil.getInstance()
  53. private var mPages = 1 //总页码
  54. private var mDataPage = -1 //返回得总条数
  55. private var page = 1
  56. private var pageSize = 10
  57. private var mPosition = 0
  58. private var mAdIndex = -1
  59. var h = Pointer.NULL
  60. lateinit var viewBinding: ActivityChemicalLabelingBinding
  61. override fun setViewBinding(): ViewBinding {
  62. viewBinding = ActivityChemicalLabelingBinding.inflate(layoutInflater)
  63. return viewBinding
  64. }
  65. override fun onInit() {
  66. val sPinner = viewBinding.sPinner
  67. viewBinding.rvInventory.layoutManager = LinearLayoutManager(this)
  68. viewBinding.rvInventory.adapter = mAdapter
  69. viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
  70. viewBinding.tvOutLogin.setOnClickListener {
  71. HttpTool.logout()
  72. }
  73. viewBinding.tvReturn.setOnClickListener {
  74. finish()
  75. }
  76. mAdapter.setOnItemClickListener { adapter, view, position ->
  77. mAdapter.data.forEach { it.isType = false }
  78. mAdapter.data[position].isType = true
  79. mAdapter.notifyDataSetChanged()
  80. getIdDate("${mAdapter.data[position].id}")
  81. mAdIndex = position
  82. }
  83. viewBinding.cabinetName.setOnClickListener {
  84. getCabinet()
  85. }
  86. viewBinding.reSou.setOnClickListener {
  87. page = 1
  88. labelingData()
  89. }
  90. viewBinding.resetting.setOnClickListener {
  91. page = 1
  92. mCabinetId = null
  93. mDoorId = null
  94. viewBinding.edCont.setText("")
  95. viewBinding.cabinetName.text = "化学品柜"
  96. sPinner.setSelection(0)
  97. labelingData()
  98. }
  99. viewBinding.reLabel.setOnClickListener {
  100. //补打标签
  101. val print = PrintBean()
  102. print.tag = mData.tagCode //化学品编码
  103. print.wxCode = mData.wxCode!! //化学品编码
  104. print.name = mData.chemicalName!! //化学品名称
  105. if (mData.casNum != null) {
  106. print.casNo = mData.casNum!! //cas号
  107. } else {
  108. print.casNo = ""
  109. }
  110. // if (mDataBean.topicGroup) {
  111. // print.person = mDataBean.topicGroupName //归属人
  112. // } else {
  113. // print.person = mDataBean.applyUserName //归属人
  114. // }
  115. print.person = mData.belongName
  116. //管控 1 非管控 2
  117. if (mData.chemicalLevel == 1) {
  118. print.level = "管控"
  119. } else {
  120. print.level = "非管控"
  121. }
  122. //
  123. print.types = "${mData.chemicalCategoryName}"
  124. PrintTool.INSTANCE.print(mData.isGr, mData.belongType == 2, print)
  125. }
  126. viewBinding.replaceLabel.setOnClickListener {
  127. if (viewBinding.replaceLabel.text.toString().startsWith("更")) {
  128. val airBottleNewDialog =
  129. AirBottleNewDialog(this, mData.rfidCode, object : AirBottleNewDialog.ILintDate {
  130. override fun onLintDate(cont: String) {
  131. if (mData.rfidCode!! != cont) {
  132. updateRfid(mData.stockDetailsId, cont)
  133. } else {
  134. showToast("更换的标签不能重复")
  135. }
  136. }
  137. })
  138. airBottleNewDialog.show()
  139. } else {
  140. //RFID打印
  141. var airBottleDialog = AirBottleDialog(this, object : AirBottleDialog.ILintDate {
  142. override fun onLintDate(cont: String) {
  143. if (cont.isNotEmpty()) {
  144. updateRfid(mData.stockDetailsId, cont)
  145. }
  146. }
  147. })
  148. airBottleDialog.show()
  149. }
  150. }
  151. viewBinding.openLok.setOnClickListener {
  152. val toString = viewBinding.openLok.text.toString()
  153. if (toString == "打开柜门") {
  154. //打开柜门
  155. if (mData.verify) {
  156. // //跳转认证
  157. // //需要双人认证
  158. // val map = mutableMapOf<String, Any>()
  159. // //当前 管控类型
  160. // map["chemicalLevel"] = mData.chemicalLevel //管控类型
  161. // map["doorId"] = "${mData.doorId}" //柜子id
  162. // map["stockId"] = "${mData.chemicalId}" //化学品id
  163. // map["mTag"] = 1
  164. // UiManager.switcher(
  165. // this,
  166. // map,
  167. // SwipeCodeTwoActivity::class.java,
  168. // Constants.REQUEST_CODE
  169. // )
  170. //需要双人认证
  171. if (ChemicalApp.confs!!.verifyType.length == 1) {
  172. val map = mutableMapOf<String, Any>()
  173. map["chemicalLevel"] = mData.chemicalLevel //管控类型
  174. // map["doorId"] = "$mDoorId" //柜子id
  175. map["doorId"] = "${mData.doorId}" //柜子id
  176. map["mTag"] = 1
  177. when (ChemicalApp.confs!!.verifyType) {
  178. "1" -> {//人脸
  179. map["mVerTyps"] = 1
  180. }
  181. "2" -> {//刷卡
  182. map["mVerTyps"] = 2
  183. }
  184. "3" -> {//扫码
  185. map["mVerTyps"] = 3
  186. }
  187. }
  188. UiManager.switcher(
  189. this,
  190. map,
  191. TwoVerificationActivity::class.java
  192. )
  193. } else {
  194. //多类型双人认证
  195. verifyChecking()
  196. }
  197. } else {
  198. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  199. mLockStr.clear()
  200. mCabinetLockVoList!!.forEach { it ->
  201. when (it.unlockingMethod) {
  202. 2 -> { //智能锁
  203. mLockStr.add("${it.lockNum}")
  204. }
  205. }
  206. }
  207. if (mLockStr != null && mLockStr.size > 0) {
  208. openLock(mLockStr)
  209. }
  210. } else {
  211. //没有锁 不需要开锁
  212. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  213. }
  214. // //不需要认证
  215. // if (mLockStr != null && mLockStr.size > 0) {
  216. // openLock(mLockStr)
  217. // } else {
  218. // //没有锁 不需要开锁
  219. // AudioPlayer.getInstance().play(R.raw.quchuhuaxuepin)
  220. // }
  221. }
  222. } else {
  223. //不需要认证
  224. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  225. mLockStr.clear()
  226. mCabinetLockVoList!!.forEach { it ->
  227. when (it.unlockingMethod) {
  228. 2 -> { //智能锁
  229. mLockStr.add("${it.lockNum}")
  230. }
  231. }
  232. }
  233. if (mLockStr != null && mLockStr.size > 0) {
  234. openLock(mLockStr)
  235. }
  236. } else {
  237. //没有锁 不需要开锁
  238. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  239. }
  240. }
  241. }
  242. sPrinDate.add("级别")
  243. sPrinDate.add("管控")
  244. sPrinDate.add("非管控")
  245. LogUtils.i("=======当前级别条数${sPrinDate.size}")
  246. val customAdapter = CustomSpinnerTwoAdapter(this, sPrinDate!!)
  247. sPinner.adapter = customAdapter
  248. sPinner.setSelection(0)
  249. sPinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
  250. override fun onItemSelected(
  251. parent: AdapterView<*>?,
  252. view: View?,
  253. position: Int,
  254. id: Long
  255. ) {
  256. // 当用户选择某一项时被调用
  257. LogUtils.i("=======当前选择下标 ${sPrinDate!![position]}")
  258. mPosition = position
  259. // 在这里可以使用 selectedPosition 来执行相应的操作
  260. }
  261. override fun onNothingSelected(parent: AdapterView<*>?) {
  262. // 当没有任何项被选择时被调用
  263. LogUtils.i("=======DUOC")
  264. }
  265. }
  266. //获取列表信息
  267. labelingData()
  268. viewBinding.butUpper.setOnClickListener {
  269. //上一页
  270. if (mDataPage != 0) {
  271. if (page != 1) {
  272. page--
  273. labelingData()
  274. }
  275. }
  276. }
  277. viewBinding.butNext.setOnClickListener {
  278. //下一页
  279. if (mDataPage != 0) {
  280. if (mDataPage != page) {
  281. page++
  282. labelingData()
  283. }
  284. }
  285. }
  286. val handler = Handler(Looper.getMainLooper())
  287. timeUpdater = TimeUpdater(handler) { currentTime ->
  288. viewBinding.nowTime.text = "$currentTime"
  289. }
  290. // 启动定时更新
  291. timeUpdater.startUpdating()
  292. viewBinding.tvName.text = ChemicalApp.userData!!.userName
  293. val imageView = viewBinding.imageName
  294. // 使用 Glide 加载网络图片
  295. Glide.with(this)
  296. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.userData!!.avatar}")
  297. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  298. .into(imageView)
  299. // 使用 Glide 加载网络图片
  300. viewBinding.deptName.text = "${ChemicalApp.confs!!.deptName}-${ChemicalApp.confs!!.roomNum}"
  301. Glide.with(this)
  302. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.circularLogo}")
  303. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  304. .into(viewBinding.image)
  305. }
  306. override fun onBackPressed() {
  307. super.onBackPressed()
  308. finish()
  309. }
  310. // 标签管理页面:消费掉外置RFID读卡器事件,仅在弹窗中处理
  311. override fun dispatchKeyEvent(event: KeyEvent): Boolean {
  312. if (UhfRfidManager.isEnabled(this) && UhfRfidManager.isUhfRfidEvent(this, event)) {
  313. return true
  314. }
  315. return super.dispatchKeyEvent(event)
  316. }
  317. override fun cdTime(cd: Int) {
  318. viewBinding.tvReturn.text = "返回${cd}s"
  319. }
  320. override fun onResume() {
  321. super.onResume()
  322. try {
  323. if (Constants.AUTHENTICATION) {
  324. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  325. mLockStr.clear()
  326. mCabinetLockVoList!!.forEach { it ->
  327. when (it.unlockingMethod) {
  328. 2 -> { //智能锁
  329. mLockStr.add("${it.lockNum}")
  330. }
  331. }
  332. }
  333. if (mLockStr != null && mLockStr.size > 0) {
  334. openLock(mLockStr)
  335. }
  336. } else {
  337. //没有锁 不需要开锁
  338. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  339. }
  340. Constants.AUTHENTICATION = false
  341. }
  342. } catch (e: Exception) {
  343. Constants.AUTHENTICATION = false
  344. }
  345. }
  346. //验证方式
  347. private fun verifyChecking() {
  348. val map = mutableMapOf<String, Any>()
  349. map["chemicalLevel"] = mData.chemicalLevel //管控类型
  350. map["doorId"] = "${mData.doorId}" //柜子id
  351. map["mTag"] = 1
  352. map["mVerTyps"] = 0
  353. if (ChemicalApp.confs!!.verifyType == "1,2" || ChemicalApp.confs!!.verifyType == "2,1") {
  354. //人脸+刷卡
  355. map["hides"] = 1
  356. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  357. } else if (ChemicalApp.confs!!.verifyType == "1,3" || ChemicalApp.confs!!.verifyType == "3,1") {
  358. //人脸+扫码
  359. map["hides"] = 2
  360. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  361. } else if (ChemicalApp.confs!!.verifyType == "2,3" || ChemicalApp.confs!!.verifyType == "3,2") {
  362. map["hides"] = 3
  363. // UiManager.switcher(
  364. // this,
  365. // map,
  366. // TwoVerificationActivity::class.java,
  367. // Constants.REQUEST_CODE
  368. // )
  369. } else {
  370. //人脸+刷卡+扫码
  371. map["hides"] = 4
  372. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  373. }
  374. UiManager.switcher(
  375. this,
  376. map,
  377. TwoVerificationActivity::class.java,
  378. Constants.REQUEST_CODE
  379. )
  380. }
  381. // override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  382. // super.onActivityResult(requestCode, resultCode, data)
  383. // if (requestCode == Constants.REQUEST_CODE && resultCode == Activity.RESULT_OK) {
  384. // val value = data?.getBooleanExtra("isLogin", false) // 获取返回的参数
  385. // if (value == true) {
  386. // //1无锁,2是智能锁,3是钥匙柜
  387. // when (mData.unlockingMethod) {
  388. // 1 -> {
  389. // //1无锁
  390. //
  391. // }
  392. // 2 -> {
  393. // //2是智能锁
  394. // openLock()
  395. // }
  396. // 3 -> {
  397. // //是钥匙柜
  398. //
  399. // }
  400. // }
  401. // } else {
  402. // showToast("认证失败!!")
  403. // }
  404. // }
  405. // }
  406. private fun updateRfid(
  407. ids: String,
  408. rfid: String
  409. ) {
  410. showLoading("操作中...")
  411. val disposable = ApiRepository.updateRfid(ids, rfid).subscribe({ data ->
  412. dismissLoading()
  413. customDialogView(1, "更换成功")
  414. mAdapter.data[mAdIndex].rfidCode = rfid
  415. mAdapter.notifyItemChanged(mAdIndex)
  416. }, { throwable ->
  417. dismissLoading()
  418. val errorMsg = resolveErrorMessage(throwable, "更换失败")
  419. customDialogView(2, errorMsg)
  420. showToast(errorMsg)
  421. })
  422. addDisposable(disposable)
  423. }
  424. private fun resolveErrorMessage(throwable: Throwable?, defaultMsg: String): String {
  425. val message = throwable?.message?.trim()
  426. if (!message.isNullOrEmpty()) {
  427. return message
  428. }
  429. val localizedMessage = throwable?.localizedMessage?.trim()
  430. if (!localizedMessage.isNullOrEmpty()) {
  431. return localizedMessage
  432. }
  433. return defaultMsg
  434. }
  435. /**
  436. * 0 没有图标 1 绿色(成功) 2红色(失败)
  437. * 失败或者成功的弹框
  438. */
  439. private fun customDialogView(types: Int, msg: String) {
  440. if (!this.isFinishing && !this.isDestroyed) {
  441. val customDialog = CustomDialog(this, types, msg)
  442. customDialog.show()
  443. }
  444. }
  445. private fun labelingData() {
  446. showLoading("查询中...")
  447. val map = mutableMapOf<String, Any>()
  448. map["subId"] = "${ChemicalApp.subjectId}"
  449. if (mPosition == 1 || mPosition == 2) {
  450. map["chemicalLevel"] = "$mPosition"
  451. }
  452. // map["chemicalLevel"] = ""
  453. if (mCabinetId != null) {
  454. map["cabinetId"] = mCabinetId!!
  455. }
  456. if (mDoorId != null) {
  457. map["doorId"] = mDoorId!!
  458. }
  459. val toString = viewBinding.edCont.text.toString()
  460. if (toString.isNotEmpty()) {
  461. map["searchValue"] = toString
  462. }
  463. map["page"] = "$page"
  464. map["pageSize"] = "$pageSize"
  465. val disposable = ApiRepository.tagDetailsList(map)
  466. .subscribe({ data ->
  467. dismissLoading()
  468. LogUtils.i("====列表==成功")
  469. mDataPage = data.pages //总页
  470. if (mAdapter.data != null) {
  471. mAdapter.data.clear()
  472. mAdapter.notifyDataSetChanged()
  473. initPagesView(data.pages)
  474. }
  475. if (data.pages != 0) {
  476. if (data.pages > 1 && data.current > 1) {
  477. //当前需要更新页码
  478. upPagesView(data.pages, data.current)
  479. mAdapter.setList(data.records.toMutableList())
  480. } else {
  481. mAdapter.setNewInstance(data.records.toMutableList())
  482. initPagesView(data.pages)
  483. }
  484. }
  485. }, { throwable ->
  486. dismissLoading()
  487. showNetError(throwable)
  488. LogUtils.i("====列表==失败")
  489. })
  490. addDisposable(disposable)
  491. }
  492. /**
  493. * 总页码 当前页 初始化
  494. */
  495. private fun initPagesView(pages: Int) {
  496. mPages = pages
  497. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  498. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  499. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  500. viewBinding.one.setTextColor(ContextCompat.getColor(this, R.color.white))
  501. viewBinding.two.setTextColor(ContextCompat.getColor(this, R.color.black))
  502. when (pages) {
  503. 1 -> {
  504. viewBinding.one.visibility = View.VISIBLE
  505. }
  506. 2 -> {
  507. viewBinding.two.visibility = View.VISIBLE
  508. }
  509. 3 -> {
  510. viewBinding.two.visibility = View.VISIBLE
  511. viewBinding.three.visibility = View.VISIBLE
  512. }
  513. else -> {
  514. viewBinding.two.visibility = View.VISIBLE
  515. viewBinding.three.visibility = View.VISIBLE
  516. viewBinding.drop.visibility = View.VISIBLE
  517. viewBinding.many.visibility = View.VISIBLE
  518. viewBinding.many.text = "$pages"
  519. }
  520. }
  521. if (pages == 1 || pages == 0) {
  522. viewBinding.two.visibility = View.GONE
  523. viewBinding.three.visibility = View.GONE
  524. viewBinding.many.visibility = View.GONE
  525. viewBinding.drop.visibility = View.GONE
  526. }
  527. if (pages < 4) {
  528. when (pages) {
  529. 1 -> {
  530. viewBinding.two.visibility = View.GONE
  531. viewBinding.three.visibility = View.GONE
  532. viewBinding.many.visibility = View.GONE
  533. viewBinding.drop.visibility = View.GONE
  534. }
  535. 2 -> {
  536. viewBinding.three.visibility = View.GONE
  537. viewBinding.many.visibility = View.GONE
  538. viewBinding.drop.visibility = View.GONE
  539. }
  540. 3 -> {
  541. viewBinding.many.visibility = View.GONE
  542. viewBinding.drop.visibility = View.GONE
  543. }
  544. }
  545. }
  546. }
  547. //更新页码
  548. private fun upPagesView(pages: Int, current: Int) {
  549. LogUtils.i("======2")
  550. if (pages < 4) {
  551. // viewBinding.one.visibility = View.VISIBLE
  552. when (pages) {
  553. 1 -> {
  554. viewBinding.two.visibility = View.GONE
  555. viewBinding.three.visibility = View.GONE
  556. viewBinding.many.visibility = View.GONE
  557. viewBinding.drop.visibility = View.GONE
  558. }
  559. 2 -> {
  560. viewBinding.three.visibility = View.GONE
  561. viewBinding.many.visibility = View.GONE
  562. viewBinding.drop.visibility = View.GONE
  563. }
  564. 3 -> {
  565. viewBinding.many.visibility = View.GONE
  566. viewBinding.drop.visibility = View.GONE
  567. }
  568. }
  569. when (current) {
  570. 1 -> {
  571. viewBinding.one.setTextColor(
  572. ContextCompat.getColor(
  573. this,
  574. R.color.white
  575. )
  576. )
  577. viewBinding.two.setTextColor(
  578. ContextCompat.getColor(
  579. this,
  580. R.color.black
  581. )
  582. )
  583. viewBinding.three.setTextColor(
  584. ContextCompat.getColor(
  585. this,
  586. R.color.black
  587. )
  588. )
  589. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  590. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  591. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  592. }
  593. 2 -> {
  594. // viewBinding.two.visibility = View.VISIBLE
  595. viewBinding.one.setTextColor(
  596. ContextCompat.getColor(
  597. this,
  598. R.color.black
  599. )
  600. )
  601. viewBinding.two.setTextColor(
  602. ContextCompat.getColor(
  603. this,
  604. R.color.white
  605. )
  606. )
  607. viewBinding.three.setTextColor(
  608. ContextCompat.getColor(
  609. this,
  610. R.color.black
  611. )
  612. )
  613. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  614. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
  615. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  616. }
  617. 3 -> {
  618. // viewBinding.three.visibility = View.VISIBLE
  619. viewBinding.one.setTextColor(
  620. ContextCompat.getColor(
  621. this,
  622. R.color.black
  623. )
  624. )
  625. viewBinding.two.setTextColor(
  626. ContextCompat.getColor(
  627. this,
  628. R.color.black
  629. )
  630. )
  631. viewBinding.three.setTextColor(
  632. ContextCompat.getColor(
  633. this,
  634. R.color.white
  635. )
  636. )
  637. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  638. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  639. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  640. }
  641. }
  642. } else {
  643. // viewBinding.many.visibility = View.VISIBLE
  644. viewBinding.three.text = "3"
  645. when (current) {
  646. 1 -> {
  647. viewBinding.one.setTextColor(
  648. ContextCompat.getColor(
  649. this,
  650. R.color.white
  651. )
  652. )
  653. viewBinding.two.setTextColor(
  654. ContextCompat.getColor(
  655. this,
  656. R.color.black
  657. )
  658. )
  659. viewBinding.three.setTextColor(
  660. ContextCompat.getColor(
  661. this,
  662. R.color.black
  663. )
  664. )
  665. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  666. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  667. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  668. }
  669. 2 -> {
  670. viewBinding.one.setTextColor(
  671. ContextCompat.getColor(
  672. this,
  673. R.color.black
  674. )
  675. )
  676. viewBinding.two.setTextColor(
  677. ContextCompat.getColor(
  678. this,
  679. R.color.white
  680. )
  681. )
  682. viewBinding.three.setTextColor(
  683. ContextCompat.getColor(
  684. this,
  685. R.color.black
  686. )
  687. )
  688. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  689. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
  690. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  691. }
  692. 3 -> {
  693. viewBinding.one.setTextColor(
  694. ContextCompat.getColor(
  695. this,
  696. R.color.black
  697. )
  698. )
  699. viewBinding.two.setTextColor(
  700. ContextCompat.getColor(
  701. this,
  702. R.color.black
  703. )
  704. )
  705. viewBinding.three.setTextColor(
  706. ContextCompat.getColor(
  707. this,
  708. R.color.white
  709. )
  710. )
  711. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  712. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  713. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  714. }
  715. else -> {
  716. viewBinding.three.text = "$current"
  717. if (pages == current) {
  718. viewBinding.three.text = "${current - 1}"
  719. viewBinding.one.setTextColor(
  720. ContextCompat.getColor(
  721. this,
  722. R.color.black
  723. )
  724. )
  725. viewBinding.two.setTextColor(
  726. ContextCompat.getColor(
  727. this,
  728. R.color.black
  729. )
  730. )
  731. viewBinding.three.setTextColor(
  732. ContextCompat.getColor(
  733. this,
  734. R.color.black
  735. )
  736. )
  737. viewBinding.many.setTextColor(
  738. ContextCompat.getColor(
  739. this,
  740. R.color.white
  741. )
  742. )
  743. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  744. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  745. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  746. viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_page)
  747. } else {
  748. viewBinding.one.setTextColor(
  749. ContextCompat.getColor(
  750. this,
  751. R.color.black
  752. )
  753. )
  754. viewBinding.two.setTextColor(
  755. ContextCompat.getColor(
  756. this,
  757. R.color.black
  758. )
  759. )
  760. viewBinding.three.setTextColor(
  761. ContextCompat.getColor(
  762. this,
  763. R.color.white
  764. )
  765. )
  766. viewBinding.many.setTextColor(
  767. ContextCompat.getColor(
  768. this,
  769. R.color.black
  770. )
  771. )
  772. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  773. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  774. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  775. viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  776. }
  777. }
  778. }
  779. }
  780. }
  781. private fun getIdDate(id: String) {
  782. showLoading("查询中...")
  783. val disposable = ApiRepository.getDetailsById(id)
  784. .subscribe({ data ->
  785. dismissLoading()
  786. upView(data)
  787. }, { throwable ->
  788. dismissLoading()
  789. showNetError(throwable)
  790. })
  791. addDisposable(disposable)
  792. }
  793. private fun upView(data: ReturnDetailsBean) {
  794. viewBinding.relOne.visibility = View.GONE
  795. viewBinding.linTow.visibility = View.VISIBLE
  796. viewBinding.chemicalName.text = "${data.chemicalName}"
  797. viewBinding.chemicalName.setOnClickListener {
  798. TextTool.showPop(
  799. this,
  800. viewBinding.chemicalName
  801. )
  802. }
  803. viewBinding.tagCode.text = "编码${data.tagCode}"
  804. viewBinding.chemicalLevelName.text = "${data.chemicalLevelName}"
  805. viewBinding.chemicalCategoryName.text = "${data.chemicalCategoryName}"
  806. viewBinding.spec.text = "${data.specNum}${data.specUnit}/${data.packUnit}"
  807. viewBinding.belongName.text = "${data.belongName}"
  808. viewBinding.surplus.text = "${data.surplus}${data.specUnit}"
  809. viewBinding.expireTime.text = ""//清除之前得数据
  810. if (data.expireTime != null) {
  811. viewBinding.expireTime.text = "${data.expireTime}"
  812. }
  813. viewBinding.cabinet.text = "${data.cabinetName}-${data.doorName}-${data.layers}层"
  814. mData = data
  815. viewBinding.replaceLabel.visibility = View.VISIBLE
  816. if (mData.rfidCode == null) {
  817. viewBinding.replaceLabel.text = "绑定RFID"
  818. } else {
  819. viewBinding.replaceLabel.text = "更换RFID"
  820. }
  821. mCabinetLockVoList = mData.cabinetLockVoList //柜锁信息
  822. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  823. var isLock = false
  824. mCabinetLockVoList!!.forEach { it ->
  825. if (it.unlockingMethod == 2) {
  826. isLock = true
  827. return@forEach
  828. }
  829. }
  830. if (isLock) {
  831. viewBinding.openLok.visibility = View.VISIBLE
  832. }
  833. }
  834. }
  835. private fun openLock(mLockStr: ArrayList<String>) {
  836. val map = mutableMapOf<String, Any>()
  837. map["subId"] = mData.subId
  838. map["subName"] = mData.subName
  839. map["cabinetId"] = "${mData.cabinetId}"
  840. map["cabinetName"] = "${mData.cabinetName}"
  841. map["doorId"] = "${mData.doorId}"
  842. map["doorName"] = "${mData.doorName}"
  843. map["lockNumList"] = mLockStr
  844. map["operationType"] = 7
  845. if (ChemicalApp.subRoom != null) {
  846. map["subRoom"] = ChemicalApp.subRoom!!
  847. }
  848. map["type"] = true
  849. try {// 从 SharedPreferences 中取出集合
  850. val retrievedList = SharedPreferencesHelper.getList(this)
  851. if (retrievedList != null && retrievedList.size > 0) {
  852. LogUtils.i("从本地取出得双人信息${retrievedList[0].name}")
  853. map["oneUserId"] = "${retrievedList[0].userId}"
  854. map["oneUserName"] = "${retrievedList[0].name}"
  855. map["twoUserId"] = "${retrievedList[1].userId}"
  856. map["twoUserName"] = "${retrievedList[1].name}"
  857. // 清空 SharedPreferences 中的集合
  858. // SharedPreferencesHelper.clearList(this)
  859. }
  860. } catch (e: Exception) {
  861. }
  862. showLoading("加载中...")
  863. val disposable = ApiRepository.lockOperate(map)
  864. .subscribe({ data ->
  865. dismissLoading()
  866. val containsFalse =
  867. mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  868. if (containsFalse) {
  869. showLoading("查询中...")
  870. // 开始执行任务,每 3 秒执行一次
  871. startCountdownLock()
  872. handlerUtil.startTask(task, 1000)
  873. } else {
  874. dismissLoading()
  875. //柜门已开去除化学品
  876. customDialogView(1, "柜门已开,请取出化学品")
  877. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  878. handlerUtil.stopAllTasks()
  879. countdownTimer?.cancel()
  880. viewBinding.openLok.text = "再次开门"
  881. }
  882. }, { throwable ->
  883. dismissLoading()
  884. LogUtils.i("=========开始调用解析失败")
  885. showNetError(throwable)
  886. })
  887. addDisposable(disposable)
  888. }
  889. private var countdownTimer: CountDownTimer? = null
  890. private fun startCountdownLock() {
  891. val totalTime = 30 * 1000 // 30秒
  892. val interval = 1000 // 每秒更新一次
  893. countdownTimer = object : CountDownTimer(totalTime.toLong(), interval.toLong()) {
  894. override fun onTick(millisUntilFinished: Long) {
  895. val secondsLeft = millisUntilFinished / 1000
  896. println("剩余时间: $secondsLeft 秒")
  897. }
  898. override fun onFinish() {
  899. println("倒计时结束!")
  900. mCabinetLockVoList = null
  901. mLockStr.clear()
  902. showToast("开锁超时,可重新操作")
  903. dismissLoading()
  904. handlerUtil.stopAllTasks()
  905. // 在这里执行合适的操作,比如退出应用程序
  906. }
  907. }
  908. println("倒计时开始...")
  909. countdownTimer?.start()
  910. }
  911. override fun onDestroy() {
  912. super.onDestroy()
  913. try {
  914. handlerUtil.stopAllTasks()
  915. countdownTimer?.cancel()
  916. } catch (e: Exception) {
  917. }
  918. try {
  919. timeUpdater.stopUpdating()
  920. } catch (e: Exception) {
  921. }
  922. }
  923. override fun cdFinish() {
  924. finish()
  925. }
  926. //查询柜子 存储位置 默认第一个
  927. private fun getCabinet() {
  928. showLoading("查询中...")
  929. val disposable = ApiRepository.getCabinetList(ChemicalApp.subjectId!!)
  930. .subscribe({ data ->
  931. dismissLoading()
  932. val storageDialog =
  933. StorageDialog(
  934. ct = this,
  935. listData = data!!,
  936. lint = object : StorageDialog.IonClickListener {
  937. override fun onClick(
  938. cabinetId: String,
  939. cabinetName: String,
  940. doorName: String,
  941. doorId: String,
  942. cabinetLockVoList: List<LockVoListBean>,
  943. layers: Int,
  944. lockNum: String,
  945. ) {
  946. mCabinetId = cabinetId
  947. mDoorId = doorId
  948. viewBinding.cabinetName.text = "$cabinetName"
  949. }
  950. override fun onClose() {
  951. mCabinetId = null
  952. mDoorId = null
  953. viewBinding.cabinetName.text = "化学品柜"
  954. }
  955. })
  956. storageDialog.show()
  957. }, { throwable ->
  958. dismissLoading()
  959. showNetError(throwable)
  960. })
  961. addDisposable(disposable)
  962. }
  963. private val task = Runnable {
  964. //判断所有的锁开锁成功
  965. val containsFalse = mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  966. LogUtils.i("=======查询调用开锁状态====$containsFalse")
  967. if (containsFalse) {
  968. getLocks()
  969. } else {
  970. dismissLoading()
  971. //柜门已开去除化学品
  972. customDialogView(1, "柜门已开,请取出化学品")
  973. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_hxp)
  974. handlerUtil.stopAllTasks()
  975. countdownTimer?.cancel()
  976. viewBinding.openLok.text = "再次开门"
  977. }
  978. }
  979. //查询开锁信息
  980. private fun getLocks() {
  981. mCabinetLockVoList!!.forEachIndexed { index, fruit ->
  982. if (fruit.isOk == false && fruit.unlockingMethod == 2) {
  983. getLocksDate(index, fruit.lockNum)
  984. }
  985. }
  986. }
  987. //查询开锁状态
  988. private fun getLocksDate(index: Int, fruit: String) {
  989. val disposable = ApiRepository.getLocks(ChemicalApp.subjectId!!, fruit)
  990. .subscribe({ data ->
  991. LogUtils.i("=======开锁查询成功")
  992. if (data) {
  993. mCabinetLockVoList!![index].isOk = true
  994. LogUtils.i("=======设置成功")
  995. }
  996. }, { throwable ->
  997. LogUtils.i("=======开锁查询成功 解析失败")
  998. dismissLoading()
  999. showNetError(throwable)
  1000. })
  1001. addDisposable(disposable)
  1002. }
  1003. }