maven
10 小时以前 d9ff3817f056ad245a16bd394133a407d6c6b9cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.ruoyi.basic.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.basic.dto.ProductDto;
import com.ruoyi.basic.dto.ProductModelDto;
import com.ruoyi.basic.dto.ProductTreeDto;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.service.IProductModelService;
import com.ruoyi.basic.service.IProductService;
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.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 lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.util.List;
 
@RestController
@AllArgsConstructor
@RequestMapping("/basic/product")
public class ProductController extends BaseController {
 
    private IProductService productService;
 
    private IProductModelService productModelService;
    @Autowired
    private ISalesLedgerProductService salesLedgerProductService;
    /**
     * 查询产品
     */
    @GetMapping("/list")
    public List<ProductTreeDto> selectProductList(ProductDto productDto) {
        return productService.selectProductList(productDto);
    }
 
    /**
     * 根据id查询产品规格
     */
    @GetMapping("/modelList")
    public List<ProductModel> selectModelList(ProductDto productDto) {
        return productModelService.selectModelList(productDto);
    }
 
    /**
     * 新增更新产品
     */
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping("/addOrEditProduct")
    public AjaxResult addOrEditProduct(@RequestBody ProductDto productDto) {
        return toAjax(productService.addOrEditProduct(productDto));
    }
 
    /**
     * 新增更新产品规格型号
     */
    @Log(title = "产品规格型号", businessType = BusinessType.INSERT)
    @PostMapping("/addOrEditProductModel")
    public AjaxResult addOrEditProductModel(@RequestBody ProductModelDto productModelDto) {
        return toAjax(productModelService.addOrEditProductModel(productModelDto));
    }
 
    /**
     * 删除
     */
    @Log(title = "产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/delProduct")
    public AjaxResult remove(@RequestBody Long[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请传入要删除的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 toAjax(productService.delProductByIds(ids));
    }
 
    /**
     * 删除产品规格型号
     */
    @Log(title = "产品规格型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/delProductModel")
    public AjaxResult delProductModel(@RequestBody Long[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请传入要删除的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 toAjax(productModelService.delProductModel(ids));
    }
 
    /**
     * 根据id查询产品规格分页查询
     */
    @GetMapping("/modelListPage")
    public IPage<ProductModel> selectModelListPage(Page page, ProductDto productDto) {
        return productModelService.modelListPage(page, productDto);
    }
 
    @ApiOperation("分页查询所有产品型号")
    @GetMapping("/pageModel")
    public IPage<ProductModel> listPageProductModel(Page<ProductModel> page, ProductModel productModel) {
        return productService.listPageProductModel(page, productModel);
    }
 
    /**
     * 导入产品
     */
    @Log(title = "导入产品",businessType = BusinessType.IMPORT)
    @PostMapping("import")
    public AjaxResult importProduct(MultipartFile file) {
        return AjaxResult.success(productModelService.importProduct(file));
    }
}