|  |  | 
 |  |  | package com.dayu.qihealonelibrary.activity; | 
 |  |  |  | 
 |  |  | import android.annotation.SuppressLint; | 
 |  |  | 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.MornyUtil; | 
 |  |  | import com.dayu.baselibrary.utils.TipUtil; | 
 |  |  | import com.dayu.qihealonelibrary.R; | 
 |  |  | import com.dayu.qihealonelibrary.card.UserCard; | 
 |  |  | import com.dayu.qihealonelibrary.databinding.ActivityRechargeQhaBinding; | 
 |  |  | import com.dayu.qihealonelibrary.dbBean.AdminDataBean; | 
 |  |  | import com.dayu.qihealonelibrary.dbBean.ElectricPriceBean; | 
 |  |  | import com.dayu.qihealonelibrary.dbBean.UserCardBean; | 
 |  |  | import com.dayu.qihealonelibrary.tools.NfcReadHelper; | 
 |  |  | import com.dayu.qihealonelibrary.utils.CardCommon; | 
 |  |  | 
 |  |  |     String userName; | 
 |  |  |     String cardNumber = null; | 
 |  |  |     UserCardBean userCardBean; | 
 |  |  |     int waterPrice; | 
 |  |  |     String rechageWater;//充值的水量 | 
 |  |  |     ElectricPriceBean priceBean; | 
 |  |  |  | 
 |  |  |     @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(); | 
 |  |  | 
 |  |  |         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(); | 
 |  |  | 
 |  |  |         if (!data.isEmpty()) { | 
 |  |  |             if (!TextUtils.isEmpty(cardNumber)) { | 
 |  |  |                 setUserData(cardType, cardNumber, data); | 
 |  |  |                 if(priceBean!=null){ | 
 |  |  |                     binding.redRechargeElectric.setText("电量单价:"+priceBean.getPrice()+"元/度"); | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 TipUtil.show(this, "读取卡片失败,请重新贴卡"); | 
 |  |  |             } | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @SuppressLint("ResourceAsColor") | 
 |  |  |     private void setUserData(String cardType, String cardNumber, 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); | 
 |  |  |         } else if (cardType.equalsIgnoreCase(CardCommon.USER_CARD_TYPE_2)) { | 
 |  |  |             state = "刷卡开泵后,当前状态不能充值"; | 
 |  |  |             state = "未刷卡关泵,当前不可充值"; | 
 |  |  |             binding.rechargeLL.setVisibility(View.GONE); | 
 |  |  |             binding.rechargeRegistBtn.setVisibility(View.GONE); | 
 |  |  |             binding.redStatu.setTextColor(com.dayu.baselibrary.R.color.red); | 
 |  |  |         } else if (cardType.equalsIgnoreCase(CardCommon.USER_CARD_TYPE_3)) { | 
 |  |  |             state = "叠加充值"; | 
 |  |  |             binding.rechargeLL.setVisibility(View.GONE); | 
 |  |  |             binding.rechargeRegistBtn.setVisibility(View.GONE); | 
 |  |  |         } else { | 
 |  |  |             TipUtil.show(this, "非用户卡,不能充值"); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         userCard = UserCard.getBean(data); | 
 |  |  |         List<UserCardBean> userCardBeans = baseDao.userCardDao().findUserName(cardNumber); | 
 |  |  |         AdminDataBean adminDataBean = baseDao.adminDao().findFirst(); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         if (adminDataBean.addressCode.equalsIgnoreCase(String.valueOf(userCard.getArerNumber()))) { | 
 |  |  |         if (Integer.valueOf(adminDataBean.getAddressCode()) == userCard.getArerNumber()) { | 
 |  |  |             if (!userCardBeans.isEmpty()) { | 
 |  |  |                 userCardBean = userCardBeans.get(0); | 
 |  |  |                 this.userName = userCardBean.getUserName(); | 
 |  |  | 
 |  |  |                 userCardBean.setSerial(String.valueOf(userCard.getArerNumber())); | 
 |  |  |                 this.userName = "未知用户"; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             binding.rechargeReadLL.setVisibility(View.GONE); | 
 |  |  |             binding.rechargeTextLL.setVisibility(View.VISIBLE); | 
 |  |  |             binding.rechargeRegistBtn.setVisibility(View.VISIBLE); | 
 |  |  |             binding.userName.setText(userName); | 
 |  |  |             binding.redStatu.setText(state); | 
 |  |  |             if (userCard != null) { | 
 |  |  | 
 |  |  |                     binding.redRechargeDate.setText("本卡最后购水日期:无"); | 
 |  |  |                 } | 
 |  |  |                 binding.redInitCode.setText(cardNumber); | 
 |  |  |                 binding.redRechargeNumber.setText("本卡充值次数:" + userCard.getRechargeTimes() + ""); | 
 |  |  |                 binding.redTotalWater.setText("总用水量:" + userCard.getTotalWater()); | 
 |  |  |                 binding.redTotalPower.setText("总用电量:" + userCard.getTotalElectric()); | 
 |  |  |                 binding.redRemainderBlance.setText(MornyUtil.changeF2Y(userCard.getBalance()) + "元"); | 
 |  |  |                 binding.redRemainderWater.setText("剩余水量:" + userCard.getSurplusWater()); | 
 |  |  | //                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()) + " 元"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } else { | 
 |  |  |             TipUtil.show(this, "不是本区域卡"); | 
 |  |  |             TipUtil.show(this, "非本区域卡\n不能充值!!!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | 
 |  |  |     private void initView() { | 
 |  |  |         try { | 
 |  |  |             adminData = baseDao.adminDao().findFirst(); | 
 |  |  |             priceBean = baseDao.electricPriceDao().findFirst(); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             CrashReport.postCatchedException(e); | 
 |  |  | 
 |  |  |                 intent.putExtra("cardNumber", cardNumber); | 
 |  |  |                 intent.putExtra("userCard", userCard); | 
 |  |  |                 intent.putExtra("userCardBean", userCardBean); | 
 |  |  | //                intent.putExtra("rechageWater", rechageWater); | 
 |  |  |                 startActivity(intent); | 
 |  |  |             } else { | 
 |  |  |                 TipUtil.show(RechargeActivity.this, "请输入充值金额(元)"); | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     //校验金额 | 
 |  |  |     public static void setPricePoint(final EditText editText) { | 
 |  |  |     public void setPricePoint(final EditText editText) { | 
 |  |  |         editText.addTextChangedListener(new TextWatcher() { | 
 |  |  |             @Override | 
 |  |  |             public void onTextChanged(CharSequence s, int start, int before, | 
 |  |  | 
 |  |  |                         editText.setSelection(1); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 String morny = editText.getText().toString(); | 
 |  |  |                 if (!TextUtils.isEmpty(morny)) { | 
 |  |  |                     rechageWater = MornyUtil.intDiv(MornyUtil.changeY2F(editText.getText().toString()), waterPrice); | 
 |  |  | //                    binding.redRechargeWater.setText("充值水量:" + rechageWater + " 立方米(吨)"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             @Override |