陶杰
2024-08-22 ee9032d9baf5f33e376d2d2699136e0a7b26bec7
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
package com.mzl.flower.web.supplier;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.flower.*;
import com.mzl.flower.dto.response.flower.FlowerSupplierDTO;
import com.mzl.flower.dto.response.flower.FlowerSupplierListDTO;
import com.mzl.flower.dto.response.flower.ParamItemDTO;
import com.mzl.flower.service.flower.FlowerParamService;
import com.mzl.flower.service.flower.FlowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.constraints.NotNull;
import java.util.List;
 
@RestController
@RequestMapping("/api/supplier/flower")
@Api(value = "商品管理-花农(供应商)", tags = "商品管理-花农(供应商)")
@Validated
@Slf4j
public class FlowerSupplierController extends BaseController {
 
    @Autowired
    private FlowerService flowerService;
 
    @Autowired
    private FlowerParamService paramService;
 
    @GetMapping("/params")
    @ApiOperation(value = "获取分类参数列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "商品分类id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<List<ParamItemDTO>>> getParamItemListByCategoryId(Long categoryId){
        return returnData(R.SUCCESS.getCode(), paramService.getParamItemListByCategoryId(categoryId));
    }
 
    @GetMapping("/list")
    @ApiOperation(value = "商品列表")
    public ResponseEntity<ReturnDataDTO<Page<FlowerSupplierListDTO>>> selectFlowerList(Page page, FlowerQueryDTO dto){
        return returnData(R.SUCCESS.getCode(), flowerService.selectFlowerSupplierList(page, dto, 0));
    }
 
    @GetMapping("/list/rc")
    @ApiOperation(value = "回收站商品列表")
    public ResponseEntity<ReturnDataDTO<Page<FlowerSupplierListDTO>>> selectFlowerRcList(Page page, FlowerQueryDTO dto){
        return returnData(R.SUCCESS.getCode(), flowerService.selectFlowerSupplierList(page, dto, 1));
    }
 
    @PostMapping("/list/new")
    @ApiOperation(value = "添加商品提交审核")
    public ResponseEntity<ReturnDataDTO> commitFlower(@RequestBody FlowerCreateDTO dto) {
        return returnData(R.SUCCESS.getCode(), flowerService.commitFlower(dto));
    }
 
    @PostMapping("/list/edit")
    @ApiOperation(value = "编辑商品")
    public ResponseEntity<ReturnDataDTO> editFlower(@RequestBody FlowerUpdateDTO dto) {
        return returnData(R.SUCCESS.getCode(), flowerService.editFlower(dto));
    }
 
    @GetMapping("/list/view")
    @ApiOperation(value = "商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<FlowerSupplierDTO>> getFlowerSupplierDetail(@NotNull(message = "id不能为空") Long id) {
        return returnData(R.SUCCESS.getCode(), flowerService.getFlowerSupplierDetail(id));
    }
 
    @GetMapping("/list/copy")
    @ApiOperation(value = "获取复制商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<FlowerSupplierDTO>> getFlowerCopyDetail(Long id) {
        FlowerSupplierDTO dto = flowerService.getFlowerSupplierDetail(id);
        dto.setId(null);
        dto.setStatus(null);
        dto.setSales(null);
        return returnData(R.SUCCESS.getCode(), dto);
    }
 
    @GetMapping("/list/up")
    @ApiOperation(value = "商品上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> setOn(Long id) {
        flowerService.setOffOn(id, Constants.FLOWER_STATUS.UP.name());
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping("/list/off")
    @ApiOperation(value = "商品下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> setOff(Long id) {
        flowerService.setOffOn(id, Constants.FLOWER_STATUS.OFF.name());
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping("/list/delete")
    @ApiOperation(value = "商品删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> deleteFlower(Long id) {
        flowerService.deleteFlower(id);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping("/list/restore")
    @ApiOperation(value = "商品恢复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> restoreFlower(Long id) {
        flowerService.restoreFlower(id);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @PostMapping("/list/price")
    @ApiOperation(value = "修改价格")
    public ResponseEntity<ReturnDataDTO> editFlowerPrice(@RequestBody FlowerPriceDTO dto) {
        flowerService.editFlowerPrice(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @PostMapping("/list/stock")
    @ApiOperation(value = "修改库存")
    public ResponseEntity<ReturnDataDTO> editFlowerStock(@RequestBody FlowerStockDTO dto) {
        flowerService.editFlowerStock(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
}