rain
2024-06-18 4ce73562f23f501ac3fd7341a9e2bf3768d0a34b
航线定时任务,水印工具地址,修改方法注释
16 files modified
391 ■■■■ changed files
src/main/java/com/dji/sample/media/controller/FileController.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/IFileService.java 25 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/PatchesController.java 7 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/GetPatchesServiceImpl.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/utils/TimerUtil.java 213 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java 25 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/pojo/TerritoryConfigPojo.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java 19 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/ITbFJService.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java 31 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java 7 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/service/IWaylineFileService.java 7 ●●●●● patch | view | raw | blame | history
src/main/resources/application-dev.yml 3 ●●●● patch | view | raw | blame | history
src/main/resources/application-prod.yml 1 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/controller/FileController.java
@@ -58,6 +58,7 @@
        return ResponseResult.success(entityList);
    }
    @PutMapping("/examine")
    public ResponseResult examineData(@RequestParam String fileId) {
        return fileService.updateExamByFileId(fileId);
@@ -82,6 +83,7 @@
    @DeleteMapping("/{workspace_id}/deleteFile")
    public ResponseResult deleteFile(@PathVariable(name = "workspace_id") String workspaceId, @RequestParam String fileId) {
        //根据fileId删除图片
        int count = fileService.deleteMedia(workspaceId, fileId);
        if (count == 0) {
            return ResponseResult.error("删除失败");
@@ -108,9 +110,5 @@
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @PostMapping("/{workspace_id}/mark")
    public void eaveMarkFile(@PathVariable(name = "workspace_id") String workspaceId,@RequestBody FileUploadDTO file) throws ImageProcessingException, IOException, FontFormatException {
        fileService.saveMarkFile(workspaceId,file);
    }
}
src/main/java/com/dji/sample/media/service/IFileService.java
@@ -38,8 +38,21 @@
     */
    Integer saveFile(String workspaceId, FileUploadDTO file);
    /**
     * 存储水印图片
     * @param workspaceId
     * @param file
     * @throws IOException
     * @throws FontFormatException
     * @throws ImageProcessingException
     */
    void saveMarkFile(String workspaceId, FileUploadDTO file) throws IOException, FontFormatException, ImageProcessingException;
    /**
     * 获取媒体文件状态
     * @param fileId
     * @return
     */
    Object mediaInfo(String fileId);
    /**
     * Query information about all files in this workspace based on the workspace id.
@@ -49,8 +62,18 @@
     */
    List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId);
    /**
     * 获取图斑图片集合
     * @param dkbh
     * @param workspaceId
     * @return
     */
    List<MediaFileEntity> listByIsadd(String dkbh,String workspaceId);
    /**
     * 图斑图片审核状态改变
     * @param fileId
     * @return
     */
    ResponseResult updateExamByFileId(String fileId);
    List<MediaFileEntity> listMediaFileEntity(String workspaceId, String jobId);
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -21,6 +21,7 @@
import com.dji.sample.patches.dao.GetPatchesMapper;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.utils.TimerUtil;
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.impl.TbFjServiceImpl;
import com.dji.sample.territory.utils.WaterMarkUtil;
import com.drew.imaging.ImageProcessingException;
@@ -61,7 +62,8 @@
    private IDeviceDictionaryService deviceDictionaryService;
    @Autowired
    private OssServiceContext ossService;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    private Optional<MediaFileEntity> getMediaByFingerprint(String workspaceId, String fingerprint) {
        MediaFileEntity fileEntity = mapper.selectOne(new LambdaQueryWrapper<MediaFileEntity>()
                .eq(MediaFileEntity::getWorkspaceId, workspaceId)
@@ -115,7 +117,7 @@
            File file1 = TbFjServiceImpl.downloadFile(url);
            long timestamp = convertToTimestamp(file.getMetadata().getCreatedTime());
            File file2 = new File(WaterMarkUtil.addWatermark(file1, timestamp, file.getMetadata().getShootPosition().getLat(),
                    file.getMetadata().getShootPosition().getLng(), file.getMetadata().getGimbalYawDegree()).toURI());
                    file.getMetadata().getShootPosition().getLng(), file.getMetadata().getGimbalYawDegree(),territoryConfigPojo.getWatermark()).toURI());
            Object data = ImgUtil.getInfo(file1);
            mediaFileMarkEntity.setDronedata(data);
            mediaFileMarkEntity.setWorkspaceId(workspaceId);
src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -16,6 +16,7 @@
import com.dji.sample.territory.service.impl.TbDkjbxxServiceImpl;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -39,6 +40,8 @@
    private ShpToDataSourceService shpToDataSourceService;
    @Autowired
    private IWaylineFileService waylineFileService;
    @Autowired
    private IWaylineJobService waylineJobService;
    @Autowired
    private TbDkjbxxServiceImpl tbDkjbxxService;
    @Autowired
@@ -142,8 +145,8 @@
    @GetMapping("/useMyTask")
    public ResponseResult useMyTask() throws Exception {
        try {
//            timerUtil.myTask();
            timerUtil.myTask2();
            timerUtil.myTask();
//            timerUtil.myTask2();
            return ResponseResult.success();
        } catch (Exception e) {
            throw new RuntimeException("db存储发送出现异常"+e);
src/main/java/com/dji/sample/patches/service/impl/GetPatchesServiceImpl.java
@@ -89,14 +89,6 @@
        return mapper.deleteById(id);
    }
    /**
     * 根据条件获取照片的分页数据
     *
     * @param param 包含分页信息和查询条件的参数对象
     * @param dkbh  查询条件中带有地块编号关键字,用于文件名的模糊搜索
     * @return 返回照片的分页数据,包括分页信息和照片实体列表
     */
    @Override
    public PaginationData<MediaFileEntity> getPhoto(PatchesParam param, String dkbh) {
        Page<MediaFileEntity> page = fileMapper.selectPage(new Page<MediaFileEntity>(param.getPage(), param.getPageSize()),
@@ -107,25 +99,10 @@
        return new PaginationData<MediaFileEntity>(records, new Pagination(page));
    }
    /**
     * 根据条件获取照片的分页数据
     *
     * @param workspaceId 工作空间的ID,用于指定查询的工作空间
     * @param dkbh        查询条件中带有地块编号关键字,用于文件名的模糊搜索
     * @return 返回照片的分页数据,包括分页信息和照片实体列表
     */
    public List<MediaFileEntity> listPohto(String dkbh, String workspaceId) {
        return fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "%")
                .eq(MediaFileEntity::getWorkspaceId, workspaceId));
    }
    /**
     * 根据地块编号和工作空间ID获取地块信息。
     *
     * @param dkbh        地块编号,用于查询特定定单的地块信息。
     * @param workspaceId 工作空间ID,用于查询属于特定工作空间的地块信息。
     * @return 返回匹配给定地块编号和工作空间ID的地块信息对象。如果找不到匹配的记录,则返回null。
     */
    public LotInfo getLotinfo(String dkbh, String workspaceId) {
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh)
                .eq(LotInfo::getWorkspaceId, workspaceId));
