广发信用卡电子账单读取

原创
2016/06/04 16:30
阅读数 309

直接上码

public static String temp_nick = "尊敬的";
    public static String temp_hello = "您好,您";
    public static String temp_bill = "的账单信息如下,请详阅:";
    public static List<TempBillModal> readBillModal(String mailContent){
        //public static List<TempBillModal> readBill(Document document) {
        Document document = Jsoup.parse(mailContent);
        List<TempBillModal> billList = new ArrayList<TempBillModal>();
        TempBillModal billModal = new TempBillModal();
        String cardUserStr = document.select("font:containsOwn(尊敬的)").first().text();
        cardUserStr = cardUserStr.substring(cardUserStr.indexOf(temp_nick)+temp_nick.length(),cardUserStr.indexOf(":"));
        billModal.setCarduser(cardUserStr);
        System.out.println("持卡人姓名:"+cardUserStr);
        //账单月份
        String billMonthDateStr = document.select("font:containsOwn("+temp_bill+")").first().text();

        billMonthDateStr = billMonthDateStr.substring(billMonthDateStr.indexOf(temp_hello)+temp_hello.length(),
                billMonthDateStr.indexOf(temp_bill));
        String billDateStr = billMonthDateStr.replaceAll("年","-").replaceAll("月","-")+"19";
        billModal.setBilldate(billDateStr);
        billMonthDateStr = billMonthDateStr.substring(billMonthDateStr.indexOf("年")+1,billMonthDateStr.indexOf("月"));
        if(billMonthDateStr.trim().indexOf("0")==0){
            billMonthDateStr = billMonthDateStr.substring(1,billMonthDateStr.length());
        }
        int month = Integer.parseInt(billMonthDateStr);
        billModal.setBankname("广发银行");
        billModal.setBillmonth(month);
        System.out.println("账单月份:"+billMonthDateStr);

        //银行卡信息
        Elements elements = document.select("table:contains(注:上期欠款+本期支出-还款)");
        Element element = elements.get(elements.size() - 4);
        Element bankElement = element.child(0).child(2);
        Elements bankDetailElements = bankElement.select("font:containsOwn(人民币)");
        Map<String,TempBillModal> temMap = new HashMap<String,TempBillModal>();
        for(Element bankDetail:bankDetailElements){
            TempBillModal billModal1 = new TempBillModal();
            billModal1.setCarduser(billModal.getCarduser());
            billModal1.setBankname("广发银行");
            billModal1.setBillmonth(billModal.getBillmonth());
            billModal1.setBilldate(billModal.getBilldate());
            Element bank = bankDetail.parent().parent().parent();
            String cardNum = bank.child(0).text();
            cardNum = cardNum.substring(cardNum.length()-4,cardNum.length());
            System.out.println("卡号:"+cardNum);
            billModal1.setCardlastnum(cardNum);
            temMap.put(cardNum, billModal1);
            billList.add(billModal1);
            String needPayStr = bank.child(1).text().replace(",", "");
            BigDecimal  needPay = new BigDecimal(needPayStr);
            billModal1.setNeddrepay(needPay);
            System.out.println("需要还款"+needPayStr);
            String lowPayStr = bank.child(2).text().replaceAll(",","");
            BigDecimal lowpay = new BigDecimal(lowPayStr);
            billModal1.setLowrepay(lowpay);
            System.out.println("最低还款"+lowPayStr);
            String payDateStr = bank.child(3).text().replaceAll("/","-");
            billModal1.setRepaydate(payDateStr);
            System.out.println("还款日:"+payDateStr);
            String creditLimitStr = bank.child(5).text().replaceAll(",","");
            BigDecimal bigDecimal = new BigDecimal(creditLimitStr);
            billModal1.setCreditlimit(bigDecimal);
            System.out.println("信用额度:"+creditLimitStr);
        }
        Element detailElement = document.select("b:containsOwn(交易明细)").first()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .parent()
                .nextElementSibling();
        //tr元素
        Elements detailElements = detailElement.select("table").get(3).child(0).children();
        for(Element element1:detailElements){
            Elements table_trs = element1.select("table").get(3).child(0).children();//tbody
            String cardNum = table_trs.get(0).text();
            cardNum = cardNum.substring(cardNum.length()-4,cardNum.length());
            System.out.println("-----------------卡号"+cardNum);
            TempBillModal tempBillModal = temMap.get(cardNum);
            if(tempBillModal == null){
                continue;
            }
            Elements tr_tables_tr = table_trs.get(1)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .child(0)
                    .children();
            List<BillDetail> billDetails = new ArrayList<BillDetail>();
            tempBillModal.setBillDetailList(billDetails);
            for(Element element2:tr_tables_tr){
                BillDetail billDetail = new BillDetail();
                billDetails.add(billDetail);
                String tradeDateStr = element2.child(0).text();
                billDetail.setTradedate(tradeDateStr);
                System.out.println("交易时间:"+tradeDateStr);
                String detailStr = element2.child(2).text();
                billDetail.setDetail(detailStr);
                System.out.println("交易摘要:"+detailStr);
                String detailmoneyStr = element2.child(3).text().replace(",","");
                if(StringUtils.isEmpty(detailmoneyStr)){
                    detailmoneyStr="0";
                }
                System.out.println("交易金额:"+detailmoneyStr);
                BigDecimal trademoney = new BigDecimal(detailmoneyStr);
                billDetail.setMoney(trademoney);

            }

        }
        return billList;
    }

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部