2ddc8ebdfc4dc8cba7ed6e7aa9393f2f537e74ba.svn-base 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package org.jeecg.modules.oss.controller;
  2. import javax.servlet.http.HttpServletRequest;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.apache.shiro.authz.annotation.RequiresRoles;
  8. import org.jeecg.common.api.vo.Result;
  9. import org.jeecg.common.system.query.QueryGenerator;
  10. import org.jeecg.modules.oss.entity.OSSFile;
  11. import org.jeecg.modules.oss.service.IOSSFileService;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.web.bind.annotation.PostMapping;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.ResponseBody;
  20. import org.springframework.web.multipart.MultipartFile;
  21. @Slf4j
  22. @Controller
  23. @RequestMapping("/sys/oss/file")
  24. public class OSSFileController {
  25. @Autowired
  26. private IOSSFileService ossFileService;
  27. @ResponseBody
  28. @GetMapping("/list")
  29. public Result<IPage<OSSFile>> queryPageList(OSSFile file,
  30. @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
  31. @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
  32. Result<IPage<OSSFile>> result = new Result<>();
  33. QueryWrapper<OSSFile> queryWrapper = QueryGenerator.initQueryWrapper(file, req.getParameterMap());
  34. Page<OSSFile> page = new Page<>(pageNo, pageSize);
  35. IPage<OSSFile> pageList = ossFileService.page(page, queryWrapper);
  36. result.setSuccess(true);
  37. result.setResult(pageList);
  38. return result;
  39. }
  40. @ResponseBody
  41. @PostMapping("/upload")
  42. //@RequiresRoles("admin")
  43. public Result upload(@RequestParam("file") MultipartFile multipartFile) {
  44. Result result = new Result();
  45. try {
  46. ossFileService.upload(multipartFile);
  47. result.success("上传成功!");
  48. }
  49. catch (Exception ex) {
  50. log.info(ex.getMessage(), ex);
  51. result.error500("上传失败");
  52. }
  53. return result;
  54. }
  55. @ResponseBody
  56. @PostMapping("/delete")
  57. public Result delete(@RequestParam(name = "id") String id) {
  58. Result result = new Result();
  59. OSSFile file = ossFileService.getById(id);
  60. if (file == null) {
  61. result.error500("未找到对应实体");
  62. }
  63. else {
  64. boolean ok = ossFileService.delete(file);
  65. if (ok) {
  66. result.success("删除成功!");
  67. }
  68. }
  69. return result;
  70. }
  71. /**
  72. * 通过id查询.
  73. */
  74. @ResponseBody
  75. @GetMapping("/queryById")
  76. public Result<OSSFile> queryById(@RequestParam(name = "id") String id) {
  77. Result<OSSFile> result = new Result<>();
  78. OSSFile file = ossFileService.getById(id);
  79. if (file == null) {
  80. result.error500("未找到对应实体");
  81. }
  82. else {
  83. result.setResult(file);
  84. result.setSuccess(true);
  85. }
  86. return result;
  87. }
  88. }