Browse Source

:sparkles: 添加历史图片下载和模型调用/云上服务器也需要新增历史分析,要根据过船时间

lag 7 months ago
parent
commit
5b9fd765d9

+ 1 - 0
download-center-server/src/main/java/com/shanghaichengdi/downloadcenterserver/cache/UrlData.java

@@ -10,4 +10,5 @@ import java.util.concurrent.ConcurrentLinkedQueue;
 public class UrlData {
 
   public static ConcurrentLinkedQueue<Map<String, List<String>>> URL_IMG_TO_SAVE = new ConcurrentLinkedQueue<>();
+  public static ConcurrentLinkedQueue<Map<String, List<String>>> URL_HISTORY_IMG_TO_SAVE = new ConcurrentLinkedQueue<>();
 }

+ 21 - 1
download-center-server/src/main/java/com/shanghaichengdi/downloadcenterserver/controller/PicDownloadController.java

@@ -6,6 +6,7 @@ import com.shanghaichengdi.downloadcentercommon.util.SSLUtil;
 import com.shanghaichengdi.downloadcenterserver.cache.UrlData;
 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 java.io.File;
@@ -41,7 +42,26 @@ public class PicDownloadController {
         faced.start();
       }
     } catch (Exception e) {
-      log.info("下载失败,原因:{}",e.getMessage());
+//      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("下载成功");

+ 82 - 0
download-center-server/src/main/java/com/shanghaichengdi/downloadcenterserver/faced/AnalyseFaced.java

@@ -20,6 +20,7 @@ public class AnalyseFaced {
   private final static String SHIP_COVER_ANALYSE_DIR = "/disk/shipCover/";
   private final static String BOAT_FLAG_ANALYSE_DIR = "/disk/shareFlag/";
   private final static String GH_CLOUD_SERVER = "http://10.83.68.108:8090/ghjgBayonetDataShareApi/analyse/receive";
+  private final static String GH_CLOUD_HISTORY_SERVER = "http://10.83.68.108:8090/ghjgBayonetDataShareApi/analyse/history/receive";
 
 
   public static String shipCoverAnalyse(String id, String filePath, String bayonetId) {
@@ -57,6 +58,42 @@ public class AnalyseFaced {
     return responseBody;
   }
 
+  public static String shipCoverAnalyseHistory(String id, String filePath, String bayonetId,String passTime) {
+    HttpRequest post = HttpUtil.createPost(SHIP_COVER);
+    Map<String, String> headers = new HashMap<>();
+    headers.put("Content-Type", "application/json;charset=utf-8");
+    post.addHeaders(headers);
+    Map<String, String> param = new LinkedHashMap<>();
+    param.put("file", DOWNLOAD_FILE_DIR + filePath);
+    String responseBody = post.body(JSONObject.toJSONString(param))
+        .setReadTimeout(3600000)
+        .execute()
+        .body();
+//    log.info("通用船舶货物识别完成,结果为:{}", responseBody);
+    // 调用云上覆盖物/国旗接收接口
+    JSONObject coverAnalyseResultData = JSONObject.parseObject(responseBody);
+    JSONArray resultArray = (JSONArray) coverAnalyseResultData.get("result");
+    JSONObject resultJsonObject = (JSONObject) resultArray.get(0);
+    if (!Objects.isNull(resultJsonObject.get("class"))) {
+      Map<String, Object> yunParam = new LinkedHashMap<>();
+      yunParam.put("type", "覆盖物");
+      yunParam.put("dir", SHIP_COVER_ANALYSE_DIR);
+      yunParam.put("id", id);
+      yunParam.put("passTime",passTime);
+      yunParam.put("data", responseBody);
+      yunParam.put("bayonetId", bayonetId);
+      String coverJsonString = JSONObject.toJSONString(yunParam);
+//      log.info("覆盖物调用云上传参为:{}", coverJsonString);
+      HttpRequest ghPost = HttpUtil.createPost(GH_CLOUD_HISTORY_SERVER);
+      ghPost.addHeaders(headers);
+      ghPost.body(coverJsonString)
+          .setReadTimeout(3600000)
+          .execute()
+          .body();
+    }
+    return responseBody;
+  }
+
 
   public static String boatFlagAnalyse(String id, List<String> filePathList, String bayonetId) {
     String result = null;
@@ -106,6 +143,51 @@ public class AnalyseFaced {
   }
 
 
+  public static String boatFlagAnalyseHistory(String id, List<String> filePathList, String bayonetId,String passTime) {
+    String result = null;
+    for (String filePath : filePathList) {
+      HttpRequest post = HttpUtil.createPost(BOAT_FLAG);
+      Map<String, String> headers = new HashMap<>();
+      headers.put("Content-Type", "application/json;charset=utf-8");
+      post.addHeaders(headers);
+      Map<String, String> param = new LinkedHashMap<>();
+      param.put("file", DOWNLOAD_FILE_DIR + filePath);
+      String responseBody = post.body(JSONObject.toJSONString(param))
+          .setReadTimeout(3600000)
+          .execute()
+          .body();
+      JSONObject jsonObject = JSONObject.parseObject(responseBody);
+      Boolean whetherHaveFlag = (Boolean) jsonObject.get("has_objects");
+      if (whetherHaveFlag) {
+        result = responseBody;
+        break;
+      } else {
+        // 没有国旗的只保留全景图的分析结果
+        String fullyImgResult = boatFlagAnalyse(id, filePathList.get(0));
+        result = fullyImgResult;
+      }
+    }
+    // 调用云上覆盖物/国旗接收接口
+    Map<String, Object> yunParam = new LinkedHashMap<>();
+    yunParam.put("type", "国旗");
+    yunParam.put("dir", BOAT_FLAG_ANALYSE_DIR);
+    yunParam.put("id", id);
+    yunParam.put("passTime", passTime);
+    yunParam.put("data", result);
+    yunParam.put("bayonetId", bayonetId);
+    String flagJsonString = JSONObject.toJSONString(yunParam);
+    HttpRequest ghPost = HttpUtil.createPost(GH_CLOUD_HISTORY_SERVER);
+    Map<String, String> headers = new HashMap<>();
+    headers.put("Content-Type", "application/json;charset=utf-8");
+    ghPost.addHeaders(headers);
+    ghPost.body(flagJsonString)
+        .setReadTimeout(3600000)
+        .execute()
+        .body();
+    return null;
+  }
+
+
   public static String boatFlagAnalyse(String id, String filePath) {
     HttpRequest post = HttpUtil.createPost(BOAT_FLAG);
     Map<String, String> headers = new HashMap<>();

+ 95 - 0
download-center-server/src/main/java/com/shanghaichengdi/downloadcenterserver/faced/PicDownloadHistoryFaced.java

@@ -0,0 +1,95 @@
+package com.shanghaichengdi.downloadcenterserver.faced;
+
+import com.shanghaichengdi.downloadcentercommon.util.ImageDownload;
+import com.shanghaichengdi.downloadcenterserver.cache.UrlData;
+import java.io.File;
+import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class PicDownloadHistoryFaced extends Thread {
+
+  private List<String> imageUrls;
+  private String passTime;
+  private String id;
+  @Getter
+  private String bayonetId;
+
+  public PicDownloadHistoryFaced(List<String> imageUrls, String passTime, String id,
+      String bayonetId) {
+    this.imageUrls = imageUrls;
+    this.passTime = passTime;
+    this.id = id;
+    this.bayonetId = bayonetId;
+  }
+
+  @Override
+  public void run() {
+    List<String> imgUrlToSave = new ArrayList<>(this.imageUrls.size());
+    String time = passTime;
+    Date times = null;
+    try {
+      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+      times =
+          formatter.parse(time);
+    } catch (ParseException e) {
+      e.printStackTrace();
+    }
+    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);
+    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("/shipAnalysis/HDImages/" + dirs);
+    photoDir.mkdirs();
+    for (String imageUrl : imageUrls) {
+      boolean isSuccess = false;
+      URL url = null;
+      try {
+        String urlToSave = dirs + "/" + "P" + i + "_" + newTime + ".jpg";
+        String photoFile = "/shipAnalysis/HDImages/" + urlToSave;
+        while (!isSuccess) {
+          try {
+            isSuccess = ImageDownload.download(imageUrl, photoFile);
+          } catch (Exception e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+          }
+        }
+        imgUrlToSave.add(urlToSave);
+        i++;
+      } catch (Exception e) {
+        log.error(e.getMessage());
+        e.printStackTrace();
+      }
+    }
+//    log.warn("====>  当前队列值:{}", UrlData.URL_IMG_TO_SAVE);
+    addQueue(id, imgUrlToSave);
+//    log.warn("======>   取出并移除首位元素:{}", JSONObject.toJSONString(UrlData.URL_IMG_TO_SAVE.poll()));
+    Map<String, List<String>> polled = UrlData.URL_HISTORY_IMG_TO_SAVE.poll();
+    if (!"8".equals(bayonetId)) {
+      String id = new ArrayList<>(polled.keySet()).get(0);
+      AnalyseFaced.shipCoverAnalyseHistory(id, polled.get(id).get(0), bayonetId, passTime);
+      AnalyseFaced.boatFlagAnalyseHistory(id, polled.get(id), bayonetId, passTime);
+    }
+  }
+
+  private synchronized static void addQueue(String id, List<String> imgUrlToSave) {
+    Map<String, List<String>> map = new HashMap<>();
+    map.put(id, imgUrlToSave);
+    UrlData.URL_HISTORY_IMG_TO_SAVE.add(map);
+  }
+}