Commit d19ead05 by carrieyzzhang

get channel name from trackingio and demo data

parent db15d67e
......@@ -62,6 +62,7 @@
<receiver.host>172.31.30.1,172.31.22.39,172.31.22.38,172.31.4.0,172.31.3.123,172.31.16.68,172.31.30.154,172.31.26.177</receiver.host>
<receiver.port>8080</receiver.port>
<trackingio.url>http://52.80.113.103:8002</trackingio.url>
<demo.url>http://localhost:9010</demo.url>
<mail.host>smtp.exmail.qq.com</mail.host>
......@@ -168,6 +169,8 @@
<admin.url>http://localhost:9020</admin.url>
<receiver.host>ec2-54-223-170-25.cn-north-1.compute.amazonaws.com.cn</receiver.host>
<receiver.port>8081</receiver.port>
<trackingio.url>http://52.80.113.103:8002</trackingio.url>
<demo.url>http://localhost:9010</demo.url>
<mail.host>smtp.exmail.qq.com</mail.host>
......@@ -233,6 +236,7 @@
<report.url>http://internal-report-api-976419027.cn-north-1.elb.amazonaws.com.cn</report.url>
<admin.url>http://ec2-54-223-136-157.cn-north-1.compute.amazonaws.com.cn:8099</admin.url>
<trackingio.url>http://www.trackingio.com</trackingio.url>
<demo.url>http://localhost:9010</demo.url>
<receiver.host>172.31.30.1,172.31.22.39,172.31.22.38,172.31.4.0,172.31.3.123,172.31.16.68,172.31.30.154,172.31.27.121,172.31.17.216</receiver.host>
<receiver.port>8080</receiver.port>
......
......@@ -89,7 +89,7 @@ public class RetentionController {
userGroupStr, dimensionStr, reportView, interval, isDevice, retentiontype,isProfile);
userLogService.insertLog(loginAccount, LogEnumType.FIND.getCode(), LogEnumType.FIND.getName() + "留存明细报表",
"{\"eventinfo\":" + eventInfo + "}", app, OperateObjectEnumType.REPORT.getCode());
"{\"eventinfo\":\"" + eventInfo + "\"}", app, OperateObjectEnumType.REPORT.getCode());
if (result.isEmpty()) {
return ResultModel.ERROR(ResultStatus.NETWORK_ERROR);
......@@ -142,8 +142,14 @@ public class RetentionController {
Map<String, List> result = retentionService.retentionReport(startDate, endDate, isList, eventInfo, app, userGroupStr,
dimensionStr, reportView, interval, isDevice, loginAccount.getId(), retentiontype,isProfile);
userLogService.insertLog(loginAccount, LogEnumType.FIND.getCode(), LogEnumType.FIND.getName() + "留存报表",
"{\"eventinfo\":" + eventInfo + "}", app, OperateObjectEnumType.REPORT.getCode());
if (retentiontype.equals("define")) {
userLogService.insertLog(loginAccount, LogEnumType.FIND.getCode(), LogEnumType.FIND.getName() + "留存报表",
"{\"eventinfo\":" + eventInfo + "}", app, OperateObjectEnumType.REPORT.getCode());
} else {
userLogService.insertLog(loginAccount, LogEnumType.FIND.getCode(), LogEnumType.FIND.getName() + "留存报表",
"{\"eventinfo\":\"" + eventInfo + "\"}", app, OperateObjectEnumType.REPORT.getCode());
}
if (result.isEmpty()) {
return ResultModel.ERROR(ResultStatus.NETWORK_ERROR);
......
......@@ -207,15 +207,15 @@ public class ComplicatedEventsServiceImpl implements ComplicateEventsService{
//替换日期
querySql = replaceQueryParticleDate(querySql, startDate, endDate, viewType);
//demo账号处理
String demoApps = configParamService.getConfigParamByKey("demo_appkey");
List<String> demoAppList = Arrays.asList(demoApps.split(","));
String url = "";
if (demoAppList.contains(app.getAppkey())) {
url = Constant.demoUrl + "/api/trackingio/eventstats/complicated/" + app.getAppkey() + "/" + viewType;
}
//数据权限过滤
// Account account = accountRepository.findOne(accountId);
//demo账号
// if (demoAppList.contains(app.getAppkey())) {
// querySql = querySql.replace("$campaign","");
// }
//母账号、管理员、子账号管理员
querySql = querySql.replace("$campaign","");
System.out.println(1111);
......@@ -225,9 +225,9 @@ public class ComplicatedEventsServiceImpl implements ComplicateEventsService{
ExecutorService pool = Executors.newFixedThreadPool(2);
//创建两个有返回值的任务
EventReportCallable c1 = new EventReportCallable(conditions,selectList,groupJsonArray,
app,accountId,startDate,endDate,eventCondition,viewType);
app,accountId,startDate,endDate,eventCondition,viewType, url);
EventReportCallable c2 = new EventReportCallable(null,null,null,
app,accountId,startDate,endDate,eventCondition,viewType);
app,accountId,startDate,endDate,eventCondition,viewType, url);
//执行任务并获取Future对象
Future<Map<String, List>> f1 = pool.submit(c1);
Future<Map<String, List>> f2 = pool.submit(c2);
......
......@@ -959,12 +959,34 @@ public class EventServiceImpl implements EventService {
// String key = appKey+","+eventName+","+attrName+","+event.getDataType()+","+(event.isCommon() ? "1" : "0");
String key = String.format("%s,%s,%s,%s,%s", appKey, eventName, attrName, event.getDataType(), (event.isCommon() ? "1" : "0"));
Set<String> set = (Set<String>) EventRedisUtil.getInstance().get(key);
set.add("6043");
if (ValidateUtil.isValid(set)) {
List<String> list = new ArrayList<>();
for (String s : set) {
list.add(s);
}
result.put("value", list);
if (attrName.equals("_cid") || attrName.equals("_campaignid")) {
String values = String.join(",", set);
String url = Constant.trackingUrl + "/api/"+ app +"/event/find/valuespecail?attrName=" + attrName + "&values=" + values;
String response = HttpClientUtil.doHttpGetRequest(url, "io");
if (!StringUtil.isEmpty(response)) {
try {
JSONObject ob = new JSONObject(response);
JSONObject content = ob.getJSONObject("content");
ObjectMapper mapper = new ObjectMapper();
result = mapper.readValue(content.toString(), Map.class);
} catch (Exception e) {
result.put("value", list);
}
} else {
result.put("value", list);
}
} else {
result.put("value", list);
}
}
}
return result;
......@@ -995,24 +1017,29 @@ public class EventServiceImpl implements EventService {
if (!CollectionUtils.isEmpty(set)) {
List<String> valueList = new ArrayList<>(set);
if (attrName.equals("_cid") || attrName.equals("_campaignid")) {
String values = String.join(",", set);
String url = Constant.trackingUrl + "/api/"+ appId +"/event/find/valuespecail?attrName=" + attrName + "&values=" + values;
String response = HttpClientUtil.doHttpGetRequest(url, "io");
if (!StringUtil.isEmpty(response)) {
try {
JSONObject ob = new JSONObject(response);
JSONObject content = ob.getJSONObject("content");
ObjectMapper mapper = new ObjectMapper();
result = mapper.readValue(content.toString(), Map.class);
} catch (Exception e) {
result.put("value", valueList);
}
String values = String.join(",", set);
String url = Constant.trackingUrl + "/api/"+ appId +"/event/find/valuespecail?attrName=" + attrName + "&values=" + values;
String response = HttpClientUtil.doHttpGetRequest(url, "io");
if (!StringUtil.isEmpty(response)) {
try {
JSONObject ob = new JSONObject(response);
JSONObject content = ob.getJSONObject("content");
ObjectMapper mapper = new ObjectMapper();
result = mapper.readValue(content.toString(), Map.class);
} catch (Exception e) {
} else {
result.put("value", valueList);
}
} else {
result.put("value", valueList);
}
}
} else {
......
package com.reyun.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.reyun.dic.CustomMenuType;
import com.reyun.dic.LogEnumType;
import com.reyun.dic.OperateObjectEnumType;
......@@ -10,6 +11,7 @@ import com.reyun.service.*;
import com.reyun.taskexecute.ReportCallable;
import com.reyun.util.*;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -218,13 +220,38 @@ public class FunnelServiceImpl implements FunnelService {
}
if (isCompare) {
Map<String, String> dimentionMap = new HashMap<>();
if (dimentionKey.equals("_campaignid") || dimentionKey.equals("_cid")) {
String url = Constant.trackingUrl + "/api/"+ app.getId() +"/channel/findchannelcamp4io?appkey=" + app.getAppkey() + "&email=" + account.getEmail();
String response = HttpClientUtil.doHttpGetRequest(url, "io");
if (!StringUtil.isEmpty(response)) {
try {
JSONObject ob = JSONObject.fromObject(response);
JSONObject content = ob.getJSONObject("content");
if (dimentionKey.equals("_cid")) {
JSONObject channelObject = content.getJSONObject("channel");
ObjectMapper mapper = new ObjectMapper();
dimentionMap = mapper.readValue(channelObject.toString(), Map.class);
}
if (dimentionKey.equals("_campaignid")) {
JSONObject campObject = content.getJSONObject("campaign");
ObjectMapper mapper = new ObjectMapper();
dimentionMap = mapper.readValue(campObject.toString(), Map.class);
}
} catch (Exception e) {
logger.error("fail to get channel or campaign name");
}
}
}
//创建一个线程池
ExecutorService pool = Executors.newFixedThreadPool(2);
//创建两个有返回值的任务
ReportCallable c1 = new ReportCallable("funnel", totalSql, funnelObject, startDate, endDate, dimentionKey,
false, true, interval, "day", null, "", eventAliasMap, null, app.getAppkey());
false, true, interval, "day", null, "", eventAliasMap, null, app.getAppkey(), null);
ReportCallable c2 = new ReportCallable("funnel", sqlTemp, funnelObject, startDate, endDate, dimentionKey,
isCompare, false, interval, "day", usergroup, usergroupName, eventAliasMap, null, app.getAppkey());
isCompare, false, interval, "day", usergroup, usergroupName, eventAliasMap, null, app.getAppkey(), dimentionMap);
//执行任务并获取Future对象
Future<Map<String, List>> f1 = pool.submit(c1);
Future<Map<String, List>> f2 = pool.submit(c2);
......@@ -254,18 +281,32 @@ public class FunnelServiceImpl implements FunnelService {
conditions.put("reportname", "funnel");
conditions.put("appid", app.getAppkey());
Map<String, List> responseJson = new HashMap<>();
Map<String, List> responseJson = reportService.reportBySql(conditions);
if (demoAppList.contains(app.getAppkey())) {
List<String> events = Arrays.asList(funnelObject.getEvents().split(","));
String url = Constant.demoUrl + "/api/trackingio/funnel/" + events.size() + "/" + app.getAppkey();
url += "/30";
try {
String responseStr = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
ObjectMapper mapper = new ObjectMapper();
responseJson = mapper.readValue(responseStr, Map.class);
} catch (Exception e) {
logger.error("fail to get demo data......");
}
} else {
responseJson = reportService.reportBySql(conditions);
}
result = SqlUtil.format4Funnel(responseJson, Arrays.asList(funnelObject.getEvents().split(",")), isCompare,
dimentionKey, startDate, endDate, false, usergroup, usergroupName, eventAliasMap, null);
dimentionKey, startDate, endDate, false, usergroup, usergroupName, eventAliasMap, null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(result);
return result;
}
......@@ -336,7 +377,7 @@ public class FunnelServiceImpl implements FunnelService {
result = SqlUtil.format4Funnel(responseJson, Arrays.asList(events.split(",")), false, "", startDate,
endDate, false, "", "", eventAliasMap, null);
endDate, false, "", "", eventAliasMap, null, null);
} catch (Exception e) {
e.printStackTrace();
......
......@@ -14,6 +14,7 @@ import com.reyun.service.EventService;
import com.reyun.service.IntelligentPathService;
import com.reyun.service.ReportService;
import com.reyun.util.Constant;
import com.reyun.util.HttpClientUtil;
import com.reyun.util.SqlUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
......@@ -156,12 +157,25 @@ public class IntelligentPathServiceImpl implements IntelligentPathService {
conditions.put("reportname", "intelligentPath");
conditions.put("appid", app.getAppkey());
Map<String, List> responseJson = reportService.reportBySql(conditions);
//demo账号处理
String demoApps = configparamService.getConfigParamByKey("demo_appkey");
List<String> demoAppList = Arrays.asList(demoApps.split(","));
Map<String, List> responseJson = new HashMap<>();
//demo账号处理
if (demoAppList.contains(appKey)) {
try {
String url = Constant.demoUrl + "/api/trackingio/intelligentPath/" + appKey;
String responseStr = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
ObjectMapper mapper = new ObjectMapper();
responseJson = mapper.readValue(responseStr, Map.class);
} catch (Exception e) {
logger.error("fail to get demo data......");
}
} else {
responseJson = reportService.reportBySql(conditions);
}
try {
List<Map<String, Object>> valueList = responseJson.get("val");
if (!CollectionUtils.isEmpty(valueList)) {
......
......@@ -253,6 +253,9 @@ public class RetentionServiceImpl implements RetentionService {
sqlTemp = chooseVirtualEvent(retentiontype, app, eventInfo, appObject, reportView);
//数据权限过滤
String demoApps = configparamService.getConfigParamByKey("demo_appkey");
List<String> demoAppList = Arrays.asList(demoApps.split(","));
sqlTemp = sqlTemp.replace("$campaign","");
if (!"install".equals(retentiontype)) {
......@@ -428,6 +431,33 @@ public class RetentionServiceImpl implements RetentionService {
dimentionKey = "usergroup";
}
Map<String, String> dimentionMap = new HashMap<>();
if (dimentionKey.equals("_campaignid") || dimentionKey.equals("_cid")) {
Account accountObject = accountRepository.findOne(account);
String url = Constant.trackingUrl + "/api/"+ app +"/channel/findchannelcamp4io?appkey=" + appObject.getAppkey() + "&email=" + accountObject.getEmail();
String response = HttpClientUtil.doHttpGetRequest(url, "io");
if (!StringUtil.isEmpty(response)) {
try {
JSONObject ob = JSONObject.fromObject(response);
JSONObject content = ob.getJSONObject("content");
if (dimentionKey.equals("_cid")) {
JSONObject channelObject = content.getJSONObject("channel");
ObjectMapper mapper = new ObjectMapper();
dimentionMap = mapper.readValue(channelObject.toString(), Map.class);
}
if (dimentionKey.equals("_campaignid")) {
JSONObject campObject = content.getJSONObject("campaign");
ObjectMapper mapper = new ObjectMapper();
dimentionMap = mapper.readValue(campObject.toString(), Map.class);
}
} catch (Exception e) {
logger.error("fail to get channel or campaign name");
}
}
}
if ("-all".equals(dimention)) {
sqlTemp = new String(totalSql);
}
......@@ -437,9 +467,9 @@ public class RetentionServiceImpl implements RetentionService {
ExecutorService pool = Executors.newFixedThreadPool(2);
// 创建两个有返回值的任务
ReportCallable c1 = new ReportCallable("retention", totalSql, null, startDate, endDate, dimentionKey, isCompare, true,
interval, reportView, null, "", null, null, appObject.getAppkey());
interval, reportView, null, "", null, null, appObject.getAppkey(), null);
ReportCallable c2 = new ReportCallable("retention", sqlTemp, null, startDate, endDate, dimentionKey, isCompare, false,
interval, reportView, usergroup, usergroupName, null, null, appObject.getAppkey());
interval, reportView, usergroup, usergroupName, null, null, appObject.getAppkey(), dimentionMap);
// 执行任务并获取Future对象
Future<Map<String, List>> f1 = pool.submit(c1);
Future<Map<String, List>> f2 = pool.submit(c2);
......@@ -467,9 +497,28 @@ public class RetentionServiceImpl implements RetentionService {
conditions.put("reportname", "retention");
conditions.put("appid", appObject.getAppkey());
Map<String, List> responseJson = reportService.reportBySql(conditions);
Map<String, List> responseJson = new HashMap<>();
result = SqlUtil.format4Retention(responseJson, interval, dimentionKey, reportView, usergroup, usergroupName, null);
String url = "";
if (demoAppList.contains(appObject.getAppkey())) {
try {
url = Constant.demoUrl + "/api/trackingio/retentionall/" + appObject.getAppkey();
url = getDemoReportUrlByView(url, reportView);
String responseStr = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
ObjectMapper mapper = new ObjectMapper();
responseJson = mapper.readValue(responseStr, Map.class);
} catch (Exception e) {
logger.error("fail to get demo data......");
}
} else {
responseJson = reportService.reportBySql(conditions);
}
result = SqlUtil.format4Retention(responseJson, interval, dimentionKey, reportView, usergroup, usergroupName, null, null);
}
} catch (Exception e) {
......@@ -479,6 +528,27 @@ public class RetentionServiceImpl implements RetentionService {
return result;
}
/**
* 获取DEMO账号的REPORT URL
* created by sunhao 20170517
*/
private String getDemoReportUrlByView(String url, String reportView) {
switch (reportView) {
case "day":
url += "/day/14";
break;
case "week":
url += "/week/12";
break;
case "month":
url += "/month/6";
break;
}
return url;
}
@Override
public Map<String, List> retentionDetailReport(Account loginAccount, String startDate, String endDate, boolean isList, String eventInfo, Long app,
String usergroup, String dimention, String reportView, int interval, boolean isDevice, String retentiontype, boolean isProfile) {
......@@ -668,7 +738,19 @@ public class RetentionServiceImpl implements RetentionService {
Map<String, List> result = new HashMap<>();
try {
Map<String, List> responseJson = reportService.reportBySql(conditions);
Map<String, List> responseJson =new HashMap<>();
String demoApps = configparamService.getConfigParamByKey("demo_appkey");
List<String> demoAppList = Arrays.asList(demoApps.split(","));
if (demoAppList.contains(appObject.getAppkey())) {
String url = Constant.demoUrl + "/api/trackingio/retentiondetail/" + appObject.getAppkey();
url = getDemoReportUrlByView(url, reportView);
String responseStr = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
ObjectMapper mapper = new ObjectMapper();
responseJson = mapper.readValue(responseStr, Map.class);
} else {
responseJson = reportService.reportBySql(conditions);
}
result = SqlUtil.format4DetailList(responseJson, startDate, interval, reportView);
} catch (Exception e) {
......@@ -677,7 +759,7 @@ public class RetentionServiceImpl implements RetentionService {
result.put("val", val);
result.put("columnkey", columnkey);
result.put("name", columnkey);
e.printStackTrace();
logger.debug("fail to get retention detail data.......");
}
return result;
}
......
package com.reyun.taskexecute;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.reyun.context.AppUtils;
import com.reyun.model.App;
import com.reyun.service.ReportService;
import com.reyun.service.impl.ComplicatedEventsServiceImpl;
import com.reyun.util.HttpClientUtil;
import com.reyun.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
......@@ -34,9 +37,11 @@ public class EventReportCallable implements Callable<Map<String, List>> {
private String eventCondition;
private String viewType;
private String url;
private Map<String, List> result;
public EventReportCallable(Map<String, String> conditions, List<JSONObject> selectList, JSONArray groupJsonArray, App app, Long accountid, String startDate, String endDate, String eventCondition, String viewType) {
public EventReportCallable(Map<String, String> conditions, List<JSONObject> selectList, JSONArray groupJsonArray, App app, Long accountid, String startDate, String endDate, String eventCondition, String viewType, String url) {
this.conditions = conditions;
this.selectList = selectList;
this.groupJsonArray = groupJsonArray;
......@@ -46,17 +51,32 @@ public class EventReportCallable implements Callable<Map<String, List>> {
this.endDate = endDate;
this.eventCondition = eventCondition;
this.viewType = viewType;
this.url = url;
}
@Override
public Map<String, List> call() throws Exception {
if(null != conditions){
Map<String, List> responseJson = reportService.reportBySql(conditions);
Map<String, List> responseJson = new HashMap<>();
if (StringUtil.isEmpty(this.url)) {
responseJson = reportService.reportBySql(conditions);
} else {
try {
String responseStr = HttpClientUtil.doHttpPostRequest(url, "trackingio", conditions);
ObjectMapper mapper = new ObjectMapper();
responseJson = mapper.readValue(responseStr, Map.class);
} catch (Exception e) {
logger.error("fail to get demo data......");
}
}
//获取时间范围内按照时间粒度的所有日期
Map<String, String> dateStringMap = eventStatsService.getDateMapByViewFlag(startDate, endDate, viewType);
//格式化数据
result = eventStatsService.formatComplicatedEventResponse(app, accountid, responseJson, dateStringMap, groupJsonArray, selectList);
}else{
//查询合计
List<JSONObject> totalValue = eventStatsService.queryDistinctTotalData(app.getId(), accountid, startDate, endDate, eventCondition, viewType);
......
package com.reyun.taskexecute;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.reyun.context.AppUtils;
import com.reyun.dic.ReportEnumType;
import com.reyun.model.Funnel;
import com.reyun.service.ConfigParamService;
import com.reyun.service.EventStatsService;
import com.reyun.service.ReportService;
import com.reyun.util.Constant;
import com.reyun.util.HttpClientUtil;
import com.reyun.util.SqlUtil;
import com.reyun.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -25,6 +29,7 @@ public class ReportCallable implements Callable<Map<String, List>> {
private EventStatsService eventStatsService = AppUtils.getApplicationContext().getBean(EventStatsService.class);
private ReportService reportService = AppUtils.getApplicationContext().getBean(ReportService.class);
private ConfigParamService configparamService = AppUtils.getApplicationContext().getBean(ConfigParamService.class);
private String sql;
private Funnel funnel;
private String startDate;
......@@ -49,7 +54,7 @@ public class ReportCallable implements Callable<Map<String, List>> {
public ReportCallable(String reportType, String sql, Funnel funnel, String startDate, String endDate, String dimensionKey, boolean isCompare,
boolean isTotal, int interval, String reportView, String userGroup, String userGroupName,
Map<String, String> eventAliasMap, String dimensionValue, String appKey) {
Map<String, String> eventAliasMap, String dimensionValue, String appKey, Map<String, String> dimensionMap) {
super();
this.reportType = reportType;
this.sql = sql;
......@@ -66,6 +71,7 @@ public class ReportCallable implements Callable<Map<String, List>> {
this.eventAliasMap = eventAliasMap;
this.dimensionValue = dimensionValue;
this.appKey = appKey;
this.dimensionMap = dimensionMap;
}
public ReportCallable(String reportType, String sql, String dimensionKey, String startDate, String endDate, String reportView, Long appId, String appKey, Long accountId, String dimentioinValue) {
......@@ -96,6 +102,44 @@ public class ReportCallable implements Callable<Map<String, List>> {
conditions.put("datatype", ReportEnumType.LIST.getCode());
conditions.put("appid", appKey);
String demoApps = configparamService.getConfigParamByKey("demo_appkey");
List<String> demoAppList = Arrays.asList(demoApps.split(","));
StringBuilder url = null;
//DEMO账号处理
if (demoAppList.contains(appKey)) {
switch (reportType) {
case "funnel":
List<String> events = Arrays.asList(funnel.getEvents().split(","));
url = new StringBuilder(Constant.demoUrl + "/api/trackingio/funnel/").append(events.size()).append("/")
.append(appKey).append((isTotal || StringUtil.isEmpty(dimensionKey) ? "" : "/" + dimensionKey));
url.append("/30");
break;
case "retention":
url = new StringBuilder(Constant.demoUrl + "/api/trackingio/retentionall/").append(appKey);
switch (reportView) {
case "week":
url.append("/week/12");
break;
case "month":
url.append("/month/6");
break;
default:
url.append("/day/14");
break;
}
url.append(isTotal || StringUtil.isEmpty(dimensionKey) ? "" : "/" + dimensionKey);
break;
case "eventstats":
url = new StringBuilder(Constant.demoUrl + "/api/trackingio/eventstats/" + appKey + "/" + reportView);
if (!dimensionKey.equals("total")) {
url.append("/" + dimensionKey);
}
break;
}
}
switch (reportType) {
......@@ -111,19 +155,34 @@ public class ReportCallable implements Callable<Map<String, List>> {
break;
}
//请求数据
Map<String, List> responseJson = reportService.reportBySql(conditions);
Map<String, List> responseJson = new HashMap<>();
if (url == null) {
try {
String responseStr = HttpClientUtil.doHttpPostRequest(url.toString(), "trackingio", conditions);
ObjectMapper mapper = new ObjectMapper();
responseJson = mapper.readValue(responseStr, Map.class);
} catch (Exception e) {
logger.error("fail to get demo data......");
}
} else {
//请求数据
responseJson = reportService.reportBySql(conditions);
}
//结果处理
switch (reportType) {
case "funnel":
result = SqlUtil.format4Funnel(responseJson, Arrays.asList(funnel.getEvents().split(",")), isCompare, dimensionKey,
startDate, endDate, isTotal, this.userGroup, this.userGroupName, this.eventAliasMap, dimensionValue);
startDate, endDate, isTotal, this.userGroup, this.userGroupName, this.eventAliasMap, dimensionValue, dimensionMap);
break;
case "retention":
result = SqlUtil.format4Retention(responseJson, this.interval, dimensionKey, this.reportView, this.userGroup,
this.userGroupName, dimensionValue);
this.userGroupName, dimensionValue, dimensionMap);
break;
case "eventstats":
......
......@@ -38,6 +38,7 @@ public class Constant {
public static String iscache = commonBundle.getString("iscache");
public static String receiverHost = commonBundle.getString("receiver.host");
public static String receiverPort = commonBundle.getString("receiver.port");
public static String demoUrl = commonBundle.getString("demo.url");
......
......@@ -350,6 +350,8 @@ public class SqlUtil
e.printStackTrace();
}
System.out.println(result);
return result;
}
......@@ -358,7 +360,7 @@ public class SqlUtil
*/
public static Map<String, List> format4Funnel(Map<String, List> response, List<String> eventList, boolean isCompare, String dimension,
String startDate, String endDate, boolean isTotal, String userGroup,
String userGroupName, Map<String, String> eventAlisMap, String dimensionValue)
String userGroupName, Map<String, String> eventAlisMap, String dimensionValue, Map<String, String> dimensionMap)
{
Map<String, List> result = new HashMap<>();
......@@ -394,8 +396,14 @@ public class SqlUtil
if (valArray.size() > 0) {
if (StringUtil.isEmpty(userGroup)) {
dimensionValueList.add(val.get(dimension).toString());
innerMap.put(dimension, val.get(dimension));
if (dimension.equals("_campaignid") || dimension.equals("_cid")) {
String dv = dimensionMap.containsKey(val.get(dimension).toString()) ? dimensionMap.get(val.get(dimension).toString()) : val.get(dimension).toString();
dimensionValueList.add(dv);
innerMap.put(dimension, dv);
} else {
dimensionValueList.add(val.get(dimension).toString());
innerMap.put(dimension, val.get(dimension));
}
}
else {
innerMap.put(dimension, userGroupName);
......@@ -702,7 +710,7 @@ public class SqlUtil
* 格式化来自报表系统的留存数据
*/
public static Map<String, List> format4Retention(Map<String, List> response, int interval, String dimension, String reportView, String userGroup,
String userGroupName, String dimensionValues)
String userGroupName, String dimensionValues, Map<String, String> dimensionMap)
{
Map<String, List> result = new HashMap<>();
......@@ -731,7 +739,11 @@ public class SqlUtil
}
else if (k.equals(dimension)) {
dimensionValue = valueMap.get(k).toString();
if (dimension.equals("_campaignid") || dimension.equals("_cid")) {
dimensionValue = dimensionMap.containsKey(valueMap.get(k).toString()) ? dimensionMap.get(valueMap.get(k).toString()) : valueMap.get(k).toString();
} else {
dimensionValue = valueMap.get(k).toString();
}
dimensionKey = valueMap.get(k).toString();
dimensionValueList.add(dimensionValue);
}
......
......@@ -9,4 +9,5 @@ report.url=${report.url}
awsneed=${awsneed}
iscache=${iscache}
admin.url=${admin.url}
trackingio.url=${trackingio.url}
\ No newline at end of file
trackingio.url=${trackingio.url}
demo.url=${demo.url}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment