package com.iotechn.unimall.data.dto.shop.XmlObject;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SendGood {

    public static String processTemplate(String template, Map<String, Object> params){
        StringBuffer sb = new StringBuffer();
        Matcher m = Pattern.compile("\\$\\{\\w+\\}").matcher(template);
        while (m.find()) {
            String param = m.group();
            Object value = params.get(param.substring(2, param.length() - 1));
            m.appendReplacement(sb, value==null ? "" : value.toString());
        }
        m.appendTail(sb);
        return sb.toString();
    }

    public static String TMPL = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n" +
            "<request>\n" +
            "    <functionID>dangdang.order.goods.send</functionID>\n" +
            "    <time>${SEND_TIME}</time>\n" +
            "    <OrdersList>\n" +
            "${ORDER_LIST}"+
            "    </OrdersList>\n" +
            "</request>";

    public static String ONE_ORDER="        <OrderInfo>\n" +
            "            <orderID>${DANG_DANG_ORDER}</orderID>\n" +
            "            <logisticsName>${KUAI_DI_GONG_SI}</logisticsName>\n" +
            "            <logisticsNameAb>${KUAI_DI_BIANMA}</logisticsNameAb>\n" +
            "            <logisticsTel>${KUAI_DI_GONG_SI_DIAN_HUA}</logisticsTel>\n" +
            "            <logisticsOrderID>${KUAI_DI_DAN_HAO}</logisticsOrderID>\n" +
            "            <SendGoodsList>\n" +

            "${SEND_ITEMS}"+

            "            </SendGoodsList>\n" +
            "        </OrderInfo>\n";

    public static String ONE_ITEM="                <ItemInfo>\n" +
            "                    <itemID>${DANG_DANG_ITEM_ID}</itemID>\n" +
            "                    <sendGoodsCount>${SHU_LIANG}</sendGoodsCount>\n" +
            "                    <belongProductsPromoID></belongProductsPromoID>\n" +
            "                    <productItemId>${PRODUCT_ID}</productItemId>\n" +
            "                </ItemInfo>\n";
}
