文件模块初步完成

This commit is contained in:
2025-05-06 19:15:01 +08:00
parent 2eb5ee1207
commit e1458e937b
21 changed files with 763 additions and 24 deletions

View File

@ -0,0 +1,89 @@
package com.greenorange.promotion.controller.fileInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.constant.UserConstant;
import com.greenorange.promotion.exception.BusinessException;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
import com.greenorange.promotion.model.dto.fileInfo.FileInfoAddRequest;
import com.greenorange.promotion.model.dto.fileInfo.FileInfoQueryRequest;
import com.greenorange.promotion.model.dto.fileInfo.FileInfoUpdateRequest;
import com.greenorange.promotion.model.dto.fileInfo.UploadFileRequest;
import com.greenorange.promotion.model.entity.FileInfo;
import com.greenorange.promotion.model.vo.fileInfo.FileInfoVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.file.FileInfoService;
import com.greenorange.promotion.utils.RegexUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.greenorange.promotion.model.dto.CommonRequest;
import jakarta.validation.Valid;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* 文件 控制器
*/
@RestController
@RequestMapping("fileInfo")
@Slf4j
@Tag(name = "文件管理")
public class FileInfoController {
@Resource
private FileInfoService fileInfoService;
/**
* Web端文件上传(服务器)
* @param uploadFileRequest 业务请求
* @param multipartFile 上传的文件
* @return 上传文件的路径
*/
@PostMapping("upload")
@Operation(summary = "Web端文件上传服务器", description = "参数文件添加请求体权限管理员方法名addFileInfo")
@SysLog(title = "文件管理", content = "Web端文件上传(服务器)")
public BaseResponse<String> uploadFile(@RequestPart("file") MultipartFile multipartFile, UploadFileRequest uploadFileRequest) {
// 校验文件
fileInfoService.validFile(multipartFile);
// 文件上传
String view = fileInfoService.uploadFile(multipartFile, uploadFileRequest);
return ResultUtils.success(view, "上传成功");
}
/**
* 文件下载(服务器)
* @param filename 文件名
* @throws IOException
*/
@GetMapping("/download")
@Operation(summary = "文件下载(服务器)", description = "参数文件名权限所有人方法名downloadFile")
public void downloadFile(@RequestParam @NotBlank String filename, HttpServletResponse response) throws IOException {
fileInfoService.downloadFile(filename, response);
}
}

View File

@ -53,6 +53,8 @@ public class ProjectController {
*/
@PostMapping("add")
@Operation(summary = "web端管理员添加项目", description = "参数项目添加请求体权限管理员方法名addProject")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "项目管理", content = "web端管理员添加项目")
public BaseResponse<Boolean> addProject(@Valid @RequestBody ProjectAddRequest projectAddRequest) {
Project project = commonService.copyProperties(projectAddRequest, Project.class);
projectService.save(project);