xiaoyong931011
2021-06-25 c4dcdec3c5419bffdf98a021cac170a5cec2e114
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
package com.xzx.gc.shop.controller;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
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.ScoreGoods;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.shop.dto.*;
import com.xzx.gc.shop.mapper.ScoreGoodsMapper;
import com.xzx.gc.shop.service.GoodsService;
import com.xzx.gc.shop.vo.QueryGoodsListVo;
import com.xzx.gc.shop.vo.ViewGoodsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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 AdminGoodsController extends BaseController {
 
    @Resource
    private GoodsService goodsService;
 
    @Resource
    private ScoreGoodsMapper scoreGoodsMapper;
    /**
     * 查询商品列表
     * xzx_score_goods 积分商品表
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/queryGoodsList.json")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = QueryGoodsListVo.class)})
    @ApiOperation(value = "商品管理-商品列表", notes = "test: 仅0有正确返回")
    public JsonResult<Map<String, Object>> queryGoodsList(@RequestBody QueryGoodsListDto model) {
        Map<String, Object> result = goodsService.queryGoodsList(model);
        return JsonResult.success(result);
    }
 
    /**
     * 添加商品
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX+"/score/goods/addGoods.json")
    @ApiOperation(value = "商品管理-添加商品", notes = "test: 仅0有正确返回")
    public JsonResult<String> addGoods(@RequestBody AddGoodsDto model, HttpServletRequest request) {
        List<ScoreGoodsStyleDto> scoreGoodsStyles = model.getScoreGoodsStyles();
        if(CollUtil.isNotEmpty(scoreGoodsStyles)){
            return JsonResult.failMessage("样式不能为空!");
        }
        model.setCreatedBy(getAdminName(request));
        model.setCreatedTime(new Date());
        Long scoreGoodsId = goodsService.addGoods(model);
        if(scoreGoodsId > 0){
            OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                    .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-添加商品-" + scoreGoodsId).build();
            mqUtil.sendApp(build);
            return  JsonResult.success("操作成功!");
        }else{
            return  JsonResult.failMessage("操作失败!");
        }
    }
 
    /**
     * 删除商品
     */
 
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/deleteGoods.json")
    @ApiOperation(value="商品管理-删除商品", notes="test: 仅0有正确返回")
    public JsonResult deleteGoods(@RequestBody DeleteGoodsDto model, HttpServletRequest request) {
        long id = model.getId();
        ScoreGoods scoreGoods = scoreGoodsMapper.selectByPrimaryKey(id);
        if(ObjectUtil.isEmpty(scoreGoods)){
            return JsonResult.failMessage("商品不存在!");
        }
        //下架商品才能删除
        Integer isSale = scoreGoods.getIsSale();
        if(ScoreGoods.ISSALE_YES == isSale){
            return JsonResult.failMessage("只允许删除下架商品!");
        }
        goodsService.deleteGoods(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("操作成功!");
    }
 
    /**
     * 查看商品详情
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/viewGoods.json")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = ViewGoodsVo.class)})
    @ApiOperation(value="商品管理-查看商品详情", notes="test: 仅0有正确返回")
    public JsonResult<ViewGoodsVo> viewGoods(@RequestBody ViewGoodsDto viewGoodsDto) {
        Long id = viewGoodsDto.getId();
        ViewGoodsVo viewGoodsVo = goodsService.viewGoods(id);
        return JsonResult.success(viewGoodsVo);
    }
 
    /**
     * 更新商品
     * @param model
     * @return
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/updateGoods.json")
    @ApiOperation(value="商品管理-更新商品", notes="test: 仅0有正确返回")
    public JsonResult updateGoods(@RequestBody UpdateGoodsDto model, HttpServletRequest request) {
        long id = model.getId();
        ScoreGoods scoreGoods = scoreGoodsMapper.selectByPrimaryKey(id);
        if(ObjectUtil.isEmpty(scoreGoods)){
            return JsonResult.failMessage("商品不存在!");
        }
        //下架商品才能更新
        Integer isSale = scoreGoods.getIsSale();
        if(ScoreGoods.ISSALE_YES == isSale){
            return JsonResult.failMessage("请先下架商品!");
        }
        List<ScoreGoodsStyleDto> scoreGoodsStyles = model.getScoreGoodsStyles();
        if(CollUtil.isNotEmpty(scoreGoodsStyles)){
            return JsonResult.failMessage("样式不能为空!");
        }
        goodsService.updateGoods(model);
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-更新商品-" + id).build();
        mqUtil.sendApp(build);
        return  JsonResult.success("操作成功!");
    }
 
    /**
     * 商品上下架
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/saleGoods.json")
    @ApiOperation(value="商品管理-商品上下架", notes="test: 仅0有正确返回")
    public JsonResult saleGoods(@RequestBody SaleGoodsDto model, HttpServletRequest request) {
        long id = model.getId();
        ScoreGoods scoreGoods = scoreGoodsMapper.selectById(id);
        if(ObjectUtil.isEmpty(scoreGoods)){
            return JsonResult.failMessage("商品不存在!");
        }
        short delFlag = scoreGoods.getDelFlag();
        if(Convert.toShort(Constants.DEL_FLAG) == delFlag){
            return JsonResult.failMessage("当前商品已删除!");
        }
        goodsService.saleGoods(id, model.getIsSale());
        String upDown = "";
        if(model.getIsSale() == ScoreGoods.ISSALE_YES){
            upDown = "上";
        }else{
            upDown = "下";
        }
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-商品"+upDown+"架-"+id).build();
        mqUtil.sendApp(build);
        return new JsonResult().success("操作成功!");
    }
 
    /**
     * 商品开始抢购开关
     */
    @PostMapping(Constants.ADMIN_VIEW_PREFIX + "/score/goods/snapUpGoods.json")
    @ApiOperation(value="商品管理-商品开始抢购开关", notes="test: 仅0有正确返回")
    public JsonResult snapUpGoods(@RequestBody SnapUpGoodsDto model, HttpServletRequest request) {
        long id = model.getId();
        ScoreGoods scoreGoods = scoreGoodsMapper.selectById(id);
        if(ObjectUtil.isEmpty(scoreGoods)){
            return JsonResult.failMessage("商品不存在!");
        }
        short delFlag = scoreGoods.getDelFlag();
        if(Convert.toShort(Constants.DEL_FLAG) == delFlag){
            return JsonResult.failMessage("当前商品已删除!");
        }
        goodsService.snapUpGoods(model);
        String upDown = "";
        if(model.getIsQg() == ScoreGoods.ISQG_YES){
            upDown = "开始";
        }else{
            upDown = "结束";
        }
        OperationAppLog build = OperationAppLog.builder().appPrograme(CommonEnum.后台.getValue()).opreateName(getAdminName(request))
                .methodName(Constants.SCORESHOP_MODUL_NAME).operateAction("商品管理-商品"+upDown+"抢购-"+id).build();
        mqUtil.sendApp(build);
        return new JsonResult().success("操作成功!");
    }
}