浏览代码

Merge remote-tracking branch 'origin/master'

zhaoxian 1 年之前
父节点
当前提交
2977416b53

+ 0 - 68
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/controller/ByteDanceVideoReportDailyController.java

@@ -43,74 +43,6 @@ public class ByteDanceVideoReportDailyController {
     @Autowired
     private IByteDanceVideoReportDailyService videoReportDailyService;
 
-    @AutoLog(value = "头条视频按天汇总")
-    @ApiOperation(value = "头条视频按天汇总", notes = "头条视频按天汇总")
-    @PostMapping(value = "/bytedanceVideoInfoList")
-    public Result bytedanceVideoInfoList(@RequestParam(name = "startDate") String startDate,
-                                         @RequestParam(name = "endDate") String endDate,
-                                         HttpServletRequest req) {
-        Result result = new Result();
-        int days = DateUtils.dateDiff(startDate, endDate);
-        List<String> dateList = new ArrayList<>();
-        for (int i = 0; i <= days; i++) {
-            String endStr = DateUtils.addDay(startDate, i);
-            dateList.add(endStr);
-        }
-
-        final ExecutorService executorService = Executors.newFixedThreadPool(8);
-        dateList.forEach(date -> {
-            executorService.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        log.info("头条视频按天汇总接口现在在跑的时间为:" + date + "~" + date);
-                        videoReportDailyService.videoInfoList(date, date);
-                        log.info("头条视频按天汇总接口运行结束,时间为" + date + "~" + date);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    } finally {
-                    }
-                }
-            });
-        });
-
-        result.setSuccess(true);
-        return result;
-    }
-
-    @AutoLog(value = "头条视频单个账户按天汇总")
-    @ApiOperation(value = "头条视频单个账户按天汇总", notes = "头条视频单个账户按天汇总")
-    @GetMapping(value = "/videoInfoListByAccountId")
-    public Result videoInfoListByAccountId(@RequestParam(name = "startDate") String startDate,
-                                           @RequestParam(name = "endDate") String endDate,
-                                           @RequestParam(name = "accountId") Long accountId,
-                                           HttpServletRequest req) {
-        Result result = new Result();
-        int days = DateUtils.dateDiff(startDate, endDate);
-        List<String> dateList = new ArrayList<>();
-        for (int i = 0; i <= days; i++) {
-            String endStr = DateUtils.addDay(startDate, i);
-            dateList.add(endStr);
-        }
-
-        final ExecutorService executorService = Executors.newFixedThreadPool(8);
-        dateList.forEach(date -> {
-            executorService.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        videoReportDailyService.videoInfoListByAccountId(date, date, accountId);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    } finally {
-                    }
-                }
-            });
-        });
-
-        result.setSuccess(true);
-        return result;
-    }
 
     @AutoLog(value = "头条视频账户视频关联方法")
     @ApiOperation(value = "头条视频账户视频关联方法", notes = "头条视频账户视频关联方法")

+ 0 - 98
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceReportController.java

@@ -143,107 +143,9 @@ public class BytedanceReportController {
         return result;
     }
 
-    @GetMapping("/bytedance/bytedanceMaterialReporRetry")
-    public Result bytedanceMaterialReportRetry() {
-        log.info("头条获取素材报表失败数据任务重试开始");
-        Result result = new Result<>();
-        try {
-            List<BytedanceReportMaterialRetry> retryList = bytedanceReportService.getRetryList();
-            final ExecutorService executorService = Executors.newFixedThreadPool(3);
-            retryList.forEach(retry -> {
-                executorService.submit(new Runnable() {
-                    @Override
-                    public void run() {
-                        try {
-                            Integer type = retry.getType();
-                            String startDate = retry.getStartDate();
-                            String endDate = retry.getEndDate();
-                            Long accountId = retry.getAccountId();
-                            CtopOauthToken token = tokenService.getOauthTokenByAccountId(String.valueOf(accountId));
-
-                            Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
-                            String start = null;
-                            String end = null;
-                            for (int i = 0; i <= days; i++) {
-                                start = DateUtils.addDay(startDate, i);
-                                end = start;
-                                //获取头条素材报表数据
-                                int code = bytedanceReportService.bytedanceMaterialReportRetry(type, token, start, end);
-                                if (code == 200 || code == 1) {
-                                    if (type == 1) {
-                                        //重试成功清洗数据
-                                        byteDanceVideoReportDailyService.videoInfoListByAccountId(start, end, accountId);
-                                    }
-                                }
-                            }
-
-                        } catch (Exception e) {
-                            e.printStackTrace();
-                        }
-                    }
-                });
-            });
-            ////
-
-        } catch (Exception e) {
-            log.error("头条获取素材报表失败数据任务重试失败");
-            e.printStackTrace();
-            result.setSuccess(false);
-        }
-
-        return result;
-    }
 
