소스 검색

伊对报表

syh 5 년 전
부모
커밋
714b8c333d
17개의 변경된 파일434개의 추가작업 그리고 155개의 파일을 삭제
  1. 20 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java
  2. 4 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/AdvertiserMapper.java
  3. 28 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/AdvertiserMapper.xml
  4. 2 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IAdvertiserService.java
  5. 71 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java
  6. 4 6
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/vo/SheetInfoVo.java
  7. 67 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/YdMaterialWeekEntity.java
  8. 95 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/YdPlanAggregateEntity.java
  9. 64 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/YdWeekAggregateEntity.java
  10. 24 0
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  11. 1 1
      module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java
  12. 4 1
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java
  13. 4 2
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java
  14. 0 31
      module-report/src/main/java/cn/com/ctop/bytedance/controller/ReportController.java
  15. 1 1
      module-report/src/main/java/cn/com/ctop/bytedance/entity/BytedanceCampaignDailyReport.java
  16. 2 6
      module-report/src/main/java/cn/com/ctop/bytedance/service/IReportService.java
  17. 43 105
      module-report/src/main/java/cn/com/ctop/bytedance/service/impl/ReportServiceImpl.java

+ 20 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java

@@ -401,7 +401,26 @@ public class AdvertiserController {
     }
 
     /**
-     * 导出报表
+     * 导出伊对报表
+     *
+     * @return
+     */
+    @RequestMapping(value = "/ydWeekReportList")
+    @ResponseBody
+    public Map<String, Object> ydReportList(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject data) throws Exception {
+        Map<String, Object> result = new HashMap<>();
+        //查询总的消耗信息
+        Long projectId = data.getLong("projectId");
+        String startDate = data.getString("startDate");
+        String endDate = data.getString("endDate");
+        List<SheetInfoVo> vos = advertiserService.getYdStatisticInfo(projectId, startDate, endDate);
+        result.put("data", vos);
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
+        return result;
+    }
+
+    /**
+     * 导出消消乐报表
      *
      * @return
      */

+ 4 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/AdvertiserMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
+import org.jeecg.modules.excelutil.entity.YdWeekAggregateEntity;
 
 import java.util.List;
 
@@ -17,4 +18,7 @@ public interface AdvertiserMapper extends BaseMapper<Advertiser> {
 
     List<KuaishouXxlEntity> getXXlStatisticInfo(@Param(value = "projectId") Long projectId, @Param(value = "systemType") String systemType, @Param(value = "accountId") Long accountId, @Param(value = "groupBy") String groupBy);
 
+    YdWeekAggregateEntity getYdWeekStatisticInfo(@Param(value = "projectId") Long projecgId, @Param(value = "start") String lastWeekStart, @Param(value = "end") String lastWeekEnd);
+
+    List<YdWeekAggregateEntity> getYdWeekPlanStatisticInfoBtTen(@Param(value = "projectId") Long projectId, @Param(value = "start") String startDate, @Param(value = "end") String endDate, @Param(value = "accountId") Long accountId);
 }

+ 28 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/AdvertiserMapper.xml

@@ -66,4 +66,32 @@
         </if>
 
     </select>
