Browse Source

实时数据

yumeng 4 năm trước cách đây
mục cha
commit
fba971b5e1

+ 12 - 10
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -8,24 +8,21 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.UReportSubscriber;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.message.handle.impl.EmailSendMsgHandle;
-import cn.com.ctop.common.module.service.IBindAccountLoginService;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.common.module.service.IUReportExportService;
-import cn.com.ctop.common.module.service.IUReportService;
-import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouRealTimeDataService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyAgentService;
-import cn.com.ctop.oa.modules.entity.WechatAttendance;
 import cn.com.ctop.oa.modules.service.IWechatCheckinDataService;
 import cn.com.ctop.oa.modules.service.IWechatDepartmentService;
 import cn.com.ctop.oa.modules.service.IWechatNoListService;
 import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.report.service.IReportService;
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -41,7 +38,6 @@ import java.text.ParseException;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -78,10 +74,16 @@ public class SampleTest {
     private IWechatNoListService wechatNoListService;
     @Autowired
     private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouRealTimeDataService realTimeDataService;
 
 
     @Test
     public void getDepartment() throws ParseException {
+
+        JSONArray campaignDate = realTimeDataService.getCampaignDate(20209274L, "7abeae7f7708bda8111c62f985da84e7", 20209274L, "2020-09-27", "2020-09-27");
+
+        System.err.println(campaignDate);
 //        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
 //        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
 //        Date parse1 = simpleDateFormat.parse("2020-09-12");
@@ -97,10 +99,10 @@ public class SampleTest {
 //        wechatCheckinDataService.getCheckinData();
 //        wechatNoListService.getNoDateByNo("1598889600","1600927780");
 
-        Map<String, Object> map = new HashMap<String, Object>();
+       /* Map<String, Object> map = new HashMap<String, Object>();
         map.put("departId", "9");
-        List<WechatAttendance> wechatAttendances = wechatNoListService.queryAttendanceData( map);
-        System.out.println(wechatAttendances);
+        List<WechatAttendance> wechatAttendances = wechatNoListService.queryAttendanceData(map);
+        System.out.println(wechatAttendances);*/
         //         kuaishouInterfaceService.getSuZaoList("a34853c230e1b949eddbe569023dbc40", 7022550L, 1, "2020-09-15", "2020-09-16");
 
     }

+ 100 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouRealTimeController.java

@@ -0,0 +1,100 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouRealTimeDataService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Description: 广告组-app信息
+ * @Author: jeecg-boot
+ * @Date: 2019-07-23
+ * @Version: V1.0
+ */
+@Slf4j
+@Api(tags = "广告组-app信息")
+@RestController
+@RequestMapping("/kuaishou/realTime")
+public class KuaiShouRealTimeController {
+    @Autowired
+    private IKuaishouRealTimeDataService realTimeDataService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+
+    @PostMapping(value = "/getCampaignDate")
+    public Result<JSONArray> getCampaignDate(@RequestBody JSONObject requestJson) {
+        Result<JSONArray> result = new Result<>();
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请传入账户id");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            Long campaignId = requestJson.getLong("campaignId");
+            if (Check.isNull(campaignId)) {
+                throw new Exception("请传入计划id");
+            }
+            String startDate = requestJson.getString("startDate");
+            String endDate = requestJson.getString("endDate");
+            if (Check.isNull(startDate) || Check.isNull(endDate)) {
+                throw new Exception("请选择开始、结束查询时间");
+            }
+            JSONArray campaignDate = realTimeDataService.getCampaignDate(accountId, oauthToken.getAccessToken(), campaignId, startDate, endDate);
+            result.setSuccess(true);
+            result.setResult(campaignDate);
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+
+        return result;
+    }
+
+
+    @PostMapping(value = "/getUnitDate")
+    public Result<JSONArray> getUnitDate(@RequestBody JSONObject requestJson) {
+        Result<JSONArray> result = new Result<>();
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请传入账户id");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            Long unitId = requestJson.getLong("unitId");
+            if (Check.isNull(unitId)) {
+                throw new Exception("请传入组id");
+            }
+            String startDate = requestJson.getString("startDate");
+            String endDate = requestJson.getString("endDate");
+            if (Check.isNull(startDate) || Check.isNull(endDate)) {
+                throw new Exception("请选择开始、结束查询时间");
+            }
+            JSONArray unitData = realTimeDataService.getUnitDate(accountId, oauthToken.getAccessToken(), unitId, startDate, endDate);
+            result.setSuccess(true);
+            result.setResult(unitData);
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+
+        return result;
+    }
+
+}

+ 4 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouRealTimeDataService.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.JSONArray;
 
 public interface IKuaishouRealTimeDataService {
-    JSONObject getCampaignDate(Long accountId, String token, Long unitId, String startDate, String endDate);
+    JSONArray getCampaignDate(Long accountId, String token, Long campaignId, String startDate, String endDate);
+
+    JSONArray getUnitDate(Long accountId, String token, Long unitId, String startDate, String endDate);
 }

+ 69 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouRealTimeDataServiceImpl.java

@@ -1,11 +1,11 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouRealTimeDataService;
-import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
-import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyCampaign;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.stereotype.Service;
 
@@ -14,8 +14,18 @@ import java.util.Map;
 
 @Service
 public class KuaishouRealTimeDataServiceImpl implements IKuaishouRealTimeDataService {
+    /**
+     * 获取计划实时数据
+     *
+     * @param accountId
+     * @param token
+     * @param campaignId
+     * @param startDate
+     * @param endDate
+     * @return
+     */
     @Override
-    public JSONObject getCampaignDate(Long accountId, String token, Long campaignId, String startDate, String endDate) {
+    public JSONArray getCampaignDate(Long accountId, String token, Long campaignId, String startDate, String endDate) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
@@ -25,10 +35,65 @@ public class KuaishouRealTimeDataServiceImpl implements IKuaishouRealTimeDataSer
         param.put("end_date", endDate);
         param.put("advertiser_id", accountId);
         param.put("temporal_granularity", "DAILY");
-        param.put("page_size", 500);
+        param.put("page_size", 2000);
         param.put("page", 1);
+
+        JSONArray array = new JSONArray();
+        array.add(campaignId);
+        param.put("campaign_ids", array);
+        try {
+            String result = HttpUtils.httpPostRequest(url, param, headers);
+            System.err.println(result);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 0) {
+                    return jsonObject.getJSONArray("details");
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 获取组实时数据
+     *
+     * @param accountId
+     * @param token
+     * @param unitId
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    @Override
+    public JSONArray getUnitDate(Long accountId, String token, Long unitId, String startDate, String endDate) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token);
+        Map<String, Object> param = new HashMap<>();
+        param.put("start_date", startDate);
+        param.put("end_date", endDate);
+        param.put("advertiser_id", accountId);
+        param.put("temporal_granularity", "DAILY");
+        param.put("page_size", 2000);
+        param.put("page", 1);
+
+        JSONArray array = new JSONArray();
+        array.add(unitId);
+        param.put("unit_ids", array);
         try {
             String result = HttpUtils.httpPostRequest(url, param, headers);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 0) {
+                    return jsonObject.getJSONArray("details");
+                }
+            }
 
         } catch (Exception e) {
             e.printStackTrace();