| | |
| | | import com.dayu.baselibrary.view.TitleBar.ClickType_LEFT_IMAGE |
| | | import com.dayu.general.BaseApplication |
| | | import com.dayu.general.R |
| | | import com.dayu.general.bean.card.UserCard |
| | | import com.dayu.general.bean.db.CardRegistrationBean |
| | | import com.dayu.general.bean.net.ClientInfo |
| | | import com.dayu.general.bean.net.NewCardDataResult |
| | | import com.dayu.general.bean.net.PaymentMethod |
| | | import com.dayu.general.bean.net.PaymentMethodResponse |
| | | import com.dayu.general.dao.BaseDaoSingleton |
| | | import com.dayu.general.databinding.ActivityNewCardGeBinding |
| | | import com.dayu.general.net.ApiManager |
| | | import com.dayu.general.net.BaseResponse |
| | | import com.dayu.general.tool.CardCommon.Companion.USER_CARD_TYPE_1 |
| | | import com.dayu.general.tool.NfcReadHelper |
| | | import com.dayu.general.tool.NfcWreatHelper |
| | | import com.dayu.general.utils.DateUtils |
| | | import com.tencent.bugly.crashreport.CrashReport |
| | | import kotlinx.coroutines.launch |
| | | import java.util.Calendar |
| | | |
| | | /** |
| | | * Description: 用户开卡界面(同步修改白卡密码) |
| | |
| | | // 客户ID |
| | | private var clientId: String = "" |
| | | |
| | | private lateinit var clientInfo : ClientInfo |
| | | |
| | | // 是否已读卡 |
| | | private var isReadCard: Boolean = false |
| | | |
| | | private var orderId:String="" |
| | | |
| | | companion object { |
| | | private const val TAG = "NewCard2Activity" |
| | | } |
| | | |
| | | // 支付方式数据类 |
| | | data class PaymentMethod( |
| | | val id: Long, |
| | | val name: String, |
| | | val remarks: String, |
| | | val deleted: Int |
| | | ) |
| | | |
| | | // 支付方式接口返回数据类 |
| | | data class PaymentMethodResponse( |
| | | val itemTotal: Any?, |
| | | val obj: List<PaymentMethod>, |
| | | val pageCurr: Any?, |
| | | val pageSize: Any?, |
| | | val pageTotal: Any? |
| | | ) |
| | | |
| | | // 用户信息数据类 |
| | | data class ClientInfo( |
| | | val clientId: String, |
| | | val clientNum: String, |
| | | val name: String, |
| | | val districtNum: String, |
| | | val phone: String, |
| | | val idCard: String, |
| | | val villageName: String, |
| | | val address: String, |
| | | val cardCount: Int, |
| | | val operateDt: String |
| | | ) |
| | | |
| | | override fun onCreate(savedInstanceState: Bundle?) { |
| | | super.onCreate(savedInstanceState) |
| | |
| | | object : SubscriberListener<BaseResponse<ClientInfo>>() { |
| | | override fun onNext(response: BaseResponse<ClientInfo>) { |
| | | if (response.success) { |
| | | val clientInfo = response.content |
| | | clientInfo = response.content!! |
| | | if (clientInfo != null) { |
| | | // 显示客户信息到界面 |
| | | displayClientInfo(clientInfo) |
| | |
| | | // 构建请求参数 |
| | | val params = HashMap<String, Any>() |
| | | params["cardAddr"] = cardPhysicalId // 水卡地址(物理ID) |
| | | params["clientNum"] = binding.newCardFarmerCode.text.toString() // 农户编号 |
| | | params["cardCost"] = (cardFee * 100).toInt() // 购卡金额(工本费)转为分 |
| | | params["amount"] = (rechargeAmount * 100).toInt() // 充值金额转为分 |
| | | params["clientId"] = clientId // 农户ID |
| | | params["cardCost"] = cardFee // 购卡金额(工本费)(元) |
| | | params["amount"] = rechargeAmount // 充值金额(元) |
| | | params["paymentId"] = paymentId // 支付方式ID |
| | | params["remarks"] = remark // 备注 |
| | | params["protocol"] = "p206V1_0_1" // 协议 |
| | | params["operator"] = BaseApplication.userId // 操作人ID |
| | | |
| | | // 执行卡片激活API请求 |
| | | ApiManager.getInstance().requestPostLoading( |
| | | this, |
| | | "sell/card/active", |
| | | String::class.java, |
| | | "terminal/card/termActiveCard", |
| | | NewCardDataResult::class.java, |
| | | params, |
| | | object : SubscriberListener<BaseResponse<String>>() { |
| | | override fun onNext(response: BaseResponse<String>) { |
| | | object : SubscriberListener<BaseResponse<NewCardDataResult>>() { |
| | | override fun onNext(response: BaseResponse<NewCardDataResult>) { |
| | | if (response.success) { |
| | | orderId=response.content?.orderNo.toString() |
| | | // 保存开卡信息到数据库 |
| | | val cardRegistration = CardRegistrationBean( |
| | | cardNumber = cardPhysicalId, |
| | | userName = binding.newCardUserName.text.toString(), |
| | | idCard = binding.newCardIdCard.text.toString(), |
| | | farmerCode = binding.newCardFarmerCode.text.toString(), |
| | | clientId = clientId, |
| | | cardFee = cardFee, |
| | | remark = binding.newCardRemark.text.toString(), |
| | | paymentMethod = paymentId.toInt(), |
| | | isReported = true, |
| | | isCardWritten = true |
| | | ) |
| | | isCardWritten = true, |
| | | operatorId = orderId, |
| | | |
| | | ) |
| | | |
| | | // 使用协程在后台线程中保存数据 |
| | | lifecycleScope.launch { |
| | | try { |
| | | BaseDaoSingleton.getInstance(this@NewCard2Activity) |
| | | .cardRegistrationDao().insert(cardRegistration) |
| | | |
| | | Toast.makeText( |
| | | this@NewCard2Activity, |
| | | "开卡成功", |
| | | Toast.LENGTH_SHORT |
| | | ).show() |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | Intent(this@NewCard2Activity, NfcWreatActivity::class.java).apply { |
| | | putExtra("cardType", USER_CARD_TYPE_1) |
| | | putExtra("orderId", orderId) |
| | | putExtra("cardAddr", cardPhysicalId) |
| | | var userCard = UserCard() |
| | | userCard.areaNumber =clientInfo.districtNum |
| | | userCard.userCode =clientInfo.clientNum |
| | | userCard.phoneNumber =clientInfo.phone |
| | | userCard.userCodeNumber = response.content?.cardNum?.toInt()!! |
| | | userCard.projectCode = response.content?.projectNo?.toInt()!! |
| | | userCard.balance = response.content?.balance?.toInt()!! |
| | | // userCard.surplusWater = response.content?.surplusWater?.toInt()!! |
| | | userCard.waterPrice = response.content?.waterPrice?.toFloat()!! |
| | | // userCard.electricPrice = response.content?.electricPrice?.toFloat()!! |
| | | userCard.rechargeDate = DateUtils.parseStringToCalendar(response.content?.time) |
| | | putExtra("userCard", userCard) |
| | | startActivity(this) |
| | | } |
| | | } catch (e: Exception) { |
| | | CrashReport.postCatchedException(e) |
| | | Toast.makeText( |