src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -13,6 +13,7 @@
import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbFJService;
import com.dji.sample.wayline.model.dto.WaylineFileDTO;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.model.param.CreateJobParam;
import com.dji.sample.wayline.service.IWaylineFileService;
@@ -30,6 +31,7 @@
import org.springframework.web.multipart.MultipartFile;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.time.LocalDateTime;
import java.io.*;
@@ -37,6 +39,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
@@ -82,13 +86,15 @@
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void myTask() throws Exception {
        Long time = getCurrentTimestampPlus8Hours();
        String taskId = "";
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
//        获取未规划的图斑集合
        List<List<LotInfo>> lists = getNoPlan();
        List<List<LotInfo>> lists = getNoPlan(workspaceId);
        List<List<LotInfo>> convertedLists = convertToLists(lists);
        for (List<LotInfo> list : convertedLists) {
            long timestamp = System.currentTimeMillis();
            time = addOneHourToTimestamp(time);
            String waylineName = "云飞行调查" + timestamp;
            //根据获取的图斑集合获得kmz航线文件
            MultipartFile multipartFile = null;
@@ -98,10 +104,17 @@
                throw new RuntimeException(e);
            }
            //上传航线文件
            backWayline(multipartFile, waylineName, workspaceId, backclaim().getUsername());
            WaylineFileEntity waylineFile = backWayline(multipartFile, waylineName, workspaceId, backclaim().getUsername());
            //将为规划的图斑状态更新为已规划
            List<List<Long>> listOfLists = new ArrayList<>();
            List<Long> sublist = new ArrayList<>();
            sublist.add(time); // 添加整数值
            listOfLists.add(sublist);
            List<Long> lists1 = new ArrayList<>();
            lists1.add(time);
            String times = convertTimestampToFormattedString(time);
            sendPostWithParameters("云飞行计划" + timestamp, waylineFile.getWaylineId(), times, lists1, listOfLists);
            updatePatchesStatu(list);
//            waylineJobService.publishFlightTask(JobParam("656c62f4-cb86-4911-930d-b38089829348"),backclaim());
        }
    }
