From 9a30a3a8d3862a9b2ce898535b7cb51c3ddac816 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 20 五月 2026 16:01:11 +0800
Subject: [PATCH] refactor(controller): 将控制器响应结果统一为R类型并继承BaseController
---
src/main/java/com/ruoyi/project/system/controller/SysPostController.java | 268 +++++++++++++++++++++++++++--------------------------
1 files changed, 135 insertions(+), 133 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/system/controller/SysPostController.java b/src/main/java/com/ruoyi/project/system/controller/SysPostController.java
index a4776c4..652ab30 100644
--- a/src/main/java/com/ruoyi/project/system/controller/SysPostController.java
+++ b/src/main/java/com/ruoyi/project/system/controller/SysPostController.java
@@ -1,133 +1,135 @@
-package com.ruoyi.project.system.controller;
-
-import java.util.List;
-import jakarta.servlet.http.HttpServletResponse;
-import lombok.AllArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-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.utils.poi.ExcelUtil;
-import com.ruoyi.framework.aspectj.lang.annotation.Log;
-import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.framework.web.controller.BaseController;
-import com.ruoyi.framework.web.domain.AjaxResult;
-import com.ruoyi.framework.web.page.TableDataInfo;
-import com.ruoyi.project.system.domain.SysPost;
-import com.ruoyi.project.system.service.ISysPostService;
-
-/**
- * 宀椾綅淇℃伅鎿嶄綔澶勭悊
- *
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/system/post")
-@AllArgsConstructor
-public class SysPostController extends BaseController
-{
- private ISysPostService postService;
-
- /**
- * 鑾峰彇宀椾綅鍒楄〃
- */
- @PreAuthorize("@ss.hasPermi('system:post:list')")
- @GetMapping("/list")
- public TableDataInfo list(SysPost post)
- {
- startPage();
- List<SysPost> list = postService.selectPostList(post);
- return getDataTable(list);
- }
- /**
- * 瀵煎嚭宀椾綅鍒楄〃
- */
-
- @Log(title = "宀椾綅绠$悊", businessType = BusinessType.EXPORT)
- @PreAuthorize("@ss.hasPermi('system:post:export')")
- @PostMapping("/export")
- public void export(HttpServletResponse response, SysPost post)
- {
- List<SysPost> list = postService.selectPostList(post);
- ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
- util.exportExcel(response, list, "宀椾綅鏁版嵁");
- }
-
- /**
- * 鏍规嵁宀椾綅缂栧彿鑾峰彇璇︾粏淇℃伅
- */
- @PreAuthorize("@ss.hasPermi('system:post:query')")
- @GetMapping(value = "/{postId}")
- public AjaxResult getInfo(@PathVariable Long postId)
- {
- return success(postService.selectPostById(postId));
- }
-
- /**
- * 鏂板宀椾綅
- */
- @PreAuthorize("@ss.hasPermi('system:post:add')")
- @Log(title = "宀椾綅绠$悊", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@Validated @RequestBody SysPost post)
- {
- if (!postService.checkPostNameUnique(post))
- {
- return error("鏂板宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶅悕绉板凡瀛樺湪");
- }
- else if (!postService.checkPostCodeUnique(post))
- {
- return error("鏂板宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶇紪鐮佸凡瀛樺湪");
- }
- post.setCreateBy(getUsername());
- return toAjax(postService.insertPost(post));
- }
-
- /**
- * 淇敼宀椾綅
- */
- @PreAuthorize("@ss.hasPermi('system:post:edit')")
- @Log(title = "宀椾綅绠$悊", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@Validated @RequestBody SysPost post)
- {
- if (!postService.checkPostNameUnique(post))
- {
- return error("淇敼宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶅悕绉板凡瀛樺湪");
- }
- else if (!postService.checkPostCodeUnique(post))
- {
- return error("淇敼宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶇紪鐮佸凡瀛樺湪");
- }
- post.setUpdateBy(getUsername());
- return toAjax(postService.updatePost(post));
- }
-
- /**
- * 鍒犻櫎宀椾綅
- */
- @PreAuthorize("@ss.hasPermi('system:post:remove')")
- @Log(title = "宀椾綅绠$悊", businessType = BusinessType.DELETE)
- @DeleteMapping("/{postIds}")
- public AjaxResult remove(@PathVariable Long[] postIds)
- {
- return toAjax(postService.deletePostByIds(postIds));
- }
-
- /**
- * 鑾峰彇宀椾綅閫夋嫨妗嗗垪琛�
- */
- @GetMapping("/optionselect")
- public AjaxResult optionselect()
- {
- List<SysPost> posts = postService.selectPostAll();
- return success(posts);
- }
-}
+package com.ruoyi.project.system.controller;
+
+import java.util.List;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.AllArgsConstructor;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+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.utils.poi.ExcelUtil;
+import com.ruoyi.framework.aspectj.lang.annotation.Log;
+import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
+import com.ruoyi.framework.web.controller.BaseController;
+import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.framework.web.page.TableDataInfo;
+import com.ruoyi.project.system.domain.SysPost;
+import com.ruoyi.project.system.service.ISysPostService;
+
+/**
+ * 宀椾綅淇℃伅鎿嶄綔澶勭悊
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/system/post")
+@AllArgsConstructor
+public class SysPostController extends BaseController
+{
+ private ISysPostService postService;
+
+ /**
+ * 鑾峰彇宀椾綅鍒楄〃
+ */
+ @PreAuthorize("@ss.hasPermi('system:post:list')")
+ @GetMapping("/list")
+ public TableDataInfo list(SysPost post)
+ {
+ startPage();
+ List<SysPost> list = postService.selectPostList(post);
+ return getDataTable(list);
+ }
+ /**
+ * 瀵煎嚭宀椾綅鍒楄〃
+ */
+
+ @Log(title = "宀椾綅绠$悊", businessType = BusinessType.EXPORT)
+ @PreAuthorize("@ss.hasPermi('system:post:export')")
+ @PostMapping("/export")
+ public void export(HttpServletResponse response, SysPost post)
+ {
+ List<SysPost> list = postService.selectPostList(post);
+ ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
+ util.exportExcel(response, list, "宀椾綅鏁版嵁");
+ }
+
+ /**
+ * 鏍规嵁宀椾綅缂栧彿鑾峰彇璇︾粏淇℃伅
+ */
+ @PreAuthorize("@ss.hasPermi('system:post:query')")
+ @GetMapping(value = "/{postId}")
+ public R<?> getInfo(@PathVariable Long postId)
+ {
+ return R.ok(postService.selectPostById(postId));
+ }
+
+ /**
+ * 鏂板宀椾綅
+ */
+ @PreAuthorize("@ss.hasPermi('system:post:add')")
+ @Log(title = "宀椾綅绠$悊", businessType = BusinessType.INSERT)
+ @PostMapping
+ public R<?> add(@Validated @RequestBody SysPost post)
+ {
+ if (!postService.checkPostNameUnique(post))
+ {
+ return R.fail("鏂板宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶅悕绉板凡瀛樺湪");
+ }
+ else if (!postService.checkPostCodeUnique(post))
+ {
+ return R.fail("鏂板宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶇紪鐮佸凡瀛樺湪");
+ }
+ post.setCreateBy(getUsername());
+ postService.insertPost(post);
+ return R.ok();
+ }
+
+ /**
+ * 淇敼宀椾綅
+ */
+ @PreAuthorize("@ss.hasPermi('system:post:edit')")
+ @Log(title = "宀椾綅绠$悊", businessType = BusinessType.UPDATE)
+ @PutMapping
+ public R<?> edit(@Validated @RequestBody SysPost post)
+ {
+ if (!postService.checkPostNameUnique(post))
+ {
+ return R.fail("淇敼宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶅悕绉板凡瀛樺湪");
+ }
+ else if (!postService.checkPostCodeUnique(post))
+ {
+ return R.fail("淇敼宀椾綅'" + post.getPostName() + "'澶辫触锛屽矖浣嶇紪鐮佸凡瀛樺湪");
+ }
+ post.setUpdateBy(getUsername());
+ postService.updatePost(post);
+ return R.ok();
+ }
+
+ /**
+ * 鍒犻櫎宀椾綅
+ */
+ @PreAuthorize("@ss.hasPermi('system:post:remove')")
+ @Log(title = "宀椾綅绠$悊", businessType = BusinessType.DELETE)
+ @DeleteMapping("/{postIds}")
+ public R<?> remove(@PathVariable Long[] postIds)
+ {
+ postService.deletePostByIds(postIds);
+ return R.ok();
+ }
+
+ /**
+ * 鑾峰彇宀椾綅閫夋嫨妗嗗垪琛�
+ */
+ @GetMapping("/optionselect")
+ public R<?> optionselect()
+ {
+ List<SysPost> posts = postService.selectPostAll();
+ return R.ok(posts);
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3