|
@@ -0,0 +1,112 @@
|
|
|
+package com.jiayue.ipfcst.console.service;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.jiayue.ipfcst.common.core.util.DateTimeUtil;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.FileCreateLog;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * DownLoadController
|
|
|
+ *
|
|
|
+ * @author bizy
|
|
|
+ * @version 1.0
|
|
|
+ * @since 2019/4/9 13:36
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+public class DownLoadService {
|
|
|
+
|
|
|
+ public void download(String stationCode) {
|
|
|
+ //@Valid注解启动后台校验,
|
|
|
+ ModelAndView modelAndView = new ModelAndView();
|
|
|
+ Long startT = System.currentTimeMillis();
|
|
|
+ log.info("下载RB文件开始,时间:" + DateTimeUtil.getStringDate());
|
|
|
+
|
|
|
+ String message = "下载成功!";
|
|
|
+ log.info("开始执行定时任务:http下载文件");
|
|
|
+ String body = HttpRequest.get("https://117.78.19.70:9010/client/getDownLoadFileAll/" + "T00003").execute().body();
|
|
|
+ JSONObject json = JSONUtil.parseObj(body);
|
|
|
+ String code = json.get("code").toString();
|
|
|
+ String data = json.get("data").toString();
|
|
|
+ if (code.equals("0") && data.length() > 0) {
|
|
|
+ JSONArray array = JSONUtil.parseArray(data);
|
|
|
+ List<FileCreateLog> list = array.toList(FileCreateLog.class);
|
|
|
+ String dir = "/Users/wanghongchen/fsdownload/"+"T00003";
|
|
|
+ //循环backups下的文件,有文件则不下载
|
|
|
+ File fileDirectory = new File(dir);
|
|
|
+ if(!fileDirectory.exists()){
|
|
|
+ fileDirectory.mkdir();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ for (FileCreateLog fileCreateLog : list) {
|
|
|
+ File file= new File(fileDirectory+File.separator+fileCreateLog.getFileName());
|
|
|
+ if(!file.exists()){
|
|
|
+ String url = "https://117.78.19.70:9010/client/getFileById?id=" + fileCreateLog.getId();
|
|
|
+ long a = HttpUtil.downloadFile(url, dir + File.separatorChar + fileCreateLog.getFileName());
|
|
|
+ if(a>0){
|
|
|
+ log.info("T00003"+"场站"+fileCreateLog.getFileName()+"文件下载成功");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("文件已经下载过了");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文件下载失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ //@Valid注解启动后台校验,
|
|
|
+ ModelAndView modelAndView = new ModelAndView();
|
|
|
+ Long startT = System.currentTimeMillis();
|
|
|
+ log.info("下载RB文件开始,时间:" + DateTimeUtil.getStringDate());
|
|
|
+
|
|
|
+ String message = "下载成功!";
|
|
|
+ log.info("开始执行定时任务:http下载文件");
|
|
|
+ String body = HttpRequest.get("https://117.78.19.70:9010/client/getDownLoadFileAll/" + "T00004").execute().body();
|
|
|
+ JSONObject json = JSONUtil.parseObj(body);
|
|
|
+ String code = json.get("code").toString();
|
|
|
+ String data = json.get("data").toString();
|
|
|
+ if (code.equals("0") && data.length() > 0) {
|
|
|
+ JSONArray array = JSONUtil.parseArray(data);
|
|
|
+ List<FileCreateLog> list = array.toList(FileCreateLog.class);
|
|
|
+ String dir = "/Users/wanghongchen/fsdownload/"+"T00004";
|
|
|
+ //循环backups下的文件,有文件则不下载
|
|
|
+ File fileDirectory = new File(dir);
|
|
|
+ if(!fileDirectory.exists()){
|
|
|
+ fileDirectory.mkdir();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ for (FileCreateLog fileCreateLog : list) {
|
|
|
+ File file= new File(fileDirectory+File.separator+fileCreateLog.getFileName());
|
|
|
+ if(!file.exists()){
|
|
|
+ String url = "https://117.78.19.70:9010/client/getFileById?id=" + fileCreateLog.getId();
|
|
|
+ long a = HttpUtil.downloadFile(url, dir + File.separatorChar + fileCreateLog.getFileName());
|
|
|
+ if(a>0){
|
|
|
+ log.info("T00004"+"场站"+fileCreateLog.getFileName()+"文件下载成功");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("文件已经下载过了");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文件下载失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|