@@ -119,6 +132,11 @@
        executor.shutdown();
    }
    /**
     * 完成对未推送的图斑数据进行整合发送
     *
     * @throws Exception
     */
    @Transactional
    public void dbOperation() throws Exception {
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
@@ -135,7 +153,7 @@
                    dkbh = getDkbh(mediaFile.getFileName());
                    //获取该媒体文件的图斑信息
                    LotInfo lotInfo2 = getPatchesService.getLotinfo(dkbh, workspaceId);
                    taskId=lotInfo2.getTaskId();
                    taskId = lotInfo2.getTaskId();
                    tbFJService.insertOneData(mediaFile, lotInfo2);
                    getPatchesService.patchesPushed(taskId, dkbh, workspaceId);
                }
@@ -176,7 +194,7 @@
     * @param username
     * @return
     */
    public String backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
    public WaylineFileEntity backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        try {
@@ -184,7 +202,7 @@
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return entity.getWaylineId();
        return entity;
    }
    /**
@@ -192,8 +210,10 @@
     *
     * @return
     */
    public List<List<LotInfo>> getNoPlan() {
        List<LotInfo> list = shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getIsPlan, 0));
    public List<List<LotInfo>> getNoPlan(String worksapceId) {
        List<LotInfo> list = shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>()
                .eq(LotInfo::getIsPlan, 0)
                .eq(LotInfo::getWorkspaceId, worksapceId));
        List<List<LotInfo>> combinedTasks = list.stream()
                .collect(Collectors.groupingBy(LotInfo::getTaskId))
                .values().stream()
