Authored by zhengwen.ge

Merge branch 'dev_unionType' into 日志优化

package com.yoho.unions.common.enums;
/**
* Created by yoho on 2016/12/12.
*/
public enum UnionTypeStatusEnum {
OPEN("1"),
CLOSE("0");
private String status;
public String getStatus() {
return status;
}
private UnionTypeStatusEnum(String status) {
this.status = status;
}
}
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionTypeManage;
import java.util.List;
/**
* Created by yoho on 2016/12/12.
*/
public interface IUnionTypeManageDAO {
List<UnionTypeManage> selectAll();
}
... ...
... ... @@ -5,12 +5,34 @@ public class UnionType {
private String name;
private String goUrl;
private Integer createId;
private Integer createTime;
private Integer unionType;
@Override
public String toString() {
return "UnionType{" +
"id=" + id +
", name='" + name + '\'' +
", goUrl=" + goUrl +
", createId=" + createId +
", createTime=" + createTime +
", unionType=" + unionType +
'}';
}
public String getGoUrl() {
return goUrl;
}
public void setGoUrl(String goUrl) {
this.goUrl = goUrl;
}
public Integer getId() {
return id;
}
... ...
package com.yoho.unions.dal.model;
/**
* Created by yoho on 2016/12/12.
*/
public class UnionTypeManage {
private Integer id;
private String name;
private String unionClass;
private String status;
private Integer createId;
private Integer createTime;
private Integer unionType;
@Override
public String toString() {
return "UnionTypeManage{" +
"id=" + id +
", name='" + name + '\'' +
", unionClass='" + unionClass + '\'' +
", status='" + status + '\'' +
", createId=" + createId +
", createTime=" + createTime +
", unionType=" + unionType +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUnionClass() {
return unionClass;
}
public void setUnionClass(String unionClass) {
this.unionClass = unionClass;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getCreateId() {
return createId;
}
public void setCreateId(Integer createId) {
this.createId = createId;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUnionType() {
return unionType;
}
public void setUnionType(Integer unionType) {
this.unionType = unionType;
}
}
... ...
<?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.IUnionTypeManageDAO" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionTypeManage" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="union_type" property="unionType" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="union_class" property="unionClass" jdbcType="VARCHAR" />
<result column="create_id" property="createId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, union_type,name,union_class, create_id, create_time, status
</sql>
<select id="selectAll" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_type_manage
</select>
<!--<select id="selectByUnionType" resultMap="BaseResultMap" parameterType="java.lang.Integer">
SELECT <include refid="Base_Column_List" />
from union_type
where union_type = #{unionType,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from union_type
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionType" >
insert into union_type (id, name, create_id,
create_time, union_type)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{createId,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{unionType,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionType" >
insert into union_type
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="name != null" >
name,
</if>
<if test="createId != null" >
create_id,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="unionType != null" >
union_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="createId != null" >
#{createId,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="unionType != null" >
#{unionType,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionType" >
update union_type
<set >
<if test="name != null" >
name = #{name,jdbcType=VARCHAR},
</if>
<if test="createId != null" >
create_id = #{createId,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="unionType != null" >
union_type = #{unionType,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionType" >
update union_type
set name = #{name,jdbcType=VARCHAR},
create_id = #{createId,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
union_type = #{unionType,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>-->
</mapper>
\ No newline at end of file
... ...
... ... @@ -4,12 +4,13 @@
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionType" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="go_url" property="goUrl" jdbcType="VARCHAR" />
<result column="create_id" property="createId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="union_type" property="unionType" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, name, create_id, create_time, union_type
id, name,go_url, create_id, create_time, union_type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -27,9 +28,9 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionType" >
insert into union_type (id, name, create_id,
insert into union_type (id, name,go_url, create_id,
create_time, union_type)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{createId,jdbcType=INTEGER},
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},#{goUrl,jdbcType=VARCHAR}, #{createId,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{unionType,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionType" >
... ... @@ -38,9 +39,12 @@
<if test="id != null" >
id,
</if>
<if test="name != null" >
<if test="name != null and name != ''" >
name,
</if>
<if test="goUrl != null and goUrl != '' " >
go_url,
</if>
<if test="createId != null" >
create_id,
</if>
... ... @@ -55,9 +59,12 @@
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="name != null" >
<if test="name != null and name != '' " >
#{name,jdbcType=VARCHAR},
</if>
<if test="goUrl != null and goUrl != '' " >
#{goUrl,jdbcType=VARCHAR},
</if>
<if test="createId != null" >
#{createId,jdbcType=INTEGER},
</if>
... ... @@ -72,9 +79,12 @@
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.UnionType" >
update union_type
<set >
<if test="name != null" >
<if test="name != null and name !='' " >
name = #{name,jdbcType=VARCHAR},
</if>
<if test="name != null and goUrl !='' " >
name = #{goUrl,jdbcType=VARCHAR},
</if>
<if test="createId != null" >
create_id = #{createId,jdbcType=INTEGER},
</if>
... ... @@ -90,6 +100,7 @@
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionType" >
update union_type
set name = #{name,jdbcType=VARCHAR},
go_url = #{goUrl,jdbcType=VARCHAR},
create_id = #{createId,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
union_type = #{unionType,jdbcType=INTEGER}
... ...
... ... @@ -2,11 +2,14 @@ package com.yoho.unions.server.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.unions.common.enums.SourceEnum;
import com.yoho.unions.dal.IUnionTypeDAO;
import com.yoho.unions.dal.model.UnionType;
import com.yoho.unions.server.service.IRedirectService;
import com.yoho.unions.vo.UnionReqVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
... ... @@ -33,6 +36,9 @@ public class RedirectServiceImpl implements IRedirectService {
private static final String WEB_REDIRECT_URL = "http://www.yohobuy.com/3party/ads";
@Autowired
private IUnionTypeDAO unionTypeDAO;
@Override
public void jump(UnionReqVO uionReqVO, HttpServletRequest request, HttpServletResponse response) {
logger.info("Enter jump: request param is {} ", uionReqVO);
... ... @@ -55,6 +61,8 @@ public class RedirectServiceImpl implements IRedirectService {
redirectUrl = this.builderUrlForPanshi(uionReqVO);
} else if ("51fanli".equals(channelId)) {
redirectUrl = this.builderUrlForFanli(uionReqVO);
}else{
redirectUrl = builderCommonUrl(uionReqVO);
}
response.setStatus(301);
response.sendRedirect(redirectUrl);
... ... @@ -117,6 +125,28 @@ public class RedirectServiceImpl implements IRedirectService {
return urlBuilder.toString();
}
private String builderCommonUrl(UnionReqVO uionReqVO){
String channelId = uionReqVO.getChannel_id();
UnionType unionType = unionTypeDAO.selectByUnionType(Integer.parseInt(channelId.trim()));
logger.info("builderCommonUrl find the UnionType = {} by channelId={}",unionType,channelId);
if(null == unionType || StringUtils.isBlank(unionType.getGoUrl()) || StringUtils.isBlank(unionType.getName()))
return "";
StringBuilder targetUrl = new StringBuilder("http://union.yohobuy.com/go?client_id=");
targetUrl.append(channelId.trim());
targetUrl.append("&channel_code=");
targetUrl.append(unionType.getName());
targetUrl.append("&append=&go_url=");
targetUrl.append(unionType.getGoUrl());
if (targetUrl.toString().contains("?")) {
targetUrl.append("&utm_source=").append(uionReqVO.getUtm_source()).append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
} else {
targetUrl.append("?utm_source=").append(uionReqVO.getUtm_source()).append("&utm_medium=").append(uionReqVO.getUtm_medium()).append("&utm_campaign=").append(uionReqVO.getUtm_campaign());
}
return targetUrl.toString();
}
/**
* 解析url
*
... ...
... ... @@ -5,9 +5,12 @@ import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.unions.common.enums.UnionTypeStatusEnum;
import com.yoho.unions.common.redis.RedisValueCache;
import com.yoho.unions.common.utils.SpringContextUtil;
import com.yoho.unions.dal.IUnionTypeManageDAO;
import com.yoho.unions.dal.IUserOrdersDAO;
import com.yoho.unions.dal.model.UnionTypeManage;
import com.yoho.unions.dal.model.UserOrders;
import com.yoho.unions.server.service.IOrderPushService;
import com.yoho.unions.server.service.IUnionOrderService;
... ... @@ -45,6 +48,9 @@ public class BigDataOrderInfoTask {
@Autowired
IUserOrdersDAO userOrdersDAO;
@Autowired
IUnionTypeManageDAO unionTypeManageDAO;
@Scheduled(cron = "* 0/3 * * * ?")
public void run() {
UnionOrderReqVO reqVO = new UnionOrderReqVO();
... ... @@ -89,8 +95,13 @@ public class BigDataOrderInfoTask {
}
orderInfoMap.get(orderInfo.getClientId()).add(orderInfo);
}
//应该推送的clientId
List<UnionTypeManage> unionTypeManageList = unionTypeManageDAO.selectAll();
//按source分类推送
for (Integer clientId : orderInfoMap.keySet()) {
if(!checkIsPush(clientId,unionTypeManageList))
continue;
IOrderPushService orderPushService = orderPushServiceMap.get(clientId);
//clientId如果不在xml配置的里面,则走通用的
try {
... ... @@ -106,4 +117,15 @@ public class BigDataOrderInfoTask {
}
}
//是否需要推送
private boolean checkIsPush(Integer clientId,List<UnionTypeManage> unionTypeManageList){
for(UnionTypeManage unionTypeManage : unionTypeManageList){
if(clientId.intValue() == unionTypeManage.getUnionType()){
if(UnionTypeStatusEnum.OPEN.getStatus().equals(unionTypeManage.getStatus())){}
return true;
}
}
return false;
}
}
... ...
... ... @@ -33,5 +33,6 @@ datasources:
daos:
- com.yoho.unions.dal.IUserOrdersDAO
- com.yoho.unions.dal.IUnionTypeDAO
- com.yoho.unions.dal.IUnionTypeManageDAO
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -34,5 +34,5 @@ datasources:
daos:
- com.yoho.unions.dal.IUserOrdersDAO
- com.yoho.unions.dal.IUnionTypeDAO
- com.yoho.unions.dal.IUnionTypeManageDAO
readOnlyInSlave: true
\ No newline at end of file
... ...