Authored by zhengwen.ge

update

... ... @@ -10,6 +10,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yoho.unions.server.service.IPinYouService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -47,6 +48,9 @@ public class ActivateUnionRest {
static ExecutorService exe = Executors.newFixedThreadPool(10);
@Resource
IPinYouService pinYouService;
@Resource(name="unionServiceImpl")
IUnionService unionService;
... ... @@ -176,4 +180,15 @@ public class ActivateUnionRest {
activeDingdang.info(j.toString());
return new ActiveUnionResponseBO();
}
/**
* 给品友留的后门,如果定时任务没有启动,则通过curl调用接口,直接获取数据,并发送给品友
*/
@RequestMapping("/sendPinYou")
@ResponseBody
public UnionResponse sendPinYou(){
log.info("begin sendPinYou");
UnionResponse response = pinYouService.sendPinYou();
return response;
}
}
... ...
... ... @@ -14,10 +14,12 @@ public interface IPinYouService {
* 给品友发送访问数据
* @param requestBO
*/
UnionResponse sendViem(ViewPinYouRequestBO requestBO);
UnionResponse sendView(ViewPinYouRequestBO requestBO);
/**
* 给品友发送转化数据,主要是下单
*/
UnionResponse sendTrans(TransPinYouRequestBO requestBO);
UnionResponse sendPinYou();
}
... ...
... ... @@ -6,16 +6,21 @@ import com.yoho.service.model.union.request.ViewPinYouRequestBO;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.enums.EnentValueEnum;
import com.yoho.unions.common.redis.RedisListCache;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.HttpUtils;
import com.yoho.unions.server.service.IPinYouService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
/**
* Created by yoho on 2016/11/15.
... ... @@ -29,12 +34,56 @@ public class PinYouServiceImpl implements IPinYouService {
static String PINYOU_TRANS_URL = "http://stats.ipinyou.com/mcvt?";
private static final String UNION_VIEW_KEY = "union:pinyou:view";
private static final String UNION_TRANS_KEY = "union:pinyou:trans";
@Autowired
private RedisListCache redisListCache;
@Override
public UnionResponse sendPinYou() {
//从redis里面获取大数据的数据
Long viewSize = redisListCache.size(UNION_VIEW_KEY);
Long transSize = redisListCache.size(UNION_TRANS_KEY);
List<ViewPinYouRequestBO> viewPinYouRequestBOList = new ArrayList<>();
int viewSizeInt = viewSize == null ? 0 : viewSize.intValue();
int transSizeInt = transSize == null ? 0 : transSize.intValue();
List<TransPinYouRequestBO> transPinYouRequestBOList = new ArrayList<>();
if (viewSizeInt > 0) {
for (int i = 0; i < viewSizeInt; i++) {
ViewPinYouRequestBO viewPinYouRequestBO = redisListCache.rightPop(UNION_VIEW_KEY, ViewPinYouRequestBO.class);
viewPinYouRequestBOList.add(viewPinYouRequestBO);
}
}
if (transSizeInt > 0) {
for (int i = 0; i < transSizeInt; i++) {
TransPinYouRequestBO transPinYouRequestBO = redisListCache.rightPop(UNION_TRANS_KEY, TransPinYouRequestBO.class);
transPinYouRequestBOList.add(transPinYouRequestBO);
}
}
if (CollectionUtils.isNotEmpty(viewPinYouRequestBOList)) {
for (ViewPinYouRequestBO requestBO : viewPinYouRequestBOList) {
sendView(requestBO);
}
}
if (CollectionUtils.isNotEmpty(transPinYouRequestBOList)) {
for (TransPinYouRequestBO transPinYouRequestBO : transPinYouRequestBOList) {
sendTrans(transPinYouRequestBO);
}
}
return new UnionResponse();
}
/**
* jp:启动参数,固定位1
*df:debug flag 固定0
* df:debug flag 固定0
*/
public UnionResponse sendViem(ViewPinYouRequestBO requestBO){
@Override
public UnionResponse sendView(ViewPinYouRequestBO requestBO) {
//广告主信息
String advertiser = "MC.LF";
//操作系统信息
... ... @@ -44,12 +93,15 @@ public class PinYouServiceImpl implements IPinYouService {
String client_type = ClientTypeEnum.IOS.getName();
String idfa = requestBO.getIdfa();
String imei = requestBO.getImei();
if(idfa.equals("")||StringUtils.isEmpty(idfa)){
if (idfa.equals("") || StringUtils.isEmpty(idfa)) {
client_type = ClientTypeEnum.ANDROID.getName();
os = ClientTypeEnum.ANDROID.getName();
}
//时间戳
int currentTime = DateUtil.getCurrentTimeSecond();
String ts = requestBO.getTs();
if (StringUtils.isEmpty(ts)) {
ts = String.valueOf(DateUtil.getCurrentTimeSecond() * 1000);
}
//启动参数,固定位1
String jp = "1";
//用户id
... ... @@ -67,23 +119,23 @@ public class PinYouServiceImpl implements IPinYouService {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer = stringBuffer.append(PINYOU_VIEW_URL).append("a=")
.append(advertiser).append("&os=").append(os)
.append("&ts=").append(currentTime)
.append("&ts=").append(ts)
.append("&jp=1").append("&ip=").append(ip)
.append("&event=").append(event)
.append("&event_vaule=").append(event_value).append("&df=0");
String url = null;
if(event.equals(EnentValueEnum.ADD_CART.getName())||event.equals(EnentValueEnum.VIEW_ITEM.getName())){
stringBuffer= stringBuffer.append("&p=").append(event_value);
if (event.equals(EnentValueEnum.ADD_CART.getName()) || event.equals(EnentValueEnum.VIEW_ITEM.getName())) {
stringBuffer = stringBuffer.append("&p=").append(event_value);
}
if(StringUtils.isNotEmpty(user_id)&& user_id.matches("[0-9]+")){
if (StringUtils.isNotEmpty(user_id) && user_id.matches("[0-9]+")) {
stringBuffer = stringBuffer.append("&user_id=").append(user_id);
}
if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
if (client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())) {
//如果是浏览商品和加入购物车则需要传p=商品编号
String dim = MD5.md5(imei);
stringBuffer = stringBuffer.append("&dim=").append(dim);
}
if(client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())){
if (client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())) {
String iam = MD5.md5(idfa);
stringBuffer = stringBuffer.append("&iam=").append(iam);
}
... ... @@ -92,22 +144,25 @@ public class PinYouServiceImpl implements IPinYouService {
return response;
}
public UnionResponse sendTrans(TransPinYouRequestBO requestBO){
public UnionResponse sendTrans(TransPinYouRequestBO requestBO) {
//广告主信息
String advertiser = "MC.LF";
//操作系统信息
String os = requestBO.getOs();
//根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
String client_type = ClientTypeEnum.IOS.getName();
os=ClientTypeEnum.IOS.getName();
os = ClientTypeEnum.IOS.getName();
String idfa = requestBO.getIdfa();
String imei = requestBO.getImei();
if(idfa.equals("")||StringUtils.isEmpty(idfa)){
if (idfa.equals("") || StringUtils.isEmpty(idfa)) {
client_type = ClientTypeEnum.ANDROID.getName();
os=ClientTypeEnum.ANDROID.getName();
os = ClientTypeEnum.ANDROID.getName();
}
//时间戳
int currentTime = DateUtil.getCurrentTimeSecond();
String ts = requestBO.getTs();
if (StringUtils.isEmpty(ts)) {
ts = String.valueOf(DateUtil.getCurrentTimeSecond() * 1000);
}
String order = requestBO.getOrder();
String money = requestBO.getMoney();
... ... @@ -122,27 +177,27 @@ public class PinYouServiceImpl implements IPinYouService {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer = stringBuffer.append(PINYOU_TRANS_URL).append("a=")
.append(advertiser).append("&os=").append(os)
.append("&ts=").append(currentTime)
.append("&ts=").append(ts)
.append("&ip=").append(ip)
.append("&df=0").append("&order=").append(order)
.append("&money=").append(money)
.append("&plist=").append(plist);
String url = null;
if(client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())){
if (client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())) {
//如果是浏览商品和加入购物车则需要传p=商品编号
String dim = MD5.md5(imei);
stringBuffer = stringBuffer.append("&dim=").append(dim);
}
if(client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())){
if (client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())) {
String iam = MD5.md5(idfa);
stringBuffer = stringBuffer.append("&iam=").append(iam);
}
if(StringUtils.isNotEmpty(user_id)&& user_id.matches("[0-9]+")){
if (StringUtils.isNotEmpty(user_id) && user_id.matches("[0-9]+")) {
stringBuffer = stringBuffer.append("&user_id=").append(user_id);
}
if(orderStatus.equals("1")||orderStatus.equals("2")){
if (orderStatus.equals("1") || orderStatus.equals("2")) {
stringBuffer = stringBuffer.append("&gl=9466");
}else{
} else {
stringBuffer = stringBuffer.append("&gl=334");
}
url = stringBuffer.toString();
... ... @@ -150,9 +205,9 @@ public class PinYouServiceImpl implements IPinYouService {
return response;
}
private UnionResponse sendUrl(String url){
log.info("sendUrl url is {}",url);
try{
private UnionResponse sendUrl(String url) {
log.info("sendUrl url is {}", url);
try {
url = URLDecoder.decode(url, "UTF-8");
Pair<Integer, String> pair = HttpUtils.httpGet(url);
log.info("activateUnion call union success url={}, and result={}", url, pair);
... ... @@ -160,9 +215,9 @@ public class PinYouServiceImpl implements IPinYouService {
log.warn("callback error with request={}", url);
return new UnionResponse(204, "callback error");
}
}catch (Exception e){
} catch (Exception e) {
log.error("callback error with request={}", url, e.getMessage());
}
return new UnionResponse();
return new UnionResponse();
}
}
... ...
... ... @@ -31,7 +31,10 @@ public class PinYouTask {
@Autowired
private RedisListCache redisListCache;
@Scheduled(cron = "0/10 * * * * ?")
/**
* 每天早上6点执行
*/
@Scheduled(cron = "0 0 6 * * ?")
public void run(){
//从redis里面获取大数据的数据
Long viewSize = redisListCache.size(UNION_VIEW_KEY);
... ... @@ -54,32 +57,12 @@ public class PinYouTask {
}
}
// //将取出来的值按照品友的要求发给品友
// ViewPinYouRequestBO viewPinYouRequestBO = new ViewPinYouRequestBO();
// viewPinYouRequestBOList = new ArrayList<>();
// viewPinYouRequestBO.setImei("aea6497538a822838d07661b89a18c5e");
// viewPinYouRequestBO.setEvent("viewItem");
// viewPinYouRequestBO.setEvent_value("387650");
// viewPinYouRequestBO.setUser_id("1357821");
// viewPinYouRequestBO.setIp("172.16.6.153");
// viewPinYouRequestBO.setOs("iphone");
// viewPinYouRequestBOList.add(viewPinYouRequestBO);
if(CollectionUtils.isNotEmpty(viewPinYouRequestBOList)){
for(ViewPinYouRequestBO requestBO:viewPinYouRequestBOList){
sendView(requestBO);
}
}
// TransPinYouRequestBO transPinYouRequest = new TransPinYouRequestBO();
// transPinYouRequest.setImei("aea6497538a822838d07661b89a18c5e");
// transPinYouRequest.setOs("iphone");
// transPinYouRequest.setMoney("20");
// transPinYouRequest.setOrderStatus("1");
// transPinYouRequest.setPlist("2999,2;3000,3");
// transPinYouRequest.setIp("172.16.6.153");
// transPinYouRequest.setUser_id("13054");
// transPinYouRequest.setOrder("342321");
// transPinYouRequestBOList = new ArrayList<>();
// transPinYouRequestBOList.add(transPinYouRequest);
if(CollectionUtils.isNotEmpty(transPinYouRequestBOList)){
for(TransPinYouRequestBO transPinYouRequestBO:transPinYouRequestBOList){
sendTrans(transPinYouRequestBO);
... ... @@ -89,7 +72,7 @@ public class PinYouTask {
//给品友推送访问数据
private void sendView(ViewPinYouRequestBO requestBO){
pinYouService.sendViem(requestBO);
pinYouService.sendView(requestBO);
}
//给品友推送转化数据
... ...