rain
2024-04-19 999c71172bc2135665bf84f5b345d59be01f28bb
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
@@ -55,7 +55,7 @@
     * @return
     * @throws IOException
     */
    private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) {
    private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) throws IOException {
        String jsonString = JSONObject.toJSONString(mediaFile.getMetadata());
        JSONObject jsonObject = JSONObject.parseObject(jsonString);
        Double absoluteAltitude = jsonObject.getDouble("absoluteAltitude");
@@ -78,7 +78,9 @@
        String key = mediaFile.getObjectKey();
        String head = "http://dev.jxpskj.com:9000/cloud-bucket";
        String url = head + key;
        byte[] FJ = downloadFileAsBytes(url);
        File file =downloadFile(url);
        File file1=WaterMark.addWatermark(file,patchesConfigPojo.getUnzip(),pssj,lat,lng);
        byte[] FJ = fileToByteArray(file1);
        TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder();
        if (lotInfo != null) {
            builder.bsm(bsm)
@@ -113,15 +115,19 @@
     * @param fileUrl
     * @return
     */
    public static byte[] downloadFileAsBytes(String fileUrl) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    public  File downloadFile(String fileUrl) {
        File downloadedFile = null;
        String localFilePath =  patchesConfigPojo.getUnzip()+ "tmp.jpg";
        try {
            URL url = new URL(fileUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            try (InputStream inputStream = connection.getInputStream()) {
            downloadedFile = new File(localFilePath);
            try (InputStream inputStream = connection.getInputStream();
                 OutputStream outputStream = new FileOutputStream(downloadedFile)) {
                byte[] buffer = new byte[1024];
                int bytesRead;
                while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -129,11 +135,21 @@
                }
            }
            System.out.println("File downloaded and saved at: " + downloadedFile.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return outputStream.toByteArray();
        return downloadedFile;
    }
}
    public static byte[] fileToByteArray(File file) throws IOException {
        FileInputStream fis = new FileInputStream(file);
        byte[] data = new byte[(int) file.length()];
        fis.read(data);
        fis.close();
        return data;
    }
}