Parcourir la source

修改报表接口

yumeng il y a 5 ans
Parent
commit
a90bf2fc17

+ 128 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouReportController.java

@@ -0,0 +1,128 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.ParseException;
+import java.util.List;
+
+/**
+ * @Description: 快手-本地图片保存
+ * @Author: jeecg-boot
+ * @Date: 2019-08-14
+ * @Version: V1.0
+ */
+@Slf4j
+
+@RestController
+@RequestMapping("/kuaishou/getReport")
+public class KuaiShouReportController {
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private CtopOauthTokenMapper ctopOauthTokenMapper;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+
+
+    @RequestMapping(value = "/historyData")
+    public String queryPageList() throws ParseException {
+
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("media_id", 2);
+        queryWrapper.groupBy("account_id");
+        List<UserAllocation> userAllocations = userAllocationMapper.selectList(queryWrapper);
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        if (!Check.isNull(userAllocations)) {
+            for (UserAllocation allocation : userAllocations) {
+                String beginDate = null;
+                String hourDate = null;
+                Long accountId = allocation.getAccountId();
+                if (!Check.isNull(accountId)) {
+                    QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
+                    tokenQueryWrapper.eq("account_id", accountId);
+                    tokenQueryWrapper.eq("media_id", 2);
+                    tokenQueryWrapper.orderByDesc("create_time");
+                    tokenQueryWrapper.last("limit 1");
+                    CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectOne(tokenQueryWrapper);
+                    if (!Check.isNull(ctopOauthToken)) {
+                        //   String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum
+                        String accessToken = ctopOauthToken.getAccessToken();
+                        Long advertiserId = ctopOauthToken.getAccountId();
+                        for (int i = 0; i < 6; i++) {
+                            if (i == 0) {
+                                String monthBefore = DateUtils.getMonthBefore("yyyy-MM-dd", nowDate, -1);
+                                System.err.println("开始时间:" + anotherDay);
+                                System.err.println("结束时间:" + monthBefore);
+                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, anotherDay, 500, 1);
+                                beginDate = monthBefore;
+
+
+                            } else if (i > 0) {
+                                String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", beginDate, -1);
+                                String monthBefore = DateUtils.getMonthBefore("yyyy-MM-dd", beginDate, -1);
+                                System.err.println("开始时间:" + startDate);
+
+                                if (i == 5) {
+                                    monthBefore = DateUtils.getAnotherDay("yyyy-MM-dd", monthBefore, 4);
+                                }
+                                System.err.println("结束时间:" + monthBefore);
+                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, startDate, 1, 500);
+                                beginDate = monthBefore;
+
+                                //
+
+                            }
+
+                        }
+
+                        for (int i = 0; i < 7; i++) {
+                            if (i == 0) {
+                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, nowDate, nowDate, 1, 500);
+                                hourDate = nowDate;
+                                System.err.println(nowDate);
+                            } else if (i > 0) {
+                                String hourAnotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", hourDate, -1);
+                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, hourAnotherDay, hourAnotherDay, 1, 500);
+                                System.err.println(hourAnotherDay);
+                                hourDate = hourAnotherDay;
+                            }
+
+                        }
+
+
+                        //     kuaishouInterfaceService.getAccountDailyReport();
+
+                    }
+
+                }
+
+            }
+        }
+
+
+        return null;
+
+
+    }
+
+
+    public static void main(String[] args) throws ParseException {
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String anotherDay1 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay1, -180);
+
+        System.err.println(anotherDay);
+    }
+}

