| New file | 
 |  |  | 
 |  |  | package com.dayu.qihealonelibrary.activity; | 
 |  |  |  | 
 |  |  | import android.content.Intent; | 
 |  |  | import android.os.Bundle; | 
 |  |  | import android.text.TextUtils; | 
 |  |  | import android.util.Log; | 
 |  |  | import android.view.KeyEvent; | 
 |  |  | import android.view.LayoutInflater; | 
 |  |  | import android.view.View; | 
 |  |  |  | 
 |  |  | import com.dayu.baselibrary.tools.HexUtil; | 
 |  |  | import com.dayu.baselibrary.utils.AidlUtil; | 
 |  |  | import com.dayu.baselibrary.utils.BaseCommon; | 
 |  |  | import com.dayu.baselibrary.utils.DateUtil; | 
 |  |  | import com.dayu.baselibrary.utils.MornyUtil; | 
 |  |  | import com.dayu.baselibrary.utils.TipUtil; | 
 |  |  | import com.dayu.baselibrary.view.ConfirmDialog; | 
 |  |  | import com.dayu.baselibrary.view.TitleBar; | 
 |  |  | import com.dayu.qihealonelibrary.QHAloneApplication; | 
 |  |  | import com.dayu.qihealonelibrary.card.CleanCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.CleanUserCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.ConfigurationPowerCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.ConfigureDeviceRegistrationCrad; | 
 |  |  | import com.dayu.qihealonelibrary.card.DomainCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.ElectricPriceCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.ManageCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.PassWordCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.RegionCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.RegisteredCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.TestCard; | 
 |  |  | import com.dayu.qihealonelibrary.card.UserCard; | 
 |  |  | import com.dayu.qihealonelibrary.databinding.ActivityWriteTextQhaBinding; | 
 |  |  | import com.dayu.qihealonelibrary.dbBean.AdminDataBean; | 
 |  |  | import com.dayu.qihealonelibrary.dbBean.RechargeBean; | 
 |  |  | import com.dayu.qihealonelibrary.dbBean.UserCardBean; | 
 |  |  | import com.dayu.qihealonelibrary.tools.NFCWriteHelper; | 
 |  |  | import com.dayu.qihealonelibrary.tools.NfcReadHelper; | 
 |  |  | import com.dayu.qihealonelibrary.tools.WriteCardUtils; | 
 |  |  | import com.dayu.qihealonelibrary.utils.CardCommon; | 
 |  |  | import com.tencent.bugly.crashreport.CrashReport; | 
 |  |  |  | 
 |  |  | import java.util.Calendar; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * Copyright (C), 2023, | 
 |  |  |  * Author: zuo | 
 |  |  |  * Date: 2023-11-08 21:19 | 
 |  |  |  * Description: nfc写卡界面 | 
 |  |  |  */ | 
 |  |  | public class NFCWreatActivity extends BaseNfcActivity { | 
 |  |  |  | 
 |  |  |     RegisteredCard registeredCard; | 
 |  |  |     CleanUserCard cleanUserCard; | 
 |  |  |     ManageCard manageCard; | 
 |  |  |     DomainCard domainCard; | 
 |  |  |  | 
 |  |  |     CleanCard cleanCard; | 
 |  |  |     ConfigureDeviceRegistrationCrad configureDeviceRegistrationCrad; | 
 |  |  |     TestCard testCard; | 
 |  |  |     //区域表号卡 | 
 |  |  |     RegionCard regionCard; | 
 |  |  |     ConfigurationPowerCard configurationPowerCard; | 
 |  |  |     //密码卡 | 
 |  |  |     PassWordCard passWordCard; | 
 |  |  |     //用户电量单价卡 | 
 |  |  |     ElectricPriceCard electricPriceCard; | 
 |  |  |     UserCardBean userCardBeanByManager; | 
 |  |  |     boolean electricPriceFlag = false; | 
 |  |  |     boolean passwordFlag = false; | 
 |  |  |     boolean cleanFlag = false; | 
 |  |  |     boolean regionFlag = false; | 
 |  |  |     boolean userFlag = false; | 
 |  |  |     boolean manageCardFlag = false; | 
 |  |  |     boolean registeredFlag = false; | 
 |  |  |     boolean administrativeCardFlag = false; | 
 |  |  |     boolean cleanUserCardFlag = false; | 
 |  |  |  | 
 |  |  |     boolean domainCrdFlag = false; | 
 |  |  |  | 
 |  |  |     boolean testCardFlag = false; | 
 |  |  |  | 
 |  |  |     boolean configDeviceRegiestFlag = false; | 
 |  |  |  | 
 |  |  |     boolean configPowerFlag = false; | 
 |  |  |  | 
 |  |  |     UserCardBean userCardBean; | 
 |  |  |     UserCard olduserCard; | 
 |  |  |  | 
 |  |  |     String morny; | 
 |  |  |     String rechageWater;//充值的水量 | 
 |  |  |     String userName; | 
 |  |  |     AdminDataBean adminData; | 
 |  |  |     RechargeBean rechargeBean; | 
 |  |  |     Intent intent; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     //打印 | 
 |  |  |     QHAloneApplication baseApp; | 
 |  |  |  | 
 |  |  |     public static NFCWreatActivity nfcWreatActivity; | 
 |  |  |     /** | 
 |  |  |      * 是否是用户卡,假如是用户卡的话需要检测卡片是否已经开过户,假如已开户则报错不能再写卡 | 
 |  |  |      */ | 
 |  |  |     boolean isUser = false;// | 
 |  |  |  | 
 |  |  |     //是否是充值过程 | 
 |  |  |     boolean isRecharge = false; | 
 |  |  |  | 
 |  |  |     ActivityWriteTextQhaBinding binding; | 
 |  |  |  | 
 |  |  |     //当前卡的物理卡号 | 
 |  |  |     String cardNumber; | 
 |  |  |     ConfirmDialog confirmDialog; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     protected void onCreate(Bundle savedInstanceState) { | 
 |  |  |         super.onCreate(savedInstanceState); | 
 |  |  |         try { | 
 |  |  |             binding = ActivityWriteTextQhaBinding.inflate(LayoutInflater.from(this)); | 
 |  |  |             setContentView(binding.getRoot()); | 
 |  |  |             nfcWreatActivity = this; | 
 |  |  |             getData(); | 
 |  |  |             titleBack(); | 
 |  |  |             baseApp = QHAloneApplication.getInstance(); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             CrashReport.postCatchedException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private void getData() { | 
 |  |  |         try { | 
 |  |  |             if (this.getIntent().hasExtra("userCard")) { | 
 |  |  |                 userCard = (UserCard) this.getIntent().getSerializableExtra("userCard"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("electricPriceCard")) { | 
 |  |  |                 electricPriceCard = (ElectricPriceCard) this.getIntent().getSerializableExtra("electricPriceCard"); | 
 |  |  |                 binding.cardData.setText("制作用户电量单价卡\n当前单价:" + electricPriceCard.getElectricPrice().toString() + " 元"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("passWordCard")) { | 
 |  |  |                 passWordCard = (PassWordCard) this.getIntent().getSerializableExtra("passWordCard"); | 
 |  |  |                 binding.cardData.setText("制作密码卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("cleanCard")) { | 
 |  |  |                 cleanCard = (CleanCard) this.getIntent().getSerializableExtra("cleanCard"); | 
 |  |  |                 binding.cardData.setText("制作清零卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("manageCard")) { | 
 |  |  |                 cardNumber = this.getIntent().getStringExtra("cardNumber"); | 
 |  |  |                 manageCard = (ManageCard) this.getIntent().getSerializableExtra("manageCard"); | 
 |  |  |                 if (this.getIntent().hasExtra("userCardBean_manager")) { | 
 |  |  |                     userCardBeanByManager = (UserCardBean) this.getIntent().getSerializableExtra("userCardBean_manager"); | 
 |  |  |                 } | 
 |  |  |                 //显示的时候要反过来 | 
 |  |  |                 String hex = HexUtil.spaceHex(manageCard.getUserCard()); | 
 |  |  |                 hex = HexUtil.HighLowHex(hex); | 
 |  |  |                 binding.cardData.setText("制作管理卡(请将管理卡贴在设备上)\n用户卡号:" + hex); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("registeredCard")) { | 
 |  |  |                 registeredCard = (RegisteredCard) this.getIntent().getSerializableExtra("registeredCard"); | 
 |  |  |                 binding.cardData.setText("制作重新注册设备卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("dbUserCard")) { | 
 |  |  |                 userCardBean = (UserCardBean) this.getIntent().getSerializableExtra("dbUserCard"); | 
 |  |  |                 isUser = true; | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("cleanUserCard")) { | 
 |  |  |                 cleanUserCard = (CleanUserCard) this.getIntent().getSerializableExtra("cleanUserCard"); | 
 |  |  |                 binding.cardData.setText("制作删除全部用户卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("domainCard")) { | 
 |  |  |                 domainCard = (DomainCard) this.getIntent().getSerializableExtra("domainCard"); | 
 |  |  |                 binding.cardData.setText("制作设置域名卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("testCard")) { | 
 |  |  |                 testCard = (TestCard) this.getIntent().getSerializableExtra("testCard"); | 
 |  |  |                 binding.cardData.setText("制作测试卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("configureDeviceRegistrationCrad")) { | 
 |  |  |                 configureDeviceRegistrationCrad = (ConfigureDeviceRegistrationCrad) this.getIntent().getSerializableExtra("configureDeviceRegistrationCrad"); | 
 |  |  |                 binding.cardData.setText("制作配置设备注册信息卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("configurationPowerCard")) { | 
 |  |  |                 configurationPowerCard = (ConfigurationPowerCard) this.getIntent().getSerializableExtra("configurationPowerCard"); | 
 |  |  |                 binding.cardData.setText("制作配置水泵功率卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("regionCard")) { | 
 |  |  |                 regionCard = (RegionCard) this.getIntent().getSerializableExtra("regionCard"); | 
 |  |  |                 binding.cardData.setText("制作区域表号卡"); | 
 |  |  |             } | 
 |  |  |             if (this.getIntent().hasExtra("morny")) { | 
 |  |  |                 // 充值逻辑 | 
 |  |  |                 isRecharge = true; | 
 |  |  |                 morny = this.getIntent().getStringExtra("morny"); | 
 |  |  |                 userName = this.getIntent().getStringExtra("userName"); | 
 |  |  |                 cardNumber = this.getIntent().getStringExtra("cardNumber"); | 
 |  |  |                 userCardBean = (UserCardBean) this.getIntent().getSerializableExtra("userCardBean"); | 
 |  |  | //                rechageWater = this.getIntent().getStringExtra("rechageWater"); | 
 |  |  |                 binding.cardData.setText("充值金额:" + morny + " 元"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             try { | 
 |  |  |                 adminData = baseDao.adminDao().findFirst(); | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 e.printStackTrace(); | 
 |  |  |                 CrashReport.postCatchedException(e); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             CrashReport.postCatchedException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 检测是否是用户卡,假如是用户卡的话需要检测卡片是否已经开过户,假如已开户则报错不能再写卡假如是用户卡需要 | 
 |  |  |      */ | 
 |  |  |     private void checkHasUser() { | 
 |  |  |  | 
 |  |  |         try { | 
 |  |  |             String 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]; | 
 |  |  |             } | 
 |  |  |             Log.i("NFCWreatActivity", "cardType=" + cardType); | 
 |  |  |             if (cardType.equals(CardCommon.USER_CARD_TYPE_1) || | 
 |  |  |                     cardType.equals(CardCommon.USER_CARD_TYPE_2) || | 
 |  |  |                     cardType.equals(CardCommon.USER_CARD_TYPE_3) | 
 |  |  |             ) { | 
 |  |  |                 binding.textView.setText("该卡已经写入用户信息,请更换卡片"); | 
 |  |  |                 binding.textView.setTextColor(getResources().getColor(com.dayu.baselibrary.R.color.red)); | 
 |  |  |             } else if (cardType.equals(BaseCommon.CARD_TYPE_ERROR1)) { | 
 |  |  |                 TipUtil.show(NFCWreatActivity.this, "请勿移动卡片,读卡失败请重试!!"); | 
 |  |  |             } else if (cardType.equals(BaseCommon.CARD_TYPE_ERROR2)) { | 
 |  |  |                 TipUtil.show(NFCWreatActivity.this, "卡片未能识别,请检查卡片是否是本公司卡片"); | 
 |  |  |             } else { | 
 |  |  |                 Log.i("NFCWreatActivity", "olduserCard!=null  saveData"); | 
 |  |  |                 userCardBean.setCardNumber(cardNumber); | 
 |  |  |                 baseDao.userCardDao().insert(userCardBean); | 
 |  |  |                 saveData(); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         stopAnim(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private void saveData() { | 
 |  |  |         try { | 
 |  |  |             startAnim(); | 
 |  |  |             if (userCard != null || cleanCard != null || manageCard != null | 
 |  |  |                     || registeredCard != null || cleanUserCard != null | 
 |  |  |                     || domainCard != null || testCard != null | 
 |  |  |                     || configureDeviceRegistrationCrad != null | 
 |  |  |                     || configurationPowerCard != null || regionCard != null || passWordCard != null || electricPriceCard != null) { | 
 |  |  |                 if (userCard != null && TextUtils.isEmpty(morny)) { | 
 |  |  |                     userFlag = WriteCardUtils.setUser(intent, userCard, this); | 
 |  |  |                 } | 
 |  |  |                 if (electricPriceCard != null) { | 
 |  |  |                     setElectricPriceCard(intent, electricPriceCard); | 
 |  |  |                 } | 
 |  |  |                 if (passWordCard != null) { | 
 |  |  |                     setPassWordCard(intent, passWordCard); | 
 |  |  |                 } | 
 |  |  |                 if (regionCard != null) { | 
 |  |  |                     setRegionCard(intent, regionCard); | 
 |  |  |                 } | 
 |  |  |                 if (cleanCard != null) { | 
 |  |  |                     setClean(intent, cleanCard); | 
 |  |  |                 } | 
 |  |  |                 if (manageCard != null) { | 
 |  |  |                     setmanageCard(intent, manageCard); | 
 |  |  | //                    if (manageCardFlag && userCardBeanByManager != null) { | 
 |  |  | //                        //修改用户表信息修改成新卡卡号 | 
 |  |  | //                        userCardBeanByManager.setCardNumber(cardNumber); | 
 |  |  | //                        baseDao.userCardDao().update(userCardBeanByManager); | 
 |  |  | //                    } | 
 |  |  |                 } | 
 |  |  |                 if (registeredCard != null) { | 
 |  |  |                     setRegisteredCard(intent, registeredCard); | 
 |  |  |                 } | 
 |  |  |                 if (cleanUserCard != null) { | 
 |  |  |                     setCleanUserCard(intent, cleanUserCard); | 
 |  |  |                 } | 
 |  |  |                 if (domainCard != null) { | 
 |  |  |                     setDomainCard(intent, domainCard); | 
 |  |  |                 } | 
 |  |  |                 if (testCard != null) { | 
 |  |  |                     setTestCard(intent, testCard); | 
 |  |  |                 } | 
 |  |  |                 if (configureDeviceRegistrationCrad != null) { | 
 |  |  |                     setConfigDeviceRegiest(intent, configureDeviceRegistrationCrad); | 
 |  |  |                 } | 
 |  |  |                 if (configurationPowerCard != null) { | 
 |  |  |                     setConfigurationPower(intent, configurationPowerCard); | 
 |  |  |                 } | 
 |  |  |                 if (electricPriceFlag || passwordFlag || regionFlag || configPowerFlag || configDeviceRegiestFlag || testCardFlag || domainCrdFlag || userFlag || cleanFlag || manageCardFlag || registeredFlag || administrativeCardFlag || cleanUserCardFlag) { | 
 |  |  |                     try { | 
 |  |  |                         if (userFlag && userCardBean != null) { | 
 |  |  |                             //用户卡 | 
 |  |  |                             startDetailActivity(userCardBean.getUserName(), "终端写卡"); | 
 |  |  |                         } else if (!TextUtils.isEmpty(morny)) { | 
 |  |  |                             TipUtil.show(NFCWreatActivity.this, "充值成功", () -> NFCWreatActivity.this.finish()); | 
 |  |  |                         } else { | 
 |  |  |                             TipUtil.show(NFCWreatActivity.this, "写卡成功", () -> NFCWreatActivity.this.finish()); | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                     } catch (Exception e) { | 
 |  |  |                         e.printStackTrace(); | 
 |  |  |                         CrashReport.postCatchedException(e); | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     TipUtil.show(NFCWreatActivity.this, "写卡失败"); | 
 |  |  |                 } | 
 |  |  |                 stopAnim(); | 
 |  |  |             } else if (userCard == null && userCardBean != null) { | 
 |  |  |                 //补卡逻辑 | 
 |  |  |  | 
 |  |  |             } else { | 
 |  |  |                 stopAnim(); | 
 |  |  |                 TipUtil.show(this, "参数错误"); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             CrashReport.postCatchedException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void onNewIntent(Intent intent) { | 
 |  |  |         super.onNewIntent(intent); | 
 |  |  |         try { | 
 |  |  |             this.intent = intent; | 
 |  |  | //            startAnim(); | 
 |  |  |             Log.i("NFCWreatActivity", "isUser:" + isUser); | 
 |  |  |             if (isUser) { | 
 |  |  |                 //新卡注册逻辑 | 
 |  |  |                 checkHasUser(); | 
 |  |  |             } else if (isRecharge) { | 
 |  |  |                 //充值逻辑 | 
 |  |  |                 rechargeWreatCard(); | 
 |  |  |             } else { | 
 |  |  |                 //其他管理卡逻辑 | 
 |  |  |                 saveData(); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             CrashReport.postCatchedException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 打印机相关信息 | 
 |  |  |      * | 
 |  |  |      * @param rechargeBean | 
 |  |  |      */ | 
 |  |  |     private void setPrinterData(RechargeBean rechargeBean) { | 
 |  |  |         try { | 
 |  |  |             StringBuffer data = new StringBuffer(); | 
 |  |  |             if (rechargeBean != null) { | 
 |  |  |                 data.append("*****************************" + "\n"); | 
 |  |  |                 data.append("设备序列号:" + rechargeBean.getSerial() + "\n"); | 
 |  |  |                 data.append("用户名:" + rechargeBean.getUserName() + "\n"); | 
 |  |  |                 data.append("卡  号:" + rechargeBean.getCardNumber() + "\n"); | 
 |  |  |                 data.append("充值金额:" + rechargeBean.getMorny() + " 元" + "\n"); | 
 |  |  |                 data.append("卡内余额:" + rechargeBean.getBalance() + " 元" + "\n"); | 
 |  |  |                 data.append("日  期:" + DateUtil.dateToStamp(rechargeBean.getDate(), DateUtil.type2) + "\n\n"); | 
 |  |  |                 data.append("*****************************"); | 
 |  |  |             } | 
 |  |  |             float size = 26; | 
 |  |  |  | 
 |  |  |             try { | 
 |  |  |                 AidlUtil.getInstance().printText(data.toString(), size, true, false); | 
 |  |  |                 AidlUtil.getInstance().print3Line(); | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 e.printStackTrace(); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |             CrashReport.postCatchedException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     void startAnim() { | 
 |  |  |         binding.avi.show(); | 
 |  |  |         // or avi.smoothToShow(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     void stopAnim() { | 
 |  |  |         binding.avi.hide(); | 
 |  |  |         // or avi.smoothToHide(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     //往卡内写充值后的数据 | 
 |  |  |     private void rechargeWreatCard() { | 
 |  |  |         try { | 
 |  |  |             String cardNumberThis = NfcReadHelper.getInstence(intent, this).getCardNumber(); | 
 |  |  |             cardNumberThis = HexUtil.spaceHex(cardNumberThis); | 
 |  |  |             cardNumberThis = HexUtil.HighLowHex(cardNumberThis); | 
 |  |  |             //判断是否充值的是一个卡 | 
 |  |  |             if (cardNumberThis.equalsIgnoreCase(cardNumber)) { | 
 |  |  |                 //余额 | 
 |  |  |                 int balance = userCard.getBalance() + MornyUtil.changeY2F(morny); | 
 |  |  |                 userCard.setBalance(balance); | 
 |  |  |                 //剩余水量 | 
 |  |  | //                int surplusWater = userCard.getSurplusWater() + MornyUtil.changeY2F(rechageWater); | 
 |  |  | //                userCard.setSurplusWater(surplusWater); | 
 |  |  |  | 
 |  |  |                 int rechageTims = userCard.getRechargeTimes() + 1; | 
 |  |  |                 if (rechageTims == 256) { | 
 |  |  |                     rechageTims = 0; | 
 |  |  |                 } | 
 |  |  |                 userCard.setRechargeTimes((short) rechageTims); | 
 |  |  |                 userCard.setRechargeDate(Calendar.getInstance()); | 
 |  |  |                 userFlag = WriteCardUtils.setUser(intent, userCard, this); | 
 |  |  |                 if (userFlag) { | 
 |  |  |                     rechargeBean = new RechargeBean(); | 
 |  |  |                     rechargeBean.setUserName(userName); | 
 |  |  |                     rechargeBean.setSerial(userCardBean.getSerial()); | 
 |  |  |                     rechargeBean.setUserId(userCardBean.getUserID()); | 
 |  |  |                     rechargeBean.setDate(System.currentTimeMillis()); | 
 |  |  |                     rechargeBean.setMorny(morny); | 
 |  |  |                     rechargeBean.setBalance(MornyUtil.changeF2Y(balance)); | 
 |  |  |                     rechargeBean.setCardNumber(cardNumber); | 
 |  |  |                     rechargeBean.setSurplusWater(MornyUtil.changeF2Y(0)); | 
 |  |  |                     rechargeBean.setRechargeWater(rechageWater); | 
 |  |  |                     try { | 
 |  |  |                         baseDao.rechargeDao().insert(rechargeBean); | 
 |  |  |                     } catch (Exception e) { | 
 |  |  |                         e.printStackTrace(); | 
 |  |  |                     } | 
 |  |  |                     //   打印相关 | 
 |  |  |                     setPrinterData(rechargeBean); | 
 |  |  |                     startDetailActivity(userName, "终端写卡"); | 
 |  |  |                 } else { | 
 |  |  |                     TipUtil.show(NFCWreatActivity.this, "写卡失败,请重新再试"); | 
 |  |  |                 } | 
 |  |  |             } else { | 
 |  |  |                 TipUtil.show(NFCWreatActivity.this, "读取的卡和充值的卡不一致"); | 
 |  |  |             } | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             TipUtil.show(NFCWreatActivity.this, "读取错误,请重试"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void setmanageCard(Intent intent, final ManageCard manageCard) { | 
 |  |  |         manageCardFlag = NFCWriteHelper.getInstence(intent, this).writeData(manageCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 制作清零卡 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param clearOrInitCard | 
 |  |  |      */ | 
 |  |  |     private void setClean(Intent intent, CleanCard clearOrInitCard) { | 
 |  |  |         cleanFlag = NFCWriteHelper.getInstence(intent, this).writeData(clearOrInitCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 保存区域表号卡 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param regionCard | 
 |  |  |      */ | 
 |  |  |     private void setRegionCard(Intent intent, RegionCard regionCard) { | 
 |  |  |         regionFlag = NFCWriteHelper.getInstence(intent, this).writeData(regionCard.toByte(), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 密码卡 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param passWordCard | 
 |  |  |      */ | 
 |  |  |     private void setPassWordCard(Intent intent, PassWordCard passWordCard) { | 
 |  |  |         passwordFlag = NFCWriteHelper.getInstence(intent, this).writeData(passWordCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 用户电量单价 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param electricPriceCard | 
 |  |  |      */ | 
 |  |  |     private void setElectricPriceCard(Intent intent, ElectricPriceCard electricPriceCard) { | 
 |  |  |         electricPriceFlag = NFCWriteHelper.getInstence(intent, this).writeData(electricPriceCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 重新注册设备卡 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param registeredCard | 
 |  |  |      */ | 
 |  |  |     private void setRegisteredCard(Intent intent, RegisteredCard registeredCard) { | 
 |  |  |         registeredFlag = NFCWriteHelper.getInstence(intent, this).writeData(registeredCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 删除全部用户卡 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param cleanUserCard | 
 |  |  |      */ | 
 |  |  |     private void setCleanUserCard(Intent intent, CleanUserCard cleanUserCard) { | 
 |  |  |         cleanUserCardFlag = NFCWriteHelper.getInstence(intent, this).writeData(cleanUserCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 设置域名卡 | 
 |  |  |      * | 
 |  |  |      * @param intent | 
 |  |  |      * @param domainCard | 
 |  |  |      */ | 
 |  |  |     private void setDomainCard(Intent intent, DomainCard domainCard) { | 
 |  |  |         try { | 
 |  |  |             domainCrdFlag = NFCWriteHelper.getInstence(intent, this).writeData(domainCard.getZeroByte(), 1, 0); | 
 |  |  |             if (!domainCrdFlag) { | 
 |  |  |                 return; | 
 |  |  |             } | 
 |  |  |             domainCrdFlag = NFCWriteHelper.getInstence(intent, this).writeData(domainCard.getOneByte(), 1, 1); | 
 |  |  |             if (!domainCrdFlag) { | 
 |  |  |                 return; | 
 |  |  |             } | 
 |  |  |             domainCrdFlag = NFCWriteHelper.getInstence(intent, this).writeData(domainCard.getTwoByte(), 1, 2); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             domainCrdFlag = false; | 
 |  |  |             throw new RuntimeException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void setTestCard(Intent intent, TestCard testCard) { | 
 |  |  |         testCardFlag = NFCWriteHelper.getInstence(intent, this).writeData(testCard.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private void setConfigDeviceRegiest(Intent intent, ConfigureDeviceRegistrationCrad configureDeviceRegistrationCrad) { | 
 |  |  |         configDeviceRegiestFlag = NFCWriteHelper.getInstence(intent, this).writeData(configureDeviceRegistrationCrad.toByte(baseDao), 1, 0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void setConfigurationPower(Intent intent, ConfigurationPowerCard configurationPowerCard) { | 
 |  |  |         try { | 
 |  |  |             configPowerFlag = NFCWriteHelper.getInstence(intent, this).writeData(configurationPowerCard.toByte(baseDao), 1, 0); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             configPowerFlag = false; | 
 |  |  |             throw new RuntimeException(e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private void startDetailActivity(String userName, String statu) { | 
 |  |  |         Intent detail = new Intent(this, RechargeDetailActivity.class); | 
 |  |  |         detail.putExtra("userName", userName); | 
 |  |  |         detail.putExtra("statu", statu); | 
 |  |  |         detail.putExtra("userCard", userCard); | 
 |  |  |         if (!TextUtils.isEmpty(morny)) { | 
 |  |  |             detail.putExtra("morny", morny); | 
 |  |  |             detail.putExtra("rechageWater", rechageWater); | 
 |  |  |         } | 
 |  |  |         if (!TextUtils.isEmpty(cardNumber)) { | 
 |  |  |             detail.putExtra("cardNumber", cardNumber); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         startActivity(detail); | 
 |  |  |         if (NewCardActivity.newCardActivity != null) { | 
 |  |  |             NewCardActivity.newCardActivity.finish(); | 
 |  |  |         } | 
 |  |  |         if (RechargeActivity.rechargeActivity != null) { | 
 |  |  |             RechargeActivity.rechargeActivity.finish(); | 
 |  |  |         } | 
 |  |  |         NFCWreatActivity.nfcWreatActivity.finish(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     protected void onDestroy() { | 
 |  |  |         super.onDestroy(); | 
 |  |  |         nfcWreatActivity = null; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 点击返回时提示用户还未写卡 | 
 |  |  |      * | 
 |  |  |      * @param keyCode | 
 |  |  |      * @param event | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     @Override | 
 |  |  |     public boolean onKeyDown(int keyCode, KeyEvent event) { | 
 |  |  |         if (keyCode == KeyEvent.KEYCODE_BACK) { | 
 |  |  |             back(); | 
 |  |  |             return true; | 
 |  |  |         } | 
 |  |  |         return super.onKeyDown(keyCode, event); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void back() { | 
 |  |  |         confirmDialog = new ConfirmDialog(NFCWreatActivity.this, v -> { | 
 |  |  |             confirmDialog.dismiss(); | 
 |  |  |             if (NewCardActivity.newCardActivity != null) { | 
 |  |  |                 NewCardActivity.newCardActivity.finish(); | 
 |  |  |             } | 
 |  |  |             if (RechargeActivity.rechargeActivity != null) { | 
 |  |  |                 RechargeActivity.rechargeActivity.finish(); | 
 |  |  |             } | 
 |  |  |             NFCWreatActivity.nfcWreatActivity.finish(); | 
 |  |  |         }); | 
 |  |  |         confirmDialog.show(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void titleBack() { | 
 |  |  |         titleBar.setOnItemclickListner(TitleBar.ClickType_LEFT_IMAGE, new View.OnClickListener() { | 
 |  |  |             @Override | 
 |  |  |             public void onClick(View v) { | 
 |  |  |                 back(); | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  | } |