yumeng 1 miesiąc temu
rodzic
commit
94d0f05879

+ 22 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/BytedanceJobApplication.java

@@ -1,16 +1,26 @@
 package cn.com.ctop.job.bytedance;
 
+import cn.com.ctop.job.bytedance.data.service.IBytedanceReportNewService;
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
 @Slf4j
 @SpringBootApplication
 @ComponentScan(basePackages = {"cn.com.ctop"})
 @Configuration
 public class BytedanceJobApplication {
-    public static void main(String[] args){
+    @Autowired
+    private IBytedanceReportNewService bytedanceReportNewService;
+
+    public static void main(String[] args) {
 
         SpringApplication.run(BytedanceJobApplication.class, args);
 
@@ -19,4 +29,15 @@ public class BytedanceJobApplication {
                 "----------------------------------------------------------");
     }
 
+    @Bean
+    CommandLineRunner runAtStartup() {
+        return args -> {
+            System.out.println("初始化数据....");
+            JSONObject tokenJson = bytedanceReportNewService.getTokenInfo();
+            bytedanceReportNewService.getMetrics(tokenJson.getLong("accountId"), tokenJson.getString("accessToken"));
+            System.out.println("初始化数据完成....");
+        };
+    }
+
+
 }

+ 1 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -49,7 +49,7 @@ public class BytedanceController {
     public Map<String, String> getBytedanceVideoByAccountId(@RequestBody JSONObject jsonObject) {
         Long accountId = 1839154028649483L;
         String token = tokenService.getByAccountId(accountId);
-        bytedanceReportNewService.getAdvertiserDailyReport(accountId, token, "2025-08-30", "2025-08-30", 1);
+        bytedanceReportNewService.getAdvertiserDailyReport(accountId, token, "2025-08-30", "2025-09-02", 1);
         return null;
     }
 

+ 3 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/AccountReportNewMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.bytedance.data.mapper;
 
 import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportDaily;
 import cn.com.ctop.job.bytedance.data.entity.BytedanceAdvertiserReportHourly;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -10,4 +11,6 @@ public interface AccountReportNewMapper {
     void replaceAccountReportHour(@Param("adds") List<BytedanceAdvertiserReportHourly> hours);
 
     void replaceAccountReportDailys(@Param("adds") List<BytedanceAdvertiserReportDaily> dailies);
+
+    JSONObject getTokenInfo();
 }

+ 7 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/AccountReportNewMapper.xml

@@ -331,5 +331,12 @@
         </foreach>
 
     </insert>
+    <select id="getTokenInfo" resultType="com.alibaba.fastjson.JSONObject">
+        select account_id as 'accountId', access_token as 'accessToken'
+        from `jeecg-boot`.ctop_oauth_token
+        where media_id = 1
+        order by update_time desc
+            limit 1
+    </select>
 
 </mapper>

+ 6 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceReportNewService.java

@@ -1,9 +1,15 @@
 package cn.com.ctop.job.bytedance.data.service;
 
 import cn.com.ctop.job.bytedance.data.entity.OauthToken;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 
 public interface IBytedanceReportNewService {
     void getBytedanceAccountHour(Long advertiserId, String accessToken, String startDate, String endDate, Integer page);
 
     void getAdvertiserDailyReport(Long advertiserId, String oauthToken, String nowDate, String endDate, int page);
+
+    JSONArray getMetrics(Long advertiserId, String token);
+
+    JSONObject getTokenInfo();
 }

+ 7 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceReportNewServiceImpl.java

@@ -214,7 +214,8 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
         }
     }
 
-    private JSONArray getMetrics(Long advertiserId, String token) {
+    @Override
+    public JSONArray getMetrics(Long advertiserId, String token) {
         if (!Check.isNull(metrics)) {
             return metrics;
         }
@@ -258,4 +259,9 @@ public class BytedanceReportNewServiceImpl implements IBytedanceReportNewService
         }
         return metrics;
     }
+
+    @Override
+    public JSONObject getTokenInfo() {
+        return accountReportNewMapper.getTokenInfo();
+    }
 }