工商银行电子账单读取

直接上码吧

 public static List readBillModal(String mailContent){
        //public static List readBill(Document document){
        List billList = new ArrayList();
        TempBillModal billModal = new TempBillModal();
        Document document = Jsoup.parse(mailContent);
        //持卡人
        String cardUserStr = document.select("p[class=first]").text();
        cardUserStr = cardUserStr.replaceAll("尊敬的","").replaceAll(",您好!","");
        billModal.setCarduser(cardUserStr);
        System.out.println(cardUserStr);

        //账单日
        String billDateStr = document.select("td:containsOwn(对账单生成日)")
                .first()//td
                .child(0)//td span
                .text();
        billDateStr = billDateStr.replaceAll("年","-").replaceAll("月", "-").replaceAll("日","");
        billModal.setBilldate(billDateStr);
        System.out.println("账单日" + billDateStr);

        //还款日
        String repayDateStr = document.select("b:containsOwn(重要提示)").first().parents()
                .get(2)
                .nextElementSibling()
                .child(2)
                .child(0).text();
        billModal.setBankname("工商银行");


        //账单月份
        String billmonthStr = repayDateStr.substring(repayDateStr.indexOf("年") + 1, repayDateStr.indexOf("月"));
        System.out.println("账单月份" + billmonthStr);
        Integer month = Integer.parseInt(billmonthStr);
        billModal.setBillmonth(month);


        repayDateStr = repayDateStr.replaceAll("年","-").replaceAll("月","-").replaceAll("日","");
        System.out.println("还款日" + repayDateStr);
        billModal.setRepaydate(repayDateStr);
        //额度相关
        Element limitElement = document.select("td:containsOwn(需 还 款 明 细)").parents()
                .get(2)//table
                .nextElementSibling()//临节点table
                .child(0)//tbody
                .child(1);//tr
        //信用额度
        String creditLimitStr = limitElement.child(4).text();
        if(creditLimitStr!=null){
            creditLimitStr = creditLimitStr.replace("/RMB","").replace(",","");
            billModal.setCreditlimit(new BigDecimal(creditLimitStr));
        }
        System.out.println("信用额度"+creditLimitStr);
        //取现额度--暂无
        //需要还款
        String needpayStr = limitElement.child(2).text();
        if(needpayStr!=null){
            needpayStr = needpayStr.replace("/RMB","").replace(",","");
            billModal.setNeddrepay(new BigDecimal(needpayStr));
        }
        System.out.println("需要还款"+needpayStr);
        //最低还款
        String lowpayStr = limitElement.child(3).text();
        if(lowpayStr!=null){
            lowpayStr = needpayStr.replace("/RMB","").replace(",","");
            billModal.setLowrepay(new BigDecimal(lowpayStr));
        }
        System.out.println("最低还款"+lowpayStr);
        //卡号后四位
        String castLastNumStr = limitElement.child(0).text();
        if(cardUserStr!=null){
            castLastNumStr = castLastNumStr.substring(0,castLastNumStr.indexOf("("));
            billModal.setCardlastnum(castLastNumStr);
        }
        System.out.println("卡号后四位"+castLastNumStr);
        //交易详情
        List billDetailList = new ArrayList();
        billModal.setBillDetailList(billDetailList);
        Elements tradeElement = document.select("td:containsOwn(人 民 币 交 易 明 细)")
                .parents()
                .get(2)//table
                .nextElementSibling()//相邻详情table
                .child(0)//tbody
                .children();//所有tr
        if(tradeElement!=null){
            for(int i=1;i3){//排除合并的一行提示文本元素
                        BillDetail billDetail = new BillDetail();
                        String tradDateStr = element.child(1).text();
                        String tradeType = element.child(3).text();
                        String tradeDetail = element.child(4).text();
                        String tradeMoney = element.child(5).text();
                        tradeMoney = tradeMoney.replace("/RMB","").replaceAll(",","");
                        BigDecimal trademoney = new BigDecimal(tradeMoney);
                        billDetail.setCardnum("");
                        billDetail.setDetail(tradeDetail);
                        billDetail.setTradedate(tradDateStr);
                        billDetail.setMoney(trademoney);
                        billDetailList.add(billDetail);
                        System.out.println("交易日期:"+tradDateStr);
                        System.out.println("交易类型:"+tradeType+" "+tradeDetail);
                        System.out.println("交易金额:"+tradeMoney);
                }else{
                    continue;//直接排除继续走
                }
            }
        }
        billList.add(billModal);
        return billList;
    }

 

转载于:https://my.oschina.net/riaway/blog/687120

你可能感兴趣的:(工商银行电子账单读取)