+ 54 - 13
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -126,7 +126,35 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("page", pageNum);
         KuaishouResult<KuaishouReportHourlyAccount> kuaishouResult = null;
         try {
+
             String result = HttpUtils.httpPostRequest(url, param, headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                if (resultJson.getInteger("code") == 0) {
+                    JSONObject dataJson = resultJson.getJSONObject("data");
+                    if (!Check.isNull(dataJson)) {
+                        JSONArray details = dataJson.getJSONArray("details");
+                        for (int i = 0; i < details.size(); i++) {
+                            JSONObject detailJson = details.getJSONObject(i);
+                            Long show = detailJson.getLong("show");
+                            detailJson.put("photo_show", show);
+                            Long like = detailJson.getLong("like");
+                            detailJson.put("photo_like", like);
+                            KuaishouReportHourlyAccount kuaishouReportHourlyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyAccount.class);
+                            System.err.println(kuaishouReportHourlyAccount);
+                            kuaishouReportHourlyAccount.setAccountId(advertiserId);
+                            kuaishouReportHourlyAccount.setId("" + advertiserId + kuaishouReportHourlyAccount.getStatDate() + kuaishouReportHourlyAccount.getStatHour());
+                            hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);
+                        }
+
+                    }
+
+                }
+
+            }
+
+
+            /*String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject resultJson = JSONArray.parseObject(result);
             if (!Check.isNull(resultJson)) {
 
@@ -140,7 +168,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 hourlyAccount.setAccountId(advertiserId);
                 hourlyAccount.setId("" + hourlyAccount.getAccountId() + hourlyAccount.getStatDate() + hourlyAccount.getStatHour());
                 hourlyAccountService.saveOrUpdate(hourlyAccount);
-            });
+            });*/
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -160,23 +188,36 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("temporal_granularity", "DAILY");
         param.put("page_size", pageSize);
         param.put("page", pageNum);
-        KuaishouResult<KuaishouReportDailyAccount> kuaishouResult = null;
         try {
             String result = HttpUtils.httpPostRequest(url, param, headers);
-            ObjectMapper mapper = new ObjectMapper();
-            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-            kuaishouResult = mapper.readValue(result, new TypeReference<KuaishouResult<KuaishouReportDailyAccount>>() {
-            });
-            List<KuaishouReportDailyAccount> dailyAccounts = kuaishouResult.getData().getDetails();
-            dailyAccounts.forEach((hourlyAccount -> {
-                hourlyAccount.setAccountId(advertiserId);
-                hourlyAccount.setId("" + hourlyAccount.getAccountId() + hourlyAccount.getStatDate());
-                dailyAccountService.saveOrUpdate(hourlyAccount);
-            }));
+
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                if (resultJson.getInteger("code") == 0) {
+                    JSONObject dataJson = resultJson.getJSONObject("data");
+                    if (!Check.isNull(dataJson)) {
+                        JSONArray details = dataJson.getJSONArray("details");
+                        for (int i = 0; i < details.size(); i++) {
+                            JSONObject detailJson = details.getJSONObject(i);
+                            Long show = detailJson.getLong("show");
+                            detailJson.put("photo_show", show);
+                            Long like = detailJson.getLong("like");
+                            detailJson.put("photo_like", like);
+                            KuaishouReportDailyAccount kuaishouReportDailyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportDailyAccount.class);
+                            kuaishouReportDailyAccount.setAccountId(advertiserId);
+                            kuaishouReportDailyAccount.setId("" + advertiserId + kuaishouReportDailyAccount.getStatDate());
+                            dailyAccountService.saveOrUpdate(kuaishouReportDailyAccount);
+                        }
+
+                    }
+
+                }
+
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
-        return kuaishouResult;
+        return null;
     }
 
     @Override

+ 5 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportDailyAccount.java

