Xiajijian
2026-03-07 4d314c8b1232773cb5c8288ea6ed6ff6fe8ee4b9
ard-admin/src/main/java/com/ard/web/controller/inspection/BigFileUploadController.java
@@ -4,7 +4,10 @@
import com.ard.common.core.controller.BaseController;
import com.ard.common.core.domain.AjaxResult;
import com.ard.common.enums.BusinessType;
import com.ard.inspection.domain.UploadFileEntity;
import com.ard.inspection.service.IBigFileUploadService;
import com.ard.inspection.utils.ZipFileUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import io.swagger.annotations.Api;
@@ -12,7 +15,10 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.*;
import java.io.File;
import java.io.IOException;
/**
 * @author xia
@@ -32,10 +38,14 @@
    @Value(value = "${inspection.chunk.path}")
    private String chunkPath;
    @Value(value = "${inspection.chunk.zipPath}")
    private String zipPath;
    /**
     * 检查分片是否存在
     */
    @GetMapping("/chunks/{fileMd5}")
    @ApiOperation("检查分片是否存在")
    @GetMapping("/bigfile/{fileMd5}")
    public AjaxResult checkChunk(@PathVariable String fileMd5) {
        Map<String, Object> result = bigFileUploadService.checkChunk(fileMd5,chunkPath);
        return AjaxResult.success(result);
@@ -44,23 +54,43 @@
    /**
     * 上传分片
     */
    @PostMapping("/chunk")
    public AjaxResult uploadChunk(@RequestParam("file") MultipartFile file,
                                  @RequestParam("chunkNumber") Integer chunkNumber,
                                  @RequestParam("fileMd5") String fileMd5) {
        Map<String, Object> result = bigFileUploadService.uploadChunk(file, chunkNumber, fileMd5, chunkPath);
    @ApiOperation("上传分片")
    @PostMapping("/bigfile/chunk")
    public AjaxResult uploadChunk(@RequestBody UploadFileEntity uploadFileEntity,
                                  @RequestParam("file") MultipartFile file) {
//    public AjaxResult uploadChunk(@RequestParam("file") MultipartFile file,
//                                  @RequestParam("chunkNumber") Integer chunkNumber,
//                                  @RequestParam("fileMd5") String fileMd5) {
        Map<String, Object> result = bigFileUploadService.uploadChunk(file,uploadFileEntity,chunkPath);
        return AjaxResult.success(result);
    }
    /**
     * 合并切片
     */
    @ApiOperation("合并分片")
    @Log(title = "合并切片", businessType = BusinessType.IMPORT)
    @PostMapping("/merge")
    @PostMapping("/bigfile/merge")
    public AjaxResult mergeChunks(@RequestParam("md5") String md5,
                                  @RequestParam("fileName") String fileName) {
        Map<String, Object> result = bigFileUploadService.mergeChunks(md5, fileName, uploadPath);
        return AjaxResult.success(result);
    }
    /**
     * 大文件上传并解压接口
     * @param file 上传的ZIP文件
     * @param overwrite 是否覆盖已存在文件(默认false)
     * @return 上传结果
     */
    @ApiOperation("大文件上传并解压接口")
    @Log(title = "大文件上传解压", businessType = BusinessType.INSERT)
    @PostMapping("/upload/bigFileUnzip")
    public AjaxResult uploadBigZipFile(
            @RequestPart("file") MultipartFile file) {
            //@RequestParam(value = "overwrite", defaultValue = "false") boolean overwrite) {
        boolean overwrite = false;
        return bigFileUploadService.uploadBigZipFile(file,overwrite,uploadPath,chunkPath,zipPath);
    }
}