yumeng 1 vuosi sitten
vanhempi
commit
71cd1d82cd

+ 42 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/controller/KuaishouController.java

@@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
@@ -125,6 +126,47 @@ public class KuaishouController {
         }
     }
 
+
+    private static ExecutorService dailyFundExecutorService = Executors.newFixedThreadPool(3);
+
+    @GetMapping(value = "/kuaishouFundDailyFlowsAllAccount")
+    public void kuaishouFundDailyFlowsAllAccount(String date) throws Exception {
+
+        List<JSONObject> accountIds = adUnitReportService.getAllAccounts();
+        if (Check.isNull(accountIds)) {
+            return;
+        }
+        Map<Long, String> accessMap = new HashMap<>();
+
+        List<JSONObject> agentTokens = tokenService.getAgentTokens();
+        if (Check.isNull(agentTokens)) {
+            return;
+        }
+        for (int i = 0; i < agentTokens.size(); i++) {
+            JSONObject jsonObject = agentTokens.get(i);
+            Long agentId = jsonObject.getLong("agentId");
+            String accessToken = jsonObject.getString("accessToken");
+            accessMap.put(agentId, accessToken);
+        }
+        String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", endDate, -2);
+        for (int i = 0; i < accountIds.size(); i++) {
+            JSONObject jsonObject = accountIds.get(i);
+            Long agentId = jsonObject.getLong("agentId");
+            Long accountId = jsonObject.getLong("accountId");
+            String token = accessMap.get(agentId);
+            dailyFundExecutorService.submit(
+                    new Runnable() {
+                        @Override
+                        public void run() {
+                            adUnitReportService.getKuaishouDailyFlows(accountId, token, startDate, endDate, 1);
+                        }
+                    });
+
+
+        }
+    }
+
     @ApiOperation(value = "获取快手当天-广告组信息、组时报", notes = "更新快手当天-广告组信息、组时报")
     @GetMapping(value = "/getKuaishouAdUnitRealTime")
     public void getKuaishouVideoByAccountId(@RequestParam(name = "accountId") long accountId) {

+ 2 - 1
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/KuaishouAdvertiserFundDailyFlowsMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.job.kuaishou.data.mapper;
 
 import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdvertiserFundDailyFlows;
 import cn.com.ctop.job.kuaishou.data.entity.KuaishouAdvertiserFundGet;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -20,5 +21,5 @@ public interface KuaishouAdvertiserFundDailyFlowsMapper {
   void replaceBatchKsFundGetBalance(KuaishouAdvertiserFundGet kuaishouAdvertiserFundGet);
 
 
-
+  List<JSONObject> getAllAccounts();
 }

+ 2 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/mapper/OauthTokenMapper.java

@@ -24,4 +24,6 @@ public interface OauthTokenMapper extends BaseMapper<OauthToken> {
     List<JSONObject> selectKuaiShouToken();
 
     List<JSONObject> getKuaishouOcpxTypeList();
+
+    List<JSONObject> getAgentTokens();
 }

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

@@ -50,6 +50,11 @@
                 #{balance}
                 )
         </insert>
+    <select id="getAllAccounts" resultType="com.alibaba.fastjson.JSONObject">
+        select agent_id as 'agentId', account_id as 'accountId'
+        from `jeecg-boot`.kuaishou_agent_account_list
+        where (balance + credit_balance) > 0
+    </select>
 
 
 </mapper>

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

@@ -62,6 +62,13 @@
         select ocpx_action_type as 'ocpxActionType', ocpx_action_name as 'ocpxActionName'
         from `jeecg-boot`.ctop_kuaishou_ocpx_action_type_config
     </select>
+    <select id="getAgentTokens" resultType="com.alibaba.fastjson.JSONObject">
+        select agent_id as 'agentId', access_token as 'accessToken'
+        from `jeecg-boot`.ctop_oauth_agent_token
+        where app_id in (
+                         27, 165893351
+            )
+    </select>
 
 
 </mapper>

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

