Authored by zhengwen.ge

update

... ... @@ -25,6 +25,23 @@ public class DateUtil {
return dateStr;
}
/**
* 时间戳转换成日期格式字符串
* @param time 精确到秒的字符串
* @param formatStr
* @return
*/
public static String timeStamp2Date(String time,String format){
if(time == null || time.isEmpty() || time.equals("null")){
return "";
}
if(format == null || format.isEmpty()){
format = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(time+"000")));
}
public static void main(String[] ars){
String s = DateUtil.long2DateStr(1449134435000L, "yyyy-MM-dd");
System.out.print(s);
... ... @@ -250,5 +267,6 @@ public class DateUtil {
Long millsec = calendar.getTimeInMillis() - 1000;
return (int)(millsec/1000);
}
}
... ...
... ... @@ -29,6 +29,7 @@
<value>/go</value>
<value>/pushUnionOrders</value>
<value>/ClickUnionRest/addUnion4Jump</value>
<value>/UnionRest/addBigData</value>
</list>
</property>
<property name="excludeMethods">
... ...
... ... @@ -2,6 +2,9 @@ package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionActivityLogs;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface IUnionActivityLogsDAO {
int deleteByPrimaryKey(Integer id);
... ... @@ -15,4 +18,6 @@ public interface IUnionActivityLogsDAO {
int updateByPrimaryKeySelective(UnionActivityLogs record);
int updateByPrimaryKey(UnionActivityLogs record);
List<UnionActivityLogs> selectByTime(@Param("beginTime")int beginTime,@Param("endTime")int endTime);
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionClickLogs;
import org.apache.ibatis.annotations.Param;
public interface IUnionClickLogsDAO {
int deleteByPrimaryKey(Integer id);
... ... @@ -12,7 +13,11 @@ public interface IUnionClickLogsDAO {
UnionClickLogs selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(UnionClickLogs record);
int updateByPrimaryKey(UnionClickLogs record);
UnionClickLogs selectByIdfa(@Param("idfa") String idfa,@Param("beginTime") int beginTime,@Param("endTime") int endTime);
UnionClickLogs selectByImei(@Param("imei") String imei,@Param("beginTime") int beginTime,@Param("endTime") int endTime);
UnionClickLogs selectByTDandIP(@Param("td") String td,@Param("clientIp")String clientIp,@Param("beginTime") int beginTime,@Param("endTime") int endTime);
}
\ No newline at end of file
... ...
... ... @@ -161,4 +161,9 @@
client_ip = #{clientIp,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByTime" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from union_activity_logs where create_time &gt; #{beginTime} and create_time &lt;#{endTime} and app_key = 'yohobuy'
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -103,39 +103,22 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionClickLogs" >
update union_click_logs
<set >
<if test="appId != null" >
app_id = #{appId,jdbcType=VARCHAR},
</if>
<if test="idfa != null" >
idfa = #{idfa,jdbcType=VARCHAR},
</if>
<if test="imei != null" >
imei = #{imei,jdbcType=VARCHAR},
</if>
<if test="unionType != null" >
union_type = #{unionType,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="clientType != null" >
client_type = #{clientType,jdbcType=VARCHAR},
</if>
<if test="td != null" >
td = #{td,jdbcType=VARCHAR},
</if>
<if test="appKey != null" >
app_key = #{appKey,jdbcType=VARCHAR},
</if>
<if test="clientIp != null" >
client_ip = #{clientIp,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByIdfa" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from
union_click_logs where idfa = #{idfa} and create_time &gt; #{beginTime} and create_time &lt;#{endTime} limit 1
</select>
<select id="selectByImei" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from
union_click_logs where imei = #{imei} and create_time &gt; #{beginTime} and create_time &lt;#{endTime} limit 1
</select>
<select id="selectByTDandIP" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from
union_click_logs where td = #{td} and client_ip = #{clientIp} and create_time &gt; #{beginTime} and create_time &lt;#{endTime} limit 1
</select>
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionClickLogs" >
update union_click_logs
set app_id = #{appId,jdbcType=VARCHAR},
... ...
... ... @@ -84,7 +84,15 @@ public class UnionRest {
response.setIsSuccess(true);
return response;
}
@RequestMapping(value ="/addBigData")
@ResponseBody
public UnionResponseBO addBigData() {
log.info("enter addBigData");
UnionResponseBO response = dingdangService.addBigData();
return response;
}
public static void main(String[] args) {
String clientId = "80003419";
if(clientId.startsWith("800")){
... ...
... ... @@ -26,4 +26,6 @@ public interface DingdangService {
* @throws Exception
*/
public UnionResponseBO activeUnion(ActiveUnionRequestBO request) throws Exception;
UnionResponseBO addBigData();
}
... ...
... ... @@ -2,6 +2,13 @@ package com.yoho.unions.server.service.impl;
import javax.annotation.Resource;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.dal.IMktMarketingUrlDAO;
import com.yoho.unions.dal.IUnionActivityLogsDAO;
import com.yoho.unions.dal.IUnionClickLogsDAO;
import com.yoho.unions.dal.model.MktMarketingUrl;
import com.yoho.unions.dal.model.UnionActivityLogs;
import com.yoho.unions.dal.model.UnionClickLogs;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.HttpStatus;
... ... @@ -23,6 +30,9 @@ import com.yoho.unions.dal.IUnionsActiveRecordDAO;
import com.yoho.unions.dal.model.UnionsActiveRecord;
import com.yoho.unions.server.service.DingdangService;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
public class DingdangServiceImpl implements DingdangService {
... ... @@ -36,6 +46,18 @@ public class DingdangServiceImpl implements DingdangService {
@Resource
IUnionsActiveRecordDAO unionsActiveRecordDAO;
@Resource
IUnionActivityLogsDAO unionActivityLogsDAO;
@Resource
IUnionClickLogsDAO unionClickLogsDAO;
@Resource
RedisValueCache redisValueCache;
@Resource
IMktMarketingUrlDAO mktMarketingUrlDAO;
private static final String unions_KEY = "yh:unions:dingdang_";
... ... @@ -215,4 +237,91 @@ public class DingdangServiceImpl implements DingdangService {
return bo;
}
@Override
public UnionResponseBO addBigData(){
int beginTime = 1486339800;
int endTime = 1486366200;
try{
List<UnionActivityLogs> unionActivityLogsList = unionActivityLogsDAO.selectByTime(beginTime,endTime);
for(UnionActivityLogs unionActivityLogs:unionActivityLogsList){
String idfa = unionActivityLogs.getIdfa();
String imei = unionActivityLogs.getImei();
int createTime = unionActivityLogs.getCreateTime();
UnionClickLogs unionClickLogs = null;
if(StringUtils.isNotEmpty(idfa)){
unionClickLogs = unionClickLogsDAO.selectByIdfa(idfa,beginTime,createTime);
}else{
unionClickLogs = unionClickLogsDAO.selectByImei(imei,beginTime,endTime);
}
//如果依然为空,则用td+IP的形式去匹配
String td = unionActivityLogs.getTd();
String ip = unionActivityLogs.getClientIp();
if(null == unionClickLogs){
unionClickLogs = unionClickLogsDAO.selectByTDandIP(td,ip,beginTime,endTime);
if(null == unionClickLogs){
//如果依然为空,则td截取一下
String[] arr = td.split("_");
if (arr.length > 3) {
td = (arr[2] + "_" + arr[3]);
unionClickLogs = unionClickLogsDAO.selectByTDandIP(td,ip,beginTime,endTime);
}
if(unionClickLogs == null){
if(arr.length==3){
td = (arr[1]+"_"+arr[2]);
unionClickLogs = unionClickLogsDAO.selectByTDandIP(td,ip,beginTime,endTime);
}
}
}
}
//如果能找到对应的unionClickLogs,则记录大数据的日志
if(unionClickLogs!=null){
// 记录日志
JSONObject j = new JSONObject();
String dateid = DateUtil.timeStamp2Date(String.valueOf(createTime), "yyyy-MM-dd HH:mm:ss");
String unionType = unionClickLogs.getUnionType();
String unionTypekey = "yh:union:uniontype:"+unionType;
MktMarketingUrl mktMarketingUrl = redisValueCache.get(unionTypekey,MktMarketingUrl.class);
if(mktMarketingUrl==null){
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(unionType));
redisValueCache.set(unionTypekey,mktMarketingUrl,1, TimeUnit.HOURS);
}
String clientType = null;
if(StringUtils.isNotEmpty(unionActivityLogs.getIdfa())){
clientType = "ios";
}else{
clientType = "android";
}
j.put("apptype", clientType);
j.put("appid", unionActivityLogs.getAppId());
j.put("idfa", unionActivityLogs.getIdfa());
j.put("imei", unionActivityLogs.getImei());
j.put("udid", unionActivityLogs.getUdid());
j.put("dateid", dateid);
j.put("source", mktMarketingUrl == null ? "" : mktMarketingUrl.getName());
j.put("source_id",unionClickLogs.getUnionType());
j.put("ip", unionActivityLogs.getClientIp());
j.put("collect_ip", "");
j.put("app_key", unionActivityLogs.getAppKey());
j.put("active_type", "90");
j.put("tdid", "");
//打印90天的大数据日志
activeDingdang.info(j.toString());
j.put("active_type", "15");
//打印15天的大数据日志
activeDingdang.info(j.toString());
}
}
}catch (Exception e){
log.error("addBigData exception is ",e.getMessage());
}
UnionResponseBO response = new UnionResponseBO();
response.setMsg("success");
response.setIsSuccess(true);
return response;
}
}
... ...
package com.test;
import com.yoho.unions.common.utils.DateUtil;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by yoho on 2016/12/20.
... ... @@ -9,20 +13,26 @@ import java.net.URLDecoder;
public class DuomaiTest {
public static void main(String args[]){
String agent= "momochat/7.5.6 ios/664 (iphone 6; ios 10.2; zh_cn; iphone7,2; s1)";
String encode = "%e5%a6%82%e6%87%bf%e4%bc%a0/1.6 cfnetwork/808.2.16 darwin/16.3.0";
String decode = null;
try{
decode = URLDecoder.decode(encode,"utf-8");
}catch (Exception e){
}
System.out.print(decode);
int first = agent.indexOf(" ios ")+4;
String version1 = agent.substring(first);
String version = version1.substring(version1.indexOf(" ")+1, version1.indexOf(";"));
System.out.print(version);
String createTime = "1486339819";
String dateId =timeStamp2Date(createTime, "yyyy-MM-dd HH:mm:ss");
System.out.print(dateId);
}
/**
* 时间戳转换成日期格式字符串
* @param seconds 精确到秒的字符串
* @param formatStr
* @return
*/
public static String timeStamp2Date(String seconds,String format) {
if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
return "";
}
if(format == null || format.isEmpty()){
format = "yyyy-MM-dd HH:mm:ss";
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(seconds+"000")));
}
}
... ...