rain
2024-08-20 74d1c21ebb6b3b916904d95d13d289df23dcdedd
src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -6,6 +6,7 @@
import com.dji.sample.common.util.MinioUrlUtils;
import com.dji.sample.media.model.MediaFileEntity;
import com.dji.sample.media.service.impl.FileServiceImpl;
import com.dji.sample.patches.constant.FileSufConstant;
import com.dji.sample.patches.model.Param.PatchesParam;
import com.dji.sample.patches.model.entity.LotInfo;
import com.dji.sample.patches.service.GetPatchesService;
@@ -154,7 +155,7 @@
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        MultipartFile file = timerUtil.getFile(waylineName, lotInfos, lat, lon);
        waylineFileService.importKmzFile(file, workspaceId, creator, patchesId, isTemp);
        waylineFileService.importKmzFile(file, workspaceId, creator, patchesId, isTemp,1);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        Map<String, String> infoMap = new HashMap<>();
        URL url = null;
@@ -199,14 +200,14 @@
        executor.shutdown();
        return ResponseResult.success();
    }
    @PostMapping("/way")
    public void getway(@RequestParam("file") MultipartFile file,
                       @RequestParam String workspaceId,
                       @RequestParam String waylineName,
                       @RequestParam String username) {
        waylineFileService.importKmzFileBack(file, workspaceId, username);
    }
//
//    @PostMapping("/way")
//    public void getway(@RequestParam("file") MultipartFile file,
//                       @RequestParam String workspaceId,
//                       @RequestParam String waylineName,
//                       @RequestParam String username) {
//        waylineFileService.importKmzFileBack(file, workspaceId, username);
//    }
    /**
     * 根据图斑的地块编号获取相对应音视频
@@ -255,10 +256,14 @@
                                 @RequestParam double airportLat,
                                 @RequestParam double airportLon,
                                 HttpServletRequest request) throws Exception {
        // 检查格式是否正确
        if(!checkFileType(file.getOriginalFilename())){
            throw new RuntimeException("文件格式异常");
        }
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        MultipartFile multipartFile = shpToDataSourceService.insertGeo(file, workspaceId, waylineName, airportLat, airportLon, creator);
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator);
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator,1);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        Map<String, String> infoMap = new HashMap<>();
        URL url = null;
@@ -272,10 +277,27 @@
        return ResponseResult.success(infoMap);
    }
    /**
     * 检查文件格式是否正确
     * @param originalFilename
     * @return
     */
    private boolean checkFileType(String originalFilename) {
        if (originalFilename.endsWith(FileSufConstant.FILE_SUFFIX_ZIP) ||
                originalFilename.endsWith(FileSufConstant.FILE_SUFFIX_KML) ||
                originalFilename.endsWith(FileSufConstant.FILE_SUFFIX_KMZ)
        ){
            return true;
        }
        // 返回
        return false;
    }
    @GetMapping("/getExcel")
    public ResponseEntity<byte[]> exportExcel(@RequestParam String workspaceId) {
        List<LotInfo> lotInfos = getPatchesService.listLotinfo(workspaceId);
    public ResponseEntity<byte[]> exportExcel(@RequestParam String ids) {
//        List<LotInfo> lotInfos = getPatchesService.listLotinfo(workspaceId);
        try {
            List<LotInfo> lotInfos = getPatchesService.getLotInfosByIDs(ids);
            ByteArrayInputStream excelStream = ExcelUtil.exportLotInfoToExcel(lotInfos);
            byte[] excelData = excelStream.readAllBytes();
            excelStream.close();
@@ -288,7 +310,7 @@
            return new ResponseEntity<>(excelData, headers, HttpStatus.OK);
        } catch (IOException e) {
            e.printStackTrace();
            return new ResponseEntity<>(("Failed to generate Excel file.").getBytes(), HttpStatus.INTERNAL_SERVER_ERROR);
            return new ResponseEntity<>(("生成excel失败.").getBytes(), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}