交通银行信用卡账单读取

原创
2016/06/04 16:35
阅读数 264
public class JiaotongBankBill {

    public static List<TempBillModal> readBill(String mailContent) {
        List<TempBillModal> billList = new ArrayList<TempBillModal>();
        TempBillModal billModal = new TempBillModal();
        billModal.setBankname("交通银行");
        Document document = Jsoup.parse(mailContent);
        String cardUserString = document.select("p:containsOwn(尊敬的 )").toString();
        int zjd = cardUserString.indexOf("尊敬的 ") + "尊敬的 ".length();
        int nh = cardUserString.indexOf("您好!");
        cardUserString = cardUserString.substring(zjd, nh);
        System.out.println(cardUserString);
        // 持卡人
        billModal.setCarduser(cardUserString);
        //账单月份
        String monthString = document.select("p:containsOwn(感谢您使用交通银行信用卡,以下是您)").toString();
        int yearIndex = monthString.indexOf("年");
        int monthIndex = monthString.indexOf("月");
        monthString = monthString.substring(yearIndex + 1, monthIndex);
        int statementMonth = Integer.parseInt(monthString);
        System.out.println("账单月份:"+statementMonth);
        billModal.setBillmonth(statementMonth);
       
        //信用卡号
        Element cardIDElement = document.select("p:containsOwn(卡号:)").first();
        String cardIDString = document.select("p:containsOwn(卡号:)").toString();
        cardIDString = cardIDString.substring(cardIDString.indexOf("卡号:") + 3, 
                cardIDString.length() - 4);
        cardIDString = cardIDString.substring(cardIDString.length() - 4);
        System.out.println("信用卡号:"+cardIDString);
        billModal.setCardlastnum(cardIDString);
        //账单日期
        String statementDate = cardIDElement.nextElementSibling().text();
        statementDate = statementDate.substring(statementDate.indexOf("-") + 1).replaceAll("/", "-");
        System.out.println("账单日期:" + statementDate.toString());
        billModal.setBilldate(statementDate);
        
        Element cnttitle = document.select("th:containsOwn(到期还款日)").first().parent().parent();
        //还款日
        String paymentDueDate = cnttitle.child(0).child(1).text().replaceAll("/", "-");
        System.out.println("还款日:" + paymentDueDate);
        billModal.setRepaydate(paymentDueDate);
        //应还款额
        String currentAmountDue = cnttitle.child(1).child(1).text()
                .replace("¥", "").replaceAll(",", "").replace(" ", "");
        System.out.println("应还款额:" + currentAmountDue);
        billModal.setNeddrepay(new BigDecimal(currentAmountDue));
        //最低还款额 
        String minAmountDue  = cnttitle.child(2).child(1).text()
                .replace("¥", "").replaceAll(",", "").replace(" ", "");
        System.out.println("最低还款额:" + minAmountDue);
        billModal.setLowrepay(new BigDecimal(minAmountDue));
        //信用额度
        String creditlimit = cnttitle.child(3).child(1).text()
                .replace("¥", "").replaceAll(",", "").replace(" ", "");
        System.out.println("信用额度:" + creditlimit);
        BigDecimal creditLimitMoney = new BigDecimal(creditlimit);
        billModal.setCreditlimit(creditLimitMoney);
        //取现额度
        String crashlimit = cnttitle.child(4).child(1).text()
                .replace("¥", "").replaceAll(",", "").replace(" ", "");
        System.out.println("取现额度:" + crashlimit);
        BigDecimal crashlimitMoney = new BigDecimal(crashlimit);
        billModal.setCrashlimit(crashlimitMoney);
        
        //交易明细
        List<BillDetail> billDetailList = new ArrayList<BillDetail>();
        
        //以下是您的还款、退货及费用返还明细
        Element hhDetailsElement = document.select("div:containsOwn(以下是您的还款、退货及费用返还明细)").first();
        if(hhDetailsElement != null) {
            hhDetailsElement = hhDetailsElement.nextElementSibling().child(0);
            hhDetailsElement.child(0).remove();
            hhDetailsElement.child(0).child(0).remove();
            String lastCardNum = hhDetailsElement.child(0).child(0).text();
            lastCardNum = lastCardNum.substring(lastCardNum.length() - 4);
            
            if(lastCardNum.equals(billModal.getCardlastnum())) {//对应卡号
                hhDetailsElement.child(0).child(0).remove();
                for (Element ele : hhDetailsElement.children()) {
                    BillDetail billDetail = new BillDetail();
                    //交易日期
                    String transDate = ele.child(0).child(0).text();
                    transDate = transDate.replaceAll("/","-");
                    billDetail.setTradedate(transDate);
                    System.out.println("交易日期:" + transDate);
                    //交易说明
                    String detail = ele.child(0).child(2).text();
                    billDetail.setDetail(detail);
                    System.out.println("交易说明:" + detail);
                    //交易金额
                    String amountStr = ele.child(0).child(3).text()
                            .replace("RMB ", "")
                            .replaceAll(" ", "")
                            .replaceAll(",", "");
                    System.out.println("交易金额:" + amountStr);
                    billDetail.setMoney(new BigDecimal(amountStr));
                    
                    billDetailList.add(billDetail);
                }
            }
        }
        
        
        //以下是您的还款、退货及费用返还明细
        Element xfDetailsElement = document.select("div:containsOwn(以下是您的消费、取现及其他费用明细)").first();
        if(xfDetailsElement != null) {
            xfDetailsElement = xfDetailsElement.nextElementSibling().child(0);
            xfDetailsElement.child(0).remove();
            xfDetailsElement.child(0).child(0).remove();
            String lastCardNum = xfDetailsElement.child(0).child(0).text();
            lastCardNum = lastCardNum.substring(lastCardNum.length() - 4);
            
            if(lastCardNum.equals(billModal.getCardlastnum())) {//对应卡号
                xfDetailsElement.child(0).child(0).remove();
                for (Element ele : xfDetailsElement.children()) {
                    BillDetail billDetail = new BillDetail();
                    //交易日期
                    String transDate = ele.child(0).child(0).text();
                    transDate = transDate.replaceAll("/","-");
                    billDetail.setTradedate(transDate);
                    System.out.println("交易日期:" + transDate);
                    //交易说明
                    String detail = ele.child(0).child(2).text();
                    billDetail.setDetail(detail);
                    System.out.println("交易说明:" + detail);
                    //交易金额
                    String amountStr = ele.child(0).child(3).text()
                            .replace("RMB ", "")
                            .replaceAll(" ", "")
                            .replaceAll(",", "");
                    System.out.println("交易金额:" + amountStr);
                    billDetail.setMoney(new BigDecimal(amountStr));
                    
                    billDetailList.add(billDetail);
                }
            }
        }
        billModal.setBillDetailList(billDetailList);
        billList.add(billModal);
        
        return billList;
    }

  
}

 

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