Authored by zhengwen.ge

update

package com.yoho.unions.vo;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 转化数据
* Created by yoho on 2017/2/22.
*/
public class TransInfo implements Serializable {
//标示是普通交寄还是首单交寄
private String type;
private BigDecimal orderAmount;
private String udid;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public BigDecimal getOrderAmount() {
return orderAmount;
}
public void setOrderAmount(BigDecimal orderAmount) {
this.orderAmount = orderAmount;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid;
}
}
... ...
package com.yoho.unions.dal;
import com.yoho.unions.dal.model.UnionActivity;
public interface IUnionActivityDAO {
int deleteByPrimaryKey(Long id);
int insert(UnionActivity record);
int insertSelective(UnionActivity record);
UnionActivity selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(UnionActivity record);
int updateByPrimaryKey(UnionActivity record);
UnionActivity selectByUdid(String udid);
}
\ No newline at end of file
... ...
//package com.yoho.unions.dal;
//
//
//import com.yoho.unions.dal.model.UnionDepartmentUrl;
//
//public interface IUnionDepartmentUrlDAO {
// int deleteByPrimaryKey(Integer id);
//
// int insert(UnionDepartmentUrl record);
//
// int insertSelective(UnionDepartmentUrl record);
//
// UnionDepartmentUrl selectByPrimaryKey(Integer id);
//
// int updateByPrimaryKeySelective(UnionDepartmentUrl record);
//
// int updateByPrimaryKey(UnionDepartmentUrl record);
//
// UnionDepartmentUrl selectByUnionType(String unionType);
//}
\ No newline at end of file
//package com.yoho.unions.dal;
//
//
//import com.yoho.unions.dal.model.UnionType;
//
//public interface IUnionTypeDAO {
// int deleteByPrimaryKey(Integer id);
//
// int insert(UnionType record);
//
// int insertSelective(UnionType record);
//
// UnionType selectByPrimaryKey(Integer id);
//
// UnionType selectByUnionType(Integer unionType);
//
// int updateByPrimaryKeySelective(UnionType record);
//
// int updateByPrimaryKey(UnionType record);
//}
\ No newline at end of file
package com.yoho.unions.dal.model;
public class UnionActivity {
private Long id;
private String udid;
private String unionType;
private String clientType;
private String advertiserId;
private String clickId;
private Integer createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid == null ? null : udid.trim();
}
public String getUnionType() {
return unionType;
}
public void setUnionType(String unionType) {
this.unionType = unionType == null ? null : unionType.trim();
}
public String getClientType() {
return clientType;
}
public void setClientType(String clientType) {
this.clientType = clientType == null ? null : clientType.trim();
}
public String getAdvertiserId() {
return advertiserId;
}
public void setAdvertiserId(String advertiserId) {
this.advertiserId = advertiserId == null ? null : advertiserId.trim();
}
public String getClickId() {
return clickId;
}
public void setClickId(String clickId) {
this.clickId = clickId == null ? null : clickId.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
package com.yoho.unions.dal.model;
import java.math.BigDecimal;
/**
* Created by yoho on 2017/2/22.
*/
public class UnionActivityTrans {
//订单金额
private BigDecimal orderAmount;
//设备号
private String udid;
public BigDecimal getOrderAmount() {
return orderAmount;
}
public void setOrderAmount(BigDecimal orderAmount) {
this.orderAmount = orderAmount;
}
public String getUdid() {
return udid;
}
public void setUdid(String udid) {
this.udid = udid;
}
}
... ...
<?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.model.UnionActivity" >
<resultMap id="BaseResultMap" type="com.yoho.unions.dal.UnionActivity" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="udid" property="udid" jdbcType="VARCHAR" />
<result column="union_type" property="unionType" jdbcType="VARCHAR" />
<result column="client_type" property="clientType" jdbcType="VARCHAR" />
<result column="advertiser_id" property="advertiserId" jdbcType="VARCHAR" />
<result column="click_id" property="clickId" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, udid, union_type, client_type, advertiser_id, click_id, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from union_activity
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from union_activity
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.UnionActivity" >
insert into union_activity (id, udid, union_type,
client_type, advertiser_id, click_id,
create_time)
values (#{id,jdbcType=BIGINT}, #{udid,jdbcType=VARCHAR}, #{unionType,jdbcType=VARCHAR},
#{clientType,jdbcType=VARCHAR}, #{advertiserId,jdbcType=VARCHAR}, #{clickId,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.UnionActivity" >
insert into union_activity
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="udid != null" >
udid,
</if>
<if test="unionType != null" >
union_type,
</if>
<if test="clientType != null" >
client_type,
</if>
<if test="advertiserId != null" >
advertiser_id,
</if>
<if test="clickId != null" >
click_id,
</if>
<if test="createTime != null" >
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="udid != null" >
#{udid,jdbcType=VARCHAR},
</if>
<if test="unionType != null" >
#{unionType,jdbcType=VARCHAR},
</if>
<if test="clientType != null" >
#{clientType,jdbcType=VARCHAR},
</if>
<if test="advertiserId != null" >
#{advertiserId,jdbcType=VARCHAR},
</if>
<if test="clickId != null" >
#{clickId,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.UnionActivity" >
update union_activity
<set >
<if test="udid != null" >
udid = #{udid,jdbcType=VARCHAR},
</if>
<if test="unionType != null" >
union_type = #{unionType,jdbcType=VARCHAR},
</if>
<if test="clientType != null" >
client_type = #{clientType,jdbcType=VARCHAR},
</if>
<if test="advertiserId != null" >
advertiser_id = #{advertiserId,jdbcType=VARCHAR},
</if>
<if test="clickId != null" >
click_id = #{clickId,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.UnionActivity" >
update union_activity
set udid = #{udid,jdbcType=VARCHAR},
union_type = #{unionType,jdbcType=VARCHAR},
client_type = #{clientType,jdbcType=VARCHAR},
advertiser_id = #{advertiserId,jdbcType=VARCHAR},
click_id = #{clickId,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yoho.unions.server.service;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.TransInfo;
import com.yoho.unions.vo.UnionOrderReqVO;
import java.util.List;
... ... @@ -9,4 +10,6 @@ public interface IUnionOrderService {
public List<OrderInfo> getUnionOrders(UnionOrderReqVO req);
public List<TransInfo> getTrandInfo(UnionOrderReqVO req);
}
... ...
package com.yoho.unions.server.service.impl;
import com.yoho.service.model.union.UnionTrans;
import com.yoho.unions.common.redis.RedisHashCache;
import com.yoho.unions.common.redis.RedisListCache;
import com.yoho.unions.dal.model.UnionActivityTrans;
import com.yoho.unions.dal.model.UnionOrders;
import com.yoho.unions.dal.model.UnionOrdersGoods;
import com.yoho.unions.server.service.IUnionOrderService;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.OrdersGood;
import com.yoho.unions.vo.TransInfo;
import com.yoho.unions.vo.UnionOrderReqVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -26,8 +29,14 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
private static final String UNION_ORDER_KEY = "union:orders";
private static final String UNION_TRAND = "YH_BD_ORDER_UNIONS";
private static final String UNION_ORDER_GOODS_KEY_PRE = "union:order_goods:";
private static final String UNION_TRANS_UNIONTYPE = "YH_BD_UNI_1_ORDER_";
private static final String UNION_NORMAL_TRANS_UNIONTYPE = "YH_BD_UNI_ALL_ORDER_";
@Autowired
private RedisListCache redisListCache;
... ... @@ -67,6 +76,41 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
}
}
@Override
public List<TransInfo> getTrandInfo(UnionOrderReqVO req){
logger.info("Enter getTrandInfo: request param is {}", req);
int limit = req.getLimit();
limit = limit < 1 ? 20 : limit;
try{
List<TransInfo> resList = new ArrayList<TransInfo>();
Long size = redisListCache.size(UNION_TRAND);
int sizeInt = size == null ? 0 : size.intValue();
limit = sizeInt < limit ? sizeInt : limit;
for(int i=0; i < limit; i++){
UnionTrans unionTrans = redisListCache.rightPop(UNION_TRAND, UnionTrans.class);
logger.info("getTrandInfo: get order list form bigdata redis: key is {}, result is {}", UNION_ORDER_KEY, unionTrans);
if(unionTrans == null){
continue;
}
String union_type = unionTrans.getUnion_type();
//首单交寄
String firstOrder = UNION_TRANS_UNIONTYPE + union_type;
//普通交寄
String normalOrder = UNION_NORMAL_TRANS_UNIONTYPE+union_type;
List<UnionActivityTrans> firstOrderList = redisListCache.rightPop(firstOrder, List.class);
logger.info("getFirstOrderList: from bigdata redis: key is {}, result size is {}", firstOrder, firstOrderList == null ? 0 : firstOrderList.size());
List<UnionActivityTrans> normalOrderList = redisListCache.rightPop(normalOrder,List.class);
logger.info("getNormalOrderList: from bigdata redis: key is {}, result size is {}", normalOrder, normalOrderList == null ? 0 : normalOrderList.size());
resList = this.convertTrans(firstOrderList,normalOrderList);
}
return resList;
}catch(Exception e){
logger.warn("getUnionOrders: get orders from bigdata redis failed, error is {}", e);
return null;
}
}
private OrderInfo convertToUnionOrderBo(UnionOrders unionOrder){
if(null == unionOrder){
return null;
... ... @@ -114,4 +158,31 @@ public class UnionOrderServiceImpl implements IUnionOrderService {
return resList;
}
private List<TransInfo> convertTrans(List<UnionActivityTrans> firstOrderList,List<UnionActivityTrans> normalOrderList){
if(CollectionUtils.isEmpty(firstOrderList)&&CollectionUtils.isEmpty(normalOrderList)){
return null;
}
List<TransInfo> transInfoList = new ArrayList<TransInfo>();
if(CollectionUtils.isNotEmpty(firstOrderList)){
for(UnionActivityTrans unionActivityTrans:firstOrderList){
TransInfo transInfo = new TransInfo();
//首单设为1
transInfo.setType("1");
transInfo.setUdid(unionActivityTrans.getUdid());
transInfo.setOrderAmount(unionActivityTrans.getOrderAmount());
transInfoList.add(transInfo);
}
}
if(CollectionUtils.isNotEmpty(normalOrderList)){
for(UnionActivityTrans unionActivityTran:normalOrderList){
TransInfo transInfo = new TransInfo();
//正常单设为2
transInfo.setType("2");
transInfo.setUdid(unionActivityTran.getUdid());
transInfo.setOrderAmount(unionActivityTran.getOrderAmount());
transInfoList.add(transInfo);
}
}
return transInfoList;
}
}
... ...
... ... @@ -93,6 +93,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
IUnionActivityLogsDAO unionActivityLogsDAO;
@Resource
IUnionActivityDAO unionActivityDAO;
@Resource
IUnionTypeMatchDAO unionTypeMatchDAO;
@Resource(name="unionServiceImpl")
... ... @@ -507,12 +510,14 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
log.warn("callback error with request={}", request);
return new UnionResponse(204, "callback error");
}
//如果来源是广点通,则把广点通的一些信息记入表,给之后做转化上报使用
saveUnionActivity(click,request);
} catch (Exception e) {
log.error("callback error with request={}", request, e);
//return new UnionResponse(204, "callback error");
}
activeUnion.info("activateUnion in success request is {}", request);
return new UnionResponse();
... ... @@ -565,6 +570,23 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
});
}
private void saveUnionActivity(ClickUnionRequestBO click,ActivateUnionRequestBO request){
taskExecutor.execute(new Runnable(){
@Override
public void run()
{
UnionActivity unionActivity = new UnionActivity();
unionActivity.setClientType(request.getClient_type());
unionActivity.setUdid(request.getUdid());
unionActivity.setUnionType(click.getUnion_type());
//广点通的账号id存入的是click的commonUse字段
unionActivity.setAdvertiserId(click.getCommonUse());
unionActivity.setClickId(click.getClickId());
unionActivityDAO.insertSelective(unionActivity);
}
});
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
... ...
package com.yoho.unions.server.task;
import com.yoho.unions.dal.IUnionActivityDAO;
import com.yoho.unions.dal.model.UnionActivity;
import com.yoho.unions.server.service.IUnionOrderService;
import com.yoho.unions.vo.OrderInfo;
import com.yoho.unions.vo.TransInfo;
import com.yoho.unions.vo.UnionOrderReqVO;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/**
* 广点通转化数据上报,定时从大数据抽取数据,然后联盟拼接,上报给广点通
* Created by yoho on 2017/2/22.
*/
@Component
public class GdtTransTask {
static Logger log = LoggerFactory.getLogger(GdtTransTask.class);
@Autowired
private IUnionOrderService unionOrderService;
@Resource
IUnionActivityDAO unionActivityDAO;
@Scheduled(cron = "* 0/3 * * * ?")
public void run() {
UnionOrderReqVO reqVO = new UnionOrderReqVO();
reqVO.setLimit(20);
this.execute(reqVO);
}
public void execute(UnionOrderReqVO reqVO){
//从大数据中取出联盟需要的广点通带来转化的设备号,和金额
List<TransInfo> transInfoList = unionOrderService.getTrandInfo(reqVO);
if (CollectionUtils.isEmpty(transInfoList)) {
return;
}
//将取出来的数据进行拼接
for(TransInfo transInfo:transInfoList){
String udid = transInfo.getUdid();
//利用udid去表中查出是两个广点通账号带来的
UnionActivity unionActivity = unionActivityDAO.selectByUdid(udid);
//按照广点通要求拼接数据
}
}
private
}
... ...