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

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

public class SendGoodChai {

    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=\"utf-8\"?>\n" +
            "\n" +
            "<request> \n" +
            "  <functionID>dangdang.order.goods.send</functionID>  \n" +
            "  <time>${ORDER_TIME}</time>  \n" +
            "  <OrdersList> \n" +
            "    <OrderInfo> \n" +
            "      <orderID>${ORDER_ID}</orderID>  \n" +
            "      <shopId>${SHOP_ID}</shopId>  \n" +
            "      <donePackageSendList> \n" +
            "${PACKAGES}  \n" +
            "      </donePackageSendList> \n" +
            "    </OrderInfo>  \n" +
            "\n" +
            "  </OrdersList> \n" +
            "</request>";


    public static String ONE_ITEM="" +
            "        <donePackageSend> \n" +
            "          <expressCompany>${KUAI_DI_GONG_SI}</expressCompany>  \n" +
            "          <expressCompanyId>${KUAI_DI_GONG_SI_CODE}</expressCompanyId>  \n" +
            "          <expressCompanyTel>${KUAI_DI_GONG_SI_TEL}</expressCompanyTel>  \n" +
            "          <expressNo>${KUAI_DI_DAN_HAO}</expressNo>  \n" +
            "          <isSplite>1</isSplite>  \n" +
            "          <SendGoodsList> \n" +
            "            <ItemInfo> \n" +
            "              <itemID>${ITEM_ID}</itemID>  \n" +
            "              <sendGoodsCount>1</sendGoodsCount>  \n" +
            "              <productItemId>${PRODUCT_ITEM_ID}</productItemId> \n" +
            "            </ItemInfo>\n" +
            "          </SendGoodsList> \n" +
            "        </donePackageSend> ";
}
