luqingyang
2023-11-01 85ad0a996a588d87f4ff589ae9a83b714d8b2c7f
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.consum.base.controller;
 
import com.consum.base.BaseController;
import com.consum.base.pojo.BaseGoodsTemplateParam;
import com.consum.base.service.BaseGoodsTemplateServiceImpl;
import com.consum.model.po.BaseGoodsModels;
import com.consum.model.po.BaseGoodsTemplate;
import com.consum.model.po.S_dict_data;
import com.consum.model.vo.BaseGoodsTemplateVo;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * @Description 物品模板
 * @Author 卢庆阳
 * @Date 2023/10/24
 */
@RestController
@RequestMapping("/pc/base/goods/template")
public class BaseGoodsTemplateController extends BaseController {
 
    @Autowired
    private BaseGoodsTemplateServiceImpl baseGoodsTemplateService;
 
    /**
     * @Description 新增物品模板
     * @Author 卢庆阳
     * @Date 2023/10/24
     */
    @PostMapping("/add")
    public ResponseValue add(@RequestBody BaseGoodsTemplateParam param) {
        if (param.getCategoryId() == null) {
            return ResponseValue.error("分类为空");
        }
        if (StringUtils.isEmpty(param.getGoodsName())) {
            return ResponseValue.error("物品名称为空");
        }
        //判断同一分类下的物品名称是否重复
        BaseGoodsTemplate goodsTemplate = this.baseGoodsTemplateService.getByGoodsNameAndCategoryId(param.getGoodsName(), param.getCategoryId());
        if (goodsTemplate != null) {
            return ResponseValue.error("物品名称已存在");
        }
 
        int result = this.baseGoodsTemplateService.add(param, this.getCurrentUser());
        if (result > 0) return ResponseValue.success(1);
        return ResponseValue.error("新增失败!");
    }
 
    /**
     * @Description 物品模板列表查询
     * @Author 卢庆阳
     * @Date 2023/10/24
     */
    @GetMapping("/list")
    public ResponseValue queryList(BaseGoodsTemplateParam param) {
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<BaseGoodsTemplate> pager = this.baseGoodsTemplateService.queryList(param);
        return ResponseValue.success(pager);
    }
 
    /**
     * 根据物品id查询物品详情
     * @author 卢庆阳
     * @date 2023/9/26
     */
    @GetMapping("/detail")
    public ResponseValue getById(Long id) {
        if (id == null) {
            return ResponseValue.error("物品id为空");
        }
        BaseGoodsTemplateVo vo = this.baseGoodsTemplateService.getById(id);
        if (vo == null) return ResponseValue.error("查询失败!");
        return ResponseValue.success("查询成功!", vo);
    }
 
    /**
     * @Description 编辑
     * @Author 卢庆阳
     * @Date 2023/10/24
     */
    @PostMapping("/edit")
    public ResponseValue edit(@RequestBody BaseGoodsTemplateParam param) {
        if (StringUtils.isEmpty(param.getGoodsName())) {
            return ResponseValue.error("物品名称为空");
        }
        List<BaseGoodsModels> models = param.getModels();
        if (CollectionUtils.isEmpty(models)) {
            return ResponseValue.error("物品型号为空");
        }
 
        int num = this.baseGoodsTemplateService.updateBaseGoodsTemplate(param);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("编辑失败!");
    }
 
    /**
     * 修改状态
     * @author 卢庆阳
     * @date 2023/10/25
     */
    //TODO 物品的禁用或删除,不影响已经采购入过库的物品信息。
    @PostMapping("/updStatus")
    public ResponseValue updateStatus(@RequestBody BaseGoodsTemplate goodsTemplate) {
        if (goodsTemplate == null || goodsTemplate.getId() == null || goodsTemplate.getStates() == null) {
            return ResponseValue.error("参数错误");
        }
 
        int num = this.baseGoodsTemplateService.updateStatus(goodsTemplate);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("修改失败!");
    }
 
    /**
     * @Description 根据物品id删除物品
     * @Author 卢庆阳
     * @Date 2023/10/25
     */
    //TODO 物品的禁用或删除,不影响已经采购入过库的物品信息。
    @DeleteMapping("/del")
    public ResponseValue updateById(@RequestBody BaseGoodsTemplate goodsTemplate) {
        if (goodsTemplate.getId() == null) {
            return ResponseValue.error("物品id为空");
        }
        int num = this.baseGoodsTemplateService.updateById(goodsTemplate,this.getCurrentUser());
 
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("删除失败!");
    }
 
    /**
     * @Description  查询仓库类型(数据字典)
     * @Author 卢庆阳
     * @Date 2023/10/30
     */
    @GetMapping("/select/classificationCode")
    public ResponseValue queryClassificationCode() {
        List<S_dict_data> list = this.baseGoodsTemplateService.queryClassificationCode();
        return ResponseValue.success(list);
    }
 
    /**
     * @Description  根据分类id查询物品模板
     * @Author 卢庆阳
     * @Date 2023/10/30
     */
    @GetMapping("/selectByCategoryId")
    public ResponseValue queryByCategoryId(Long categoryId) {
        List<BaseGoodsTemplate> list = this.baseGoodsTemplateService.queryByCategoryId(categoryId);
        return ResponseValue.success(list);
    }
 
 
 
 
 
}