Authored by zhouxiang

no message

... ... @@ -43,22 +43,22 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UserOrders" >
insert into user_orders (id, uid, order_code,
order_amount, amount, yoho_coin,
coupons_num, create_time, order_status,
channel_code, append, is_valid,
remark, user_id, mbr_name,
is_settle_accounts, settle_amount, settle_accounts_time,
campaign_id, source, tracking_code,
insert into user_orders (id, uid, order_code,
order_amount, amount, yoho_coin,
coupons_num, create_time, order_status,
channel_code, append, is_valid,
remark, user_id, mbr_name,
is_settle_accounts, settle_amount, settle_accounts_time,
campaign_id, source, tracking_code,
u_id, order_time, is_push
)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=VARCHAR},
#{orderAmount,jdbcType=DECIMAL}, #{amount,jdbcType=DECIMAL}, #{yohoCoin,jdbcType=SMALLINT},
#{couponsNum,jdbcType=SMALLINT}, #{createTime,jdbcType=INTEGER}, #{orderStatus,jdbcType=TINYINT},
#{channelCode,jdbcType=VARCHAR}, #{append,jdbcType=VARCHAR}, #{isValid,jdbcType=CHAR},
#{remark,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{mbrName,jdbcType=VARCHAR},
#{isSettleAccounts,jdbcType=TINYINT}, #{settleAmount,jdbcType=DECIMAL}, #{settleAccountsTime,jdbcType=INTEGER},
#{campaignId,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, #{trackingCode,jdbcType=VARCHAR},
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=VARCHAR},
#{orderAmount,jdbcType=DECIMAL}, #{amount,jdbcType=DECIMAL}, #{yohoCoin,jdbcType=SMALLINT},
#{couponsNum,jdbcType=SMALLINT}, #{createTime,jdbcType=INTEGER}, #{orderStatus,jdbcType=TINYINT},
#{channelCode,jdbcType=VARCHAR}, #{append,jdbcType=VARCHAR}, #{isValid,jdbcType=CHAR},
#{remark,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{mbrName,jdbcType=VARCHAR},
#{isSettleAccounts,jdbcType=TINYINT}, #{settleAmount,jdbcType=DECIMAL}, #{settleAccountsTime,jdbcType=INTEGER},
#{campaignId,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, #{trackingCode,jdbcType=VARCHAR},
#{uId,jdbcType=INTEGER}, #{orderTime,jdbcType=INTEGER}, #{isPush,jdbcType=INTEGER}
)
</insert>
... ...
... ... @@ -3,6 +3,7 @@ package com.yoho.unions.server.mqconsumer;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.message.YhMessageConsumer;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.dal.IUserOrdersDAO;
import com.yoho.unions.dal.model.UserOrders;
import com.yoho.unions.message.CommonMessageConsumer;
... ... @@ -52,12 +53,12 @@ public class OrderPushConsumer implements CommonMessageConsumer {
*/
private void saveUnionOrder(String orderData) {
UserOrders userOrders = convertData(orderData);
userOrdersDAO.insert(userOrders);
userOrdersDAO.insertSelective(userOrders);
}
private UserOrders convertData(String orderData) {
JSONObject jsonObject = JSON.parseObject(orderData);
JSONObject unionCookie = jsonObject.getJSONObject("union_cookie");
JSONObject unionCookie = JSONObject.parseObject(jsonObject.getString("unionCookie"));
UserOrders userOrders = new UserOrders();
//联盟id
userOrders.setUid(jsonObject.getInteger("clientId"));
... ... @@ -75,10 +76,19 @@ public class OrderPushConsumer implements CommonMessageConsumer {
userOrders.setOrderStatus(jsonObject.getInteger("orderStatus"));
//使用有货币、券
//第三方tracking_code
userOrders.setTrackingCode(unionCookie.getString("tracking_code"));
userOrders.setTrackingCode(unionCookie.getString("channel_code"));
//第三方用户id
userOrders.setUserId(unionCookie.getString("u_id"));
userOrders.setUserId(unionCookie.getString("fl_uid"));
//创建时间
userOrders.setCreateTime(DateUtil.getCurrentTimeSecond());
//是否推送
userOrders.setIsPush(0);
return userOrders;
}
public static void main(String[] args) {
OrderPushConsumer orderPushConsumer = new OrderPushConsumer();
orderPushConsumer.handleMessage("{\"clientId\":3001,\"createTime\":1478589459,\"lastOrderAmount\":2.95,\"orderAmount\":11,\"orderCode\":160590048,\"orderStatus\":0,\"uid\":8040155,\"unionCookie\":\"{'client_id':3001,'fl_uid':2589067,'channel_code':'af90906e212bk'}\"}");
}
}
... ...
... ... @@ -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);
}
}
... ...
... ... @@ -23,4 +23,14 @@ datasources:
password: 9nm0icOwt6bMHjMusIfMLw==
daos:
- com.yoho.unions.dal.IAppActivateIdfaListDAO
yh_unions:
servers:
- 192.168.102.219:3306
- 192.168.102.219:3306
username: yh_test
password: 9nm0icOwt6bMHjMusIfMLw==
daos:
- com.yoho.unions.dal.IUserOrdersDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -24,4 +24,13 @@ datasources:
password: ${bigdate.db.password}
daos:
- com.yoho.unions.dal.IAppActivateIdfaListDAO
yh_unions:
servers:
- ${jdbc.mysql.unions.master}
- ${jdbc.mysql.unions.slave}
username: ${jdbc.mysql.unions.username}
password: ${jdbc.mysql.unions.password}
daos:
- com.yoho.unions.dal.IUserOrdersDAO
readOnlyInSlave: true
\ No newline at end of file
... ...