华夏信用卡电子账单读取

原创
2016/06/04 16:32
阅读数 300

上码

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("span:containsOwn(尊敬的)").text();
        int zjd = cardUserString.indexOf("尊敬的") + "尊敬的".length();
        cardUserString = cardUserString.substring(zjd, cardUserString.length() - 1);
        System.out.println(cardUserString);
        billModal.setCarduser(cardUserString);
        
        //华夏信用卡对账单(
        Element dzdElement = document.select("b:containsOwn(华夏信用卡对账单()").first();
        System.out.println(dzdElement);
        //账单月份
        String statementMonth = dzdElement.text();
        statementMonth = statementMonth.substring(statementMonth.indexOf("年") + 1, statementMonth.indexOf("年") + 3);
        System.out.println("账单月份:"+statementMonth);
        billModal.setBillmonth(Integer.valueOf(statementMonth));
        //年份
        String statementYear = dzdElement.text().substring(dzdElement.text().indexOf("年") - 4, dzdElement.text().indexOf("年"));
        System.out.println("账单年份:"+statementYear);
        //账单日期
        dzdElement = dzdElement.parent().nextElementSibling().child(0);
        String statementDate = dzdElement.child(0).child(1).text();
        statementDate = statementDate.substring(statementDate.length() - 3, statementDate.length() - 1);
        statementDate = statementYear + '-' + statementMonth + '-' + statementDate;
        System.out.println("账单日期:"+statementDate);
        billModal.setBilldate(statementDate);
        //还款日
        String paymentDueDate = dzdElement.child(1).child(1).text();
        paymentDueDate = paymentDueDate.replaceAll("/", "-");
        System.out.println("还款日:" + paymentDueDate);
        billModal.setRepaydate(paymentDueDate);
        //信用额度
        String creditlimit = dzdElement.child(2).child(1).text().replaceAll(",", "");
        System.out.println("信用额度:" + creditlimit);
        BigDecimal creditLimitMoney = new BigDecimal(creditlimit);
        billModal.setCreditlimit(creditLimitMoney);
        //应还款额
        String currentAmountDue = dzdElement.child(4).child(1).text().replace("RMB:", "").replaceAll(",", "");
        System.out.println("应还款额:" + currentAmountDue);
        billModal.setNeddrepay(new BigDecimal(currentAmountDue));
        //最低还款额 
        String minAmountDue  = dzdElement.child(6).child(1).text().replace("RMB:", "").replaceAll(",", "");
        System.out.println("最低还款额:" + minAmountDue);
        billModal.setLowrepay(new BigDecimal(minAmountDue));
        
        //交易明细
        List<BillDetail> billDetailList = new ArrayList<BillDetail>();
        Element detailElements = document.select("b:contains(人民币交易明细 RMB Trans. Details)").last()
                .parent()
                .parent()
                .parent();
        detailElements.child(0).remove();
        detailElements.child(0).remove();
        Elements eleValues = detailElements.children();
        
        //信用卡号
        String cardlastnum = eleValues.get(0).child(4).text();
        System.out.println("信用卡号:"+cardlastnum);
        billModal.setCardlastnum(cardlastnum);

        for (Element item : eleValues) {
            BillDetail billDetail = new BillDetail();
            //交易日期
            String transDate = item.child(0).text();
            transDate = transDate.replaceAll("/","-");
            System.out.println("交易日期:" + transDate);
            billDetail.setTradedate(transDate);
            
            //交易说明
            String detail = item.child(2).text();
            System.out.println("交易摘要:" + detail);
            billDetail.setDetail(detail);
            
            //交易金额
            String amountStr = item.child(3).text()
                    .replaceAll(",", "");
            System.out.println("交易金额:" + amountStr);
            if(StringUtils.isEmpty(amountStr)){
                amountStr = "0";
            }
            billDetail.setMoney(new BigDecimal(amountStr));
            billDetailList.add(billDetail); 
        }
           
        billModal.setBillDetailList(billDetailList);
        billList.add(billModal);
        return billList;
    }

 

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