xiangpei
7 天以前 288ce585418550bbf2fd898fc01bc2ff9245f960
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
package cn.lili.controller.goods;
 
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.security.OperationalJudgment;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.DraftGoods;
import cn.lili.modules.goods.entity.dto.DraftGoodsDTO;
import cn.lili.modules.goods.entity.dto.DraftGoodsSearchParams;
import cn.lili.modules.goods.entity.vos.DraftGoodsVO;
import cn.lili.modules.goods.service.DraftGoodsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Objects;
 
/**
 * 店铺端,草稿商品接口
 *
 * @author paulG
 * @since 2021/2/20 2:26 下午
 */
@RestController
@Api(tags = "店铺端,草稿商品接口")
@RequestMapping("/store/goods/draftGoods")
public class DraftGoodsStoreController {
    @Autowired
    private DraftGoodsService draftGoodsService;
 
 
    @ApiOperation(value = "分页获取草稿商品列表")
    @GetMapping(value = "/page")
    public ResultMessage<IPage<DraftGoods>> getDraftGoodsByPage(DraftGoodsSearchParams searchParams) {
        String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
        searchParams.setStoreId(storeId);
        return ResultUtil.data(draftGoodsService.getDraftGoods(searchParams));
    }
 
    @ApiOperation(value = "获取草稿商品")
    @GetMapping(value = "/{id}")
    public ResultMessage<DraftGoodsVO> getDraftGoods(@PathVariable String id) {
        DraftGoodsVO draftGoods = OperationalJudgment.judgment(draftGoodsService.getDraftGoods(id));
        return ResultUtil.data(draftGoods);
    }
 
    @ApiOperation(value = "保存草稿商品")
    @PostMapping(value = "/save", consumes = "application/json", produces = "application/json")
    public ResultMessage<String> saveDraftGoods(@RequestBody DraftGoodsDTO draftGoodsVO) {
        String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
        if (draftGoodsVO.getStoreId() == null) {
            draftGoodsVO.setStoreId(storeId);
        } else if (draftGoodsVO.getStoreId() != null && !storeId.equals(draftGoodsVO.getStoreId())) {
            throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
        }
        draftGoodsService.saveGoodsDraft(draftGoodsVO);
        return ResultUtil.success();
    }
 
    @ApiOperation(value = "删除草稿商品")
    @DeleteMapping(value = "/{id}")
    public ResultMessage<String> deleteDraftGoods(@PathVariable String id) {
        OperationalJudgment.judgment(draftGoodsService.getDraftGoods(id));
        draftGoodsService.deleteGoodsDraft(id);
        return ResultUtil.success();
    }
 
}