| | |
| | | override fun onNext(t: BaseResponse<String>) { |
| | | if (t.success) { |
| | | // 上报成功,更新本地数据库isReported为true |
| | | updateCardReportedStatus(cardAddr, orderNumber) |
| | | updateCardReportedStatus(cardAddr, orderNumber, operationTypeCode) |
| | | } else { |
| | | // 上报失败,记录错误但不影响用户操作 |
| | | CrashReport.postCatchedException(Exception("上报写卡结果失败: ${t.msg}")) |
| | |
| | | |
| | | /** |
| | | * 更新本地数据库中的上报状态 |
| | | * 将CardRegistrationBean中的isReported状态设置为true |
| | | * 根据操作类型判断是更新ManagerCardBean还是CardRegistrationBean的isReported状态为true |
| | | * |
| | | * @param cardNumber 卡号 |
| | | * @param orderNumber 订单号 |
| | | * @param operationTypeCode 操作类型代码 |
| | | */ |
| | | private fun updateCardReportedStatus(cardNumber: String, orderNumber: String = "") { |
| | | private fun updateCardReportedStatus(cardNumber: String, orderNumber: String = "", operationTypeCode: Int = -1) { |
| | | lifecycleScope.launch { |
| | | try { |
| | | val cardRegistrationDao = BaseDaoSingleton.getInstance(this@MainActivity) |
| | | .cardRegistrationDao() |
| | | |
| | | // 根据订单号查找CardRegistrationBean记录 |
| | | val cardRegistration = if (orderNumber.isNotEmpty()) { |
| | | cardRegistrationDao.getByOrderId(orderNumber) |
| | | } else { |
| | | // 如果没有订单号,则通过卡号查找 |
| | | cardRegistrationDao.getByCardNumber(cardNumber) |
| | | } |
| | | val baseDaoSingleton = BaseDaoSingleton.getInstance(this@MainActivity) |
| | | |
| | | if (cardRegistration != null) { |
| | | // 创建更新后的CardRegistrationBean对象,将isReported设置为true |
| | | val updatedCardRegistration = cardRegistration.copy(isReported = true) |
| | | // 更新数据库记录 |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | // 根据操作类型判断是管理卡还是用户卡操作 |
| | | val isManagerCardOperation = operationTypeCode in 100..108 |
| | | |
| | | if (isManagerCardOperation) { |
| | | // 管理卡制作操作类型,查询和更新ManagerCardBean |
| | | val managerCardDao = baseDaoSingleton.managerCardDao() |
| | | val managerCard = if (orderNumber.isNotEmpty()) { |
| | | managerCardDao.getByOrderId(orderNumber) |
| | | } else { |
| | | managerCardDao.getByCardAddress(cardNumber) |
| | | } |
| | | |
| | | if (managerCard != null) { |
| | | val updatedManagerCard = managerCard.copy(isReported = true) |
| | | managerCardDao.update(updatedManagerCard) |
| | | } |
| | | } else { |
| | | // 用户卡操作类型,查询和更新CardRegistrationBean |
| | | val cardRegistrationDao = baseDaoSingleton.cardRegistrationDao() |
| | | val cardRegistration = if (orderNumber.isNotEmpty()) { |
| | | cardRegistrationDao.getByOrderId(orderNumber) |
| | | } else { |
| | | // 如果没有订单号,则通过卡号查找 |
| | | cardRegistrationDao.getByCardNumber(cardNumber) |
| | | } |
| | | |
| | | if (cardRegistration != null) { |
| | | // 创建更新后的CardRegistrationBean对象,将isReported设置为true |
| | | val updatedCardRegistration = cardRegistration.copy(isReported = true) |
| | | // 更新数据库记录 |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | } |
| | | } |
| | | } catch (e: Exception) { |
| | | // 记录异常信息,但不影响用户操作 |