futian.liu
2023-12-22 fd95223d9703b9c038ed3c782474c885052dda08
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.consum.base.controller;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.pojo.BaseCategoryParam;
import com.consum.base.pojo.ProjectTreeResult;
import com.consum.base.service.BaseCategoryService;
import com.consum.base.service.BaseGoodsTemplateService;
import com.consum.model.po.BaseCategory;
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 io.swagger.annotations.Api;
 
/**
 * @Description 物品分类
 * @Author 卢庆阳
 * @Date 2023/10/23
 */
@Api(value = "物品分类", tags = "物品分类")
@RestController
@RequestMapping("/pc/base/category")
public class BaseCategoryController extends BaseController {
 
    @Autowired
    private BaseCategoryService baseCategoryService;
 
    @Autowired
    private BaseGoodsTemplateService baseGoodsTemplateService;
 
    /**
     * @Description 获取分类树
     * @Author 卢庆阳
     * @Date 2023/10/30
     */
    @GetMapping("/select/tree")
    public ResponseValue trees() {
        List<ProjectTreeResult> tree = this.baseCategoryService.tree();
        return ResponseValue.success(tree);
    }
 
    /**
     * @Description 新增分类
     * @Author 卢庆阳
     * @Date 2023/10/23
     */
    @PostMapping("/add")
    public ResponseValue add() {
        BaseCategoryParam param = CommonUtil.getObjFromReqBody(BaseCategoryParam.class);
        BaseCategoryParam param2 = new BaseCategoryParam();
        CommonUtil.copyProperties(param, param2);
        param = param2;
        if (StringUtils.isEmpty(param.getCategoryName())) {
            return ResponseValue.error("分类名称为空");
        }
        if (param.getOrderNumber() == null) {
            return ResponseValue.error("顺序号为空");
        }
        // 判断同一父类id下分类名称是否重复
        BaseCategory category = this.baseCategoryService.getByCategoryNameAndFatherCategoryId(param.getCategoryName(),
            param.getFatherCategoryId());
        if (category != null) {
            return ResponseValue.error("分类名称已存在");
        }
 
        int result = this.baseCategoryService.add(param, this.getCurrentUser());
        if (result > 0) {
            return ResponseValue.success(1);
        }
        return ResponseValue.error("新增失败!");
    }
 
    /**
     * @Description 物品分类列表查询
     * @Author 卢庆阳
     * @Date 2023/10/23
     */
    @GetMapping("/list")
    public ResponseValue queryBaseCategoryList() {
        BaseCategoryParam param = CommonUtil.getObjFromReq(BaseCategoryParam.class);
        BaseCategoryParam param2 = new BaseCategoryParam();
        CommonUtil.copyProperties(param, param2);
        param = param2;
 
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<BaseCategory> pager = this.baseCategoryService.queryBaseCategoryList(param);
        return ResponseValue.success(pager);
    }
 
    /**
     * @Description 编辑
     * @Author 卢庆阳
     * @Date 2023/10/23
     */
    @PostMapping("/edit")
    public ResponseValue edit() {
        BaseCategory baseCategory = CommonUtil.getObjFromReqBody(BaseCategory.class);
        BaseCategory param2 = new BaseCategory();
        CommonUtil.copyProperties(baseCategory, param2);
        baseCategory = param2;
 
        Long id = baseCategory.getId();
        if (id == null || id.longValue() <= 0) {
            return ResponseValue.error("编辑的物品分类不存在");
        }
        if (StringUtils.isEmpty(baseCategory.getCategoryName())) {
            return ResponseValue.error("分类名称为空");
        }
        if (baseCategory.getOrderNumber() == null) {
            return ResponseValue.error("顺序号为空");
        }
 
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        int num = this.baseCategoryService.updateBaseCategory(baseCategory);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("编辑失败!");
    }
 
    /**
     * 修改状态
     *
     * @author 卢庆阳
     * @date 2023/10/23
     */
    // 分类下有正常状态的物品时,不允许禁用
    @PostMapping("/updStatus")
    public ResponseValue updateStatus() {
        BaseCategory baseCategory = CommonUtil.getObjFromReqBody(BaseCategory.class);
        BaseCategory param2 = new BaseCategory();
        CommonUtil.copyProperties(baseCategory, param2);
        baseCategory = param2;
 
        if (baseCategory.getId() == null || baseCategory.getStates() == null) {
            return ResponseValue.error("参数错误");
        }
        // 根据分类id和状态查询物品模版
        List<BaseCategory> list = this.baseGoodsTemplateService.getByCategoryId(baseCategory.getId());
        if (baseCategory.getStates() == 2 && !CollectionUtils.isEmpty(list)) {
            return ResponseValue.error("分类下有正常状态的物品,不允许禁用");
        }
 
        int num = this.baseCategoryService.updateStatus(baseCategory);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("修改失败!");
    }
 
    /**
     * @Description 根据id删除物品分类
     * @Author 卢庆阳
     * @Date 2023/10/23
     */
    @DeleteMapping("/del")
    public ResponseValue updateById() {
        BaseCategory baseCategory = CommonUtil.getObjFromReqBody(BaseCategory.class);
        BaseCategory param2 = new BaseCategory();
        CommonUtil.copyProperties(baseCategory, param2);
        baseCategory = param2;
 
        if (baseCategory.getId() == null) {
            return ResponseValue.error("分类id为空");
        }
        int num = this.baseCategoryService.updateById(baseCategory, this.getCurrentUser());
 
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("删除失败!");
    }
 
    /**
     * 根据物品id查询节点详情
     *
     * @author 卢庆阳
     * @Date 2023/10/23
     */
    @GetMapping("/detail")
    public ResponseValue getById(Long id) {
        if (id == null) {
            return ResponseValue.error("分类id为空");
        }
        BaseCategory baseCategory = this.baseCategoryService.getById(id);
        if (baseCategory == null) {
            return ResponseValue.error("查询失败!");
        }
        return ResponseValue.success("查询成功!", baseCategory);
    }
 
    /**
     * @Description 三级分类列表查询
     * @Author 卢庆阳
     * @Date 2023/10/24
     */
    @GetMapping("/select/lv3_tree")
    public ResponseValue tree() {
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
 
        List<BaseCategory> baseCategories = this.baseCategoryService.queryForLv3Tree();
        return ResponseValue.success(baseCategories);
    }
 
}