...
|
...
|
@@ -3,18 +3,18 @@ package com.yoho.unions.channel.service.impl; |
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.service.model.union.request.MktReportFormReqVO;
|
|
|
import com.yoho.service.model.union.response.MktReportFormRspBO;
|
|
|
import com.yoho.service.model.union.response.PageMktReportFormRspBO;
|
|
|
import com.yoho.unions.channel.service.IMktCostReportFormService;
|
|
|
import com.yoho.unions.dal.IAppActiveDAO;
|
|
|
import com.yoho.unions.dal.IMktReportFormDAO;
|
|
|
import com.yoho.unions.dal.model.AppActive;
|
|
|
import com.yoho.unions.dal.model.MktReportForm;
|
|
|
import com.yoho.unions.dal.model.MktReportWithAppActive;
|
|
|
import com.yoho.unions.dal.model.MktReportBean;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -33,8 +33,6 @@ public class MktCostReportFormServiceImpl implements IMktCostReportFormService { |
|
|
|
|
|
@Override
|
|
|
public MktReportFormRspBO getMktReportForm(MktReportFormReqVO reportFormReqVO) {
|
|
|
MktReportFormRspBO pageMktReportFormRspBO = new MktReportFormRspBO();
|
|
|
|
|
|
//从APP_ACTIVE中获取数据
|
|
|
Map<String, Integer> queryParam = new HashMap<>();
|
|
|
queryParam.put("beginTime", reportFormReqVO.getBeginTime());
|
...
|
...
|
@@ -43,54 +41,223 @@ public class MktCostReportFormServiceImpl implements IMktCostReportFormService { |
|
|
List<AppActive> appActiveList = appActiveDAO.selectActivationAndActualCostByDateId(queryParam);
|
|
|
List<MktReportForm> mktReportFormList = mktReportFormDAO.selectMktReportFormByDateId(queryParam);
|
|
|
|
|
|
List<String> dateIdStrList = Lists.newArrayList();
|
|
|
List<String> totalActualCostList = Lists.newArrayList();
|
|
|
List<String> iosActualCostList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
// List<String> dateIdStrList = Lists.newArrayList();
|
|
|
|
|
|
// int resultSize = appActiveList.size() > mktReportFormList.size() ? appActiveList.size() : mktReportFormList.size();
|
|
|
//
|
|
|
//
|
|
|
// if ((!appActiveList.isEmpty()) && (!mktReportFormList.isEmpty())){
|
|
|
// boolean flag = appActiveList.size() > mktReportFormList.size() ? true : false;
|
|
|
// if (flag){
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
Map<Integer, MktReportBean> resultMap = mergeData(appActiveList, mktReportFormList);
|
|
|
|
|
|
MktReportFormRspBO rspBO = composingResult(resultMap);
|
|
|
|
|
|
return rspBO;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, MktReportBean> mergeData(List<AppActive> appActiveList, List<MktReportForm> mktReportFormList) {
|
|
|
Map<Integer, MktReportBean> resultMap = new TreeMap<>();
|
|
|
|
|
|
if ((!appActiveList.isEmpty()) && !mktReportFormList.isEmpty())
|
|
|
{
|
|
|
setValueToMapForAppActive(resultMap, appActiveList);
|
|
|
|
|
|
for (MktReportForm mktReportForm : mktReportFormList){
|
|
|
Integer dateId = mktReportForm.getDateId();
|
|
|
MktReportBean mktReportBean = null;
|
|
|
if (!resultMap.containsKey(dateId)){
|
|
|
mktReportBean = new MktReportBean();
|
|
|
setMktReportData(mktReportForm, mktReportBean);
|
|
|
} else {
|
|
|
mktReportBean = resultMap.get(mktReportForm.getDateId());
|
|
|
setMktReportData(mktReportForm, mktReportBean);
|
|
|
}
|
|
|
|
|
|
resultMap.put(dateId, mktReportBean);
|
|
|
}
|
|
|
} else if (!appActiveList.isEmpty()){
|
|
|
setValueToMapForAppActive(resultMap, appActiveList);
|
|
|
} else if (!mktReportFormList.isEmpty()){
|
|
|
setValueToMapForMktReportForm(resultMap, mktReportFormList);
|
|
|
} else {
|
|
|
resultMap = null;
|
|
|
}
|
|
|
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
private void mergeData(List<AppActive> appActiveList, List<MktReportForm> mktReportFormList){
|
|
|
List<MktReportWithAppActive> mktReportWithAppActiveList = Lists.newArrayList();
|
|
|
Set<Integer> dateIdSet = new TreeSet<>();
|
|
|
private void setValueToMapForAppActive(Map<Integer, MktReportBean> resultMap, List<AppActive> appActiveList){
|
|
|
for (AppActive appActive : appActiveList) {
|
|
|
Integer dateId = appActive.getDateId();
|
|
|
MktReportBean mktReportBean = new MktReportBean();
|
|
|
setAppActiveData(appActive, mktReportBean);
|
|
|
resultMap.put(dateId, mktReportBean);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void setValueToMapForMktReportForm(Map<Integer, MktReportBean> resultMap, List<MktReportForm> mktReportFormList){
|
|
|
for (MktReportForm mktReportForm : mktReportFormList) {
|
|
|
Integer dateId = mktReportForm.getDateId();
|
|
|
MktReportBean mktReportBean = new MktReportBean();
|
|
|
setMktReportData(mktReportForm, mktReportBean);
|
|
|
resultMap.put(dateId, mktReportBean);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (AppActive active : appActiveList){
|
|
|
dateIdSet.add(active.getDateId());
|
|
|
private void setAppActiveData(AppActive appActive, MktReportBean mktReportBean){
|
|
|
if (null != appActive){
|
|
|
if ("yohobuy_ios".equals(appActive.getAppKey())){
|
|
|
mktReportBean.setIosAppActive(appActive.getAppActive());
|
|
|
mktReportBean.setIosNewUdid(appActive.getNewUdid());
|
|
|
} else if ("yohobuy_android".equals(appActive.getAppKey())){
|
|
|
mktReportBean.setAndroidAppActive(appActive.getAppActive());
|
|
|
mktReportBean.setAndroidNewUdid(appActive.getNewUdid());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (MktReportForm mktReportForm : mktReportFormList){
|
|
|
dateIdSet.add(mktReportForm.getDateId());
|
|
|
private void setMktReportData(MktReportForm mktReportForm, MktReportBean mktReportBean){
|
|
|
if (null != mktReportForm){
|
|
|
if (1 == mktReportForm.getDeviceType()){
|
|
|
mktReportBean.setIosActualCost(mktReportForm.getActualCost());
|
|
|
mktReportBean.setIosExposureNum(mktReportForm.getExposureNum());
|
|
|
} else if (2 == mktReportForm.getDeviceType()){
|
|
|
mktReportBean.setAndroidActualCost(mktReportForm.getActualCost());
|
|
|
mktReportBean.setAndroidExposureNum(mktReportForm.getExposureNum());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private MktReportFormRspBO composingResult(Map<Integer, MktReportBean> resultMap){
|
|
|
List<String> dateIdStrList = Lists.newArrayList();
|
|
|
List<BigDecimal> totalActualCostList = Lists.newArrayList();
|
|
|
List<BigDecimal> iosActualCostList = Lists.newArrayList();
|
|
|
List<BigDecimal> androidActualCostList = Lists.newArrayList();
|
|
|
List<Integer> totalAppActiveList = Lists.newArrayList();
|
|
|
List<Integer> iosAppActiveList = Lists.newArrayList();
|
|
|
List<Integer> androidAppActiveList = Lists.newArrayList();
|
|
|
List<Integer> totalExposureNumList = Lists.newArrayList();
|
|
|
List<Integer> iosExposureNumList = Lists.newArrayList();
|
|
|
List<Integer> androidExposureNumList = Lists.newArrayList();
|
|
|
List<Integer> totalNewUserList = Lists.newArrayList();
|
|
|
List<Integer> iosNewUserList = Lists.newArrayList();
|
|
|
List<Integer> androidNewUserList = Lists.newArrayList();
|
|
|
List<BigDecimal> totalActiveRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> iosActiveRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> androidActiveRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> totalExposureRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> iosExposureRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> androidExposureRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> totalNewUdidRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> iosNewUdidRatioList = Lists.newArrayList();
|
|
|
List<BigDecimal> androidNewUdidRatioList = Lists.newArrayList();
|
|
|
|
|
|
Iterator it = resultMap.keySet().iterator();
|
|
|
while (it.hasNext()){
|
|
|
Integer dateId = (Integer) it.next();
|
|
|
MktReportBean mktReportBean = resultMap.get(dateId);
|
|
|
|
|
|
//日期
|
|
|
dateIdStrList.add(dateId.toString());
|
|
|
|
|
|
|
|
|
//实际费用
|
|
|
iosActualCostList.add(mktReportBean.getIosActualCost());
|
|
|
androidActualCostList.add(mktReportBean.getAndroidActualCost());
|
|
|
BigDecimal totalActualCost = mktReportBean.getIosActualCost().add(mktReportBean.getAndroidActualCost());
|
|
|
totalActualCostList.add(totalActualCost);
|
|
|
|
|
|
int minDateId = appActiveList.get(0).getDateId() < mktReportFormList.get(0).getDateId() ? appActiveList.get(0).getDateId() : mktReportFormList.get(0).getDateId();
|
|
|
int maxDateId = appActiveList.get(appActiveList.size() - 1).getDateId() > mktReportFormList.get(mktReportFormList.size() - 1).getDateId() ? appActiveList.get(appActiveList.size() - 1).getDateId() : mktReportFormList.get(mktReportFormList.size() - 1).getDateId();
|
|
|
//曝光数
|
|
|
iosExposureNumList.add(mktReportBean.getIosExposureNum());
|
|
|
androidExposureNumList.add(mktReportBean.getAndroidExposureNum());
|
|
|
Integer totalExposureNum = mktReportBean.getIosExposureNum() +mktReportBean.getAndroidExposureNum();
|
|
|
totalExposureNumList.add(totalExposureNum);
|
|
|
|
|
|
//激活数
|
|
|
iosAppActiveList.add(mktReportBean.getIosAppActive());
|
|
|
androidAppActiveList.add(mktReportBean.getAndroidAppActive());
|
|
|
Integer totalAppActive = mktReportBean.getIosAppActive() + mktReportBean.getAndroidAppActive();
|
|
|
totalAppActiveList.add(totalAppActive);
|
|
|
|
|
|
//新客数
|
|
|
iosNewUserList.add(mktReportBean.getIosNewUdid());
|
|
|
androidNewUserList.add(mktReportBean.getAndroidNewUdid());
|
|
|
Integer totalNewUser = mktReportBean.getIosNewUdid() + mktReportBean.getAndroidNewUdid();
|
|
|
totalNewUserList.add(totalNewUser);
|
|
|
|
|
|
//激活转化率
|
|
|
iosActiveRatioList.add(getDivideData(mktReportBean.getIosActualCost(), new BigDecimal(mktReportBean.getIosAppActive())));
|
|
|
androidActiveRatioList.add(getDivideData(mktReportBean.getAndroidActualCost(), new BigDecimal(mktReportBean.getAndroidAppActive())));
|
|
|
totalActiveRatioList.add(getDivideData(totalActualCost, new BigDecimal(totalAppActive)));
|
|
|
|
|
|
//曝光转化率
|
|
|
iosExposureRatioList.add(getDivideData(mktReportBean.getIosActualCost(), new BigDecimal(mktReportBean.getIosExposureNum())));
|
|
|
androidExposureRatioList.add(getDivideData(mktReportBean.getAndroidActualCost(), new BigDecimal(mktReportBean.getAndroidExposureNum())));
|
|
|
iosExposureRatioList.add(getDivideData(totalActualCost, new BigDecimal(totalExposureNum)));
|
|
|
|
|
|
//新客转化率
|
|
|
iosNewUdidRatioList.add(getDivideData(mktReportBean.getIosActualCost(), new BigDecimal(mktReportBean.getIosNewUdid())));
|
|
|
androidNewUdidRatioList.add(getDivideData(mktReportBean.getAndroidActualCost(), new BigDecimal(mktReportBean.getAndroidNewUdid())));
|
|
|
iosNewUdidRatioList.add(getDivideData(totalActualCost, new BigDecimal(totalNewUser)));
|
|
|
}
|
|
|
|
|
|
MktReportFormRspBO mktReportFormRspBO = new MktReportFormRspBO();
|
|
|
|
|
|
//日期
|
|
|
mktReportFormRspBO.setDateIdStrList(dateIdStrList);
|
|
|
|
|
|
//实际费用
|
|
|
mktReportFormRspBO.setIosActualCostList(iosActualCostList);
|
|
|
mktReportFormRspBO.setAndroidActualCostList(androidActualCostList);
|
|
|
mktReportFormRspBO.setTotalActualCostList(totalActualCostList);
|
|
|
|
|
|
//曝光量
|
|
|
mktReportFormRspBO.setIosExposureNumList(iosExposureNumList);
|
|
|
mktReportFormRspBO.setAndroidExposureNumList(androidExposureNumList);
|
|
|
mktReportFormRspBO.setTotalExposureNumList(totalExposureNumList);
|
|
|
|
|
|
//激活量
|
|
|
mktReportFormRspBO.setIosAppActiveList(iosAppActiveList);
|
|
|
mktReportFormRspBO.setAndroidAppActiveList(androidAppActiveList);
|
|
|
mktReportFormRspBO.setTotalAppActiveList(totalAppActiveList);
|
|
|
|
|
|
//新客量
|
|
|
mktReportFormRspBO.setIosNewUserList(iosNewUserList);
|
|
|
mktReportFormRspBO.setAndroidNewUserList(androidNewUserList);
|
|
|
mktReportFormRspBO.setTotalNewUserList(totalNewUserList);
|
|
|
|
|
|
//曝光转化率
|
|
|
mktReportFormRspBO.setIosExposureRatioList(iosExposureRatioList);
|
|
|
mktReportFormRspBO.setAndroidExposureRatioList(androidExposureRatioList);
|
|
|
mktReportFormRspBO.setTotalExposureRatioList(totalExposureRatioList);
|
|
|
|
|
|
//激活转化率
|
|
|
mktReportFormRspBO.setIosActiveRatioList(iosActiveRatioList);
|
|
|
mktReportFormRspBO.setAndroidActiveRatioList(androidActiveRatioList);
|
|
|
mktReportFormRspBO.setTotalActiveRatioList(totalActiveRatioList);
|
|
|
|
|
|
//新客转化率
|
|
|
mktReportFormRspBO.setIosNewUdidRatioList(iosNewUdidRatioList);
|
|
|
mktReportFormRspBO.setAndroidNewUdidRatioList(androidNewUdidRatioList);
|
|
|
mktReportFormRspBO.setTotalNewUdidRatioList(totalNewUdidRatioList);
|
|
|
|
|
|
BigDecimal topRatio = Collections.max(totalExposureRatioList);
|
|
|
if (topRatio.compareTo(Collections.max(totalActiveRatioList)) < 0)
|
|
|
{
|
|
|
topRatio = Collections.max(totalActiveRatioList);
|
|
|
} else if (topRatio.compareTo(Collections.max(totalNewUdidRatioList)) < 0){
|
|
|
topRatio = Collections.max(totalNewUdidRatioList);
|
|
|
}
|
|
|
mktReportFormRspBO.setTopRatio(topRatio);
|
|
|
|
|
|
Integer topExActNew = Collections.max(totalAppActiveList);
|
|
|
if (topExActNew < Collections.max(totalExposureNumList)){
|
|
|
topExActNew = Collections.max(totalExposureNumList);
|
|
|
} else if (topExActNew < Collections.max(totalNewUserList)){
|
|
|
topExActNew = Collections.max(totalNewUserList);
|
|
|
}
|
|
|
mktReportFormRspBO.setTopExposureActiveNewUdid(topExActNew);
|
|
|
|
|
|
return mktReportFormRspBO;
|
|
|
}
|
|
|
|
|
|
for (int dateId = minDateId; maxDateId <= maxDateId;){
|
|
|
private BigDecimal getDivideData(BigDecimal d1,BigDecimal d2){
|
|
|
|
|
|
if(d2.compareTo(new BigDecimal(0)) == 0){
|
|
|
return new BigDecimal(0);
|
|
|
}
|
|
|
return d1.divide(d2,4,BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
} |
...
|
...
|
|