Selaa lähdekoodia

应用列表增加广告报表数据展示

marxjaw 4 kuukautta sitten
vanhempi
commit
dd230d86ea

+ 6 - 0
yt-advertise/advertise-feign/src/main/java/com/ytpm/feign/AdvertiseFeign.java

@@ -2,9 +2,11 @@ package com.ytpm.feign;
 
 import com.ytpm.advertise.param.AddAppParam;
 import com.ytpm.advertise.param.AddPlacementParam;
+import com.ytpm.advertise.param.ComprehensiveReportParam;
 import com.ytpm.advertise.param.RelativeChannelParam;
 import com.ytpm.advertise.view.AddAppResponse;
 import com.ytpm.advertise.view.AddPlacementResponse;
+import com.ytpm.advertise.view.ComprehensiveAppReport;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
 import org.apache.ibatis.annotations.Param;
@@ -14,6 +16,8 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.util.List;
+
 @FeignClient(name = "advertise-service")
 public interface AdvertiseFeign {
     @PostMapping("/advertise/saveApp")
@@ -26,4 +30,6 @@ public interface AdvertiseFeign {
     ResultTable<AddPlacementResponse> savePlacement(@RequestBody AddPlacementParam param);
     @GetMapping("/advertise/savePlacement")
     Result<?> delPlacement(@RequestParam("placementId")String placementId);
+    @PostMapping("/advertise/getAppReport")
+    List<ComprehensiveAppReport> getAppReport(@RequestBody ComprehensiveReportParam param);
 }

+ 12 - 0
yt-advertise/advertise-service/src/main/java/com/ytpm/controller/AdvertiseController.java

@@ -2,11 +2,13 @@ package com.ytpm.controller;
 
 import com.ytpm.advertise.param.AddAppParam;
 import com.ytpm.advertise.param.AddPlacementParam;
+import com.ytpm.advertise.param.ComprehensiveReportParam;
 import com.ytpm.advertise.param.PlacementParam;
 import com.ytpm.advertise.param.RelativeChannelParam;
 import com.ytpm.advertise.view.AddAppResponse;
 import com.ytpm.advertise.view.AddPlacementResponse;
 import com.ytpm.advertise.view.AppV1View;
+import com.ytpm.advertise.view.ComprehensiveAppReport;
 import com.ytpm.agent.param.ChannelParam;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
@@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Collections;
+import java.util.List;
 
 @Api("Taku广告聚合管理模块")
 @RestController
@@ -84,4 +87,13 @@ public class AdvertiseController {
     public Result<?> delPlacement(@RequestParam("placementId")String placementId) {
         return takuApiService.delPlacement(Collections.singletonList(placementId));
     }
+
+    /**
+     * 根据应用分组查询数据报表
+     */
+    @ApiOperation("根据应用分组查询数据报表")
+    @PostMapping("/getAppReport")
+    public List<ComprehensiveAppReport> getAppReport(@RequestBody ComprehensiveReportParam param){
+        return takuApiService.getAppReport(param);
+    }
 }

+ 6 - 0
yt-advertise/advertise-service/src/main/java/com/ytpm/service/TakuApiService.java

@@ -11,6 +11,7 @@ import com.ytpm.advertise.param.UnitsParam;
 import com.ytpm.advertise.view.AddAppResponse;
 import com.ytpm.advertise.view.AddPlacementResponse;
 import com.ytpm.advertise.view.AppV1View;
+import com.ytpm.advertise.view.ComprehensiveAppReport;
 import com.ytpm.advertise.view.ComprehensiveReportView;
 import com.ytpm.advertise.view.HourReportView;
 import com.ytpm.advertise.view.ReportRoiView;
@@ -88,6 +89,11 @@ public interface TakuApiService {
      * 查询综合报表
      */
     Result<ComprehensiveReportView> comprehensiveReport(ComprehensiveReportParam param);
+
+    /**
+     * 查询APP综合报表
+     */
+    List<ComprehensiveAppReport> getAppReport(ComprehensiveReportParam param);
     /**
      * 查询ROI报表
      */

+ 15 - 0
yt-advertise/advertise-service/src/main/java/com/ytpm/service/impl/TakuApiServiceImpl.java

@@ -19,6 +19,7 @@ import com.ytpm.advertise.param.UnitsParam;
 import com.ytpm.advertise.view.AddAppResponse;
 import com.ytpm.advertise.view.AddPlacementResponse;
 import com.ytpm.advertise.view.AppV1View;
+import com.ytpm.advertise.view.ComprehensiveAppReport;
 import com.ytpm.advertise.view.ComprehensiveReportView;
 import com.ytpm.advertise.view.HourReportView;
 import com.ytpm.advertise.view.ReportRoiView;
@@ -42,6 +43,7 @@ import org.apache.http.client.methods.HttpPut;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
@@ -242,6 +244,19 @@ public class TakuApiServiceImpl implements TakuApiService {
         return Result.resultObjOk(JSONObject.parseObject(result, ComprehensiveReportView.class));
     }
 
+    /**
+     * 查询APP综合报表
+     */
+    @Override
+    public List<ComprehensiveAppReport> getAppReport(ComprehensiveReportParam param) {
+        param.setGroup_by(Collections.singletonList("app"));
+        String result = TakuRequestUtil.doRequest(HttpPost.METHOD_NAME, "/v2/fullreport", JSON.toJSONString(param));
+        JSONObject object = JSONObject.parseObject(result);
+        String records = object.getString("records");
+        List<ComprehensiveAppReport> appReports = JSONArray.parseArray(records, ComprehensiveAppReport.class);
+        return appReports;
+    }
+
     /**
      * 查询Roi报表
      */

+ 4 - 0
yt-advertise/advertise-service/src/main/java/com/ytpm/util/TakuRequestUtil.java

@@ -3,6 +3,8 @@ package com.ytpm.util;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ytpm.advertise.param.ComprehensiveReportParam;
+import com.ytpm.advertise.view.ComprehensiveAppReport;
+import com.ytpm.advertise.view.ComprehensiveReportView;
 import com.ytpm.handle.CustomerException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -39,7 +41,9 @@ public class TakuRequestUtil {
         param.setApp_id_list(Arrays.asList("a685138d49cd2d","a684009039113d"));
         param.setGroup_by(Collections.singletonList("app"));
         String result = TakuRequestUtil.doRequest(HttpPost.METHOD_NAME, "/v2/fullreport", JSON.toJSONString(param));
+        ComprehensiveAppReport report = JSONObject.parseObject(result, ComprehensiveAppReport.class);
         System.err.println(result);
+        System.err.println(JSON.toJSONString(report));
     }
 
     public static String doRequest(String httpMethod, String reqUrl, String reqBody) {

+ 44 - 1
yt-agent/agent-service/src/main/java/com/ytpm/service/impl/AgentAppServiceImpl.java

@@ -1,12 +1,15 @@
 package com.ytpm.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.param.AddAppParam;
+import com.ytpm.advertise.param.ComprehensiveReportParam;
 import com.ytpm.advertise.param.RelativeChannelParam;
 import com.ytpm.advertise.view.AddAppResponse;
+import com.ytpm.advertise.view.ComprehensiveAppReport;
 import com.ytpm.agent.model.YtApp;
 import com.ytpm.agent.param.AppListParam;
 import com.ytpm.agent.param.AppParam;
@@ -23,7 +26,14 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 
 @Service
@@ -52,7 +62,40 @@ public class AgentAppServiceImpl implements AgentAppService {
     @Override
     public ResultTable<AgentAppView> searchAppList(AppListParam appListParam) {
         PageHelper.startPage(appListParam.getPage(), appListParam.getLimit());
-        return ResultTable.resultTableOk(new PageInfo<>(agentAppMapper.searchAppList(appListParam)));
+        List<AgentAppView> views = agentAppMapper.searchAppList(appListParam);
+        //设置报表数据
+        if(CollUtil.isEmpty(views)){
+            return ResultTable.resultTableOk(new PageInfo<>(new ArrayList<>()));
+        }
+        List<String> appIds = views.stream().map(AgentAppView::getAppId).collect(Collectors.toList());
+        ComprehensiveReportParam param = new ComprehensiveReportParam();
+        param.setStartdate(getDateNum(LocalDate.now().minusDays(7)));
+        param.setEnddate(getDateNum(LocalDate.now()));
+        param.setTime_zone("UTC-8");
+        param.setApp_id_list(appIds);
+        List<ComprehensiveAppReport> appReport = advertiseFeign.getAppReport(param);
+        Map<String, ComprehensiveAppReport> reportMap = new HashMap<>();
+        if(CollUtil.isNotEmpty(appReport)){
+            reportMap =  appReport.stream().collect(Collectors.toMap(
+                            s -> s.getApp().getId(), O -> O));
+        }
+        for (AgentAppView view : views) {
+            if(!reportMap.containsKey(view.getAppId()))continue;
+            BeanUtil.copyProperties(reportMap.get(view.getAppId()), view);
+        }
+        return ResultTable.resultTableOk(new PageInfo<>(views));
+    }
+
+    /**
+     * 获取日期数字
+     */
+    private int getDateNum(LocalDate currentDate) {
+        // 定义日期格式化器,格式为YYYYMMDD
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
+        // 将当前日期格式化为字符串
+        String formattedDate = currentDate.format(formatter);
+        // 将字符串转换为整数
+        return Integer.parseInt(formattedDate);
     }
 
     /**

+ 30 - 0
yt-common/src/main/java/com/ytpm/advertise/view/ComprehensiveAppReport.java

@@ -0,0 +1,30 @@
+package com.ytpm.advertise.view;
+
+import lombok.Data;
+
+/**
+ * 综合报表APP分组报表
+ */
+@Data
+public class ComprehensiveAppReport{
+    /** 应用信息 */
+    private ReportAppView app;
+    /** 广告源请求数 */
+    private String request;
+    /** 广告源填充率 */
+    private String fillrate;
+    /** 展示数 */
+    private String impression;
+    /** 点击数 */
+    private String click;
+    /** ECPM */
+    private String ecpm;
+    /** 收益 */
+    private String revenue;
+    /** 三方广告平台的展示数 */
+    private String impression_api;
+    /** 三方广告平台的点击数 */
+    private String click_api;
+    /** 三方广告平台的ECPM */
+    private String ecpm_api;
+}

+ 5 - 1
yt-common/src/main/java/com/ytpm/advertise/view/ComprehensiveReportView.java

@@ -2,8 +2,10 @@ package com.ytpm.advertise.view;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
-public class ComprehensiveReportView {
+public class ComprehensiveReportView<T> {
     /** 总条数 */
     private Integer count;
     /** 日期  group_by有选 */
@@ -38,4 +40,6 @@ public class ComprehensiveReportView {
     private String time_zone;
     /** 开发者账号币种,该字段与revenue字段组成的收益需与开发者后台报表的收益一致 */
     private String currency;
+    /** 返回的数据列表 */
+    private List<T> records;
 }

+ 28 - 1
yt-common/src/main/java/com/ytpm/agent/view/AgentAppView.java

@@ -79,6 +79,33 @@ public class AgentAppView {
      * 屏幕方向
      */
     private Integer screenOrientation;
-
+    /** -------- 数据报告 ---------- */
+    /** 广告源请求数 */
+    @ApiModelProperty("广告源请求数")
+    private String request;
+    /** 广告源填充率 */
+    @ApiModelProperty("广告源填充率")
+    private String fillrate;
+    /** 展示数 */
+    @ApiModelProperty("展示数")
+    private String impression;
+    /** 点击数 */
+    @ApiModelProperty("点击数")
+    private String click;
+    /** ECPM */
+    @ApiModelProperty("ECPM")
+    private String ecpm;
+    /** 收益 */
+    @ApiModelProperty("收益")
+    private String revenue;
+    /** 三方广告平台的展示数 */
+    @ApiModelProperty("三方广告平台的展示数")
+    private String impression_api;
+    /** 三方广告平台的点击数 */
+    @ApiModelProperty("三方广告平台的点击数")
+    private String click_api;
+    /** 三方广告平台的ECPM */
+    @ApiModelProperty("三方广告平台的ECPM")
+    private String ecpm_api;
 
 }