port com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.base.BaseController;
import com.itheima.pinda.base.R;
import com.itheima.pinda.dozer.DozerUtils;
import com.itheima.pinda.file.dto.FilePageReqDTO;
import com.itheima.pinda.file.dto.FileUpdateDTO;
import com.itheima.pinda.file.dto.FolderDTO;
import com.itheima.pinda.file.dto.FolderSaveDTO;
import com.itheima.pinda.file.entity.File;
import com.itheima.pinda.file.manager.FileRestManager;
import com.itheima.pinda.file.service.FileService;
import com.itheima.pinda.log.annotation.SysLog;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
/**
* 文件前端控制器
*/
@Validated
@RestController
@RequestMapping("/file")
@Slf4j
@Api(value = "文件表", tags = "文件表")
public class FileController extends BaseController {
@Autowired
private FileService fileService;
@Autowired
private FileRestManager fileRestManager;
@Autowired
private DozerUtils dozerUtils;
/**
* 查询单个文件信息
*
* @param id
* @return
*/
@ApiOperation(value = "查询文件", notes = "查询文件")
@GetMapping
public R<File> get(@RequestParam(value = "id") Long id) {
File file = fileService.getById(id);
if (file != null && file.getIsDelete()) {
return success(null);
}
return success(file);
}
/**
* 获取文件分页
*/
@ApiOperation(value = "分页查询文件", notes = "获取文件分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "current", value = "当前页", dataType = "long", paramType = "query", defaultValue = "1"),
@ApiImplicitParam(name = "size", value = "每页显示几条", dataType = "long", paramType = "query", defaultValue = "10"),
})
@GetMapping(value = "/page")
public R<IPage<File>> page(FilePageReqDTO data) {
return success(fileRestManager.page(getPage(), data));
}
/**
* 上传文件
*/
@ApiOperation(value = "上传文件", notes = "上传文件 ")
@ApiResponses({
@ApiResponse(code = 60102, message = "文件夹为空"),
})
@ApiImplicitParams({
@ApiImplicitParam(name = "source", value = "文件来源", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "long", paramType = "query"),
@ApiImplicitParam(name = "folderId", value = "文件夹id", dataType = "long", paramType = "query"),
@ApiImplicitParam(name = "file", value = "附件", dataType = "MultipartFile", allowMultiple = true, required = true),
})
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public R<File> upload(
@NotNull(messag |