-    /**
-     * 绑定头条账户之后的操作,对此账户进行素材报表数据拉取以及素材报表数据清洗
-     *
-     * @param accountId
-     * @param startDate
-     * @param endDate
-     * @return
-     */
-    @GetMapping("/bytedance/bytedanceMaterialReportAndVideoReport")
-    public Result bytedanceMaterialReportAndVideoReport(@RequestParam(name = "accountId") Long accountId,
-                                                        @RequestParam(name = "startDate") String startDate,
-                                                        @RequestParam(name = "endDate") String endDate) {
-        Result result = new Result<>();
-        if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate) || null == accountId) {
-            result.error500("开始时间和结束时间、accountId均不能为空");
-            return result;
-        }
 
-        try {
-            log.info("头条获取素材报表数据任务执行开始");
-            Long starttime = System.currentTimeMillis();
-            CtopOauthToken token = tokenService.getAccessTokenByAccountIdAndMediaId(1, accountId);
-            if (null == token) {
-                log.info("头条获取素材报表数据任务执行失败:未获取到可用的token,accountId:" + accountId);
-                return result;
-            }
 
-            Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
-            String start = null;
-            String end = null;
-            for (int i = 0; i <= days; i++) {
-                start = DateUtils.addDay(startDate, i);
-                end = start;
-                //获取头条素材报表数据
-                int code = bytedanceReportService.bytedanceMaterialReport(token, start, end);
-                //如果成功的话跑视频清洗数据方法,失败会进入重试库,重试成功后再清洗数据
-                if (code == 200 || code == 1) {
-                    byteDanceVideoReportDailyService.videoInfoListByAccountId(start, end, accountId);
-                }
-            }
-
-            Long endtime = System.currentTimeMillis();
-            log.info("头条获取素材报表数据任务执行结束,accountId:{},执行耗时:{}秒", accountId, (endtime - starttime) / 1000);
-        } catch (Exception e) {
-            log.error("头条获取素材报表数据任务执行结失败accountId:" + accountId);
-            e.printStackTrace();
-            result.setSuccess(false);
-        }
-        return result;
-    }
 
 
     /**

+ 110 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceVideoReportCtrl.java

@@ -7,6 +7,7 @@ import cn.com.ctop.toutiao.modules.report.service.IBytedanceVideoReportService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
+import io.swagger.models.auth.In;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
@@ -19,12 +20,16 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.naming.ldap.HasControls;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Created by JQ.bi on 2020.09.21
@@ -37,6 +42,94 @@ public class BytedanceVideoReportCtrl {
     @Autowired
     IBytedanceVideoReportService bytedanceVideoReportService;
 
+
+    @PostMapping("/getBytedanceSevenDayCost")
+    public Result<PageInfo<JSONObject>> getBytedanceSevenDayCost(@RequestBody JSONObject requestBody) {
+        Result<PageInfo<JSONObject>> result = new Result<>();
+        if (requestBody.isEmpty()) {
+            log.error("request body is empty");
+            result.setSuccess(false);
+        } else {
+            Long projectId = requestBody.getLong("projectId");
+            Long startDate = Long.valueOf(requestBody.getString("startDate").replace("-", ""));
+            Long endDate = Long.valueOf(requestBody.getString("endDate").replace("-", ""));
+            Map<String, Long> requestMap = new HashMap<>();
+            if (!Check.isNull(projectId)) {
+                requestMap.put("projectId", projectId);
+            }
+            if (!Check.isNull(startDate)) {
+                requestMap.put("startDate", startDate);
+            }
+            if (!Check.isNull(endDate)) {
+                requestMap.put("endDate", endDate);
+            }
+            Integer pageSize = requestBody.getInteger("pageSize");
+            Integer pageNo = requestBody.getInteger("pageNo");
+            try {
+                PageInfo<JSONObject> listData = bytedanceVideoReportService.getBytedanceSevenDayCost(requestMap, pageSize, pageNo);
+                result.setResult(listData);
+                result.setSuccess(true);
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                result.setSuccess(false);
+            }
+        }
+        return result;
+    }
+
+    @PostMapping("/exportBytedanceSevenDayCost")
+    public void exportBytedanceSevenDayCost(HttpServletRequest request, HttpServletResponse response,@RequestBody JSONObject requestBody) {
+
+        if (requestBody.isEmpty()) {
+            log.error("request body is empty");
+
+        } else {
+            Long projectId = requestBody.getLong("projectId");
+            Long startDate = Long.valueOf(requestBody.getString("startDate").replace("-", ""));
+            Long endDate = Long.valueOf(requestBody.getString("endDate").replace("-", ""));
+            Map<String, Long> requestMap = new HashMap<>();
+            if (!Check.isNull(projectId)) {
+                requestMap.put("projectId", projectId);
+            }
+            if (!Check.isNull(startDate)) {
+                requestMap.put("startDate", startDate);
+            }
+            if (!Check.isNull(endDate)) {
+                requestMap.put("endDate", endDate);
+            }
+
+            try {
+                List<JSONObject> listData = bytedanceVideoReportService.getBytedanceSevenDayCostNoPage(requestMap);
+                List<List<Object>> exportList = new ArrayList<>();
+                if (!Check.isNull(listData)) {
+                    for (int i = 0; i < listData.size(); i++) {
+                        JSONObject date = listData.get(i);
+                        List<Object> export = new ArrayList();
+                        export.add(date.getString("project_name"));
+                        export.add(date.getString("material_id"));
+                        export.add(date.getString("material_name"));
+                        export.add(date.getString("first_cost_time"));
+                        export.add(date.getString("diff_day"));
+                        export.add(date.getString("seven_day_cost"));
+                        exportList.add(export);
+                    }
+                }
+                String[] headers = {"项目名称", "素材ID", "素材名称", "首次消耗日期", "消耗天数", "消耗"};
+                OutputStream os = response.getOutputStream();
+                ExportExcelUtils eeu = new ExportExcelUtils();
+                XSSFWorkbook workbook = new XSSFWorkbook();
+                eeu.exportExcel(workbook, 0, "首消视频", headers, exportList);
+                this.setResponseHeader(response, "首消视频.xls");
+                workbook.write(os);
+                os.flush();
+                os.close();
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+            }
+        }
+    }
+
+
     @PostMapping("/list")
     public Result<PageInfo<JSONObject>> getListReport(@RequestBody JSONObject requestBody) {
         Result<PageInfo<JSONObject>> result = new Result<>();
@@ -216,4 +309,21 @@ public class BytedanceVideoReportCtrl {
             log.error(e.getMessage());
         }
     }
+
+    //发送响应流方法
+    public void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            try {
+                fileName = new String(fileName.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
 }

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/BytedanceVideoReportMapper.java

@@ -5,10 +5,13 @@ import com.alibaba.fastjson.JSONObject;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 public interface BytedanceVideoReportMapper {
 
     List<JSONObject> queryVideoReportBy(@Param("accountIds") JSONArray accountIds,@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("filed") String filed,@Param("target") String target,@Param("order") String order,@Param("clip") String clip,@Param("shot") String shot,@Param("plan") String plan,@Param("leader") String leader);
 
     List<JSONObject> queryVideoDetailBy(@Param("accountIds") JSONArray accountIds,@Param("startDate") String startDate,@Param("endDate") String endDate,@Param("filed") String filed,@Param("signature") String signature);
+
+    List<JSONObject> getBytedanceSevenDayCost(Map<String, Long> requestMap);
 }

+ 22 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceVideoReportMapper.xml

@@ -76,4 +76,26 @@
         GROUP BY t1.signature,t1.stat_datetime
         order by t1.stat_datetime desc
     </select>
+    <select id="getBytedanceSevenDayCost" resultType="com.alibaba.fastjson.JSONObject">
+        select project_name,
+        cast(material_id as char) as 'material_id',
+        material_name,
+        date_format(first_cost_time, '%Y-%m-%d') as 'first_cost_time',
+        (diff_day + 1) as diff_day,
+        seven_day_cost
+        from application.bytedance_material_seven_day_cost
+        where 1 = 1
+        <if test="projectId != null ">
+            and project_id = #{projectId}
+        </if>
+        <if test="startDate != null ">
+            and first_cost_time &gt;= #{startDate}
+        </if>
+        <if test="endDate != null ">
+            and first_cost_time &lt;= #{endDate}
+        </if>
+        and media_id = 1
+        order by seven_day_cost desc
+
+    </select>
 </mapper>

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceVideoReportService.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
 
 import java.util.List;
+import java.util.Map;
 
 public interface IBytedanceVideoReportService {
 
@@ -16,4 +17,8 @@ public interface IBytedanceVideoReportService {
     List<JSONObject> exportExcelReportBy(JSONArray accountIds, String startDate, String endDate, String filed, String target, String order, String clip, String shot, String plan, String leader);
 
     void pullVideoReport(CtopOauthToken oauthToken,String startDate, String endDate,int page);
+
+    PageInfo<JSONObject> getBytedanceSevenDayCost(Map<String, Long> requestMap, Integer pageSize, Integer pageNo);
+
+    List<JSONObject> getBytedanceSevenDayCostNoPage(Map<String, Long> requestMap);
 }

+ 12 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceVideoReportServiceImpl.java

@@ -101,4 +101,16 @@ public class BytedanceVideoReportServiceImpl implements IBytedanceVideoReportSer
             pullVideoReport(oauthToken, startDate, endDate, page + 1);
         }
     }
+
+    @Override
+    public PageInfo<JSONObject> getBytedanceSevenDayCost(Map<String, Long> requestMap, Integer pageSize, Integer pageNo) {
+        PageHelper.startPage(pageNo,pageSize);
+        List<JSONObject> jsonObjectList=bytedanceVideoReportMapper.getBytedanceSevenDayCost(requestMap);
+        return new PageInfo<>(jsonObjectList);
+    }
+
+    @Override
+    public List<JSONObject> getBytedanceSevenDayCostNoPage(Map<String, Long> requestMap) {
+        return bytedanceVideoReportMapper.getBytedanceSevenDayCost(requestMap);
+    }
 }

+ 4 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -241,7 +241,7 @@ public class CallbackController {
                     Integer materialType = materialTypeArr.getInteger(0);
                     //账号绑定
                     bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId);
-                    if (json.getInteger("dataSync") == 1) {
+          /*          if (json.getInteger("dataSync") == 1) {
                         Thread t = new Thread() {
                             @Override
                             public void run() {
@@ -259,7 +259,7 @@ public class CallbackController {
                         t.start();
                     } else if (json.getInteger("dataSync") == 2) {
                         log.info("客户自运营,无需获取数据");
-                    }
+                    }*/
                 }
                 detailService.removeById(id);
                 return "授权绑定成功";
@@ -416,7 +416,7 @@ public class CallbackController {
                             }
                             //账号绑定
                             bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiserId);
-                            new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
+                        //    new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
                         }
 
                     }
@@ -471,7 +471,7 @@ public class CallbackController {
                     }
                     //账号绑定
                     bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiserId);
-                    new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
+                  //  new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
                 }
 
 

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -996,7 +996,7 @@ public class TestController {
 
 
 
-    @GetMapping("loadBytedanceHistoryData")
+/*    @GetMapping("loadBytedanceHistoryData")
     public Map<String, Object> loadBytedanceHistoryData() {
         Map<String, Object> result = new HashMap<>();
         //1:查询所有头条的token数据
@@ -1014,7 +1014,7 @@ public class TestController {
         }
         ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
         return result;
-    }
+    }*/
 
 
     @GetMapping(value = "/getPlanAndGroupByAccount")