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
package com.xzx.gc.shop.controller;
 
 
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.request.BaseController;
import com.xzx.gc.model.JsonResult;
import com.xzx.gc.service.BaseAccountService;
import com.xzx.gc.shop.dto.AddGoodsOrderDto;
import com.xzx.gc.shop.dto.XcxGoodsListDto;
import com.xzx.gc.shop.service.GoodsService;
import com.xzx.gc.shop.service.OrderService;
import com.xzx.gc.shop.vo.GoodsCategoryVo;
import com.xzx.gc.shop.vo.XcxGoodsDetailVo;
import com.xzx.gc.shop.vo.XcxGoodsListVo;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
@RestController
@Api(tags = {"积分商城--API商品管理"})
@Slf4j
public class ApiGoodsController extends BaseController {
 
    @Autowired
    private GoodsService goodsService;
 
    @Autowired
    private OrderService orderService;
 
    @ApiOperation("分类列表")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = GoodsCategoryVo.class)
    )
    @GetMapping(value = "/goods/goodsCategory")
    public JsonResult<List<GoodsCategoryVo>> goodsCategory() {
        return JsonResult.success(goodsService.findCategoryWithChildren());
    }
 
    @ApiOperation("商品列表")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = XcxGoodsListVo.class)
    )
    @PostMapping(value = "/goods/goodsList")
    public JsonResult<PageInfo<XcxGoodsListVo>> goodsList(@RequestBody XcxGoodsListDto xcxGoodsListDto, HttpServletRequest request) {
        return JsonResult.success(goodsService.findGoodsListInPage(xcxGoodsListDto));
    }
 
    @ApiOperation("商品详情")
    @ApiResponses(
            @ApiResponse(code = 200, message = "success", response = XcxGoodsDetailVo.class)
    )
    @PostMapping(value = "/goods/goodsDetails/{id}")
    public JsonResult<XcxGoodsDetailVo> goodsDetails(@PathVariable("id") Long id) {
        return JsonResult.success(goodsService.findGoodsDetails(id));
    }
 
    @ApiOperation("积分商城下单")
    @PostMapping(value = "/goods/order/add")
    public Result<String> addOrder(@RequestBody AddGoodsOrderDto addGoodsOrderDto, HttpServletRequest request) {
        String userId = getUserId(request);
        addGoodsOrderDto.setUserId(userId);
 
        orderService.addOrder(addGoodsOrderDto);
 
        Result<String> result = Result.success();
        result.setMsg("下单成功");
        return result;
    }
 
}