| | |
| | | package com.dji.sample.territory.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.config.pojo.PatchesConfigPojo; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.utils.MultipartFileTOFileUtil; |
| | | import com.dji.sample.territory.dao.ITbFjMapper; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import com.dji.sample.territory.service.ITbFJService; |
| | | import com.dji.sample.territory.utils.Sm3Util; |
| | | import com.dji.sample.territory.utils.VideoZipUtil; |
| | | import com.dji.sample.territory.utils.WaterMark; |
| | | import com.dji.sample.territory.utils.WaterMarkUtil; |
| | | import org.bouncycastle.crypto.params.ECPrivateKeyParameters; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | import static com.dji.sample.territory.utils.CoordinateSystemUtil.*; |
| | | import static com.dji.sample.territory.utils.SM2SignUtil.getSM2PrivateKey; |
| | | import static com.dji.sample.territory.utils.SM2SignUtil.signWithSM2; |
| | | |
| | | @Service |
| | | @DS("sqlite-ret") |
| | |
| | | * @throws IOException |
| | | */ |
| | | @Transactional |
| | | public int insertData(List<MediaFileEntity> mediaFile, LotInfo lotInfo) throws IOException { |
| | | public int insertData(List<MediaFileEntity> mediaFile, LotInfo lotInfo) throws Exception { |
| | | int count = 0; |
| | | List<TbFjEntity> list = new ArrayList<>(); |
| | | TbFjEntity tbFj; |
| | |
| | | return count; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteData() { |
| | | tbFjMapper.delete(null); |
| | | } |
| | | |
| | | /** |
| | | * 将Media和Lotinfo实体类转化为TbFjEntity实体类 |
| | | * |
| | |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) throws IOException { |
| | | private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception { |
| | | File file1 = null; |
| | | byte[] FJ = null; |
| | | String jsonString = JSONObject.toJSONString(mediaFile.getMetadata()); |
| | |
| | | JSONObject shootPosition = jsonObject.getJSONObject("shootPosition"); |
| | | Double lat = shootPosition.getDouble("lat"); |
| | | Double lng = shootPosition.getDouble("lng"); |
| | | double[] coordinates = extractCoordinates(pointWGStoCGCS(lng, lat)); |
| | | double x = Double.parseDouble(((formatCoordinate(coordinates[1])))); |
| | | double y = Double.parseDouble(((formatCoordinate(coordinates[0])))); |
| | | //本地数据库没有的数据在FJ表非空用0 |
| | | int psjd = 0; |
| | | String fjhxz = "0"; |
| | | int pshgj = 0; |
| | | String jym = "0"; |
| | | String psry = "0"; |
| | | String zsdm = "0"; |
| | | String zsdm = "23C8CCC61E3042FBA6A658F319337B1A"; |
| | | String dklx = "0"; |
| | | String xzqdm = "0"; |
| | | int fjlx = 1; |
| | |
| | | //对应图片和视频文件进行不同处理 |
| | | boolean endsWith = key.endsWith(".mp4"); |
| | | if (!endsWith) { |
| | | file1 = WaterMark.addWatermark(file, patchesConfigPojo.getUnzip(), pssj, lat, lng); |
| | | file1 = WaterMarkUtil.addWatermark(file, patchesConfigPojo.getUnzip(), pssj, lat, lng,gimbalYawDegree); |
| | | FJ = fileToByteArray(file1); |
| | | } else { |
| | | file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720); |
| | | FJ = fileToByteArray(file1); |
| | | } |
| | | String sm3 = Sm3Util.calculateSM3Hash(fjhxz+","+pssj+","+lng+","+lat+","+gimbalYawDegree+","+psjd+","+pshgj+","+psry+","+zsdm); |
| | | |
| | | byte[] hash = sm3.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值 |
| | | // 加载私钥 |
| | | ECPrivateKeyParameters sm2PrivateKey = getSM2PrivateKey(); |
| | | // 使用SM2私钥对哈希值进行签名 |
| | | String signatureHex = signWithSM2(hash, sm2PrivateKey); |
| | | TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder(); |
| | | if (lotInfo != null) { |
| | | builder.bsm(bsm) |
| | |
| | | .dklx(dklx) |
| | | .xdgd(relativeAltitude) |
| | | .jdgd(absoluteAltitude) |
| | | .Latitude(lat) |
| | | .longitude(lng) |
| | | .Latitude(x) |
| | | .longitude(y) |
| | | .fj(FJ) |
| | | .fjmc(fjmc) |
| | | .fjlx(fjlx) |
| | |
| | | .pshgj(pshgj) |
| | | .zsdm(zsdm) |
| | | .psry(psry) |
| | | .jym(jym) |
| | | .jym(signatureHex) |
| | | .url(url) |
| | | .build(); |
| | | } else { |
| | | throw new IllegalArgumentException("未匹配到相关地块"); |
| | | } |
| | | // else { |
| | | //// throw new IllegalArgumentException("未匹配到相关地块"); |
| | | // } |
| | | return builder.build(); |
| | | } |
| | | |
| | |
| | | */ |
| | | 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"); |
| | | downloadedFile = new File(localFilePath); |
| | | downloadedFile = new File(File.createTempFile("temp", ".jpeg").toURI()); |
| | | InputStream inputStream = connection.getInputStream(); |
| | | OutputStream outputStream = new FileOutputStream(downloadedFile); |
| | | byte[] buffer = new byte[1024]; |