+    <select id="getYdWeekStatisticInfo" resultType="org.jeecg.modules.excelutil.entity.YdWeekAggregateEntity">
+        select
+            concat(#{start},'至',#{end}) as date,
+            round(sum(cost),2) as cost,
+            sum(active) as active,
+            (
+                case
+                    when sum(cost)!=0 and sum(active)!=0
+                    then round(sum(cost)/sum(active),2)
+                    else 0
+                end)    as activeAvg
+        from
+            ctop_bytedance_report_advertiser_daily daily
+        left join ctop_user_allocation allocation on allocation.account_id = daily.advertiser_id
+        where
+            allocation.project_id = #{projectId}
+        and
+            allocation.account_status = 0
+        and
+            daily.stat_datetime &gt;= #{start}
+        and
+            daily.stat_datetime &lt;= #{end}
+
+    </select>
+    <select id="getYdWeekPlanStatisticInfoBtTen"
+            resultType="org.jeecg.modules.excelutil.entity.YdWeekAggregateEntity">
+
+    </select>
 </mapper>

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IAdvertiserService.java

@@ -19,4 +19,6 @@ public interface IAdvertiserService extends IService<Advertiser> {
     SheetInfoVo getXxlStatisticInfo(Long projectId, String systemType, Long accountId, String sheetName);
 
     List<SheetInfoVo> getSystemTypeXxlStatisticInfo(Long projectId);
+
+    List<SheetInfoVo> getYdStatisticInfo(Long projectId, String startDate, String endDate);
 }

+ 71 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java

@@ -1,16 +1,25 @@
 package org.jeecg.modules.ctop.service.impl;
 
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.mapper.AdvertiserMapper;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
 import org.jeecg.modules.ctop.vo.SheetInfoVo;
 import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
+import org.jeecg.modules.excelutil.entity.YdPlanAggregateEntity;
+import org.jeecg.modules.excelutil.entity.YdWeekAggregateEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.ParseException;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -33,7 +42,7 @@ public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Adverti
 
     @Override
     public SheetInfoVo getXxlStatisticInfo(Long projectId, String systemType, Long accountId, String sheetName) {
-        SheetInfoVo vo = new SheetInfoVo();
+        SheetInfoVo vo = new SheetInfoVo<KuaishouXxlEntity>();
         List<KuaishouXxlEntity> details = new ArrayList<>();
         vo.setSheetName(sheetName);
         List<KuaishouXxlEntity> totalList = advertiserMapper.getXXlStatisticInfo(projectId, systemType, accountId, null);
@@ -54,4 +63,65 @@ public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Adverti
         vos.add(ios);
         return vos;
     }
+
+    @Override
+    public List<SheetInfoVo> getYdStatisticInfo(Long projectId, String startDate, String endDate) {
+        List<SheetInfoVo> sheetInfoVos = new ArrayList<>();
+        try {
+            Date start = DateUtils.parseDate(startDate, "yyyy-MM-dd");
+            Date end = DateUtils.parseDate(endDate, "yyyy-MM-dd");
+            String lastWeekStart = DateUtils.formatDate(DateUtils.addDay(start, -7));
+            String lastWeekEnd = DateUtils.formatDate(DateUtils.addDay(end, -7));
+            //1:获取周报汇总数据
+            SheetInfoVo voFirst = new SheetInfoVo();
+            List<YdWeekAggregateEntity> weekEntities = new ArrayList<>();
+            YdWeekAggregateEntity lastWeek = advertiserMapper.getYdWeekStatisticInfo(projectId, lastWeekStart + " 00:00:00", lastWeekEnd + " 00:00:00");
+            weekEntities.add(lastWeek);
+            YdWeekAggregateEntity thWeek = advertiserMapper.getYdWeekStatisticInfo(projectId, startDate + " 00:00:00", endDate + " 00:00:00");
+            weekEntities.add(thWeek);
+            YdWeekAggregateEntity qoq = new YdWeekAggregateEntity();
+            qoq.setDate("环比数据");
+            BigDecimal qoqActive = (new BigDecimal(thWeek.getActive()).subtract(new BigDecimal(lastWeek.getActive()))).divide(
+                    new BigDecimal(lastWeek.getActive()), 5, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
+            qoq.setActive(qoqActive.toString() + "%");
+            BigDecimal qoqCost = (new BigDecimal(thWeek.getCost()).subtract(new BigDecimal(lastWeek.getCost()))).divide(
+                    new BigDecimal(lastWeek.getCost()), 5, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
+            qoq.setCost(qoqCost.toString() + "%");
+            BigDecimal qoqActiveAvg = (new BigDecimal(thWeek.getActiveAvg()).subtract(new BigDecimal(lastWeek.getActiveAvg()))).divide(
+                    new BigDecimal(lastWeek.getActiveAvg()), 5, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);
+            qoq.setActiveAvg(qoqActiveAvg.toString() + "%");
+            weekEntities.add(qoq);
+            voFirst.setSheetName("周数据");
+            voFirst.setDetails(weekEntities);
+            sheetInfoVos.add(voFirst);
+            //2:获取主力计划汇总
+            SheetInfoVo secondVo = new SheetInfoVo();
+            secondVo.setSheetName("主力计划汇总");
+            List<YdPlanAggregateEntity> planAggregateEntities = getYdPlanStatisticInfo(projectId, startDate, endDate);
+            //3:获取每周素材统计
+            return null;
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private List<YdPlanAggregateEntity> getYdPlanStatisticInfo(Long projectId, String startDate, String endDate) {
+        List<YdPlanAggregateEntity> result = new ArrayList<>();
+        List<UserAllocation> allocations = userAllocationService.getByProjectId(projectId, null);
+        if (null != allocations && allocations.size() > 0) {
+            allocations.forEach(allocation -> {
+                List<YdWeekAggregateEntity> plans = statisticWeekInfoByAccount(allocation, startDate, endDate, projectId);
+            });
+        }
+        return result;
+    }
+
+    private List<YdWeekAggregateEntity> statisticWeekInfoByAccount(UserAllocation allocation, String startDate, String endDate, Long projectId) {
+        List<YdWeekAggregateEntity> entitiesBtTens = advertiserMapper.getYdWeekPlanStatisticInfoBtTen(projectId, startDate, endDate, allocation.getAccountId());
+        return null;
+    }
+
+    @Autowired
+    private IUserAllocationService userAllocationService;
 }

+ 4 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/vo/SheetInfoVo.java

@@ -1,21 +1,19 @@
 package org.jeecg.modules.ctop.vo;
 
-import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
-
 import java.util.List;
 
 /**
  * @author 宋英豪
  */
-public class SheetInfoVo {
+public class SheetInfoVo<T> {
     private String sheetName;
-    List<KuaishouXxlEntity> details;
+    List<T> details;
 
-    public List<KuaishouXxlEntity> getDetails() {
+    public List<T> getDetails() {
         return details;
     }
 
-    public void setDetails(List<KuaishouXxlEntity> details) {
+    public void setDetails(List<T> details) {
         this.details = details;
     }
 

+ 67 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/YdMaterialWeekEntity.java

@@ -0,0 +1,67 @@
+package org.jeecg.modules.excelutil.entity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.metadata.BaseRowModel;
+
+/**
+ * 伊对每周素材统计
+ *
+ * @author 宋英豪
+ */
+public class YdMaterialWeekEntity extends BaseRowModel {
+    /**
+     * 日期
+     */
+    @ExcelProperty(index = 1, value = "日期")
+    private String date;
+
+    /**
+     * 创意类型
+     */
+    @ExcelProperty(index = 1, value = "创意类型")
+    private String type;
+
+    /**
+     * 视频链接/图片数量
+     */
+    @ExcelProperty(index = 1, value = "视频链接/图片数量")
+    private String imageUrl;
+
+    /**
+     * 创意类型
+     */
+    @ExcelProperty(index = 1, value = "创意名称")
+    private String name;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getImageUrl() {
+        return imageUrl;
+    }
+
+    public void setImageUrl(String imageUrl) {
+        this.imageUrl = imageUrl;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

+ 95 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/YdPlanAggregateEntity.java

@@ -0,0 +1,95 @@
+package org.jeecg.modules.excelutil.entity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.metadata.BaseRowModel;
+
+/**
+ * 伊对计划汇总报表信息
+ *
+ * @author 宋英豪
+ */
+public class YdPlanAggregateEntity extends BaseRowModel {
+    /**
+     * 账号名称
+     */
+    @ExcelProperty(index = 1, value = "账号名称")
+    private String accountName;
+
+    /**
+     * 投放时间
+     */
+    @ExcelProperty(index = 1, value = "投放时间")
+    private String date;
+
+    /**
+     * 计划名称
+     */
+    @ExcelProperty(index = 1, value = "计划名称")
+    private String planName;
+
+    /**
+     * 总花费(元)
+     */
+    @ExcelProperty(index = 1, value = "总花费(元)")
+    private String totalCost;
+
+    /**
+     * 展示
+     */
+    @ExcelProperty(index = 1, value = "展示")
+    private String show;
+
+    /**
+     * 点击
+     */
+    @ExcelProperty(index = 1, value = "点击")
+    private String click;
+
+    /**
+     * 点击率(%)
+     */
+    @ExcelProperty(index = 1, value = "点击率(%)")
+    private String clickRate;
+
+    /**
+     * 平均点击单价(元)
+     */
+    @ExcelProperty(index = 1, value = "平均点击单价(元)")
+    private String priceAvg;
+
+    /**
+     * 平均千次展现费用(元)
+     */
+    @ExcelProperty(index = 1, value = "平均千次展现费用(元)")
+    private String ctr;
+
+    /**
+     * 转化数
+     */
+    @ExcelProperty(index = 1, value = "转化数")
+    private String convert;
+
+    /**
+     * 转化成本
+     */
+    @ExcelProperty(index = 1, value = "转化成本")
+    private String convertPrice;
+
+    /**
+     * 转化率(%)
+     */
+    @ExcelProperty(index = 1, value = "转化率(%)")
+    private String convertRate;
+
+    /**
+     * 投放平台
+     */
+    @ExcelProperty(index = 1, value = "投放平台")
+    private String platform;
+
+    /**
+     * 投放性别
+     */
+    @ExcelProperty(index = 1, value = "投放性别")
+    private String sex;
+}

+ 64 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/excelutil/entity/YdWeekAggregateEntity.java

@@ -0,0 +1,64 @@
+package org.jeecg.modules.excelutil.entity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.metadata.BaseRowModel;
+
+/**
+ * 伊对周报汇总
+ *
+ * @author 宋英豪
+ */
+public class YdWeekAggregateEntity extends BaseRowModel {
+    /**
+     * 时间
+     */
+    @ExcelProperty(index = 1, value = "时间")
+    private String date;
+    /**
+     * 时间
+     */
+    @ExcelProperty(index = 2, value = "总消费")
+    private String cost;
+    /**
+     * 时间
+     */
+    @ExcelProperty(index = 3, value = "激活数(头条)")
+    private String active;
+    /**
+     * 时间
+     */
+    @ExcelProperty(index = 4, value = "激活成本(头条)")
+    private String activeAvg;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public String getCost() {
+        return cost;
+    }
+
+    public void setCost(String cost) {
+        this.cost = cost;
+    }
+
+    public String getActive() {
+        return active;
+    }
+
+    public void setActive(String active) {
+        this.active = active;
+    }
+
+    public String getActiveAvg() {
+        return activeAvg;
+    }
+
+    public void setActiveAvg(String activeAvg) {
+        this.activeAvg = activeAvg;
+    }
+}

+ 24 - 0
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
@@ -13,6 +14,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.service.IBytedanceFundDailyService;
 import org.jeecg.modules.ctop.service.IPerformanceSaleService;
 import org.junit.Test;
@@ -168,6 +170,28 @@ public class SampleTest {
         }
     }
 
+    @Test
+    public void loadCampaignDate() {
+        Date endDate = DateUtils.addDay(new Date(), -1);
+        Date startDate = DateUtils.addDay(new Date(), -10);
+        //1:查询当日数据
+        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+        if (null == tokens || tokens.size() <= 0) {
+            log.info("定时获取头条数据异常:为获取到可用的token");
+            return;
+        }
+//        executorService = Executors.newFixedThreadPool(10);
+        tokens.forEach(token -> {
+//            executorService.submit(new Runnable() {
+//                @Override
+//                public void run() {
+            //获取广告主信息数据
+            reportService.getCampaignReportByPage(token, startDate, endDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY, 1);
+//                }
+//            });
+        });
+    }
+
     @Autowired
     private IReportService reportService;
     @Autowired

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -15,5 +15,5 @@ public interface IUserAllocationService extends IService<UserAllocation> {
 
     UserAllocation getByAccountId(Long accountId);
 
-    List<UserAllocation> getByProjectId(long projectId, String systemType);
+    List<UserAllocation> getByProjectId(Long projectId, String systemType);
 }

+ 4 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java

@@ -154,7 +154,10 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
     @Override
     public List<CtopOauthToken> getTokenListByType(String platformType) {
         QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("media_id", platformType).orderByDesc("account_id");
+        if (null != platformType && !platformType.trim().equals("")) {
+            queryWrapper.eq("media_id", platformType);
+        }
+        queryWrapper.orderByDesc("account_id");
         return this.list(queryWrapper);
     }
 

+ 4 - 2
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -26,9 +26,11 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     }
 
     @Override
-    public List<UserAllocation> getByProjectId(long projectId, String systemType) {
+    public List<UserAllocation> getByProjectId(Long projectId, String systemType) {
         QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("project_id", projectId);
+        if (null != projectId && projectId != 0) {
+            queryWrapper.eq("project_id", projectId);
+        }
         if (null != systemType && !systemType.trim().equals("")) {
             queryWrapper.eq("system_type", systemType);
         }

+ 0 - 31
module-report/src/main/java/cn/com/ctop/bytedance/controller/ReportController.java

@@ -38,37 +38,6 @@ public class ReportController {
     }
 
     /**
-     * 头条广告计划报表信息
-     * 只支持查询2016-10-26及以后的日期
-     * 单次获取最大条数1000
-     * @return 广告组报表数据
-     */
-    @GetMapping("bytedance/campaign")
-    public Map<String, Object> campaignReport(@RequestBody ByteDanceAdvertiserReportDTO conditions) {
-        return reportService.getCampaignReport(conditions);
-    }
-
-    /**
-     * 头条广告计划报表信息
-     * @param conditions 查询条件
-     * @return 广告计划报表数据
-     */
-    @GetMapping("bytedance/ad")
-    public Map<String, Object> adReport(@RequestBody ByteDanceAdvertiserReportDTO conditions) {
-        return reportService.getAdReport(conditions);
-    }
-
-    /**
-     * 头条广告创意报表信息
-     * @param conditions
-     * @return
-     */
-    @GetMapping("bytedance/creative")
-    public Map<String, Object> creativeReport(@RequestBody ByteDanceAdvertiserReportDTO conditions) {
-        return reportService.getCreativeReport(conditions);
-    }
-
-    /**
      * 代理商数据
      * @param conditions
      * @return

+ 1 - 1
module-report/src/main/java/cn/com/ctop/bytedance/entity/BytedanceCampaignDailyReport.java

@@ -429,7 +429,7 @@ public class BytedanceCampaignDailyReport {
         }
         String statDatetime = data.getString("stat_datetime");
         if (null != statDatetime && !"".equals(statDatetime.trim())) {
-            this.statDatetime = statDatetime;
+            this.statDatetime = statDatetime.substring(0, 10);
         }
         Long shopping = data.getLong("shopping");
         if (null != shopping) {

+ 2 - 6
module-report/src/main/java/cn/com/ctop/bytedance/service/IReportService.java

@@ -10,12 +10,6 @@ import java.util.Map;
 public interface IReportService {
     Map<String, Object> getAdvertiserReport(ByteDanceAdvertiserReportDTO conditions);
 
-    Map<String, Object> getCampaignReport(ByteDanceAdvertiserReportDTO conditions);
-
-    Map<String, Object> getAdReport(ByteDanceAdvertiserReportDTO conditions);
-
-    Map<String, Object> getCreativeReport(ByteDanceAdvertiserReportDTO conditions);
-
     Map<String, Object> getAgentReport(JSONObject conditions);
 
     void insertCustomerInfo(String csvPath, String charset);
@@ -28,6 +22,8 @@ public interface IReportService {
 
     void getAdvertiserCampaignReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePL);
 
+    void getCampaignReportByPage(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl, Integer pageNum);
+
     void getAdvertiserPlanReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePL);
 
     void getAdvertiserCreativeReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePL);

+ 43 - 105
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/ReportServiceImpl.java

@@ -146,12 +146,10 @@ public class ReportServiceImpl implements IReportService {
         getCampaignReportByPage(token, conditions, 1);
     }
 
-    private void getCampaignReportByPage(CtopOauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
-        conditions.setPage(page);
-        SerializeConfig config = new SerializeConfig();
-        config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
-        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
-        JSONObject getObject = getCampaignStat(token, jsonObject);
+    @Override
+    public void getCampaignReportByPage(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl, Integer pageNum) {
+        JSONObject getObject = getCampaignStat(token, startDate, endDate, bytedanceReportTypePl, pageNum);
+        System.out.println("返回数据:" + getObject.toJSONString());
         Integer code = getObject.getInteger("code");
         String message = getObject.getString("message");
         if (null == code || code != 0) {
@@ -165,51 +163,63 @@ public class ReportServiceImpl implements IReportService {
         }
         for (var i = 0; i < dataArray.size(); i++) {
             var data = dataArray.getJSONObject(i);
-            if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
+            if (CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(bytedanceReportTypePl)) {
                 var hourlyReport = new BytedanceCampaignHourlyReport(data, token.getAccountId());
                 campaignHourlyReportService.saveOrUpdate(hourlyReport);
             } else {
+                System.out.println(data.toJSONString());
                 var dailyReport = new BytedanceCampaignDailyReport(data, token.getAccountId());
                 campaignDailyReportService.saveOrUpdate(dailyReport);
             }
         }
-        getCampaignReportByPage(token, conditions, page + 1);
+        getCampaignReportByPage(token, startDate, endDate, bytedanceReportTypePl, pageNum + 1);
     }
 
-    @Override
-    public Map<String, Object> getCampaignReport(ByteDanceAdvertiserReportDTO conditions) {
-        conditions.setAdvertiserId(111463131228L);
-        conditions.setStartDate("2019-06-01");
-        conditions.setEndDate("2019-06-10");
-        conditions.setPageSize(1000);
-        conditions.setPage(1);
-        conditions.setTimeGranularity(CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
+    private JSONObject getCampaignStat(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl, Integer pageNum) {
+        // 请求地址
+        String url = "https://ad.oceanengine.com/open_api/2/report/campaign/get/";
+        // 请求参数
+        JSONObject params = new JSONObject();
+        params.put("page", pageNum);
+        params.put("page_size", 100);
+        params.put("advertiser_id", token.getAccountId());
+        params.put("start_date", DateUtils.formatDate(startDate));
+        params.put("end_date", DateUtils.formatDate(endDate));
+        params.put("time_granularity", bytedanceReportTypePl);
+        params.put("group_by", new String[]{"STAT_GROUP_BY_FIELD_ID", "STAT_GROUP_BY_FIELD_STAT_TIME"});
+        return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
+    }
+
+    private void getCampaignReportByPage(CtopOauthToken token, ByteDanceAdvertiserReportDTO conditions, int page) {
+        conditions.setPage(page);
         SerializeConfig config = new SerializeConfig();
         config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
         JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
-        Long accountId = conditions.getAdvertiserId();
-        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
-        JSONObject getObject = getAdStat(token, jsonObject);
+        System.out.println(jsonObject.toJSONString());
+        JSONObject getObject = getCampaignStat(token, jsonObject);
+        System.out.println(getObject.toJSONString());
         Integer code = getObject.getInteger("code");
         String message = getObject.getString("message");
         if (null == code || code != 0) {
             log.error("广告组报表数据获取异常:{}", message);
-        } else {
-            JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
-            if (null != dataArray && dataArray.size() > 0) {
-                for (int i = 0; i < dataArray.size(); i++) {
-                    JSONObject data = dataArray.getJSONObject(i);
-                    if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
-                        BytedanceCampaignHourlyReport hourlyReport = new BytedanceCampaignHourlyReport(data, token.getAccountId());
-                        campaignHourlyReportService.saveOrUpdate(hourlyReport);
-                    } else {
-                        BytedanceCampaignDailyReport dailyReport = new BytedanceCampaignDailyReport(data, token.getAccountId());
-                        campaignDailyReportService.saveOrUpdate(dailyReport);
-                    }
-                }
+            return;
+        }
+        JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
+        if (null == dataArray || dataArray.size() <= 0) {
+            log.info("广告组报表信息为空=》accountId:{}", token.getAccountId());
+            return;
+        }
+        for (var i = 0; i < dataArray.size(); i++) {
+            var data = dataArray.getJSONObject(i);
+            if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
+                var hourlyReport = new BytedanceCampaignHourlyReport(data, token.getAccountId());
+                campaignHourlyReportService.saveOrUpdate(hourlyReport);
+            } else {
+                var dailyReport = new BytedanceCampaignDailyReport(data, token.getAccountId());
+                campaignDailyReportService.saveOrUpdate(dailyReport);
             }
         }
-        return getObject;
+        getCampaignReportByPage(token, conditions, page + 1);
     }
 
     @Override
@@ -266,42 +276,6 @@ public class ReportServiceImpl implements IReportService {
     }
 
     @Override
-    public Map<String, Object> getAdReport(ByteDanceAdvertiserReportDTO conditions) {
-        conditions.setAdvertiserId(111463131228L);
-        conditions.setStartDate("2019-06-01");
-        conditions.setEndDate("2019-06-10");
-        conditions.setPageSize(1000);
-        conditions.setPage(1);
-        conditions.setTimeGranularity(CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-        SerializeConfig config = new SerializeConfig();
-        config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
-        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
-        Long accountId = conditions.getAdvertiserId();
-        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
-        JSONObject getObject = getAdStat(token, jsonObject);
-        Integer code = getObject.getInteger("code");
-        String message = getObject.getString("message");
-        if (null == code || code != 0) {
-            log.error("广告计划报表数据获取异常:{}", message);
-        } else {
-            JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
-            if (null != dataArray && dataArray.size() > 0) {
-                for (int i = 0; i < dataArray.size(); i++) {
-                    JSONObject data = dataArray.getJSONObject(i);
-                    if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
-                        BytedancePlanHourlyReport hourlyReport = new BytedancePlanHourlyReport(data, token.getAccountId());
-                        planHourlyReportService.saveOrUpdate(hourlyReport);
-                    } else {
-                        BytedancePlanDailyReport dailyReport = new BytedancePlanDailyReport(data, token.getAccountId());
-                        planDailyReportService.saveOrUpdate(dailyReport);
-                    }
-                }
-            }
-        }
-        return getObject;
-    }
-
-    @Override
     public void getAdvertiserCreativeReport(CtopOauthToken token, Date startDate, Date endDate, String bytedanceReportTypePl) {
         var conditions = getReportDTO(token, startDate, endDate, bytedanceReportTypePl);
         getCreativeReportByPage(token, conditions, 1);
@@ -373,42 +347,6 @@ public class ReportServiceImpl implements IReportService {
     }
 
     @Override
-    public Map<String, Object> getCreativeReport(ByteDanceAdvertiserReportDTO conditions) {
-        conditions.setAdvertiserId(111463131228L);
-        conditions.setStartDate("2019-06-01");
-        conditions.setEndDate("2019-06-10");
-        conditions.setPageSize(1000);
-        conditions.setPage(1);
-        conditions.setTimeGranularity(CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
-        SerializeConfig config = new SerializeConfig();
-        config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
-        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(conditions, config));
-        Long accountId = conditions.getAdvertiserId();
-        CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");
-        JSONObject getObject = getCreativeStat(token, jsonObject);
-        Integer code = getObject.getInteger("code");
-        String message = getObject.getString("message");
-        if (null == code || code != 0) {
-            log.error("广告创意报表数据获取异常:{}", message);
-        } else {
-            JSONArray dataArray = getObject.getJSONObject("data").getJSONArray("list");
-            if (null != dataArray && dataArray.size() > 0) {
-                for (int i = 0; i < dataArray.size(); i++) {
-                    JSONObject data = dataArray.getJSONObject(i);
-                    if (null != conditions.getTimeGranularity() && CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY.equals(conditions.getTimeGranularity())) {
-                        BytedanceCreativeHourlyReport hourlyReport = new BytedanceCreativeHourlyReport(data, token.getAccountId());
-                        creativeHourlyReportService.saveOrUpdate(hourlyReport);
-                    } else {
-                        BytedanceCreativeDailyReport dailyReport = new BytedanceCreativeDailyReport(data, token.getAccountId());
-                        creativeDailyReportService.saveOrUpdate(dailyReport);
-                    }
-                }
-            }
-        }
-        return getObject;
-    }
-
-    @Override
     public Map<String, Object> getAgentReport(JSONObject conditions) {
         Long accountId = conditions.getLong("accountId");
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId + "");