| | |
| | | package com.dayu.qiheonlinelibrary.activity; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.Editable; |
| | |
| | | import android.view.View; |
| | | import android.widget.EditText; |
| | | |
| | | import com.dayu.baselibrary.tools.HexUtil; |
| | | import com.dayu.baselibrary.utils.DeviceUtils; |
| | | import com.dayu.baselibrary.utils.MornyUtil; |
| | | import com.dayu.baselibrary.utils.TipUtil; |
| | | |
| | | |
| | | import com.dayu.baselibrary.utils.ToastUtil; |
| | | import com.dayu.baselibrary.view.TipDialog; |
| | | import com.dayu.qiheonlinelibrary.QHOnLineApplication; |
| | | import com.dayu.qiheonlinelibrary.R; |
| | | import com.dayu.qiheonlinelibrary.bean.CardInfoResult; |
| | | import com.dayu.qiheonlinelibrary.bean.RechargeResult; |
| | | import com.dayu.qiheonlinelibrary.card.UserCard; |
| | | import com.dayu.qiheonlinelibrary.databinding.ActivityRechargeQhlBinding; |
| | | import com.dayu.qiheonlinelibrary.dbBean.AdminDataBean; |
| | | import com.dayu.qiheonlinelibrary.dbBean.ElectricPriceBean; |
| | | import com.dayu.qiheonlinelibrary.dbBean.RechargeBean; |
| | | import com.dayu.qiheonlinelibrary.dbBean.UserCardBean; |
| | | import com.dayu.qiheonlinelibrary.net.ApiManager; |
| | | import com.dayu.qiheonlinelibrary.net.BaseResponse; |
| | | import com.dayu.qiheonlinelibrary.net.RSAUtile; |
| | | import com.dayu.qiheonlinelibrary.net.subscribers.SubscriberListener; |
| | | import com.dayu.qiheonlinelibrary.tools.NfcReadHelper; |
| | | import com.dayu.qiheonlinelibrary.utils.CardCommon; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | |
| | | |
| | | CardInfoResult cardInfoResult; |
| | | |
| | | UserCard mOldUserCard; |
| | | |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | cardType = cardType.split(",")[1]; |
| | | } |
| | | //获取卡内信息 |
| | | mOldUserCard = NfcReadHelper.getInstence(intent, this).getUserCardData(); |
| | | getUserInfoAndCardInfo(cardNumber,mOldUserCard.getMyUserCode()); |
| | | userCard = NfcReadHelper.getInstence(intent, this).getUserCardData(); |
| | | if (userCard != null) { |
| | | try { |
| | | getUserInfoAndCardInfo(cardNumber, userCard.getMyUserCode()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | CrashReport.postCatchedException(e); |
| | | TipUtil.show(this, "读卡失败,请刷卡后不要立即移开"); |
| | | } |
| | | } else { |
| | | TipUtil.show(this, "读卡失败,请刷卡后不要立即移开"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | private void setUserData(String cardNumber, String userName, String lastRechargeTime, List<byte[]> data) { |
| | | private void setUserData(String cardNumber, String userName, String lastRechargeTime) { |
| | | if (cardType.equalsIgnoreCase(CardCommon.USER_CARD_TYPE_1)) { |
| | | setCardState("终端写卡"); |
| | | binding.rechargeLL.setVisibility(View.VISIBLE); |
| | |
| | | TipUtil.show(this, "非用户卡,不能充值"); |
| | | return; |
| | | } |
| | | if (userCard != null) { |
| | | try { |
| | | if (Integer.valueOf(QHOnLineApplication.getInstance().arerNumber) == userCard.getArerNumber()) { |
| | | binding.rechargeReadLL.setVisibility(View.GONE); |
| | | binding.rechargeTextLL.setVisibility(View.VISIBLE); |
| | | binding.userName.setText(userName); |
| | | binding.redInitCode.setText(cardNumber); |
| | | binding.redRechargeDate.setText("本卡最后购水日期:\n\n" + lastRechargeTime); |
| | | binding.redUserCode.setText(cardInfoResult.getIccardCode()); |
| | | if (userCard != null) { |
| | | binding.redRemainderBlance.setText(MornyUtil.changeF2Y(userCard.getBalance()) + " 元"); |
| | | binding.redBalanceElectric.setText("充值后剩余电量:" + MornyUtil.changeF2Y(userCard.getSurplusElecticity()) + " 度"); |
| | | } |
| | | binding.redRechargeElectric.setText("电量单价:" + QHOnLineApplication.getInstance().electriclePriceStr + "元/度"); |
| | | |
| | | userCard = UserCard.getBean(data); |
| | | |
| | | if (Integer.valueOf(QHOnLineApplication.getInstance().arerNumber) == userCard.getArerNumber()) { |
| | | |
| | | binding.rechargeReadLL.setVisibility(View.GONE); |
| | | binding.rechargeTextLL.setVisibility(View.VISIBLE); |
| | | binding.userName.setText(userName); |
| | | binding.redInitCode.setText(cardNumber); |
| | | binding.redRechargeDate.setText("本卡最后购水日期:\n\n" + lastRechargeTime); |
| | | binding.redUserCode.setText(cardInfoResult.getIccardCode()); |
| | | if (userCard != null) { |
| | | binding.redRemainderBlance.setText(MornyUtil.changeF2Y(userCard.getBalance()) + " 元"); |
| | | binding.redBalanceElectric.setText("充值后剩余电量:" + MornyUtil.changeF2Y(userCard.getSurplusElecticity()) + " 度"); |
| | | } else { |
| | | TipUtil.show(this, "非本区域卡\n不能充值!!!"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | CrashReport.postCatchedException(e); |
| | | TipUtil.show(this, "读卡失败,请刷卡后不要立即移开"); |
| | | } |
| | | binding.redRechargeElectric.setText("电量单价:" + QHOnLineApplication.getInstance().electriclePriceStr + "元/度"); |
| | | |
| | | } else { |
| | | TipUtil.show(this, "非本区域卡\n不能充值!!!"); |
| | | TipUtil.show(this, "读卡失败,请刷卡后不要立即移开"); |
| | | } |
| | | |
| | | |
| | |
| | | private void startNfcActivity(String morny, String balance, float rechargeElectric, float iccardBalanceElectric, float totalMorny, String iccardRechargeRecordId) { |
| | | //先处理补扣 |
| | | //充值补扣金额=充值金额+充值前读取的卡内余额-充值回调返回卡内余额 |
| | | int deductionMorny = MornyUtil.changeY2F(morny) + mOldUserCard.getBalance() - MornyUtil.changeY2F(balance); |
| | | int deductionMorny = MornyUtil.changeY2F(morny) + userCard.getBalance() - MornyUtil.changeY2F(balance); |
| | | |
| | | if (MornyUtil.changeY2F(morny) < deductionMorny) { |
| | | TipUtil.show(RechargeActivity.this, "当前充值金额小于补扣金额,补扣金额为" + MornyUtil.changeF2Y(deductionMorny) + "元,充值金额应大于补扣金额!"); |
| | |
| | | if (t.getData() != null) { |
| | | //ic卡状态 0 正常 1 已注销 2 已挂失 |
| | | if (t.getData().getIccardStatus() == 0) { |
| | | List<byte[]> data = NfcReadHelper.getInstence(intent, RechargeActivity.this).getOnesectorData(); |
| | | // List<byte[]> data = NfcReadHelper.getInstence(intent, RechargeActivity.this).getOnesectorData(); |
| | | if (!data.isEmpty()) { |
| | | if (!TextUtils.isEmpty(cardNumber)) { |
| | | cardInfoResult = t.getData(); |
| | | setUserData(cardNumber, cardInfoResult.getPeasantName(), cardInfoResult.getLastRechargeTime(), data); |
| | | setUserData(cardNumber, cardInfoResult.getPeasantName(), cardInfoResult.getLastRechargeTime()); |
| | | } else { |
| | | TipUtil.show(RechargeActivity.this, "读取卡片失败,请重新贴卡"); |
| | | } |