| | |
| | | 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.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; |
| | | |
| | | |
| | | /** |
| | |
| | | ActivityRechargeQhlBinding binding; |
| | | public static RechargeActivity rechargeActivity; |
| | | |
| | | AdminDataBean adminData; |
| | | String userName; |
| | | String cardNumber = null; |
| | | UserCardBean userCardBean; |
| | | int waterPrice; |
| | | |
| | | String cardNumber = null;//实体卡号 |
| | | RechargeBean rechargeBean; |
| | | |
| | | String rechageWater;//充值的水量 |
| | | ElectricPriceBean priceBean; |
| | | |
| | | String cardType;//卡状态 |
| | | |
| | | CardInfoResult cardInfoResult; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | setContentView(binding.getRoot()); |
| | | setPricePoint(binding.rechargeWater); |
| | | rechargeActivity = this; |
| | | waterPrice = baseDao.adminDao().findFirst().getWaterPrice(); |
| | | initView(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | |
| | | |
| | | private void readAllData() { |
| | | String cardType = NfcReadHelper.getInstence(intent, this).getCradTypeAndCardNumber(); |
| | | cardType = NfcReadHelper.getInstence(intent, this).getCradTypeAndCardNumber(); |
| | | |
| | | String[] cardTypes = cardType.split(","); |
| | | if (cardTypes != null && cardTypes.length == 2) { |
| | | cardNumber = cardType.split(",")[0]; |
| | | cardNumber = HexUtil.spaceHex(cardNumber); |
| | | cardNumber = HexUtil.HighLowHex(cardNumber); |
| | | cardType = cardType.split(",")[1]; |
| | | } |
| | | List<byte[]> data = NfcReadHelper.getInstence(intent, this).getOnesectorData(); |
| | | getUserInfoAndCardInfo(cardNumber); |
| | | |
| | | if (!data.isEmpty()) { |
| | | if (!TextUtils.isEmpty(cardNumber)) { |
| | | setUserData(cardType, cardNumber, data); |
| | | if(priceBean!=null){ |
| | | binding.redRechargeElectric.setText("电量单价:"+priceBean.getPrice()+"元/度"); |
| | | } |
| | | } else { |
| | | TipUtil.show(this, "读取卡片失败,请重新贴卡"); |
| | | } |
| | | } else { |
| | | TipUtil.show(this, "卡片识别错误,请重试!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @SuppressLint("ResourceAsColor") |
| | | private void setUserData(String cardType, String cardNumber, List<byte[]> data) { |
| | | |
| | | |
| | | private void setUserData(String cardNumber, String userName, String lastRechargeTime, float iccardBalanceMoney, List<byte[]> data) { |
| | | String state = ""; |
| | | if (cardType.equalsIgnoreCase(CardCommon.USER_CARD_TYPE_1)) { |
| | | state = "终端写卡"; |
| | | binding.rechargeLL.setVisibility(View.VISIBLE); |
| | | binding.rechargeRegistBtn.setVisibility(View.VISIBLE); |
| | | binding.redStatu.setTextColor(R.color.black); |
| | | binding.redStatu.setTextColor(this.getResources().getColor(R.color.black)); |
| | | } else if (cardType.equalsIgnoreCase(CardCommon.USER_CARD_TYPE_2)) { |
| | | state = "未刷卡关泵,当前不可充值"; |
| | | binding.rechargeLL.setVisibility(View.GONE); |
| | | binding.rechargeRegistBtn.setVisibility(View.GONE); |
| | | binding.redStatu.setTextColor(com.dayu.baselibrary.R.color.red); |
| | | setCardState("未刷卡关泵,当前不可充值"); |
| | | } else if (cardType.equalsIgnoreCase(CardCommon.USER_CARD_TYPE_3)) { |
| | | state = "叠加充值"; |
| | | binding.rechargeLL.setVisibility(View.GONE); |
| | | binding.rechargeRegistBtn.setVisibility(View.GONE); |
| | | setCardState("叠加充值"); |
| | | } else { |
| | | TipUtil.show(this, "非用户卡,不能充值"); |
| | | return; |
| | | } |
| | | |
| | | |
| | | userCard = UserCard.getBean(data); |
| | | List<UserCardBean> userCardBeans = baseDao.userCardDao().findUserName(cardNumber); |
| | | AdminDataBean adminDataBean = baseDao.adminDao().findFirst(); |
| | | |
| | | if (Integer.valueOf(QHOnLineApplication.getInstance().arerNumber) == userCard.getArerNumber()) { |
| | | |
| | | if (Integer.valueOf(adminDataBean.getAddressCode()) == userCard.getArerNumber()) { |
| | | if (!userCardBeans.isEmpty()) { |
| | | userCardBean = userCardBeans.get(0); |
| | | this.userName = userCardBean.getUserName(); |
| | | } else { |
| | | userCardBean = new UserCardBean(); |
| | | userCardBean.setCardNumber(cardNumber); |
| | | userCardBean.setUserName("未知用户"); |
| | | userCardBean.setPhone("未知"); |
| | | userCardBean.setUserID("未知"); |
| | | userCardBean.setAddressCode(String.valueOf(userCard.getArerNumber())); |
| | | userCardBean.setSerial(String.valueOf(userCard.getArerNumber())); |
| | | this.userName = "未知用户"; |
| | | } |
| | | binding.rechargeReadLL.setVisibility(View.GONE); |
| | | binding.rechargeTextLL.setVisibility(View.VISIBLE); |
| | | binding.userName.setText(userName); |
| | | binding.redStatu.setText(state); |
| | | if (userCard != null) { |
| | | Calendar calendar = userCard.getRechargeDate(); |
| | | if (calendar != null) { |
| | | int year = calendar.get(Calendar.YEAR); |
| | | int month = calendar.get(Calendar.MONTH); // 月份从0开始,所以需要加1 |
| | | int day = calendar.get(Calendar.DAY_OF_MONTH); |
| | | binding.redRechargeDate.setText("本卡最后购水日期:" + year + "年" + month + "月" + day + "日"); |
| | | } else { |
| | | binding.redRechargeDate.setText("本卡最后购水日期:无"); |
| | | } |
| | | binding.redInitCode.setText(cardNumber); |
| | | // binding.redRechargeNumber.setText("本卡充值次数:" + userCard.getRechargeTimes() + " 次"); |
| | | // binding.redTotalWater.setText("总用水量:" + MornyUtil.changeF2Y(userCard.getTotalWater()) + " 吨"); |
| | | // binding.redTotalPower.setText("总用电量:" + MornyUtil.changeF2Y(userCard.getTotalElectric()) + " 度"); |
| | | binding.redRemainderBlance.setText(MornyUtil.changeF2Y(userCard.getBalance()) + " 元"); |
| | | binding.redRemainderWater.setText("剩余水量:" + MornyUtil.changeF2Y(userCard.getSurplusWater()) + " 吨"); |
| | | // binding.redWaterPrice.setText("每立方米水价格:" + MornyUtil.changeF2Y(adminData.getWaterPrice()) + " 元"); |
| | | binding.redRechargeDate.setText("本卡最后购水日期:\n\n" + lastRechargeTime); |
| | | if (userCard != null) { |
| | | |
| | | binding.redRemainderBlance.setText(String.valueOf(iccardBalanceMoney) + " 元"); |
| | | } |
| | | |
| | | binding.redRechargeElectric.setText("电量单价:" + QHOnLineApplication.getInstance().electriclePriceStr + "元/度"); |
| | | |
| | | } else { |
| | | TipUtil.show(this, "非本区域卡\n不能充值!!!"); |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | private void initView() { |
| | | try { |
| | | adminData = baseDao.adminDao().findFirst(); |
| | | priceBean = baseDao.electricPriceDao().findFirst(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | CrashReport.postCatchedException(e); |
| | | } |
| | | binding.rechargeRegistBtn.setOnClickListener(v -> { |
| | | String morny = binding.rechargeWater.getText().toString(); |
| | | if (!TextUtils.isEmpty(morny)) { |
| | | Intent intent = new Intent(RechargeActivity.this, NFCWreatActivity.class); |
| | | //当前金额单位为元 |
| | | intent.putExtra("morny", morny); |
| | | intent.putExtra("userName", userName); |
| | | intent.putExtra("cardNumber", cardNumber); |
| | | intent.putExtra("userCard", userCard); |
| | | intent.putExtra("userCardBean", userCardBean); |
| | | // intent.putExtra("rechageWater", rechageWater); |
| | | startActivity(intent); |
| | | rechaege(morny); |
| | | } else { |
| | | TipUtil.show(RechargeActivity.this, "请输入充值金额(元)"); |
| | | TipUtil.show(RechargeActivity.this, "请输入充值金额"); |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | String morny = editText.getText().toString(); |
| | | if (!TextUtils.isEmpty(morny)) { |
| | | rechageWater = MornyUtil.intDiv(MornyUtil.changeY2F(editText.getText().toString()), waterPrice); |
| | | // rechageWater = MornyUtil.intDiv(MornyUtil.changeY2F(editText.getText().toString()), waterPrice); |
| | | // binding.redRechargeWater.setText("充值水量:" + rechageWater + " 立方米(吨)"); |
| | | } |
| | | |
| | |
| | | super.onDestroy(); |
| | | rechargeActivity = null; |
| | | } |
| | | |
| | | |
| | | private void startNfcActivity(String morny, String balance, float rechargeElectric, float iccardBalanceElectric, float totalMorny, String iccardRechargeRecordId) { |
| | | |
| | | //添加充值信息 |
| | | rechargeBean = new RechargeBean(); |
| | | rechargeBean.setCardNumber(cardNumber); |
| | | rechargeBean.setUserCode(userCard.getUserCode()); |
| | | rechargeBean.setUserName(""); |
| | | rechargeBean.setPersonId(cardInfoResult.getPeasantId()); |
| | | rechargeBean.setSerial(DeviceUtils.getSN()); |
| | | rechargeBean.setArerNumber(QHOnLineApplication.getInstance().arerNumber); |
| | | rechargeBean.setMorny(morny); |
| | | rechargeBean.setBalance(balance); |
| | | rechargeBean.setRechargeElectric(String.valueOf(rechargeElectric)); |
| | | rechargeBean.setPrice(QHOnLineApplication.getInstance().electriclePriceStr); |
| | | rechargeBean.setSurplusElectic(String.valueOf(iccardBalanceElectric)); |
| | | long time = System.currentTimeMillis(); |
| | | rechargeBean.setRechargeDate(time); |
| | | rechargeBean.setUserId(""); |
| | | rechargeBean.setTotalMorny(String.valueOf(totalMorny)); |
| | | rechargeBean.setState(1); |
| | | rechargeBean.setOrderId(iccardRechargeRecordId); |
| | | |
| | | userCard.setCardWriteState(0); |
| | | userCard.setCardState(1); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(time); |
| | | userCard.setBalance(MornyUtil.changeY2F(String.valueOf(balance))); |
| | | userCard.setSurplusElecticity(MornyUtil.changeY2F(String.valueOf(iccardBalanceElectric))); |
| | | String sumMorny = MornyUtil.sumPrice(Float.valueOf(MornyUtil.changeF2Y(userCard.getTotalMorny())), Float.valueOf(morny)); |
| | | userCard.setTotalMorny(MornyUtil.changeY2F(sumMorny)); |
| | | userCard.setRechargeDate(calendar); |
| | | |
| | | |
| | | Intent intent = new Intent(RechargeActivity.this, NFCWreatActivity.class); |
| | | intent.putExtra("morny", morny); |
| | | intent.putExtra("userCard", userCard); |
| | | intent.putExtra("rechargeBean", rechargeBean); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * IC卡充值 |
| | | * |
| | | * @param morny |
| | | */ |
| | | public void rechaege(String morny) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | //终端设备号 |
| | | data.put("equipCode", DeviceUtils.getSN()); |
| | | //ic卡信息id |
| | | data.put("iccardNum", cardNumber); |
| | | //交易水费金额(元) |
| | | data.put("rechargeWaterMoney", morny); |
| | | //卡内剩余金额(元) |
| | | data.put("iccardBalanceMoney", MornyUtil.changeF2Y(userCard.getBalance())); |
| | | //卡内剩余水量(m³) |
| | | data.put("iccardBalanceAmonunt", "0"); |
| | | //卡内剩余电量 |
| | | data.put("iccardBalanceElectric", MornyUtil.changeF2Y(userCard.getSurplusElecticity())); |
| | | ApiManager.getInstance().requestPostLoading(this, "api/sjgg/iccard/recharge/rechargeCard", RechargeResult.class, data, new SubscriberListener<BaseResponse<RechargeResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<RechargeResult> t) { |
| | | if (t.isSuccess()) { |
| | | RechargeResult rechargeResult = t.getData(); |
| | | startNfcActivity(morny, rechargeResult.getIccardBalanceMoney(), rechargeResult.getRechargeElectricAmount(), rechargeResult.getIccardBalanceElectric(), rechargeResult.getTotalRechargeMoney(), rechargeResult.getIccardRechargeRecordId()); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取卡信息和用户信息 |
| | | * |
| | | * @param iccardCode |
| | | */ |
| | | public void getUserInfoAndCardInfo(String iccardCode) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | //ic卡信息id |
| | | data.put("iccardNum", iccardCode); |
| | | ApiManager.getInstance().requestPostLoading(this, "api/sjgg/iccard/peasant/getIccardInfoVoByCardCode", CardInfoResult.class, data, new SubscriberListener<BaseResponse<CardInfoResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<CardInfoResult> t) { |
| | | String state = ""; |
| | | if (t.isSuccess()) { |
| | | //ic卡状态 0 正常 1 已注销 2 已挂失 |
| | | if (t.getData().getIccardStatus() == 0) { |
| | | 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(), cardInfoResult.getIccardBalanceMoney(), data); |
| | | } else { |
| | | TipUtil.show(RechargeActivity.this, "读取卡片失败,请重新贴卡"); |
| | | } |
| | | } else { |
| | | TipUtil.show(RechargeActivity.this, "卡片识别错误,请重试!"); |
| | | } |
| | | } else if (t.getData().getIccardStatus() == 1) { |
| | | TipUtil.show(RechargeActivity.this, "当前卡已注销"); |
| | | } else { |
| | | TipUtil.show(RechargeActivity.this, "当前卡已挂失"); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void setCardState(String state) { |
| | | binding.rechargeLL.setVisibility(View.GONE); |
| | | binding.rechargeRegistBtn.setVisibility(View.GONE); |
| | | binding.redStatu.setTextColor(RechargeActivity.this.getResources().getColor(com.dayu.baselibrary.R.color.red)); |
| | | binding.redStatu.setText(state); |
| | | } |
| | | |
| | | |
| | | } |