左晓为主开发手持机充值管理机
zuoxiao
2023-11-23 50f6dd3b617f769e7fc6094c2dd0752747541489
修复导出充值记录bug
优化充值记录加载逻辑和速度
优化导出记录逻辑
17个文件已修改
1个文件已添加
684 ■■■■■ 已修改文件
app/src/main/java/com/dayu/recharge/MyApplication.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/activity/BaseNfcActivity.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/activity/HomeActivity.java 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/activity/MyActivity.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/activity/ReadCardAcitivy.java 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/activity/RechargeActivity.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/activity/RechargeListActivity.java 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/dao/RechargeDao.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/model/RechargeListModel.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/model/UserListMode.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java 204 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/utils/ExcelUtil.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_admin.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_home.xml 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_my.xml 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_parameter.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_recharge.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_recharge_detail.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/dayu/recharge/MyApplication.java
@@ -66,13 +66,20 @@
        isAidl = aidl;
    }
    IpBean ipBean;
    /**
     * 初始化EasySocket
     */
    public void initEasySocket(boolean isCreate, SocketNet.CreateBack createBack) {
        try {
            this.createBack = createBack;
            IpBean ipBean = BaseDaoSingleton.getInstance(MyApplication.myApplication).ipDao().findFirst();
            ipBean = BaseDaoSingleton.getInstance(MyApplication.myApplication).ipDao().findFirst();
            if (ipBean == null) {
                ipBean = new IpBean();
                ipBean.setIp("dayuyanjiuyuan.top");
                ipBean.setPort(8888);
            }
            if (ipBean != null) {
                try {
                    //处理当连接上IP后修改ip不生效问题
app/src/main/java/com/dayu/recharge/activity/BaseNfcActivity.java
@@ -9,12 +9,16 @@
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.nfc.Tag;
import android.os.Handler;
import android.os.Message;
import com.dayu.recharge.card.UserCard;
import com.dayu.recharge.tools.NfcReadHelper;
import com.dayu.recharge.utils.LogUtil;
import com.dayu.recharge.utils.TipUtil;
import com.tencent.bugly.crashreport.CrashReport;
@@ -62,6 +66,23 @@
        super.onStart();
        //此处adapter需要重新获取,否则无法获取message
        mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (mNfcAdapter != null){
            mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
                @Override
                public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
                    // 在此处处理NFC消息的创建
                    return null;
                }
            }, this);
        }
//            mNfcAdapter.enableReaderMode(this, new NfcAdapter.ReaderCallback() {
//                @Override
//                public void onTagDiscovered(Tag tag) {
//                    LogUtil.e(tag.toString());
//                }
//            }, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
        //一旦截获NFC消息,就会通过PendingIntent调用窗口
        mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()), 0);
@@ -107,43 +128,5 @@
            return false;
        }
        return true;
    }
    /**
     * 读取全部数据
     */
    public void readAllData(Intent intent) {
        try {
            NfcReadHelper.getInstence(intent)
                    .getAllData(new NfcReadHelper.NFCCallListback() {
                        @Override
                        public void callBack(Map<String, List<byte[]>> data) {
                            Message message = new Message();
//                           获取1扇区数据
                            List<byte[]> oneSector = data.get("1");
                            if (oneSector != null && oneSector.size() > 0) {
                                userCard = UserCard.getBean(oneSector);
                                message.what = RECHARGE;
                            } else {
                                message.what = ERROR;
                            }
                            if (handler != null) {
                                handler.sendMessage(message);
                            }
                        }
                        @Override
                        public void error(int code) {
                            if (handler != null) {
                                Message message = new Message();
                                message.what = ERROR;
                                handler.sendMessage(message);
                            }
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
        }
    }
}
app/src/main/java/com/dayu/recharge/activity/HomeActivity.java
@@ -3,14 +3,17 @@
import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;
import com.dayu.recharge.MyApplication;
import com.dayu.recharge.R;
import com.dayu.recharge.databinding.ActivityHomeBinding;
import com.dayu.recharge.dbBean.AdminDataBean;
import com.dayu.recharge.utils.TipUtil;
import com.dayu.recharge.utils.ToastUtil;
import com.permissionx.guolindev.PermissionX;
@@ -71,7 +74,7 @@
                if (adminData != null) {
                    startActivity(new Intent(HomeActivity.this, NewCardActivity.class));
                } else {
                    TipUtil.show("请先设置管理员信息");
                    TipUtil.show("请先设置地址信息");
                }
            }
@@ -83,7 +86,7 @@
                if (adminData != null) {
                    startActivity(new Intent(HomeActivity.this, RechargeActivity.class));
                } else {
                    TipUtil.show("请先设置管理员信息");
                    TipUtil.show("请先设置地址信息");
                }
            }
