|
@@ -1,9 +1,12 @@
|
|
package com.zanxiang.game.data.serve.service.impl;
|
|
package com.zanxiang.game.data.serve.service.impl;
|
|
|
|
|
|
|
|
+import com.google.common.base.CaseFormat;
|
|
import com.zanxiang.game.data.serve.pojo.dto.PromotionDayDTO;
|
|
import com.zanxiang.game.data.serve.pojo.dto.PromotionDayDTO;
|
|
import com.zanxiang.game.data.serve.pojo.dto.PromotionDayTotalDTO;
|
|
import com.zanxiang.game.data.serve.pojo.dto.PromotionDayTotalDTO;
|
|
|
|
+import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
|
|
import com.zanxiang.game.data.serve.pojo.vo.PromotionDayTotalVO;
|
|
import com.zanxiang.game.data.serve.pojo.vo.PromotionDayTotalVO;
|
|
import com.zanxiang.game.data.serve.pojo.vo.PromotionDayVO;
|
|
import com.zanxiang.game.data.serve.pojo.vo.PromotionDayVO;
|
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.PromotionRechargeTrendVO;
|
|
import com.zanxiang.game.data.serve.service.IAdsPromotionDayService;
|
|
import com.zanxiang.game.data.serve.service.IAdsPromotionDayService;
|
|
import com.zanxiang.game.data.serve.utils.Page;
|
|
import com.zanxiang.game.data.serve.utils.Page;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -15,11 +18,21 @@ import org.nutz.dao.pager.Pager;
|
|
import org.nutz.dao.sql.Criteria;
|
|
import org.nutz.dao.sql.Criteria;
|
|
import org.nutz.dao.sql.Sql;
|
|
import org.nutz.dao.sql.Sql;
|
|
import org.nutz.dao.util.Daos;
|
|
import org.nutz.dao.util.Daos;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.BeanWrapper;
|
|
|
|
+import org.springframework.beans.BeanWrapperImpl;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.beans.PropertyDescriptor;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author tianhua
|
|
* @author tianhua
|
|
@@ -35,11 +48,304 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Page<PromotionDayVO> getPromotionDayData(PromotionDayDTO dto) {
|
|
public Page<PromotionDayVO> getPromotionDayData(PromotionDayDTO dto) {
|
|
|
|
+ //不传递查询条件默认查询当天数据
|
|
|
|
+ if (dto.getCostBeginDate() == null || dto.getCostEndDate() == null) {
|
|
|
|
+ dto.setCostBeginDate(LocalDate.now());
|
|
|
|
+ dto.setCostEndDate(LocalDate.now());
|
|
|
|
+ }
|
|
|
|
+ //如果没有排序条件给默认值
|
|
|
|
+ if (StringUtils.isBlank(dto.getSortFiled())) {
|
|
|
|
+ dto.setSortFiled("today_cost");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(dto.getSortType())) {
|
|
|
|
+ dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
|
+ }
|
|
|
|
+ Criteria cri = myCri(dto);
|
|
|
|
+ //创建sql语句
|
|
|
|
+ Sql sql = Sqls.create(getPromotionDayDataSql() + cri);
|
|
|
|
+ //添加自定义回传对象
|
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
|
+ sql.setEntity(dao.getEntity(PromotionDayVO.class));
|
|
|
|
+ //设置pager对象
|
|
|
|
+ Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
|
+ sql.setPager(pager);
|
|
|
|
+ //执行sql
|
|
|
|
+ dao.execute(sql);
|
|
|
|
+ //获取到结果list
|
|
|
|
+ List<PromotionDayVO> list = sql.getList(PromotionDayVO.class);
|
|
|
|
+ //分页对象设置总条数
|
|
|
|
+ Sql sqlCount = Sqls.queryEntity("select count(*) from ads_promotion_day" + cri);
|
|
|
|
+ pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
|
|
|
|
+
|
|
|
|
+ //处理List中的每个vo对象缺少的数据
|
|
|
|
+ list.stream().map(vo ->{
|
|
|
|
+ //记录最近有数据的LocalDate
|
|
|
|
+ LocalDate latestDate = dto.getCostEndDate();
|
|
|
|
+ Boolean hasDataDate = findDate(vo.getPromotionId(), latestDate);
|
|
|
|
+ while (!hasDataDate) {
|
|
|
|
+ latestDate = latestDate.minusDays(1);
|
|
|
|
+ hasDataDate = findDate(vo.getPromotionId(), latestDate);
|
|
|
|
+ }
|
|
|
|
+ //构建查询条件
|
|
|
|
+ Criteria totalCri = Cnd.cri();
|
|
|
|
+ totalCri.where().andEquals("dt", latestDate);
|
|
|
|
+ totalCri.where().andEquals("promotion_id", vo.getPromotionId());
|
|
|
|
+ //查询出最近一条包含总数据的记录
|
|
|
|
+ Sql totalDataSql = Sqls.create(getTotalDataSql() + totalCri);
|
|
|
|
+ //设置回传对象
|
|
|
|
+ totalDataSql.setCallback(Sqls.callback.entity());
|
|
|
|
+ totalDataSql.setEntity(dao.getEntity(PromotionDayVO.class));
|
|
|
|
+ //执行sql
|
|
|
|
+ dao.execute(totalDataSql);
|
|
|
|
+ //得到对象
|
|
|
|
+ PromotionDayVO tempVO = totalDataSql.getObject(PromotionDayVO.class);
|
|
|
|
+ //将两个对象内容合并
|
|
|
|
+ copyNullProperties(tempVO, vo);
|
|
|
|
+
|
|
|
|
+ //计算d2(次日)数据
|
|
|
|
+ vo.setD2Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD2().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD2())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD2().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+ //计算d3数据
|
|
|
|
+ vo.setD3Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD3().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD3())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD3().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+ //计算d7数据
|
|
|
|
+ vo.setD7Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD7().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD7())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD7().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+ //计算d15数据
|
|
|
|
+ vo.setD15Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD15().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD15())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD15().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+
|
|
|
|
+ //返回最终数据
|
|
|
|
+ return vo;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //返回查询得结果
|
|
|
|
+ return new Page<>(list, pager);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 广告监控数据总计一栏
|
|
|
|
+ *
|
|
|
|
+ * @param dto
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public PromotionDayTotalVO getPromotionDayTotalData(PromotionDayTotalDTO dto) {
|
|
//不传递查询条件默认查询当天数据
|
|
//不传递查询条件默认查询当天数据
|
|
if (dto.getCostBeginDate() == null || dto.getCostEndDate() == null) {
|
|
if (dto.getCostBeginDate() == null || dto.getCostEndDate() == null) {
|
|
dto.setCostBeginDate(LocalDate.now());
|
|
dto.setCostBeginDate(LocalDate.now());
|
|
dto.setCostEndDate(LocalDate.now());
|
|
dto.setCostEndDate(LocalDate.now());
|
|
}
|
|
}
|
|
|
|
+ //创建查询条件
|
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
|
+ if (dto.getAccountId() != null) {
|
|
|
|
+ //拼接推广账号Id查询条件
|
|
|
|
+ cri.where().andEquals("account_id", dto.getAccountId());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountName())) {
|
|
|
|
+ //拼接推广账号名称查询条件
|
|
|
|
+ cri.where().andEquals("account_name", dto.getAccountName());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountType())) {
|
|
|
|
+ //推广账号类型
|
|
|
|
+ cri.where().andEquals("account_type", dto.getAccountType());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getPitcherName())) {
|
|
|
|
+ cri.where().andEquals("pitcher_name", dto.getPitcherName());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getAgentId() != null) {
|
|
|
|
+ cri.where().andEquals("agent_id", dto.getAgentId());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getAgentKey())) {
|
|
|
|
+ cri.where().andEquals("agent_key", dto.getAgentKey());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getAgentName())) {
|
|
|
|
+ cri.where().andEquals("agent_name", dto.getAgentName());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getCpName())) {
|
|
|
|
+ cri.where().andEquals("cp_name", dto.getCpName());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameName())) {
|
|
|
|
+ cri.where().andEquals("game_name", dto.getGameName());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getGameId() != null) {
|
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getClassify() != null) {
|
|
|
|
+ cri.where().andEquals("classify", dto.getClassify());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getPromotionName())) {
|
|
|
|
+ cri.where().andEquals("promotion_name", dto.getPromotionName());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getPromotionId() != null) {
|
|
|
|
+ cri.where().andEquals("promotion_id", dto.getPromotionId());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getStatus())) {
|
|
|
|
+ cri.where().andEquals("status", dto.getStatus());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getProjectName())) {
|
|
|
|
+ cri.where().andEquals("project_name", dto.getProjectName());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getProjectId() != null) {
|
|
|
|
+ cri.where().andEquals("project_id", dto.getProjectId());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getCostBeginDate() != null && dto.getCostEndDate() != null) {
|
|
|
|
+ cri.where().andBetween("dt", dto.getCostBeginDate(), dto.getCostEndDate());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
|
+ }
|
|
|
|
+ //创建sql
|
|
|
|
+ Sql promotionDayTotalSql = Sqls.create(promotionDayTotalSql() + cri);
|
|
|
|
+ //设置回传对象
|
|
|
|
+ promotionDayTotalSql.setCallback(Sqls.callback.entity());
|
|
|
|
+ promotionDayTotalSql.setEntity(dao.getEntity(PromotionDayTotalVO.class));
|
|
|
|
+ //执行sql
|
|
|
|
+ dao.execute(promotionDayTotalSql);
|
|
|
|
+ //得到结果
|
|
|
|
+ PromotionDayTotalVO vo = promotionDayTotalSql.getObject(PromotionDayTotalVO.class);
|
|
|
|
+
|
|
|
|
+ //计算总数据要根据promotionId分组
|
|
|
|
+ Criteria totalCri = cri;
|
|
|
|
+ totalCri.getGroupBy().groupBy("promotion_id");
|
|
|
|
+ //构建sql
|
|
|
|
+ Sql tempSql = Sqls.create(promotionDayTotalTotalDataTempSql() + totalCri);
|
|
|
|
+ Sql totalSumSql = Sqls.create(promotionDayTotalTotalDataSumSql() + "(" + tempSql + ") a");
|
|
|
|
+ //设置回传对象
|
|
|
|
+ totalSumSql.setCallback(Sqls.callback.entity());
|
|
|
|
+ totalSumSql.setEntity(dao.getEntity(PromotionDayTotalVO.class));
|
|
|
|
+ //执行sql
|
|
|
|
+ dao.execute(totalSumSql);
|
|
|
|
+ PromotionDayTotalVO tempVO = totalSumSql.getObject(PromotionDayTotalVO.class);
|
|
|
|
+ //将取到的值赋值vo
|
|
|
|
+ copyNullProperties(tempVO, vo);
|
|
|
|
+
|
|
|
|
+ //如果没有tempVO,返回默认值0
|
|
|
|
+ if (tempVO.getPromotionTotalCost() == null) {
|
|
|
|
+ //计算总数据
|
|
|
|
+ //总注册成本
|
|
|
|
+ vo.setRegTotalCost(BigDecimal.ZERO);
|
|
|
|
+ //总创角成本
|
|
|
|
+ vo.setRoleTotalCost(BigDecimal.ZERO);
|
|
|
|
+ //总创角率
|
|
|
|
+ vo.setRoleTotalRate(BigDecimal.ZERO);
|
|
|
|
+ //广告总ROI
|
|
|
|
+ vo.setPromotionTotalRoi(BigDecimal.ZERO);
|
|
|
|
+ //总付费成本
|
|
|
|
+ vo.setTotalRechargeCost(BigDecimal.ZERO);
|
|
|
|
+ //计算d2,d3,d7,d15数据
|
|
|
|
+ //计算d2(次日)数据
|
|
|
|
+ vo.setD2Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(BigDecimal.ZERO)
|
|
|
|
+ .rechargeMoney(BigDecimal.ZERO)
|
|
|
|
+ .multiples(BigDecimal.ZERO)
|
|
|
|
+ .build());
|
|
|
|
+ //计算d3数据
|
|
|
|
+ vo.setD3Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(BigDecimal.ZERO)
|
|
|
|
+ .rechargeMoney(BigDecimal.ZERO)
|
|
|
|
+ .multiples(BigDecimal.ZERO)
|
|
|
|
+ .build());
|
|
|
|
+ //计算d7数据
|
|
|
|
+ vo.setD7Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(BigDecimal.ZERO)
|
|
|
|
+ .rechargeMoney(BigDecimal.ZERO)
|
|
|
|
+ .multiples(BigDecimal.ZERO)
|
|
|
|
+ .build());
|
|
|
|
+ //计算d15数据
|
|
|
|
+ vo.setD15Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(BigDecimal.ZERO)
|
|
|
|
+ .rechargeMoney(BigDecimal.ZERO)
|
|
|
|
+ .multiples(BigDecimal.ZERO)
|
|
|
|
+ .build());
|
|
|
|
+
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //计算总数据
|
|
|
|
+ //总注册成本
|
|
|
|
+ vo.setRegTotalCost(vo.getRegTotalNum() == 0L ? BigDecimal.ZERO :
|
|
|
|
+ vo.getPromotionTotalCost().divide(BigDecimal.valueOf(vo.getRegTotalNum()), 2, RoundingMode.HALF_UP));
|
|
|
|
+ //总创角成本
|
|
|
|
+ vo.setRoleTotalCost(vo.getRoleTotalNum() == 0L ? BigDecimal.ZERO :
|
|
|
|
+ vo.getPromotionTotalCost().divide(BigDecimal.valueOf(vo.getRoleTotalNum()), 2, RoundingMode.HALF_UP));
|
|
|
|
+ //总创角率
|
|
|
|
+ vo.setRoleTotalRate(vo.getRegTotalNum() == 0L ? BigDecimal.ZERO :
|
|
|
|
+ BigDecimal.valueOf(vo.getRoleTotalNum()).divide(BigDecimal.valueOf(vo.getRegTotalNum()), 4, RoundingMode.HALF_UP));
|
|
|
|
+ //广告总ROI
|
|
|
|
+ vo.setPromotionTotalRoi(vo.getPromotionTotalCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getTotalAmount().divide(vo.getPromotionTotalCost(), 4, RoundingMode.HALF_UP));
|
|
|
|
+ //总付费成本
|
|
|
|
+ vo.setTotalRechargeCost(vo.getTotalAmountNum() == 0L ? BigDecimal.ZERO :
|
|
|
|
+ vo.getPromotionTotalCost().divide(BigDecimal.valueOf(vo.getTotalAmountNum()), 2, RoundingMode.HALF_UP));
|
|
|
|
+
|
|
|
|
+ //计算d2,d3,d7,d15数据
|
|
|
|
+ //计算d2(次日)数据
|
|
|
|
+ vo.setD2Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD2().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD2())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD2().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+ //计算d3数据
|
|
|
|
+ vo.setD3Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD3().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD3())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD3().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+ //计算d7数据
|
|
|
|
+ vo.setD7Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD7().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD7())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD7().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+ //计算d15数据
|
|
|
|
+ vo.setD15Trend(PromotionRechargeTrendVO.builder()
|
|
|
|
+ .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD15().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .rechargeMoney(vo.getD15())
|
|
|
|
+ .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
|
+ vo.getD15().divide(vo.getD1(), 4, RoundingMode.HALF_UP))
|
|
|
|
+ .build());
|
|
|
|
+
|
|
|
|
+ return vo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 广告监控用到的查询条件
|
|
|
|
+ *
|
|
|
|
+ * @param dto 前端传递的查询条件
|
|
|
|
+ * @return 查询条件
|
|
|
|
+ */
|
|
|
|
+ private Criteria myCri(PromotionDayDTO dto) {
|
|
//创建查询条件
|
|
//创建查询条件
|
|
Criteria cri = Cnd.cri();
|
|
Criteria cri = Cnd.cri();
|
|
if (dto.getAccountId() != null) {
|
|
if (dto.getAccountId() != null) {
|
|
@@ -104,29 +410,79 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
|
|
}
|
|
}
|
|
//拼接分组条件
|
|
//拼接分组条件
|
|
cri.getGroupBy().groupBy("promotion_id");
|
|
cri.getGroupBy().groupBy("promotion_id");
|
|
- //创建sql语句
|
|
|
|
- Sql sql = Sqls.create(getPromotionDayDataSql() + cri );
|
|
|
|
- //添加自定义回传对象
|
|
|
|
- sql.setCallback(Sqls.callback.entities());
|
|
|
|
- sql.setEntity(dao.getEntity(PromotionDayVO.class));
|
|
|
|
- //设置pager对象
|
|
|
|
- Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
|
- sql.setPager(pager);
|
|
|
|
- //执行sql
|
|
|
|
|
|
+ //拼接排序条件
|
|
|
|
+ cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return cri;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用来判断当前日期有没有数据
|
|
|
|
+ *
|
|
|
|
+ * @param promotionId 查询的广告id
|
|
|
|
+ * @param latestDate 时间参数
|
|
|
|
+ * @return Boolean
|
|
|
|
+ */
|
|
|
|
+ private Boolean findDate(String promotionId, LocalDate latestDate) {
|
|
|
|
+ //创建查询条件
|
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
|
+ cri.where().andEquals("promotion_id", Long.valueOf(promotionId));
|
|
|
|
+ cri.where().andEquals("dt", latestDate);
|
|
|
|
+ Sql sql = Sqls.create("""
|
|
|
|
+ SELECT
|
|
|
|
+ promotion_id
|
|
|
|
+ FROM
|
|
|
|
+ game_ads.ads_promotion_day
|
|
|
|
+ """ + cri);
|
|
|
|
+ sql.setCallback(Sqls.callback.str());
|
|
dao.execute(sql);
|
|
dao.execute(sql);
|
|
- //获取到结果list
|
|
|
|
- List<PromotionDayVO> list = sql.getList(PromotionDayVO.class);
|
|
|
|
- //分页对象设置总条数
|
|
|
|
- Sql sqlCount = Sqls.queryEntity("select count(*) from ads_promotion_day" + cri);
|
|
|
|
- pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
|
|
|
|
|
|
+ String tempStr = sql.getString();
|
|
|
|
+ //查询结果判断
|
|
|
|
+ if (tempStr != null) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
- //返回查询得结果
|
|
|
|
- return new Page<>(list,pager);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 所有为空值的属性都不copy
|
|
|
|
+ *
|
|
|
|
+ * @param source 原数据
|
|
|
|
+ * @param target 目标数据
|
|
|
|
+ */
|
|
|
|
+ private void copyNullProperties(Object source, Object target) {
|
|
|
|
+ BeanUtils.copyProperties(source, target, getNullField(source));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 查询广告监控数据
|
|
|
|
- * @return
|
|
|
|
|
|
+ * 获取属性中为空的字段
|
|
|
|
+ *
|
|
|
|
+ * @param target 目标对象
|
|
|
|
+ * @return 不需要替换的字段数组
|
|
|
|
+ */
|
|
|
|
+ private static String[] getNullField(Object target) {
|
|
|
|
+ BeanWrapper beanWrapper = new BeanWrapperImpl(target);
|
|
|
|
+ PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors();
|
|
|
|
+ Set<String> notNullFieldSet = new HashSet<>();
|
|
|
|
+ if (propertyDescriptors.length > 0) {
|
|
|
|
+ for (PropertyDescriptor p : propertyDescriptors) {
|
|
|
|
+ String name = p.getName();
|
|
|
|
+ Object value = beanWrapper.getPropertyValue(name);
|
|
|
|
+ if (Objects.isNull(value)) {
|
|
|
|
+ notNullFieldSet.add(name);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String[] notNullField = new String[notNullFieldSet.size()];
|
|
|
|
+
|
|
|
|
+ return notNullFieldSet.toArray(notNullField);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询广告监控数据sql
|
|
|
|
+ *
|
|
|
|
+ * @return String
|
|
*/
|
|
*/
|
|
private String getPromotionDayDataSql() {
|
|
private String getPromotionDayDataSql() {
|
|
return """
|
|
return """
|
|
@@ -201,6 +557,7 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
|
|
round(if(SUM(reg_num) > 0, SUM(first_new_user_amount_num) / SUM(reg_num), 0), 4) as first_amount_rate,
|
|
round(if(SUM(reg_num) > 0, SUM(first_new_user_amount_num) / SUM(reg_num), 0), 4) as first_amount_rate,
|
|
round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_avg_price,
|
|
round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_avg_price,
|
|
round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_avg_price,
|
|
round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_avg_price,
|
|
|
|
+ SUM(d1) as d1,
|
|
SUM(d2) as d2,
|
|
SUM(d2) as d2,
|
|
SUM(d3) as d3,
|
|
SUM(d3) as d3,
|
|
SUM(d7) as d7,
|
|
SUM(d7) as d7,
|
|
@@ -210,8 +567,148 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
|
|
""";
|
|
""";
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public PromotionDayTotalVO getPromotionDayTotalData(PromotionDayTotalDTO dto) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查询广告每日里总数据sql
|
|
|
|
+ *
|
|
|
|
+ * @return String
|
|
|
|
+ */
|
|
|
|
+ private String getTotalDataSql() {
|
|
|
|
+ return """
|
|
|
|
+ SELECT
|
|
|
|
+ status,
|
|
|
|
+ creative_preview,
|
|
|
|
+ landing_type,
|
|
|
|
+ pricing,
|
|
|
|
+ cpa_bid,
|
|
|
|
+ roi_goal,
|
|
|
|
+ budget,
|
|
|
|
+ schedule_time,
|
|
|
|
+ notes,
|
|
|
|
+ service,
|
|
|
|
+ balance,
|
|
|
|
+ promotion_total_cost,
|
|
|
|
+ convert_target,
|
|
|
|
+ reg_total_num,
|
|
|
|
+ role_total_num,
|
|
|
|
+ reg_total_cost,
|
|
|
|
+ role_total_cost,
|
|
|
|
+ role_total_rate,
|
|
|
|
+ total_amount_count,
|
|
|
|
+ total_amount_num,
|
|
|
|
+ total_amount,
|
|
|
|
+ promotion_total_roi,
|
|
|
|
+ total_recharge_cost
|
|
|
|
+ FROM
|
|
|
|
+ game_ads.ads_promotion_day
|
|
|
|
+ """;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询广告监控每日总计一栏sql
|
|
|
|
+ *
|
|
|
|
+ * @return String
|
|
|
|
+ */
|
|
|
|
+ private String promotionDayTotalSql() {
|
|
|
|
+ return """
|
|
|
|
+ SELECT
|
|
|
|
+ IFNULL(SUM(today_cost), 0) as today_cost,
|
|
|
|
+ IFNULL(SUM(show_count), 0) as show_count,
|
|
|
|
+ round(if(SUM(show_count) > 0, SUM(today_cost) / SUM(show_count), 0), 2) as thousand_display_price,
|
|
|
|
+ IFNULL(SUM(click_count), 0) as click_count,
|
|
|
|
+ round(if(SUM(click_count) > 0, SUM(today_cost) / SUM(click_count), 0), 2) as avg_click_cost,
|
|
|
|
+ round(if(SUM(show_count) > 0, SUM(click_count) / SUM(show_count), 0), 4) as ctr,
|
|
|
|
+ IFNULL(SUM(convert_count), 0) as convert_count,
|
|
|
|
+ IFNULL(SUM(convert_cost), 0) as convert_cost,
|
|
|
|
+ round(if(SUM(click_count) > 0, SUM(convert_count) / SUM(click_count), 0), 4) as convert_rate,
|
|
|
|
+ IFNULL(SUM(reg_num), 0) as reg_num,
|
|
|
|
+ IFNULL(SUM(first_role_num), 0) as first_role_num,
|
|
|
|
+ IFNULL(SUM(new_user_total_role_num), 0) as new_user_total_role_num,
|
|
|
|
+ round(if(SUM(reg_num) > 0, SUM(today_cost) / SUM(reg_num), 0), 2) as reg_cost,
|
|
|
|
+ round(if(SUM(first_role_num) > 0, SUM(today_cost) / SUM(first_role_num), 0), 2) as first_role_cost,
|
|
|
|
+ round(if(SUM(new_user_total_role_num) > 0, SUM(today_cost) / SUM(new_user_total_role_num), 0), 2) as new_user_total_role_cost,
|
|
|
|
+ round(if(SUM(reg_num) > 0, SUM(first_role_num) / SUM(reg_num), 0), 4) as first_role_rate,
|
|
|
|
+ round(if(SUM(reg_num) > 0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) as new_user_total_role_rate,
|
|
|
|
+ IFNULL(SUM(first_new_user_amount_count), 0) as first_new_user_amount_count,
|
|
|
|
+ IFNULL(SUM(first_new_user_amount_num), 0) as first_new_user_amount_num,
|
|
|
|
+ IFNULL(SUM(first_new_user_amount), 0) as first_new_user_amount,
|
|
|
|
+ IFNULL(SUM(new_user_total_amount_count), 0) as new_user_total_amount_count,
|
|
|
|
+ IFNULL(SUM(new_user_total_amount_num), 0) as new_user_total_amount_num,
|
|
|
|
+ IFNULL(SUM(new_user_total_amount), 0) as new_user_total_amount,
|
|
|
|
+ round(if(SUM(today_cost) > 0, SUM(first_new_user_amount) / SUM(today_cost), 0), 4) as first_roi,
|
|
|
|
+ IFNULL(SUM(twenty_four_hours_amount), 0) as twenty_four_hours_amount,
|
|
|
|
+ round(if(SUM(today_cost) > 0, SUM(twenty_four_hours_amount) / SUM(today_cost), 0), 4) as twenty_four_hours_roi,
|
|
|
|
+ round(if(SUM(today_cost) > 0, SUM(new_user_total_amount) / SUM(today_cost), 0), 4) as total_roi,
|
|
|
|
+ round(if(SUM(first_new_user_amount_num) > 0, SUM(today_cost) / SUM(first_new_user_amount_num), 0), 2) as first_new_user_recharge_cost,
|
|
|
|
+ round(if(SUM(new_user_total_amount_num) > 0, SUM(today_cost) / SUM(new_user_total_amount_num), 0), 2) as new_user_total_recharge_cost,
|
|
|
|
+ round(if(SUM(first_new_user_amount_num) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) as first_new_user_arppu,
|
|
|
|
+ round(if(SUM(new_user_total_amount_num) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) as new_user_total_amount_arppu,
|
|
|
|
+ IFNULL(SUM(first_new_user_hundred_user_num), 0) as first_new_user_hundred_user_num,
|
|
|
|
+ round(if(SUM(first_new_user_hundred_user_num) > 0, SUM(today_cost) / SUM(first_new_user_hundred_user_num), 0), 2) as first_new_user_hundred_user_cost,
|
|
|
|
+ IFNULL(SUM(first_recharge_fifty_hundred_num), 0) as first_recharge_fifty_hundred_num,
|
|
|
|
+ round(if(SUM(new_user_total_amount_num) > 0, SUM(first_recharge_fifty_hundred_num) / SUM(new_user_total_amount_num), 0), 4) as first_recharge_fifty_hundred_rate,
|
|
|
|
+ IFNULL(SUM(first_new_user_two_hundred_user_num), 0) as first_new_user_two_hundred_user_num,
|
|
|
|
+ round(if(SUM(first_new_user_two_hundred_user_num) > 0, SUM(today_cost) / SUM(first_new_user_two_hundred_user_num), 0), 2) as first_new_user_two_hundred_user_cost,
|
|
|
|
+ IFNULL(SUM(new_user_total_hundred_user_num), 0) as new_user_total_hundred_user_num,
|
|
|
|
+ round(if(SUM(new_user_total_hundred_user_num) > 0, SUM(today_cost) / SUM(new_user_total_hundred_user_num), 0), 2) as new_user_total_hundred_user_cost,
|
|
|
|
+ IFNULL(SUM(first_ios_amount_num), 0) as first_ios_amount_num,
|
|
|
|
+ IFNULL(SUM(first_ios_amount_count), 0) as first_ios_amount_count,
|
|
|
|
+ IFNULL(SUM(first_ios_amount), 0) as first_ios_amount,
|
|
|
|
+ round(if(SUM(first_new_user_amount_num) > 0, SUM(first_ios_amount_num) / SUM(first_new_user_amount_num), 0), 4) as first_ios_amount_num_rate,
|
|
|
|
+ round(if(SUM(first_new_user_amount) > 0, SUM(first_ios_amount) / SUM(first_new_user_amount), 0), 4) as first_ios_amount_rate,
|
|
|
|
+ round(if(SUM(today_cost)> 0, SUM(first_ios_amount) / SUM(today_cost), 0), 4) as first_ios_amount_roi,
|
|
|
|
+ IFNULL(SUM(first_android_amount_count), 0) as first_android_amount_count,
|
|
|
|
+ IFNULL(SUM(first_android_amount_num), 0) as first_android_amount_num,
|
|
|
|
+ IFNULL(SUM(first_android_amount), 0) as first_android_amount,
|
|
|
|
+ round(if(SUM(first_new_user_amount_num) > 0,SUM(first_android_amount_num) / SUM(first_new_user_amount_num), 0), 4) as first_android_amount_num_rate,
|
|
|
|
+ round(if(SUM(first_new_user_amount) > 0, SUM(first_android_amount) / SUM(first_new_user_amount), 0), 4) as first_android_amount_rate,
|
|
|
|
+ round(if(SUM(today_cost) > 0, SUM(first_android_amount) / SUM(today_cost), 0), 4) as first_android_amount_roi,
|
|
|
|
+ round(if(SUM(reg_num) > 0, SUM(first_new_user_amount_num) / SUM(reg_num), 0), 4) as first_amount_rate,
|
|
|
|
+ round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_avg_price,
|
|
|
|
+ round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_avg_price,
|
|
|
|
+ IFNULL(SUM(d1), 0) as d1,
|
|
|
|
+ IFNULL(SUM(d2), 0) as d2,
|
|
|
|
+ IFNULL(SUM(d3), 0) as d3,
|
|
|
|
+ IFNULL(SUM(d7), 0) as d7,
|
|
|
|
+ IFNULL(SUM(d15), 0) as d15
|
|
|
|
+ FROM
|
|
|
|
+ game_ads.ads_promotion_day
|
|
|
|
+ """;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用来查询出总计一栏的总数据sql
|
|
|
|
+ *
|
|
|
|
+ * @return String
|
|
|
|
+ */
|
|
|
|
+ private String promotionDayTotalTotalDataTempSql() {
|
|
|
|
+ return """
|
|
|
|
+ SELECT
|
|
|
|
+ MAX(promotion_total_cost) promotion_total_cost,
|
|
|
|
+ MAX(reg_total_num) reg_total_num,
|
|
|
|
+ MAX(role_total_num) role_total_num,
|
|
|
|
+ MAX(total_amount_count) total_amount_count,
|
|
|
|
+ MAX(total_amount_num) total_amount_num,
|
|
|
|
+ MAX(total_amount) total_amount
|
|
|
|
+ FROM
|
|
|
|
+ game_ads.ads_promotion_day
|
|
|
|
+ """;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 得到计算后的总数据
|
|
|
|
+ *
|
|
|
|
+ * @return String
|
|
|
|
+ */
|
|
|
|
+ private String promotionDayTotalTotalDataSumSql() {
|
|
|
|
+ return """
|
|
|
|
+ SELECT
|
|
|
|
+ IFNULL(SUM(promotion_total_cost), 0) promotion_total_cost,
|
|
|
|
+ IFNULL(SUM(reg_total_num), 0) reg_total_num,
|
|
|
|
+ IFNULL(SUM(role_total_num), 0) role_total_num,
|
|
|
|
+ IFNULL(SUM(total_amount_count), 0) total_amount_count,
|
|
|
|
+ IFNULL(SUM(total_amount_num), 0) total_amount_num,
|
|
|
|
+ IFNULL(SUM(total_amount), 0) total_amount
|
|
|
|
+ FROM
|
|
|
|
+ """;
|
|
}
|
|
}
|
|
}
|
|
}
|