huangpingkang 1 год назад
Родитель
Сommit
12cfacfdfe

+ 2 - 12
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/DianZhongController.java

@@ -13,16 +13,12 @@ import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 
 @RestController
 @RestController
 @RequestMapping("/bytedance/dianzhong")
 @RequestMapping("/bytedance/dianzhong")
 @Api(tags = "点众拉取")
 @Api(tags = "点众拉取")
 @Slf4j
 @Slf4j
 public class DianZhongController {
 public class DianZhongController {
-    private static final ExecutorService executorService = Executors.newFixedThreadPool(5);
-
     @Autowired
     @Autowired
     private IDianZhongService dianZhongService;
     private IDianZhongService dianZhongService;
 
 
@@ -48,14 +44,8 @@ public class DianZhongController {
     }
     }
 
 
     @GetMapping("/getUrlData")
     @GetMapping("/getUrlData")
-    public void urlData(String statDate) {
-        executorService.submit(new Runnable() {
-            @Override
-            public void run() {
-                dianZhongService.getUrlData(statDate);
-            }
-        });
-
+    public void urlData(@RequestParam(required = false) String statDate) {
+        dianZhongService.getUrlData(statDate);
     }
     }
 
 
 }
 }

+ 1 - 1
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/DianZhongMapper.xml

@@ -23,7 +23,7 @@
     </update>
     </update>
 
 
     <select id="getTaskUrl" resultType="com.alibaba.fastjson.JSONObject">
     <select id="getTaskUrl" resultType="com.alibaba.fastjson.JSONObject">
-        select task_id,url,type,client_id
+        select task_id,url,type,client_id,stat_date
         from media_api.dianzhong_data_download_url
         from media_api.dianzhong_data_download_url
         where downloaded = 0 and url is not null and url != '-1'
         where downloaded = 0 and url is not null and url != '-1'
         <if test="statDate != null">
         <if test="statDate != null">

+ 39 - 30
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/DianZhongServiceImpl.java

@@ -26,10 +26,14 @@ import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 
 @Service
 @Service
 @Slf4j
 @Slf4j
 public class DianZhongServiceImpl implements IDianZhongService {
 public class DianZhongServiceImpl implements IDianZhongService {
+    private static final ExecutorService executorService = Executors.newFixedThreadPool(5);
+
     @Autowired
     @Autowired
     private ICacheService cacheService;
     private ICacheService cacheService;
 
 
@@ -129,39 +133,44 @@ public class DianZhongServiceImpl implements IDianZhongService {
     下载点众IAP数据
     下载点众IAP数据
      */
      */
     public void getUrlData(String statDate) {
     public void getUrlData(String statDate) {
-        List<JSONObject> tasks = dianZhongMapper.getTaskUrl(statDate.replace("-", ""));
+        List<JSONObject> tasks = dianZhongMapper.getTaskUrl(statDate == null ? null : statDate.replace("-", ""));
         if (!Check.isNull(tasks)) {
         if (!Check.isNull(tasks)) {
             for (JSONObject task : tasks) {
             for (JSONObject task : tasks) {
-                String taskId = task.getString("task_id");
-                String url = task.getString("url");
-                String type = task.getString("type");
-                String clientId = task.getString("client_id");
-                try {
-                    log.info("开始下载点众数据 taskId:{}, clientId:{}, type:{}", taskId, clientId, type);
-                    downloadFileRestTemplate.execute(url, org.springframework.http.HttpMethod.GET, null,
-                            (ResponseExtractor<Void>) response -> {
-                                try (BufferedReader reader = new BufferedReader(
-                                        new InputStreamReader(response.getBody(), StandardCharsets.UTF_8))) {
-                                    String line;
-                                    while ((line = reader.readLine()) != null) {
-                                        if ("user".equals(type)) {
-                                            getDZUser(line);
-                                            getDZLogin(line);
-                                            getDZActivation(line);
-                                            getDZRegister(line, statDate);
-                                        } else if ("order".equals(type)) {
-                                            getDZOrder(line);
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        String taskId = task.getString("task_id");
+                        String url = task.getString("url");
+                        String type = task.getString("type");
+                        String clientId = task.getString("client_id");
+                        String dataDate = task.getString("stat_date");
+                        try {
+                            log.info("开始下载点众数据 taskId:{}, clientId:{}, type:{}", taskId, clientId, type);
+                            downloadFileRestTemplate.execute(url, org.springframework.http.HttpMethod.GET, null,
+                                    (ResponseExtractor<Void>) response -> {
+                                        try (BufferedReader reader = new BufferedReader(
+                                                new InputStreamReader(response.getBody(), StandardCharsets.UTF_8))) {
+                                            String line;
+                                            while ((line = reader.readLine()) != null) {
+                                                if ("user".equals(type)) {
+                                                    getDZUser(line);
+                                                    getDZLogin(line);
+                                                    getDZActivation(line);
+                                                    getDZRegister(line, dataDate);
+                                                } else if ("order".equals(type)) {
+                                                    getDZOrder(line);
+                                                }
+                                            }
                                         }
                                         }
-                                    }
-                                }
-                                return null;
-                            });
-                    dianZhongMapper.updateTaskDownloaded(taskId);
-                    log.info("下载点众数据成功 taskId:{}, clientId:{}, type:{}", taskId, clientId, type);
-                } catch (Exception e) {
-                    log.error("下载点众数据失败 taskId:{}, clientId:{}, type:{}", taskId, clientId, type, e);
-                }
-
+                                        return null;
+                                    });
+                            dianZhongMapper.updateTaskDownloaded(taskId);
+                            log.info("下载点众数据成功 taskId:{}, clientId:{}, type:{}", taskId, clientId, type);
+                        } catch (Exception e) {
+                            log.error("下载点众数据失败 taskId:{}, clientId:{}, type:{}", taskId, clientId, type, e);
+                        }
+                    }
+                });
             }
             }
         }
         }
     }
     }