|
@@ -1,114 +1,115 @@
|
|
|
-package com.fdkankan.download.service.impl;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
-import cn.hutool.core.lang.UUID;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.fdkankan.download.bean.ResultData;
|
|
|
-import com.fdkankan.download.service.IBatchDonloadService;
|
|
|
-import com.fdkankan.download.service.ISsoService;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.boot.CommandLineRunner;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 应用启动校验是否有下载任务正在进行,如有过就重新入队头,从新下载
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author dengsixing
|
|
|
- * @since 2022/2/22
|
|
|
- **/
|
|
|
-@Slf4j
|
|
|
-@Component
|
|
|
-public class CheckDownloadingRunnerImpl implements CommandLineRunner {
|
|
|
-
|
|
|
- @Value("${download.dir}")
|
|
|
- private String parentPath;
|
|
|
- @Value("${download.task}")
|
|
|
- private String taskLogPath;
|
|
|
- @Value("${download.id}")
|
|
|
- private String idLogPath;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ISsoService ssoService;
|
|
|
- @Autowired
|
|
|
- private IBatchDonloadService batchDonloadService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(String... args) throws Exception {
|
|
|
-
|
|
|
- //读取正在执行的任务
|
|
|
- Set<String> set = null;
|
|
|
- try {
|
|
|
- String taskStr = FileUtil.readUtf8String(taskLogPath);
|
|
|
- set = (Set<String>) JSON.parseObject(taskStr, Set.class);
|
|
|
- BatchDonloadServiceImpl.taskSet.addAll(set);
|
|
|
- }catch (Exception e){
|
|
|
- log.info("读取正在执行的下载任务失败");
|
|
|
- }
|
|
|
-
|
|
|
- if(CollUtil.isEmpty(set)){
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<String, Object> headers = new HashMap<>();
|
|
|
- try {
|
|
|
- String token = ssoService.login();
|
|
|
- headers.put("token", token);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("登录失败", e);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (String uuid : set) {
|
|
|
- String dir = parentPath.concat(uuid).concat(File.separator);
|
|
|
- String origFilePath = dir.concat(uuid + ".txt");
|
|
|
- if (!FileUtil.exist(origFilePath)) {
|
|
|
- log.error("原始文件不存在,filePath:{}", origFilePath);
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<String> numList = FileUtil.readUtf8Lines(origFilePath);
|
|
|
- if (CollUtil.isEmpty(numList)) {
|
|
|
- log.error("场景码为空,filePath:{}", origFilePath);
|
|
|
- continue;
|
|
|
- }
|
|
|
- String downloadResultLog = dir.concat("log.txt");
|
|
|
- String downloadingLog = dir.concat("downloading.txt");
|
|
|
-
|
|
|
- //过滤出需要下载的场景码
|
|
|
- Set<String> numSet = numList.stream().collect(Collectors.toSet());
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- List<String> logList = null;
|
|
|
- try {
|
|
|
- logList = FileUtil.readUtf8Lines(downloadResultLog);
|
|
|
- logList.stream().forEach(str->{
|
|
|
- String[] s = str.split(" ");
|
|
|
- map.put(s[0], str);
|
|
|
- });
|
|
|
- }catch (Exception e){
|
|
|
-
|
|
|
- }
|
|
|
- Set<String> collect = numSet.stream().filter(num -> {
|
|
|
- if(map.containsKey(num)){
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }).collect(Collectors.toSet());
|
|
|
-
|
|
|
- batchDonloadService.downloadHandler(uuid, collect, headers, dir, downloadingLog, downloadResultLog);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.fdkankan.download.service.impl;
|
|
|
+//
|
|
|
+//import cn.hutool.core.collection.CollUtil;
|
|
|
+//import cn.hutool.core.io.FileUtil;
|
|
|
+//import cn.hutool.core.lang.UUID;
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
+//import com.fdkankan.download.bean.ResultData;
|
|
|
+//import com.fdkankan.download.service.IBatchDonloadService;
|
|
|
+//import com.fdkankan.download.service.ISsoService;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.boot.CommandLineRunner;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//
|
|
|
+//import java.io.File;
|
|
|
+//import java.util.HashMap;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Map;
|
|
|
+//import java.util.Set;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * <p>
|
|
|
+// * 应用启动校验是否有下载任务正在进行,如有过就重新入队头,从新下载
|
|
|
+// * </p>
|
|
|
+// *
|
|
|
+// * @author dengsixing
|
|
|
+// * @since 2022/2/22
|
|
|
+// **/
|
|
|
+//@Slf4j
|
|
|
+//@Component
|
|
|
+//public class CheckDownloadingRunnerImpl implements CommandLineRunner {
|
|
|
+//
|
|
|
+// @Value("${download.dir}")
|
|
|
+// private String parentPath;
|
|
|
+// @Value("${download.task}")
|
|
|
+// private String taskLogPath;
|
|
|
+// @Value("${download.id}")
|
|
|
+// private String idLogPath;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private ISsoService ssoService;
|
|
|
+// @Autowired
|
|
|
+// private IBatchDonloadService batchDonloadService;
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void run(String... args) throws Exception {
|
|
|
+//
|
|
|
+// //读取正在执行的任务
|
|
|
+// Set<String> set = null;
|
|
|
+// try {
|
|
|
+// String taskStr = FileUtil.readUtf8String(taskLogPath);
|
|
|
+// set = (Set<String>) JSON.parseObject(taskStr, Set.class);
|
|
|
+// BatchDonloadServiceImpl.taskSet.addAll(set);
|
|
|
+// }catch (Exception e){
|
|
|
+// log.info("读取正在执行的下载任务失败");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(CollUtil.isEmpty(set)){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// Map<String, Object> headers = new HashMap<>();
|
|
|
+// try {
|
|
|
+// String token = ssoService.login();
|
|
|
+// headers.put("token", token);
|
|
|
+// }catch (Exception e){
|
|
|
+// log.error("登录失败", e);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (String uuid : set) {
|
|
|
+// String dir = parentPath.concat(uuid).concat(File.separator);
|
|
|
+// String origFilePath = dir.concat(uuid + ".txt");
|
|
|
+// if (!FileUtil.exist(origFilePath)) {
|
|
|
+// log.error("原始文件不存在,filePath:{}", origFilePath);
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// List<String> numList = FileUtil.readUtf8Lines(origFilePath);
|
|
|
+// if (CollUtil.isEmpty(numList)) {
|
|
|
+// log.error("场景码为空,filePath:{}", origFilePath);
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// String downloadResultLog = dir.concat("log.txt");
|
|
|
+// String downloadingLog = dir.concat("downloading.txt");
|
|
|
+//
|
|
|
+// //过滤出需要下载的场景码
|
|
|
+//
|
|
|
+// Set<String> numSet = numList.stream().collect(Collectors.toSet());
|
|
|
+// Map<String, String> map = new HashMap<>();
|
|
|
+// List<String> logList = null;
|
|
|
+// try {
|
|
|
+// logList = FileUtil.readUtf8Lines(downloadResultLog);
|
|
|
+// logList.stream().forEach(str->{
|
|
|
+// String[] s = str.split(" ");
|
|
|
+// map.put(s[0], str);
|
|
|
+// });
|
|
|
+// }catch (Exception e){
|
|
|
+//
|
|
|
+// }
|
|
|
+// Set<String> collect = numSet.stream().filter(num -> {
|
|
|
+// if(map.containsKey(num)){
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+// return true;
|
|
|
+// }).collect(Collectors.toSet());
|
|
|
+//
|
|
|
+// batchDonloadService.downloadHandler(uuid, collect, headers, dir, downloadingLog, downloadResultLog);
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|