| | |
| | | import java.util.UUID; |
| | | |
| | | @Service |
| | | @DS("sqlite") |
| | | @DS("sqlite-ret") |
| | | public class TbFjServiceImpl implements ITbFJService { |
| | | @Autowired |
| | | private ITbFjMapper mapper; |
| | |
| | | * @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"); |
| | |
| | | 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) |
| | |
| | | .jdgd(absoluteAltitude) |
| | | .Latitude(lat) |
| | | .longitude(lng) |
| | | .fj(FJ) |
| | | // .fj(FJ) |
| | | .fjmc(fjmc) |
| | | .fjlx(1) |
| | | .psfyj(gimbalYawDegree) |
| | |
| | | .zsdm(zsdm) |
| | | .psry(psry) |
| | | .jym(jym) |
| | | .url(url) |
| | | .build(); |
| | | } else { |
| | | throw new IllegalArgumentException("未匹配到相关地块"); |
| | |
| | | * @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) { |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | } |