Authored by linlong

Merge branch 'master' into fix_0223

1 package com.yoho.unions.common.redis; 1 package com.yoho.unions.common.redis;
2 2
3 import com.yoho.core.redis.YHListOperations; 3 import com.yoho.core.redis.YHListOperations;
  4 +import com.yoho.core.redis.YHRedisTemplate;
4 import com.yoho.unions.common.utils.SerializeUtils; 5 import com.yoho.unions.common.utils.SerializeUtils;
  6 +import com.yoho.unions.helper.CacheKeyHelper;
  7 +import org.apache.commons.collections.CollectionUtils;
5 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
6 import org.slf4j.Logger; 9 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
@@ -9,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -9,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
10 13
11 import javax.annotation.Resource; 14 import javax.annotation.Resource;
  15 +import java.util.ArrayList;
  16 +import java.util.Collection;
  17 +import java.util.concurrent.TimeUnit;
12 18
13 @Component 19 @Component
14 public class RedisListCache { 20 public class RedisListCache {
@@ -17,6 +23,8 @@ public class RedisListCache { @@ -17,6 +23,8 @@ public class RedisListCache {
17 23
18 @Resource(name="yhListOperations") 24 @Resource(name="yhListOperations")
19 YHListOperations<String, String> yhListOperations; 25 YHListOperations<String, String> yhListOperations;
  26 + @Resource
  27 + YHRedisTemplate<String, String> yHRedisTemplate;
20 28
21 /** 29 /**
22 * redis rightPop 操作 30 * redis rightPop 操作
@@ -66,4 +74,33 @@ public class RedisListCache { @@ -66,4 +74,33 @@ public class RedisListCache {
66 74
67 } 75 }
68 76
  77 + public <T> void rightPushAll(String key,Collection<T> values, long timeout, TimeUnit unit) {
  78 + logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, values, timeout, unit);
  79 + // 如果是空列表,直接返回
  80 + if (CollectionUtils.isEmpty(values)) {
  81 + return;
  82 + }
  83 +
  84 + String cacheKey = key;
  85 + // 如果获取的key为空,则说明缓存开关是关闭的
  86 + if (StringUtils.isEmpty(cacheKey)) {
  87 + return;
  88 + }
  89 + try {
  90 + Collection<String> strValues = new ArrayList<String>();
  91 + for (T t : values) {
  92 + String strValue = CacheKeyHelper.value2String(t);
  93 + if (StringUtils.isEmpty(strValue)) {
  94 + continue;
  95 + }
  96 + strValues.add(strValue);
  97 + }
  98 + yhListOperations.rightPushAll(cacheKey, strValues);
  99 + yHRedisTemplate.longExpire(cacheKey, timeout, unit);
  100 +
  101 + } catch (Exception e) {
  102 + logger.warn("rightPushAll redis list operation failed. key is {}", cacheKey, e);
  103 + }
  104 + }
  105 +
69 } 106 }
  1 +package com.yoho.unions.vo;
  2 +
  3 +import java.io.Serializable;
  4 +import java.math.BigDecimal;
  5 +
  6 +/**
  7 + * 转化数据
  8 + * Created by yoho on 2017/2/22.
  9 + */
  10 +public class TransInfo implements Serializable {
  11 +
  12 + //标示是普通交寄还是首单交寄
  13 + private String type;
  14 +
  15 + private BigDecimal orderAmount;
  16 +
  17 + private String udid;
  18 +
  19 + private String uid;
  20 +
  21 + private String ordercode;
  22 +
  23 + public String getUid() {
  24 + return uid;
  25 + }
  26 +
  27 + public void setUid(String uid) {
  28 + this.uid = uid;
  29 + }
  30 +
  31 + public String getOrdercode() {
  32 + return ordercode;
  33 + }
  34 +
  35 + public void setOrdercode(String ordercode) {
  36 + this.ordercode = ordercode;
  37 + }
  38 +
  39 + public String getType() {
  40 + return type;
  41 + }
  42 +
  43 + public void setType(String type) {
  44 + this.type = type;
  45 + }
  46 +
  47 + public BigDecimal getOrderAmount() {
  48 + return orderAmount;
  49 + }
  50 +
  51 + public void setOrderAmount(BigDecimal orderAmount) {
  52 + this.orderAmount = orderAmount;
  53 + }
  54 +
  55 + public String getUdid() {
  56 + return udid;
  57 + }
  58 +
  59 + public void setUdid(String udid) {
  60 + this.udid = udid;
  61 + }
  62 +}
  1 +package com.yoho.unions.dal;
  2 +
  3 +
  4 +import com.yoho.unions.dal.model.UnionActivity;
  5 +
  6 +public interface IUnionActivityDAO {
  7 +
  8 + int insert(UnionActivity record);
  9 +
  10 + int insertSelective(UnionActivity record);
  11 +
  12 + UnionActivity selectByPrimaryKey(Long id);
  13 +
  14 + UnionActivity selectByUdid(String udid);
  15 +}
1 -//package com.yoho.unions.dal;  
2 -//  
3 -//  
4 -//import com.yoho.unions.dal.model.UnionDepartmentUrl;  
5 -//  
6 -//public interface IUnionDepartmentUrlDAO {  
7 -// int deleteByPrimaryKey(Integer id);  
8 -//  
9 -// int insert(UnionDepartmentUrl record);  
10 -//  
11 -// int insertSelective(UnionDepartmentUrl record);  
12 -//  
13 -// UnionDepartmentUrl selectByPrimaryKey(Integer id);  
14 -//  
15 -// int updateByPrimaryKeySelective(UnionDepartmentUrl record);  
16 -//  
17 -// int updateByPrimaryKey(UnionDepartmentUrl record);  
18 -//  
19 -// UnionDepartmentUrl selectByUnionType(String unionType);  
20 -//}  
1 -//package com.yoho.unions.dal;  
2 -//  
3 -//  
4 -//import com.yoho.unions.dal.model.UnionType;  
5 -//  
6 -//public interface IUnionTypeDAO {  
7 -// int deleteByPrimaryKey(Integer id);  
8 -//  
9 -// int insert(UnionType record);  
10 -//  
11 -// int insertSelective(UnionType record);  
12 -//  
13 -// UnionType selectByPrimaryKey(Integer id);  
14 -//  
15 -// UnionType selectByUnionType(Integer unionType);  
16 -//  
17 -// int updateByPrimaryKeySelective(UnionType record);  
18 -//  
19 -// int updateByPrimaryKey(UnionType record);  
20 -//}  
@@ -27,6 +27,8 @@ public class MktMarketingUrl { @@ -27,6 +27,8 @@ public class MktMarketingUrl {
27 27
28 private String mktActivityCode; 28 private String mktActivityCode;
29 29
  30 + private String landingPageUrl;
  31 +
30 public String getMktActivityCode() { 32 public String getMktActivityCode() {
31 return mktActivityCode; 33 return mktActivityCode;
32 } 34 }
@@ -130,4 +132,12 @@ public class MktMarketingUrl { @@ -130,4 +132,12 @@ public class MktMarketingUrl {
130 public void setCreateTime(Integer createTime) { 132 public void setCreateTime(Integer createTime) {
131 this.createTime = createTime; 133 this.createTime = createTime;
132 } 134 }
  135 +
  136 + public String getLandingPageUrl() {
  137 + return landingPageUrl;
  138 + }
  139 +
  140 + public void setLandingPageUrl(String landingPageUrl) {
  141 + this.landingPageUrl = landingPageUrl;
  142 + }
133 } 143 }
  1 +package com.yoho.unions.dal.model;
  2 +
  3 +public class UnionActivity {
  4 + private Long id;
  5 +
  6 + private String udid;
  7 +
  8 + private String muid;
  9 +
  10 + private String unionType;
  11 +
  12 + private String clientType;
  13 +
  14 + private String advertiserId;
  15 +
  16 + private String clickId;
  17 +
  18 + private Integer createTime;
  19 +
  20 + public Long getId() {
  21 + return id;
  22 + }
  23 +
  24 + public void setId(Long id) {
  25 + this.id = id;
  26 + }
  27 +
  28 + public String getUdid() {
  29 + return udid;
  30 + }
  31 +
  32 + public void setUdid(String udid) {
  33 + this.udid = udid == null ? null : udid.trim();
  34 + }
  35 +
  36 + public String getMuid() {
  37 + return muid;
  38 + }
  39 +
  40 + public void setMuid(String muid) {
  41 + this.muid = muid == null ? null : muid.trim();
  42 + }
  43 +
  44 + public String getUnionType() {
  45 + return unionType;
  46 + }
  47 +
  48 + public void setUnionType(String unionType) {
  49 + this.unionType = unionType == null ? null : unionType.trim();
  50 + }
  51 +
  52 + public String getClientType() {
  53 + return clientType;
  54 + }
  55 +
  56 + public void setClientType(String clientType) {
  57 + this.clientType = clientType == null ? null : clientType.trim();
  58 + }
  59 +
  60 + public String getAdvertiserId() {
  61 + return advertiserId;
  62 + }
  63 +
  64 + public void setAdvertiserId(String advertiserId) {
  65 + this.advertiserId = advertiserId == null ? null : advertiserId.trim();
  66 + }
  67 +
  68 + public String getClickId() {
  69 + return clickId;
  70 + }
  71 +
  72 + public void setClickId(String clickId) {
  73 + this.clickId = clickId == null ? null : clickId.trim();
  74 + }
  75 +
  76 + public Integer getCreateTime() {
  77 + return createTime;
  78 + }
  79 +
  80 + public void setCreateTime(Integer createTime) {
  81 + this.createTime = createTime;
  82 + }
  83 +}
  1 +package com.yoho.unions.dal.model;
  2 +
  3 +import java.math.BigDecimal;
  4 +
  5 +/**
  6 + * Created by yoho on 2017/2/22.
  7 + */
  8 +public class UnionActivityTrans {
  9 +
  10 + //订单金额
  11 + private BigDecimal order_amount;
  12 + //设备号
  13 + private String udid;
  14 +
  15 + private String uid;
  16 +
  17 + private String order_code;
  18 +
  19 + public String getUid() {
  20 + return uid;
  21 + }
  22 +
  23 + public void setUid(String uid) {
  24 + this.uid = uid;
  25 + }
  26 +
  27 + public String getUdid() {
  28 + return udid;
  29 + }
  30 +
  31 + public void setUdid(String udid) {
  32 + this.udid = udid;
  33 + }
  34 +
  35 + public BigDecimal getOrder_amount() {
  36 + return order_amount;
  37 + }
  38 +
  39 + public void setOrder_amount(BigDecimal order_amount) {
  40 + this.order_amount = order_amount;
  41 + }
  42 +
  43 + public String getOrder_code() {
  44 + return order_code;
  45 + }
  46 +
  47 + public void setOrder_code(String order_code) {
  48 + this.order_code = order_code;
  49 + }
  50 +}
@@ -15,10 +15,11 @@ @@ -15,10 +15,11 @@
15 <result column="status" property="status" jdbcType="INTEGER" /> 15 <result column="status" property="status" jdbcType="INTEGER" />
16 <result column="create_time" property="createTime" jdbcType="INTEGER" /> 16 <result column="create_time" property="createTime" jdbcType="INTEGER" />
17 <result column="mkt_activity_code" property="mktActivityCode" jdbcType="VARCHAR" /> 17 <result column="mkt_activity_code" property="mktActivityCode" jdbcType="VARCHAR" />
  18 + <result column="landing_page_url" property="landingPageUrl" jdbcType="VARCHAR" />
18 </resultMap> 19 </resultMap>
19 <sql id="Base_Column_List" > 20 <sql id="Base_Column_List" >
20 union_type, division_code, class_code, channel_code, device_code, dept_id, create_id, 21 union_type, division_code, class_code, channel_code, device_code, dept_id, create_id,
21 - name, src_url, dest_url, status, create_time,mkt_activity_code 22 + name, src_url, dest_url, status, create_time,mkt_activity_code,landing_page_url
22 </sql> 23 </sql>
23 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" > 24 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
24 select 25 select
  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.IUnionActivityDAO" >
  4 + <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionActivity" >
  5 + <id column="id" property="id" jdbcType="BIGINT" />
  6 + <result column="udid" property="udid" jdbcType="VARCHAR" />
  7 + <result column="muid" property="muid" jdbcType="VARCHAR" />
  8 + <result column="union_type" property="unionType" jdbcType="VARCHAR" />
  9 + <result column="client_type" property="clientType" jdbcType="VARCHAR" />
  10 + <result column="advertiser_id" property="advertiserId" jdbcType="VARCHAR" />
  11 + <result column="click_id" property="clickId" jdbcType="VARCHAR" />
  12 + <result column="create_time" property="createTime" jdbcType="INTEGER" />
  13 + </resultMap>
  14 + <sql id="Base_Column_List" >
  15 + id, udid, muid, union_type, client_type, advertiser_id, click_id, create_time
  16 + </sql>
  17 +
  18 + <select id="selectByUdid" resultMap="BaseResultMap">
  19 + select <include refid="Base_Column_List" />
  20 + from union_activity
  21 + where udid = #{udid} limit 1
  22 + </select>
  23 + <insert id="insert" parameterType="com.yoho.unions.dal.model.UnionActivity" >
  24 + insert into union_activity (id, udid, muid,
  25 + union_type, client_type, advertiser_id,
  26 + click_id, create_time)
  27 + values (#{id,jdbcType=BIGINT}, #{udid,jdbcType=VARCHAR}, #{muid,jdbcType=VARCHAR},
  28 + #{unionType,jdbcType=VARCHAR}, #{clientType,jdbcType=VARCHAR}, #{advertiserId,jdbcType=VARCHAR},
  29 + #{clickId,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER})
  30 + </insert>
  31 + <insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionActivity" >
  32 + insert into union_activity
  33 + <trim prefix="(" suffix=")" suffixOverrides="," >
  34 + <if test="id != null" >
  35 + id,
  36 + </if>
  37 + <if test="udid != null" >
  38 + udid,
  39 + </if>
  40 + <if test="muid != null" >
  41 + muid,
  42 + </if>
  43 + <if test="unionType != null" >
  44 + union_type,
  45 + </if>
  46 + <if test="clientType != null" >
  47 + client_type,
  48 + </if>
  49 + <if test="advertiserId != null" >
  50 + advertiser_id,
  51 + </if>
  52 + <if test="clickId != null" >
  53 + click_id,
  54 + </if>
  55 + <if test="createTime != null" >
  56 + create_time,
  57 + </if>
  58 + </trim>
  59 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  60 + <if test="id != null" >
  61 + #{id,jdbcType=BIGINT},
  62 + </if>
  63 + <if test="udid != null" >
  64 + #{udid,jdbcType=VARCHAR},
  65 + </if>
  66 + <if test="muid != null" >
  67 + #{muid,jdbcType=VARCHAR},
  68 + </if>
  69 + <if test="unionType != null" >
  70 + #{unionType,jdbcType=VARCHAR},
  71 + </if>
  72 + <if test="clientType != null" >
  73 + #{clientType,jdbcType=VARCHAR},
  74 + </if>
  75 + <if test="advertiserId != null" >
  76 + #{advertiserId,jdbcType=VARCHAR},
  77 + </if>
  78 + <if test="clickId != null" >
  79 + #{clickId,jdbcType=VARCHAR},
  80 + </if>
  81 + <if test="createTime != null" >
  82 + #{createTime,jdbcType=INTEGER},
  83 + </if>
  84 + </trim>
  85 + </insert>
  86 +
  87 +</mapper>
@@ -62,7 +62,7 @@ public class ActivateUnionRest { @@ -62,7 +62,7 @@ public class ActivateUnionRest {
62 * @return 62 * @return
63 */ 63 */
64 @RequestMapping("/activateUnion") 64 @RequestMapping("/activateUnion")
65 - @ResponseBody public ActiveUnionResponseBO activateUnion(ActivateUnionRequestVO vo, HttpServletRequest request, HttpServletResponse response) { 65 + @ResponseBody public UnionResponse activateUnion(ActivateUnionRequestVO vo, HttpServletRequest request, HttpServletResponse response) {
66 log.info("activateUnion with param is {}", vo); 66 log.info("activateUnion with param is {}", vo);
67 if ("iphone".equals(vo.getClient_type())) { 67 if ("iphone".equals(vo.getClient_type())) {
68 vo.setClient_type(ClientTypeEnum.IOS.getName()); 68 vo.setClient_type(ClientTypeEnum.IOS.getName());
@@ -97,7 +97,7 @@ public class ActivateUnionRest { @@ -97,7 +97,7 @@ public class ActivateUnionRest {
97 97
98 if (!ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType) && !ClientTypeEnum.IOS.getName().equalsIgnoreCase(clientType)) { 98 if (!ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType) && !ClientTypeEnum.IOS.getName().equalsIgnoreCase(clientType)) {
99 log.warn("activateUnion error with param is {}", vo); 99 log.warn("activateUnion error with param is {}", vo);
100 - return new ActiveUnionResponseBO(600, "error"); 100 + return new UnionResponse(200, "error",new JSONObject());
101 } 101 }
102 //IP取出来的有可能是42.239.40.36,123.151.42.50,只取第一个 102 //IP取出来的有可能是42.239.40.36,123.151.42.50,只取第一个
103 String IP = RemoteIPInterceptor.getRemoteIP(); 103 String IP = RemoteIPInterceptor.getRemoteIP();
@@ -108,8 +108,40 @@ public class ActivateUnionRest { @@ -108,8 +108,40 @@ public class ActivateUnionRest {
108 } 108 }
109 bo.setClientIp(clientIp); 109 bo.setClientIp(clientIp);
110 //多线程处理 110 //多线程处理
111 - exe.execute(new RunActivate(bo));  
112 - return new ActiveUnionResponseBO(200, "success"); 111 + //exe.execute(new RunActivate(bo));
  112 + return getGoUrl(bo);
  113 + }
  114 +
  115 + private UnionResponse getGoUrl(ActivateUnionRequestBO bo){
  116 + MainUnionService service = null;
  117 + if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(bo.getClient_type())) {
  118 + //处理安卓的服务
  119 + for (String str : UnionConstant.andriodServiceList) {
  120 + //捕获异常,不影响后面的联盟
  121 + try {
  122 + service = SpringContextUtil.getBean(str, MainUnionService.class);
  123 + service.activeUnion(bo);
  124 + } catch (Exception e) {
  125 + log.warn("addUnion error with param is {}", bo, e);
  126 + }
  127 + }
  128 + } else if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(bo.getClient_type())) {
  129 + //处理iOS的服务
  130 + for (String str : UnionConstant.iOSServiceList) {
  131 + //捕获异常,不影响后面的联盟
  132 + try {
  133 + service = SpringContextUtil.getBean(str, MainUnionService.class);
  134 + service.activeUnion(bo);
  135 + } catch (Exception e) {
  136 + log.warn("addUnion error with param is {}", bo, e);
  137 + }
  138 + }
  139 + }
  140 +
  141 + //调用统一的联盟激活接口
  142 + IUnionService unionService = SpringContextUtil.getBean("unionServiceImpl", IUnionService.class);
  143 + activeUnion.info("activeUnion request is {}",bo);
  144 + return unionService.activateUnion(bo);
113 } 145 }
114 146
115 public static class RunActivate implements Runnable { 147 public static class RunActivate implements Runnable {
@@ -122,35 +154,7 @@ public class ActivateUnionRest { @@ -122,35 +154,7 @@ public class ActivateUnionRest {
122 154
123 @Override 155 @Override
124 public void run() { 156 public void run() {
125 - MainUnionService service = null;  
126 - if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(bo.getClient_type())) {  
127 - //处理安卓的服务  
128 - for (String str : UnionConstant.andriodServiceList) {  
129 - //捕获异常,不影响后面的联盟  
130 - try {  
131 - service = SpringContextUtil.getBean(str, MainUnionService.class);  
132 - service.activeUnion(bo);  
133 - } catch (Exception e) {  
134 - log.warn("addUnion error with param is {}", bo, e);  
135 - }  
136 - }  
137 - } else if (ClientTypeEnum.IOS.getName().equalsIgnoreCase(bo.getClient_type())) {  
138 - //处理iOS的服务  
139 - for (String str : UnionConstant.iOSServiceList) {  
140 - //捕获异常,不影响后面的联盟  
141 - try {  
142 - service = SpringContextUtil.getBean(str, MainUnionService.class);  
143 - service.activeUnion(bo);  
144 - } catch (Exception e) {  
145 - log.warn("addUnion error with param is {}", bo, e);  
146 - }  
147 - }  
148 - }  
149 157
150 - //调用统一的联盟激活接口  
151 - IUnionService unionService = SpringContextUtil.getBean("unionServiceImpl", IUnionService.class);  
152 - activeUnion.info("activeUnion request is {}",bo);  
153 - unionService.activateUnion(bo);  
154 158
155 } 159 }
156 public ActivateUnionRequestBO getBo() { 160 public ActivateUnionRequestBO getBo() {
1 package com.yoho.unions.server.service; 1 package com.yoho.unions.server.service;
2 2
3 import com.yoho.unions.vo.OrderInfo; 3 import com.yoho.unions.vo.OrderInfo;
  4 +import com.yoho.unions.vo.TransInfo;
4 import com.yoho.unions.vo.UnionOrderReqVO; 5 import com.yoho.unions.vo.UnionOrderReqVO;
5 6
6 import java.util.List; 7 import java.util.List;
@@ -9,4 +10,6 @@ public interface IUnionOrderService { @@ -9,4 +10,6 @@ public interface IUnionOrderService {
9 10
10 public List<OrderInfo> getUnionOrders(UnionOrderReqVO req); 11 public List<OrderInfo> getUnionOrders(UnionOrderReqVO req);
11 12
  13 + public List<TransInfo> getTrandInfo(UnionOrderReqVO req);
  14 +
12 } 15 }
1 package com.yoho.unions.server.service.impl; 1 package com.yoho.unions.server.service.impl;
2 2
  3 +import com.yoho.service.model.union.UnionTrans;
3 import com.yoho.unions.common.redis.RedisHashCache; 4 import com.yoho.unions.common.redis.RedisHashCache;
4 import com.yoho.unions.common.redis.RedisListCache; 5 import com.yoho.unions.common.redis.RedisListCache;
  6 +import com.yoho.unions.dal.model.UnionActivityTrans;
5 import com.yoho.unions.dal.model.UnionOrders; 7 import com.yoho.unions.dal.model.UnionOrders;
6 import com.yoho.unions.dal.model.UnionOrdersGoods; 8 import com.yoho.unions.dal.model.UnionOrdersGoods;
7 import com.yoho.unions.server.service.IUnionOrderService; 9 import com.yoho.unions.server.service.IUnionOrderService;
8 import com.yoho.unions.vo.OrderInfo; 10 import com.yoho.unions.vo.OrderInfo;
9 import com.yoho.unions.vo.OrdersGood; 11 import com.yoho.unions.vo.OrdersGood;
  12 +import com.yoho.unions.vo.TransInfo;
10 import com.yoho.unions.vo.UnionOrderReqVO; 13 import com.yoho.unions.vo.UnionOrderReqVO;
11 import org.apache.commons.collections.CollectionUtils; 14 import org.apache.commons.collections.CollectionUtils;
12 import org.apache.commons.lang3.StringUtils; 15 import org.apache.commons.lang3.StringUtils;
@@ -26,8 +29,14 @@ public class UnionOrderServiceImpl implements IUnionOrderService { @@ -26,8 +29,14 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
26 29
27 private static final String UNION_ORDER_KEY = "union:orders"; 30 private static final String UNION_ORDER_KEY = "union:orders";
28 31
  32 + private static final String UNION_TRAND = "YH:BD:ORDER:UNIONS";
  33 +
29 private static final String UNION_ORDER_GOODS_KEY_PRE = "union:order_goods:"; 34 private static final String UNION_ORDER_GOODS_KEY_PRE = "union:order_goods:";
30 35
  36 + private static final String UNION_TRANS_UNIONTYPE = "YH:BD:UNI:1:ORDER:";
  37 +
  38 + private static final String UNION_NORMAL_TRANS_UNIONTYPE = "YH:BD:UNI:ALL:ORDER:";
  39 +
31 @Autowired 40 @Autowired
32 private RedisListCache redisListCache; 41 private RedisListCache redisListCache;
33 42
@@ -59,6 +68,7 @@ public class UnionOrderServiceImpl implements IUnionOrderService { @@ -59,6 +68,7 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
59 orderInfo.setOrdersGoods(ordersGoodList); 68 orderInfo.setOrdersGoods(ordersGoodList);
60 resList.add(orderInfo); 69 resList.add(orderInfo);
61 } 70 }
  71 + logger.info("Exit getUnionOrders: resList size is {}",resList.size());
62 return resList; 72 return resList;
63 73
64 }catch(Exception e){ 74 }catch(Exception e){
@@ -67,6 +77,53 @@ public class UnionOrderServiceImpl implements IUnionOrderService { @@ -67,6 +77,53 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
67 } 77 }
68 } 78 }
69 79
  80 + @Override
  81 + public List<TransInfo> getTrandInfo(UnionOrderReqVO req) {
  82 + logger.info("Enter getTrandInfo: request param is {}", req);
  83 + try {
  84 + List<TransInfo> resList = new ArrayList<TransInfo>();
  85 + Long size = redisListCache.size(UNION_TRAND);
  86 + int sizeInt = size == null ? 0 : size.intValue();
  87 + logger.info("getTrandInfo UNION_TRAND size is {}",size);
  88 + if (sizeInt > 0) {
  89 + for (int i = 0; i < size; i++) {
  90 + UnionTrans unionTrans = redisListCache.rightPop(UNION_TRAND, UnionTrans.class);
  91 + String union_type = unionTrans.getUnion_type();
  92 + //首单交寄
  93 + String firstOrder = UNION_TRANS_UNIONTYPE + union_type;
  94 + //普通交寄
  95 + String normalOrder = UNION_NORMAL_TRANS_UNIONTYPE + union_type;
  96 + List<UnionActivityTrans> firstOrderList = new ArrayList<>();
  97 + Long firstOrderSize = redisListCache.size(firstOrder);
  98 + Long normalOrderSize = redisListCache.size(normalOrder);
  99 + if (firstOrderSize > 0) {
  100 + for (int j = 0; j < firstOrderSize; j++) {
  101 + UnionActivityTrans unionActivityTrans = redisListCache.rightPop(firstOrder, UnionActivityTrans.class);
  102 + firstOrderList.add(unionActivityTrans);
  103 + }
  104 +
  105 + }
  106 + logger.info("getFirstOrderList: from bigdata redis: key is {}, result size is {}", firstOrder, firstOrderList == null ? 0 : firstOrderList.size());
  107 + List<UnionActivityTrans> normalOrderList = new ArrayList<>();
  108 + if (normalOrderSize > 0) {
  109 + for (int k = 0; k < normalOrderSize; k++) {
  110 + UnionActivityTrans unionActivityTrans = redisListCache.rightPop(normalOrder, UnionActivityTrans.class);
  111 + normalOrderList.add(unionActivityTrans);
  112 + }
  113 + }
  114 + logger.info("getNormalOrderList: from bigdata redis: key is {}, result size is {}", normalOrder, normalOrderList == null ? 0 : normalOrderList.size());
  115 + resList = this.convertTrans(resList,firstOrderList, normalOrderList);
  116 + }
  117 + }
  118 + logger.info("exit getTrandInfo result size is {}",resList.size());
  119 + return resList;
  120 +
  121 + } catch (Exception e) {
  122 + logger.warn("getTrandInfo: get orders from bigdata redis failed, error is {}", e.getMessage());
  123 + return null;
  124 + }
  125 + }
  126 +
70 private OrderInfo convertToUnionOrderBo(UnionOrders unionOrder){ 127 private OrderInfo convertToUnionOrderBo(UnionOrders unionOrder){
71 if(null == unionOrder){ 128 if(null == unionOrder){
72 return null; 129 return null;
@@ -114,4 +171,35 @@ public class UnionOrderServiceImpl implements IUnionOrderService { @@ -114,4 +171,35 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
114 return resList; 171 return resList;
115 } 172 }
116 173
  174 + private List<TransInfo> convertTrans(List<TransInfo> resList,List<UnionActivityTrans> firstOrderList,List<UnionActivityTrans> normalOrderList){
  175 + if(CollectionUtils.isEmpty(firstOrderList)&&CollectionUtils.isEmpty(normalOrderList)){
  176 + return null;
  177 + }
  178 +
  179 + if(CollectionUtils.isNotEmpty(firstOrderList)){
  180 + for(UnionActivityTrans unionActivityTrans:firstOrderList){
  181 + TransInfo transInfo = new TransInfo();
  182 + //首单设为1
  183 + transInfo.setType("1");
  184 + transInfo.setUdid(unionActivityTrans.getUdid());
  185 + transInfo.setOrderAmount(unionActivityTrans.getOrder_amount());
  186 + transInfo.setUid(unionActivityTrans.getUid());
  187 + transInfo.setOrdercode(unionActivityTrans.getOrder_code());
  188 + resList.add(transInfo);
  189 + }
  190 + }
  191 + if(CollectionUtils.isNotEmpty(normalOrderList)){
  192 + for(UnionActivityTrans unionActivityTran:normalOrderList){
  193 + TransInfo transInfo = new TransInfo();
  194 + //正常单设为2
  195 + transInfo.setType("2");
  196 + transInfo.setUdid(unionActivityTran.getUdid());
  197 + transInfo.setOrderAmount(unionActivityTran.getOrder_amount());
  198 + transInfo.setUid(unionActivityTran.getUid());
  199 + transInfo.setOrdercode(unionActivityTran.getOrder_code());
  200 + resList.add(transInfo);
  201 + }
  202 + }
  203 + return resList;
  204 + }
117 } 205 }
@@ -19,6 +19,7 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO; @@ -19,6 +19,7 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO;
19 import com.yoho.service.model.union.request.ClickUnionRequestBO; 19 import com.yoho.service.model.union.request.ClickUnionRequestBO;
20 import com.yoho.service.model.union.response.UnionResponse; 20 import com.yoho.service.model.union.response.UnionResponse;
21 import com.yoho.unions.common.enums.ClientTypeEnum; 21 import com.yoho.unions.common.enums.ClientTypeEnum;
  22 +import com.yoho.unions.common.redis.RedisListCache;
22 import com.yoho.unions.common.redis.RedisValueCache; 23 import com.yoho.unions.common.redis.RedisValueCache;
23 import com.yoho.unions.common.utils.DateUtil; 24 import com.yoho.unions.common.utils.DateUtil;
24 import com.yoho.unions.common.utils.HttpUtils; 25 import com.yoho.unions.common.utils.HttpUtils;
@@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory; @@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory;
34 import org.springframework.context.ApplicationEventPublisher; 35 import org.springframework.context.ApplicationEventPublisher;
35 import org.springframework.context.ApplicationEventPublisherAware; 36 import org.springframework.context.ApplicationEventPublisherAware;
36 import org.springframework.stereotype.Service; 37 import org.springframework.stereotype.Service;
  38 +
37 import javax.annotation.Resource; 39 import javax.annotation.Resource;
38 import java.net.URLDecoder; 40 import java.net.URLDecoder;
39 import java.util.List; 41 import java.util.List;
@@ -70,7 +72,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -70,7 +72,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
70 72
71 @Resource(name="yhValueOperations") 73 @Resource(name="yhValueOperations")
72 YHValueOperations<String, String> yhValueOperations; 74 YHValueOperations<String, String> yhValueOperations;
73 - 75 +
74 @Resource 76 @Resource
75 IUnionLogsDAO unionLogsDAO; 77 IUnionLogsDAO unionLogsDAO;
76 78
@@ -84,6 +86,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -84,6 +86,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
84 RedisValueCache redisValueCache; 86 RedisValueCache redisValueCache;
85 87
86 @Resource 88 @Resource
  89 + RedisListCache redisListCache;
  90 +
  91 + @Resource
87 IMktMarketingUrlDAO mktMarketingUrlDAO; 92 IMktMarketingUrlDAO mktMarketingUrlDAO;
88 93
89 @Resource 94 @Resource
@@ -93,6 +98,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -93,6 +98,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
93 IUnionActivityLogsDAO unionActivityLogsDAO; 98 IUnionActivityLogsDAO unionActivityLogsDAO;
94 99
95 @Resource 100 @Resource
  101 + IUnionActivityDAO unionActivityDAO;
  102 +
  103 + @Resource
96 IUnionTypeMatchDAO unionTypeMatchDAO; 104 IUnionTypeMatchDAO unionTypeMatchDAO;
97 105
98 @Resource(name="unionServiceImpl") 106 @Resource(name="unionServiceImpl")
@@ -182,25 +190,18 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -182,25 +190,18 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
182 yhValueOperations.set(key, JSON.toJSONString(request)); 190 yhValueOperations.set(key, JSON.toJSONString(request));
183 yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS); 191 yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS);
184 clickUnion.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request)); 192 clickUnion.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request));
185 -  
186 -// log.info("clickUnion set redis success with request={}", request);  
187 -  
188 -// if (union != null) {  
189 -// //如果90天以内,已经存在点击记录,则不需要插入或更新数据库  
190 -// log.info("clickUnion have click in 90 days with request={}", request);  
191 -// return new UnionResponse(); 193 +
  194 +// UnionActivityTrans unionActivityTrans = new UnionActivityTrans();
  195 +// List<UnionActivityTrans> list = new ArrayList<>();
  196 +// for(int i=0;i<3;i++){
  197 +// UnionActivityTrans unionActivityTrans = new UnionActivityTrans();
  198 +// unionActivityTrans.setOrdercode("123");
  199 +// unionActivityTrans.setUdid("234");
  200 +// unionActivityTrans.setOrderAmount(new BigDecimal(12));
  201 +// unionActivityTrans.setUid("12");
  202 +// list.add(unionActivityTrans);
192 // } 203 // }
193 - //保存信息到数据库  
194 -// UnionLogs logs = new UnionLogs();  
195 -// logs.setTd(request.getTd());  
196 -// logs.setAppId(request.getAppid());  
197 -// logs.setClientType(request.getClient_type());  
198 -// logs.setUnionType(Byte.valueOf(request.getUnion_type()));  
199 -// logs.setCreateTime(DateUtil.getCurrentTimeSecond());  
200 -// logs.setUpdateTime(logs.getCreateTime());  
201 -// logs.setAddParams(JSON.toJSONString(request));  
202 -// logs.setIsActivate(Byte.valueOf("0"));  
203 -// unionLogsDAO.insert(logs); 204 +// redisListCache.rightPushAll("UNION:KEY:123",list,activeTime.get(),TimeUnit.HOURS);
204 205
205 return new UnionResponse(); 206 return new UnionResponse();
206 } catch (Exception e) { 207 } catch (Exception e) {
@@ -216,25 +217,25 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -216,25 +217,25 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
216 // 检查输入参数 217 // 检查输入参数
217 if (StringUtils.isEmpty(request.getAppid())) { 218 if (StringUtils.isEmpty(request.getAppid())) {
218 log.warn("activateUnion error because appid is empty with param is {}", request); 219 log.warn("activateUnion error because appid is empty with param is {}", request);
219 - return new UnionResponse(201, "appid is empty"); 220 + return new UnionResponse(200, "appid is empty",new JSONObject());
220 } 221 }
221 if (StringUtils.isEmpty(request.getTd())) { 222 if (StringUtils.isEmpty(request.getTd())) {
222 log.warn("activateUnion error because td is empty with param is {}", request); 223 log.warn("activateUnion error because td is empty with param is {}", request);
223 - return new UnionResponse(201, "td is empty"); 224 + return new UnionResponse(200, "td is empty",new JSONObject());
224 } 225 }
225 if (StringUtils.isEmpty(request.getUdid())) { 226 if (StringUtils.isEmpty(request.getUdid())) {
226 log.warn("activateUnion error because udid is empty with param is {}", request); 227 log.warn("activateUnion error because udid is empty with param is {}", request);
227 - return new UnionResponse(201, "udid is empty"); 228 + return new UnionResponse(200, "udid is empty",new JSONObject());
228 } 229 }
229 230
230 if (ClientTypeEnum.IOS.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getIdfa())) { 231 if (ClientTypeEnum.IOS.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getIdfa())) {
231 log.warn("activateUnion error because idfa is empty with request is {}", request); 232 log.warn("activateUnion error because idfa is empty with request is {}", request);
232 - return new UnionResponse(201, "idfa is empty"); 233 + return new UnionResponse(200, "idfa is empty",new JSONObject());
233 } 234 }
234 235
235 if (ClientTypeEnum.ANDROID.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getImei())) { 236 if (ClientTypeEnum.ANDROID.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getImei())) {
236 log.warn("activateUnion error because imei is empty with request is {}", request); 237 log.warn("activateUnion error because imei is empty with request is {}", request);
237 - return new UnionResponse(201, "imei is empty"); 238 + return new UnionResponse(200, "imei is empty",new JSONObject());
238 } 239 }
239 240
240 try{ 241 try{
@@ -315,7 +316,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -315,7 +316,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
315 value = yhValueOperations.get(key); 316 value = yhValueOperations.get(key);
316 if(StringUtils.isNotEmpty(value)){ 317 if(StringUtils.isNotEmpty(value)){
317 ipMatch.info("activateUnion with IP params td is {},imei is {},idfa is {},IP is {},---- clickMsg is {}",request.getTd(),request.getImei(),request.getIdfa(),request.getClientIp(),value); 318 ipMatch.info("activateUnion with IP params td is {},imei is {},idfa is {},IP is {},---- clickMsg is {}",request.getTd(),request.getImei(),request.getIdfa(),request.getClientIp(),value);
318 - return new UnionResponse(204, "user not click"); 319 + return new UnionResponse(200, "user not click",new JSONObject());
319 } 320 }
320 321
321 } 322 }
@@ -326,7 +327,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -326,7 +327,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
326 // 如果redis中不存在存在该用户点击信息,则退出 327 // 如果redis中不存在存在该用户点击信息,则退出
327 if (StringUtils.isEmpty(value)) { 328 if (StringUtils.isEmpty(value)) {
328 log.warn("activateUnion error user not click info. with param is {}", request); 329 log.warn("activateUnion error user not click info. with param is {}", request);
329 - return new UnionResponse(204, "user not click"); 330 + return new UnionResponse(200, "user not click",new JSONObject());
330 } 331 }
331 332
332 // 把存储的字符串变为对象 333 // 把存储的字符串变为对象
@@ -348,17 +349,23 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -348,17 +349,23 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
348 //强制删除带ip的key 349 //强制删除带ip的key
349 yHRedisTemplate.delete(UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey()); 350 yHRedisTemplate.delete(UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey());
350 351
351 - if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {  
352 - // 如果90天之内有过激活日志,则不允许重复激活  
353 - log.warn("activateUnion error because 90 days has activate info with param is {}", request);  
354 - return new UnionResponse(203, "have activite in 90 days");  
355 - }  
356 String unionTypekey = "yh:union:uniontype:"+click.getUnion_type(); 352 String unionTypekey = "yh:union:uniontype:"+click.getUnion_type();
357 MktMarketingUrl mktMarketingUrl = redisValueCache.get(unionTypekey,MktMarketingUrl.class); 353 MktMarketingUrl mktMarketingUrl = redisValueCache.get(unionTypekey,MktMarketingUrl.class);
358 if(mktMarketingUrl==null){ 354 if(mktMarketingUrl==null){
359 mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(click.getUnion_type())); 355 mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(click.getUnion_type()));
360 redisValueCache.set(unionTypekey, mktMarketingUrl, 1, TimeUnit.HOURS); 356 redisValueCache.set(unionTypekey, mktMarketingUrl, 1, TimeUnit.HOURS);
361 } 357 }
  358 +
  359 + JSONObject result = new JSONObject();
  360 + result.put("landing_page_url",StringUtils.isEmpty(mktMarketingUrl.getLandingPageUrl()) ? "" : mktMarketingUrl.getLandingPageUrl());
  361 +
  362 + if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
  363 + // 如果90天之内有过激活日志,则不允许重复激活
  364 + log.warn("activateUnion error because 90 days has activate info with param is {}", request);
  365 + return new UnionResponse(200, "have activite in 90 days",result);
  366 + }
  367 +// UnionTypeModel u = UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
  368 +
