package com.oying.rest;
|
|
import com.oying.annotation.Log;
|
import com.oying.domain.BucketStorage;
|
import com.oying.exception.BadRequestException;
|
import com.oying.service.BucketStorageService;
|
import com.oying.domain.dto.BucketStorageQueryCriteria;
|
import com.oying.utils.FileUtil;
|
import lombok.RequiredArgsConstructor;
|
import java.util.List;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
import io.swagger.annotations.*;
|
import java.io.IOException;
|
import javax.servlet.http.HttpServletResponse;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.oying.utils.PageResult;
|
import org.springframework.web.multipart.MultipartFile;
|
|
/**
|
* @author lixin
|
* @date 2025-06-03
|
**/
|
@RestController
|
@RequiredArgsConstructor
|
@Api(tags = "存储桶")
|
@RequestMapping("/api/bucketStorage")
|
public class BucketStorageController {
|
|
private final BucketStorageService bucketStorageService;
|
|
@ApiOperation("导出数据")
|
@GetMapping(value = "/download")
|
@PreAuthorize("@el.check('bucketStorage:list')")
|
public void exportBucketStorage(HttpServletResponse response, BucketStorageQueryCriteria criteria) throws IOException {
|
bucketStorageService.download(bucketStorageService.queryAll(criteria), response);
|
}
|
|
@GetMapping
|
@ApiOperation("查询存储桶")
|
@PreAuthorize("@el.check('bucketStorage:list')")
|
public ResponseEntity<PageResult<BucketStorage>> queryBucketStorage(BucketStorageQueryCriteria criteria){
|
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
|
return new ResponseEntity<>(bucketStorageService.queryAll(criteria,page),HttpStatus.OK);
|
}
|
|
@PostMapping
|
@Log("上传存储桶文件")
|
@ApiOperation("上传存储桶文件")
|
@PreAuthorize("@el.check('bucketStorage:add')")
|
public ResponseEntity<Object> create(@RequestParam String name, @RequestParam("file") MultipartFile file) {
|
return new ResponseEntity<>(bucketStorageService.create(name, file), HttpStatus.CREATED);
|
}
|
|
@PostMapping("/pictures")
|
@ApiOperation("上传图片")
|
public ResponseEntity<Object> upload(@RequestParam MultipartFile file) {
|
// 判断文件是否为图片
|
String suffix = FileUtil.getExtensionName(file.getOriginalFilename());
|
FileUtil.checkSize(5, file.getSize());
|
if (!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))) {
|
throw new BadRequestException("只能上传图片");
|
}
|
BucketStorage bucketStorage = bucketStorageService.create(null, file);
|
return new ResponseEntity<>(bucketStorage, HttpStatus.OK);
|
}
|
|
@DeleteMapping
|
@Log("删除存储桶")
|
@ApiOperation("删除存储桶")
|
@PreAuthorize("@el.check('bucketStorage:del')")
|
public ResponseEntity<Object> deleteBucketStorage(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
|
bucketStorageService.deleteAll(ids);
|
return new ResponseEntity<>(HttpStatus.OK);
|
}
|
}
|