Authored by zhengwen.ge

update

1 -package com.yoho.unions.server.service.impl;  
2 -  
3 -import com.alibaba.fastjson.JSONObject;  
4 -import com.yoho.unions.common.utils.HttpUtils;  
5 -import com.yoho.unions.common.utils.MathUtils;  
6 -import com.yoho.unions.dal.IUserOrdersDAO;  
7 -import com.yoho.unions.server.service.IOrderPushService;  
8 -import com.yoho.unions.vo.OrderInfo;  
9 -import com.yoho.unions.vo.OrdersGood;  
10 -import net.spy.memcached.compat.log.Logger;  
11 -import net.spy.memcached.compat.log.LoggerFactory;  
12 -import org.apache.commons.collections.CollectionUtils;  
13 -import org.apache.commons.lang3.tuple.Pair;  
14 -import org.springframework.beans.factory.annotation.Autowired;  
15 -  
16 -import java.math.BigDecimal;  
17 -import java.net.URLEncoder;  
18 -import java.util.*;  
19 -  
20 -/**  
21 - * 多麦推送订单数据  
22 - * Created by yoho on 2016/12/15.  
23 - */  
24 -public class DuomaiServiceImpl implements IOrderPushService {  
25 -  
26 - @Autowired  
27 - private IUserOrdersDAO userOrdersDAO;  
28 -  
29 - static Logger logger = LoggerFactory.getLogger(DuomaiServiceImpl.class);  
30 -  
31 - @Override  
32 - public void pushOrder(List<OrderInfo> orderInfoList) {  
33 - List<String> successCodes = new ArrayList<>();  
34 - String duomaiContext = getDuomaiContext(orderInfoList);  
35 - OrderInfo orderInfo = orderInfoList.get(0);  
36 - int clientId = orderInfo.getClientId();  
37 - String duomaiPushUrl = null;  
38 - if (clientId == 3017) {  
39 - duomaiPushUrl = "http://www.duomai.com/api/push/yohobuy.php1";  
40 - } else if (clientId == 3019) {  
41 - duomaiPushUrl = "http://www.duomai.com/api/push/myohobuy.php1";  
42 - } else {  
43 - duomaiPushUrl = "http://www.duomai.com/api/push/yohobuyroi.php1";  
44 - }  
45 - Pair<Integer, String> pair = null;  
46 - Map param = new HashMap<>();  
47 - param.put("content", duomaiContext);  
48 - try {  
49 - logger.info("pushOrder: url is {}, param is {}", duomaiPushUrl, param);  
50 - pair = HttpUtils.httpPost(duomaiPushUrl, param);  
51 - } catch (Exception e) {  
52 - logger.error("duomai order post fail,orderCode is {}", orderInfo.getParentOrderCode());  
53 - }  
54 - JSONObject json = JSONObject.parseObject(pair.getRight());  
55 - if (((String) json.get("code")).equals("200")) {  
56 - logger.info("duomai pushOrder success,orderCode is {}", orderInfo.getParentOrderCode());  
57 - successCodes.add(orderInfo.getParentOrderCode());  
58 - } else {  
59 - logger.warn("duomai pushOrder fail,orderCode is {},message is {}", orderInfo.getParentOrderCode(), (String) json.get("msg"));  
60 - }  
61 - //批量更新推送成功的订单状态为1  
62 - userOrdersDAO.batchUpdatePush(successCodes);  
63 - }  
64 -  
65 - private String getDuomaiContext(List<OrderInfo> orderInfoList) {  
66 - String urlContext = null;  
67 - for (OrderInfo orderInfo : orderInfoList) {  
68 - //联盟id  
69 - int client_id = orderInfo.getClientId();  
70 - String hash = "";  
71 - int channel = 0;  
72 - if (client_id == 3017) {  
73 - hash = "96613bf38393aa3d16451218f22344a8";  
74 - channel = 0;  
75 - } else if (client_id == 3019) {  
76 - hash = "d54be2dbc75753eb863ba6139950656b";  
77 - channel = 1;  
78 - } else if (client_id == 3057) {  
79 - hash = "bbf70bcaf5c52947ad26853f7cc1176d";  
80 - channel = 0;  
81 - }  
82 - //多麦在YOHO上的网站主标识  
83 - String euid = orderInfo.getMbrName();  
84 - String orderCode = orderInfo.getOrderCode();  
85 - int orderTime = orderInfo.getOrderTime();  
86 - BigDecimal orderAmount = orderInfo.getOrderAmount();  
87 - String orderStatus = orderInfo.getOrderStatus();  
88 - List<OrdersGood> goods = orderInfo.getOrdersGoods();  
89 - List<String> goodsIdList = new ArrayList<>();  
90 - List<String> goodsNameList = new ArrayList<>();  
91 - List<BigDecimal> goodsPriceList = new ArrayList<>();  
92 - //商品结算金额 price*num-优惠&折扣  
93 - List<BigDecimal> goodsTotalPriceList = new ArrayList<>();  
94 - // 商品分类编号  
95 - List<Integer> small_sort_idList = new ArrayList<>();  
96 - List<Integer> goodsNumList = new ArrayList<>();  
97 -  
98 - for(OrdersGood ordersGood:goods){  
99 - goodsIdList.add(ordersGood.getProductSkn());  
100 - goodsNameList.add(ordersGood.getProductName());  
101 - goodsPriceList.add(ordersGood.getLastPrice());  
102 - goodsNumList.add(ordersGood.getBuyNumber());  
103 - small_sort_idList.add(ordersGood.getSortId());  
104 - goodsTotalPriceList.add(ordersGood.getLastPrice());  
105 - }  
106 -  
107 - LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();  
108 - linkedHashMap.put("hash", hash);  
109 - linkedHashMap.put("euid", euid);  
110 - linkedHashMap.put("order_sn", orderCode);  
111 - linkedHashMap.put("order_time", orderTime);  
112 - linkedHashMap.put("orders_price", orderAmount);  
113 - linkedHashMap.put("promotion_code", 0);  
114 - //@TODO需要订单传过来,是否新用户  
115 - linkedHashMap.put("is_new_custom", 0);  
116 - linkedHashMap.put("channel", channel);  
117 - linkedHashMap.put("status", orderStatus);  
118 - linkedHashMap.put("goods_id", CollectionUtils.isEmpty(goodsIdList) ? "" : org.apache.commons.lang.StringUtils.join(goodsIdList, "|"));  
119 - linkedHashMap.put("goods_name", CollectionUtils.isEmpty(goodsNameList) ? "" : org.apache.commons.lang.StringUtils.join(goodsNameList, "|"));  
120 - linkedHashMap.put("goods_price", CollectionUtils.isEmpty(goodsPriceList) ? "" : org.apache.commons.lang.StringUtils.join(goodsPriceList, "|"));  
121 - linkedHashMap.put("goods_ta", CollectionUtils.isEmpty(goodsNumList) ? "" : org.apache.commons.lang.StringUtils.join(goodsNumList, "|"));  
122 - linkedHashMap.put("goods_cate", CollectionUtils.isEmpty(small_sort_idList) ? "" : org.apache.commons.lang.StringUtils.join(small_sort_idList, "|"));  
123 - linkedHashMap.put("goods_cate_name", 0);  
124 - linkedHashMap.put("totalPrice", CollectionUtils.isEmpty(goodsTotalPriceList) ? "" : org.apache.commons.lang.StringUtils.join(goodsTotalPriceList, "|"));  
125 - //佣金计算,月底计算一次,7%计算,数据库比例已经老的  
126 - linkedHashMap.put("rate", 0);  
127 - linkedHashMap.put("commission", "");  
128 - linkedHashMap.put("commission_type", 0);  
129 - double coupon = 12d;  
130 - linkedHashMap.put("coupon", MathUtils.roundPrice(coupon));  
131 - Set<String> keys = linkedHashMap.keySet();  
132 - StringBuilder builder = new StringBuilder();  
133 - for (String key : keys) {  
134 - builder.append(key).append("=").append(linkedHashMap.get(key)).append("&");  
135 - }  
136 - try {  
137 - urlContext = URLEncoder.encode(builder.substring(0, builder.length() - 1), "UTF-8");  
138 - } catch (Exception e) {  
139 - logger.warn("send duomai error", e.getMessage());  
140 - }  
141 - }  
142 - return urlContext;  
143 - }  
144 -  
145 -} 1 +//package com.yoho.unions.server.service.impl;
  2 +//
  3 +//import com.alibaba.fastjson.JSONObject;
  4 +//import com.yoho.unions.common.utils.HttpUtils;
  5 +//import com.yoho.unions.common.utils.MathUtils;
  6 +//import com.yoho.unions.dal.IUserOrdersDAO;
  7 +//import com.yoho.unions.server.service.IOrderPushService;
  8 +//import com.yoho.unions.vo.OrderInfo;
  9 +//import com.yoho.unions.vo.OrdersGood;
  10 +//import net.spy.memcached.compat.log.Logger;
  11 +//import net.spy.memcached.compat.log.LoggerFactory;
  12 +//import org.apache.commons.collections.CollectionUtils;
  13 +//import org.apache.commons.lang3.tuple.Pair;
  14 +//import org.springframework.beans.factory.annotation.Autowired;
  15 +//
  16 +//import java.math.BigDecimal;
  17 +//import java.net.URLEncoder;
  18 +//import java.util.*;
  19 +//
  20 +///**
  21 +// * 多麦走通用的,不单独走定制的
  22 +// * 多麦推送订单数据
  23 +// * Created by yoho on 2016/12/15.
  24 +// */
  25 +//public class DuomaiServiceImpl implements IOrderPushService {
  26 +//
  27 +// @Autowired
  28 +// private IUserOrdersDAO userOrdersDAO;
  29 +//
  30 +// static Logger logger = LoggerFactory.getLogger(DuomaiServiceImpl.class);
  31 +//
  32 +// @Override
  33 +// public void pushOrder(List<OrderInfo> orderInfoList) {
  34 +// List<String> successCodes = new ArrayList<>();
  35 +// String duomaiContext = getDuomaiContext(orderInfoList);
  36 +// OrderInfo orderInfo = orderInfoList.get(0);
  37 +// int clientId = orderInfo.getClientId();
  38 +// String duomaiPushUrl = null;
  39 +// if (clientId == 3017) {
  40 +// duomaiPushUrl = "http://www.duomai.com/api/push/yohobuy.php";
  41 +// } else if (clientId == 3019) {
  42 +// duomaiPushUrl = "http://www.duomai.com/api/push/myohobuy.php";
  43 +// } else {
  44 +// duomaiPushUrl = "http://www.duomai.com/api/push/yohobuyroi.php";
  45 +// }
  46 +// Pair<Integer, String> pair = null;
  47 +// Map param = new HashMap<>();
  48 +// param.put("content", duomaiContext);
  49 +// try {
  50 +// logger.info("pushOrder: url is {}, param is {}", duomaiPushUrl, param);
  51 +// pair = HttpUtils.httpPost(duomaiPushUrl, param);
  52 +// } catch (Exception e) {
  53 +// logger.error("duomai order post fail,orderCode is {}", orderInfo.getParentOrderCode());
  54 +// }
  55 +// JSONObject json = JSONObject.parseObject(pair.getRight());
  56 +// if (((String) json.get("code")).equals("200")) {
  57 +// logger.info("duomai pushOrder success,orderCode is {}", orderInfo.getParentOrderCode());
  58 +// successCodes.add(orderInfo.getParentOrderCode());
  59 +// } else {
  60 +// logger.warn("duomai pushOrder fail,orderCode is {},message is {}", orderInfo.getParentOrderCode(), (String) json.get("msg"));
  61 +// }
  62 +// //批量更新推送成功的订单状态为1
  63 +// userOrdersDAO.batchUpdatePush(successCodes);
  64 +// }
  65 +//
  66 +// private String getDuomaiContext(List<OrderInfo> orderInfoList) {
  67 +// String urlContext = null;
  68 +// for (OrderInfo orderInfo : orderInfoList) {
  69 +// //联盟id
  70 +// int client_id = orderInfo.getClientId();
  71 +// String hash = "";
  72 +// int channel = 0;
  73 +// if (client_id == 3017) {
  74 +// hash = "96613bf38393aa3d16451218f22344a8";
  75 +// channel = 0;
  76 +// } else if (client_id == 3019) {
  77 +// hash = "d54be2dbc75753eb863ba6139950656b";
  78 +// channel = 1;
  79 +// } else if (client_id == 3057) {
  80 +// hash = "bbf70bcaf5c52947ad26853f7cc1176d";
  81 +// channel = 0;
  82 +// }
  83 +// //多麦在YOHO上的网站主标识
  84 +// String euid = orderInfo.getMbrName();
  85 +// String orderCode = orderInfo.getOrderCode();
  86 +// int orderTime = orderInfo.getOrderTime();
  87 +// BigDecimal orderAmount = orderInfo.getOrderAmount();
  88 +// String orderStatus = orderInfo.getOrderStatus();
  89 +// List<OrdersGood> goods = orderInfo.getOrdersGoods();
  90 +// List<String> goodsIdList = new ArrayList<>();
  91 +// List<String> goodsNameList = new ArrayList<>();
  92 +// List<BigDecimal> goodsPriceList = new ArrayList<>();
  93 +// //商品结算金额 price*num-优惠&折扣
  94 +// List<BigDecimal> goodsTotalPriceList = new ArrayList<>();
  95 +// // 商品分类编号
  96 +// List<Integer> small_sort_idList = new ArrayList<>();
  97 +// List<Integer> goodsNumList = new ArrayList<>();
  98 +//
  99 +// for(OrdersGood ordersGood:goods){
  100 +// goodsIdList.add(ordersGood.getProductSkn());
  101 +// goodsNameList.add(ordersGood.getProductName());
  102 +// goodsPriceList.add(ordersGood.getLastPrice());
  103 +// goodsNumList.add(ordersGood.getBuyNumber());
  104 +// small_sort_idList.add(ordersGood.getSortId());
  105 +// goodsTotalPriceList.add(ordersGood.getLastPrice());
  106 +// }
  107 +//
  108 +// LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
  109 +// linkedHashMap.put("hash", hash);
  110 +// linkedHashMap.put("euid", euid);
  111 +// linkedHashMap.put("order_sn", orderCode);
  112 +// linkedHashMap.put("order_time", orderTime);
  113 +// linkedHashMap.put("orders_price", orderAmount);
  114 +// linkedHashMap.put("promotion_code", 0);
  115 +// //@TODO需要订单传过来,是否新用户
  116 +// linkedHashMap.put("is_new_custom", 0);
  117 +// linkedHashMap.put("channel", channel);
  118 +// linkedHashMap.put("status", orderStatus);
  119 +// linkedHashMap.put("goods_id", CollectionUtils.isEmpty(goodsIdList) ? "" : org.apache.commons.lang.StringUtils.join(goodsIdList, "|"));
  120 +// linkedHashMap.put("goods_name", CollectionUtils.isEmpty(goodsNameList) ? "" : org.apache.commons.lang.StringUtils.join(goodsNameList, "|"));
  121 +// linkedHashMap.put("goods_price", CollectionUtils.isEmpty(goodsPriceList) ? "" : org.apache.commons.lang.StringUtils.join(goodsPriceList, "|"));
  122 +// linkedHashMap.put("goods_ta", CollectionUtils.isEmpty(goodsNumList) ? "" : org.apache.commons.lang.StringUtils.join(goodsNumList, "|"));
  123 +// linkedHashMap.put("goods_cate", CollectionUtils.isEmpty(small_sort_idList) ? "" : org.apache.commons.lang.StringUtils.join(small_sort_idList, "|"));
  124 +// linkedHashMap.put("goods_cate_name", 0);
  125 +// linkedHashMap.put("totalPrice", CollectionUtils.isEmpty(goodsTotalPriceList) ? "" : org.apache.commons.lang.StringUtils.join(goodsTotalPriceList, "|"));
  126 +// //佣金计算,月底计算一次,7%计算,数据库比例已经老的
  127 +// linkedHashMap.put("rate", 0);
  128 +// linkedHashMap.put("commission", "");
  129 +// linkedHashMap.put("commission_type", 0);
  130 +// double coupon = 12d;
  131 +// linkedHashMap.put("coupon", MathUtils.roundPrice(coupon));
  132 +// Set<String> keys = linkedHashMap.keySet();
  133 +// StringBuilder builder = new StringBuilder();
  134 +// for (String key : keys) {
  135 +// builder.append(key).append("=").append(linkedHashMap.get(key)).append("&");
  136 +// }
  137 +// try {
  138 +// urlContext = URLEncoder.encode(builder.substring(0, builder.length() - 1), "UTF-8");
  139 +// } catch (Exception e) {
  140 +// logger.warn("send duomai error", e.getMessage());
  141 +// }
  142 +// }
  143 +// return urlContext;
  144 +// }
  145 +//
  146 +//}
