rain
2024-06-14 77565e7990bdeacac09c63efffdd51dd8214b81c
将未推送字段更新到图斑表,db推送以图斑字段is_push为依据
9 files modified
145 ■■■■ changed files
src/main/java/com/dji/sample/media/model/MediaFileEntity.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/model/MediaFileMarkEntity.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/PatchesController.java 20 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/model/entity/LotInfo.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/GetPatchesService.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/GetPatchesServiceImpl.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/utils/TimerUtil.java 101 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/model/MediaFileEntity.java
@@ -76,9 +76,6 @@
    @TableField(value = "metadata", typeHandler = FastjsonTypeHandler.class)
    private Object metadata;
    @TableField("isadd")
    private Integer isadd;
    @TableField("examine")
    private Integer examine;
src/main/java/com/dji/sample/media/model/MediaFileMarkEntity.java
@@ -75,9 +75,6 @@
    @TableField(value = "metadata", typeHandler = FastjsonTypeHandler.class)
    private Object metadata;
    @TableField("isadd")
    private Integer isadd;
    @TableField(value = "drone_data", typeHandler = FastjsonTypeHandler.class)
    private Object dronedata;
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -255,7 +255,6 @@
        if (file != null) {
            builder.fileName(file.getName())
                    .filePath(file.getPath())
                    .isadd(0)
                    .examine(1)
                    .fingerprint(file.getFingerprint())
                    .objectKey(file.getObjectKey())
@@ -282,8 +281,6 @@
        if (file != null) {
            builder.fileName(file.getName())
                    .filePath(file.getPath())
                    .isadd(0)
                    .fingerprint(file.getFingerprint())
                    .objectKey(file.getObjectKey())
                    .subFileType(file.getSubFileType())
src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -149,16 +149,16 @@
            throw new RuntimeException("db存储发送出现异常"+e);
        }
    }
    @GetMapping ("/tests")
    public ResponseResult use()  {
        try {
            TimerUtil.sendPostWithFileAndParameter("DB/result_db.db",
                    "635148ea-0ddb-4b23-945c-8a67abd813c9");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return ResponseResult.success();
    }
//    @GetMapping ("/tests")
//    public ResponseResult use()  {
//        try {
//            TimerUtil.sendPostWithFileAndParameter("src/main/resources/tmp/20240613/205621_635148ea-0ddb-4b23-945c-8a67abd813c9.db",
//                    "635148ea-0ddb-4b23-945c-8a67abd813c9");
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//        return ResponseResult.success();
//    }
    /**
     * 根据图斑的地块编号获取相对应音视频
src/main/java/com/dji/sample/patches/model/entity/LotInfo.java
@@ -75,6 +75,9 @@
    @TableField("investigate")
    private int investigate;
    @TableField("is_push")
    private int isPush;
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Long createTime;
src/main/java/com/dji/sample/patches/service/GetPatchesService.java
@@ -16,6 +16,7 @@
    PaginationData<LotInfo> limitGet(PatchesParam param);
    int delPatches(String workspaceId);
    void patchesPushed(String taskId, String dkbh, String workspaceId);
    int deleteOne(int id);
    /**
     * 根据条件获取照片的分页数据
src/main/java/com/dji/sample/patches/service/impl/GetPatchesServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dji.sample.common.model.Pagination;
import com.dji.sample.common.model.PaginationData;
@@ -129,7 +130,14 @@
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh)
                .eq(LotInfo::getWorkspaceId, workspaceId));
    }
    public void patchesPushed(String taskId, String dkbh, String workspaceId) {
        LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(LotInfo::getIsPush, 1)
                .eq(LotInfo::getWorkspaceId, workspaceId)
                .eq(LotInfo::getDkbh, dkbh)
                .eq(LotInfo::getTaskId, taskId);
        mapper.update(null, updateWrapper);
    }
    public LotInfo getLotinfoToDb(String dkbh) {
        return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh));
    }
src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -105,6 +105,7 @@
                .dkfw(file.getFShape())
                .workspaceId(workspaceId)
                .isPlan(0)
                .isPush(0)
                .xmc(DistrictCodeUtils.nameToCode(file.getFXzqdm()))
                .investigate(0)
                .taskId(id)
src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -1,12 +1,11 @@
package com.dji.sample.patches.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dji.sample.common.model.CustomClaim;
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.media.dao.IFileMapper;
import com.dji.sample.media.model.MediaFileEntity;
import com.dji.sample.patches.config.pojo.PatchesConfigPojo;
import com.dji.sample.patches.dao.GetPatchesMapper;
import com.dji.sample.patches.dao.ShpToDataSourceMapper;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.service.GetPatchesService;
@@ -19,10 +18,6 @@
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.*;
@@ -33,16 +28,11 @@
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;
import java.time.LocalDateTime;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -54,7 +44,6 @@
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;
@@ -76,6 +65,9 @@
    private ITbFJService tbFJService;
    @Autowired
    private GetPatchesService getPatchesService;
    @Autowired
    private GetPatchesMapper patchesMapper;
    @Autowired
    private IWaylineJobService waylineJobService;
    @Autowired
@@ -131,26 +123,28 @@
    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) {
            //清空FJ表
            tbFJService.deleteData();
            for (MediaFileEntity mediaFile : media) {
                //获取媒体文件名里的dkbh和taskId
                String dkbh = getDkbh(mediaFile.getFileName());
                taskId = getTaskId(mediaFile.getFileName());
                //获取该媒体文件的图斑信息
                LotInfo lotInfo = getPatchesService.getLotinfo(dkbh, workspaceId);
                tbFJService.insertOneData(mediaFile, lotInfo);
                //更新媒体文件的是否添加状态
                updateMediaStatu(mediaFile);
        String dkbh = null;
        List<List<LotInfo>> lists = convertToLists(getNoPush(workspaceId));
        for (List<LotInfo> lotInfo : lists) {
            for (LotInfo lotInfo1 : lotInfo) {
                List<MediaFileEntity> media = getPatchesService.listPohto(lotInfo1.getDkbh(), workspaceId);
                //清空FJ表
                tbFJService.deleteData();
                for (MediaFileEntity mediaFile : media) {
                    //获取媒体文件名里的dkbh和taskId
                    dkbh = getDkbh(mediaFile.getFileName());
                    //获取该媒体文件的图斑信息
                    LotInfo lotInfo2 = getPatchesService.getLotinfo(dkbh, workspaceId);
                    taskId=lotInfo2.getTaskId();
                    tbFJService.insertOneData(mediaFile, lotInfo2);
                    getPatchesService.patchesPushed(taskId, dkbh, workspaceId);
                }
            }
            //存储db到服务器
            dbSave(territoryConfigPojo.getResult(), territoryConfigPojo.getResultsave(), taskId);
            //发送请求给第三方接口
            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId);
            sendPostWithFileAndParameter(territoryConfigPojo.getResult(), taskId, dkbh, workspaceId);
        }
    }
@@ -220,19 +214,14 @@
        }
    }
    public void updateMediaStatu(MediaFileEntity mediaFile) {
        mediaFile.setIsadd(1);
        fileMapper.updateById(mediaFile);
    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::getWorkspaceId, workspaceId));
        return groupTasks(list);
    }
    public List<List<MediaFileEntity>> getNoadd() {
        List<MediaFileEntity> list = fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
                .eq(MediaFileEntity::getIsadd, 0)
                .eq(MediaFileEntity::getExamine, 1)
                .like(MediaFileEntity::getFileName, "~"));
        List<List<MediaFileEntity>> groupedFilenames = groupTasks(list);
        return groupedFilenames;
    }
    public CustomClaim backclaim() {
        CustomClaim claim = new CustomClaim();
@@ -278,7 +267,19 @@
    // 对任务ID进行分组
    public static List<List<MediaFileEntity>> groupTasks(List<MediaFileEntity> mediaFiles) {
    public static List<List<LotInfo>> groupTasks(List<LotInfo> lotInfos) {
        Map<String, List<LotInfo>> groupedTasks = new HashMap<>();
        for (LotInfo lotInfo : lotInfos) {
            String taskId = lotInfo.getTaskId();
            if (!groupedTasks.containsKey(taskId)) {
                groupedTasks.put(taskId, new ArrayList<>());
            }
            groupedTasks.get(taskId).add(lotInfo);
        }
        return new ArrayList<>(groupedTasks.values());
    }
    public static List<List<MediaFileEntity>> groupTask(List<MediaFileEntity> mediaFiles) {
        Map<String, List<MediaFileEntity>> groupedTasks = new HashMap<>();
        for (MediaFileEntity mediaFile : mediaFiles) {
            String taskId = getTaskId(mediaFile.getFileName());
@@ -312,7 +313,7 @@
     * @param taskId
     * @throws IOException
     */
    public static void sendPostWithFileAndParameter(String filePath, String taskId) throws IOException {
    public void sendPostWithFileAndParameter(String filePath, String taskId, String dkbh, String workspaceId) throws IOException {
        // 创建 RestTemplate 实例
        try {
            RestTemplate restTemplate = new RestTemplate();
@@ -333,26 +334,12 @@
            HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
            // 发送请求
            ResponseEntity<String> response =restTemplate.exchange(
                    "https://jxlandcloud.org.cn/landCloudWork/artifact/media/upload.action",
//                  "http://localhost:6789/territory/tbdkjbxx/upload",
            ResponseEntity<String> response = restTemplate.exchange(
                  "http://39.98.48.180:8087/landCloudWork/artifact/media/upload.action",
//                    "http://localhost:6789/territory/tbdkjbxx/upload",
                    HttpMethod.POST,
                    requestEntity,
                    String.class);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
            System.out.println(response);
        } catch (Exception e) {
            throw new IllegalArgumentException("db推送失败" + e.getMessage());