362 UnionTypeModel u = new UnionTypeModel(); 369 UnionTypeModel u = new UnionTypeModel();
363 u.setName(mktMarketingUrl.getName()); 370 u.setName(mktMarketingUrl.getName());
364 u.setValue(String.valueOf(mktMarketingUrl.getUnionType())); 371 u.setValue(String.valueOf(mktMarketingUrl.getUnionType()));
@@ -406,7 +413,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -406,7 +413,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
406 j.put("tdid", request.getTdid()); 413 j.put("tdid", request.getTdid());
407 activeDingdang.info(j.toString()); 414 activeDingdang.info(j.toString());
408 } 415 }
409 - return new UnionResponse(203, "have activite in 90 days"); 416 + return new UnionResponse(200, "have activite in 90 days",result);
410 } 417 }
411 } 418 }
412 419
@@ -489,7 +496,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -489,7 +496,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
489 } 496 }
490 if (StringUtils.isEmpty(url)) { 497 if (StringUtils.isEmpty(url)) {
491 log.info("activateUnion in success request is {}", request); 498 log.info("activateUnion in success request is {}", request);
492 - return new UnionResponse(); 499 + return new UnionResponse(200,"success",result);
493 } 500 }
494 if(!"3".equals(union_type)||!"100000000000453".equals(union_type)){ 501 if(!"3".equals(union_type)||!"100000000000453".equals(union_type)){
495 url = URLDecoder.decode(url, "UTF-8"); 502 url = URLDecoder.decode(url, "UTF-8");
@@ -506,21 +513,26 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -506,21 +513,26 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
506 activeUnion.info("activateUnion call union success url={}, and result={}", url, pair); 513 activeUnion.info("activateUnion call union success url={}, and result={}", url, pair);
507 if (pair.getLeft() != 200) { 514 if (pair.getLeft() != 200) {
508 log.warn("callback error with request={}", request); 515 log.warn("callback error with request={}", request);
509 - return new UnionResponse(204, "callback error"); 516 + return new UnionResponse(200, "callback error",result);
  517 + }
  518 + //如果来源是广点通,则把广点通的一些信息记入表,给之后做转化上报使用
  519 + if(union_type.equals("3")){
  520 + saveUnionActivity(click,request);
510 } 521 }
  522 +
  523 +
511 } catch (Exception e) { 524 } catch (Exception e) {
512 log.error("callback error with request={}", request, e); 525 log.error("callback error with request={}", request, e);
513 //return new UnionResponse(204, "callback error"); 526 //return new UnionResponse(204, "callback error");
514 } 527 }
515 528
516 -  
517 activeUnion.info("activateUnion in success request is {}", request); 529 activeUnion.info("activateUnion in success request is {}", request);
518 -  
519 - return new UnionResponse(); 530 +
  531 + return new UnionResponse(200,"success",result);
