cloudroam
2024-12-12 db6da36b94e1e43096a818052ee65dbfcd5e6d98
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
package com.mzl.flower.web.flower;
 
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.base.annotation.OperationLog;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.flower.*;
import com.mzl.flower.dto.response.flower.FlowerListDTO;
import com.mzl.flower.dto.response.flower.FlowerZoneDTO;
import com.mzl.flower.entity.flower.FlowerZone;
import com.mzl.flower.entity.log.OperationRecord;
import com.mzl.flower.service.flower.FlowerService;
import com.mzl.flower.service.flower.FlowerZoneService;
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.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/flower/zone")
@Api(value = "专区管理", tags = "专区管理")
@Validated
@Slf4j
public class FlowerZoneController extends BaseController {
 
    private final FlowerZoneService flowerZoneService;
 
    private final FlowerService flowerService;
    public FlowerZoneController(FlowerZoneService flowerZoneService, FlowerService flowerService) {
        this.flowerZoneService = flowerZoneService;
        this.flowerService = flowerService;
    }
 
    @PostMapping("/page/new")
    @OperationLog(value = "新增专区", type = "flower_zone")
    @ApiOperation(value = "新增专区")
    public ResponseEntity<ReturnDataDTO> addTag(@RequestBody FlowerZoneCreateDTO dto) {
        flowerZoneService.addZone(dto);
        String content = "新增专区:专区标题:【" + dto.getName() + "】,专区图片:【" + dto.getBgUrl() + "】,排序:【" + dto.getSeq() + "】";
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
    }
 
    @PostMapping("/page/edit")
    @OperationLog(value = "编辑专区", type = "flower_zone")
    @ApiOperation(value = "编辑专区")
    public ResponseEntity<ReturnDataDTO> updateZone(@RequestBody FlowerZoneUpdateDTO dto) {
        flowerZoneService.updateZone(dto);
        String content = "编辑专区:专区id:【"+dto.getId()+"】,专区标题:【" + dto.getName() + "】,专区图片:【" + dto.getBgUrl() + "】,排序:【" + dto.getSeq() + "】";
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
    }
 
    @GetMapping("/page/view")
    @ApiOperation(value = "查询专区详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "专区id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<FlowerZoneDTO>> getZone(@NotNull(message = "id不能为空") Long id){
        return returnData(R.SUCCESS.getCode(), flowerZoneService.getZone(id));
    }
    
    @GetMapping("/page")
    @ApiOperation(value = "专区分页查询")
    public ResponseEntity<ReturnDataDTO<Page<FlowerZoneDTO>>> selectZonePage(Page page,String name){
        return returnData(R.SUCCESS.getCode(), flowerZoneService.selectZonePage(page, name));
    }
 
    @GetMapping("/page/delete")
    @OperationLog(value = "删除专区", type = "flower_zone")
    @ApiOperation(value = "删除专区")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "专区id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> deleteZone(@NotNull(message = "id不能为空") Long id){
        FlowerZone flowerZone = flowerZoneService.selectFlowerZoneById(id);
        flowerZoneService.deleteZone(id);
        String content = "删除专区:专区id:【" + id + "】,专区标题:【" + flowerZone.getName() + "】,专区图片:【" + flowerZone.getBgUrl() + "】,排序:【" + flowerZone.getSeq() + "】";
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
    }
 
    @GetMapping("/list")
    @ApiOperation(value = "用户端-专区列表查询")
    public ResponseEntity<ReturnDataDTO<List<FlowerZoneDTO>>> selectZoneList(){
        return returnData(R.SUCCESS.getCode(), flowerZoneService.selectZoneList(Constants.COMMON_PUBLISH_STATUS.published.name()));
    }
 
    @GetMapping("/page/changeStatus")
    @ApiOperation(value = "专区上下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "专区id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> changeStatus(@NotNull(message = "id不能为空") Long id){
        flowerZoneService.changeStatus(id);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
 
    @PostMapping("/page/set/rank")
    @ApiOperation(value = "设置专区商品排序")
    public ResponseEntity<ReturnDataDTO> setFlowerRank(@RequestBody FlowerZoneRankDTO dto) {
        flowerZoneService.setFlowerZoneRank(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
 
    @GetMapping("/page/flower/list")
    @ApiOperation(value = "商品列表")
    public ResponseEntity<ReturnDataDTO<Page<FlowerListDTO>>> selectZoneFlowerList(Page page, FlowerZoneQueryDTO dto){
        if(dto.getZoneId()==null || dto.getZoneId()==0){
            throw new ValidationException("专区id不能为空");
        }
        return returnData(R.SUCCESS.getCode(), flowerService.selectZoneFlowerList(page, dto));
    }
 
 
}