@@ -9,6 +9,7 @@ import com.yoho.unions.vo.OrderInfo; @@ -9,6 +9,7 @@ import com.yoho.unions.vo.OrderInfo;
9 import com.yoho.unions.vo.OrdersGood; 9 import com.yoho.unions.vo.OrdersGood;
10 import net.spy.memcached.compat.log.Logger; 10 import net.spy.memcached.compat.log.Logger;
11 import net.spy.memcached.compat.log.LoggerFactory; 11 import net.spy.memcached.compat.log.LoggerFactory;
  12 +import org.apache.commons.lang.StringUtils;
12 import org.apache.commons.lang3.tuple.Pair; 13 import org.apache.commons.lang3.tuple.Pair;
13 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
@@ -100,7 +101,11 @@ public class OrderPushServiceImpl implements IOrderPushService{ @@ -100,7 +101,11 @@ public class OrderPushServiceImpl implements IOrderPushService{
100 //根据不同的厂商,发送不同的URL 101 //根据不同的厂商,发送不同的URL
101 int clientId = orderInfo.getClientId(); 102 int clientId = orderInfo.getClientId();
102 UnionOrderPush unionOrderPush = unionOrderPushDAO.selectByChannelId(clientId); 103 UnionOrderPush unionOrderPush = unionOrderPushDAO.selectByChannelId(clientId);
103 - String commRate = unionOrderPush.getCommRate(); 104 + String commRate = null;
  105 + if(null!=unionOrderPush&& StringUtils.isNotEmpty(unionOrderPush.getCommRate())){
  106 + commRate = unionOrderPush.getCommRate();
  107 + }
  108 +
104 param.put("commRate", commRate == null?0:commRate); 109 param.put("commRate", commRate == null?0:commRate);
105 Pair<Integer, String> pair = null; 110 Pair<Integer, String> pair = null;
106 try { 111 try {