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/basic/controller/ProductController.java | 46 +++++++++++++++++++++++-----------------------
1 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/main/java/com/ruoyi/basic/controller/ProductController.java b/src/main/java/com/ruoyi/basic/controller/ProductController.java
index 65a5301..5109662 100644
--- a/src/main/java/com/ruoyi/basic/controller/ProductController.java
+++ b/src/main/java/com/ruoyi/basic/controller/ProductController.java
@@ -10,18 +10,16 @@
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.service.IProductModelService;
import com.ruoyi.basic.service.IProductService;
+import com.ruoyi.basic.vo.ProductModelVo;
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.domain.R;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
-import com.ruoyi.sales.service.ISalesLedgerService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -34,9 +32,7 @@
public class ProductController extends BaseController {
private IProductService productService;
-
private IProductModelService productModelService;
- @Autowired
private ISalesLedgerProductService salesLedgerProductService;
/**
* 鏌ヨ浜у搧
@@ -59,8 +55,9 @@
*/
@Log(title = "浜у搧", businessType = BusinessType.INSERT)
@PostMapping("/addOrEditProduct")
- public AjaxResult addOrEditProduct(@RequestBody ProductDto productDto) {
- return toAjax(productService.addOrEditProduct(productDto));
+ public R<?> addOrEditProduct(@RequestBody ProductDto productDto) {
+ productService.addOrEditProduct(productDto);
+ return R.ok();
}
/**
@@ -68,8 +65,9 @@
*/
@Log(title = "浜у搧瑙勬牸鍨嬪彿", businessType = BusinessType.INSERT)
@PostMapping("/addOrEditProductModel")
- public AjaxResult addOrEditProductModel(@RequestBody ProductModelDto productModelDto) {
- return toAjax(productModelService.addOrEditProductModel(productModelDto));
+ public R<?> addOrEditProductModel(@RequestBody ProductModelDto productModelDto) {
+ productModelService.addOrEditProductModel(productModelDto);
+ return R.ok();
}
/**
@@ -77,18 +75,19 @@
*/
@Log(title = "浜у搧", businessType = BusinessType.DELETE)
@DeleteMapping("/delProduct")
- public AjaxResult remove(@RequestBody Long[] ids) {
+ public R<?> remove(@RequestBody Long[] ids) {
if (ids == null || ids.length == 0) {
- return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
+ return R.fail("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
}
// 妫�鏌ユ槸鍚︽湁閿�鍞晢鍝佽褰曞叧鑱旇浜у搧
LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SalesLedgerProduct::getProductId, ids);
List<SalesLedgerProduct> salesLedgerProductList = salesLedgerProductService.list(queryWrapper);
if (salesLedgerProductList.size() > 0) {
- return AjaxResult.error("璇ヤ骇鍝佸瓨鍦ㄩ攢鍞�/閲囪喘璁板綍锛屼笉鑳藉垹闄�");
+ return R.fail("璇ヤ骇鍝佸瓨鍦ㄩ攢鍞�/閲囪喘璁板綍锛屼笉鑳藉垹闄�");
}
- return toAjax(productService.delProductByIds(ids));
+ productService.delProductByIds(ids);
+ return R.ok();
}
/**
@@ -96,18 +95,19 @@
*/
@Log(title = "浜у搧瑙勬牸鍨嬪彿", businessType = BusinessType.DELETE)
@DeleteMapping("/delProductModel")
- public AjaxResult delProductModel(@RequestBody Long[] ids) {
+ public R<?> delProductModel(@RequestBody Long[] ids) {
if (ids == null || ids.length == 0) {
- return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
+ return R.fail("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
}
// 妫�鏌ユ槸鍚︽湁閿�鍞晢鍝佽褰曞叧鑱旇浜у搧瑙勬牸鍨嬪彿
LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SalesLedgerProduct::getProductModelId, ids);
List<SalesLedgerProduct> salesLedgerProductList = salesLedgerProductService.list(queryWrapper);
if (salesLedgerProductList.size() > 0) {
- return AjaxResult.error("璇ヤ骇鍝佽鏍煎瀷鍙峰瓨鍦ㄩ攢鍞�/閲囪喘璁板綍锛屼笉鑳藉垹闄�");
+ return R.fail("璇ヤ骇鍝佽鏍煎瀷鍙峰瓨鍦ㄩ攢鍞�/閲囪喘璁板綍锛屼笉鑳藉垹闄�");
}
- return toAjax(productModelService.delProductModel(ids));
+ productModelService.delProductModel(ids);
+ return R.ok();
}
/**
@@ -118,9 +118,9 @@
return productModelService.modelListPage(page, productDto);
}
- @ApiOperation("鍒嗛〉鏌ヨ鎵�鏈変骇鍝佸瀷鍙�")
+ @Operation(summary = "鍒嗛〉鏌ヨ鎵�鏈変骇鍝佸瀷鍙�")
@GetMapping("/pageModel")
- public IPage<ProductModel> listPageProductModel(Page<ProductModel> page, ProductModel productModel) {
+ public IPage<ProductModelVo> listPageProductModel(Page<ProductModelVo> page, ProductModel productModel) {
return productService.listPageProductModel(page, productModel);
}
@@ -129,7 +129,7 @@
*/
@PostMapping("/import")
@Log(title = "瀵煎叆浜у搧", businessType = BusinessType.IMPORT)
- public AjaxResult importProductModel(@RequestParam("file") MultipartFile file, Integer productId) {
+ public R<?> importProductModel(@RequestParam("file") MultipartFile file, Integer productId) {
return productModelService.importProductModel(file, productId);
}
@@ -137,7 +137,7 @@
* 浜у搧瀵煎叆妯℃澘
*/
@GetMapping("/export")
- @ApiOperation("浜у搧瀵煎叆妯℃澘")
+ @Operation(summary = "浜у搧瀵煎叆妯℃澘")
@Log(title = "浜у搧瀵煎叆妯℃澘", businessType = BusinessType.EXPORT)
public void importProduct(HttpServletResponse response) {
ExcelUtil<ProductModelExportDto> excelUtil = new ExcelUtil<>(ProductModelExportDto.class);
--
Gitblit v1.9.3