520 532
521 } catch (Exception e) { 533 } catch (Exception e) {
522 log.error("activateUnion error with request={}", request, e); 534 log.error("activateUnion error with request={}", request, e);
523 - return new UnionResponse(300, e.getMessage()); 535 + return new UnionResponse(200, e.getMessage(),new JSONObject());
524 } 536 }
525 537
526 } 538 }
@@ -567,6 +579,30 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher @@ -567,6 +579,30 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
567 }); 579 });
568 } 580 }
569 581
  582 + private void saveUnionActivity(ClickUnionRequestBO click,ActivateUnionRequestBO request){
  583 + taskExecutor.execute(new Runnable(){
  584 + @Override
  585 + public void run()
  586 + {
  587 + UnionActivity unionActivity = new UnionActivity();
  588 + unionActivity.setClientType(request.getClient_type());
  589 + unionActivity.setUdid(request.getUdid());
  590 + if(StringUtils.isNotEmpty(click.getIdfa())){
  591 + unionActivity.setUdid(click.getIdfa());
  592 + }else {
  593 + unionActivity.setUdid(click.getImei());
  594 + }
  595 + unionActivity.setUnionType(click.getUnion_type());
  596 + //广点通的账号id存入的是click的commonUse字段
  597 + unionActivity.setAdvertiserId(click.getCommonUse());
  598 + //广点通点击id
  599 + unionActivity.setClickId(click.getClickId());
  600 + unionActivity.setCreateTime(DateUtil.getCurrentTimeSecond());
  601 + unionActivityDAO.insertSelective(unionActivity);
  602 + }
  603 + });
  604 + }
  605 +
