Ver código fonte

常读推广链拉取分天

huangpingkang 1 ano atrás
pai
commit
cfc51f21e4

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

@@ -45,7 +45,7 @@ public class BytedanceController {
 
         String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
         String yesDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
-       List<JSONObject> dataList =  promoterReportService.getListBydate(20250312);
+        List<JSONObject> dataList = promoterReportService.getListBydate(20250312);
         for (int i = 0; i < dataList.size(); i++) {
             JSONObject jsonObject = dataList.get(i);
             Long advertiserId = jsonObject.getLong("advertiserId");
@@ -57,21 +57,19 @@ public class BytedanceController {
         }
 
 
-
-
-
-
     }
 
 
     @GetMapping("/getChannel")
-    public void getChannel() {
+    public void getChannel(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
         List<JSONObject> channelList = promoterReportService.getChannelInfoList();
+        startDate = startDate == null ? DateUtils.getNowAddDate("yyyy-MM-dd", -1) : startDate;
+        endDate = endDate == null ? DateUtils.getNowDate("yyyy-MM-dd") : endDate;
         for (int i = 0; i < channelList.size(); i++) {
             JSONObject jsonObject = channelList.get(i);
             String channelAccountId = jsonObject.getString("channelAccountId");
             String secretKey = jsonObject.getString("secretKey");
-            channelService.getPromotionIdList(channelAccountId, secretKey, 0);
+            channelService.getPromotionIdList(startDate, endDate, channelAccountId, secretKey, 0);
         }
     }
 

+ 1 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IChannelService.java

@@ -1,5 +1,5 @@
 package cn.com.ctop.job.bytedance.data.service;
 
 public interface IChannelService {
-     void   getPromotionIdList(String distributorId, String secretKey,Integer offset);
+     void   getPromotionIdList(String startDt,String endDt, String distributorId, String secretKey,Integer offset);
 }

+ 8 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/ChannelServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
 import cn.com.ctop.job.bytedance.data.mapper.ChannelMapper;
 import cn.com.ctop.job.bytedance.data.service.IChannelService;
 import cn.com.ctop.job.bytedance.data.utils.Check;
+import cn.com.ctop.job.bytedance.data.utils.DateUtils;
 import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -25,17 +27,21 @@ public class ChannelServiceImpl implements IChannelService {
     private ChannelMapper channelMapper;
 
     @Override
-    public void getPromotionIdList(String distributorId, String secretKey, Integer offset) {
+    public void getPromotionIdList(String startDt, String endDt, String distributorId, String secretKey, Integer offset) {
         try {
             String url = "https://www.changdunovel.com/novelsale/openapi/promotion/list/v1";
             String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
             String sign = getSign(distributorId, secretKey, ts);
             Map<String, Object> params = new JSONObject();
+            Long startT = DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", startDt + " 00:00:00");
+            Long endT = DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", endDt + " 23:59:59");
             params.put("distributor_id", distributorId);
             params.put("ts", ts);
             params.put("offset", offset);
             params.put("limit", 1000);
             params.put("sign", sign);
+            params.put("begin", startT);
+            params.put("end", endT);
             Boolean has_more = false;
             String s = HttpUtils.httpGet(url, params, null);
             JSONObject jsonObject = JSONObject.parseObject(s);
@@ -69,7 +75,7 @@ public class ChannelServiceImpl implements IChannelService {
             }
 
             if (has_more) {
-                getPromotionIdList(distributorId, secretKey, offset);
+                getPromotionIdList(startDt, endDt, distributorId, secretKey, offset);
             } else {
                 log.info("番茄推广链拉取成功,distributorId:{}", distributorId);
             }

+ 19 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/utils/DateUtils.java

@@ -26,6 +26,25 @@ public class DateUtils {
         return sdf.format(date);
     }
 
+    public static String getNowAddDate(String format, Integer day) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.DAY_OF_MONTH, day);
+        Date resultDate = calendar.getTime();
+        return sdf.format(resultDate);
+    }
+
+    public static Long getTimestampFormat(String format, String date) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        Date getDate = null;
+        try {
+            getDate = sdf.parse(date);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return getDate.getTime()/1000;
+    }
+
     public static Integer getIntegerDate(String date) {
         return Integer.valueOf(date.replace("-", ""));
     }

+ 3 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedancePromoterReportJob.java

@@ -95,7 +95,9 @@ public class BytedancePromoterReportJob {
             JSONObject jsonObject = channelList.get(i);
             String channelAccountId = jsonObject.getString("channelAccountId");
             String secretKey = jsonObject.getString("secretKey");
-            channelService.getPromotionIdList(channelAccountId, secretKey, 0);
+            String startDate = DateUtils.getNowAddDate("yyyy-MM-dd",-1);
+            String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+            channelService.getPromotionIdList(startDate, endDate, channelAccountId, secretKey, 0);
         }
     }