数据对接相关

back_recharge
lvxinran 2020-07-08 10:14:50 +08:00
parent ac75b947d8
commit ef04e7f413
7 changed files with 285 additions and 3 deletions

View File

@ -0,0 +1,14 @@
package com.ljsd.jieling.ktbeans;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/7/7
* @discribe
*/
public interface IReportEvent {
Map<String,Object> getEventProperties(ReportEventEnum eventEnum,Object... param);
}

View File

@ -0,0 +1,67 @@
package com.ljsd.jieling.ktbeans;
import com.ljsd.jieling.ktbeans.reportEvent.CommonEventHandler;
import java.util.HashMap;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/7/7
* @discribe
*/
public enum ReportEventEnum {
CREATE_ACCOUNT(1,"create_account", new CommonEventHandler(),new String[]{""});
private int type;
private String eventName;
private IReportEvent eventHandler;
private String[] param;
ReportEventEnum(int type, String eventName, IReportEvent eventHandler,String[] param){
this.type = type;
this.eventName = eventName;
this.eventHandler = eventHandler;
this.param = param;
}
private static Map<Integer,ReportEventEnum> enumMap = new HashMap<>();
public static ReportEventEnum getReport(int type) {
if(enumMap.get(type)!=null){
return enumMap.get(type);
}
ReportEventEnum[] values = ReportEventEnum.values();
ReportEventEnum targetEnum = null;
for(ReportEventEnum value:values){
if(value.getType()!=type){
continue;
}
targetEnum = value;
}
if(targetEnum==null){
return null;
}
enumMap.put(type,targetEnum);
return targetEnum;
}
public int getType() {
return type;
}
public String getEventName() {
return eventName;
}
public IReportEvent getEventHandler() {
return eventHandler;
}
public String[] getParam() {
return param;
}
}

View File

