Alex пре 4 година
родитељ
комит
d07147fdac

+ 148 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TPersonalImgController.java

@@ -0,0 +1,148 @@
+package com.ruoyi.web.controller.system;
+
+import java.util.List;
+
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.framework.config.ServerConfig;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.system.domain.TPersonalImg;
+import com.ruoyi.system.service.ITPersonalImgService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 个人页 图片Controller
+ * 
+ * @author ruoyi
+ * @date 2020-09-03
+ */
+@Api(value = "个人图片", tags = "个人图片")
+@RestController
+@RequestMapping("/system/personalImg")
+public class TPersonalImgController extends BaseController
+{
+    @Autowired
+    private ITPersonalImgService tPersonalImgService;
+
+    /**
+     * 查询个人页 图片列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:list')")
+    @ApiOperation("个人图片分页")
+    @GetMapping("/list")
+    public TableDataInfo list(TPersonalImg tPersonalImg)
+    {
+        startPage();
+        List<TPersonalImg> list = tPersonalImgService.selectTPersonalImgList(tPersonalImg);
+        return getDataTable(list);
+    }
+    /**
+     * 查询个人页 图片列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:list')")
+    @ApiOperation("个人图片列表")
+    @GetMapping("/all")
+    public AjaxResult all(TPersonalImg tPersonalImg)
+    {
+        List<TPersonalImg> list = tPersonalImgService.selectTPersonalImgList(tPersonalImg);
+        return AjaxResult.success(list);
+    }
+
+    /**
+     * 导出个人页 图片列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:export')")
+    @ApiOperation("个人图片列表导出")
+    @GetMapping("/export")
+    public AjaxResult export(TPersonalImg tPersonalImg)
+    {
+        List<TPersonalImg> list = tPersonalImgService.selectTPersonalImgList(tPersonalImg);
+        ExcelUtil<TPersonalImg> util = new ExcelUtil<TPersonalImg>(TPersonalImg.class);
+        return util.exportExcel(list, "img");
+    }
+
+    /**
+     * 获取个人页 图片详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:query')")
+    @ApiOperation("个人图片详细信息")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return AjaxResult.success(tPersonalImgService.selectTPersonalImgById(id));
+    }
+
+    /**
+     * 新增个人页 图片
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:add')")
+    @ApiOperation("添加个人图片")
+    @PostMapping
+    public AjaxResult add(@RequestBody TPersonalImg tPersonalImg)
+    {
+        return toAjax(tPersonalImgService.insertTPersonalImg(tPersonalImg));
+    }
+
+    /**
+     * 修改个人页 图片
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:edit')")
+    @Log(title = "个人页 图片", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody TPersonalImg tPersonalImg)
+    {
+        return toAjax(tPersonalImgService.updateTPersonalImg(tPersonalImg));
+    }
+
+    /**
+     * 删除个人页 图片
+     */
+    @PreAuthorize("@ss.hasPermi('system:img:remove')")
+    @Log(title = "个人页 图片", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids)
+    {
+        return toAjax(tPersonalImgService.deleteTPersonalImgByIds(ids));
+    }
+
+    @Autowired
+    private ServerConfig serverConfig;
+    @PostMapping("/upload")
+    public AjaxResult uploadFile(MultipartFile file, TPersonalImg item) throws Exception {
+        try {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getProfile() + "/personal";
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("fileName", fileName);
+            ajax.put("url", url);
+
+            item.setEnable("0");
+            item.setUrl(fileName);
+            tPersonalImgService.insertTPersonalImg(item);
+
+            return ajax;
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+}