WasteChemicalsActivity.kt 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. package xn.hxp.ui.discard
  2. import android.content.IntentFilter
  3. import android.hardware.usb.UsbManager
  4. import android.os.CountDownTimer
  5. import android.os.Handler
  6. import android.os.Looper
  7. import android.view.KeyEvent
  8. import android.view.View
  9. import androidx.core.content.ContextCompat
  10. import androidx.recyclerview.widget.LinearLayoutManager
  11. import androidx.viewbinding.ViewBinding
  12. import com.blankj.utilcode.util.LogUtils
  13. import com.bumptech.glide.Glide
  14. import com.bumptech.glide.load.engine.DiskCacheStrategy
  15. import com.bumptech.glide.request.RequestOptions
  16. import com.rc.core.ui.activity.BaseActivity
  17. import com.rc.httpcore.HttpConfig
  18. import com.rc.httpcore.bean.*
  19. import com.rc.httpcore.client.ApiRepository
  20. import com.rc.httpcore.client.HttpTool
  21. import com.rc.httpcore.exception.NetException
  22. import org.greenrobot.eventbus.EventBus
  23. import org.greenrobot.eventbus.Subscribe
  24. import org.greenrobot.eventbus.ThreadMode
  25. import retrofit2.HttpException
  26. import xn.hxp.R
  27. import xn.hxp.app.ChemicalApp
  28. import xn.hxp.comm.Constants
  29. import xn.hxp.databinding.ActivityWasteChemicalsBinding
  30. import xn.hxp.receiver.OnSerialScanListener
  31. import xn.hxp.receiver.PortScanHelper
  32. import xn.hxp.receiver.UsbReceiver
  33. import xn.hxp.ui.adapter.WasteChemicalsAdapter
  34. import xn.hxp.ui.verify.TwoVerificationActivity
  35. import xn.hxp.utils.*
  36. import xn.hxp.weidith.CustomDialog
  37. import xn.hxp.weidith.DiscardDialog
  38. import xn.hxp.weidith.StorageDialog
  39. import xn.hxp.weidith.TextTool
  40. import java.net.ConnectException
  41. import java.net.SocketTimeoutException
  42. //废弃- 化学品
  43. class WasteChemicalsActivity : BaseActivity() {
  44. private val mAdapter by lazy { WasteChemicalsAdapter(this) }
  45. private var mUsbReceiver: UsbReceiver? = null // 刷卡广播注册
  46. private var mHandleScanEvent = false //当前是否已经获取过 usb返回的参数
  47. private lateinit var mDataBean: ReturnDetailsBean //查询返回单挑信息
  48. private lateinit var mGiveBackBean: GiveBackBean //归还参数
  49. private lateinit var timeUpdater: TimeUpdater
  50. private var mCabinetId: String? = null
  51. private var mDoorId: String? = null
  52. private var mCabinetLockVoList: List<LockVoListBean>? = null //柜锁会又多个
  53. private var mLockStr = ArrayList<String>() //需要打开得柜锁数量
  54. private val handlerUtil = HandlerUtil.getInstance()
  55. // private var mWasteChemicalsListBean: WasteChemicalsListBean? = null
  56. private var mPages = 1 //总页码
  57. private var mDataPage = 10 //返回得总条数
  58. private var page = 1
  59. private var pageSize = 10
  60. private var mTyps = 1
  61. // private var mStockModelList = mutableListOf<ReturnDetailsBean>()
  62. private var mIsLock = false //是否打开过锁 只要是只能锁被打开 就需要进行异常数据上报
  63. lateinit var viewBinding: ActivityWasteChemicalsBinding
  64. override fun setViewBinding(): ViewBinding {
  65. viewBinding = ActivityWasteChemicalsBinding.inflate(layoutInflater)
  66. return viewBinding
  67. }
  68. override fun onInit() {
  69. inAdapter()
  70. viewBinding.tvReturn.text = "返回${ChemicalApp.confs!!.backTime}s"
  71. viewBinding.tvOutLogin.setOnClickListener {
  72. HttpTool.logout()
  73. }
  74. viewBinding.tvReturn.setOnClickListener {
  75. // if (mStockModelList != null && mStockModelList.size > 0) {
  76. if (mIsLock) {
  77. outTimeWarnData()
  78. } else {
  79. finish()
  80. }
  81. }
  82. //废弃 不需要称重
  83. viewBinding.butDiscard.setOnClickListener {
  84. if (viewBinding.linTow.visibility == View.VISIBLE) {
  85. val discardDialog = DiscardDialog(
  86. this,
  87. "${mDataBean.surplus}${mDataBean.specUnit}",
  88. object : DiscardDialog.IClickLit {
  89. override fun onClickClose() {
  90. }
  91. override fun onDetermineClick(cont: String?) {
  92. //调用归还API
  93. mGiveBackBean = GiveBackBean(
  94. id = mDataBean.id,
  95. stockId = mDataBean.id,
  96. stockDetailsId = mDataBean.stockDetailsId,
  97. returnType = 1,
  98. useStatus = 3,
  99. remark = "repeal",
  100. weigh = 1.0,
  101. cabinetId = mDataBean.cabinetId,
  102. cabinetName = mDataBean.cabinetName,
  103. doorId = mDataBean.doorId,
  104. doorName = mDataBean.doorName,
  105. layers = mDataBean.layers.toInt(),
  106. disuseReason = cont
  107. )
  108. try {// 从 SharedPreferences 中取出集合
  109. val retrievedList =
  110. SharedPreferencesHelper.getList(this@WasteChemicalsActivity)
  111. if (retrievedList != null && retrievedList.size > 0) {
  112. mGiveBackBean.backOneUser = "${retrievedList[0].userId}"
  113. mGiveBackBean.backOneUserName = "${retrievedList[0].name}"
  114. mGiveBackBean.backTwoUser = "${retrievedList[1].userId}"
  115. mGiveBackBean.backTwoUserName = "${retrievedList[1].name}"
  116. // 清空 SharedPreferences 中的集合
  117. SharedPreferencesHelper.clearList(this@WasteChemicalsActivity)
  118. }
  119. } catch (e: Exception) {
  120. }
  121. //chemical/aio/giveBack
  122. showLoading("加载中...")
  123. val disposable = ApiRepository.giveBack(mGiveBackBean)
  124. .subscribe({ data ->
  125. dismissLoading()
  126. AudioPlayer.getInstance().play(R.raw.revoked_recycle_hint)
  127. customDialogView(1, "已废弃出库,请及时进行废弃回收")
  128. viewBinding.relOne.visibility = View.GONE
  129. viewBinding.lint3.visibility = View.GONE
  130. viewBinding.linTow.visibility = View.GONE
  131. viewBinding.lintComplete.visibility = View.VISIBLE
  132. viewBinding.surplusTow.text =
  133. "废弃量:${mDataBean.surplus}${mDataBean.specUnit}"
  134. mHandleScanEvent = false
  135. mIsLock = false
  136. stockDetailsList()
  137. }, { throwable ->
  138. dismissLoading()
  139. showNetError(throwable)
  140. })
  141. addDisposable(disposable)
  142. }
  143. override fun onTimerReply() {
  144. }
  145. })
  146. if (!this.isFinishing && !this.isDestroyed) {
  147. discardDialog.show()
  148. }
  149. // discardDialogShow()
  150. } else {
  151. showToast("请扫描或点击需要废弃的化学品")
  152. }
  153. }
  154. viewBinding.butOpen.setOnClickListener {
  155. //再次开门
  156. if (mLockStr != null && mLockStr.size > 0) {
  157. openLock(mLockStr)
  158. } else {
  159. upList(
  160. mDataBean!!.cabinetName,
  161. mDataBean!!.doorName,
  162. mDataBean!!.layers
  163. )
  164. }
  165. }
  166. //化学品柜 查询
  167. viewBinding.relCabinet.setOnClickListener {
  168. getCabinet()
  169. }
  170. //列表查询 EdContDialog
  171. viewBinding.reQuy.setOnClickListener {
  172. page = 1
  173. stockDetailsList()
  174. }
  175. viewBinding.resetting.setOnClickListener {
  176. page = 1
  177. mCabinetId = null
  178. mDoorId = null
  179. viewBinding.cabinetName.text = "化学品柜"
  180. viewBinding.edCont.setText("")
  181. stockDetailsList()
  182. }
  183. val handler = Handler(Looper.getMainLooper())
  184. timeUpdater = TimeUpdater(handler) { currentTime ->
  185. viewBinding.nowTime.text = "$currentTime"
  186. }
  187. // 启动定时更新
  188. timeUpdater.startUpdating()
  189. initTitle()
  190. stockDetailsList()
  191. viewBinding.butUpper.setOnClickListener {
  192. //上一页
  193. if (mDataPage != 0) {
  194. if (mDataPage != 0) {
  195. if (page != 1) {
  196. page--
  197. stockDetailsList()
  198. }
  199. }
  200. }
  201. }
  202. viewBinding.butNext.setOnClickListener {
  203. //下一页
  204. if (mDataPage != 0) {
  205. if (mDataPage != 0) {
  206. if (mDataPage != page) {
  207. page++
  208. stockDetailsList()
  209. }
  210. }
  211. }
  212. }
  213. }
  214. private fun outTimeWarnData() {
  215. var mStockModelList = mutableListOf<TimeWarBean>()
  216. val map = mutableMapOf<String, Any>()
  217. val bean = TimeWarBean()
  218. bean.floorId = ChemicalApp.labInfo!!.floorId
  219. bean.floorName = ChemicalApp.labInfo!!.floorName
  220. bean.subId = ChemicalApp.labInfo!!.subjectId
  221. bean.subName = ChemicalApp.labInfo!!.subjectName
  222. bean.subRoom = ChemicalApp.labInfo!!.room
  223. bean.cabinetName = mDataBean.cabinetName
  224. bean.doorName = mDataBean.doorName
  225. bean.deptName = ChemicalApp.confs!!.deptName
  226. bean.stockTypeStr = "废弃"
  227. mStockModelList.add(bean)
  228. showLoading("提交中...")
  229. map["stockModelList"] = mStockModelList //管控类型
  230. val disposable =
  231. ApiRepository.outTimeWarn(map)
  232. .subscribe({ data ->
  233. dismissLoading()
  234. finish()
  235. }, { throwable ->
  236. dismissLoading()
  237. showNetError(throwable)
  238. })
  239. addDisposable(disposable)
  240. }
  241. // //验证方式
  242. // private fun verifyChecking() {
  243. // val map = mutableMapOf<String, Any>()
  244. // map["chemicalLevel"] = mDataBean.chemicalLevel //管控类型
  245. // map["doorId"] = "${mDataBean.doorId}" //柜子id
  246. // map["mTag"] = 1
  247. // if (ChemicalApp.confs!!.verifyType == "1,2" || ChemicalApp.confs!!.verifyType == "2,1") {
  248. // //人脸+刷卡
  249. // map["hides"] = 0 //隐藏扫码
  250. // UiManager.switcher(this, map, TwoPersonActivity::class.java)
  251. // } else if (ChemicalApp.confs!!.verifyType == "1,3" || ChemicalApp.confs!!.verifyType == "3,1") {
  252. // //人脸+扫码
  253. // map["hides"] = 1 //隐藏刷卡
  254. // UiManager.switcher(this, map, TwoPersonActivity::class.java)
  255. // } else if (ChemicalApp.confs!!.verifyType == "2,3" || ChemicalApp.confs!!.verifyType == "3,2") {
  256. // map["hides"] = 2 //隐藏扫码
  257. // UiManager.switcher(
  258. // this,
  259. // map,
  260. // SwipeCodeTwoActivity::class.java,
  261. // Constants.REQUEST_CODE
  262. // )
  263. // } else {
  264. // //人脸+刷卡+扫码
  265. // map["hides"] = 3
  266. // UiManager.switcher(this, map, TwoPersonActivity::class.java)
  267. // }
  268. // }
  269. //验证方式
  270. private fun verifyChecking() {
  271. val map = mutableMapOf<String, Any>()
  272. map["chemicalLevel"] = mDataBean.chemicalLevel //管控类型
  273. map["doorId"] = "${mDataBean.doorId}" //柜子id
  274. map["mTag"] = 1
  275. map["mVerTyps"] = 0
  276. if (ChemicalApp.confs!!.verifyType == "1,2" || ChemicalApp.confs!!.verifyType == "2,1") {
  277. //人脸+刷卡
  278. map["hides"] = 1
  279. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  280. } else if (ChemicalApp.confs!!.verifyType == "1,3" || ChemicalApp.confs!!.verifyType == "3,1") {
  281. //人脸+扫码
  282. map["hides"] = 2
  283. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  284. } else if (ChemicalApp.confs!!.verifyType == "2,3" || ChemicalApp.confs!!.verifyType == "3,2") {
  285. map["hides"] = 3
  286. // UiManager.switcher(
  287. // this,
  288. // map,
  289. // TwoVerificationActivity::class.java,
  290. // Constants.REQUEST_CODE
  291. // )
  292. } else {
  293. //人脸+刷卡+扫码
  294. map["hides"] = 4
  295. // UiManager.switcher(this, map, TwoVerificationActivity::class.java)
  296. }
  297. UiManager.switcher(
  298. this,
  299. map,
  300. TwoVerificationActivity::class.java,
  301. Constants.REQUEST_CODE
  302. )
  303. }
  304. //查询柜子 存储位置 默认第一个
  305. private fun getCabinet() {
  306. showLoading("查询中...")
  307. val disposable = ApiRepository.getCabinetList(ChemicalApp.subjectId!!)
  308. .subscribe({ data ->
  309. dismissLoading()
  310. val storageDialog =
  311. StorageDialog(
  312. ct = this,
  313. listData = data!!,
  314. lint = object : StorageDialog.IonClickListener {
  315. override fun onClick(
  316. cabinetId: String,
  317. cabinetName: String,
  318. doorName: String,
  319. doorId: String,
  320. cabinetLockVoList: List<LockVoListBean>,
  321. layers: Int,
  322. lockNum: String,
  323. ) {
  324. mCabinetId = cabinetId
  325. mDoorId = doorId
  326. viewBinding.cabinetName.text = "$doorName"
  327. }
  328. override fun onClose() {
  329. if (mCabinetId != null) {
  330. mCabinetId = null
  331. mDoorId = null
  332. viewBinding.cabinetName.text = "化学品柜"
  333. }
  334. }
  335. })
  336. if (!this.isFinishing && !this.isDestroyed) {
  337. storageDialog.show()
  338. }
  339. }, { throwable ->
  340. dismissLoading()
  341. showNetError(throwable)
  342. })
  343. addDisposable(disposable)
  344. }
  345. private fun initTitle() {
  346. viewBinding.tvName.text = ChemicalApp.userData!!.userName
  347. val imageView = viewBinding.imageName
  348. // 使用 Glide 加载网络图片
  349. Glide.with(this)
  350. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.userData!!.avatar}")
  351. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  352. .into(imageView)
  353. // 使用 Glide 加载网络图片
  354. viewBinding.deptName.text = "${ChemicalApp.confs!!.deptName}-${ChemicalApp.confs!!.roomNum}"
  355. Glide.with(this)
  356. .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.confs!!.circularLogo}")
  357. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  358. .into(viewBinding.image)
  359. }
  360. private fun discardDialogShow() {
  361. if (mDataBean.chemicalLevel == 1) {
  362. val discardDialog = DiscardDialog(
  363. this,
  364. "${mDataBean.surplus}${mDataBean.specUnit}",
  365. object : DiscardDialog.IClickLit {
  366. override fun onClickClose() {
  367. }
  368. override fun onDetermineClick(cont: String?) {
  369. //调用归还API
  370. mGiveBackBean = GiveBackBean(
  371. id = mDataBean.id,
  372. stockId = mDataBean.id,
  373. stockDetailsId = mDataBean.stockDetailsId,
  374. returnType = 1,
  375. useStatus = 3,
  376. remark = "repeal",
  377. weigh = 1.0,
  378. cabinetId = mDataBean.cabinetId,
  379. cabinetName = mDataBean.cabinetName,
  380. doorId = mDataBean.doorId,
  381. doorName = mDataBean.doorName,
  382. layers = mDataBean.layers.toInt(),
  383. disuseReason = cont
  384. )
  385. try {// 从 SharedPreferences 中取出集合
  386. val retrievedList =
  387. SharedPreferencesHelper.getList(this@WasteChemicalsActivity)
  388. if (retrievedList != null && retrievedList.size > 0) {
  389. mGiveBackBean.backOneUser = "${retrievedList[0].userId}"
  390. mGiveBackBean.backOneUserName = "${retrievedList[0].name}"
  391. mGiveBackBean.backTwoUser = "${retrievedList[1].userId}"
  392. mGiveBackBean.backTwoUserName = "${retrievedList[1].name}"
  393. // 清空 SharedPreferences 中的集合
  394. SharedPreferencesHelper.clearList(this@WasteChemicalsActivity)
  395. }
  396. } catch (e: Exception) {
  397. }
  398. //chemical/aio/giveBack
  399. showLoading("加载中...")
  400. val disposable = ApiRepository.giveBack(mGiveBackBean)
  401. .subscribe({ data ->
  402. dismissLoading()
  403. AudioPlayer.getInstance().play(R.raw.revoked_recycle_hint)
  404. customDialogView(1, "已废弃出库,请及时进行废弃回收")
  405. viewBinding.relOne.visibility = View.GONE
  406. viewBinding.lint3.visibility = View.GONE
  407. viewBinding.linTow.visibility = View.GONE
  408. viewBinding.lintComplete.visibility = View.VISIBLE
  409. viewBinding.surplusTow.text =
  410. "废弃量:${mDataBean.surplus}${mDataBean.specUnit}"
  411. mHandleScanEvent = false
  412. mIsLock = false
  413. stockDetailsList()
  414. }, { throwable ->
  415. dismissLoading()
  416. showNetError(throwable)
  417. })
  418. addDisposable(disposable)
  419. }
  420. override fun onTimerReply() {
  421. }
  422. })
  423. if (!this.isFinishing && !this.isDestroyed) {
  424. discardDialog.show()
  425. }
  426. } else {
  427. //调用归还API
  428. mGiveBackBean = GiveBackBean(
  429. id = mDataBean.id,
  430. stockId = mDataBean.id,
  431. stockDetailsId = mDataBean.stockDetailsId,
  432. returnType = 1,
  433. useStatus = 3,
  434. remark = "repeal",
  435. weigh = 1.0,
  436. cabinetId = mDataBean.cabinetId,
  437. cabinetName = mDataBean.cabinetName,
  438. doorId = mDataBean.doorId,
  439. doorName = mDataBean.doorName,
  440. layers = mDataBean.layers.toInt()
  441. )
  442. try {// 从 SharedPreferences 中取出集合
  443. val retrievedList = SharedPreferencesHelper.getList(this@WasteChemicalsActivity)
  444. if (retrievedList != null && retrievedList.size > 0) {
  445. mGiveBackBean.backOneUser = "${retrievedList[0].userId}"
  446. mGiveBackBean.backOneUserName = "${retrievedList[0].name}"
  447. mGiveBackBean.backTwoUser = "${retrievedList[1].userId}"
  448. mGiveBackBean.backTwoUserName = "${retrievedList[1].name}"
  449. // 清空 SharedPreferences 中的集合
  450. SharedPreferencesHelper.clearList(this@WasteChemicalsActivity)
  451. }
  452. } catch (e: Exception) {
  453. }
  454. //chemical/aio/giveBack
  455. showLoading("加载中...")
  456. val disposable = ApiRepository.giveBack(mGiveBackBean)
  457. .subscribe({ data ->
  458. dismissLoading()
  459. AudioPlayer.getInstance().play(R.raw.revoked_recycle_hint)
  460. customDialogView(1, "已废弃出库,请及时进行废弃回收")
  461. viewBinding.relOne.visibility = View.GONE
  462. viewBinding.lint3.visibility = View.GONE
  463. viewBinding.linTow.visibility = View.GONE
  464. viewBinding.lintComplete.visibility = View.VISIBLE
  465. viewBinding.surplusTow.text = "废弃量:${mDataBean.surplus}${mDataBean.specUnit}"
  466. mHandleScanEvent = false
  467. mIsLock = false
  468. stockDetailsList()
  469. }, { throwable ->
  470. dismissLoading()
  471. showNetError(throwable)
  472. })
  473. addDisposable(disposable)
  474. }
  475. }
  476. private fun stockDetailsList() {
  477. showLoading("查询中...")
  478. val mutableMap = mutableMapOf<String, String>()
  479. mutableMap["subId"] = "${ChemicalApp.subjectId!!}"
  480. mutableMap["status"] = "1"
  481. if (mCabinetId != null) {
  482. mutableMap["cabinetId"] = "$mCabinetId"
  483. }
  484. if (mDoorId != null) {
  485. mutableMap["doorId"] = "$mDoorId"
  486. }
  487. var toString = viewBinding.edCont.text.toString()
  488. LogUtils.i("======ceshi======$toString")
  489. if (toString.isNotEmpty()) {
  490. mutableMap["searchValue"] = "$toString"
  491. }
  492. mutableMap["page"] = "$page"
  493. mutableMap["pageSize"] = "$pageSize"
  494. val disposable =
  495. ApiRepository.stockDetailsList(mutableMap)
  496. .subscribe({ data ->
  497. dismissLoading()
  498. if (mAdapter.data != null) {
  499. mAdapter.data.clear()
  500. mAdapter.notifyDataSetChanged()
  501. initPagesView(data.pages)
  502. }
  503. mDataPage = data.pages //总页
  504. LogUtils.i("===条==${data.pages} ===条==${data.current}")
  505. if (data.pages != 0) {
  506. if (data.pages > 1 && data.current > 1) {
  507. //当前需要更新页码
  508. upPagesView(data.pages, data.current)
  509. mAdapter.setList(data.records.toMutableList())
  510. } else {
  511. mAdapter.setNewInstance(data.records.toMutableList())
  512. initPagesView(data.pages)
  513. }
  514. }
  515. }, { throwable ->
  516. dismissLoading()
  517. showNetError(throwable)
  518. })
  519. addDisposable(disposable)
  520. }
  521. /**
  522. * 总页码 当前页 初始化
  523. */
  524. private fun initPagesView(pages: Int) {
  525. mPages = pages
  526. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  527. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  528. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  529. viewBinding.one.setTextColor(ContextCompat.getColor(this, R.color.white))
  530. viewBinding.two.setTextColor(ContextCompat.getColor(this, R.color.black))
  531. when (pages) {
  532. 1 -> {
  533. viewBinding.one.visibility = View.VISIBLE
  534. }
  535. 2 -> {
  536. viewBinding.two.visibility = View.VISIBLE
  537. }
  538. 3 -> {
  539. viewBinding.two.visibility = View.VISIBLE
  540. viewBinding.three.visibility = View.VISIBLE
  541. }
  542. else -> {
  543. viewBinding.two.visibility = View.VISIBLE
  544. viewBinding.three.visibility = View.VISIBLE
  545. viewBinding.drop.visibility = View.VISIBLE
  546. viewBinding.many.visibility = View.VISIBLE
  547. viewBinding.many.text = "$pages"
  548. }
  549. }
  550. if (pages == 1 || pages == 0) {
  551. viewBinding.two.visibility = View.GONE
  552. viewBinding.three.visibility = View.GONE
  553. viewBinding.many.visibility = View.GONE
  554. viewBinding.drop.visibility = View.GONE
  555. }
  556. if (pages < 4) {
  557. when (pages) {
  558. 1 -> {
  559. viewBinding.two.visibility = View.GONE
  560. viewBinding.three.visibility = View.GONE
  561. viewBinding.many.visibility = View.GONE
  562. viewBinding.drop.visibility = View.GONE
  563. }
  564. 2 -> {
  565. viewBinding.three.visibility = View.GONE
  566. viewBinding.many.visibility = View.GONE
  567. viewBinding.drop.visibility = View.GONE
  568. }
  569. 3 -> {
  570. viewBinding.many.visibility = View.GONE
  571. viewBinding.drop.visibility = View.GONE
  572. }
  573. }
  574. }
  575. }
  576. //更新页码
  577. private fun upPagesView(pages: Int, current: Int) {
  578. LogUtils.i("======2")
  579. if (pages < 4) {
  580. // viewBinding.one.visibility = View.VISIBLE
  581. when (pages) {
  582. 1 -> {
  583. viewBinding.two.visibility = View.GONE
  584. viewBinding.three.visibility = View.GONE
  585. viewBinding.many.visibility = View.GONE
  586. viewBinding.drop.visibility = View.GONE
  587. }
  588. 2 -> {
  589. viewBinding.three.visibility = View.GONE
  590. viewBinding.many.visibility = View.GONE
  591. viewBinding.drop.visibility = View.GONE
  592. }
  593. 3 -> {
  594. viewBinding.many.visibility = View.GONE
  595. viewBinding.drop.visibility = View.GONE
  596. }
  597. }
  598. when (current) {
  599. 1 -> {
  600. viewBinding.one.setTextColor(
  601. ContextCompat.getColor(
  602. this,
  603. R.color.white
  604. )
  605. )
  606. viewBinding.two.setTextColor(
  607. ContextCompat.getColor(
  608. this,
  609. R.color.black
  610. )
  611. )
  612. viewBinding.three.setTextColor(
  613. ContextCompat.getColor(
  614. this,
  615. R.color.black
  616. )
  617. )
  618. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  619. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  620. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  621. }
  622. 2 -> {
  623. // viewBinding.two.visibility = View.VISIBLE
  624. viewBinding.one.setTextColor(
  625. ContextCompat.getColor(
  626. this,
  627. R.color.black
  628. )
  629. )
  630. viewBinding.two.setTextColor(
  631. ContextCompat.getColor(
  632. this,
  633. R.color.white
  634. )
  635. )
  636. viewBinding.three.setTextColor(
  637. ContextCompat.getColor(
  638. this,
  639. R.color.black
  640. )
  641. )
  642. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  643. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
  644. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  645. }
  646. 3 -> {
  647. // viewBinding.three.visibility = View.VISIBLE
  648. viewBinding.one.setTextColor(
  649. ContextCompat.getColor(
  650. this,
  651. R.color.black
  652. )
  653. )
  654. viewBinding.two.setTextColor(
  655. ContextCompat.getColor(
  656. this,
  657. R.color.black
  658. )
  659. )
  660. viewBinding.three.setTextColor(
  661. ContextCompat.getColor(
  662. this,
  663. R.color.white
  664. )
  665. )
  666. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  667. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  668. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  669. }
  670. }
  671. } else {
  672. // viewBinding.many.visibility = View.VISIBLE
  673. viewBinding.three.text = "3"
  674. when (current) {
  675. 1 -> {
  676. viewBinding.one.setTextColor(
  677. ContextCompat.getColor(
  678. this,
  679. R.color.white
  680. )
  681. )
  682. viewBinding.two.setTextColor(
  683. ContextCompat.getColor(
  684. this,
  685. R.color.black
  686. )
  687. )
  688. viewBinding.three.setTextColor(
  689. ContextCompat.getColor(
  690. this,
  691. R.color.black
  692. )
  693. )
  694. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_page)
  695. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  696. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  697. }
  698. 2 -> {
  699. viewBinding.one.setTextColor(
  700. ContextCompat.getColor(
  701. this,
  702. R.color.black
  703. )
  704. )
  705. viewBinding.two.setTextColor(
  706. ContextCompat.getColor(
  707. this,
  708. R.color.white
  709. )
  710. )
  711. viewBinding.three.setTextColor(
  712. ContextCompat.getColor(
  713. this,
  714. R.color.black
  715. )
  716. )
  717. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  718. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_page)
  719. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  720. }
  721. 3 -> {
  722. viewBinding.one.setTextColor(
  723. ContextCompat.getColor(
  724. this,
  725. R.color.black
  726. )
  727. )
  728. viewBinding.two.setTextColor(
  729. ContextCompat.getColor(
  730. this,
  731. R.color.black
  732. )
  733. )
  734. viewBinding.three.setTextColor(
  735. ContextCompat.getColor(
  736. this,
  737. R.color.white
  738. )
  739. )
  740. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  741. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  742. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  743. }
  744. else -> {
  745. viewBinding.three.text = "$current"
  746. if (pages == current) {
  747. viewBinding.three.text = "${current - 1}"
  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.black
  764. )
  765. )
  766. viewBinding.many.setTextColor(
  767. ContextCompat.getColor(
  768. this,
  769. R.color.white
  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_two_page)
  775. viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_page)
  776. } else {
  777. viewBinding.one.setTextColor(
  778. ContextCompat.getColor(
  779. this,
  780. R.color.black
  781. )
  782. )
  783. viewBinding.two.setTextColor(
  784. ContextCompat.getColor(
  785. this,
  786. R.color.black
  787. )
  788. )
  789. viewBinding.three.setTextColor(
  790. ContextCompat.getColor(
  791. this,
  792. R.color.white
  793. )
  794. )
  795. viewBinding.many.setTextColor(
  796. ContextCompat.getColor(
  797. this,
  798. R.color.black
  799. )
  800. )
  801. viewBinding.one.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  802. viewBinding.two.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  803. viewBinding.three.setBackgroundResource(R.drawable.bg_sou_suo_page)
  804. viewBinding.many.setBackgroundResource(R.drawable.bg_sou_suo_two_page)
  805. }
  806. }
  807. }
  808. }
  809. }
  810. private fun inAdapter() {
  811. viewBinding.rvView?.layoutManager = LinearLayoutManager(this)
  812. viewBinding.rvView?.adapter = mAdapter
  813. //点击左侧进行 废弃
  814. mAdapter.setOnItemClickListener { adapter, view, position ->
  815. mAdapter.data.forEach { it.isType = false }
  816. mAdapter.data[position].isType = true
  817. mAdapter.notifyDataSetChanged()
  818. // mDataBean = mAdapter.data[position]
  819. try {
  820. codeDateIn(mAdapter.data[position].tagCode)
  821. } catch (e: Exception) {
  822. showToast("参数异常")
  823. }
  824. }
  825. }
  826. private fun upList(cabinetName: String, doorName: String, layers: String) {
  827. viewBinding.relOne.visibility = View.GONE
  828. viewBinding.linTow.visibility = View.GONE
  829. viewBinding.lintComplete.visibility = View.GONE
  830. viewBinding.cabinet.text =
  831. "${cabinetName}-${doorName}-${layers}层"
  832. }
  833. private fun upListTwo(cabinetName: String, doorName: String, layers: String) {
  834. viewBinding.relOne.visibility = View.GONE
  835. viewBinding.lint3.visibility = View.VISIBLE
  836. viewBinding.linTow.visibility = View.GONE
  837. viewBinding.lintComplete.visibility = View.GONE
  838. viewBinding.cabinet.text =
  839. "${cabinetName}-${doorName}-${layers}层"
  840. }
  841. private fun upView() {
  842. viewBinding.relOne.visibility = View.GONE
  843. viewBinding.lint3.visibility = View.GONE
  844. viewBinding.linTow.visibility = View.VISIBLE
  845. viewBinding.lintComplete.visibility = View.GONE
  846. viewBinding.chemicalName.text = "${mDataBean.chemicalName}"
  847. viewBinding.chemicalName.setOnClickListener {
  848. TextTool.showPop(this, viewBinding.chemicalName)
  849. }
  850. viewBinding.chemicalLevelName.text = "${mDataBean.chemicalLevelName}"
  851. viewBinding.chemicalCategoryName.text = "${mDataBean.chemicalCategoryName}"
  852. viewBinding.tagCode.text = "编码${mDataBean.tagCode}"
  853. // specNum/specUnit/packUnit
  854. viewBinding.spec.text = "${mDataBean.specNum}${mDataBean.specUnit}/${mDataBean.packUnit}"
  855. viewBinding.belongName.text = "${mDataBean.belongName}"
  856. viewBinding.surplus.text = "${mDataBean.surplus}${mDataBean.specUnit}"
  857. if (mDataBean.expireTime != null) {
  858. viewBinding.expireTime.text = "${mDataBean.expireTime}"
  859. }
  860. viewBinding.storage.text =
  861. "${mDataBean.cabinetName}-${mDataBean.doorName}-${mDataBean.layers}层"
  862. if (mDataBean.expireStatus == 1) {
  863. viewBinding.tvNoName.visibility = View.VISIBLE
  864. }
  865. }
  866. //=========================刷卡start================
  867. //刷卡信息 调用当前化学品信息 进行归还
  868. private fun handleScanEvent(cont: String) {
  869. showLoading("查询中...")
  870. val disposable = ApiRepository.discardDetail(cont)
  871. .subscribe({ data ->
  872. dismissLoading()
  873. mDataBean = data
  874. upView()
  875. mHandleScanEvent = false
  876. }, { throwable ->
  877. dismissLoading()
  878. mHandleScanEvent = false
  879. throwableView(throwable)
  880. })
  881. addDisposable(disposable)
  882. }
  883. //通过化学品code码确定当前是否需要双人认证业务
  884. private fun codeDateIn(tagCode: String) {
  885. showLoading("查询中...")
  886. val disposable = ApiRepository.discardDetail(tagCode)
  887. .subscribe({ data ->
  888. dismissLoading()
  889. mDataBean = data
  890. if (mDataBean.verify) {
  891. //需要双人认证
  892. if (ChemicalApp.confs!!.verifyType.length == 1) {
  893. val map = mutableMapOf<String, Any>()
  894. map["chemicalLevel"] = mDataBean.chemicalLevel //管控类型
  895. // map["doorId"] = "$mDoorId" //柜子id
  896. map["doorId"] = "${data.doorId}" //柜子id
  897. map["mTag"] = 1
  898. when (ChemicalApp.confs!!.verifyType) {
  899. "1" -> {//人脸
  900. map["mVerTyps"] = 1
  901. }
  902. "2" -> {//刷卡
  903. map["mVerTyps"] = 2
  904. }
  905. "3" -> {//扫码
  906. map["mVerTyps"] = 3
  907. }
  908. }
  909. UiManager.switcher(
  910. this,
  911. map,
  912. TwoVerificationActivity::class.java
  913. )
  914. } else {
  915. //多类型双人认证
  916. verifyChecking()
  917. }
  918. } else {
  919. mTyps = 2
  920. showLoading("查询中...")
  921. val disposable =
  922. ApiRepository.getCabinetLock(mDataBean!!.doorId)
  923. .subscribe({ data ->
  924. dismissLoading()
  925. mCabinetLockVoList = data
  926. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  927. mLockStr.clear()
  928. mCabinetLockVoList!!.forEach { it ->
  929. when (it.unlockingMethod) {
  930. 2 -> { //智能锁
  931. mLockStr.add("${it.lockNum}")
  932. }
  933. }
  934. }
  935. if (mLockStr != null && mLockStr.size > 0) {
  936. viewBinding.butOpen.visibility = View.VISIBLE
  937. openLock(mLockStr)
  938. } else {
  939. viewBinding.butOpen.visibility = View.GONE
  940. //没有锁 直接显示 需要扫描化学品信息
  941. upListTwo(
  942. mDataBean!!.cabinetName,
  943. mDataBean!!.doorName,
  944. mDataBean!!.layers
  945. )
  946. }
  947. } else {
  948. //没有锁 直接显示 需要扫描化学品信息
  949. upListTwo(
  950. mDataBean!!.cabinetName,
  951. mDataBean!!.doorName,
  952. mDataBean!!.layers
  953. )
  954. }
  955. }, { throwable ->
  956. dismissLoading()
  957. showNetError(throwable)
  958. })
  959. addDisposable(disposable)
  960. }
  961. }, { throwable ->
  962. dismissLoading()
  963. throwableView(throwable)
  964. })
  965. addDisposable(disposable)
  966. }
  967. /**
  968. * 异常处理
  969. */
  970. private fun throwableView(throwable: Throwable) {
  971. when (throwable) {
  972. is NetException -> {
  973. if (throwable.message.isNullOrEmpty()) {
  974. "接口请求失败(${throwable.code})"
  975. } else {
  976. throwable.message!!
  977. }
  978. }
  979. is SocketTimeoutException -> "请求超时,请稍后重试"
  980. is ConnectException -> "无法连接服务器,请检查网络"
  981. is HttpException -> "服务器繁忙,请稍后重试"
  982. else -> null
  983. }?.let { customDialogView(2, "$it") }
  984. }
  985. private val mPortScanHelper by lazy {
  986. PortScanHelper(this, object : OnSerialScanListener {
  987. override fun dispatchScanEvent(type: OnSerialScanListener.ScanType, content: String) {
  988. if (!mHandleScanEvent) {
  989. if (content.isNotBlank()) {
  990. LogUtils.i("==========当前usb返回参数$content $type")
  991. mHandleScanEvent = true
  992. //所有通过查询二维码的参数 需要先判断 http开头的 然后进行截取
  993. if (content.startsWith("http")) {
  994. try {
  995. val currentDateTimeString =
  996. BigDecimalUtils.extractParameterValue(content, "code")
  997. LogUtils.i("=======ce $currentDateTimeString")
  998. // if (mDataBean.rfidCode == null) {
  999. // mDataBean.rfidCode = "-1"
  1000. // }
  1001. handleScanEvent(currentDateTimeString!!)
  1002. // if (mDataBean.tagCode == currentDateTimeString || currentDateTimeString == mDataBean.rfidCode!!) {
  1003. // handleScanEvent(currentDateTimeString!!)
  1004. // } else {
  1005. // showToast("请检查化学品标签是否一致")
  1006. // mHandleScanEvent = false
  1007. // }
  1008. } catch (e: Exception) {
  1009. showToast("扫码失败,请重新扫码")
  1010. mHandleScanEvent = false
  1011. }
  1012. } else {
  1013. // if (mDataBean.rfidCode == null) {
  1014. // mDataBean.rfidCode = "-1"
  1015. // }
  1016. // if (mDataBean.tagCode == content || content == mDataBean.rfidCode!!) {
  1017. // handleScanEvent(content)
  1018. // } else {
  1019. // showToast("请检查化学品标签是否一致")
  1020. // mHandleScanEvent = false
  1021. // }
  1022. handleScanEvent(content)
  1023. }
  1024. }
  1025. }
  1026. }
  1027. })
  1028. }
  1029. //刷卡usb链接
  1030. private fun registerUsbBroadcast() {
  1031. if (null == mUsbReceiver) {
  1032. val filter = IntentFilter().apply {
  1033. addAction(UsbReceiver.ACTION_USB_PERMISSION)
  1034. addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
  1035. addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
  1036. addAction(UsbReceiver.ACTION_USB_STATE) // usb连接状态广播
  1037. }
  1038. mUsbReceiver = UsbReceiver()
  1039. registerReceiver(mUsbReceiver, filter)
  1040. }
  1041. }
  1042. override fun onResume() {
  1043. super.onResume()
  1044. mPortScanHelper.onResume()
  1045. try {
  1046. if (Constants.AUTHENTICATION) {
  1047. mTyps = 2
  1048. showLoading("查询中...")
  1049. val disposable =
  1050. ApiRepository.getCabinetLock(mDataBean!!.doorId)
  1051. .subscribe({ data ->
  1052. dismissLoading()
  1053. mCabinetLockVoList = data
  1054. if (mCabinetLockVoList != null && mCabinetLockVoList!!.size > 0) {
  1055. mLockStr.clear()
  1056. mCabinetLockVoList!!.forEach { it ->
  1057. when (it.unlockingMethod) {
  1058. 2 -> { //智能锁
  1059. mLockStr.add("${it.lockNum}")
  1060. }
  1061. }
  1062. }
  1063. if (mLockStr != null && mLockStr.size > 0) {
  1064. viewBinding.butOpen.visibility = View.VISIBLE
  1065. openLock(mLockStr)
  1066. } else {
  1067. viewBinding.butOpen.visibility = View.GONE
  1068. //没有锁 直接显示 需要扫描化学品信息
  1069. upListTwo(
  1070. mDataBean!!.cabinetName,
  1071. mDataBean!!.doorName,
  1072. mDataBean!!.layers
  1073. )
  1074. }
  1075. } else {
  1076. //没有锁 直接显示 需要扫描化学品信息
  1077. upListTwo(
  1078. mDataBean!!.cabinetName,
  1079. mDataBean!!.doorName,
  1080. mDataBean!!.layers
  1081. )
  1082. }
  1083. }, { throwable ->
  1084. dismissLoading()
  1085. showNetError(throwable)
  1086. })
  1087. addDisposable(disposable)
  1088. }
  1089. } catch (e: Exception) {
  1090. Constants.AUTHENTICATION = false
  1091. }
  1092. registerUsbBroadcast()
  1093. }
  1094. //获取刷卡信息
  1095. override fun dispatchKeyEvent(event: KeyEvent): Boolean {
  1096. mPortScanHelper.dispatchKeyEvent(event)
  1097. return super.dispatchKeyEvent(event)
  1098. }
  1099. //停止 销毁广播传递
  1100. override fun onPause() {
  1101. mPortScanHelper.onPause()
  1102. super.onPause()
  1103. }
  1104. override fun onDestroy() {
  1105. super.onDestroy()
  1106. mPortScanHelper.onPause()
  1107. try {
  1108. handlerUtil.stopAllTasks()
  1109. countdownTimer?.cancel()
  1110. } catch (e: Exception) {
  1111. }
  1112. try {
  1113. timeUpdater.stopUpdating()
  1114. } catch (e: Exception) {
  1115. }
  1116. // 停止定时更新
  1117. unregisterReceiver(mUsbReceiver)
  1118. EventBus.getDefault().unregister(this) //关闭广播
  1119. }
  1120. //必须写这个方法 防止注册失败
  1121. @Subscribe(threadMode = ThreadMode.MAIN)
  1122. fun onUpdateEventEvent(event: KeyEvent) {
  1123. }
  1124. //=========================刷卡end==================
  1125. override fun onBackPressed() {
  1126. super.onBackPressed()
  1127. finish()
  1128. }
  1129. override fun cdTime(cd: Int) {
  1130. viewBinding.tvReturn.text = "返回${cd}s"
  1131. }
  1132. //=================开锁流程================
  1133. private fun openLock(mLockStr: ArrayList<String>) {
  1134. val map = mutableMapOf<String, Any>()
  1135. map["subId"] = ChemicalApp.subjectId!!
  1136. map["subName"] = ChemicalApp.subjectName!!
  1137. map["cabinetId"] = "${mDataBean.cabinetId}"
  1138. map["cabinetName"] = "${mDataBean.cabinetName}"
  1139. map["doorId"] = "${mDataBean.doorId}"
  1140. map["doorName"] = "${mDataBean.doorName}"
  1141. map["lockNumList"] = mLockStr
  1142. map["operationType"] = 5
  1143. if (ChemicalApp.subRoom != null) {
  1144. map["subRoom"] = ChemicalApp.subRoom!!
  1145. }
  1146. map["type"] = true
  1147. try {// 从 SharedPreferences 中取出集合
  1148. val retrievedList = SharedPreferencesHelper.getList(this)
  1149. if (retrievedList != null && retrievedList.size > 0) {
  1150. LogUtils.i("从本地取出得双人信息${retrievedList[0].name}")
  1151. map["oneUserId"] = "${retrievedList[0].userId}"
  1152. map["oneUserName"] = "${retrievedList[0].name}"
  1153. map["twoUserId"] = "${retrievedList[1].userId}"
  1154. map["twoUserName"] = "${retrievedList[1].name}"
  1155. // 清空 SharedPreferences 中的集合
  1156. // SharedPreferencesHelper.clearList(this)
  1157. }
  1158. } catch (e: Exception) {
  1159. }
  1160. showLoading("加载中...")
  1161. val disposable = ApiRepository.lockOperate(map)
  1162. .subscribe({ data ->
  1163. dismissLoading()
  1164. val containsFalse =
  1165. mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  1166. if (containsFalse) {
  1167. showLoading("查询中...")
  1168. // 开始执行任务,每 1 秒执行一次
  1169. startCountdownLock()
  1170. handlerUtil.startTask(task, 1000)
  1171. }
  1172. }, { throwable ->
  1173. dismissLoading()
  1174. showNetError(throwable)
  1175. })
  1176. addDisposable(disposable)
  1177. }
  1178. private var countdownTimer: CountDownTimer? = null
  1179. private fun startCountdownLock() {
  1180. val totalTime = 30 * 1000 // 30秒
  1181. val interval = 1000 // 每秒更新一次
  1182. countdownTimer = object : CountDownTimer(totalTime.toLong(), interval.toLong()) {
  1183. override fun onTick(millisUntilFinished: Long) {
  1184. val secondsLeft = millisUntilFinished / 1000
  1185. println("剩余时间: $secondsLeft 秒")
  1186. }
  1187. override fun onFinish() {
  1188. println("倒计时结束!")
  1189. mCabinetLockVoList = null
  1190. mLockStr.clear()
  1191. showToast("开锁超时,可重新操作")
  1192. dismissLoading()
  1193. handlerUtil.stopAllTasks()
  1194. // 在这里执行合适的操作,比如退出应用程序
  1195. }
  1196. }
  1197. println("倒计时开始...")
  1198. countdownTimer?.start()
  1199. }
  1200. private val task = Runnable {
  1201. //判断所有的锁开锁成功
  1202. val containsFalse = mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
  1203. if (containsFalse) {
  1204. getLocks()
  1205. } else {
  1206. dismissLoading()
  1207. mIsLock = true
  1208. // discardDialogShow()
  1209. //没有锁 直接显示 需要扫描化学品信息
  1210. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai_qu_chu_fq_hxp)
  1211. handlerUtil.stopAllTasks()
  1212. countdownTimer?.cancel()
  1213. // mStockModelList.add(mDataBean)
  1214. if (mTyps == 1) {
  1215. upList(
  1216. mDataBean!!.cabinetName,
  1217. mDataBean!!.doorName,
  1218. mDataBean!!.layers
  1219. )
  1220. } else {
  1221. upListTwo(
  1222. mDataBean!!.cabinetName,
  1223. mDataBean!!.doorName,
  1224. mDataBean!!.layers
  1225. )
  1226. }
  1227. }
  1228. }
  1229. //查询开锁信息
  1230. private fun getLocks() {
  1231. mCabinetLockVoList!!.forEachIndexed { index, fruit ->
  1232. if (fruit.isOk == false && fruit.unlockingMethod == 2) {
  1233. getLocksDate(index, fruit.lockNum)
  1234. }
  1235. }
  1236. }
  1237. //查询开锁状态
  1238. private fun getLocksDate(index: Int, fruit: String) {
  1239. val disposable = ApiRepository.getLocks(ChemicalApp.subjectId!!, fruit)
  1240. .subscribe({ data ->
  1241. if (data) {
  1242. mCabinetLockVoList!![index].isOk = true
  1243. }
  1244. }, { throwable ->
  1245. dismissLoading()
  1246. showNetError(throwable)
  1247. })
  1248. addDisposable(disposable)
  1249. }
  1250. /**
  1251. * 0 没有图标 1 绿色(成功) 2红色(失败)
  1252. * 失败或者成功的弹框
  1253. */
  1254. private fun customDialogView(types: Int, msg: String) {
  1255. val customDialog = CustomDialog(this, types, msg)
  1256. if (!this.isFinishing && !this.isDestroyed) {
  1257. customDialog.show()
  1258. }
  1259. }
  1260. //自动返回了
  1261. override fun cdFinish() {
  1262. finish()
  1263. }
  1264. }