@ -0,0 +1,84 @@
package com.ljsd.jieling.ktbeans;
import java.util.HashMap;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/7/7
* @discribe
*/
public class ReportUserEvent {
protected Map<String, Object> baseInfo = new HashMap<>();
protected Map<String, Object> eventInfo = new HashMap<>();
protected String eventName = "";
public ReportUserEvent setAccount_id(String accountId){
baseInfo.put("#account_id",accountId);
return this;
}
public ReportUserEvent setServer_id(String server_id){
baseInfo.put("server_id",server_id);
return this;
}
public ReportUserEvent setAccount(String account){
baseInfo.put("account",account);
return this;
}
public ReportUserEvent setRole_id(String role_id){
baseInfo.put("role_id",role_id);
return this;
}
public ReportUserEvent setRole_name(String role_name){
baseInfo.put("role_name",role_name);
return this;
}
public ReportUserEvent setGuild_name(String guild_name){
baseInfo.put("guild_name",guild_name);
return this;
}
public ReportUserEvent setGuild_id(String guild_id){
baseInfo.put("guild_id",guild_id);
return this;
}
public ReportUserEvent setGuild_level(int guild_level){
baseInfo.put("guild_level",guild_level);
return this;
}
public ReportUserEvent setVip_level(int vip_level){
baseInfo.put("vip_level",vip_level);
return this;
}public ReportUserEvent setCoins_amount(int coins_amount){
baseInfo.put("coins_amount",coins_amount);
return this;
}
public ReportUserEvent setDiamond_amount(int diamond_amount){
baseInfo.put("diamond_amount",diamond_amount);
return this;
}
public ReportUserEvent setFighting_capacity(int fighting_capacity){
baseInfo.put("fighting_capacity",fighting_capacity);
return this;
}
public Map<String, Object> getBaseInfo() {
return baseInfo;
}
public String getEventName() {
return eventName;
}
public Map<String, Object> getEventInfo() {
return eventInfo;
}
public void setEventInfo(Map<String, Object> eventInfo) {
this.eventInfo = eventInfo;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
}

View File

@ -0,0 +1,84 @@
package com.ljsd.jieling.ktbeans;
import cn.thinkingdata.tga.javasdk.ThinkingDataAnalytics;
import com.ljsd.GameApplication;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.logic.dao.GuilidManager;
import com.ljsd.jieling.logic.dao.Item;
import com.ljsd.jieling.logic.dao.root.GuildInfo;
import com.ljsd.jieling.logic.dao.root.User;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/7/7
* @discribe
*/
public class ReportUtil {
private static final String LOG_PATH = "";
private static ThinkingDataAnalytics ta = new ThinkingDataAnalytics(new ThinkingDataAnalytics.LoggerConsumer(LOG_PATH));
private static final int COIN_ID = 14;
private static final int DIAMOND_ID = 16;
//对外接口只有一个
public static void onReportEvent(User user,int type,Object... param) throws Exception {
ReportUserEvent reportUserEvent = userToReportBean(user);
//根据事件类型获取对应处理
ReportEventEnum report = ReportEventEnum.getReport(type);
if(report==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
//设置事件属性
Map<String, Object> eventProperties = report.getEventHandler().getEventProperties(report,param);
reportUserEvent.setEventInfo(eventProperties);
//设置事件名称
reportUserEvent.setEventName(report.getEventName());
//执行
doReport(reportUserEvent);
}
private static ReportUserEvent userToReportBean(User user){
ReportUserEvent reportUserEvent = new ReportUserEvent();
setBaseData(user,reportUserEvent);
return reportUserEvent;
}
private static void setBaseData(User user ,ReportUserEvent reportUserEvent){
int guildId = user.getPlayerInfoManager().getGuildId();
GuildInfo guildInfo = null;
if(guildId!=0){
guildInfo = GuilidManager.guildInfoMap.get(guildId);
}
Item coin = user.getItemManager().getItem(COIN_ID);
Item diamond = user.getItemManager().getItem(DIAMOND_ID);
reportUserEvent.setAccount_id(user.getPlayerInfoManager().getOpenId())
.setServer_id(String.valueOf(GameApplication.serverId))
.setAccount(user.getPlayerInfoManager().getOpenId())
.setRole_id(String.valueOf(user.getId()))
.setRole_name(user.getPlayerInfoManager().getNickName())
.setGuild_id(String.valueOf(guildId))
.setGuild_name(guildInfo==null?"":guildInfo.getName())
.setGuild_level(guildInfo==null?0:guildInfo.getLevel())
.setVip_level(user.getPlayerInfoManager().getVipLevel())
.setCoins_amount(coin==null?0:coin.getItemNum())
.setDiamond_amount(diamond==null?0:diamond.getItemNum())
.setFighting_capacity(user.getPlayerInfoManager().getMaxForce());
}
private static void doReport(ReportUserEvent reportUserEvent){
try {
//todo 访客id
ta.setSuperProperties(reportUserEvent.getBaseInfo());
ta.track("1000001","1000001",reportUserEvent.getEventName(),reportUserEvent.getEventInfo());
ta.flush();
} catch (Exception e) {
//异常处理
System.out.println("except:"+e);
}
}
}

View File

@ -44,8 +44,8 @@ public class ParamEventBean {
public ParamEventBean() { public ParamEventBean() {
} }
public ParamEventBean(int eveentType){ public ParamEventBean(int eventType){
add(eventTypeStringMap.get(eveentType)); add(eventTypeStringMap.get(eventType));
} }
public List<String> getEvent_s() { public List<String> getEvent_s() {

View File

@ -0,0 +1,30 @@
package com.ljsd.jieling.ktbeans.reportEvent;
import com.ljsd.jieling.ktbeans.IReportEvent;
import com.ljsd.jieling.ktbeans.ReportEventEnum;
import java.util.HashMap;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/7/7
* @discribe
*/
public class CommonEventHandler implements IReportEvent {
@Override
public Map<String, Object> getEventProperties(ReportEventEnum eventEnum, Object... param) {
Map<String, Object> resultMap = new HashMap<>();
if(param.length<1){
return null;
}
String[] paramName= eventEnum.getParam();
if(param.length!=paramName.length){
return null;
}
for(int i = 0 ; i <param.length;i++){
resultMap.put(paramName[i],param[i]);
}
return resultMap;
}
}

View File

@ -6,6 +6,8 @@ import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.globals.BIReason; import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.ktbeans.KtEventUtils; import com.ljsd.jieling.ktbeans.KtEventUtils;
import com.ljsd.jieling.ktbeans.ReportEventEnum;
import com.ljsd.jieling.ktbeans.ReportUtil;
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean; import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
import com.ljsd.jieling.logic.activity.ActivityLogic; import com.ljsd.jieling.logic.activity.ActivityLogic;
import com.ljsd.jieling.logic.activity.event.NewWelfareEvent; import com.ljsd.jieling.logic.activity.event.NewWelfareEvent;
@ -113,7 +115,8 @@ public class UserManager {
playerManager.setMaxForce(force); playerManager.setMaxForce(force);
user.getExpeditionManager().setExpeditionLeve(1); user.getExpeditionManager().setExpeditionLeve(1);
// user.getExpeditionManager().setForceSnap(force); // user.getExpeditionManager().setForceSnap(force);
KtEventUtils.onKtEvent(user, ParamEventBean.UserRegister); // KtEventUtils.onKtEvent(user, ParamEventBean.UserRegister);
ReportUtil.onReportEvent(user, ReportEventEnum.CREATE_ACCOUNT.getType());
} }