@@ -120,8 +123,24 @@
    @Override
    protected void onDestroy() {
        super.onDestroy();
        homeActivity=null;
        homeActivity = null;
    }
    long mExitTime;
    //点击两次退出程序 有时间间隔 间隔内点击则退出程序 否则 则提示
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if ((System.currentTimeMillis() - mExitTime) > 2000) {
                Toast.makeText(HomeActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                mExitTime = System.currentTimeMillis();
            } else {
                HomeActivity.this.finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
app/src/main/java/com/dayu/recharge/activity/MyActivity.java
@@ -6,9 +6,13 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import androidx.annotation.NonNull;
import com.dayu.recharge.MyApplication;
import com.dayu.recharge.databinding.ActivityMyBinding;
@@ -119,42 +123,72 @@
    }
    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(@NonNull Message msg) {
            switch (msg.what) {
                case 1:
                    TipUtil.show(MyActivity.this, "导出成功!");
                    break;
                default:
                    TipUtil.show(MyActivity.this, "导出失败!");
                    break;
            }
            stopAnim();
            return false;
        }
    });
    /**
     * 导出成Excel
     */
    private void outExcl() {
        startAnim();
        File file = new File(ExcelUtil.outPath);
        //文件夹是否已经存在
        if (!file.exists()) {
            file.mkdirs();
        }
        List listData = new ArrayList();
        try {
            if (isRechargeList) {
                listData = baseDao.rechargeDao().findByTime(beginTime, endTime);
            } else {
                listData = baseDao.userCardDao().findByTime(beginTime, endTime);
        new Thread(new Runnable() {
            @Override
            public void run() {
                {
                    try {
                        File file = new File(ExcelUtil.outPath);
                        //文件夹是否已经存在
                        if (!file.exists()) {
                            file.mkdirs();
                        }
                        List listData = new ArrayList();
                        try {
                            if (isRechargeList) {
                                listData = asynchBaseDao.rechargeDao().ansyFindByTime(beginTime, endTime);
                            } else {
                                listData = baseDao.userCardDao().findByTime(beginTime, endTime);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        String[] title;
                        String fileName;
                        if (listData == null || listData.size() == 0) {
                            TipUtil.show(MyActivity.this, "记录为空");
                            return;
                        }
                        if (isRechargeList) {
                            title = new String[]{"设备序列号", "用户名", "身份证号", "充值日期", "充值金额(元)", "剩余金额(元)"};
                            fileName = file.toString() + "/" + ExcelUtil.outRechargePathName;
                        } else {
                            title = new String[]{"设备序列号", "用户名", "身份证号", "注册日期", "电话"};
                            fileName = file.toString() + "/" + ExcelUtil.outUserPathName;
                        }
                        ExcelUtil.initExcel(fileName, title);
                        ExcelUtil.writeObjListToExcel(listData, fileName, MyActivity.this);
                        handler.sendEmptyMessage(1);
                    } catch (Exception e) {
                        handler.sendEmptyMessage(2);
                        e.printStackTrace();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        String[] title;
        String fileName;
        if (listData == null || listData.size() == 0) {
            TipUtil.show(MyActivity.this, "记录为空");
            return;
        }
        if (isRechargeList) {
            title = new String[]{"设备序列号", "用户名", "身份证号", "充值日期", "充值金额(元)", "剩余金额(元)"};
            fileName = file.toString() + "/" + ExcelUtil.outRechargePathName;
        } else {
            title = new String[]{"设备序列号", "用户名", "身份证号", "注册日期", "电话"};
            fileName = file.toString() + "/" + ExcelUtil.outUserPathName;
        }
        ExcelUtil.initExcel(fileName, title);
        ExcelUtil.writeObjListToExcel(listData, fileName, MyActivity.this);
        stopAnim();
        }).start();
    }
    void getVersion(Activity context) {
app/src/main/java/com/dayu/recharge/activity/ReadCardAcitivy.java
@@ -3,11 +3,9 @@
import android.content.Intent;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import com.dayu.recharge.card.ConfigurationPowerCard;
import com.dayu.recharge.card.DomainCard;
@@ -96,12 +94,12 @@
    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        this.intent = intent;
        ProgressDialog.show(this);
        if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) {
            readAllData(intent);
        }
        super.onNewIntent(intent);
    }
    /**
@@ -110,136 +108,93 @@
    public void readAllData(Intent intent) {
        NfcReadHelper.getInstence(intent)
                .getAllData(new NfcReadHelper.NFCCallListback() {
                .getOneSectorData(new NfcReadHelper.NFCCallListback() {
                    @Override
                    public void callBack(Map<String, List<byte[]>> data) {
                        Message message = new Message();
                    public void callBack(List<byte[]> data) {
                        //获取1扇区数据
                        List<byte[]> oneSector = data.get("1");
                        if (oneSector != null && oneSector.size() > 0) {
                            byte cardType = oneSector.get(0)[0];
                        if (data != null && data.size() > 0) {
                            byte cardType = data.get(0)[0];
                            String cardTypeStr = HexUtil.byteToHex(cardType);
                            switch (cardTypeStr) {
                                case MyCommon.USER_CARD_TYPE_1:
                                case MyCommon.USER_CARD_TYPE_2:
                                case MyCommon.USER_CARD_TYPE_3:
                                    userCard = UserCard.getBean(oneSector);
                                    message.what = USER_CRAD;
                                    userCard = UserCard.getBean(data);
                                    selectBalance(userCard.getInitPeasantCode());
                                    break;
                                case MyCommon.MANAGE_CRAD:
                                    message.what = MANAGE_CRAD;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为管理卡");
                                    stopAnim();
                                    break;
                                case MyCommon.CLEAN_CARD_TYPE:
                                    message.what = CLEAN_CARD;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为清零卡");
                                    stopAnim();
                                    break;
                                case MyCommon.REGISTERED_CARD_TYPE:
                                    message.what = REGISTERED_CARD;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为重新注册设备卡");
                                    stopAnim();
                                    break;
                                case MyCommon.CLEAN_ALL_USER_CARD_TYPE:
                                    message.what = CLEAN_ALL_USER;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为删除全部用户卡");
                                    stopAnim();
                                    break;
                                case MyCommon.DOMAIN_CARD_TYPE:
                                    message.what = DOMAIN_CARD;
                                    message.obj = oneSector;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为设置域名卡");
                                    DomainCard domainCard = DomainCard.toBean(data);
                                    redCardBinding.readCardDataTV.setText("序号:" + domainCard.getDomainNumber() + "\n" + "域名:" + domainCard.getDomainName() + "\n" + "端口号:" + domainCard.getPort());
                                    stopAnim();
                                    break;
                                case MyCommon.TEST_CARD_TYPE:
                                    message.what = TEST_CARD;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为测试卡");
                                    stopAnim();
                                    break;
                                case MyCommon.CONFIGURATION_CARD_TYPE:
                                    message.what = CONFIGURATION_CARD;
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前为配置设备注册信息卡");
                                    stopAnim();
                                    break;
                                case MyCommon.CONFIGURATION_POWER_CARD_TYPE:
                                    message.what = CONFIGURATION_POWER_CARD;
                                    message.obj = oneSector.get(0);
                                    viweGone(false);
                                    redCardBinding.readCardTypeTV.setText("当前配置水泵功率卡");
                                    ConfigurationPowerCard powerCard = ConfigurationPowerCard.toBean(data.get(0));
                                    redCardBinding.readCardDataTV.setText(powerCard.getPower());
                                    stopAnim();
                                    break;
                                default:
                                    TipUtil.show(ReadCardAcitivy.this, "卡片无法识别");
                                    stopAnim();
                                    break;
                            }
                        } else {
                            message.what = MyCommon.ERROR;
                            TipUtil.show(ReadCardAcitivy.this, "卡片无法识别");
                            stopAnim();
                        }
                        handler.sendMessage(message);
                    }
                    }
                    @Override
                    public void error(int code) {
                        Message message = new Message();
                        message.what = code;
                        handler.sendMessage(message);
                        switch (code) {
                            case MyCommon.ERROR_MOVE:
                                stopAnim();
                                TipUtil.show("连接中断,请重新贴合卡片");
                                break;
                            default:
                                stopAnim();
                                TipUtil.show("卡片识别错误,请重试!");
                        }
                    }
                });
    }
    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case USER_CRAD:
                    selectBalance(userCard.getInitPeasantCode());
                    break;
                case MANAGE_CRAD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为管理卡");
                    stopAnim();
                    break;
                case CLEAN_CARD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为清零卡");
                    stopAnim();
                    break;
                case REGISTERED_CARD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为重新注册设备卡");
                    stopAnim();
                    break;
                case CLEAN_ALL_USER:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为删除全部用户卡");
                    stopAnim();
                    break;
                case DOMAIN_CARD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为设置域名卡");
                    List<byte[]> data = (List<byte[]>) msg.obj;
                    DomainCard domainCard = DomainCard.toBean(data);
                    redCardBinding.readCardDataTV.setText("序号:" + domainCard.getDomainNumber() + "\n" + "域名:" + domainCard.getDomainName() + "\n" + "端口号:" + domainCard.getPort());
                    stopAnim();
                    break;
                case TEST_CARD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为测试卡");
                    stopAnim();
                    break;
                case CONFIGURATION_CARD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为配置设备注册信息卡");
                    stopAnim();
                    break;
                case CONFIGURATION_POWER_CARD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前配置水泵功率卡");
                    byte[] powerData = (byte[]) msg.obj;
                    ConfigurationPowerCard powerCard = ConfigurationPowerCard.toBean(powerData);
                    redCardBinding.readCardDataTV.setText(powerCard.getPower());
                    stopAnim();
                    break;
                case PASS_WORD_CRAD:
                    viweGone(false);
                    redCardBinding.readCardTypeTV.setText("当前为密码卡");
                    stopAnim();
                    break;
                case MyCommon.ERROR_MOVE:
                    stopAnim();
                    TipUtil.show("连接中断,请重新贴合卡片");
                    break;
                default:
                    TipUtil.show(ReadCardAcitivy.this, "卡片无法识别");
                    stopAnim();
                    break;
            }
            return false;
        }
    });
    private void viweGone(boolean isUSerCard) {
        redCardBinding.readImgLL.setVisibility(View.GONE);
app/src/main/java/com/dayu/recharge/activity/RechargeActivity.java
@@ -73,7 +73,7 @@
                TipUtil.show(RechargeActivity.this, "卡片读取失败");
            }
            readAllData(intent);
//            readAllData(intent);
        } catch (Exception e) {
            e.printStackTrace();
            CrashReport.postCatchedException(e);
@@ -195,7 +195,9 @@
                            binding.redRemainderBlance.setText(MornyUtil.changeF2Y(balance));
                            binding.redStatu.setText(stateText.toString());
                            binding.redInitCode.setText(initPeasantCode);
                            if ("00".equals(state)) {
                                binding.rechargeRegistBtn.setVisibility(View.VISIBLE);
                                stateText.append("启用");
                                userCard.setState("00");
                                userCard.setBalance(balance);
@@ -215,6 +217,7 @@
                            }
                            binding.redStatu.setText(stateText.toString());
                            binding.rechargeLL.setVisibility(View.GONE);
                            binding.rechargeRegistBtn.setVisibility(View.GONE);
                            binding.rechargeRegistBtn.setVisibility(View.GONE);
                            TipUtil.show(RechargeActivity.this, stateText.toString());
                        } catch (Exception e) {
@@ -238,8 +241,9 @@
        }
    }
    protected void onDestroy() {
        super.onDestroy();
        rechargeActivity=null;
        rechargeActivity = null;
    }
}
app/src/main/java/com/dayu/recharge/activity/RechargeListActivity.java
@@ -35,6 +35,8 @@
    long beginTime;
    long endTime;
    RechargeListModel rechargeListModel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -48,11 +50,12 @@
    private void setData() {
        RechargeListModel rechargeListModel = new RechargeListModel(this);
        rechargeListModel.getRechargeList().observe(this, myList -> {
        rechargeListModel = new RechargeListModel(this);
        rechargeListModel.getAllRechargeList().observe(this, myList -> {
            rechargeList.clear();
            rechargeList.addAll(myList);
            adapter.notifyDataSetChanged();
            getTotal();
        });
        adapter = new RechargeAdapter(this, rechargeList);
        rechargeListBinding.rechargeList.setAdapter(adapter);
@@ -109,11 +112,19 @@
                    TipUtil.show(RechargeListActivity.this, "结束时间不能晚于开始时间");
                } else {
                    endTime = endTime + (1000 * 60 * 60 * 24) - 1;
                    List<RechargeBean> userList = baseDao.rechargeDao().findByTime(beginTime, endTime);
                    rechargeList.clear();
                    rechargeList.addAll(userList);
                    adapter.notifyDataSetChanged();
                    getTotal();
                    rechargeListModel.getRechargeList(beginTime, endTime).observe(RechargeListActivity.this, list -> {
                        if (rechargeList != null) {
                            rechargeList.clear();
                            rechargeList.addAll(list);
                            adapter.notifyDataSetChanged();
                            getTotal();
                        } else {
                            TipUtil.show(RechargeListActivity.this, "未查询到数据!");
                        }
                    });
                }
            }
app/src/main/java/com/dayu/recharge/dao/RechargeDao.java
@@ -35,5 +35,8 @@
    LiveData<List<RechargeBean>> findAll();
    @Query("select  * from RechargeBean where date>=:beginTime and date<=:endTime")
    List<RechargeBean> findByTime(long beginTime, long endTime);
    LiveData<List<RechargeBean>> findByTime(long beginTime, long endTime);
    @Query("select  * from RechargeBean where date>=:beginTime and date<=:endTime")
    List<RechargeBean> ansyFindByTime(long beginTime, long endTime);
}
app/src/main/java/com/dayu/recharge/model/RechargeListModel.java
@@ -4,6 +4,7 @@
import androidx.lifecycle.ViewModel;
import com.dayu.recharge.activity.BaseActivity;
import com.dayu.recharge.dao.RechargeDao;
import com.dayu.recharge.dbBean.RechargeBean;
import java.util.List;
@@ -13,17 +14,23 @@
 * author: zuo
 * Date: 2023-11-23
 * Time: 9:06
 * 备注:
 * 备注:充值记录的mode
 */
public class RechargeListModel   {
public class RechargeListModel {
    LiveData<List<RechargeBean>> rechargeList;
    RechargeDao rechargeDao;
    public RechargeListModel(BaseActivity baseActivity) {
        rechargeList = baseActivity.asynchBaseDao.rechargeDao().findAll();
        rechargeDao = baseActivity.asynchBaseDao.rechargeDao();
    }
    public LiveData<List<RechargeBean>> getRechargeList() {
    public LiveData<List<RechargeBean>> getAllRechargeList() {
        rechargeList = rechargeDao.findAll();
        return rechargeList;
    }
    public LiveData<List<RechargeBean>> getRechargeList(long beginTime, long endTime) {
        rechargeList = rechargeDao.findByTime(beginTime,endTime);
        return rechargeList;
    }
app/src/main/java/com/dayu/recharge/model/UserListMode.java
New file
@@ -0,0 +1,30 @@
package com.dayu.recharge.model;
import android.app.Activity;
import com.dayu.recharge.dbBean.UserCardBean;
import java.util.List;
/**
 * Created by Android Studio.
 * author: zuo
 * Date: 2023-11-23
 * Time: 16:35
 * 备注:用户记录的mode
 */
public class UserListMode {
    List<UserCardBean> userCardBeanList;
    public UserListMode(Activity activity) {
    }
    public List<UserCardBean> getUserCardBeanList() {
        return userCardBeanList;
    }
    public void setUserCardBeanList(List<UserCardBean> userCardBeanList) {
        this.userCardBeanList = userCardBeanList;
    }
}
app/src/main/java/com/dayu/recharge/tools/NfcReadHelper.java
@@ -69,8 +69,8 @@
                List<byte[]> list = new ArrayList<>();
                //验证扇区密码,否则会报错(链接失败错误)
                boolean isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
                if (!isOpen){
                    isOpen=   mfc.authenticateSectorWithKeyA(1, companyKey);
                if (!isOpen) {
                    isOpen = mfc.authenticateSectorWithKeyA(1, companyKey);
                }
                if (isOpen) {
                    //获取扇区里面块的数量
@@ -118,8 +118,8 @@
            try {
                mfc.connect();
                boolean isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
                if (!isOpen){
                    isOpen= mfc.authenticateSectorWithKeyA(1, companyKey);
                if (!isOpen) {
                    isOpen = mfc.authenticateSectorWithKeyA(1, companyKey);
                }
                if (isOpen) {
                    int bIndex = mfc.sectorToBlock(1);
@@ -152,72 +152,136 @@
     *
     * @param callback
     */
    public void getAllData(final NFCCallListback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Map<String, List<byte[]>> map = new HashMap<>();
                MifareClassic mfc = MifareClassic.get(tag);
                if (null != mfc) {
                    try {
                        //链接NFC
                        mfc.connect();
                        //获取扇区数量
                        int count = mfc.getSectorCount();
                        //存储空间
                        int size = mfc.getSize();
                        //用于判断时候有内容读取出来
                        boolean flag = false;
                        for (int i = 0; i < count; i++) {
                            List<byte[]> list = new ArrayList<>();
                            //验证扇区密码,否则会报错(链接失败错误)
                            boolean isOpen = mfc.authenticateSectorWithKeyA(i, defauleKey);
                            if (!isOpen){
                                isOpen = mfc.authenticateSectorWithKeyA(i, companyKey);
    public void getAllData(final NFCCallMapback callback) {
        Map<String, List<byte[]>> map = new HashMap<>();
        MifareClassic mfc = MifareClassic.get(tag);
        if (null != mfc) {
            try {
                //链接NFC
                mfc.connect();
                //获取扇区数量
                int count = mfc.getSectorCount();
                //存储空间
                int size = mfc.getSize();
                //用于判断时候有内容读取出来
                boolean flag = false;
                for (int i = 0; i < count; i++) {
                    List<byte[]> list = new ArrayList<>();
                    //验证扇区密码,否则会报错(链接失败错误)
                    boolean isOpen = mfc.authenticateSectorWithKeyA(i, defauleKey);
                    if (!isOpen) {
                        isOpen = mfc.authenticateSectorWithKeyA(i, companyKey);
                    }
                    if (isOpen) {
                        //获取扇区里面块的数量
                        int bCount = mfc.getBlockCountInSector(i);
                        //获取扇区第一个块对应芯片存储器的位置(我是这样理解的,因为第0扇区的这个值是4而不是0)
                        int bIndex = mfc.sectorToBlock(i);
                        //String data1 = "";
                        for (int j = 0; j < bCount; j++) {
                            //读取数据
                            byte[] data = null;
                            try {
                                data = mfc.readBlock(bIndex);
                                bIndex++;
                                list.add(data);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            if (isOpen) {
                                //获取扇区里面块的数量
                                int bCount = mfc.getBlockCountInSector(i);
                                //获取扇区第一个块对应芯片存储器的位置(我是这样理解的,因为第0扇区的这个值是4而不是0)
                                int bIndex = mfc.sectorToBlock(i);
                                //String data1 = "";
                                for (int j = 0; j < bCount; j++) {
                                    //读取数据
                                    byte[] data = null;
                                    try {
                                        data = mfc.readBlock(bIndex);
                                        bIndex++;
                                        list.add(data);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                                flag = true;
                            }
                            map.put(i + "", list);
                        }
                        if (flag) {
                            callback.callBack(map);
                        } else {
                            callback.error(MyCommon.ERROR);
                        }
                    } catch (IOException e) {
                        callback.error(MyCommon.ERROR_MOVE);
                        e.printStackTrace();
                    } catch (Exception e) {
                        callback.error(MyCommon.ERROR);
                        e.printStackTrace();
                    } finally {
                        flag = true;
                    }
                    map.put(i + "", list);
                }
                if (flag) {
                    callback.callBack(map);
                } else {
                    callback.error(MyCommon.ERROR);
                }
            } catch (IOException e) {
                callback.error(MyCommon.ERROR_MOVE);
                e.printStackTrace();
            } catch (Exception e) {
                callback.error(MyCommon.ERROR);
                e.printStackTrace();
            } finally {
                try {
                    mfc.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     * 获取1扇区信息
     *
     * @param callback
     */
    public void getOneSectorData(NFCCallListback callback) {
        MifareClassic mfc = null;
        try {
            mfc = MifareClassic.get(tag);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (null != mfc) {
            try {
                //链接NFC
                mfc.connect();
                //用于判断时候有内容读取出来
                boolean flag = false;
                List<byte[]> list = new ArrayList<>();
                //验证扇区密码,否则会报错(链接失败错误)
                boolean isOpen = mfc.authenticateSectorWithKeyA(1, companyKey);
                if (!isOpen) {
                    isOpen = mfc.authenticateSectorWithKeyA(1, defauleKey);
                }
                if (isOpen) {
                    //获取扇区里面块的数量
                    int bCount = mfc.getBlockCountInSector(1);
                    //获取扇区第一个块对应芯片存储器的位置(我是这样理解的,因为第0扇区的这个值是4而不是0)
                    int bIndex = mfc.sectorToBlock(1);
                    //String data1 = "";
                    for (int j = 0; j < bCount; j++) {
                        //读取数据
                        byte[] data = null;
                        try {
                            mfc.close();
                            data = mfc.readBlock(bIndex);
                            bIndex++;
                            list.add(data);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    flag = true;
                }
                if (flag) {
                    callback.callBack(list);
                } else {
                    callback.error(MyCommon.ERROR);
                }
            } catch (IOException e) {
                callback.error(MyCommon.ERROR_MOVE);
                e.printStackTrace();
            } catch (Exception e) {
                callback.error(MyCommon.ERROR);
                e.printStackTrace();
            } finally {
                try {
                    mfc.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        }
    }
    /**
     * 读取NFC卡的特定扇区信息
@@ -263,7 +327,7 @@
                                break;
                        }
                        boolean isOpen = mfc.authenticateSectorWithKeyA(a, defauleKey);
                        if (!isOpen){
                        if (!isOpen) {
                            isOpen = mfc.authenticateSectorWithKeyA(a, companyKey);
                        }
                        if (isOpen) {
@@ -293,7 +357,7 @@
    /**
     * 返回监听类
     */
    public interface NFCCallListback {
    public interface NFCCallMapback {
        /**
         * 返回读取nfc卡的全部信息
         *
@@ -305,6 +369,22 @@
        void error(int code);
    }
    /**
     * 返回监听类
     */
    public interface NFCCallListback {
        /**
         * 返回读取nfc卡的全部信息
         *
         * @param data 前面代表扇区 四个块的数据用#号隔开
         */
        void callBack(List<byte[]> data);
        void error(int code);
    }
    public interface NFCCallByteback {
        /**
         * 返回读取nfc卡的全部信息
app/src/main/java/com/dayu/recharge/utils/ExcelUtil.java
@@ -131,7 +131,11 @@
                        RechargeBean projectBean = (RechargeBean) objList.get(j);
                        list.add(projectBean.getSerial());
                        list.add(projectBean.getUserName());
                        list.add(projectBean.getUserId());
                        if (projectBean.getUserId() != null) {
                            list.add(projectBean.getUserId());
                        } else {
                            list.add("");
                        }
                        list.add(DateUtil.dateToStamp(projectBean.getDate(), DateUtil.type2));
                        list.add(projectBean.getMorny());
                        list.add(projectBean.getBalance());
app/src/main/res/layout/activity_admin.xml
@@ -31,6 +31,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作管理卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -41,6 +42,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作清零卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -51,6 +53,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作重新注册设备卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -61,6 +64,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作删除全部用户卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -71,6 +75,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作设置域名卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
@@ -82,6 +87,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作测试卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -92,6 +98,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作配置设备信息卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -102,6 +109,7 @@
                android:layout_marginTop="20dp"
                android:padding="5dp"
                android:text="制作配置水泵功率卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
        </LinearLayout>
app/src/main/res/layout/activity_home.xml
@@ -14,15 +14,15 @@
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:layout_marginTop="30dp"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/home_newCard"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="新卡开户"
@@ -32,7 +32,7 @@
        <TextView
            android:id="@+id/home_recharge"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="充值"
@@ -42,7 +42,7 @@
        <TextView
            android:id="@+id/home_redCard"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="读取卡片"
@@ -52,7 +52,7 @@
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:orientation="horizontal">
@@ -60,7 +60,7 @@
        <TextView
            android:id="@+id/home_admin"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="管理系统"
@@ -70,7 +70,7 @@
        <TextView
            android:id="@+id/home_parameter"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="参数设置"
@@ -80,7 +80,7 @@
        <TextView
            android:id="@+id/home_my"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="个人中心"
app/src/main/res/layout/activity_my.xml
@@ -57,12 +57,14 @@
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="地址信息:"
                    android:textColor="@color/text_selecter"
                    android:textSize="@dimen/text_size" />
                <TextView
                    android:id="@+id/my_adminName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@color/text_selecter"
                    android:textSize="@dimen/text_size" />
            </LinearLayout>
@@ -81,6 +83,7 @@
                    android:layout_height="wrap_content"
                    android:layout_toStartOf="@+id/my_newCardOut"
                    android:text="开户记录"
                    android:textColor="@color/text_selecter"
                    android:textSize="@dimen/text_size" />
                <TextView
@@ -89,6 +92,7 @@
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:text="导出记录"
                    android:textColor="@color/text_selecter"
                    android:textSize="@dimen/text_size" />
            </RelativeLayout>
@@ -104,6 +108,7 @@
                    android:layout_height="wrap_content"
                    android:layout_toStartOf="@+id/my_rechargeOut"
                    android:text="充值记录"
                    android:textColor="@color/text_selecter"
                    android:textSize="@dimen/text_size" />
                <TextView
@@ -112,6 +117,7 @@
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:text="导出记录"
                    android:textColor="@color/text_selecter"
                    android:textSize="@dimen/text_size" />
            </RelativeLayout>
@@ -123,6 +129,7 @@
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="IP设置"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -131,6 +138,7 @@
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="用户补卡"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
@@ -140,6 +148,7 @@
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="密码设置"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
            <TextView
@@ -148,6 +157,7 @@
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:text="未连接数据中心"
                android:textColor="@color/text_selecter"
                android:textSize="@dimen/text_size" />
        </LinearLayout>
app/src/main/res/layout/activity_parameter.xml
@@ -21,6 +21,7 @@
        android:layout_marginTop="20dp"
        android:padding="5dp"
        android:text="域名卡设置"
        android:textColor="@color/text_selecter"
        android:textSize="@dimen/text_size" />
    <TextView
@@ -31,6 +32,7 @@
        android:layout_marginTop="20dp"
        android:padding="5dp"
        android:text="水泵功率卡设置"
        android:textColor="@color/text_selecter"
        android:textSize="@dimen/text_size" />
@@ -42,6 +44,7 @@
        android:layout_marginTop="20dp"
        android:padding="5dp"
        android:text="电量单价设置"
        android:textColor="@color/text_selecter"
        android:textSize="@dimen/text_size" />
    <TextView
@@ -52,6 +55,7 @@
        android:layout_marginTop="20dp"
        android:padding="5dp"
        android:text="卡标识码设置"
        android:textColor="@color/text_selecter"
        android:textSize="@dimen/text_size" />
</LinearLayout>
app/src/main/res/layout/activity_recharge.xml
@@ -160,6 +160,7 @@
        android:id="@+id/recharge_registBtn"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:visibility="gone"
        android:layout_alignParentBottom="true"
        android:background="@color/title_bg"
        android:gravity="center"
app/src/main/res/layout/activity_recharge_detail.xml
@@ -43,6 +43,7 @@
            android:layout_marginTop="15dp"
            android:text="充值金额:"
            android:textSize="@dimen/text_size" />
        <TextView
            android:id="@+id/red_remainder_blance"
            android:layout_width="match_parent"
@@ -76,5 +77,16 @@
            android:layout_marginTop="15dp"
            android:text="卡状态:"
            android:textSize="@dimen/text_size" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:gravity="center"
            android:text="充值成功!"
            android:textColor="@color/red"
            android:textSize="@dimen/text_size" />
    </LinearLayout>
</LinearLayout>