@@ -214,47 +234,28 @@
        }
    }
    /**
     * 获取未推送的图斑集合
     *
     * @param workspaceId
     * @return
     */
    public List<List<LotInfo>> getNoPush(String workspaceId) {
        List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>()
                .eq(LotInfo::getIsPush, 0)
                .eq(LotInfo::getInvestigate,1)
                .eq(LotInfo::getInvestigate, 1)
                .eq(LotInfo::getWorkspaceId, workspaceId));
        return groupTasks(list);
    }
    public CustomClaim backclaim() {
    public static CustomClaim backclaim() {
        CustomClaim claim = new CustomClaim();
        claim.setId("1");
        claim.setUsername("adminPC");
        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(1715941980L); // 添加整数值
        listOfLists.add(sublist);
        List<Long> list = new ArrayList<>();
        list.add(1715941980L);
        CreateJobParam param = new CreateJobParam();
        param.setName("云飞行调查" + timestamp);
        param.setExecuteStartTimeArr(listOfLists);
        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) {
@@ -266,7 +267,12 @@
    }
    // 对任务ID进行分组
    /**
     * 根据taskID对图斑进行分组
     *
     * @param lotInfos
     * @return
     */
    public static List<List<LotInfo>> groupTasks(List<LotInfo> lotInfos) {
        Map<String, List<LotInfo>> groupedTasks = new HashMap<>();
        for (LotInfo lotInfo : lotInfos) {
@@ -291,16 +297,25 @@
        return new ArrayList<>(groupedTasks.values());
    }
    // 从filename字段中提取任务ID(任务ID在文件名中以"~"开头、"."结尾)
    /**
     * 从filename中获取taskId
     *
     * @param filename
     * @return
     */
    public static String getTaskId(String filename) {
        // 这里只是一个示例,你需要根据实际情况编写提取task_id的逻辑
        int startIndex = filename.indexOf("~") + 1;
        int endIndex = filename.indexOf(".");
        return filename.substring(startIndex, endIndex);
    }
    /**
     * 从filename中获取地块编号
     *
     * @param filename
     * @return
     */
    public static String getDkbh(String filename) {
        // 这里只是一个示例,你需要根据实际情况编写提取task_id的逻辑
        int startIndex = filename.indexOf("点") + 1;
        int endIndex = filename.indexOf("~");
        return filename.substring(startIndex, endIndex);
@@ -335,7 +350,7 @@
            // 发送请求
            ResponseEntity<String> response = restTemplate.exchange(
                  "http://39.98.48.180:8087/landCloudWork/artifact/media/upload.action",
                    "http://39.98.48.180:8087/landCloudWork/artifact/media/upload.action",
//                    "http://localhost:6789/territory/tbdkjbxx/upload",
                    HttpMethod.POST,
                    requestEntity,
@@ -346,6 +361,14 @@
        }
    }
    /**
     * 发送的请求参数
     *
     * @param taskId
     * @param fileContent
     * @param filePath
     * @return
     */
    private static MultiValueMap<String, Object> buildRequestBody(String taskId, byte[] fileContent, String filePath) {
        MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
        body.add("taskId", taskId);
@@ -361,6 +384,68 @@
    private static byte[] readFileToBytes(String filePath) throws IOException {
        Path path = Paths.get(filePath);
        return Files.readAllBytes(path);
    }
    public static void sendPostWithParameters(String name, String fileId, String time, List<Long> taskDays, List<List<Long>> taskPeriods) throws IOException {
        try {
            RestTemplate restTemplate = new RestTemplate();
            // 构建请求体
            String jsonBody = buildRequestBody(name, fileId, time, taskDays, taskPeriods);
            // 设置请求头
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
            headers.set("Accept-Language", "zh-CN,zh;q=0.9");
            headers.setConnection("keep-alive");
            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MTg1ODUxNTQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDQ5ODUxNTQsImlhdCI6MTcxODU4NTE1NCwidXNlcm5hbWUiOiJhZG1pbkRQIn0.eTi9DTYGwcTvnIZasKTFq9OHQgMFS1-m840terb7ss0");
            // 构建请求实体
            HttpEntity<String> requestEntity = new HttpEntity<>(jsonBody, headers);
            // 发送请求
            ResponseEntity<String> response = restTemplate.exchange(
                    "https://wrj.shuixiongit.com/drone-api/wayline/api/v1/workspaces/4a574db8-4ad3-48f7-9f16-3edbcd8056e1/flight-tasks",
//                    "http://localhost:6789/wayline/api/v1/workspaces/4a574db8-4ad3-48f7-9f16-3edbcd8056e1/flight-tasks",
                    HttpMethod.POST,
                    requestEntity,
                    String.class);
        } catch (Exception e) {
            throw new IllegalArgumentException("Request failed: " + e.getMessage());
        }
    }
    /**
     * 构建请求体
     *
     * @param name
     * @param fileId
     * @param taskDays
     * @param taskPeriods
     * @return
     */
    private static String buildRequestBody(String name, String fileId, String select_execute_time, List<Long> taskDays, List<List<Long>> taskPeriods) {
        return String.format("{"
                + "\"name\":\"%s\","
                + "\"file_id\":\"%s\","
                + "\"dock_sn\":\"4TADKCM0010016\","
                + "\"task_type\":1,"
                + "\"select_execute_time\":\"%s\","
                + "\"rth_altitude\":80,"
                + "\"out_of_control_action\":0,"
                + "\"executeTimeContinuousArr\":[{\"index\":1,\"value\":[]}],"
                + "\"executeTimeRepeatArr\":[{\"index\":1,\"value\":\"\"}],"
                + "\"rep_fre_val\":1,"
                + "\"rep_fre_type\":3,"
                + "\"rep_rule_type\":1,"
                + "\"time_range\":[],"
                + "\"1conValue\":[],"
                + "\"1repValue\":\"\","
                + "\"task_days\":%s,"
                + "\"task_periods\":%s,"
                + "\"wayline_type\":0"
                + "}", name, fileId, select_execute_time, taskDays, taskPeriods);
    }
    /**
@@ -399,6 +484,12 @@
        }
    }
    /**
     * 根据时间创建db存储时的文件夹
     *
     * @param fold
     * @return
     */
    private static File fileFold(String fold) {
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
@@ -419,4 +510,46 @@
        return folder;
    }
    public static Long getCurrentTimestampPlus8Hours() {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 加上8小时
        LocalDateTime nowPlus8Hours = now.plusHours(8);
        // 转换为UTC时间戳
        ZonedDateTime zonedDateTime = nowPlus8Hours.atZone(ZoneId.systemDefault());
        long timestamp = zonedDateTime.toInstant().toEpochMilli();
        // 将毫秒级时间戳转换为秒级时间戳
        return timestamp / 1000;
    }
    public static Long addOneHourToTimestamp(Long timestampInSeconds) {
        // 将输入的秒级时间戳转换为Instant对象
        Instant instant = Instant.ofEpochSecond(timestampInSeconds);
        // 将Instant对象转换为ZonedDateTime对象,使用系统默认时区
        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
        // 加上一小时
        ZonedDateTime zonedDateTimePlusOneHour = zonedDateTime.plusHours(1);
        // 将ZonedDateTime对象转换回秒级时间戳
        return zonedDateTimePlusOneHour.toInstant().getEpochSecond();
    }
    // 方法:将时间戳转换为指定格式的字符串
    public static String convertTimestampToFormattedString(Long timestamp) {
        // 将时间戳转换为Instant对象
        Instant instant = Instant.ofEpochMilli(timestamp);
        // 将Instant对象转换为ZonedDateTime对象,并设置时区为UTC
        ZonedDateTime chinaTime = instant.atZone(ZoneId.of("Asia/Shanghai"));
        // 格式化时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.000'Z'");
        return chinaTime.format(formatter);
    }
}
src/main/java/com/dji/sample/territory/controller/TbDkjbxxController.java
@@ -74,19 +74,19 @@
    @PostMapping("/upload")
    public ResponseResult uploadFile(@RequestParam("file") MultipartFile file,
                                     @RequestParam String taskName,
                                     @RequestParam String taskId){
        String workspaceId="4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
        if (file==null){
                                     @RequestParam String taskId) {
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
        if (file == null) {
            return ResponseResult.error("上传文件为空");
        }
        tbDkjbxxService.uploadFile(file);
        List<TbDkjbxxEntity> list = tbDkjbxxService.list();
        if (list.size()==0){
        if (list.size() == 0) {
            return ResponseResult.error("上传文件数据为空");
        }
        try {
            shpToDataSourceService.savaInMysql(list, workspaceId,taskId,taskName);
        }catch (Exception e){
            shpToDataSourceService.savaInMysql(list, workspaceId, taskId, taskName);
        } catch (Exception e) {
            return ResponseResult.error("上传db文件的内容格式不匹配");
        }
        return ResponseResult.success("上传成功");
@@ -95,10 +95,15 @@
    @PostMapping("/uploadUrl")
    public ResponseResult uploadUrl(@RequestBody UploadUrlParam param) {
        tbDkjbxxService.uploadUrl(param.getDbUrl(), param.getTaskName());
        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
        List<TbDkjbxxEntity> list = tbDkjbxxService.list();
        shpToDataSourceService.savaInMysql(list, workspaceId, param.getTaskId(), param.getTaskName());
        try {
            tbDkjbxxService.uploadUrl(param.getDbUrl(), param.getTaskName());
            String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
            List<TbDkjbxxEntity> list = tbDkjbxxService.list();
            shpToDataSourceService.savaInMysql(list, workspaceId, param.getTaskId(), param.getTaskName());
        } catch (Exception e) {
            return ResponseResult.error("文件下载发生错误" + e);
        }
        return ResponseResult.success(200);
    }
src/main/java/com/dji/sample/territory/pojo/TerritoryConfigPojo.java
@@ -19,10 +19,14 @@
    @Value("${db.sqlite.result}")
    private String result;
    @Value("${db.sqlite.resultSave}")
    private String resultsave;
    @Value("${db.sqlite.resourceSave}")
    private String resourcesave;
    @Value("${db.sqlite.waterMark}")
    private String watermark;
}
src/main/java/com/dji/sample/territory/service/ITbDkjbxxService.java
@@ -27,8 +27,25 @@
     */
    ResponseResult uploadFile(MultipartFile file);
    /**
     * 根据给定的工作空间ID、航线名称、机场纬度和经度,生成并返回一个包含航线文件的MultipartFile对象。
     *
     * @param workspaceId 工作空间ID,用于查询相关数据。
     * @param waylineName 航线名称,用于命名生成的文件。
     * @param airportLat  机场纬度,用于地理坐标转换和航迹点排序。
     * @param airportLon  机场经度,用于地理坐标转换和航迹点排序。
     * @return MultipartFile 对象,包含压缩后的航迹文件。
     * @throws IOException 如果文件操作失败,则抛出IOException。
     */
    MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException;
    ResponseResult uploadUrl(String url,String taskName);
    /**
     * 根据url下载db文件导入图斑表
     *
     * @param url
     * @param taskName
     * @return
     */
    void uploadUrl(String url, String taskName);
}
src/main/java/com/dji/sample/territory/service/ITbFJService.java
@@ -17,6 +17,15 @@
     * @throws IOException
     */
    int insertData(List<MediaFileEntity> mediaFile, LotInfo lotInfo) throws Exception;
    void deleteData();
    void  insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception;
    /**
     * 存入单个图片信息到db
     *
     * @param mediaFile
     * @param lotInfo
     * @throws Exception
     */
    void insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception;
}
src/main/java/com/dji/sample/territory/service/impl/TbDkjbxxServiceImpl.java
@@ -92,17 +92,6 @@
        }
    }
    /**
     * 根据给定的工作空间ID、航线名称、机场纬度和经度,生成并返回一个包含航线文件的MultipartFile对象。
     *
     * @param workspaceId 工作空间ID,用于查询相关数据。
     * @param waylineName 航线名称,用于命名生成的文件。
     * @param airportLat  机场纬度,用于地理坐标转换和航迹点排序。
     * @param airportLon  机场经度,用于地理坐标转换和航迹点排序。
     * @return MultipartFile 对象,包含压缩后的航迹文件。
     * @throws IOException 如果文件操作失败,则抛出IOException。
     */
    @Transactional
    public MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException {
        List<TbDkjbxxEntity> list = iTbDkjbxxMapper.selectList(null);
@@ -119,22 +108,28 @@
    }
    @Override
    public ResponseResult uploadUrl(String url,String taskName) {
    public void uploadUrl(String url, String taskName) {
        if (url.isEmpty()) {
            throw new IllegalArgumentException("上传文件为空");
        }
        String saveFilePath = territoryConfigPojo.getResource(); // 要保存文件的本地路径
        try {
            downloadFile(url, saveFilePath);
            System.out.println("文件下载完成");
        } catch (IOException e) {
            System.out.println("下载文件时发生错误:" + e.getMessage());
            throw new IllegalArgumentException("下载db文件发生错误" + e);
        }
        TimerUtil util=new TimerUtil();
        util.dbSave(territoryConfigPojo.getResource(),territoryConfigPojo.getResourcesave(),taskName);
        return ResponseResult.success();
        TimerUtil util = new TimerUtil();
        util.dbSave(territoryConfigPojo.getResource(), territoryConfigPojo.getResourcesave(), taskName);
    }
    /**
     * 根据地址下载文件
     *
     * @param fileUrl
     * @param saveFilePath
     * @throws IOException
     */
    public static void downloadFile(String fileUrl, String saveFilePath) throws IOException {
        // 创建URL对象
        URL url = new URL(fileUrl);
src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
@@ -9,6 +9,7 @@
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.territory.dao.ITbFjMapper;
import com.dji.sample.territory.model.entity.TbFjEntity;
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbFJService;
import com.dji.sample.territory.utils.*;
import com.dji.sample.territory.utils.jym.SM2SignVO;
@@ -52,6 +53,8 @@
    private ITbFjMapper tbFjMapper;
    @Autowired
    private PatchesConfigPojo patchesConfigPojo;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    /**
     * 按照地块编号所对应的信息和音视频文件存入sqlite数据库
@@ -142,7 +145,7 @@
        //对应图片和视频文件进行不同处理
        boolean endsWith = key.endsWith(".mp4");
        if (!endsWith) {
            file1 = WaterMarkUtil.addWatermark(file, sj, lat, lng, gimbalYawDegree);
            file1 = WaterMarkUtil.addWatermark(file, sj, lat, lng, gimbalYawDegree,territoryConfigPojo.getWatermark());
            byte[] bytesArray = Files.readAllBytes(file1.toPath());
            fjhxz= sm3(bytesArray);
            FJ = fileToByteArray(file1);
@@ -242,6 +245,7 @@
    }
    public static Double truncateToTwoDecimalPlaces(Double value) {
        //小数点只保留两位
        if (value == null) {
            return null;  // 处理null值情况
        }
@@ -250,6 +254,7 @@
    }
    public static Double truncateToSevenDecimalPlaces(Double value) {
        //小数点只保留七位
        if (value == null) {
            return null;  // 处理null值情况
        }
src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
@@ -15,6 +15,7 @@
@Component
public class WaterMarkUtil {
    /**
     * 将图片加上水印并压缩
     *
@@ -25,7 +26,7 @@
     * @return 添加水印并压缩后的图片文件。
     * @throws IOException 如果读取或保存图片失败。
     */
    public static File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles) throws IOException, FontFormatException {
    public static File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles,String path) throws IOException, FontFormatException {
        double anglses = convertAngle(angles);
        String angel = angle(anglses);
        Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位)
src/main/java/com/dji/sample/wayline/service/IWaylineFileService.java
@@ -84,6 +84,13 @@
     */
    void importKmzFile(MultipartFile file, String workspaceId, String creator,String patchesId);
    /**
     * 创建航线,返回航线对象
     * @param file
     * @param workspaceId
     * @param creator
     * @return
     */
    WaylineFileDTO importKmzFileBack (MultipartFile file, String workspaceId, String creator);
    WaylineFileEntity selectByName(String name);
src/main/resources/application-dev.yml
@@ -117,4 +117,5 @@
    resource: DB/resource_db.db
    result: DB/result_db.db
    resultSave: src/main/resources/tmp
    resourceSave: src/main/resources/tmp
    resourceSave: src/main/resources/tmp
    waterMark: src/main/resources/MiSans-Normal.ttf
src/main/resources/application-prod.yml
@@ -117,3 +117,4 @@
    result: /home/drone/server/sqlite/result_db.db
    resultSave: /home/drone/server/sqlite/retUpload/
    resourceSave: /home/drone/server/sqlite/upload/
    waterMark: /usr/share/fonts/MiSans-Normal.ttf