陶杰
2025-01-08 ae1471f378f399f76518539ec8992e64a3673436
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
package com.mzl.flower.web.flower;
 
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.dto.request.flower.FlowerCategoryCreateDTO;
import com.mzl.flower.dto.request.flower.FlowerCategoryQueryDTO;
import com.mzl.flower.dto.request.flower.FlowerCategoryUpdateDTO;
import com.mzl.flower.dto.response.flower.FlowerCategoryDTO;
import com.mzl.flower.dto.response.flower.FlowerCategoryTreeDTO;
import com.mzl.flower.entity.flower.FlowerCategory;
import com.mzl.flower.entity.log.OperationRecord;
import com.mzl.flower.service.flower.FlowerCategoryService;
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.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.constraints.NotBlank;
import java.util.List;
 
@RestController
@RequestMapping("/api/flower/category")
@Api(value = "商品分类管理", tags = "商品分类管理")
@Validated
@Slf4j
public class FlowerCategoryController extends BaseController {
 
    @Autowired
    private FlowerCategoryService categoryService;
 
    @Autowired
    private FlowerService flowerService;
 
    @PostMapping("/tree/new")
    @OperationLog(value = "新增商品分类",type = "flower_category")
    @ApiOperation(value = "新增商品分类")
    public ResponseEntity<ReturnDataDTO> addCategory(@RequestBody FlowerCategoryCreateDTO dto) {
        String content = "";
        if (StringUtils.isEmpty(dto.getParentId())) {
            content = "新增商品分类:分类名称:【" + dto.getName() + "】,等级:【" + dto.getLevelLimit() + "】";
        } else {
            content = "新增商品分类:上级分类id:【" + dto.getParentId() + "】分类名称:【" + dto.getName() + "】,等级:【" + dto.getLevelLimit() + "】";
        }
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), categoryService.addCategory(dto), operationRecord);
    }
 
    @PostMapping("/tree/edit")
    @OperationLog(value = "编辑商品分类",type = "flower_category")
    @ApiOperation(value = "编辑商品分类")
    public ResponseEntity<ReturnDataDTO> updateCategory(@RequestBody FlowerCategoryUpdateDTO dto) {
        Long category = categoryService.updateCategory(dto);
        flowerService.updateCategoryInfo(category);
        String content = "";
        if (StringUtils.isEmpty(dto.getParentId())) {
            content = "编辑商品分类:分类名称:【" + dto.getName() + "】,等级:【" + dto.getLevelLimit() + "】";
        } else {
            content = "编辑商品分类:上级分类id:【" + dto.getParentId() + "】分类名称:【" + dto.getName() + "】,等级:【" + dto.getLevelLimit() + "】";
        }
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), category, operationRecord);
    }
 
    @GetMapping("/tree/view")
    @ApiOperation(value = "查询商品分类详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "String", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<FlowerCategoryDTO>> getCategory(@NotBlank(message = "id不能为空") String id){
        return returnData(R.SUCCESS.getCode(), categoryService.getCategory(id));
    }
    
    @GetMapping("/tree")
    @ApiOperation(value = "获取商品分类树")
    public ResponseEntity<ReturnDataDTO<List<FlowerCategoryTreeDTO>>> selectCategoryTree(FlowerCategoryQueryDTO dto){
        return returnData(R.SUCCESS.getCode(), categoryService.selectCategoryTree(dto));
    }
 
    @GetMapping("/list")
    @ApiOperation(value = "获取商品分类列表")
    public ResponseEntity<ReturnDataDTO<List<FlowerCategoryTreeDTO>>> selectCategoryList(FlowerCategoryQueryDTO dto){
        return returnData(R.SUCCESS.getCode(), categoryService.selectCategoryList(dto));
    }
 
    @GetMapping("/tree/delete")
    @OperationLog(value = "删除商品分类",type = "flower_category")
    @ApiOperation(value = "删除商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> deleteCategory(Long id){
        FlowerCategory flowerCategory = categoryService.selectCategoryById(id);
        categoryService.deleteCategory(id);
        String content = "";
        if (StringUtils.isEmpty(flowerCategory.getParentId())) {
            content = "删除商品分类id:【" + id + "】,分类名称:【" + flowerCategory.getName() + "】,等级:【" + flowerCategory.getLevelLimit() + "】";
        } else {
            content = "删除商品分类id:【" + id + "】,上级分类id:【" + flowerCategory.getParentId() + "】,分类名称:【" + flowerCategory.getName() + "】,等级:【" + flowerCategory.getLevelLimit() + "】";
        }
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
    }
 
    @GetMapping("/tree/shown")
    @OperationLog(value = "显示商品分类",type = "flower_category")
    @ApiOperation(value = "显示商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> showCategory(Long id){
        categoryService.setCategoryShown(id, true);
        FlowerCategory flowerCategory = categoryService.selectCategoryById(id);
        String content = "显示商品分类id:【" + id + "】,分类名称:【" + flowerCategory.getName() + "】,等级:【" + flowerCategory.getLevelLimit() + "】";
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
 
    }
 
    @GetMapping("/tree/hidden")
    @OperationLog(value = "隐藏商品分类",type = "flower_category")
    @ApiOperation(value = "隐藏商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "Long", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> hideCategory(Long id){
        categoryService.setCategoryShown(id, false);
        FlowerCategory flowerCategory = categoryService.selectCategoryById(id);
        String content = "隐藏商品分类id:【" + id + "】,分类名称:【" + flowerCategory.getName() + "】,等级:【" + flowerCategory.getLevelLimit() + "】";
        OperationRecord operationRecord = getOperationRecord(content);
        return returnData(R.SUCCESS.getCode(), null, operationRecord);
    }
 
}