建设银行信用卡电子账单读取

原创
2016/06/04 16:33
阅读数 255

上马

public class JianSheBankBill {
    public static String temp_nick="尊敬的";
    public static String temp_hello = ",您好!";
    public static List<TempBillModal> readBillModal(String mailContent){
        //public static TempBillModal readBill(Document document) {
        List<TempBillModal> tempBillModalList = new ArrayList<TempBillModal>();
        TempBillModal billModal = new TempBillModal();
        Document document = Jsoup.parse(mailContent);

        //持卡人
        String cardUserStr = document.select("font:containsOwn(尊敬的)").first().text();
        cardUserStr = cardUserStr.substring(cardUserStr.indexOf(temp_nick)+temp_nick.length(),
                cardUserStr.indexOf(temp_hello));
        System.out.println(cardUserStr);

        //账单日期

        Element billDateElement = document.select("tr:contains(Statement Date)").last();
        String billDateStr = billDateElement.child(1).text();
        System.out.println("账单日期:"+billDateStr);
        //账单月份
        String billMonthStr = billDateStr.substring(billDateStr.indexOf("-") + 1, billDateStr.lastIndexOf("-"));
        if(billMonthStr.trim().indexOf("0")==0){
            billMonthStr = billMonthStr.substring(1,billMonthStr.length());
        }
        int month = Integer.parseInt(billMonthStr);
        System.out.println("账单月份"+billMonthStr);
        //还款日
        Element repayElement = document.select("tr:contains(Payment Due Date)").last();
        String repayDateStr = repayElement.child(1).text();
        System.out.println("还款日"+repayDateStr);
        //信用额度
        Element creditElement = document.select("tr:contains(Credit Limit)").last();
        String creditDateStr = creditElement.child(1).text().replace("CNY ","").replaceAll(",","");
        System.out.println("信用额度:"+creditDateStr);
        BigDecimal creditLimit = new BigDecimal(creditDateStr);
        //取现额度
        Element crashElement = document.select("tr:contains(Cash Advance Limit)").last();
        String crashDateStr = crashElement.child(1).text().replace("CNY ","").replaceAll(",","");
        System.out.println("取现额度:"+crashDateStr);
        BigDecimal crashLimit = new BigDecimal(crashDateStr);

        //不同银行的还款信息

        Element element = document.select("b:containsOwn(【应还款明细】)").first()
                .parent()//font
                .parent()//td
                .parent()//tr
                .nextElementSibling()//tr
                .child(0)//td
                .child(0)//table
                .child(0);//tobdy
        Elements bankElements = element.children();
        System.out.println("-------所有信用卡---------");
        Map<String,TempBillModal> temMap = new HashMap<String,TempBillModal>();
        for(int i=1; i<bankElements.size();i++){
            TempBillModal tempBillModal = new TempBillModal();
            tempBillModal.setBankname("建设银行");
            tempBillModalList.add(tempBillModal);
            tempBillModal.setCarduser(cardUserStr);
            tempBillModal.setBillmonth(month);
            tempBillModal.setBilldate(billDateStr);
            tempBillModal.setRepaydate(repayDateStr);
            tempBillModal.setCreditlimit(creditLimit);
            tempBillModal.setCrashlimit(crashLimit);
            //第一行忽略表头
            Element bank = bankElements.get(i);
            String cardNum = bank.child(0).text();
            cardNum = cardNum.substring(cardNum.length()-4,cardNum.length());
            System.out.println("信用卡卡号:" + cardNum);
            tempBillModal.setCardlastnum(cardNum);
            temMap.put(cardNum, tempBillModal);
            String needpay = bank.child(2).text().replaceAll(",","").replaceAll(" ","");
            tempBillModal.setNeddrepay(new BigDecimal(needpay));
            System.out.println("应还金额:"+needpay);
            String lowPay = bank.child(3).text().replaceAll(",","").replaceAll(" ","");
            tempBillModal.setLowrepay(new BigDecimal(lowPay));
            System.out.println("最低还款:" + lowPay);
            tempBillModal.setBillDetailList(new ArrayList<BillDetail>());
        }
        System.out.println("------交易明细--------");
        Elements  tradeElements = document.select("b:containsOwn(【交易明细】)")
                .first()//b
                .parent()//font
                .parent()//td
                .parent()//tr
                .parent()//tbody
                .children();//tr
        for(int j=3;j<tradeElements.size();j++){
            //0去除标题交易明细
            //1去除表格标题头
            //2去除英文
            Element trade = tradeElements.get(j);
            if(trade.children().size()>4){
                BillDetail billDetail = new BillDetail();
                String tradeBankStr = trade.child(2).text().replace(" ", "");
                System.out.println("交易银行卡号:"+tradeBankStr);
                if(temMap.get(tradeBankStr)==null){//不存在下一个循环
                    continue;
                }else{
                    temMap.get(tradeBankStr).getBillDetailList().add(billDetail);
                }
                String tradeDateStr = trade.child(0).text().replaceAll(" ", "");
                billDetail.setTradedate(tradeDateStr);
                System.out.println("交易日期:" + tradeDateStr);
                String tradeDetailStr = trade.child(3).text();
                System.out.println("交易详情:"+tradeDetailStr);
                billDetail.setDetail(tradeDetailStr);
                String tradeMoneyStr = trade.child(7).text().replaceAll(" ","").replaceAll(",","");
                if(StringUtils.isEmpty(tradeMoneyStr)){
                    tradeMoneyStr = "0";
                }
                billDetail.setMoney(new BigDecimal(tradeMoneyStr));
                System.out.println("交易金额"+tradeMoneyStr);
            }else{
                continue;//去除单独行信息只过滤有用的记录数
            }
        }
        return tempBillModalList;
    }

    /*public static void main(String[] args) {
        try {
            Document document = Jsoup.connect("http://127.0.0.1/card/jianshe.html").get();
            JianSheBankBill.readBill(document);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }*/

 

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