yumeng 1 месяц назад
Родитель
Сommit
3d7ce43017

+ 19 - 54
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/controller/KuaishouController.java

@@ -34,6 +34,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -83,45 +85,22 @@ public class KuaishouController {
 
     @ApiOperation(value = "根据账户获取视频素材-账户下全部视频素材", notes = "根据账户获取视频素材-账户下全部视频素材")
     @GetMapping(value = "/KuaishouUnitAudienceReport")
-    public void KuaishouUnitAudienceReportJob(String date) throws Exception {
-
-        List<JSONObject> tokens = tokenService.getByProjectId(458L);    //淘特项目
-//        String date = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.getNowDate("yyyy-MM-dd"), -1);
-        Date enDate = DateUtils.addDay(DateUtils.getNowDate(), -1);
-        for (JSONObject t : tokens) {
-            Long accountId = t.getLong("accountId");
-            String token = t.getString("accessToken");
-            if (Check.isNull(token)) {
-                log.error("此账户未获取到相关token,accountId:{}", accountId);
-                continue;
-            }
-            //过期跳过
-            if (enDate.after(t.getDate("accessTokenExpiresIn"))) {
-                continue;
-            }
-            //广告计划 ID 集
-            List<JSONObject> campaignArray = unitReportDailyService.selectPlanIdsByAccountIdAndTime(accountId, date);
-            if (Check.isNull(campaignArray)) {
-                log.error("未查询到计划ID");
-                continue;
-            }
-            //广告组 ID 集
-            for (JSONObject obj : campaignArray) {
-                Long campaignId = obj.getLong("campaignId");
-                List<Long> unitIds = unitReportDailyService.selectUnitIdsByAccountIdAndTime(accountId, campaignId, date);
-                if (Check.isNull(unitIds)) {
-                    continue;
-                }
-                if (unitIds.size() > 59) {
-                    List<List<Long>> unitIdArray = Lists.partition(unitIds, 59);
-                    for (List<Long> list : unitIdArray) {
-                        unitReportDailyService.standardCrowdAnalysisReport(accountId, token, date, campaignId, list);
-                    }
-                } else {
-                    unitReportDailyService.standardCrowdAnalysisReport(accountId, token, date, campaignId, unitIds);
-                }
-            }
+    public void KuaishouUnitAudienceReportJob() throws Exception {
+
+
+        LocalDate start = LocalDate.of(2024, 5, 1);
+        LocalDate end = LocalDate.of(2024, 12, 31);
+
+        List<LocalDate> dateList = DateUtils.getDatesBetween(start, end);
+        for (int i = 0; i < dateList.size(); i++) {
+            LocalDate localDate = dateList.get(i);
+            String s = localDate + "";
+            Long date = Long.valueOf(s.replace("-", ""));
+            adUnitReportService.deleteData(date);
+            System.err.println(date + ":数据删除成功");
         }
+
+
     }
 
 
@@ -197,24 +176,10 @@ public class KuaishouController {
     @GetMapping(value = "/testOne")
     public void testOne(@RequestParam(name = "accountId") long accountId) throws Exception {
         String token = tokenService.getByAccountId(accountId);
-//        List<String> list = new ArrayList<>();
-//        list.add("2023-11-10");
-//        list.add("2023-08-26");
-//        list.add("2023-08-27");
-//        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
-//        String date = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -4);
-//        for (String s : list) {
-//            unitReportDailyService2.getUnitReportDaily(accountId, token, s, s, 1);
-//        adUnitReportService.getAgentReport();
-        kuaishouAccountReportHourlyService
-                .getAdvertiserReportHour(accountId, token, "2024-07-11", "2024-07-11", 1);
-//        videoListService.getVideoList(accountId, token, null, null, 1);
-//            campaignReportDailyService.getCampaignReportDaily(accountId, token, s, s, 1);
-//        }
 
-//        videoReportDailyService.getImageReportDaily(accountId, token, date, nowDate, 1);
+        kuaishouAccountReportHourlyService
+                .getAdvertiserReportHour(accountId, token, "2025-11-05", "2025-11-05", 1);
 
-//        videoListService.getVideosByAccountId(accountId, "2023-11-01", "2023-11-09");
 
 
     }

+ 4 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/OauthAgentTokenMapper.java

@@ -21,4 +21,8 @@ public interface OauthAgentTokenMapper extends BaseMapper<OauthAgentToken> {
 
 
     OauthAgentToken getTokenByAppId(@Param("appId") Long appId);
+
+    void deleteKuaishou(@Param("date") Long date);
+
+    void deleteBytedance(@Param("date") Long date);
 }

+ 8 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/xml/OauthAgentTokenMapper.xml

@@ -1,6 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.job.kuaishou.data.mapper.OauthAgentTokenMapper">
+    <delete id="deleteKuaishou">
+        delete from application.kuaishou_account_report_hourly_dw where stat_date  = #{date}
+    </delete>
+    <delete id="deleteBytedance">
+        delete
+        from application.bytedance_advertiser_report_hourly_dw
+        where stat_datetime = #{date}
+    </delete>
 
     <!-- 查询快手代理商信息 -->
     <select id="getOauthAgentTokenKs" resultType="cn.com.ctop.job.kuaishou.data.entity.OauthAgentToken">

+ 1 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IAdUnitReportService.java

@@ -36,4 +36,5 @@ public interface IAdUnitReportService {
     void getAgentAccountList();
 
 
+    void deleteData(Long date);
 }

+ 6 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/AdUnitReportServiceImpl.java

@@ -857,6 +857,12 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
 
     }
 
+    @Override
+    public void deleteData(Long date) {
+        agentTokenMapper.deleteKuaishou(date);
+        agentTokenMapper.deleteBytedance(date);
+    }
+
 
     /**
      * 代理商获取广告主列表

+ 22 - 8
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/impl/KuaishouAccountReportDailyServiceImpl.java

@@ -22,6 +22,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 快手-账户日报
@@ -32,6 +34,7 @@ import java.util.Map;
 @Slf4j
 @Service
 public class KuaishouAccountReportDailyServiceImpl extends ServiceImpl<KuaishouAccountReportDailyMapper, KuaishouAccountReportDaily> implements IKuaishouAccountReportDailyService {
+    private static ExecutorService hourExecutorService = Executors.newFixedThreadPool(20);
 
     @Autowired
     private KuaishouAccountReportDailyMapper accountReportDailyMapper;
@@ -80,14 +83,25 @@ public class KuaishouAccountReportDailyServiceImpl extends ServiceImpl<KuaishouA
 
     @Override
     public void sendMessage(Long accountId, String startDate, String endDate, String date_type) {
-        String url = KuaishouConstant.SEND_URL;
-        Map<String, Object> param = new HashMap<>();
-        param.put("start_date", DateUtils.getDateInteger(startDate));
-        param.put("end_date", DateUtils.getDateInteger(endDate));
-        param.put("account_id", accountId);
-        param.put("date_type", date_type);
-        String result = HttpUtils.httpPostRequest(url, param, null);
-        System.err.println(result);
+
+        hourExecutorService.submit(
+                new Runnable() {
+                    @Override
+                    public void run() {
+                        String url = KuaishouConstant.SEND_URL;
+                        Map<String, Object> param = new HashMap<>();
+                        param.put("start_date", DateUtils.getDateInteger(startDate));
+                        param.put("end_date", DateUtils.getDateInteger(endDate));
+                        param.put("account_id", accountId);
+                        param.put("date_type", date_type);
+                        String result = HttpUtils.httpPostRequest(url, param, null);
+                        System.err.println(result);
+                    }
+                });
+
+
+
+
     }
 
     @Override

+ 33 - 4
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/utils/DateUtils.java

@@ -2,6 +2,8 @@ package cn.com.ctop.job.kuaishou.data.utils;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -9,6 +11,37 @@ import java.util.List;
 
 public class DateUtils {
 
+
+    public static void main(String[] args) {
+        LocalDate start = LocalDate.of(2022, 1, 1);
+        LocalDate end = LocalDate.of(2022, 12, 31);
+
+        List<LocalDate> dateList = getDatesBetween(start, end);
+        System.err.println(dateList);
+    }
+
+
+    public static List<LocalDate> getDatesBetween(LocalDate startDate, LocalDate endDate) {
+        List<LocalDate> dates = new ArrayList<>();
+
+        // 检查开始日期是否在结束日期之后
+        if (startDate.isAfter(endDate)) {
+            throw new IllegalArgumentException("开始日期不能晚于结束日期");
+        }
+
+        // 计算两个日期之间的天数差
+        long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
+
+        // 添加范围内的所有日期
+        for (long i = 0; i <= daysBetween; i++) {
+            dates.add(startDate.plusDays(i));
+        }
+
+        return dates;
+    }
+
+
+
     public static Integer getDateInteger(String date) {
         if (!Check.isNull(date)) {
             String replace = date.replace("-", "");
@@ -113,8 +146,4 @@ public class DateUtils {
         return d2;
     }
 
-    public static void main(String[] args) {
-
-        System.out.println(tempToDate(1721873285120L,"yyyy-MM-dd HH:mm:ss"));
-    }
 }