|
@@ -0,0 +1,446 @@
|
|
|
|
+package cn.com.ctop.bytedance.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.com.ctop.bytedance.mapper.AccountReportMapper;
|
|
|
|
+import cn.com.ctop.bytedance.service.IAccountReportService;
|
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class AccountReportServiceImpl implements IAccountReportService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private AccountReportMapper accountReportMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取 汇总
|
|
|
|
+ *
|
|
|
|
+ * @param json
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public JSONObject getSummaryReport(JSONObject json) {
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
|
+ if (Check.isNull(json)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ JSONArray accountIds = json.getJSONArray("accountIds");
|
|
|
|
+ if (Check.isNull(accountIds)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ JSONObject accountJson = new JSONObject();
|
|
|
|
+ List<JSONObject> detail = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ Integer type = json.getInteger("type");
|
|
|
|
+ BigDecimal discount = json.getBigDecimal("discount");
|
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
|
|
|
|
+ String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
|
|
|
|
+ if (type == 1) { // 今日汇总
|
|
|
|
+ Integer maxHour = accountReportMapper.selectMaxHourByDate(nowDate);
|
|
|
|
+ if (Check.isNull(maxHour) || maxHour == 0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ String maxHourStr = String.valueOf(maxHour - 1);
|
|
|
|
+ accountJson = accountReportMapper.selectSumDayHourlyByHourAndDate(nowDate, maxHourStr, accountIds); // 今日 小时汇总数据
|
|
|
|
+ JSONObject yesterdayJson = accountReportMapper.selectSumDayHourlyByHourAndDate(anotherDay, maxHourStr, accountIds); // 昨日 小时汇总数据
|
|
|
|
+ accountJson.put("maxHour", maxHour);
|
|
|
|
+ if (!Check.isNull(accountJson)) {
|
|
|
|
+ BigDecimal cost = accountJson.getBigDecimal("cost"); // 今日消耗
|
|
|
|
+ BigDecimal yesterdayCost = yesterdayJson.getBigDecimal("cost");// 昨日消耗
|
|
|
|
+ BigDecimal compareBigDecimal = new BigDecimal(0);
|
|
|
|
+ if (yesterdayCost.compareTo(compareBigDecimal) != 0) {
|
|
|
|
+ BigDecimal costProportion = (cost.subtract(yesterdayCost)).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ accountJson.put("costProportion", costProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ accountJson.put("costProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal discountCost = cost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ accountJson.put("discountCost", discountCost); // 折后消耗
|
|
|
|
+ BigDecimal yesterdayDiscountCost = yesterdayCost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ if (yesterdayDiscountCost.compareTo(compareBigDecimal) != 0) {
|
|
|
|
+ BigDecimal discountCostProportion = (discountCost.subtract(yesterdayDiscountCost)).divide(yesterdayDiscountCost, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ accountJson.put("discountCostProportion", discountCostProportion); // 较昨日折后上涨
|
|
|
|
+ } else {
|
|
|
|
+ accountJson.put("discountCostProportion", 0); // 较昨日折后上涨
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long photoShow = accountJson.getLong("photoShow");// 今日封面展示
|
|
|
|
+ Long yesterdayPhotoShow = yesterdayJson.getLong("photoShow");// 昨日封面展示
|
|
|
|
+ if (yesterdayPhotoShow != 0L) {
|
|
|
|
+ double showProportion = (photoShow.doubleValue() - yesterdayPhotoShow.doubleValue()) / yesterdayPhotoShow.doubleValue();
|
|
|
|
+ accountJson.put("showProportion", showProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ accountJson.put("showProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long photoClick = accountJson.getLong("photoClick");// 今日封面展示
|
|
|
|
+ Long yesterdayPhotoClick = yesterdayJson.getLong("photoClick");// 昨日封面展示
|
|
|
|
+ if (yesterdayPhotoClick != 0L) {
|
|
|
|
+ double photoClickProportion = (photoClick.doubleValue() - yesterdayPhotoClick.doubleValue()) / yesterdayPhotoClick.doubleValue();
|
|
|
|
+ accountJson.put("photoClickProportion", photoClickProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ accountJson.put("photoClickProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long aClick = accountJson.getLong("aclick");
|
|
|
|
+ Long yesterdayAClick = yesterdayJson.getLong("aclick");
|
|
|
|
+ if (yesterdayAClick != 0L) {
|
|
|
|
+ double aClickProportion = (aClick.doubleValue() - yesterdayAClick.doubleValue()) / yesterdayAClick.doubleValue();
|
|
|
|
+ accountJson.put("aClickProportion", aClickProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ accountJson.put("aClickProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 折线图
|
|
|
|
+ List<JSONObject> yesterdayDetailArr = accountReportMapper.selectReportDetail(anotherDay, accountIds);
|
|
|
|
+ for (int i = 0; i < yesterdayDetailArr.size(); i++) {
|
|
|
|
+
|
|
|
|
+ JSONObject yesterdayDetail = yesterdayDetailArr.get(i);
|
|
|
|
+ if (!Check.isNull(yesterdayDetail)) {
|
|
|
|
+ String yesterdayStatHour = yesterdayDetail.getString("statHour");
|
|
|
|
+ JSONObject nowJson = accountReportMapper.selectDayHourlyByHourAndDate(nowDate, yesterdayStatHour, accountIds);
|
|
|
|
+ if (!Check.isNull(nowJson)) {
|
|
|
|
+ nowJson.put("statDate", nowDate);
|
|
|
|
+ BigDecimal cost = nowJson.getBigDecimal("cost"); // 今日消耗
|
|
|
|
+ BigDecimal yesterdayCost = yesterdayDetail.getBigDecimal("cost");// 昨日消耗
|
|
|
|
+ BigDecimal compareBigDecimal = new BigDecimal(0);
|
|
|
|
+ if (yesterdayCost.compareTo(compareBigDecimal) != 0) {
|
|
|
|
+ BigDecimal costProportion = ((cost.subtract(yesterdayCost))).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ nowJson.put("costProportion", costProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ nowJson.put("costProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long photoShow = nowJson.getLong("photoShow");// 今日封面展示
|
|
|
|
+ Long yesterdayPhotoShow = yesterdayDetail.getLong("photoShow");// 昨日封面展示
|
|
|
|
+ if (yesterdayPhotoShow != 0L) {
|
|
|
|
+ double showProportion = (photoShow.doubleValue() - yesterdayPhotoShow.doubleValue()) / yesterdayPhotoShow.doubleValue();
|
|
|
|
+ nowJson.put("showProportion", showProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ nowJson.put("showProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long photoClick = nowJson.getLong("photoClick");// 今日封面展示
|
|
|
|
+ Long yesterdayPhotoClick = yesterdayDetail.getLong("photoClick");// 昨日封面展示
|
|
|
|
+ if (yesterdayPhotoClick != 0L) {
|
|
|
|
+ double photoClickProportion = (photoClick.doubleValue() - yesterdayPhotoClick.doubleValue()) / yesterdayPhotoClick.doubleValue();
|
|
|
|
+ nowJson.put("photoClickProportion", photoClickProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ nowJson.put("photoClickProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long aClick = nowJson.getLong("aclick");// 今日封面展示
|
|
|
|
+ Long yesterdayAClick = yesterdayDetail.getLong("aclick");// 昨日封面展示
|
|
|
|
+ if (yesterdayAClick != 0L) {
|
|
|
|
+ double aClickProportion = (aClick.doubleValue() - yesterdayAClick.doubleValue()) / yesterdayAClick.doubleValue();
|
|
|
|
+ nowJson.put("aClickProportion", aClickProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ nowJson.put("aClickProportion", 0); // 较昨日增加比例
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal discountCost = cost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ nowJson.put("discountCost", discountCost); // 折后消耗
|
|
|
|
+ BigDecimal yesterdayDiscountCost = yesterdayCost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ if (yesterdayDiscountCost.compareTo(compareBigDecimal) != 0) {
|
|
|
|
+ BigDecimal discountCostProportion = (discountCost.subtract(yesterdayDiscountCost)).divide(yesterdayDiscountCost, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ nowJson.put("discountCostProportion", discountCostProportion); // 较昨日折后上涨
|
|
|
|
+ } else {
|
|
|
|
+ nowJson.put("discountCostProportion", 0); // 较昨日折后上涨
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ yesterdayDetail.put("now", nowJson);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ detail.add(yesterdayDetail);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else if (type == 2) {
|
|
|
|
+ accountJson = accountReportMapper.selectDayReport(anotherDay, accountIds);
|
|
|
|
+ detail = accountReportMapper.selectReportDetail(anotherDay, accountIds);
|
|
|
|
+ } else if (type == 3) { // 近七天
|
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
|
|
|
|
+ accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ } else if (type == 4) { // 近15天
|
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -15);
|
|
|
|
+ accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
|
|
|
|
+ detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ } else if (type == 5) {// 近一个月
|
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
|
|
|
|
+ accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
|
|
|
|
+ detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ } else if (type == 6) {// 近三个月
|
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
|
|
|
|
+ accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
|
|
|
|
+ detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ } else if (type == 7) {// 近六个月
|
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
|
|
|
|
+ accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
|
|
|
|
+ detail = accountReportMapper.selectDayDetailByMonth(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ } else if (type == 8) { // 所有
|
|
|
|
+ accountJson = accountReportMapper.selectAllAccount(accountIds);
|
|
|
|
+ detail = accountReportMapper.selectAllByAccounts(accountIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else if (type == 9) { // 自定义查询日期
|
|
|
|
+ String startDate = json.getString("startDate");
|
|
|
|
+ String endDate = json.getString("endDate");
|
|
|
|
+ accountJson = accountReportMapper.selectByDate(startDate, endDate, accountIds);
|
|
|
|
+ detail = accountReportMapper.selectDayDetailByDate(startDate, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (type != 1) {
|
|
|
|
+ if (!Check.isNull(accountJson)) {
|
|
|
|
+ BigDecimal cost = accountJson.getBigDecimal("cost");
|
|
|
|
+ BigDecimal discountCost = cost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ accountJson.put("discountCost", discountCost); // 折后消耗
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ returnJson.put("summary", accountJson);
|
|
|
|
+ returnJson.put("trend", detail);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return returnJson;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public JSONObject getStatistics(JSONObject json) {
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
|
+ try {
|
|
|
|
+ Integer type = json.getInteger("type");
|
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
|
|
|
|
+ String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
|
|
|
|
+ JSONArray accountIds = json.getJSONArray("accountIds");
|
|
|
|
+ BigDecimal discount = json.getBigDecimal("discount");
|
|
|
|
+ if (Check.isNull(accountIds)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<JSONObject> accountDetail = new ArrayList<>();
|
|
|
|
+ Integer statHour = json.getInteger("statHour");
|
|
|
|
+ Integer hour;
|
|
|
|
+ if (type == 1) { // 今日汇总
|
|
|
|
+ if (Check.isNull(statHour)) {
|
|
|
|
+ Integer maxHour = accountReportMapper.selectMaxHourByDate(nowDate);
|
|
|
|
+ hour = maxHour - 1;
|
|
|
|
+ } else {
|
|
|
|
+ hour = statHour;
|
|
|
|
+ }
|
|
|
|
+ JSONObject chainRatioJson = new JSONObject();
|
|
|
|
+ accountDetail = accountReportMapper.selectReportDetailGroupAccountId(nowDate, accountIds, hour);
|
|
|
|
+ JSONObject nowAccountSummary = accountReportMapper.selectSummaryByAccountId(nowDate, accountIds, hour);
|
|
|
|
+ if (!Check.isNull(nowAccountSummary)) {
|
|
|
|
+ returnJson.put("now", nowAccountSummary);
|
|
|
|
+ JSONObject yesterdayAccountSummary = accountReportMapper.selectSummaryByAccountId(anotherDay, accountIds, hour);
|
|
|
|
+ if (!Check.isNull(yesterdayAccountSummary)) {
|
|
|
|
+ returnJson.put("yesterday", yesterdayAccountSummary);
|
|
|
|
+ BigDecimal nowCost = nowAccountSummary.getBigDecimal("cost");
|
|
|
|
+ BigDecimal yesterdayCost = yesterdayAccountSummary.getBigDecimal("cost");
|
|
|
|
+ if (!Check.isNull(nowCost) && !Check.isNull(yesterdayCost)) {
|
|
|
|
+ if (yesterdayCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
|
+ BigDecimal costProportion = (nowCost.subtract(yesterdayCost)).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ chainRatioJson.put("costProportion", costProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("costProportion", 0); // 消耗环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long photoShow = nowAccountSummary.getLong("photoShow");// 今日封面展示
|
|
|
|
+ Long yesterdayPhotoShow = yesterdayAccountSummary.getLong("photoShow");// 昨日封面展示
|
|
|
|
+ if (!Check.isNull(photoShow) && !Check.isNull(yesterdayPhotoShow)) {
|
|
|
|
+ if (yesterdayPhotoShow != 0L) {
|
|
|
|
+ double showProportion = (photoShow.doubleValue() - yesterdayPhotoShow.doubleValue()) / yesterdayPhotoShow.doubleValue();
|
|
|
|
+ chainRatioJson.put("showProportion", showProportion); // 较昨日增加比例
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("showProportion", 0); // 展示环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long photoClick = nowAccountSummary.getLong("photoClick");// 封面点击
|
|
|
|
+ Long yesterdayPhotoClick = yesterdayAccountSummary.getLong("photoClick");
|
|
|
|
+ if (!Check.isNull(photoClick) && !Check.isNull(yesterdayPhotoClick)) {
|
|
|
|
+ if (yesterdayPhotoClick != 0L) {
|
|
|
|
+ double photoClickProportion = (photoClick.doubleValue() - yesterdayPhotoClick.doubleValue()) / yesterdayPhotoClick.doubleValue();
|
|
|
|
+ chainRatioJson.put("photoClickProportion", photoClickProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("photoClickProportion", 0); // 点击环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long nowAClick = nowAccountSummary.getLong("aclick"); // 爆光
|
|
|
|
+ Long yesterdayAClick = yesterdayAccountSummary.getLong("aclick");
|
|
|
|
+ if (!Check.isNull(nowAClick) && !Check.isNull(nowAClick)) {
|
|
|
|
+ if (yesterdayAClick != 0L) {
|
|
|
|
+ double aClickProportion = (nowAClick.doubleValue() - yesterdayAClick.doubleValue()) / yesterdayAClick.doubleValue();
|
|
|
|
+ chainRatioJson.put("aClickProportion", aClickProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("aClickProportion", 0); //爆光环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal nowPhotoClickRatio = nowAccountSummary.getBigDecimal("photoClickRatio"); // 封面点击率
|
|
|
|
+ BigDecimal yesterdayPhotoClickRatio = yesterdayAccountSummary.getBigDecimal("photoClickRatio");
|
|
|
|
+ if (!Check.isNull(nowPhotoClickRatio) && !Check.isNull(yesterdayPhotoClickRatio)) {
|
|
|
|
+ if (yesterdayPhotoClickRatio.compareTo(new BigDecimal(0)) != 0) {
|
|
|
|
+ BigDecimal photoClickRatioProportion = (nowPhotoClickRatio.subtract(yesterdayPhotoClickRatio)).divide(yesterdayPhotoClickRatio, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ chainRatioJson.put("photoClickRatioProportion", photoClickRatioProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("photoClickRatioProportion", 0); // 封面点击率环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal nowCvr = nowAccountSummary.getBigDecimal("cvr"); // cvr
|
|
|
|
+ BigDecimal yesterdayCvr = yesterdayAccountSummary.getBigDecimal("cvr");
|
|
|
|
+ if (!Check.isNull(nowCvr) && !Check.isNull(yesterdayCvr)) {
|
|
|
|
+ if (yesterdayCvr.compareTo(new BigDecimal(0)) != 0) {
|
|
|
|
+ BigDecimal cvrProportion = (nowCvr.subtract(yesterdayCvr)).divide(yesterdayCvr, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ chainRatioJson.put("cvrProportion", cvrProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("cvrProportion", 0); // cvr环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal nowCpm = nowAccountSummary.getBigDecimal("cpm"); // cpm
|
|
|
|
+ BigDecimal yesterdayCpm = yesterdayAccountSummary.getBigDecimal("cpm");
|
|
|
|
+ if (!Check.isNull(nowCpm) && !Check.isNull(yesterdayCpm)) {
|
|
|
|
+ if (yesterdayCpm.compareTo(new BigDecimal(0)) != 0) {
|
|
|
|
+ BigDecimal cpmProportion = (nowCpm.subtract(yesterdayCpm)).divide(yesterdayCpm, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ chainRatioJson.put("cpmProportion", cpmProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("cpmProportion", 0); // cpm环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long nowBClick = nowAccountSummary.getLong("bClick"); // 行为数
|
|
|
|
+ Long yesterdayBClick = yesterdayAccountSummary.getLong("bClick");
|
|
|
|
+ if (!Check.isNull(nowBClick) && !Check.isNull(yesterdayBClick)) {
|
|
|
|
+ if (yesterdayAClick != 0L) {
|
|
|
|
+ double bClickProportion = (nowBClick.doubleValue() - yesterdayBClick.doubleValue()) / yesterdayBClick.doubleValue();
|
|
|
|
+ chainRatioJson.put("bClickProportion", bClickProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("bClickProportion", 0); //行为数环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Long nowFormCount = nowAccountSummary.getLong("formCount"); // 表单提交数
|
|
|
|
+ Long yesterdayFormCount = yesterdayAccountSummary.getLong("formCount");
|
|
|
|
+
|
|
|
|
+ if (!Check.isNull(nowFormCount) && !Check.isNull(yesterdayFormCount)) {
|
|
|
|
+ if (yesterdayAClick != 0L) {
|
|
|
|
+ double formCountProportion = (nowFormCount.doubleValue() - yesterdayFormCount.doubleValue()) / yesterdayFormCount.doubleValue();
|
|
|
|
+ chainRatioJson.put("formCountProportion", formCountProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("formCountProportion", 0); //表单提交数环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Long nowActivationCount = nowAccountSummary.getLong("activationCount"); // 激活数
|
|
|
|
+ Long yesterdayActivationCount = yesterdayAccountSummary.getLong("activationCount");
|
|
|
|
+ if (!Check.isNull(nowActivationCount) && !Check.isNull(yesterdayActivationCount)) {
|
|
|
|
+ if (yesterdayAClick != 0L) {
|
|
|
|
+ double activationCountProportion = (nowActivationCount.doubleValue() - yesterdayActivationCount.doubleValue()) / yesterdayActivationCount.doubleValue();
|
|
|
|
+ chainRatioJson.put("activationCountProportion", activationCountProportion);
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("activationCountProportion", 0); //表单提交数环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal nowFormPrice = nowAccountSummary.getBigDecimal("formPrice"); // 表单提交单价
|
|
|
|
+ BigDecimal yesterdayFormPrice = yesterdayAccountSummary.getBigDecimal("formPrice");
|
|
|
|
+ if (!Check.isNull(nowFormPrice) && !Check.isNull(yesterdayFormPrice)) {
|
|
|
|
+ if (yesterdayFormPrice.compareTo(new BigDecimal(0)) != 0) {
|
|
|
|
+ BigDecimal formPriceProportion = (nowFormPrice.subtract(yesterdayFormPrice)).divide(yesterdayFormPrice, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ chainRatioJson.put("formPriceProportion", formPriceProportion.divide(discount, BigDecimal.ROUND_HALF_UP, 2));
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("formPriceProportion", 0); // 表单提交单价环比
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ BigDecimal nowActivationPrice = nowAccountSummary.getBigDecimal("activationPrice"); // 表单提交单价
|
|
|
|
+ BigDecimal yesterdayActivationPrice = yesterdayAccountSummary.getBigDecimal("activationPrice");
|
|
|
|
+ if (!Check.isNull(nowActivationPrice) && !Check.isNull(yesterdayActivationPrice)) {
|
|
|
|
+ if (yesterdayFormPrice.compareTo(new BigDecimal(0)) != 0) {
|
|
|
|
+ BigDecimal activationPriceProportion = (nowActivationPrice.subtract(yesterdayActivationPrice)).divide(yesterdayActivationPrice, BigDecimal.ROUND_HALF_UP, 2);
|
|
|
|
+ chainRatioJson.put("activationPriceProportion", activationPriceProportion.divide(discount, BigDecimal.ROUND_HALF_UP, 2));
|
|
|
|
+ } else {
|
|
|
|
+ chainRatioJson.put("activationPriceProportion", 0); // 表单提交单价环比
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ returnJson.put("chainRatio", chainRatioJson);
|
|
|
|
+ } else if (type == 2) {
|
|
|
|
+ if (Check.isNull(statHour)) {
|
|
|
|
+ accountDetail = accountReportMapper.selectReportDetailGroupAccountId(anotherDay, accountIds, 23);
|
|
|
|
+ } else {
|
|
|
|
+ accountDetail = accountReportMapper.selectReportDetailGroupAccountId(anotherDay, accountIds, statHour);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else if (type == 3) { // 近七天
|
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ } else if (type == 4) { // 近15天
|
|
|
|
+ String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -15);
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else if (type == 5) {// 近一个月
|
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else if (type == 6) {// 近三个月
|
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else if (type == 7) {// 近六个月
|
|
|
|
+ String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else if (type == 8) { // 所有
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReport(accountIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } else if (type == 9) { // 自定义查询日期
|
|
|
|
+ String startDate = json.getString("startDate");
|
|
|
|
+ String endDate = json.getString("endDate");
|
|
|
|
+ accountDetail = accountReportMapper.selectAccountReportByDate(startDate, endDate, accountIds);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ returnJson.put("accountDetail", accountDetail);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return returnJson;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|