|
|
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.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.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.*;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2017/4/26.
|
|
|
*/
|
|
|
@Service
|
|
|
public class MktCostReportFormServiceImpl implements IMktCostReportFormService {
|
|
|
|
|
|
static Logger logger = LoggerFactory.getLogger(MktCostReportFormServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private IMktReportFormDAO mktReportFormDAO;
|
|
|
|
|
|
@Autowired
|
|
|
private IAppActiveDAO appActiveDAO;
|
|
|
|
|
|
@Override
|
|
|
public MktReportFormRspBO getMktReportForm(MktReportFormReqVO reportFormReqVO) {
|
|
|
Map<String, Integer> queryParam = new HashMap<>();
|
|
|
queryParam.put("beginTime", reportFormReqVO.getBeginTime());
|
|
|
queryParam.put("endTime", reportFormReqVO.getEndTime());
|
|
|
queryParam.put("channelCode", 1061);
|
|
|
|
|
|
List<AppActive> appActiveList = appActiveDAO.selectActivationAndActualCostByDateId(queryParam);
|
|
|
List<MktReportForm> mktReportFormList = mktReportFormDAO.selectMktReportFormByDateId(queryParam);
|
|
|
|
|
|
Map<Integer, MktReportBean> resultMap = mergeData(appActiveList, mktReportFormList);
|
|
|
if (!resultMap.isEmpty()){
|
|
|
logger.info("getMktReportForm impl resultMap size is : " + resultMap.size());
|
|
|
} else {
|
|
|
logger.info("getMktReportForm impl resultMap size is : zero");
|
|
|
}
|
|
|
|
|
|
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 setValueToMapForAppActive(Map<Integer, MktReportBean> resultMap, List<AppActive> appActiveList){
|
|
|
for (AppActive appActive : appActiveList) {
|
|
|
Integer dateId = appActive.getDateId();
|
|
|
MktReportBean mktReportBean = null;
|
|
|
if (resultMap.containsKey(dateId)){
|
|
|
mktReportBean = resultMap.get(dateId);
|
|
|
} else {
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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){
|
|
|
if (null == resultMap){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
BigDecimal initBigDemical = new BigDecimal(0);
|
|
|
while (it.hasNext()){
|
|
|
Integer dateId = (Integer) it.next();
|
|
|
MktReportBean mktReportBean = resultMap.get(dateId);
|
|
|
|
|
|
//日期
|
|
|
dateIdStrList.add(dateId.toString());
|
|
|
|
|
|
//实际费用
|
|
|
BigDecimal iosActualCost = mktReportBean.getIosActualCost() == null ? new BigDecimal(0) : mktReportBean.getIosActualCost();
|
|
|
iosActualCostList.add(iosActualCost);
|
|
|
|
|
|
BigDecimal androidActualCost = mktReportBean.getAndroidActualCost() == null ? new BigDecimal(0) : mktReportBean.getAndroidActualCost();
|
|
|
androidActualCostList.add(androidActualCost);
|
|
|
|
|
|
BigDecimal totalActualCost = iosActualCost.add(androidActualCost);
|
|
|
totalActualCostList.add(totalActualCost);
|
|
|
|
|
|
//曝光数
|
|
|
Integer iosExposureNum = mktReportBean.getIosExposureNum() == null ? 0 : mktReportBean.getIosExposureNum();
|
|
|
iosExposureNumList.add(iosExposureNum);
|
|
|
|
|
|
Integer androidExposureNum = mktReportBean.getAndroidExposureNum() == null ? 0 : mktReportBean.getAndroidExposureNum();
|
|
|
androidExposureNumList.add(androidExposureNum);
|
|
|
|
|
|
Integer totalExposureNum = iosExposureNum + androidExposureNum;
|
|
|
totalExposureNumList.add(totalExposureNum);
|
|
|
|
|
|
//激活数
|
|
|
Integer iosAppActive = mktReportBean.getIosAppActive() == null ? 0 : mktReportBean.getIosAppActive();
|
|
|
iosAppActiveList.add(iosAppActive);
|
|
|
|
|
|
Integer androidActive = mktReportBean.getAndroidAppActive() == null ? 0 : mktReportBean.getAndroidAppActive();
|
|
|
androidAppActiveList.add(androidActive);
|
|
|
|
|
|
Integer totalAppActive = iosAppActive + androidActive;
|
|
|
totalAppActiveList.add(totalAppActive);
|
|
|
|
|
|
//新客数
|
|
|
Integer iosNewUser = mktReportBean.getIosNewUdid() == null ? 0 : mktReportBean.getIosNewUdid();
|
|
|
iosNewUserList.add(iosNewUser);
|
|
|
|
|
|
Integer androidNewUser = mktReportBean.getAndroidNewUdid() == null ? 0 : mktReportBean.getAndroidNewUdid();
|
|
|
androidNewUserList.add(androidNewUser);
|
|
|
|
|
|
Integer totalNewUser = iosNewUser + androidNewUser;
|
|
|
totalNewUserList.add(totalNewUser);
|
|
|
|
|
|
//激活转化率
|
|
|
iosActiveRatioList.add(getDivideData(iosActualCost, new BigDecimal(iosAppActive)));
|
|
|
androidActiveRatioList.add(getDivideData(androidActualCost, new BigDecimal(androidActive)));
|
|
|
totalActiveRatioList.add(getDivideData(totalActualCost, new BigDecimal(totalAppActive)));
|
|
|
|
|
|
//曝光转化率
|
|
|
iosExposureRatioList.add(getDivideData(iosActualCost, new BigDecimal(iosExposureNum)));
|
|
|
androidExposureRatioList.add(getDivideData(androidActualCost, new BigDecimal(androidExposureNum)));
|
|
|
totalExposureRatioList.add(getDivideData(totalActualCost, new BigDecimal(totalExposureNum)));
|
|
|
|
|
|
//新客转化率
|
|
|
iosNewUdidRatioList.add(getDivideData(iosActualCost, new BigDecimal(iosNewUser)));
|
|
|
androidNewUdidRatioList.add(getDivideData(androidActualCost, new BigDecimal(androidNewUser)));
|
|
|
totalNewUdidRatioList.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;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
} |
...
|
...
|
|