heheng
2024-11-21 b3631dd074d7fa5520f7afcf2cdc1ab681700e7c
expert-admin/src/main/java/com/gkhy/web/controller/common/CommonController.java
@@ -5,6 +5,7 @@
import com.gkhy.common.config.ExpertConfig;
import com.gkhy.common.constant.Constants;
import com.gkhy.common.core.domain.AjaxResult;
import com.gkhy.common.exception.ServiceException;
import com.gkhy.common.utils.StringUtils;
import com.gkhy.common.utils.file.FileUploadUtils;
import com.gkhy.common.utils.file.FileUtils;
@@ -15,14 +16,12 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -172,4 +171,22 @@
            log.error("下载文件失败", e);
        }
    }
    @ApiOperation(value = "删除附件")
    @DeleteMapping("/removeFile")
    public void removeFile(@RequestParam(required = true) String path){
        // 本地资源路径
        String localPath = ExpertConfig.getProfile();
        // 数据库资源地址
        String deletePath = localPath + path;
        File dirFile=new File(deletePath);
        if(!dirFile.exists()){
            throw new ServiceException("文件不存在");
        }
        if(!dirFile.isFile()){
            throw new ServiceException("非文件,不能删除");
        }
        dirFile.delete();
    }
}