Crunchy
2025-06-14 b2f31607cbe26d721cd7514b619162b3e355b1aa
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
package com.wms_admin.server.controller;
 
 
import com.wms_admin.server.entity.ProductModel;
import com.wms_admin.server.service.ProductModelService;
import com.wms_admin.utils.Result;
import io.swagger.annotations.*;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-06-07
 */
@Api(tags = "添加库存型号")
@RestController
@RequestMapping("/product-model")
public class ProductModelController {
 
    @Autowired
    private ProductModelService service;
 
    @PostMapping("/add")
    @ApiOperation("库存型号添加接口")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "productCode",value = "型号编码", dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "productModel",value = "型号名称", dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "productNameId",value = "库存名称id", dataTypeClass = String.class,required = true)
    })
    public Result<?> AddProductModel(String productCode,
                                     String productModel,
                                     Integer productNameId){
        if (ObjectUtils.isEmpty(productCode)){
            return Result.fail("添加失败,请输入编码!");
        }
        if (ObjectUtils.isEmpty(productModel)){
            return Result.fail("添加失败,请输入型号!");
        }
        if (ObjectUtils.isEmpty(productNameId)){
            return Result.fail("添加失败,请选择名称!");
        }
        Integer integer = service.AddProductModel(productCode, productModel, productNameId);
        if (integer == 1){
            return Result.success("添加【"+ productModel +"】成功!");
        }
        return Result.fail("添加【"+ productModel +"】失败,可能已经存在!");
    }
 
 
    @GetMapping("/selectAll")
    @ApiOperation("查询库存名称ID查询对应型号")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "productNameId",value = "库存名称id", dataTypeClass = String.class,required = true),
    })
    public Result<?> SelectIdAllProductModel(Integer productNameId){
        List<ProductModel> productModels = service.SelectIdAllProductModel(productNameId);
        Map<String, Object> map = new HashMap<>();
        map.put("models", productModels);
        return Result.success(map);
    }
 
    @PostMapping("/update")
    @ApiOperation("根据型号的主键ID,更新对应型号")
    public Result<?> UpdateIdProductModel(ProductModel productModel){
        System.out.println(productModel);
        Integer integer = service.UpdateIdProductModel(productModel);
        if (integer == 1){
            return Result.success("更新【"+ productModel.getProductModel() +"】成功!");
        }
        return Result.fail("更新【"+ productModel.getProductModel() +"】失败,可能已经存在!");
    }
 
    @DeleteMapping("/delete")
    @ApiOperation("根据型号主键ID删除对应型号")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "productModel",value = "型号", dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "id",value = "型号主键ID", dataTypeClass = String.class,required = true)
    })
    public Result<?> DeleteIdProductModel(String productModel, String id){
        Integer integer = service.DeleteIdProductModel(id);
        if (integer == 1){
            return Result.success("删除【"+ productModel +"】成功!");
        }
        return Result.fail("删除【"+ productModel +"】失败");
    }
 
    @GetMapping("/selectId")
    @ApiOperation("新:根据模型Id查询对应信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "productModelId",value = "型号id", dataTypeClass = String.class,required = true),
    })
    public Result<?> selectIdProductModel(Integer productModelId){
        Map<String, Object> productModels = service.selectIdProductModel(productModelId);
        return Result.success(productModels);
    }
}