570 @Override 606 @Override
571 public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { 607 public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
572 this.publisher = applicationEventPublisher; 608 this.publisher = applicationEventPublisher;
  1 +package com.yoho.unions.server.task;
  2 +
  3 +import com.yoho.service.model.union.response.UnionResponse;
  4 +import com.yoho.unions.common.enums.ClientTypeEnum;
  5 +import com.yoho.unions.common.utils.DateUtil;
  6 +import com.yoho.unions.common.utils.HttpUtils;
  7 +import com.yoho.unions.dal.IUnionActivityDAO;
  8 +import com.yoho.unions.dal.IUnionConfigDAO;
  9 +import com.yoho.unions.dal.model.UnionActivity;
  10 +import com.yoho.unions.dal.model.UnionConfig;
  11 +import com.yoho.unions.server.service.IUnionOrderService;
  12 +import com.yoho.core.common.utils.MD5;
  13 +import org.apache.commons.codec.binary.Base64;
  14 +import com.yoho.unions.vo.TransInfo;
  15 +import com.yoho.unions.vo.UnionOrderReqVO;
  16 +import org.apache.commons.collections.CollectionUtils;
  17 +import org.apache.commons.lang.StringUtils;
  18 +import org.apache.commons.lang3.tuple.Pair;
  19 +import org.slf4j.Logger;
  20 +import org.slf4j.LoggerFactory;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.scheduling.annotation.Scheduled;
  23 +import org.springframework.stereotype.Component;
  24 +
  25 +import javax.annotation.Resource;
  26 +import java.io.UnsupportedEncodingException;
  27 +import java.math.BigDecimal;
  28 +import java.net.URLEncoder;
  29 +import java.util.List;
  30 +
  31 +/**
  32 + * 广点通转化数据上报,定时从大数据抽取数据,然后联盟拼接,上报给广点通
  33 + * Created by yoho on 2017/2/22.
  34 + */
  35 +@Component
  36 +public class GdtTransTask {
  37 +
  38 + static Logger log = LoggerFactory.getLogger(GdtTransTask.class);
  39 +
  40 + @Autowired
  41 + private IUnionOrderService unionOrderService;
  42 +
  43 + @Resource
  44 + IUnionActivityDAO unionActivityDAO;
  45 +
  46 + @Resource
  47 + IUnionConfigDAO unionConfigDAO;
  48 +
  49 + @Scheduled(cron = "0 0/6 * * * ?")
  50 + public void run() {
  51 + UnionOrderReqVO reqVO = new UnionOrderReqVO();
  52 + reqVO.setLimit(10);
  53 + this.execute(reqVO);
  54 + }
  55 +
  56 + public void execute(UnionOrderReqVO reqVO){
  57 + //从大数据中取出联盟需要的广点通带来转化的设备号,和金额
  58 +
  59 + List<TransInfo> transInfoList = unionOrderService.getTrandInfo(reqVO);
  60 + if (CollectionUtils.isEmpty(transInfoList)) {
  61 + return;
  62 + }
  63 + //将取出来的数据进行拼接
  64 + for(TransInfo transInfo:transInfoList){
  65 + log.info("enter trans udid is {},ordercode is {}",transInfo.getUdid(),transInfo.getOrdercode());
  66 + String udid = transInfo.getUdid();
  67 + //利用udid去表中查出是两个广点通账号带来的
  68 + UnionActivity unionActivity = unionActivityDAO.selectByUdid(udid);
  69 +
  70 + if(unionActivity==null){
  71 + continue;
  72 + }
  73 + //按照广点通要求拼接数据
  74 + String url = urlEode(unionActivity,transInfo);
  75 + //改成httpclient方式调用
  76 + Pair<Integer, String> pair = HttpUtils.httpGet(url);
  77 + log.info("GdtTransTask call union success url={}, and result={}", url, pair);
  78 + if (pair.getLeft() != 200) {
  79 + log.warn("callback error with request={}", url);
  80 + }
  81 +
  82 + }
  83 + }
  84 +
  85 + public String urlEode(UnionActivity requestBO,TransInfo transInfo) {
  86 + log.info("enter GdtTransTask.urlEode requestBO is {}, transInfo is {} ", requestBO,transInfo);
  87 + // 根据不同的应用类型,获取不同的加密密钥和签名密钥
  88 + String encryptKey = "BAAAAAAAAAAABZJQ";
  89 + String signKey = "1461f1237d22dfc7";
  90 + String muid4MD5 = requestBO.getMuid();
  91 + String url = "http://t.gdt.qq.com/conv/app/";
  92 + //有货在智慧推的账号id
  93 + String uid = "365136";
  94 + if(StringUtils.isNotEmpty(requestBO.getAdvertiserId())){
  95 + uid = requestBO.getAdvertiserId();
  96 + }
  97 + String clientType = ClientTypeEnum.IOS.getName();
  98 + if(StringUtils.isNotEmpty(requestBO.getClientType())){
  99 + clientType = requestBO.getClientType().toLowerCase();
  100 + }
  101 + UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType);
  102 + if(null!=unionConfig){
  103 + encryptKey = unionConfig.getEncryptKey();
  104 + signKey = unionConfig.getSignKey();
  105 + url = unionConfig.getUrl();
  106 + }
  107 + //APPID可以固定根据clientType判断
  108 + String appId = "490655927";
  109 + if(clientType.equals(ClientTypeEnum.ANDROID.getName())){
  110 + appId = "100898104";
  111 + }
  112 + int conv_time = DateUtil.getCurrentTimeSecond();
  113 + String page = null;
  114 + String query_string = null;
  115 + String clickId = requestBO.getClickId();
  116 + StringBuffer bf = new StringBuffer();
  117 + StringBuffer sf = new StringBuffer();
  118 + page = bf.append(url).append(appId).append("/conv?click_id=").append(clickId).append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
  119 + query_string = sf.append("click_id=").append(clickId).append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&value=").append(transInfo.getOrderAmount().multiply(new BigDecimal(100))).toString();
  120 + log.info("enter GdtTransTask.urlEode page is {}",page);
  121 + log.info("enter GdtTransTask.urlEode query_string is {}",query_string);
  122 + // 对url进行加密
  123 + String encode_page = null;
  124 + try {
  125 + encode_page = URLEncoder.encode(page, "UTF-8");
  126 + log.info("activateZhiHuitui urlEncoder is{} ", encode_page);
  127 + } catch (UnsupportedEncodingException e) {
  128 + log.error("encode exception.", e);
  129 + }
  130 + // 将签名密钥和提交方式与加密后的url进行拼接
  131 + StringBuffer urlBuffer = new StringBuffer();
  132 +
  133 + String property = urlBuffer.append(signKey).append("&GET&").append(encode_page).toString();
  134 + String signature = MD5.md5(property);
  135 + StringBuffer base = new StringBuffer();
  136 + String base_data = base.append(query_string).append("&sign=").append(signature).toString();
  137 +
  138 + // 简单异或处理
  139 + String data = simpleXorByGdt(base_data, encryptKey);
  140 + // base64编码
  141 + String ret = Base64.encodeBase64String(data.getBytes());
  142 + // 64位处理之后,防止里面有换行符
  143 + String retRep = ret.replaceAll("\n", "");
  144 + // 将64位处理之后的值,按照url加密的方式进行加密
  145 + try {
  146 + retRep = URLEncoder.encode(retRep, "UTF-8");
  147 + log.info("activateUnion retRep is{}", retRep);
  148 + } catch (UnsupportedEncodingException e) {
  149 + log.error("encode exception.", e);
  150 + }
  151 + // conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE);
  152 + String convType = "MOBILEAPP_COST";
  153 + if(transInfo.getType().equals("1")){
  154 + convType = "MOBILEAPP_ADDTOCART";
  155 + }
  156 + StringBuffer sb = new StringBuffer();
  157 + url = sb.append(url).append(appId).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver(clientType)).append("&advertiser_id=").append(uid).toString();
  158 + log.info("GdtTransTask url is {}", url);
  159 + return url;
  160 + }
  161 +
  162 + /**
  163 + * 简单异或
  164 + *
  165 + * @param source
  166 + * @param key
  167 + * @return
  168 + */
  169 + private String simpleXorByGdt(String source, String key) {
  170 + String result = "";
  171 + int j = 0;
  172 + for (int i = 0; i < source.length(); i++) {
  173 + int c1 = source.charAt(i);
  174 + int c2 = key.charAt(j);
  175 +
  176 + result = result + (char) (c1 ^ c2);
  177 + j = j + 1;
  178 + j = j % (key.length());
  179 + }
  180 +
  181 + return result;
  182 + }
  183 +
  184 + private String clientTypeConver(String clientType) {
  185 + if (StringUtils.isEmpty(clientType)) {
  186 + return null;
  187 + }
  188 + if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType)) {
  189 + return clientType.toUpperCase();
  190 + } else {
  191 + return "IOS";
  192 + }
  193 +
  194 + }
  195 +}
