huminmin
6 天以前 d06ef3f44d6dc19dae223ab420165369ea13cc16
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.v3.oas.annotations.tags.Tag;
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;
@@ -57,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();
    }
    /**
@@ -66,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();
    }
    /**
@@ -75,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("请传入要删除的ID");
            return R.fail("请传入要删除的ID");
        }
        // 检查是否有销售商品记录关联该产品
        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();
    }
    /**
@@ -94,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("请传入要删除的ID");
            return R.fail("请传入要删除的ID");
        }
        // 检查是否有销售商品记录关联该产品规格型号
        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,7 +120,7 @@
    @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);
    }
@@ -127,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);
    }