@@ -23,10 +23,11 @@ public class KuaishouReportDailyAccount implements Serializable {
 
     @JsonProperty
     private BigDecimal charge;
-    @TableField("photo_show")
-    private Long show;
+
+    @JsonProperty
+    private Long photoShow;
+
     @JsonProperty("photo_click")
-    @TableField("photo_click")
     private Long photoClick;
 
     @JsonProperty
@@ -38,8 +39,7 @@ public class KuaishouReportDailyAccount implements Serializable {
     @JsonProperty
     private Long comment;
     @JsonProperty
-    @TableField("`like`")
-    private Long like;
+    private Long photoLike;
     @JsonProperty
     private Long follow;
     @JsonProperty("cancel_follow")

+ 5 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportHourlyAccount.java

@@ -1,6 +1,5 @@
 package cn.com.ctop.kuaishou.modules.report.entity;
 
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -8,6 +7,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+
 @Data
 @TableName("ctop_kuaishou_report_hourly_account")
 public class KuaishouReportHourlyAccount implements Serializable {
@@ -24,10 +24,10 @@ public class KuaishouReportHourlyAccount implements Serializable {
 
     @JsonProperty
     private BigDecimal charge;
-    @TableField("photo_show")
-    private Long show;
+
+    @JsonProperty
+    private Long photoShow;
     @JsonProperty("photo_click")
-    @TableField("photo_click")
     private Long photoClick;
     @JsonProperty
     private Long aclick;
@@ -38,8 +38,7 @@ public class KuaishouReportHourlyAccount implements Serializable {
     @JsonProperty
     private Long comment;
     @JsonProperty
-    @TableField("`like`")
-    private Long like;
+    private Long photoLike;
     @JsonProperty
     private Long follow;
     @JsonProperty("cancel_follow")

+ 4 - 4
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/BytedanceReportMapper.xml

@@ -69,10 +69,10 @@
 
     <select id="selectDayDetailByDate" resultType="com.alibaba.fastjson.JSONObject">
       select
-       charge cost,
-       photo_show photoShow,
-       photo_click photoClick,
-       aclick aclick,
+       sum(charge) cost,
+       sum(photo_show) photoShow,
+       sum(photo_click) photoClick,
+       sum(aclick) aclick,
        stat_date statDate
      from
       ctop_kuaishou_report_daily_account

+ 9 - 7
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java

@@ -137,7 +137,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                         kuaishouDetailJson.put("click", click);
                         kuaishouClick += click;
 
-                        Long show = reportDailyAccount.getShow();
+                        Long show = reportDailyAccount.getPhotoShow();
                         kuaishouDetailJson.put("show", show);
                         kuaishouShow += show;
 
@@ -209,8 +209,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     if (!Check.isNull(yesterdayJson)) {
                         BigDecimal cost = accountJson.getBigDecimal("cost"); // 今日消耗
                         BigDecimal yesterdayCost = yesterdayJson.getBigDecimal("cost");// 昨日消耗
-                        BigDecimal compareBigDecima = new BigDecimal(0);
-                        if (yesterdayCost.compareTo(compareBigDecima) != 0) {
+                        BigDecimal compareBigDecimal = new BigDecimal(0);
+                        if (yesterdayCost.compareTo(compareBigDecimal) != 0) {
                             BigDecimal costProportion = (cost.subtract(yesterdayCost)).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP);
                             accountJson.put("costProportion", costProportion); // 较昨日增加比例
                         } else {
@@ -618,11 +618,13 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
                 } else if ("day".equals(sign)) {
                     List<JSONObject> comparedArr = reportMapper.selectHourlyDetailsByDate(comparedDate);// 除数数据
-                    detailJson.put("beStatDate", beComparedDate);
-                    detailJson.put("beComparedDetail", comparedArr);
+                    detailJson.put("statDate", beComparedDate);
+                    detailJson.put("comparedDetail", comparedArr);
+
+
                     List<JSONObject> beComparedArr = reportMapper.selectHourlyDetailsByDate(beComparedDate);// 被除数数据
-                    detailJson.put("statDate", comparedDate);
-                    detailJson.put("comparedDetail", beComparedArr);
+                    detailJson.put("beStatDate", comparedDate);
+                    detailJson.put("beComparedDetail", beComparedArr);
 
                 }
                 reportList.add(detailJson);