Authored by zhengwen.ge

update

  1 +package com.yoho.unions.dal;
  2 +
  3 +
  4 +import com.yoho.unions.dal.model.UnionOrderPush;
  5 +
  6 +public interface IUnionOrderPushDAO {
  7 + int deleteByPrimaryKey(Integer id);
  8 +
  9 + int insert(UnionOrderPush record);
  10 +
  11 + int insertSelective(UnionOrderPush record);
  12 +
  13 + UnionOrderPush selectByPrimaryKey(Integer id);
  14 +
  15 + int updateByPrimaryKeySelective(UnionOrderPush record);
  16 +
  17 + int updateByPrimaryKey(UnionOrderPush record);
  18 +
  19 + UnionOrderPush selectByChannelId(int channelId);
  20 +}
  1 +package com.yoho.unions.dal.model;
  2 +
  3 +public class UnionOrderPush {
  4 + private Integer id;
  5 +
  6 + private Integer channelId;
  7 +
  8 + private String url;
  9 +
  10 + private String commRate;
  11 +
  12 + public Integer getId() {
  13 + return id;
  14 + }
  15 +
  16 + public void setId(Integer id) {
  17 + this.id = id;
  18 + }
  19 +
  20 + public Integer getChannelId() {
  21 + return channelId;
  22 + }
  23 +
  24 + public void setChannelId(Integer channelId) {
  25 + this.channelId = channelId;
  26 + }
  27 +
  28 + public String getUrl() {
  29 + return url;
  30 + }
  31 +
  32 + public void setUrl(String url) {
  33 + this.url = url;
  34 + }
  35 +
  36 + public String getCommRate() {
  37 + return commRate;
  38 + }
  39 +
  40 + public void setCommRate(String commRate) {
  41 + this.commRate = commRate;
  42 + }
  43 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.unions.dal.IUnionOrderPushDAO" >
  4 + <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionOrderPush" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="channel_id" property="channelId" jdbcType="INTEGER" />
  7 + <result column="url" property="url" jdbcType="VARCHAR" />
  8 + <result column="comm_rate" property="commRate" jdbcType="VARCHAR" />
  9 + </resultMap>
  10 + <sql id="Base_Column_List" >
  11 + id, channel_id, url, comm_rate
  12 + </sql>
  13 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  14 + select
  15 + <include refid="Base_Column_List" />
  16 + from union_order_push
  17 + where id = #{id,jdbcType=INTEGER}
  18 + </select>
  19 + <select id="selectByChannelId" resultMap="BaseResultMap">
  20 + select <include refid="Base_Column_List" />
  21 + from union_order_push
  22 + where channel_id = #{channelId,jdbcType=INTEGER}
  23 + </select>
  24 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  25 + delete from union_order_push
  26 + where id = #{id,jdbcType=INTEGER}
  27 + </delete>
  28 + <insert id="insert" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
  29 + insert into union_order_push (id, channel_id, url,
  30 + comm_rate)
  31 + values (#{id,jdbcType=INTEGER}, #{channelId,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR},
  32 + #{commRate,jdbcType=VARCHAR})
  33 + </insert>
  34 + <insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
  35 + insert into union_order_push
  36 + <trim prefix="(" suffix=")" suffixOverrides="," >
  37 + <if test="id != null" >
  38 + id,
  39 + </if>
  40 + <if test="channelId != null" >
  41 + channel_id,
  42 + </if>
  43 + <if test="url != null" >
  44 + url,
  45 + </if>
  46 + <if test="commRate != null" >
  47 + comm_rate,
  48 + </if>
  49 + </trim>
  50 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  51 + <if test="id != null" >
  52 + #{id,jdbcType=INTEGER},
  53 + </if>
  54 + <if test="channelId != null" >
  55 + #{channelId,jdbcType=INTEGER},
  56 + </if>
  57 + <if test="url != null" >
  58 + #{url,jdbcType=VARCHAR},
  59 + </if>
  60 + <if test="commRate != null" >
  61 + #{commRate,jdbcType=VARCHAR},
  62 + </if>
  63 + </trim>
  64 + </insert>
  65 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
  66 + update union_order_push
  67 + <set >
  68 + <if test="channelId != null" >
  69 + channel_id = #{channelId,jdbcType=INTEGER},
  70 + </if>
  71 + <if test="url != null" >
  72 + url = #{url,jdbcType=VARCHAR},
  73 + </if>
  74 + <if test="commRate != null" >
  75 + comm_rate = #{commRate,jdbcType=VARCHAR},
  76 + </if>
  77 + </set>
  78 + where id = #{id,jdbcType=INTEGER}
  79 + </update>
  80 + <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
  81 + update union_order_push
  82 + set channel_id = #{channelId,jdbcType=INTEGER},
  83 + url = #{url,jdbcType=VARCHAR},
  84 + comm_rate = #{commRate,jdbcType=VARCHAR}
  85 + where id = #{id,jdbcType=INTEGER}
  86 + </update>
  87 +</mapper>
1 package com.yoho.unions.server.restapi; 1 package com.yoho.unions.server.restapi;
2 2
3 import com.yoho.service.model.union.response.UnionResponse; 3 import com.yoho.service.model.union.response.UnionResponse;
  4 +import com.yoho.unions.common.utils.SpringContextUtil;
  5 +import com.yoho.unions.server.service.IOrderPushService;
4 import com.yoho.unions.server.service.IRedirectService; 6 import com.yoho.unions.server.service.IRedirectService;
5 import com.yoho.unions.server.task.BigDataOrderInfoTask; 7 import com.yoho.unions.server.task.BigDataOrderInfoTask;
6 import com.yoho.unions.vo.OrderInfo; 8 import com.yoho.unions.vo.OrderInfo;
  9 +import com.yoho.unions.vo.OrdersGood;
7 import com.yoho.unions.vo.UnionOrderReqVO; 10 import com.yoho.unions.vo.UnionOrderReqVO;
8 import com.yoho.unions.vo.UnionReqVO; 11 import com.yoho.unions.vo.UnionReqVO;
9 import org.slf4j.Logger; 12 import org.slf4j.Logger;
@@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
15 18
16 import javax.servlet.http.HttpServletRequest; 19 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse; 20 import javax.servlet.http.HttpServletResponse;
  21 +import java.math.BigDecimal;
  22 +import java.util.ArrayList;
18 import java.util.List; 23 import java.util.List;
19 24
20 @Controller 25 @Controller
@@ -56,5 +61,37 @@ public class OrderUnionRest { @@ -56,5 +61,37 @@ public class OrderUnionRest {
56 return new UnionResponse(); 61 return new UnionResponse();
57 } 62 }
58 63
  64 + @RequestMapping(value = "/pushCommonUnionOrders")
  65 + @ResponseBody
  66 + public UnionResponse pushCommonUnionOrders(){
  67 + logger.info("Enter pushCommonUnionOrders: req is {}");
  68 + IOrderPushService pushService = SpringContextUtil.getBean("orderPushServiceImpl", IOrderPushService.class);
  69 + List<OrderInfo> orderInfoList = new ArrayList<>();
  70 + OrderInfo orderInfo = new OrderInfo();
  71 + orderInfo.setParentOrderCode("111");
  72 + orderInfo.setOrderTime(1482391381);
  73 + orderInfo.setPayment("1");
  74 + orderInfo.setOrderAmount(new BigDecimal(1));
  75 + orderInfo.setShippingCost(new BigDecimal(1));
  76 + orderInfo.setOrderStatus("1");
  77 + orderInfo.setOrderType("web");
  78 + orderInfo.setClientId(3001);
  79 + List<OrdersGood> ordersGoods = new ArrayList<>();
  80 + for(int i = 0;i<3;i++){
  81 + OrdersGood ordersGood = new OrdersGood();
  82 + ordersGood.setProductSkn("23");
  83 + ordersGood.setProductName("NIKE");
  84 + ordersGood.setBuyNumber(1);
  85 + ordersGood.setLastPrice(new BigDecimal(450));
  86 + ordersGood.setSortName("鞋类");
  87 + ordersGood.setSortId(22);
  88 + ordersGood.setRealPayFee(new BigDecimal(225));
  89 + ordersGoods.add(ordersGood);
  90 + orderInfo.setOrdersGoods(ordersGoods);
  91 + orderInfoList.add(orderInfo);
  92 + }
  93 + pushService.pushOrder(orderInfoList);
  94 + return new UnionResponse();
  95 + }
59 } 96 }
60 97
@@ -5,12 +5,15 @@ import com.netflix.config.DynamicBooleanProperty; @@ -5,12 +5,15 @@ import com.netflix.config.DynamicBooleanProperty;
5 import com.netflix.config.DynamicPropertyFactory; 5 import com.netflix.config.DynamicPropertyFactory;
6 import com.netflix.config.DynamicStringProperty; 6 import com.netflix.config.DynamicStringProperty;
7 import com.yoho.unions.common.utils.HttpUtils; 7 import com.yoho.unions.common.utils.HttpUtils;
  8 +import com.yoho.unions.dal.IUnionOrderPushDAO;
  9 +import com.yoho.unions.dal.model.UnionOrderPush;
