Bläddra i källkod

添加定时获取计划,组,创意

zhaoxian 2 år sedan
förälder
incheckning
edbf65d304

+ 4 - 4
job-live/src/main/java/cn/com/ctop/job/live/controller/LiveController.java

@@ -52,7 +52,7 @@ public class LiveController {
      */
     @GetMapping(value = "/getKuaishouAccountReport")
     public void getKuaishouAccountReport(Long accountId) {
-        String token = "cc299cdc3785e1416d0b7b0ea334b6ea";
+        String token = tokenService.getByAccountId(accountId);
         accountReportDailyService.getKuaishouAccountHourReport(accountId, token);
     }
 
@@ -61,7 +61,7 @@ public class LiveController {
      */
     @GetMapping(value = "/getKuaishouCampaignReport")
     public Result<Object> getKuaishouCampaignReport(Long accountId) {
-        String token = "5490f684f0f2bdabdf5d40d9c4f34300";
+        String token = tokenService.getByAccountId(accountId);
         return campaignReportDailyService.getKuaishouCampaignReport(accountId, token, 1);
     }
 
@@ -70,7 +70,7 @@ public class LiveController {
      */
     @GetMapping(value = "/getKuaishouUnitReport")
     public Result<Object> getKuaishouUnitReport(Long accountId) {
-        String token = "5490f684f0f2bdabdf5d40d9c4f34300";
+        String token = tokenService.getByAccountId(accountId);
         return unitReportDailyService.getKuaishouUnitReport(accountId, token, 1);
     }
 
@@ -79,7 +79,7 @@ public class LiveController {
      */
     @GetMapping(value = "/getKuaishouCreativeReport")
     public Result<Object> getKuaishouCreativeReport(Long accountId) {
-        String token = "5490f684f0f2bdabdf5d40d9c4f34300";
+        String token = tokenService.getByAccountId(accountId);
         return creativeReportDailyService.getKuaishouCreativeReport(accountId, token, 1);
     }
 

+ 61 - 61
job-live/src/main/java/cn/com/ctop/job/live/service/impl/KuaishouLiveUnitListServiceImpl.java

@@ -20,75 +20,75 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * 广告组Service业务层处理
- *
- * @author ruoyi
- * @date 2022-07-28
- */
+* 广告组Service业务层处理
+*
+* @author ruoyi
+* @date 2022-07-28
+*/
 @Slf4j
 @Service
 public class KuaishouLiveUnitListServiceImpl implements IKuaishouLiveUnitListService {
-    @Autowired
-    private KuaishouLiveUnitListMapper mapper;
+@Autowired
+private KuaishouLiveUnitListMapper mapper;
 
-    /**
-     * 查询广告组
-     *
-     * @param accountId 广告组主键
-     * @return 广告组
-     */
-    @Override
-    public KuaishouLiveUnitList selectKuaishouLiveUnitListByAccountId(Long accountId) {
-        return mapper.selectKuaishouLiveUnitListByAccountId(accountId);
-    }
+/**
+ * 查询广告组
+ *
+ * @param accountId 广告组主键
+ * @return 广告组
+ */
+@Override
+public KuaishouLiveUnitList selectKuaishouLiveUnitListByAccountId(Long accountId) {
+    return mapper.selectKuaishouLiveUnitListByAccountId(accountId);
+}
 
-    /**
-     * 查询广告组列表
-     *
-     * @param kuaishouLiveUnitList 广告组
-     * @return 广告组
-     */
-    @Override
-    public List<KuaishouLiveUnitList> selectKuaishouLiveUnitListList(KuaishouLiveUnitList kuaishouLiveUnitList) {
-        return mapper.selectKuaishouLiveUnitListList(kuaishouLiveUnitList);
-    }
+/**
+ * 查询广告组列表
+ *
+ * @param kuaishouLiveUnitList 广告组
+ * @return 广告组
+ */
+@Override
+public List<KuaishouLiveUnitList> selectKuaishouLiveUnitListList(KuaishouLiveUnitList kuaishouLiveUnitList) {
+    return mapper.selectKuaishouLiveUnitListList(kuaishouLiveUnitList);
+}
 
 
-    @Override
-    public Result<Object> getKuaishouUnit(Long accountId, String token) {
-        log.info("调用接口---getKuaishouUnit(获取广告组信息)---账户:{}", accountId);
-        Result<Object> result = new Result<>();
-        Map<String, Object> param = new HashMap<String, Object>();
-        param.put("advertiser_id", accountId);
-        JSONObject params = new JSONObject();
-        params.put("start_time", DateUtils.timeToStamp(DateUtils.getDate() + " 00:00:00"));
-        params.put("end_time", DateUtils.timeToStamp(DateUtils.getDate() + " 23:23:59"));
-        params.put("search_level", 2);
-        JSONObject pageInfo = new JSONObject();
-        pageInfo.put("page", 1);
-        pageInfo.put("page_size", 2000);
-        param.put("page_info", pageInfo);
-        param.put("param", params);
-        JSONObject apiResult = APIUtil.getApiResult(KuaishouAPIConstant.AD_SEARCH, token, param);
-        if (apiResult.getInteger("code") == 0) {
-            apiResult = apiResult.getJSONObject("data");
-            JSONArray data = apiResult.getJSONArray("data");
-            List<KuaishouLiveUnitList> list = new ArrayList<>();
-            for (int i = 0; i < data.size(); i++) {
-                JSONObject object = data.getJSONObject(i);
-                KuaishouLiveUnitList accountReport = JSONObject.parseObject(object.toJSONString(), KuaishouLiveUnitList.class);
-                accountReport.setAccountId(accountId);
-                accountReport.setReportDate(Long.valueOf(object.getString("report_date").replace("-", "")));
-                accountReport.setUnitCreateTime(Long.valueOf(DateUtils.timestampToStr(object.getLong("unit_create_time"))));
-                list.add(accountReport);
-            }
-            if (!Check.isNull(list)) {
-                mapper.replaceBatch(list);
-            }
-        } else {
-            log.error("获取直播账户报表,账户{},{}", accountId, apiResult.toJSONString());
+@Override
+public Result<Object> getKuaishouUnit(Long accountId, String token) {
+    log.info("调用接口---getKuaishouUnit(获取广告组信息)---账户:{}", accountId);
+    Result<Object> result = new Result<>();
+    Map<String, Object> param = new HashMap<String, Object>();
+    param.put("advertiser_id", accountId);
+    JSONObject params = new JSONObject();
+    params.put("start_time", DateUtils.timeToStamp(DateUtils.getDate() + " 00:00:00"));
+    params.put("end_time", DateUtils.timeToStamp(DateUtils.getDate() + " 23:23:59"));
+    params.put("search_level", 2);
+    JSONObject pageInfo = new JSONObject();
+    pageInfo.put("page", 1);
+    pageInfo.put("page_size", 2000);
+    param.put("page_info", pageInfo);
+    param.put("param", params);
+    JSONObject apiResult = APIUtil.getApiResult(KuaishouAPIConstant.AD_SEARCH, token, param);
+    if (apiResult.getInteger("code") == 0) {
+        apiResult = apiResult.getJSONObject("data");
+        JSONArray data = apiResult.getJSONArray("data");
+        List<KuaishouLiveUnitList> list = new ArrayList<>();
+        for (int i = 0; i < data.size(); i++) {
+            JSONObject object = data.getJSONObject(i);
+            KuaishouLiveUnitList accountReport = JSONObject.parseObject(object.toJSONString(), KuaishouLiveUnitList.class);
+            accountReport.setAccountId(accountId);
+            accountReport.setReportDate(Long.valueOf(object.getString("report_date").replace("-", "")));
+            accountReport.setUnitCreateTime(Long.valueOf(DateUtils.timestampToStr(object.getLong("unit_create_time"))));
+            list.add(accountReport);
+        }
+        if (!Check.isNull(list)) {
+            mapper.replaceBatch(list);
         }
-        return result.success("success");
+    } else {
+        log.error("获取直播账户报表,账户{},{}", accountId, apiResult.toJSONString());
     }
+    return result.success("success");
+}
 
 }

+ 75 - 0
job-live/src/main/java/cn/com/ctop/job/live/utils/DateUtils.java

@@ -10,10 +10,12 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -304,4 +306,77 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
     }
 
 
+    public static int dateDiff(String start, String end) {
+        //设置转换的日期格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //开始时间
+        Date startDate = null;
+        Date endDate = null;
+        try {
+            startDate = sdf.parse(start);
+            endDate = sdf.parse(end);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+
+        //得到相差的天数 betweenDate
+        long betweenDate = (endDate.getTime() - startDate.getTime()) / (60 * 60 * 24 * 1000);
+        return (int) betweenDate;
+    }
+
+    /***
+     * 两日期之间相差天数
+     * @param dateStart
+     * @param dateEnd
+     * @return
+     */
+    public static long getDiscrepantDays(String dateStart, String dateEnd) {
+        //设置转换的日期格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //结束时间
+        Date startDate = null;
+        Date endDate = null;
+        try {
+            //开始时间
+            startDate = sdf.parse(dateStart);
+            endDate = sdf.parse(dateEnd);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        //得到相差的天数 betweenDate
+        return (endDate.getTime() - startDate.getTime()) / (60 * 60 * 24 * 1000);
+    }
+
+
+    /**
+     * 日期中获取月份
+     *
+     * @param format
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static String getMonth(String format, String date) {
+        SimpleDateFormat df = new SimpleDateFormat(format);
+        Date parse = null;
+        try {
+            parse = df.parse(date);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return String.format("%tm", parse);
+    }
+
+
+    public static void main(String[] args) {
+        List<Integer> l = new ArrayList<>();
+        int a = 1;
+        int b =(a++);
+        l.add(a);
+        l.add(b);
+        l.forEach(System.out::print);
+        System.out.println(a);
+        System.out.println(b);
+    }
+
 }