xiaoyong931011
2021-06-24 3df48185231b49359be9ba843978e3450f36e1ed
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
package com.xzx.gc.shop.controller;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.dto.log.OperationAppLog;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.entity.ScoreGoodsCategory;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.model.admin.GoodsCategoryModel;
import com.xzx.gc.shop.dto.*;
import com.xzx.gc.shop.mapper.ScoreGoodsCategoryMapper;
import com.xzx.gc.shop.service.GoodsService;
import com.xzx.gc.shop.vo.*;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
@RestController
@Api(tags = {"积分商城--商品分类管理"})
@Slf4j
public class AdminGoodsCategoryController extends BaseController {
 
    @Resource
    private GoodsService goodsService;
 
    @Resource
    private ScoreGoodsCategoryMapper scoreGoodsCategoryMapper;
 
    /**
     * 查询商品分类列表
     * xzx_score_goods_category商品分类
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/queryGoodsCategoryList.json")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = QueryGoodsCategoryListVo.class)})
    @ApiOperation(value = "商品分类管理-商品分类列表", notes = "test: 仅0有正确返回")
    public JsonResult<Map<String, Object>> queryGoodsCategoryList(@RequestBody QueryGoodsCategoryListDto model) {
        Map<String, Object> result = goodsService.queryGoodsCategoryList(model);
        return JsonResult.success(result);
    }
 
    /**
     * 查询商品分类--所有一级分类
     * xzx_score_goods_category商品分类
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/viewGoodsCategoryList.json")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewGoodsCategoryListVo.class)})
    @ApiOperation(value = "商品分类管理--所有一级分类", notes = "test: 仅0有正确返回")
    public JsonResult<List<ViewGoodsCategoryListVo>> viewGoodsCategoryList(@RequestBody ViewGoodsCategoryListDto viewGoodsCategoryListDto) {
        List<ViewGoodsCategoryListVo> result = goodsService.viewGoodsCategoryList(viewGoodsCategoryListDto);
        return JsonResult.success(result);
    }
 
    /**
     * 添加商品分类
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/addGoodsCategory.json")
    @ApiOperation(value = "商品分类管理-添加商品分类", notes = "test: 仅0有正确返回")
    public JsonResult<String> addGoodsCategory(@RequestBody AddGoodsCategoryDto model, HttpServletRequest request) {
        String name = model.getName();
        if(StrUtil.isEmpty(name)){
            return JsonResult.failMessage("分类名称不能为空!");
        }
        String categoryIden = model.getCategoryIden();
        if(StrUtil.isEmpty(categoryIden)){
            return JsonResult.failMessage("分类代码不能为空!");
        }
        Long parentId = model.getParentId();
        if(StrUtil.isEmpty(parentId.toString())){
            return JsonResult.failMessage("父类不能为空!");
        }
        GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel();
        goodsCategoryModel.setName(name);
        goodsCategoryModel.setCategoryIden(categoryIden);
        goodsCategoryModel.setParentId(parentId);
        List<QueryGoodsCategoryListVo> maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel);
        if(CollUtil.isNotEmpty(maps)){
            return JsonResult.failMessage("分类不能重复添加!");
        }
        goodsCategoryModel.setCreatedBy(getAdminName(request));
        goodsCategoryModel.setCreatedTime(new Date());
        Long scoreGoodsCategoryId = goodsService.addGoodsCategory(goodsCategoryModel);
        if(scoreGoodsCategoryId > 0){
            OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-添加商品分类-" + scoreGoodsCategoryId).build();
            mqUtil.sendApp(build);
            return  JsonResult.success("操作成功!");
        }else{
            return  JsonResult.failMessage("操作失败!");
        }
    }
 
    /**
     * 删除添加商品分类
     */
 
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/deleteGoodsCategory.json")
    @ApiOperation(value="商品分类管理-删除添加商品分类", notes="test: 仅0有正确返回")
    public JsonResult deleteGoodsCategory(@RequestBody DeleteGoodsCategoryDto model, HttpServletRequest request) {
        long id = model.getId();
        ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id);
        if(ObjectUtil.isEmpty(scoreGoodsCategory)){
            return JsonResult.failMessage("分类不存在!");
        }
        goodsService.deleteGoodsCategory(id);
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-删除商品分类-"+id).build();
        mqUtil.sendApp(build);
        return new JsonResult().success("操作成功!");
    }
 
    /**
     * 查看商品分类详情
     */
    @GetMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/viewGoodsCategory/{id}")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewGoodsCategoryVo.class)})
    @ApiOperation(value="商品分类管理-查看商品分类详情", notes="test: 仅0有正确返回")
    public JsonResult<ViewGoodsCategoryVo> viewGoodsCategory(@PathVariable long id) {
        ViewGoodsCategoryVo viewGoodsCategoryVo = goodsService.viewGoodsCategoryById(id);
        return JsonResult.success(viewGoodsCategoryVo);
    }
 
    /**
     * 更新商品分类
     * @param model
     * @return
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/updateGoodsCategory.json")
    @ApiOperation(value="商品分类管理-更新商品分类", notes="test: 仅0有正确返回")
    public JsonResult updateGoodsCategory(@RequestBody UpdateGoodsCategoryDto model, HttpServletRequest request) {
        long id = model.getId();
        ScoreGoodsCategory scoreGoodsCategory = scoreGoodsCategoryMapper.selectByPrimaryKey(id);
        if(ObjectUtil.isEmpty(scoreGoodsCategory)){
            return JsonResult.failMessage("分类不存在!");
        }
        String name = model.getName();
        if(StrUtil.isEmpty(name)){
            return JsonResult.failMessage("分类名称不能为空!");
        }
        if(!name.equals(scoreGoodsCategory.getName())){
            scoreGoodsCategory.setName(name);
        }
        String categoryIden = model.getCategoryIden();
        if(StrUtil.isEmpty(categoryIden)){
            return JsonResult.failMessage("分类代码不能为空!");
        }
        if(!categoryIden.equals(scoreGoodsCategory.getCategoryIden())){
            scoreGoodsCategory.setCategoryIden(categoryIden);
        }
        Long parentId = model.getParentId();
        if(StrUtil.isEmpty(parentId.toString())){
            return JsonResult.failMessage("父类不能为空!");
        }
        if(!parentId.equals(scoreGoodsCategory.getParentId())){
            scoreGoodsCategory.setParentId(parentId);
        }
        if(parentId.equals(id)){
            return JsonResult.failMessage("父类不能为自己!");
        }
 
        GoodsCategoryModel goodsCategoryModel = new GoodsCategoryModel();
        goodsCategoryModel.setName(name);
        goodsCategoryModel.setCategoryIden(categoryIden);
        goodsCategoryModel.setParentId(parentId);
        List<QueryGoodsCategoryListVo> maps = scoreGoodsCategoryMapper.queryGoodsCategoryList(goodsCategoryModel);
        if(CollUtil.isNotEmpty(maps)){
            return JsonResult.failMessage("分类不能重复添加!");
        }
        goodsCategoryModel.setId(id);
        goodsService.updateGoodsCategory(goodsCategoryModel);
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-更新商品分类-" + id).build();
        mqUtil.sendApp(build);
        return  JsonResult.success("操作成功!");
    }
 
 
 
 
}