Authored by zhengwen.ge

update

package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionOrderPush;
public interface IUnionOrderPushDAO {
int deleteByPrimaryKey(Integer id);
int insert(UnionOrderPush record);
int insertSelective(UnionOrderPush record);
UnionOrderPush selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(UnionOrderPush record);
int updateByPrimaryKey(UnionOrderPush record);
UnionOrderPush selectByChannelId(int channelId);
}
\ No newline at end of file
... ...
package com.yoho.unions.dal.model;
public class UnionOrderPush {
private Integer id;
private Integer channelId;
private String url;
private String commRate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getChannelId() {
return channelId;
}
public void setChannelId(Integer channelId) {
this.channelId = channelId;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCommRate() {
return commRate;
}
public void setCommRate(String commRate) {
this.commRate = commRate;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.unions.dal.IUnionOrderPushDAO" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionOrderPush" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="channel_id" property="channelId" jdbcType="INTEGER" />
<result column="url" property="url" jdbcType="VARCHAR" />
<result column="comm_rate" property="commRate" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, channel_id, url, comm_rate
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from union_order_push
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByChannelId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from union_order_push
where channel_id = #{channelId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from union_order_push
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
insert into union_order_push (id, channel_id, url,
comm_rate)
values (#{id,jdbcType=INTEGER}, #{channelId,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR},
#{commRate,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
insert into union_order_push
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="channelId != null" >
channel_id,
</if>
<if test="url != null" >
url,
</if>
<if test="commRate != null" >
comm_rate,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="channelId != null" >
#{channelId,jdbcType=INTEGER},
</if>
<if test="url != null" >
#{url,jdbcType=VARCHAR},
</if>
<if test="commRate != null" >
#{commRate,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
update union_order_push
<set >
<if test="channelId != null" >
channel_id = #{channelId,jdbcType=INTEGER},
</if>
<if test="url != null" >
url = #{url,jdbcType=VARCHAR},
</if>
<if test="commRate != null" >
comm_rate = #{commRate,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionOrderPush" >
update union_order_push
set channel_id = #{channelId,jdbcType=INTEGER},
url = #{url,jdbcType=VARCHAR},
comm_rate = #{commRate,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yoho.unions.server.restapi;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.utils.SpringContextUtil;
import com.yoho.unions.server.service.IOrderPushService;
import com.yoho.unions.server.service.IRedirectService;
import com.yoho.unions.server.task.BigDataOrderInfoTask;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.OrdersGood;
import com.yoho.unions.vo.UnionOrderReqVO;
import com.yoho.unions.vo.UnionReqVO;
import org.slf4j.Logger;
... ... @@ -15,6 +18,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Controller
... ... @@ -56,5 +61,37 @@ public class OrderUnionRest {
return new UnionResponse();
}
@RequestMapping(value = "/pushCommonUnionOrders")
@ResponseBody
public UnionResponse pushCommonUnionOrders(){
logger.info("Enter pushCommonUnionOrders: req is {}");
IOrderPushService pushService = SpringContextUtil.getBean("orderPushServiceImpl", IOrderPushService.class);
List<OrderInfo> orderInfoList = new ArrayList<>();
OrderInfo orderInfo = new OrderInfo();
orderInfo.setParentOrderCode("111");
orderInfo.setOrderTime(1482391381);
orderInfo.setPayment("1");
orderInfo.setOrderAmount(new BigDecimal(1));
orderInfo.setShippingCost(new BigDecimal(1));
orderInfo.setOrderStatus("1");
orderInfo.setOrderType("web");
orderInfo.setClientId(3001);
List<OrdersGood> ordersGoods = new ArrayList<>();
for(int i = 0;i<3;i++){
OrdersGood ordersGood = new OrdersGood();
ordersGood.setProductSkn("23");
ordersGood.setProductName("NIKE");
ordersGood.setBuyNumber(1);
ordersGood.setLastPrice(new BigDecimal(450));
ordersGood.setSortName("鞋类");
ordersGood.setSortId(22);
ordersGood.setRealPayFee(new BigDecimal(225));
ordersGoods.add(ordersGood);
orderInfo.setOrdersGoods(ordersGoods);
orderInfoList.add(orderInfo);
}
pushService.pushOrder(orderInfoList);
return new UnionResponse();
}
}
... ...
... ... @@ -5,12 +5,15 @@ import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
import com.yoho.unions.common.utils.HttpUtils;
import com.yoho.unions.dal.IUnionOrderPushDAO;
import com.yoho.unions.dal.model.UnionOrderPush;
import com.yoho.unions.server.service.IOrderPushService;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.OrdersGood;
import net.spy.memcached.compat.log.Logger;
import net.spy.memcached.compat.log.LoggerFactory;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
... ... @@ -25,6 +28,9 @@ import java.util.Map;
@Service
public class OrderPushServiceImpl implements IOrderPushService{
@Autowired
IUnionOrderPushDAO unionOrderPushDAO;
static final Logger logger = LoggerFactory.getLogger(OrderPushServiceImpl.class);
//推送公共的订单
public void pushOrder(List<OrderInfo> orderInfos){
... ... @@ -61,7 +67,9 @@ public class OrderPushServiceImpl implements IOrderPushService{
//商品名称
param.put("proName", good.getProductName());
//商品分类名称
param.put("proCat", good.getSortName());
param.put("proSortName", good.getSortName());
//商品分类id
param.put("proSortId",good.getSortId());
//商品最终支付金额
proRealPay = good.getRealPayFee().setScale(2, BigDecimal.ROUND_HALF_UP);
} else {
... ... @@ -70,28 +78,38 @@ public class OrderPushServiceImpl implements IOrderPushService{
StringBuffer nums = new StringBuffer();
StringBuffer names = new StringBuffer();
StringBuffer cats = new StringBuffer();
StringBuffer sortIds = new StringBuffer();
for (int i = 0; i < goods.size(); i++) {
skns.append(goods.get(i).getProductSkn() + "|");
prices.append(goods.get(i).getLastPrice().setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "|");
nums.append(goods.get(i).getBuyNumber() + "|");
names.append(goods.get(i).getProductName() + "|");
cats.append(goods.get(i).getSortName() + "|");
sortIds.append(goods.get(i).getSortId()+"|");
proRealPay = proRealPay.add(goods.get(i).getRealPayFee());
}
param.put("proNo", skns.substring(0, skns.length() - 1));
param.put("proPrice", prices.substring(0, prices.length() - 1));
param.put("proNum", nums.substring(0, nums.length() - 1));
param.put("proName", names.substring(0, names.length() - 1));
param.put("proCat", cats.substring(0, cats.length() - 1));
param.put("proSortName", cats.substring(0, cats.length() - 1));
param.put("proSortId", sortIds.substring(0, cats.length() - 1));
}
param.put("proRealPay",proRealPay.doubleValue());
Pair<Integer, String> pair = null;
try {
//渠道id
param.put("channelId",orderInfo.getClientId());
//佣金比例---根据不同的厂商去计算,在表中维护
//根据不同的厂商,发送不同的URL
int clientId = orderInfo.getClientId();
DynamicStringProperty url = DynamicPropertyFactory.getInstance().getStringProperty("union-type-url:"+clientId, "");
UnionOrderPush unionOrderPush = unionOrderPushDAO.selectByChannelId(clientId);
String commRate = unionOrderPush.getCommRate();
param.put("commRate", commRate == null?0:commRate);
Pair<Integer, String> pair = null;
try {
String url = unionOrderPush.getUrl();
logger.info("pushOrder: url is {}, param is {}", url, param);
pair = HttpUtils.httpPost(url.get(), param);
pair = HttpUtils.httpPost(url, param);
} catch (Exception e) {
logger.error("common order post fail,orderCode is {}", orderInfo.getParentOrderCode());
}
... ...
... ... @@ -34,5 +34,5 @@ datasources:
- com.yoho.unions.dal.IUserOrdersDAO
- com.yoho.unions.dal.IUnionTypeDAO
- com.yoho.unions.dal.IUnionTypeManageDAO
- com.yoho.unions.dal.IUnionOrderPushDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -35,4 +35,5 @@ datasources:
- com.yoho.unions.dal.IUserOrdersDAO
- com.yoho.unions.dal.IUnionTypeDAO
- com.yoho.unions.dal.IUnionTypeManageDAO
- com.yoho.unions.dal.IUnionOrderPushDAO
readOnlyInSlave: true
\ No newline at end of file
... ...