| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.oying.service.LocalStorageService; |
| | | import com.oying.utils.R; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.oying.annotation.Log; |
| | | import com.oying.domain.LocalStorage; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import io.swagger.annotations.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | |
| | |
| | | @GetMapping |
| | | @ApiOperation("查询文件") |
| | | @PreAuthorize("@el.check('storage:list')") |
| | | public ResponseEntity<PageResult<LocalStorage>> queryFile(LocalStorageQueryCriteria criteria){ |
| | | public ResponseEntity<Object> queryFile(LocalStorageQueryCriteria criteria) { |
| | | Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize()); |
| | | return new ResponseEntity<>(localStorageService.queryAll(criteria,page),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(localStorageService.queryAll(criteria, page)), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("导出数据") |
| | |
| | | @PreAuthorize("@el.check('storage:add')") |
| | | public ResponseEntity<Object> createFile(@RequestParam String name, @RequestParam("file") MultipartFile file){ |
| | | localStorageService.create(name, file); |
| | | return new ResponseEntity<>(HttpStatus.CREATED); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.CREATED); |
| | | } |
| | | |
| | | @ApiOperation("上传图片") |
| | | @PostMapping("/pictures") |
| | | public ResponseEntity<LocalStorage> uploadPicture(@RequestParam MultipartFile file){ |
| | | public ResponseEntity<Object> uploadPicture(@RequestParam MultipartFile file) { |
| | | // 判断文件是否为图片 |
| | | String suffix = FileUtil.getExtensionName(file.getOriginalFilename()); |
| | | if(!FileUtil.IMAGE.equals(FileUtil.getFileType(suffix))){ |
| | | throw new BadRequestException("只能上传图片"); |
| | | } |
| | | LocalStorage localStorage = localStorageService.create(null, file); |
| | | return new ResponseEntity<>(localStorage, HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(localStorage), HttpStatus.OK); |
| | | } |
| | | |
| | | @PutMapping |
| | |
| | | @PreAuthorize("@el.check('storage:edit')") |
| | | public ResponseEntity<Object> updateFile(@Validated @RequestBody LocalStorage resources){ |
| | | localStorageService.update(resources); |
| | | return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT); |
| | | } |
| | | |
| | | @Log("删除文件") |
| | |
| | | @ApiOperation("多选删除") |
| | | public ResponseEntity<Object> deleteFile(@RequestBody Long[] ids) { |
| | | localStorageService.deleteAll(ids); |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | } |