package com.kmall.common.utils.wechat;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.Iterator;

/**
 * 获取请求微信订单查询接口返回xml中的state
 * @author huangyq
 * @version 1.0
 * 2018-05-24 15:53
 */
public class ReaderXmlForDOM4J {

    public static WechatRefundQueryResult parse(String protocolXML, int count) {
        WechatRefundQueryResult querySuccessResponseDto = new WechatRefundQueryResult();
        try {
            Document doc=(Document) DocumentHelper.parseText(protocolXML);
            Element books = doc.getRootElement();
            // Iterator users_subElements = books.elementIterator("UID");//指定获取那个元素
            Iterator Elements = books.elementIterator();
            while(Elements.hasNext()){
                Element element = (Element)Elements.next();
                String out_refund_no ="out_refund_no_"+(count);
                String refund_account ="refund_account_"+(count);
                String refund_channel ="refund_channel_"+(count);
                String refund_fee ="refund_fee_"+(count);
                String refund_id ="refund_id_"+(count);
                String refund_recv_accout ="refund_recv_accout_"+(count);
                String refund_status ="refund_status_"+(count);
                String refund_success_time ="refund_success_time_"+(count);
                if(out_refund_no.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setOut_refund_no(element.getText());
                }
                if(refund_account.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_account(element.getText());
                }
                if(refund_channel.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_channel(element.getText());
                }
                if(refund_fee.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_fee(element.getText());
                }
                if(refund_id.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_id(element.getText());
                }
                if(refund_recv_accout.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_recv_accout(element.getText());
                }
                if(refund_status.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_status(element.getText());
                }
                if(refund_success_time.equalsIgnoreCase(element.getName())){
                    querySuccessResponseDto.setRefund_success_time(element.getText());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return querySuccessResponseDto;
    }
}
