| | |
| | | |
| | | /** |
| | | * 更新本地数据库中的写卡状态 |
| | | * 将CardRegistrationBean中的isCardWritten状态设置为true |
| | | * 根据操作类型判断是更新ManagerCardBean还是CardRegistrationBean的isCardWritten状态为true |
| | | * 然后跳转到写卡成功界面,并通知MainActivity调用postCardData |
| | | * |
| | | * @param cardNumber 卡号 |
| | |
| | | private fun updateCardWrittenStatus(cardNumber: String) { |
| | | lifecycleScope.launch { |
| | | try { |
| | | val cardRegistrationDao = BaseDaoSingleton.getInstance(this@NfcWreatActivity) |
| | | .cardRegistrationDao() |
| | | |
| | | // 根据订单号查找CardRegistrationBean记录 |
| | | val cardRegistration = cardRegistrationDao.getByOrderId(orderNumber) |
| | | |
| | | if (cardRegistration != null) { |
| | | // 创建更新后的CardRegistrationBean对象,将isCardWritten设置为true |
| | | val updatedCardRegistration = cardRegistration.copy(isCardWritten = true) |
| | | // 更新数据库记录 |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | |
| | | // 在主线程中关闭Activity并跳转到成功页面 |
| | | runOnUiThread { |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | |
| | | // 跳转到写卡成功界面 |
| | | Intent(this@NfcWreatActivity, CardWriteSuccessActivity::class.java).apply { |
| | | putExtra("cardNumber", cardNumber) |
| | | if (::userCard.isInitialized) { |
| | | putExtra("userCard", userCard) |
| | | } |
| | | putExtra("operationTypeCode", operationTypeCode) |
| | | startActivity(this) |
| | | } |
| | | |
| | | // 通知MainActivity调用postCardData |
| | | notifyMainActivityToPostCardData(cardNumber) |
| | | val baseDaoSingleton = BaseDaoSingleton.getInstance(this@NfcWreatActivity) |
| | | |
| | | // 根据操作类型判断是管理卡还是用户卡操作 |
| | | val isManagerCardOperation = operationTypeCode in 100..108 |
| | | |
| | | var updateSuccess = false |
| | | |
| | | if (isManagerCardOperation) { |
| | | // 管理卡制作操作类型,查询和更新ManagerCardBean |
| | | val managerCardDao = baseDaoSingleton.managerCardDao() |
| | | val managerCard = managerCardDao.getByOrderId(orderNumber) |
| | | |
| | | if (managerCard != null) { |
| | | val updatedManagerCard = managerCard.copy(isCardWritten = true) |
| | | managerCardDao.update(updatedManagerCard) |
| | | updateSuccess = true |
| | | } |
| | | } else { |
| | | // 用户卡操作类型,查询和更新CardRegistrationBean |
| | | val cardRegistrationDao = baseDaoSingleton.cardRegistrationDao() |
| | | val cardRegistration = cardRegistrationDao.getByOrderId(orderNumber) |
| | | |
| | | if (cardRegistration != null) { |
| | | val updatedCardRegistration = cardRegistration.copy(isCardWritten = true) |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | updateSuccess = true |
| | | } |
| | | } |
| | | |
| | | // 无论是否找到记录,都跳转到成功界面 |
| | | runOnUiThread { |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | |
| | | // 跳转到写卡成功界面 |
| | | Intent(this@NfcWreatActivity, CardWriteSuccessActivity::class.java).apply { |
| | | putExtra("cardNumber", cardNumber) |
| | | if (::userCard.isInitialized) { |
| | | putExtra("userCard", userCard) |
| | | } |
| | | putExtra("operationTypeCode", operationTypeCode) |
| | | startActivity(this) |
| | | } |
| | | |
| | | // 通知MainActivity调用postCardData |
| | | notifyMainActivityToPostCardData(cardNumber) |
| | | } |
| | | |
| | | } catch (e: Exception) { |
| | | // 记录异常信息 |
| | | CrashReport.postCatchedException(e) |