Authored by zhengwen.ge

update

@@ -25,6 +25,23 @@ public class DateUtil { @@ -25,6 +25,23 @@ public class DateUtil {
25 return dateStr; 25 return dateStr;
26 } 26 }
27 27
  28 + /**
  29 + * 时间戳转换成日期格式字符串
  30 + * @param time 精确到秒的字符串
  31 + * @param formatStr
  32 + * @return
  33 + */
  34 + public static String timeStamp2Date(String time,String format){
  35 + if(time == null || time.isEmpty() || time.equals("null")){
  36 + return "";
  37 + }
  38 + if(format == null || format.isEmpty()){
  39 + format = "yyyy-MM-dd HH:mm:ss";
  40 + }
  41 + SimpleDateFormat sdf = new SimpleDateFormat(format);
  42 + return sdf.format(new Date(Long.valueOf(time+"000")));
  43 + }
  44 +
28 public static void main(String[] ars){ 45 public static void main(String[] ars){
29 String s = DateUtil.long2DateStr(1449134435000L, "yyyy-MM-dd"); 46 String s = DateUtil.long2DateStr(1449134435000L, "yyyy-MM-dd");
30 System.out.print(s); 47 System.out.print(s);
@@ -250,5 +267,6 @@ public class DateUtil { @@ -250,5 +267,6 @@ public class DateUtil {
250 Long millsec = calendar.getTimeInMillis() - 1000; 267 Long millsec = calendar.getTimeInMillis() - 1000;
251 return (int)(millsec/1000); 268 return (int)(millsec/1000);
252 } 269 }
  270 +
253 271
254 } 272 }
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 <value>/go</value> 29 <value>/go</value>
30 <value>/pushUnionOrders</value> 30 <value>/pushUnionOrders</value>
31 <value>/ClickUnionRest/addUnion4Jump</value> 31 <value>/ClickUnionRest/addUnion4Jump</value>
  32 + <value>/UnionRest/addBigData</value>
