Authored by zhengwen.ge

Merge branch 'master' into 统一推送接口联调

package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionTypeMatch;
public interface IUnionTypeMatchDAO {
UnionTypeMatch selectByPrimaryKey(Long unionType);
}
\ No newline at end of file
... ...
package com.yoho.unions.dal.model;
public class UnionTypeMatch {
private Long unionType;
private Long unionTypeMatch;
private Integer createTime;
public Long getUnionType() {
return unionType;
}
public void setUnionType(Long unionType) {
this.unionType = unionType;
}
public Long getUnionTypeMatch() {
return unionTypeMatch;
}
public void setUnionTypeMatch(Long unionTypeMatch) {
this.unionTypeMatch = unionTypeMatch;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.unions.dal.IUnionTypeMatchDAO" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionTypeMatch" >
<id column="union_type" property="unionType" jdbcType="BIGINT" />
<result column="union_type_match" property="unionTypeMatch" jdbcType="BIGINT" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
union_type, union_type_match, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from union_type_match
where union_type = #{unionType,jdbcType=BIGINT}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -14,6 +14,8 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yoho.unions.dal.IUnionTypeMatchDAO;
import com.yoho.unions.dal.model.UnionTypeMatch;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -48,8 +50,8 @@ public class ClickUnionRest {
IUnionService unionService;
@Resource
IMobvistaService mobvistaService;
@Resource
IUnionTypeMatchDAO unionTypeMatchDAO;
/**
* 添加联盟
... ... @@ -279,8 +281,13 @@ public class ClickUnionRest {
}
log.info("addMonitor request={}", bo);
//根据union_type区分不同的厂商
//根据union_type区分不同的厂商
String union_type = request.getParameter("union_type");
//先去union_type_match表里面查看,是否有对应关系
UnionTypeMatch unionTypeMatch = unionTypeMatchDAO.selectByPrimaryKey(Long.valueOf(union_type));
if(unionTypeMatch!=null && StringUtils.isNotEmpty(String.valueOf(unionTypeMatch.getUnionTypeMatch()))){
union_type = String.valueOf(unionTypeMatch.getUnionTypeMatch());
}
StringBuffer stringBuffer = new StringBuffer();
String bean = stringBuffer.append("UnionServiceImpl").append("_").append(union_type).toString();
boolean containsBean = SpringContextUtil.containsBean(bean);
... ...
... ... @@ -53,10 +53,13 @@ public class UnionServiceImpl implements IUnionService {
static Logger activeUnion = LoggerFactory.getLogger("activeUnion");
static Logger clickUnion = LoggerFactory.getLogger("clickUnion");
static Logger ipMatch = LoggerFactory.getLogger("ipMatch");
private static final String UNION_KEY = "UNION:KEY:";
static Logger log = LoggerFactory.getLogger(UnionServiceImpl.class);
@Resource(name="yhRedisTemplate")
YHRedisTemplate<String, String> yHRedisTemplate;
... ... @@ -177,14 +180,12 @@ public class UnionServiceImpl implements IUnionService {
//把IP作为key,也保存到redis
// key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
// yhValueOperations.set(key, JSON.toJSONString(request));
// yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS);
// log.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request));
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
yhValueOperations.set(key, JSON.toJSONString(request));
yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS);
log.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request));
log.info("clickUnion set redis success with request={}", request);
// log.info("clickUnion set redis success with request={}", request);
// if (union != null) {
// //如果90天以内,已经存在点击记录,则不需要插入或更新数据库
... ... @@ -284,35 +285,29 @@ public class UnionServiceImpl implements IUnionService {
}
log.info("activateUnion with get redis first with key={}, value={}", key, value);
clickUnion.info("activateUnion with get redis first with key={}, value={}", key, value);
if (StringUtils.isNotEmpty(request.getTd())) {
activeUnion.info("activateUnion with get redis first with key={}, value={}", key, value);
String td = request.getTd();
if (StringUtils.isNotEmpty(td)) {
if (StringUtils.isEmpty(value)) {
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd() + "_" + request.getAppkey();
key = UNION_KEY + "_" + request.getClientIp() + "_" + td + "_" + request.getAppkey();
value = yhValueOperations.get(key);
log.info("activateUnion with get redis first with key={}, value={}", key, value);
}
if (StringUtils.isEmpty(value)) {
String[] arr = request.getTd().split("_");
if (arr.length > 3) {
request.setTd(arr[2] + "_" + arr[3]);
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd() + "_" + request.getAppkey();
td=(arr[2] + "_" + arr[3]);
key = UNION_KEY + "_" + request.getClientIp() + "_" + td + "_" + request.getAppkey();
value = yhValueOperations.get(key);
log.info("activateUnion with get redis second with key={}, value={}", key, value);
clickUnion.info("activateUnion with get redis second with key={}, value={}", key, value);
activeUnion.info("activateUnion with get redis second with key={}, value={}", key, value);
}
if(arr.length==3){
request.setTd(arr[1]+"_"+arr[2]);
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd() + "_" + request.getAppkey();
value = yhValueOperations.get(key);
log.info("activateUnion with get redis third with key={}, value={}", key, value);
clickUnion.info("activateUnion with get redis third with key={}, value={}", key, value);
}
if(arr.length==3){
request.setTd(arr[1]+"_"+arr[2]);
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd() + "_" + request.getAppkey();
td = (arr[1]+"_"+arr[2]);
key = UNION_KEY + "_" + request.getClientIp() + "_" + td + "_" + request.getAppkey();
value = yhValueOperations.get(key);
log.info("activateUnion with get redis third with key={}, value={}", key, value);
activeUnion.info("activateUnion with get redis third with key={}, value={}", key, value);
}
}
}
... ... @@ -323,10 +318,15 @@ public class UnionServiceImpl implements IUnionService {
}else{
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
value = yhValueOperations.get(key);
if(StringUtils.isNotEmpty(value)){
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);
return new UnionResponse(204, "user not click");
}
}
log.info("activateUnion with get redis forth with key={}, value={}", key, value);
clickUnion.info("activateUnion with get redis forth with key={}, value={}", key, value);
activeUnion.info("activateUnion with get redis forth with key={}, value={}", key, value);
}
// 如果redis中不存在存在该用户点击信息,则退出
... ... @@ -395,6 +395,7 @@ public class UnionServiceImpl implements IUnionService {
//15天内有记录,退出
log.warn("activateUnion error because 15 days has activate in bigdata database info with param is {}", request);
} else {
//根据mkt_markering
//15天内没有记录,则记录大数据日志,退出
JSONObject j = new JSONObject();
j.put("apptype", request.getClient_type());
... ...
... ... @@ -39,5 +39,6 @@ datasources:
- com.yoho.unions.dal.IUnionOrderPushDAO
- com.yoho.unions.dal.IUnionDepartmentUrlDAO
- com.yoho.unions.dal.IMktMarketingUrlDAO
- com.yoho.unions.dal.IUnionTypeMatchDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -161,7 +161,21 @@
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
</encoder>
</appender>
<!--IP匹配日志-->
<appender name="IP_MATCH" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/IP_MATCH.log</fileNamePattern>
<!-- 日志最大的保存天数 -->
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>${maxFileSize}</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
</encoder>
</appender>
<!-- 数据库操作日志 -->
<logger name="java.sql.PreparedStatement" value="DEBUG" />
... ... @@ -215,5 +229,9 @@
<logger name="activeUnion" level="INFO" additivity="false">
<appender-ref ref="ACTIVE_UNION"/>
</logger>
<logger name="ipMatch" level="INFO" additivity="false">
<appender-ref ref="IP_Match"/>
</logger>
</configuration>
\ No newline at end of file
... ...
... ... @@ -40,4 +40,6 @@ datasources:
- com.yoho.unions.dal.IUnionOrderPushDAO
- com.yoho.unions.dal.IUnionDepartmentUrlDAO
- com.yoho.unions.dal.IMktMarketingUrlDAO
- com.yoho.unions.dal.IUnionTypeMatchDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -191,6 +191,23 @@
</encoder>
</appender>
<appender name="IP_MATCH" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${yoho.logs.basedir}/${yoho.unions.env.namespace}/IP_MATCH.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${yoho.logs.basedir}/${yoho.unions.env.namespace}/archived/IP_MATCH/IP_MATCH.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>${yoho.logs.maxFileSize}</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>${yoho.logs.maxHistory}</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger:%line - %msg%n</pattern>
</encoder>
</appender>
<!-- 数据库操作日志 -->
<logger name="java.sql.PreparedStatement" value="${yoho.logs.level}" />
<logger name="java.sql.Connection" value="${yoho.logs.level}" />
... ... @@ -255,4 +272,8 @@
<logger name="activeUnion" level="INFO" additivity="false">
<appender-ref ref="ACTIVE_UNION"/>
</logger>
<logger name="ipMatch" level="INFO" additivity="false">
<appender-ref ref="IP_MATCH"/>
</logger>
</configuration>
\ No newline at end of file
... ...
... ... @@ -21,6 +21,7 @@
<url-pattern>/downmars.html</url-pattern>
<url-pattern>/downshow.html</url-pattern>
<url-pattern>/downyohoshow.html</url-pattern>
<url-pattern>/downapp3.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
... ...
... ... @@ -6,7 +6,7 @@
<meta charset="utf-8">
<title>潮流商品 | YOHO!有货</title>
<meta name="description" content="">
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<script src="//lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
var agent = navigator.userAgent.toLowerCase() ;
var version, type, appid, td, queryString, downUrl;
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>潮流商品 | YOHO!有货</title>
<meta name="description" content="">
<script src="//lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
var agent = navigator.userAgent.toLowerCase() ;
var version, type, appid, td, queryString, downUrl;
var jumpTypes = [110];
function isInJump(unionType) {
for (var i = 0 ;i < jumpTypes.length; i++) {
if (unionType == jumpTypes[i]) {
return true;
}
}
return false;
}
function getQueryString() {
var vars = [],
hash,
i;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
queryString = getQueryString();
downUrl = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho&g_f=995445';
//downUrl = "https://itunes.apple.com/cn/app/yoho!-you-huo/id490655927?mt=8";
var appkey = queryString.appkey;
if (appkey == "yoho") {
//yohonow
downUrl = "http://a.app.qq.com/o/simple.jsp?pkgname=cn.yoho.magazine#opened";
} else if (appkey == "mars") {
//mars
downUrl = "https://itunes.apple.com/cn/app/mars-xin-xian-hao-qu-chu-yu/id1056487123?l=en&mt=8";
//downUrl = "http://yoho-apps.qiniudn.com/YohoMars.apk";
}
if (agent.indexOf("like mac os x") > 0) {
var regStr_saf = /os [\d._]*/gi ;
var verinfo = agent.match(regStr_saf) ;
version = (verinfo+'').replace(/[^0-9|_.]/ig,'').replace(/_/ig, '.');
type = 'ios';
appid = '490655927';
td = window.screen.width + '_' + window.screen.height + '_' + type + '_' + version;
} else if (agent.indexOf('android') > -1 || agent.indexOf('linux') > -1) {
type = 'android';
appid = 'com.yoho';
try {
var indextd = agent.indexOf('_td');
var index = agent.indexOf(' build');
var preString = '';
var deviceType = '';
//alert(agent);
if (indextd > -1) {
preString = agent.substr(0, indextd);
preString = preString.substr(preString.lastIndexOf(";") + 1);
preString = preString.replace(/\s+/g,'').replace(/_/ig, '');
var sansungIndex = preString.indexOf('samsung-');
if (sansungIndex > -1) {
preString = preString.substr(8);
}
} else if (index > -1) {
preString = agent.substr(0, index);
preString = preString.substr(preString.lastIndexOf(";") + 1);
preString = preString.replace(/\s+/g,'').replace(/_/ig, '');
//alert(preString);
}
deviceType = preString;
version = agent.substr(agent.indexOf('android') + 8, 3);
td = deviceType + '_' + type + '_' + version;
} catch(e) {
}
//downUrl = 'http://cdn.yoho.cn/app-downfiles/yohoBuy_YOHO_2953.apk';
}
$.ajax({
method: 'POST',
url: 'http://union.yoho.cn/union/ClickUnionRest/addUnion',
// url: 'http://192.168.102.205:8088/union/ClickUnionRest/addUnion',
data: {
union_type: queryString.union_type,
identify_id: queryString.identify_id,
callbackurl: queryString.callbackurl,
client_type: type,
td: queryString.td ? queryString.td : td,
appid: queryString.appid ? queryString.appid : appid,
appkey: queryString.appkey,
idfa : queryString.idfa ? queryString.idfa : queryString.IDFA,
imei:queryString.imei?queryString.imei:queryString.IMEI
},
complete: function() {
/* if (!downUrl) {
window.location.href = "http://m.yohobuy.com";
} else {
window.location.href = downUrl;
} */
window.location.href = downUrl;
window.setTimeout(function() {
window.location.href = "http://m.yohobuy.com";
}, 2000);
}
});
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
... ...