8 import com.yoho.unions.server.service.IOrderPushService; 10 import com.yoho.unions.server.service.IOrderPushService;
9 import com.yoho.unions.vo.OrderInfo; 11 import com.yoho.unions.vo.OrderInfo;
10 import com.yoho.unions.vo.OrdersGood; 12 import com.yoho.unions.vo.OrdersGood;
11 import net.spy.memcached.compat.log.Logger; 13 import net.spy.memcached.compat.log.Logger;
12 import net.spy.memcached.compat.log.LoggerFactory; 14 import net.spy.memcached.compat.log.LoggerFactory;
13 import org.apache.commons.lang3.tuple.Pair; 15 import org.apache.commons.lang3.tuple.Pair;
  16 +import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
15 18
16 import java.math.BigDecimal; 19 import java.math.BigDecimal;
@@ -25,6 +28,9 @@ import java.util.Map; @@ -25,6 +28,9 @@ import java.util.Map;
25 @Service 28 @Service
26 public class OrderPushServiceImpl implements IOrderPushService{ 29 public class OrderPushServiceImpl implements IOrderPushService{
27 30
  31 + @Autowired
  32 + IUnionOrderPushDAO unionOrderPushDAO;
  33 +
28 static final Logger logger = LoggerFactory.getLogger(OrderPushServiceImpl.class); 34 static final Logger logger = LoggerFactory.getLogger(OrderPushServiceImpl.class);
29 //推送公共的订单 35 //推送公共的订单
30 public void pushOrder(List<OrderInfo> orderInfos){ 36 public void pushOrder(List<OrderInfo> orderInfos){
@@ -61,7 +67,9 @@ public class OrderPushServiceImpl implements IOrderPushService{ @@ -61,7 +67,9 @@ public class OrderPushServiceImpl implements IOrderPushService{
61 //商品名称 67 //商品名称
62 param.put("proName", good.getProductName()); 68 param.put("proName", good.getProductName());
63 //商品分类名称 69 //商品分类名称
64 - param.put("proCat", good.getSortName()); 70 + param.put("proSortName", good.getSortName());
  71 + //商品分类id
  72 + param.put("proSortId",good.getSortId());
65 //商品最终支付金额 73 //商品最终支付金额
66 proRealPay = good.getRealPayFee().setScale(2, BigDecimal.ROUND_HALF_UP); 74 proRealPay = good.getRealPayFee().setScale(2, BigDecimal.ROUND_HALF_UP);
67 } else { 75 } else {
@@ -70,28 +78,38 @@ public class OrderPushServiceImpl implements IOrderPushService{ @@ -70,28 +78,38 @@ public class OrderPushServiceImpl implements IOrderPushService{
70 StringBuffer nums = new StringBuffer(); 78 StringBuffer nums = new StringBuffer();
71 StringBuffer names = new StringBuffer(); 79 StringBuffer names = new StringBuffer();
72 StringBuffer cats = new StringBuffer(); 80 StringBuffer cats = new StringBuffer();
  81 + StringBuffer sortIds = new StringBuffer();
73 for (int i = 0; i < goods.size(); i++) { 82 for (int i = 0; i < goods.size(); i++) {
74 skns.append(goods.get(i).getProductSkn() + "|"); 83 skns.append(goods.get(i).getProductSkn() + "|");
75 prices.append(goods.get(i).getLastPrice().setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "|"); 84 prices.append(goods.get(i).getLastPrice().setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "|");
76 nums.append(goods.get(i).getBuyNumber() + "|"); 85 nums.append(goods.get(i).getBuyNumber() + "|");
77 names.append(goods.get(i).getProductName() + "|"); 86 names.append(goods.get(i).getProductName() + "|");
78 cats.append(goods.get(i).getSortName() + "|"); 87 cats.append(goods.get(i).getSortName() + "|");
  88 + sortIds.append(goods.get(i).getSortId()+"|");
79 proRealPay = proRealPay.add(goods.get(i).getRealPayFee()); 89 proRealPay = proRealPay.add(goods.get(i).getRealPayFee());
  90 +
80 } 91 }
81 param.put("proNo", skns.substring(0, skns.length() - 1)); 92 param.put("proNo", skns.substring(0, skns.length() - 1));
82 param.put("proPrice", prices.substring(0, prices.length() - 1)); 93 param.put("proPrice", prices.substring(0, prices.length() - 1));
83 param.put("proNum", nums.substring(0, nums.length() - 1)); 94 param.put("proNum", nums.substring(0, nums.length() - 1));
84 param.put("proName", names.substring(0, names.length() - 1)); 95 param.put("proName", names.substring(0, names.length() - 1));
85 - param.put("proCat", cats.substring(0, cats.length() - 1)); 96 + param.put("proSortName", cats.substring(0, cats.length() - 1));
  97 + param.put("proSortId", sortIds.substring(0, cats.length() - 1));
86 } 98 }
87 param.put("proRealPay",proRealPay.doubleValue()); 99 param.put("proRealPay",proRealPay.doubleValue());
  100 + //渠道id
  101 + param.put("channelId",orderInfo.getClientId());
  102 + //佣金比例---根据不同的厂商去计算,在表中维护
  103 + //根据不同的厂商,发送不同的URL
  104 + int clientId = orderInfo.getClientId();
  105 + UnionOrderPush unionOrderPush = unionOrderPushDAO.selectByChannelId(clientId);
  106 + String commRate = unionOrderPush.getCommRate();
  107 + param.put("commRate", commRate == null?0:commRate);
88 Pair<Integer, String> pair = null; 108 Pair<Integer, String> pair = null;
89 try { 109 try {
90 - //根据不同的厂商,发送不同的URL  
91 - int clientId = orderInfo.getClientId();  
92 - DynamicStringProperty url = DynamicPropertyFactory.getInstance().getStringProperty("union-type-url:"+clientId, ""); 110 + String url = unionOrderPush.getUrl();
93 logger.info("pushOrder: url is {}, param is {}", url, param); 111 logger.info("pushOrder: url is {}, param is {}", url, param);
94 - pair = HttpUtils.httpPost(url.get(), param); 112 + pair = HttpUtils.httpPost(url, param);
95 } catch (Exception e) { 113 } catch (Exception e) {
96 logger.error("common order post fail,orderCode is {}", orderInfo.getParentOrderCode()); 114 logger.error("common order post fail,orderCode is {}", orderInfo.getParentOrderCode());
97 } 115 }
@@ -34,5 +34,5 @@ datasources: @@ -34,5 +34,5 @@ datasources:
34 - com.yoho.unions.dal.IUserOrdersDAO 34 - com.yoho.unions.dal.IUserOrdersDAO
35 - com.yoho.unions.dal.IUnionTypeDAO 35 - com.yoho.unions.dal.IUnionTypeDAO
36 - com.yoho.unions.dal.IUnionTypeManageDAO 36 - com.yoho.unions.dal.IUnionTypeManageDAO
37 - 37 + - com.yoho.unions.dal.IUnionOrderPushDAO
38 readOnlyInSlave: true 38 readOnlyInSlave: true
@@ -35,4 +35,5 @@ datasources: @@ -35,4 +35,5 @@ datasources:
35 - com.yoho.unions.dal.IUserOrdersDAO 35 - com.yoho.unions.dal.IUserOrdersDAO
36 - com.yoho.unions.dal.IUnionTypeDAO 36 - com.yoho.unions.dal.IUnionTypeDAO
37 - com.yoho.unions.dal.IUnionTypeManageDAO 37 - com.yoho.unions.dal.IUnionTypeManageDAO
  38 + - com.yoho.unions.dal.IUnionOrderPushDAO
38 readOnlyInSlave: true 39 readOnlyInSlave: true