@@ -42,5 +42,7 @@ datasources: @@ -42,5 +42,7 @@ datasources:
42 - com.yoho.unions.dal.IUnionTypeMatchDAO 42 - com.yoho.unions.dal.IUnionTypeMatchDAO
43 - com.yoho.unions.dal.ITencentMktActivityDAO 43 - com.yoho.unions.dal.ITencentMktActivityDAO
44 - com.yoho.unions.dal.ITencentMktCouponHistoryDAO 44 - com.yoho.unions.dal.ITencentMktCouponHistoryDAO
  45 + - com.yoho.unions.dal.IUnionActivityDAO
  46 + - com.yoho.unions.dal.IUnionConfigDAO
45 47
46 readOnlyInSlave: true 48 readOnlyInSlave: true
@@ -43,5 +43,7 @@ datasources: @@ -43,5 +43,7 @@ datasources:
43 - com.yoho.unions.dal.IUnionTypeMatchDAO 43 - com.yoho.unions.dal.IUnionTypeMatchDAO
44 - com.yoho.unions.dal.ITencentMktActivityDAO 44 - com.yoho.unions.dal.ITencentMktActivityDAO
45 - com.yoho.unions.dal.ITencentMktCouponHistoryDAO 45 - com.yoho.unions.dal.ITencentMktCouponHistoryDAO
  46 + - com.yoho.unions.dal.IUnionActivityDAO
  47 + - com.yoho.unions.dal.IUnionConfigDAO
