ソースを参照

测试类提交

John 4 ヶ月 前
コミット
95aa27128a

+ 154 - 0
download-center-server/src/main/java/com/shanghaichengdi/downloadcenterserver/controller/testController.java

@@ -0,0 +1,154 @@
+package com.shanghaichengdi.downloadcenterserver.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.shanghaichengdi.downloadcentercommon.util.ImageDownload;
+import com.shanghaichengdi.downloadcentercommon.util.SSLUtil;
+import com.shanghaichengdi.downloadcenterserver.domain.PicDownload;
+import com.shanghaichengdi.downloadcenterserver.faced.PicDownloadFaced;
+import com.shanghaichengdi.downloadcenterserver.faced.PicDownloadHistoryFaced;
+import com.shanghaigeography.entity.ResultMsg;
+import com.shanghaigeography.eum.ResultState;
+import lombok.extern.slf4j.Slf4j;
+import lombok.val;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static com.shanghaichengdi.downloadcenterserver.faced.AnalyseFaced.lifeJacketAnalyse;
+
+/**
+ * @author gengaoliu
+ */
+@Slf4j
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/download123")
+public class testController {
+  @PostMapping("/pictures")
+  public String downloadPictures(@RequestBody String data) {
+    PicDownload picDownload = JSONObject.parseObject(data, PicDownload.class);
+//    log.info("接收到的数据为:{}",JSONObject.toJSON(picDownload));
+    PicDownloadFaced faced =
+        new PicDownloadFaced(picDownload.getImageUrls(), picDownload.getPassTime(),picDownload.getId(),picDownload.getBayonetId());
+    try {
+      if (!"8".equals(faced.getBayonetId())) {
+        faced.start();
+      }
+    } catch (Exception e) {
+//      log.info("下载失败,原因:{}",e.getMessage());
+      return new ResultMsg<String>().setMsg("下载失败").setCode(ResultState.ERROR).setData(null).toJSON();
+    }
+//    log.info("下载成功");
+    return new ResultMsg<String>().setMsg("下载成功").setCode(ResultState.SUCCESS).setData(null).toJSON();
+  }
+
+
+  @PostMapping("/pictures/history")
+  public String downloadPicturesHistory(@RequestBody String data) {
+    PicDownload picDownload = JSONObject.parseObject(data, PicDownload.class);
+//    log.info("接收到的数据为:{}",JSONObject.toJSON(picDownload));
+    PicDownloadHistoryFaced faced =
+        new PicDownloadHistoryFaced(picDownload.getImageUrls(), picDownload.getPassTime(),picDownload.getId(),picDownload.getBayonetId());
+    try {
+      if (!"8".equals(faced.getBayonetId())) {
+        faced.start();
+      }
+    } catch (Exception e) {
+//      log.info("下载失败,原因:{}",e.getMessage());
+      return new ResultMsg<String>().setMsg("下载失败").setCode(ResultState.ERROR).setData(null).toJSON();
+    }
+//    log.info("下载成功");
+    return new ResultMsg<String>().setMsg("下载成功").setCode(ResultState.SUCCESS).setData(null).toJSON();
+  }
+
+  @PostMapping("/lifejacket")
+  public String LifeJacketAnalyse(@RequestBody Map<String,Object> lifeJacket) { //String id, List<String> filePathList, String bayonetId
+    // 调用lifeJacketAnalyse方法并传入参数
+    String id = lifeJacket.get("id").toString();
+    List filePathList= (List) lifeJacket.get("filePathList");
+    String bayonetId = lifeJacket.get("bayonetId").toString();
+    String result = lifeJacketAnalyse(id, filePathList, bayonetId);
+
+    // 返回结果
+    return new ResultMsg<String>()
+            .setMsg("调用成功")
+            .setCode(ResultState.SUCCESS)
+            .setData(String.valueOf(result))
+            .toJSON();}
+
+  @Deprecated
+  @PostMapping("/first/pictures")
+  public String downloadFirstPictures(@RequestBody String data) {
+    PicDownload picDownload = JSONObject.parseObject(data, PicDownload.class);
+    int resultNum = this.downloadPics(picDownload.getImageUrls(), picDownload.getPassTime());
+    if (resultNum != picDownload.getImageUrls().size()) {
+      return new ResultMsg<String>()
+          .setMsg("下载失败")
+          .setCode(ResultState.ERROR)
+          .setData(String.valueOf(resultNum))
+          .toJSON();
+    }
+    return new ResultMsg<String>()
+        .setMsg("下载成功")
+        .setCode(ResultState.SUCCESS)
+        .setData(String.valueOf(resultNum))
+        .toJSON();
+  }
+
+  @Deprecated
+  private int downloadPics(List<String> imageUrls, String passTime) {
+    String time = passTime.split("\\+")[0];
+    Date times;
+    try {
+      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+      times =
+          formatter.parse(
+              time.split("\\.")[0].split("T")[0] + " " + time.split("\\.")[0].split("T")[1]);
+    } catch (ParseException e) {
+      e.printStackTrace();
+      return -1;
+    }
+    SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
+    SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd_HHmmss");
+    String dir = formatter.format(times);
+    String newTime = formatter1.format(times) + time.split("\\.")[1];
+    String year = dir.split("\\_")[0];
+    String month = dir.split("\\_")[1];
+    String day = dir.split("\\_")[2];
+    String hour = dir.split("\\_")[3];
+    String dirs = year + "\\" + year + month + day + "\\" + hour;
+
+    int i = 0;
+    File photoDir = new File("\\\\K6XL82KY31YIWFC\\photo\\" + dirs);
+    photoDir.mkdirs();
+    for (String imageUrl : imageUrls) {
+      boolean isSuccess = false;
+      URL url = null;
+      try {
+        url = new URL(URLDecoder.decode(imageUrl, "utf-8"));
+        if ("https".equalsIgnoreCase(url.getProtocol())) {
+          SSLUtil.ignoreSsl();
+        }
+        String photoFile =
+            "\\\\K6XL82KY31YIWFC\\photo\\" + dirs + "\\" + "P" + i + "_" + newTime + ".jpg";
+        System.out.println(url);
+        isSuccess = ImageDownload.download(imageUrl, photoFile);
+        if (!isSuccess) {
+          return i;
+        }
+        i++;
+      } catch (Exception e) {
+        e.printStackTrace();
+        return i;
+      }
+    }
+    return i;
+  }
+}