@@ -1,5 +1,7 @@
 package cn.com.ctop.job.kuaishou.data.service;
 
+import com.alibaba.fastjson.JSONObject;
+
 import java.util.List;
 
 /**
@@ -29,4 +31,5 @@ public interface IAdUnitReportService {
 
     void getKuaishouDailyFundGet(Long advertiserId, String accessToken);
 
+    List<JSONObject> getAllAccounts();
 }

+ 2 - 0
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/data/service/IOauthTokenService.java

@@ -21,4 +21,6 @@ public interface IOauthTokenService extends IService<OauthToken> {
     List<Long> getAllAccountIds();
 
   List<JSONObject> selectKuaiShouToken();
+
+    List<JSONObject> getAgentTokens();
 }

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

@@ -793,5 +793,10 @@ public class AdUnitReportServiceImpl implements IAdUnitReportService {
 
     }
 
+    @Override
+    public List<JSONObject> getAllAccounts() {
+        return fundDailyFlowsMapper.getAllAccounts();
+    }
+
 
 }

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

@@ -40,4 +40,9 @@ public class OauthTokenServiceImpl extends ServiceImpl<OauthTokenMapper, OauthTo
   public List<JSONObject> selectKuaiShouToken() {
     return tokenMapper.selectKuaiShouToken();
   }
+
+    @Override
+    public List<JSONObject> getAgentTokens() {
+        return tokenMapper.getAgentTokens();
+    }
 }

+ 45 - 3
job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/AdUnitReportJob.java

@@ -6,6 +6,7 @@ import cn.com.ctop.job.kuaishou.data.service.IOauthTokenService;
 import cn.com.ctop.job.kuaishou.data.utils.Check;
 import cn.com.ctop.job.kuaishou.data.utils.DateUtils;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.support.hsf.HSFJSONUtils;
 import com.google.common.collect.Lists;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -13,9 +14,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -30,6 +29,7 @@ public class AdUnitReportJob {
     private IAdUnitReportService adUnitReportService;
 
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(2);
+    private static ExecutorService dailyFundExecutorService = Executors.newFixedThreadPool(3);
     private static ExecutorService hourExecutorService = Executors.newFixedThreadPool(3);
 
 
@@ -288,6 +288,48 @@ public class AdUnitReportJob {
     }
 
 
+    @XxlJob("kuaishouFundDailyFlowsAllAccount")
+    public void kuaishouFundDailyFlowsAllAccount() throws Exception {
+
+
+        List<JSONObject> accountIds = adUnitReportService.getAllAccounts();
+        if (Check.isNull(accountIds)) {
+            return;
+        }
+        Map<Long, String> accessMap = new HashMap<>();
+
+        List<JSONObject> agentTokens = tokenService.getAgentTokens();
+        if (Check.isNull(agentTokens)) {
+            return;
+        }
+        for (int i = 0; i < agentTokens.size(); i++) {
+            JSONObject jsonObject = agentTokens.get(i);
+            Long agentId = jsonObject.getLong("agentId");
+            String accessToken = jsonObject.getString("accessToken");
+            accessMap.put(agentId, accessToken);
+        }
+        String endDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", endDate, -2);
+        for (int i = 0; i < accountIds.size(); i++) {
+            JSONObject jsonObject = accountIds.get(i);
+            Long agentId = jsonObject.getLong("agentId");
+            Long accountId = jsonObject.getLong("accountId");
+            String token = accessMap.get(agentId);
+            dailyFundExecutorService.submit(
+                    new Runnable() {
+                        @Override
+                        public void run() {
+                            adUnitReportService.getKuaishouDailyFlows(accountId, token, startDate, endDate, 1);
+                        }
+                    });
+
+
+        }
+
+
+    }
+
+
     /**
      * 快手-账户余额
      *