32 </list> 33 </list>
33 </property> 34 </property>
34 <property name="excludeMethods"> 35 <property name="excludeMethods">
@@ -2,6 +2,9 @@ package com.yoho.unions.dal; @@ -2,6 +2,9 @@ package com.yoho.unions.dal;
2 2
3 3
4 import com.yoho.unions.dal.model.UnionActivityLogs; 4 import com.yoho.unions.dal.model.UnionActivityLogs;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
5 8
6 public interface IUnionActivityLogsDAO { 9 public interface IUnionActivityLogsDAO {
7 int deleteByPrimaryKey(Integer id); 10 int deleteByPrimaryKey(Integer id);
@@ -15,4 +18,6 @@ public interface IUnionActivityLogsDAO { @@ -15,4 +18,6 @@ public interface IUnionActivityLogsDAO {
15 int updateByPrimaryKeySelective(UnionActivityLogs record); 18 int updateByPrimaryKeySelective(UnionActivityLogs record);
16 19
17 int updateByPrimaryKey(UnionActivityLogs record); 20 int updateByPrimaryKey(UnionActivityLogs record);
  21 +
  22 + List<UnionActivityLogs> selectByTime(@Param("beginTime")int beginTime,@Param("endTime")int endTime);
18 } 23 }
@@ -2,6 +2,7 @@ package com.yoho.unions.dal; @@ -2,6 +2,7 @@ package com.yoho.unions.dal;
2 2
3 3
4 import com.yoho.unions.dal.model.UnionClickLogs; 4 import com.yoho.unions.dal.model.UnionClickLogs;
  5 +import org.apache.ibatis.annotations.Param;
5 6
6 public interface IUnionClickLogsDAO { 7 public interface IUnionClickLogsDAO {
7 int deleteByPrimaryKey(Integer id); 8 int deleteByPrimaryKey(Integer id);
@@ -12,7 +13,11 @@ public interface IUnionClickLogsDAO { @@ -12,7 +13,11 @@ public interface IUnionClickLogsDAO {
12 13
13 UnionClickLogs selectByPrimaryKey(Integer id); 14 UnionClickLogs selectByPrimaryKey(Integer id);
14 15
15 - int updateByPrimaryKeySelective(UnionClickLogs record);  
16 -  
17 int updateByPrimaryKey(UnionClickLogs record); 16 int updateByPrimaryKey(UnionClickLogs record);
  17 +
  18 + UnionClickLogs selectByIdfa(@Param("idfa") String idfa,@Param("beginTime") int beginTime,@Param("endTime") int endTime);
  19 +
  20 + UnionClickLogs selectByImei(@Param("imei") String imei,@Param("beginTime") int beginTime,@Param("endTime") int endTime);
  21 +
  22 + UnionClickLogs selectByTDandIP(@Param("td") String td,@Param("clientIp")String clientIp,@Param("beginTime") int beginTime,@Param("endTime") int endTime);
18 } 23 }
@@ -161,4 +161,9 @@ @@ -161,4 +161,9 @@
161 client_ip = #{clientIp,jdbcType=VARCHAR} 161 client_ip = #{clientIp,jdbcType=VARCHAR}
162 where id = #{id,jdbcType=INTEGER} 162 where id = #{id,jdbcType=INTEGER}
163 </update> 163 </update>
  164 + <select id="selectByTime" resultMap="BaseResultMap">
  165 + select
  166 + <include refid="Base_Column_List" />
  167 + from union_activity_logs where create_time &gt; #{beginTime} and create_time &lt;#{endTime} and app_key = 'yohobuy'
  168 + </select>
164 </mapper> 169 </mapper>
@@ -103,39 +103,22 @@ @@ -103,39 +103,22 @@
103 </if> 103 </if>
104 </trim> 104 </trim>
105 </insert> 105 </insert>
106 - <update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionClickLogs" >  
107 - update union_click_logs  
108 - <set >  
109 - <if test="appId != null" >  
110 - app_id = #{appId,jdbcType=VARCHAR},  
111 - </if>  
112 - <if test="idfa != null" >  
113 - idfa = #{idfa,jdbcType=VARCHAR},  
114 - </if>  
115 - <if test="imei != null" >  
116 - imei = #{imei,jdbcType=VARCHAR},  
117 - </if>  
118 - <if test="unionType != null" >  
119 - union_type = #{unionType,jdbcType=VARCHAR},  
120 - </if>  
121 - <if test="createTime != null" >  
122 - create_time = #{createTime,jdbcType=INTEGER},  
123 - </if>  
124 - <if test="clientType != null" >  
125 - client_type = #{clientType,jdbcType=VARCHAR},  
126 - </if>  
127 - <if test="td != null" >  
128 - td = #{td,jdbcType=VARCHAR},  
129 - </if>  
130 - <if test="appKey != null" >  
131 - app_key = #{appKey,jdbcType=VARCHAR},  
132 - </if>  
133 - <if test="clientIp != null" >  
134 - client_ip = #{clientIp,jdbcType=VARCHAR},  
135 - </if>  
136 - </set>  
137 - where id = #{id,jdbcType=INTEGER}  
138 - </update> 106 + <select id="selectByIdfa" resultMap="BaseResultMap">
  107 + select <include refid="Base_Column_List" /> from
  108 + union_click_logs where idfa = #{idfa} and create_time &gt; #{beginTime} and create_time &lt;#{endTime} limit 1
  109 + </select>
  110 +
  111 + <select id="selectByImei" resultMap="BaseResultMap">
  112 + select <include refid="Base_Column_List" /> from
  113 + union_click_logs where imei = #{imei} and create_time &gt; #{beginTime} and create_time &lt;#{endTime} limit 1
  114 + </select>
  115 +
  116 + <select id="selectByTDandIP" resultMap="BaseResultMap">
  117 + select <include refid="Base_Column_List"/> from
  118 + union_click_logs where td = #{td} and client_ip = #{clientIp} and create_time &gt; #{beginTime} and create_time &lt;#{endTime} limit 1
  119 +
  120 + </select>
  121 +
139 <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionClickLogs" > 122 <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionClickLogs" >
140 update union_click_logs 123 update union_click_logs
141 set app_id = #{appId,jdbcType=VARCHAR}, 124 set app_id = #{appId,jdbcType=VARCHAR},
@@ -84,7 +84,15 @@ public class UnionRest { @@ -84,7 +84,15 @@ public class UnionRest {
84 response.setIsSuccess(true); 84 response.setIsSuccess(true);
85 return response; 85 return response;
86 } 86 }
87 - 87 +
  88 + @RequestMapping(value ="/addBigData")
  89 + @ResponseBody
  90 + public UnionResponseBO addBigData() {
  91 + log.info("enter addBigData");
  92 + UnionResponseBO response = dingdangService.addBigData();
  93 + return response;
  94 + }
  95 +
88 public static void main(String[] args) { 96 public static void main(String[] args) {
89 String clientId = "80003419"; 97 String clientId = "80003419";
90 if(clientId.startsWith("800")){ 98 if(clientId.startsWith("800")){
@@ -26,4 +26,6 @@ public interface DingdangService { @@ -26,4 +26,6 @@ public interface DingdangService {
26 * @throws Exception 26 * @throws Exception
27 */ 27 */
28 public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws Exception; 28 public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws Exception;
  29 +
  30 + UnionResponseBO addBigData();
29 } 31 }
@@ -2,6 +2,13 @@ package com.yoho.unions.server.service.impl; @@ -2,6 +2,13 @@ package com.yoho.unions.server.service.impl;
2 2
3 import javax.annotation.Resource; 3 import javax.annotation.Resource;
4 4
  5 +import com.yoho.unions.common.redis.RedisValueCache;
  6 +import com.yoho.unions.dal.IMktMarketingUrlDAO;
  7 +import com.yoho.unions.dal.IUnionActivityLogsDAO;
  8 +import com.yoho.unions.dal.IUnionClickLogsDAO;
  9 +import com.yoho.unions.dal.model.MktMarketingUrl;
  10 +import com.yoho.unions.dal.model.UnionActivityLogs;
  11 +import com.yoho.unions.dal.model.UnionClickLogs;
5 import org.apache.commons.lang.StringUtils; 12 import org.apache.commons.lang.StringUtils;
6 import org.apache.commons.lang3.tuple.Pair; 13 import org.apache.commons.lang3.tuple.Pair;
7 import org.apache.http.HttpStatus; 14 import org.apache.http.HttpStatus;
@@ -23,6 +30,9 @@ import com.yoho.unions.dal.IUnionsActiveRecordDAO; @@ -23,6 +30,9 @@ import com.yoho.unions.dal.IUnionsActiveRecordDAO;
23 import com.yoho.unions.dal.model.UnionsActiveRecord; 30 import com.yoho.unions.dal.model.UnionsActiveRecord;
24 import com.yoho.unions.server.service.DingdangService; 31 import com.yoho.unions.server.service.DingdangService;
25 32
  33 +import java.util.List;
  34 +import java.util.concurrent.TimeUnit;
  35 +
26 @Service 36 @Service
27 public class DingdangServiceImpl implements DingdangService { 37 public class DingdangServiceImpl implements DingdangService {
28 38
@@ -36,6 +46,18 @@ public class DingdangServiceImpl implements DingdangService { @@ -36,6 +46,18 @@ public class DingdangServiceImpl implements DingdangService {
36 46
37 @Resource 47 @Resource
38 IUnionsActiveRecordDAO unionsActiveRecordDAO; 48 IUnionsActiveRecordDAO unionsActiveRecordDAO;
  49 +
  50 + @Resource
  51 + IUnionActivityLogsDAO unionActivityLogsDAO;
  52 +
  53 + @Resource
  54 + IUnionClickLogsDAO unionClickLogsDAO;
  55 +
  56 + @Resource
  57 + RedisValueCache redisValueCache;
  58 +
  59 + @Resource
  60 + IMktMarketingUrlDAO mktMarketingUrlDAO;
39 61
40 private static final String unions_KEY = "yh:unions:dingdang_"; 62 private static final String unions_KEY = "yh:unions:dingdang_";
41 63
@@ -215,4 +237,91 @@ public class DingdangServiceImpl implements DingdangService { @@ -215,4 +237,91 @@ public class DingdangServiceImpl implements DingdangService {
215 return bo; 237 return bo;
216 } 238 }
217 239
  240 + @Override
  241 + public UnionResponseBO addBigData(){
  242 + int beginTime = 1486339800;
  243 + int endTime = 1486366200;
  244 + try{
  245 + List<UnionActivityLogs> unionActivityLogsList = unionActivityLogsDAO.selectByTime(beginTime,endTime);
  246 + for(UnionActivityLogs unionActivityLogs:unionActivityLogsList){
  247 + String idfa = unionActivityLogs.getIdfa();
  248 + String imei = unionActivityLogs.getImei();
  249 + int createTime = unionActivityLogs.getCreateTime();
  250 + UnionClickLogs unionClickLogs = null;
  251 + if(StringUtils.isNotEmpty(idfa)){
  252 + unionClickLogs = unionClickLogsDAO.selectByIdfa(idfa,beginTime,createTime);
  253 + }else{
  254 + unionClickLogs = unionClickLogsDAO.selectByImei(imei,beginTime,endTime);
  255 + }
  256 + //如果依然为空,则用td+IP的形式去匹配
  257 + String td = unionActivityLogs.getTd();
  258 + String ip = unionActivityLogs.getClientIp();
  259 + if(null == unionClickLogs){
  260 + unionClickLogs = unionClickLogsDAO.selectByTDandIP(td,ip,beginTime,endTime);
  261 + if(null == unionClickLogs){
  262 + //如果依然为空,则td截取一下
  263 + String[] arr = td.split("_");
  264 + if (arr.length > 3) {
  265 + td = (arr[2] + "_" + arr[3]);
  266 + unionClickLogs = unionClickLogsDAO.selectByTDandIP(td,ip,beginTime,endTime);
  267 + }
  268 + if(unionClickLogs == null){
  269 + if(arr.length==3){
  270 + td = (arr[1]+"_"+arr[2]);
  271 + unionClickLogs = unionClickLogsDAO.selectByTDandIP(td,ip,beginTime,endTime);
  272 + }
  273 + }
  274 + }
  275 +
  276 + }
  277 +
  278 + //如果能找到对应的unionClickLogs,则记录大数据的日志
  279 + if(unionClickLogs!=null){
  280 + // 记录日志
  281 + JSONObject j = new JSONObject();
  282 + String dateid = DateUtil.timeStamp2Date(String.valueOf(createTime), "yyyy-MM-dd HH:mm:ss");
  283 + String unionType = unionClickLogs.getUnionType();
  284 + String unionTypekey = "yh:union:uniontype:"+unionType;
  285 + MktMarketingUrl mktMarketingUrl = redisValueCache.get(unionTypekey,MktMarketingUrl.class);
  286 + if(mktMarketingUrl==null){
  287 + mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(unionType));
  288 + redisValueCache.set(unionTypekey,mktMarketingUrl,1, TimeUnit.HOURS);
  289 + }
  290 + String clientType = null;
  291 + if(StringUtils.isNotEmpty(unionActivityLogs.getIdfa())){
  292 + clientType = "ios";
  293 + }else{
  294 + clientType = "android";
  295 + }
  296 + j.put("apptype", clientType);
  297 + j.put("appid", unionActivityLogs.getAppId());
  298 + j.put("idfa", unionActivityLogs.getIdfa());
  299 + j.put("imei", unionActivityLogs.getImei());
  300 + j.put("udid", unionActivityLogs.getUdid());
  301 + j.put("dateid", dateid);
  302 + j.put("source", mktMarketingUrl == null ? "" : mktMarketingUrl.getName());
  303 + j.put("source_id",unionClickLogs.getUnionType());
  304 + j.put("ip", unionActivityLogs.getClientIp());
  305 + j.put("collect_ip", "");
  306 + j.put("app_key", unionActivityLogs.getAppKey());
  307 + j.put("active_type", "90");
  308 + j.put("tdid", "");
  309 + //打印90天的大数据日志
  310 + activeDingdang.info(j.toString());
  311 +
  312 + j.put("active_type", "15");
  313 + //打印15天的大数据日志
  314 + activeDingdang.info(j.toString());
  315 + }
  316 +
  317 + }
  318 + }catch (Exception e){
  319 + log.error("addBigData exception is ",e.getMessage());
  320 + }
  321 + UnionResponseBO response = new UnionResponseBO();
  322 + response.setMsg("success");
  323 + response.setIsSuccess(true);
  324 + return response;
  325 + }
  326 +
218 } 327 }
1 package com.test; 1 package com.test;
2 2
3 3
  4 +import com.yoho.unions.common.utils.DateUtil;
  5 +
4 import java.net.URLDecoder; 6 import java.net.URLDecoder;
  7 +import java.text.SimpleDateFormat;
  8 +import java.util.Date;
5 9
6 /** 10 /**
7 * Created by yoho on 2016/12/20. 11 * Created by yoho on 2016/12/20.
@@ -9,20 +13,26 @@ import java.net.URLDecoder; @@ -9,20 +13,26 @@ import java.net.URLDecoder;
9 public class DuomaiTest { 13 public class DuomaiTest {
10 14
11 public static void main(String args[]){ 15 public static void main(String args[]){
12 - String agent= "momochat/7.5.6 ios/664 (iphone 6; ios 10.2; zh_cn; iphone7,2; s1)";  
13 - String encode = "%e5%a6%82%e6%87%bf%e4%bc%a0/1.6 cfnetwork/808.2.16 darwin/16.3.0";  
14 - String decode = null;  
15 - try{  
16 - decode = URLDecoder.decode(encode,"utf-8");  
17 - }catch (Exception e){  
18 -  
19 - }  
20 - System.out.print(decode);  
21 - int first = agent.indexOf(" ios ")+4;  
22 - String version1 = agent.substring(first);  
23 - String version = version1.substring(version1.indexOf(" ")+1, version1.indexOf(";"));  
24 - System.out.print(version);  
25 - 16 + String createTime = "1486339819";
  17 + String dateId =timeStamp2Date(createTime, "yyyy-MM-dd HH:mm:ss");
  18 + System.out.print(dateId);
26 } 19 }
27 20
  21 + /**
  22 + * 时间戳转换成日期格式字符串
  23 + * @param seconds 精确到秒的字符串
  24 + * @param formatStr
  25 + * @return
  26 + */
  27 + public static String timeStamp2Date(String seconds,String format) {
  28 + if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
  29 + return "";
  30 + }
  31 + if(format == null || format.isEmpty()){
  32 + format = "yyyy-MM-dd HH:mm:ss";
  33 + }
  34 + SimpleDateFormat sdf = new SimpleDateFormat(format);
  35 + return sdf.format(new Date(Long.valueOf(seconds+"000")));
  36 + }
  37 +
28 } 38 }