rain
2024-05-16 6ad595014ddd8578ead23116b3f9cb00f828627a
db对接格式修改,定时器异步、水印调整
7 files modified
154 ■■■■ changed files
src/main/java/com/dji/sample/patches/controller/PatchesController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/utils/TimerUtil.java 116 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java 14 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java 16 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -77,9 +77,9 @@
    @GetMapping("/useMyTask")
    public ResponseResult useMyTask() throws Exception {
        timerUtil.myTask();
        timerUtil.myTask2();
        return ResponseResult.success();
    }
    /**
     * 根据图斑的地块编号获取相对应音视频
     *
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -100,7 +100,7 @@
    private LotInfo dbConvertToEntity(TbDkjbxxEntity file, String workspaceId,String id,String name) {
        LotInfo.LotInfoBuilder builder = LotInfo.builder();
        builder.bsm(file.getFId())
                .xzqdm(file.getFXzqdmsys())
                .xzqdm(file.getFXzqdm())
                .dkbh(file.getFTbbh())
                .dkfw(file.getFShape())
                .workspaceId(workspaceId)
src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -19,15 +19,21 @@
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.UriComponentsBuilder;
import javax.xml.transform.Result;
import java.nio.file.StandardCopyOption;
@@ -46,6 +52,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert;
@@ -90,12 +99,37 @@
            long timestamp = System.currentTimeMillis();
            String waylineName = "云飞行调查" + timestamp;
            //根据获取的图斑集合获得kmz航线文件
            MultipartFile multipartFile = getFile(waylineName, list);
            MultipartFile multipartFile = null;
            try {
                multipartFile = getFile(waylineName, list);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            //上传航线文件
            backWayline(multipartFile, waylineName, workspaceId, backclaim().getUsername());
            //将为规划的图斑状态更新为已规划
            updatePatchesStatu(list);
        }
    }
    @Scheduled(cron = "0 0 0 * * ?")
    public void myTask2() {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(() -> {
            try {
                dbOperation();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        executor.shutdown();
    }
    @Transactional
    public void dbOperation() throws Exception {
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
        String taskId = "";
        List<List<MediaFileEntity>> list = getNoadd();
        List<List<MediaFileEntity>> medias = convertToLists(list);
        for (List<MediaFileEntity> media : medias) {
@@ -110,16 +144,18 @@
                tbFJService.insertOneData(mediaFile, lotInfo);
                //更新媒体文件的是否添加状态
                updateMediaStatu(mediaFile);
            }
            //存储db到服务器
            dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
            //发送请求给第三方接口
            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
        }
    }
    /**
     * 创建航线
     *
     * @param waylineName
     * @param list
     * @return
@@ -137,6 +173,7 @@
    /**
     * 将航线上传Oss
     *
     * @param multipartFile
     * @param waylineName
     * @param workspaceId
@@ -182,8 +219,8 @@
    }
    public void updateMediaStatu(MediaFileEntity mediaFile) {
            mediaFile.setIsadd(1);
            fileMapper.updateById(mediaFile);
        mediaFile.setIsadd(1);
        fileMapper.updateById(mediaFile);
    }
    public List<List<MediaFileEntity>> getNoadd() {
@@ -200,6 +237,30 @@
        claim.setWorkspaceId("4a574db8-4ad3-48f7-9f16-3edbcd8056e1");
        claim.setUserType(1);
        return claim;
    }
    public static CreateJobParam JobParam(String waylineId) {
        long timestamp = System.currentTimeMillis();
        List<List<Long>> listOfLists = new ArrayList<>();
        List<Long> sublist = new ArrayList<>();
        sublist.add(1715852375L); // 添加整数值
        listOfLists.add(sublist);
        List<Long> list = new ArrayList<>();
        list.add(1715852375L);
        CreateJobParam param = new CreateJobParam();
        param.setName("云飞行调查"+timestamp);
        param.setTaskType(TIMED);
        param.setOutOfControlAction(0);
        param.setRepFreType(3);
        param.setRepFreVal(1);
        param.setRepRuleType(1);
        param.setRthAltitude(80);
        param.setWaylineType(WAYPOINT);
        param.setTaskPeriods(listOfLists);
        param.setTaskDays(list);
        param.setFileId(waylineId);
        param.setDockSn("4TADKCMB0010016");
        return param;
    }
    public static <T> List<List<T>> convertToLists(List<List<T>> listOfLists) {
@@ -241,39 +302,40 @@
    /**
     * 将成果发送post请求到第三方接口
     *
     * @param filePath
     * @param taskId
     * @throws IOException
     */
    public static void sendPostWithFileAndParameter(String filePath, String taskId) throws IOException {
        // 创建 RestTemplate 实例
        try{
        RestTemplate restTemplate = new RestTemplate();
        try {
            RestTemplate restTemplate = new RestTemplate();
        // 读取文件内容为字节数组
        byte[] fileContent = readFileToBytes(filePath);
            // 读取文件内容为字节数组
            byte[] fileContent = readFileToBytes(filePath);
        // 构建请求体
        MultiValueMap<String, Object> body = buildRequestBody(taskId, fileContent, filePath);
            // 构建请求体
            MultiValueMap<String, Object> body = buildRequestBody(taskId, fileContent, filePath);
        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        headers.set("X-SHARE-TOKEN", "981D9B822A9A09DE28B66243AA330DC666E1A82826B58EC3FE63FEB1EC8AA190");
        headers.set("X-SHARE-AK", "gwc952d483-bfe5-476b-8431-ae15fe94c006");
            // 设置请求头
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
            headers.set("X-SHARE-TOKEN", "981D9B822A9A09DE28B66243AA330DC666E1A82826B58EC3FE63FEB1EC8AA190");
            headers.set("X-SHARE-AK", "gwc952d483-bfe5-476b-8431-ae15fe94c006");
        // 构建请求实体
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
            // 构建请求实体
            HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
        // 发送请求
                ResponseEntity<String> result=restTemplate.exchange(
                "http://39.98.48.180:8087/landCloudWork/artifact/media/upload.action",
//                "http://localhost:6789/territory/tbdkjbxx/upload",
                HttpMethod.POST,
                requestEntity,
                String.class);
        }catch (Exception e){
            throw new IllegalArgumentException("db推送失败"+e.getMessage());
            // 发送请求
                     restTemplate.exchange(
                    "https://jxlandcloud.org.cn/landCloudWork/artifact/media/upload.action",
//                  "http://localhost:6789/territory/tbdkjbxx/upload",
                    HttpMethod.POST,
                    requestEntity,
                    String.class);
        } catch (Exception e) {
            throw new IllegalArgumentException("db推送失败" + e.getMessage());
        }
    }
@@ -296,6 +358,7 @@
    /**
     * 将上传的db保存一份到本地
     *
     * @param path
     * @param folder
     * @param taskId
@@ -348,5 +411,4 @@
        }
        return folder;
    }
}
src/main/java/com/dji/sample/territory/model/entity/TbDkjbxxEntity.java
@@ -21,7 +21,7 @@
@TableName(value = "table_info")
public class TbDkjbxxEntity {
private String fXzqdmsys;
private String fXzqdm;
private String fShape;
src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
@@ -166,7 +166,7 @@
                builder.bsm(file.getFId())
                        .dkbh(file.getFTbbh())
                        .dkfw(file.getFShape())
                        .xzqdm(file.getFXzqdmsys())
                        .xzqdm(file.getFXzqdm())
                        .build();
                // 将构建好的LotInfo对象添加到infos列表中
                infos.add(builder.build());
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
@@ -94,12 +94,13 @@
        Double absoluteAltitude = jsonObject.getDouble("absoluteAltitude");
        Double relativeAltitude = jsonObject.getDouble("relativeAltitude");
        Double gimbalYawDegree = jsonObject.getDouble("gimbalYawDegree");
        Long sj =jsonObject.getLong("createdTime");
        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]))));
//        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;
        int pshgj = 0;
@@ -108,7 +109,6 @@
        String dklx = "0";
        int fjlx = 1;
        String pstz="Y";
        Long sj = mediaFile.getCreateTime();
        String pssj=convertTimestampToDateTime(sj);
        String bsm = UUID.randomUUID().toString();
        String fjmc = mediaFile.getFileName();
@@ -129,7 +129,7 @@
            file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720);
            FJ = fileToByteArray(file1);
        }
        String sm3 = Sm3Util.calculateSM3Hash(fjhxz+","+pssj+","+y+","+x+","+gimbalYawDegree+","+psjd+","+pshgj+","+psry+","+zsdm);
        String sm3 = Sm3Util.calculateSM3Hash(fjhxz+","+pssj+","+lng+","+lat+","+gimbalYawDegree+","+psjd+","+pshgj+","+psry+","+zsdm);
        byte[] hash = sm3.getBytes(); // 注意:使用SM3或其他哈希算法来计算数据的哈希值
        // 加载私钥
@@ -144,8 +144,8 @@
                    .dklx(dklx)
                    .xdgd(relativeAltitude)
                    .jdgd(absoluteAltitude)
                    .Latitude(x)
                    .longitude(y)
                    .Latitude(lat)
                    .longitude(lng)
                    .fj(FJ)
                    .fjmc(fjmc)
                    .fjlx(fjlx)
src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
@@ -24,7 +24,7 @@
     * @throws IOException 如果读取或保存图片失败。
     */
    public static File addWatermark(File file, String path, Long pssj, Double lat, Double lng, Double angles) throws IOException {
        String author="机巢";
        String author="中图智绘无人机";
        String angel=angle(angles);
        Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位)
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -40,20 +40,20 @@
        // 创建 Graphics2D 对象以在图像上绘制水印
        Graphics2D g2d = originalImage.createGraphics();
        // 设置水印文字 "国土调查云"
        // 设置水印文字 "江西调查云"
        String watermarkText = "江西调查云";
        float alpha = 0.5f; // 设置透明度为 0.5
        float alpha = 0.7f; // 设置透明度为 0.7
        AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
        g2d.setComposite(alphaComposite);
        g2d.setFont(new Font("宋体", Font.BOLD, 100)); // 使用宋体字体
        g2d.setFont(new Font("宋体", Font.BOLD, 150)); // 使用宋体字体
        FontMetrics fms = g2d.getFontMetrics();
        int textHeights = fms.getHeight();
        // 设置水印位置(左居中)
        int x1 = 100; // 左边距离图片左边缘的距离
        int y1 = (originalImage.getHeight() - textHeights) / 2; // 垂直居中
        int x1 = 600; // 左边距离图片左边缘的距离
        int y1 = (originalImage.getHeight() - textHeights) -800; // 垂直居中
        // 旋转35度角
        double angle = Math.toRadians(35);
        double angle = Math.toRadians(50);
        AffineTransform at = AffineTransform.getRotateInstance(angle, x1, y1);
        g2d.setTransform(at);
        // 绘制左上角旋转水印文字
@@ -71,7 +71,7 @@
        g2d.setTransform(new AffineTransform());
        // 设置文本位置(右下角)
        int x2 = originalImage.getWidth() - textWidth - 30; // 右对齐的 x 坐标
        int y2 = originalImage.getHeight() - textHeight - 65; // 最底部位置 y 坐标
        int y2 = originalImage.getHeight() - textHeight - 68; // 最底部位置 y 坐标
        // 绘制文本信息
        String[] lines = extraInfo.split("\n");
        for (String line : lines) {