46 48
47 readOnlyInSlave: true 49 readOnlyInSlave: true
1 package com.test; 1 package com.test;
2 2
3 import java.io.UnsupportedEncodingException; 3 import java.io.UnsupportedEncodingException;
  4 +import java.math.BigDecimal;
4 import java.net.URLDecoder; 5 import java.net.URLDecoder;
5 import java.net.URLEncoder; 6 import java.net.URLEncoder;
6 7
@@ -30,7 +31,7 @@ public class Test { @@ -30,7 +31,7 @@ public class Test {
30 String encryptKey = "test_encrypt_key"; 31 String encryptKey = "test_encrypt_key";
31 String signKey = "test_sign_key"; 32 String signKey = "test_sign_key";
32 String muid4MD5 = "0f074dc8e1f0547310e729032ac0730b"; 33 String muid4MD5 = "0f074dc8e1f0547310e729032ac0730b";
33 - String url = "http://jump.t.l.qq.com/conv/app/"; 34 + String url = "http://t.gdt.qq.com/conv/app/";
34 //有货在智慧推的账号id 35 //有货在智慧推的账号id
35 String uid = "18261"; 36 String uid = "18261";
36 37
@@ -40,20 +41,33 @@ public class Test { @@ -40,20 +41,33 @@ public class Test {
40 // clientType = requestBO.getClient_type().toLowerCase(); 41 // clientType = requestBO.getClient_type().toLowerCase();
41 // } 42 // }
42 43
43 - String client_ip = "10.11.12.13"; 44 +// if(org.apache.commons.lang.StringUtils.isNotEmpty(requestBO.getAdvertiserId())){
  45 +// uid = requestBO.getAdvertiserId();
  46 +// }
  47 +// String clientType = ClientTypeEnum.IOS.getName();
  48 +// if(org.apache.commons.lang.StringUtils.isNotEmpty(requestBO.getClientType())){
  49 +// clientType = requestBO.getClientType().toLowerCase();
  50 +// }
  51 +// UnionConfig unionConfig = unionConfigDAO.selectByUidAndClientType(Integer.valueOf(uid),clientType);
  52 +// if(null!=unionConfig){
  53 +// encryptKey = unionConfig.getEncryptKey();
  54 +// signKey = unionConfig.getSignKey();
  55 +// url = unionConfig.getUrl();
  56 +// }
  57 + //APPID可以固定根据clientType判断
44 String appId = "112233"; 58 String appId = "112233";
45 - int conv_time =1422263664; 59 + if(clientType.equals(ClientTypeEnum.ANDROID.getName())){
  60 + appId = "112233";
  61 + }
  62 + int conv_time = DateUtil.getCurrentTimeSecond();
46 String page = null; 63 String page = null;
47 String query_string = null; 64 String query_string = null;
48 StringBuffer bf = new StringBuffer(); 65 StringBuffer bf = new StringBuffer();
49 StringBuffer sf = new StringBuffer(); 66 StringBuffer sf = new StringBuffer();
50 - if (StringUtils.isEmpty(client_ip)){  
51 - page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).toString();  
52 - query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).toString();  
53 - }else{  
54 - page = bf.append(url).append(appId).append("/conv?muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();  
55 - query_string = sf.append("muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=").append(client_ip).toString();  
56 - } 67 +
  68 + page = bf.append(url).append(appId).append("/conv?click_id=").append("007210548a030059ccdfd1d4").append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=10.11.12.13").toString();
  69 + query_string = sf.append("click_id=").append("007210548a030059ccdfd1d4").append("&muid=").append(muid4MD5).append("&conv_time=").append(conv_time).append("&client_ip=10.11.12.13").toString();
  70 +
57 // 对url进行加密 71 // 对url进行加密
58 String encode_page = null; 72 String encode_page = null;
59 try { 73 try {
@@ -84,11 +98,15 @@ public class Test { @@ -84,11 +98,15 @@ public class Test {
84 log.error("encode exception.", e); 98 log.error("encode exception.", e);
85 } 99 }
86 // conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE); 100 // conv_type,,现在只有移动应用激活类型(MOBILEAPP_ACTIVITE);
87 - String convType = "MOBILE_APP_ACTIVITE"; 101 + String convType = "MOBILEAPP_COST";
  102 +// if(transInfo.getType().equals("1")){
  103 +// convType = "MOBILEAPP_ADDTOCART";
  104 +// }
88 StringBuffer sb = new StringBuffer(); 105 StringBuffer sb = new StringBuffer();
89 - url = sb.append(url).append(112233).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver("Android")).append("&advertiser_id=").append(uid).toString();  
90 - log.info("zhihuitui url is {}", url);  
91 - System.out.print(url); 106 + url = sb.append(url).append(appId).append("/conv?v=").append(retRep).append("&conv_type=").append(convType).append("&app_type=").append(clientTypeConver(clientType)).append("&advertiser_id=").append(uid).toString();
  107 + log.info("GdtTransTask url is {}", url);
  108 + String md5 = MD5.md5("862380036648114");
  109 + System.out.print(md5);
92 } 110 }
93 111
94 private static String clientTypeConver(String clientType) { 112 private static String clientTypeConver(String clientType) {