| | |
| | | import com.dayu.general.bean.card.ClearCard |
| | | import com.dayu.general.bean.card.DebugCard |
| | | import com.dayu.general.bean.card.UserCard |
| | | import com.dayu.general.bean.net.CardInfoResult |
| | | import com.dayu.general.dao.BaseDaoSingleton |
| | | import com.dayu.general.databinding.ActivityNfcWriteGeBinding |
| | | import com.dayu.general.net.ApiManager |
| | |
| | | /** 项目号(1-255) */ |
| | | private var projectNumber: String = "" |
| | | |
| | | private var cardInfo: CardInfoResult? = null |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | | binding = ActivityNfcWriteGeBinding.inflate(layoutInflater) |
| | |
| | | operationTypeCode = intent?.getIntExtra("operationTypeCode", -1) ?: -1 |
| | | orderNumber = intent?.getStringExtra("orderNumber") ?: "" |
| | | operationType = CardOperationType.fromCode(operationTypeCode) |
| | | cardInfo = intent?.getSerializableExtra("cardInfo") as? CardInfoResult |
| | | |
| | | // 获取充值相关金额 |
| | | rechargeAmount = intent?.getDoubleExtra("rechargeAmount", 0.0) ?: 0.0 |
| | |
| | | object : NFCCallBack { |
| | | override fun isSusses(flag: Boolean, msg: String?) { |
| | | // 确保Toast在主线程中调用 |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 检查卡写卡成功,更新写卡状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | } else { |
| | | ToastUtil.show("检查卡写卡失败: ${msg ?: "未知错误"}") |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 检查卡写卡成功,更新写卡状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | } else { |
| | | ToastUtil.show("检查卡写卡失败: ${msg ?: "未知错误"}") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | |
| | | object : NFCCallBack { |
| | | override fun isSusses(flag: Boolean, msg: String?) { |
| | | // 确保Toast在主线程中调用 |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 区域表号卡写卡成功,更新写卡状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | } else { |
| | | ToastUtil.show("区域表号卡写卡失败: ${msg ?: "未知错误"}") |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 区域表号卡写卡成功,更新写卡状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | } else { |
| | | ToastUtil.show("区域表号卡写卡失败: ${msg ?: "未知错误"}") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | |
| | | object : NFCCallBack { |
| | | override fun isSusses(flag: Boolean, msg: String?) { |
| | | // 确保Toast在主线程中调用 |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 调试卡写卡成功,更新写卡状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | } else { |
| | | ToastUtil.show("调试卡写卡失败: ${msg ?: "未知错误"}") |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 调试卡写卡成功,更新写卡状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | } else { |
| | | ToastUtil.show("调试卡写卡失败: ${msg ?: "未知错误"}") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | |
| | | lifecycleScope.launch { |
| | | try { |
| | | 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) |
| | |
| | | // 用户卡操作类型,查询和更新CardRegistrationBean |
| | | val cardRegistrationDao = baseDaoSingleton.cardRegistrationDao() |
| | | val cardRegistration = cardRegistrationDao.getByOrderId(orderNumber) |
| | | |
| | | |
| | | if (cardRegistration != null) { |
| | | val updatedCardRegistration = cardRegistration.copy(isCardWritten = true) |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | |
| | | runOnUiThread { |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | |
| | | |
| | | // 跳转到写卡成功界面 |
| | | Intent(this@NfcWreatActivity, CardWriteSuccessActivity::class.java).apply { |
| | | |
| | | |
| | | putExtra("cardNumber", cardNumber) |
| | | putExtra("cardAddr", cardAddr) |
| | | putExtra("operationTypeCode", operationTypeCode) |
| | | putExtra("orderNumber", orderNumber) |
| | | //开卡相关参数 |
| | | putExtra("cardFee", cardFee) |
| | | |
| | | // 传递充值相关参数 |
| | | putExtra("rechargeAmount", rechargeAmount) |
| | | putExtra("bonusAmount", bonusAmount) |
| | | |
| | | // 传递销卡相关参数 |
| | | putExtra("refundAmount", refundAmount) |
| | | putExtra("cardBalance", cardBalance) |
| | | |
| | | // 传递返还相关参数 |
| | | putExtra("returnAmount", returnAmount) |
| | | |
| | | // 传递补扣相关参数 |
| | | putExtra("deductAmount", deductAmount) |
| | | |
| | | // 传递补卡相关参数 |
| | | putExtra("cardCost", cardCost) |
| | | putExtra("reissueAmount", reissueAmount) |
| | | |
| | | // 传递用户卡对象 |
| | | if (::userCard.isInitialized) { |
| | | putExtra("userCard", userCard) |
| | | } |
| | | putExtra("operationTypeCode", operationTypeCode) |
| | | |
| | | // 传递卡片信息对象 |
| | | cardInfo?.let { |
| | | putExtra("cardInfo", it) |
| | | } |
| | | |
| | | |
| | | startActivity(this) |
| | | } |
| | | |
| | | |
| | | // 通知MainActivity调用postCardData |
| | | notifyMainActivityToPostCardData(cardNumber) |
| | | } |
| | | |
| | | |
| | | } catch (e: Exception) { |
| | | // 记录异常信息 |
| | | CrashReport.postCatchedException(e) |