...
|
...
|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.core.common.utils.MD5;
|
|
|
import com.yoho.unions.common.utils.HttpUtils;
|
|
|
import com.yoho.unions.server.service.IFanliService;
|
|
|
import com.yoho.unions.server.service.IOrderPushService;
|
|
|
import com.yoho.unions.vo.OrderInfo;
|
...
|
...
|
@@ -25,6 +27,10 @@ import java.util.Map; |
|
|
@Service
|
|
|
public class FanliServiceImpl implements IFanliService, IOrderPushService {
|
|
|
|
|
|
private static final String SHOP_NO = "";
|
|
|
|
|
|
private static final String SHOP_KEY = "";
|
|
|
|
|
|
/**
|
|
|
* 推送订单
|
|
|
*
|
...
|
...
|
@@ -36,73 +42,106 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService { |
|
|
Element rootElement = document.addElement("orders");
|
|
|
document.setRootElement(rootElement);
|
|
|
for (OrderInfo orderInfo : orderInfos) {
|
|
|
JSONObject unionCookie = JSONObject.parseObject(orderInfo.getUnionCookie());
|
|
|
//订单信息
|
|
|
Element orderElement = rootElement.addElement("order");
|
|
|
orderElement.addElement("s_id").setText("");
|
|
|
orderElement.addElement("order_id_parent").setText(String.valueOf(orderInfo.getParentOrderCode()));
|
|
|
orderElement.addElement("order_id").setText(String.valueOf(orderInfo.getOrderCode()));
|
|
|
orderElement.addElement("order_time").setText(DateUtil.date2String(new Date(orderInfo.getOrderTime() * 1000), "yyyy-MM-dd HH:mm:ss"));
|
|
|
orderElement.addElement("uid").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("uname").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("tc").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("pay_time").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("status").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("locked").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("lastmod").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("is_newbuyer").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("platform").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("code").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("remark").setText(unionCookie.getString("uid"));
|
|
|
|
|
|
//商品信息
|
|
|
List<OrdersGood> ordersGoodList = orderInfo.getOrdersGoods();
|
|
|
//创建订单子节点
|
|
|
this.creatOrderLeaf(orderElement, orderInfo);
|
|
|
//商品节点
|
|
|
Element productsElement = orderElement.addElement("products");
|
|
|
//同个订单 skn相同的合并
|
|
|
Map<String, List<OrdersGood>> ordersGoodMap = Maps.newHashMap();
|
|
|
for (OrdersGood ordersGood : ordersGoodList) {
|
|
|
if (!ordersGoodMap.containsKey(ordersGood.getProductSkn())) {
|
|
|
ordersGoodMap.put(ordersGood.getProductSkn(), Lists.newArrayList());
|
|
|
}
|
|
|
ordersGoodMap.get(ordersGood.getProductSkn()).add(ordersGood);
|
|
|
//创建商品信息子节点
|
|
|
this.creatProductLeaf(productsElement, orderInfo);
|
|
|
}
|
|
|
String xmlData = document.asXML();
|
|
|
Map<String, Object> param = Maps.newHashMap();
|
|
|
param.put("content", xmlData);
|
|
|
int i = 0;
|
|
|
//发送推送请求
|
|
|
while (i < 3) {
|
|
|
try {
|
|
|
String resultXml = HttpUtils.httpPost("", param).getRight();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (String orderCode : ordersGoodMap.keySet()) {
|
|
|
Element productElement = productsElement.addElement("product");
|
|
|
OrdersGood ordersGood = null;
|
|
|
List<OrdersGood> ordersGoods = ordersGoodMap.get(orderCode);
|
|
|
for (OrdersGood good : ordersGoods) {
|
|
|
if (null == ordersGood) {
|
|
|
ordersGood = good;
|
|
|
continue;
|
|
|
}
|
|
|
//合并数量
|
|
|
ordersGood.setBuyNumber(ordersGood.getBuyNumber() + good.getBuyNumber());
|
|
|
//合并结算金额
|
|
|
ordersGood.setRealPayFee(ordersGood.getRealPayFee().add(good.getRealPayFee()));
|
|
|
//合并佣金
|
|
|
ordersGood.setCommission(ordersGood.getCommission().add(good.getCommission()));
|
|
|
}
|
|
|
/**
|
|
|
* 订单信息节点信息
|
|
|
*
|
|
|
* @param orderElement
|
|
|
* @param orderInfo
|
|
|
*/
|
|
|
private void creatOrderLeaf(Element orderElement, OrderInfo orderInfo) {
|
|
|
JSONObject unionCookie = JSONObject.parseObject(orderInfo.getUnionCookie());
|
|
|
orderElement.addElement("s_id").setText("");
|
|
|
orderElement.addElement("order_id_parent").setText(String.valueOf(orderInfo.getParentOrderCode()));
|
|
|
orderElement.addElement("order_id").setText(String.valueOf(orderInfo.getOrderCode()));
|
|
|
orderElement.addElement("order_time").setText(DateUtil.date2String(new Date(orderInfo.getOrderTime() * 1000), "yyyy-MM-dd HH:mm:ss"));
|
|
|
orderElement.addElement("uid").setText(unionCookie.getString("uid"));
|
|
|
orderElement.addElement("uname").setText("@51fanli");
|
|
|
orderElement.addElement("tc").setText(unionCookie.getString("tracking_code"));
|
|
|
orderElement.addElement("pay_time").setText("");
|
|
|
orderElement.addElement("status").setText(orderInfo.getOrderStatus());
|
|
|
orderElement.addElement("locked").setText("");
|
|
|
orderElement.addElement("lastmod").setText("");
|
|
|
orderElement.addElement("is_newbuyer").setText("");
|
|
|
orderElement.addElement("platform").setText(orderInfo.getOrderType());
|
|
|
orderElement.addElement("code").setText(getPassCode());
|
|
|
orderElement.addElement("remark").setText("");
|
|
|
}
|
|
|
|
|
|
productElement.addElement("pid").setText(ordersGood.getProductSkn());
|
|
|
productElement.addElement("title").setText(formatToCadata(ordersGood.getProductName()));
|
|
|
productElement.addElement("category").setText(String.valueOf(ordersGood.getSortId()));
|
|
|
productElement.addElement("category_title").setText(ordersGood.getSortName());
|
|
|
productElement.addElement("url").setText(formatToCadata(""));
|
|
|
productElement.addElement("num").setText(String.valueOf(ordersGood.getBuyNumber()));
|
|
|
productElement.addElement("price").setText(String.valueOf(ordersGood.getLastPrice()));
|
|
|
productElement.addElement("real_pay_fee").setText(String.valueOf(ordersGood.getRealPayFee()));
|
|
|
productElement.addElement("refund_num").setText("0");
|
|
|
productElement.addElement("commission").setText("");
|
|
|
productElement.addElement("comm_type").setText("");
|
|
|
/**
|
|
|
* 订单商品节点信息
|
|
|
*
|
|
|
* @param productsElement
|
|
|
* @param orderInfo
|
|
|
*/
|
|
|
private void creatProductLeaf(Element productsElement, OrderInfo orderInfo) {
|
|
|
//商品信息
|
|
|
List<OrdersGood> ordersGoodList = orderInfo.getOrdersGoods();
|
|
|
//同个订单 skn相同的合并
|
|
|
Map<String, List<OrdersGood>> ordersGoodMap = Maps.newHashMap();
|
|
|
for (OrdersGood ordersGood : ordersGoodList) {
|
|
|
if (!ordersGoodMap.containsKey(ordersGood.getProductSkn())) {
|
|
|
ordersGoodMap.put(ordersGood.getProductSkn(), Lists.newArrayList());
|
|
|
}
|
|
|
ordersGoodMap.get(ordersGood.getProductSkn()).add(ordersGood);
|
|
|
}
|
|
|
|
|
|
for (String orderCode : ordersGoodMap.keySet()) {
|
|
|
Element productElement = productsElement.addElement("product");
|
|
|
OrdersGood ordersGood = null;
|
|
|
List<OrdersGood> ordersGoods = ordersGoodMap.get(orderCode);
|
|
|
for (OrdersGood good : ordersGoods) {
|
|
|
if (null == ordersGood) {
|
|
|
ordersGood = good;
|
|
|
continue;
|
|
|
}
|
|
|
//合并数量
|
|
|
ordersGood.setBuyNumber(ordersGood.getBuyNumber() + good.getBuyNumber());
|
|
|
//合并结算金额
|
|
|
ordersGood.setRealPayFee(ordersGood.getRealPayFee().add(good.getRealPayFee()));
|
|
|
//合并佣金
|
|
|
ordersGood.setCommission(ordersGood.getCommission().add(good.getCommission()));
|
|
|
}
|
|
|
|
|
|
productElement.addElement("pid").setText(ordersGood.getProductSkn());
|
|
|
productElement.addElement("title").setText(formatToCadata(ordersGood.getProductName()));
|
|
|
productElement.addElement("category").setText(String.valueOf(ordersGood.getSortId()));
|
|
|
productElement.addElement("category_title").setText(ordersGood.getSortName());
|
|
|
productElement.addElement("url").setText(formatToCadata(""));
|
|
|
productElement.addElement("num").setText(String.valueOf(ordersGood.getBuyNumber()));
|
|
|
productElement.addElement("price").setText(String.valueOf(ordersGood.getLastPrice()));
|
|
|
productElement.addElement("real_pay_fee").setText(String.valueOf(ordersGood.getRealPayFee()));
|
|
|
productElement.addElement("refund_num").setText("0");
|
|
|
productElement.addElement("commission").setText("");
|
|
|
productElement.addElement("comm_type").setText("");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 格式化为cadata
|
|
|
*
|
|
|
* @param str
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -110,4 +149,14 @@ public class FanliServiceImpl implements IFanliService, IOrderPushService { |
|
|
return "<![CDATA[ " + str + "]]>";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取校验码
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getPassCode() {
|
|
|
String code = StringUtils.lowerCase(SHOP_NO + SHOP_KEY);
|
|
|
return MD5.md5(code);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|