TPersonalImgController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package com.ruoyi.web.controller.system;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import java.util.List;
  4. import java.util.Arrays;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.ruoyi.common.config.RuoYiConfig;
  7. import com.ruoyi.common.utils.StringUtils;
  8. import com.ruoyi.common.utils.file.FileUploadUtils;
  9. import com.ruoyi.framework.config.ServerConfig;
  10. import io.swagger.annotations.ApiOperation;
  11. import lombok.RequiredArgsConstructor;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.PutMapping;
  17. import org.springframework.web.bind.annotation.DeleteMapping;
  18. import org.springframework.web.bind.annotation.PathVariable;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21. import org.springframework.web.bind.annotation.RestController;
  22. import com.ruoyi.common.annotation.Log;
  23. import com.ruoyi.common.core.controller.BaseController;
  24. import com.ruoyi.common.core.domain.AjaxResult;
  25. import com.ruoyi.common.enums.BusinessType;
  26. import com.ruoyi.system.domain.TPersonalImg;
  27. import com.ruoyi.system.service.ITPersonalImgService;
  28. import com.ruoyi.common.utils.poi.ExcelUtil;
  29. import com.ruoyi.common.core.page.TableDataInfo;
  30. import org.springframework.web.multipart.MultipartFile;
  31. /**
  32. * 个人页 图片Controller
  33. *
  34. * @author Alex
  35. * @date 2020-09-16
  36. */
  37. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  38. @RestController
  39. @RequestMapping("/system/personalImg" )
  40. public class TPersonalImgController extends BaseController {
  41. private final ITPersonalImgService iTPersonalImgService;
  42. @Autowired
  43. private ServerConfig serverConfig;
  44. /**
  45. * 查询个人页 图片列表
  46. */
  47. @PreAuthorize("@ss.hasPermi('system:img:list')")
  48. @GetMapping("/list")
  49. public TableDataInfo list(TPersonalImg tPersonalImg)
  50. {
  51. startPage();
  52. LambdaQueryWrapper<TPersonalImg> lqw = new LambdaQueryWrapper<TPersonalImg>();
  53. if (tPersonalImg.getPersonalId() != null){
  54. lqw.eq(TPersonalImg::getPersonalId ,tPersonalImg.getPersonalId());
  55. }
  56. if (StringUtils.isNotBlank(tPersonalImg.getUrl())){
  57. lqw.eq(TPersonalImg::getUrl ,tPersonalImg.getUrl());
  58. }
  59. if (StringUtils.isNotBlank(tPersonalImg.getEnable())){
  60. lqw.eq(TPersonalImg::getEnable ,tPersonalImg.getEnable());
  61. }
  62. List<TPersonalImg> list = iTPersonalImgService.list(lqw);
  63. return getDataTable(list);
  64. }
  65. /**
  66. * 查询个人页 图片列表
  67. */
  68. @ApiOperation("个人图片列表")
  69. @GetMapping("/all")
  70. public AjaxResult all(TPersonalImg tPersonalImg)
  71. {
  72. List<TPersonalImg> list = iTPersonalImgService.list(new QueryWrapper<TPersonalImg>()
  73. .eq(StringUtils.isNotBlank(tPersonalImg.getEnable()),"enable", tPersonalImg.getEnable())
  74. );
  75. return AjaxResult.success(list);
  76. }
  77. /**
  78. * 导出个人页 图片列表
  79. */
  80. @PreAuthorize("@ss.hasPermi('system:img:export')" )
  81. @Log(title = "个人页 图片" , businessType = BusinessType.EXPORT)
  82. @GetMapping("/export" )
  83. public AjaxResult export(TPersonalImg tPersonalImg) {
  84. LambdaQueryWrapper<TPersonalImg> lqw = new LambdaQueryWrapper<TPersonalImg>(tPersonalImg);
  85. List<TPersonalImg> list = iTPersonalImgService.list(lqw);
  86. ExcelUtil<TPersonalImg> util = new ExcelUtil<TPersonalImg>(TPersonalImg. class);
  87. return util.exportExcel(list, "img" );
  88. }
  89. /**
  90. * 获取个人页 图片详细信息
  91. */
  92. @PreAuthorize("@ss.hasPermi('system:img:query')" )
  93. @GetMapping(value = "/{id}" )
  94. public AjaxResult getInfo(@PathVariable("id" ) Long id) {
  95. return AjaxResult.success(iTPersonalImgService.getById(id));
  96. }
  97. /**
  98. * 新增个人页 图片
  99. */
  100. @PreAuthorize("@ss.hasPermi('system:img:add')" )
  101. @Log(title = "个人页 图片" , businessType = BusinessType.INSERT)
  102. @PostMapping
  103. public AjaxResult add(@RequestBody TPersonalImg tPersonalImg) {
  104. return toAjax(iTPersonalImgService.save(tPersonalImg) ? 1 : 0);
  105. }
  106. /**
  107. * 修改个人页 图片
  108. */
  109. @PreAuthorize("@ss.hasPermi('system:img:edit')" )
  110. @Log(title = "个人页 图片" , businessType = BusinessType.UPDATE)
  111. @PutMapping
  112. public AjaxResult edit(@RequestBody TPersonalImg tPersonalImg) {
  113. return toAjax(iTPersonalImgService.updateById(tPersonalImg) ? 1 : 0);
  114. }
  115. /**
  116. * 删除个人页 图片
  117. */
  118. @PreAuthorize("@ss.hasPermi('system:img:remove')" )
  119. @Log(title = "个人页 图片" , businessType = BusinessType.DELETE)
  120. @DeleteMapping("/{ids}" )
  121. public AjaxResult remove(@PathVariable Long[] ids) {
  122. return toAjax(iTPersonalImgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
  123. }
  124. @PostMapping("/upload")
  125. public AjaxResult uploadFile(MultipartFile file, String personalId) throws Exception {
  126. try {
  127. // 上传文件路径
  128. String filePath = RuoYiConfig.getProfile() + "/personal";
  129. // 上传并返回新文件名称
  130. String fileName = FileUploadUtils.upload(filePath, file);
  131. String url = serverConfig.getUrl() + fileName;
  132. AjaxResult ajax = AjaxResult.success();
  133. ajax.put("fileName", fileName);
  134. ajax.put("url", url);
  135. TPersonalImg item = new TPersonalImg();
  136. item.setPersonalId(Long.parseLong(personalId));
  137. item.setEnable("0");
  138. item.setUrl(fileName);
  139. iTPersonalImgService.save(item);
  140. return ajax;
  141. } catch (Exception e) {
  142. return AjaxResult.error(e.getMessage());
  143. }
  144. }
  145. }