| | |
| | | |
| | | import com.dayu.recharge.MyApplication; |
| | | |
| | | import com.dayu.recharge.R; |
| | | import com.dayu.recharge.card.CleanCard; |
| | | import com.dayu.recharge.card.CleanUserCard; |
| | | import com.dayu.recharge.card.ConfigurationPowerCard; |
| | |
| | | import com.dayu.recharge.card.UserCard; |
| | | import com.dayu.recharge.databinding.ActivityWriteTextBinding; |
| | | import com.dayu.recharge.dbBean.AdminDataBean; |
| | | import com.dayu.recharge.dbBean.DeviceNumber; |
| | | import com.dayu.recharge.dbBean.ElectricPriceBean; |
| | | import com.dayu.recharge.dbBean.RechargeBean; |
| | | import com.dayu.recharge.dbBean.UserCardBean; |
| | | import com.dayu.recharge.net.SocketCallBack; |
| | |
| | | import com.dayu.recharge.utils.AidlUtil; |
| | | import com.dayu.recharge.utils.CRC8; |
| | | import com.dayu.recharge.utils.DateUtil; |
| | | import com.dayu.recharge.utils.DeviceNumberUtils; |
| | | import com.dayu.recharge.utils.MornyUtil; |
| | | import com.dayu.recharge.utils.SocketUtil; |
| | | import com.dayu.recharge.utils.ToastUtil; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * Copyright (C), 2023, |
| | | * Author: zuo |
| | | * Date: 2023-11-08 21:19 |
| | | * Description: nfc写卡界面 |
| | | */ |
| | | public class NFCWreatActivity extends BaseNfcActivity { |
| | | |
| | | |
| | |
| | | } |
| | | if (this.getIntent().hasExtra("cleanCard")) { |
| | | cleanCard = (CleanCard) this.getIntent().getSerializableExtra("cleanCard"); |
| | | binding.cardData.setText("制作清零卡"); |
| | | } |
| | | if (this.getIntent().hasExtra("manageCard")) { |
| | | manageCard = (ManageCard) this.getIntent().getSerializableExtra("manageCard"); |
| | | binding.cardData.setText("制作管理卡"); |
| | | } |
| | | 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"); |
| | | } |
| | | 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("morny")) { |
| | | morny = this.getIntent().getStringExtra("morny"); |
| | | binding.cardData.setText("充值金额:" + morny + "元"); |
| | | } |
| | | |
| | | morny = this.getIntent().getStringExtra("morny"); |
| | | try { |
| | | adminData = baseDao.adminDao().findFirst(); |
| | | } catch (Exception e) { |
| | |
| | | if ((configPowerFlag || configDeviceRegiestFlag || testCardFlag || domainCrdFlag || userFlag || cleanFlag || manageCardFlag || registeredFlag || administrativeCardFlag || cleanUserCardFlag)) { |
| | | try { |
| | | if (userFlag && userCardBean != null) { |
| | | baseDao.userCardDao().insert(userCardBean); |
| | | |
| | | ToastUtil.show(this, "注册成功"); |
| | | NFCWreatActivity.this.finish(); |
| | | if (NewCardActivity.newCardActivity != null) { |
| | |
| | | stopAnim(); |
| | | } else if (!TextUtils.isEmpty(morny)) { |
| | | readAllData(intent); |
| | | } else if (userCard == null && userCardBean != null) { |
| | | //补卡逻辑 |
| | | selectBalance(userCardBean.getInitPeasantCode()); |
| | | } else { |
| | | stopAnim(); |
| | | ToastUtil.show(this, "参数错误"); |
| | |
| | | StringBuffer data = new StringBuffer(); |
| | | if (rechargeBean != null) { |
| | | data.append("*****************************" + "\n"); |
| | | data.append(" 农业水价综合改革充值系统\n\n"); |
| | | data.append(getResources().getString(R.string.login_title) + "\n"); |
| | | data.append("设备序列号:" + rechargeBean.getSerial() + "\n"); |
| | | data.append("用户名:" + rechargeBean.getUserName() + "\n"); |
| | | // data.append("户 号:" + rechargeBean.getUserNum() + "\n"); |
| | |
| | | try { |
| | | RechargeRequestBean rechargeRequestBean = new RechargeRequestBean(); |
| | | rechargeRequestBean.setControl("01"); |
| | | String initCode = WSHelper.getInstance(this).get("initCode", ""); |
| | | String initCode = DeviceNumberUtils.getDeviceNumber(); |
| | | rechargeRequestBean.setInitCode(initCode); |
| | | rechargeRequestBean.setXuLie(SocketUtil.getXuLie(this)); |
| | | rechargeRequestBean.setAFN("95"); |
| | |
| | | |
| | | |
| | | /** |
| | | * 查询余额 |
| | | * |
| | | * @param initPeasantCode 农户注册编号 |
| | | */ |
| | | private void selectBalance(String initPeasantCode) { |
| | |
| | | BalanceSelecteRequestBean requestBean = new BalanceSelecteRequestBean(); |
| | | requestBean.setAFN("94"); |
| | | requestBean.setControl("01"); |
| | | String initCode = WSHelper.getInstance(this).get("initCode", ""); |
| | | String initCode = DeviceNumberUtils.getDeviceNumber(); |
| | | requestBean.setInitCode(initCode); |
| | | requestBean.setInitPeasantCode(initPeasantCode); |
| | | requestBean.setXuLie(SocketUtil.getXuLie(this)); |
| | |
| | | stateText = new StringBuffer(); |
| | | stateText.append("状 态:"); |
| | | String state = BcdUtil.bcdToStr(readData.getBodyBytes()[2]); //BCD码00启用 01禁用 02隶属信息不符 03无此卡信息 04其它s |
| | | if (userCard == null) { |
| | | userCard = new UserCard(); |
| | | userCard.setRechargeTimes(0); |
| | | |
| | | ElectricPriceBean electricPriceBean = baseDao.electricPriceDao().findFirst(); |
| | | if (electricPriceBean != null) { |
| | | userCard.setElectricityPrice(electricPriceBean.getPrice()); |
| | | } else { |
| | | //默认是1元 |
| | | userCard.setElectricityPrice(1.000f); |
| | | } |
| | | userCard.setSwipeNumber((short) 0); |
| | | userCard.setState("00"); |
| | | userCard.setBalance(0); |
| | | userCard.setAddressCode(adminData.getAddressCode()); |
| | | userCard.setInitPeasantCode(initPeasantCode); |
| | | } |
| | | |
| | | if ("00".equals(state)) { |
| | | //只有启动状态才能充值 |
| | | //金额 |
| | |
| | | //姓名 |
| | | byte[] nameByte = Arrays.copyOfRange(readData.getBodyBytes(), 7, 19); |
| | | String name = SocketUtil.fromHexString(SocketUtil.bytesToHexClean0(nameByte)); |
| | | rechargeBean = new RechargeBean(); |
| | | rechargeBean.setDate(System.currentTimeMillis()); |
| | | rechargeBean.setMorny(morny); |
| | | if (userCardBean != null) { |
| | | rechargeBean.setUserName(userCardBean.getUserName()); |
| | | } else { |
| | | rechargeBean.setUserName(name); |
| | | } |
| | | List<UserCardBean> userCardBeans = baseDao.userCardDao().findAll(); |
| | | String userId = ""; |
| | | if (userCardBeans != null) { |
| | | for (int i = 0; i < userCardBeans.size(); i++) { |
| | | if (initPeasantCode.equalsIgnoreCase(userCardBeans.get(i).getInitPeasantCode())) { |
| | | userId = userCardBeans.get(i).getUserID(); |
| | | userCard.setBalance(balance); |
| | | //与socket服务器通信后进行后续操作 |
| | | |
| | | if (!TextUtils.isEmpty(morny)) { |
| | | //充值 |
| | | rechargeBean = new RechargeBean(); |
| | | rechargeBean.setDate(System.currentTimeMillis()); |
| | | rechargeBean.setMorny(morny); |
| | | if (userCardBean != null) { |
| | | rechargeBean.setUserName(userCardBean.getUserName()); |
| | | } else { |
| | | rechargeBean.setUserName(name); |
| | | } |
| | | List<UserCardBean> userCardBeans = baseDao.userCardDao().findAll(); |
| | | String userId = ""; |
| | | if (userCardBeans != null) { |
| | | for (int i = 0; i < userCardBeans.size(); i++) { |
| | | if (initPeasantCode.equalsIgnoreCase(userCardBeans.get(i).getInitPeasantCode())) { |
| | | userId = userCardBeans.get(i).getUserID(); |
| | | } |
| | | } |
| | | } |
| | | rechargeBean.setSerial(adminData.getSerial()); |
| | | userCard.setRechargeDate(Calendar.getInstance()); |
| | | rechargeBean.setBalance(MornyUtil.changeF2Y(balance + MornyUtil.changeY2F(morny)) + ""); |
| | | rechargeBean.setUserId(userId); |
| | | recharge(initPeasantCode); |
| | | } else { |
| | | //补卡逻辑 |
| | | setUser(intent, userCard); |
| | | if (userFlag) { |
| | | NFCWreatActivity.this.finish(); |
| | | ToastUtil.show(NFCWreatActivity.this, "补卡成功"); |
| | | } |
| | | } |
| | | rechargeBean.setSerial(adminData.getSerial()); |
| | | userCard.setBalance(balance); |
| | | userCard.setRechargeDate(Calendar.getInstance()); |
| | | rechargeBean.setBalance(MornyUtil.changeF2Y(balance) + ""); |
| | | rechargeBean.setUserId(userId); |
| | | //与socket服务器通信后进行后续操作 |
| | | recharge(initPeasantCode); |
| | | |
| | | stateText.append("启用"); |
| | | return; |
| | | } else if ("01".equals(state)) { |