| 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.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.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.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") | 
|     @ApiOperation(value = "新增商品分类") | 
|     public ResponseEntity<ReturnDataDTO> addCategory(@RequestBody FlowerCategoryCreateDTO dto) { | 
|         return returnData(R.SUCCESS.getCode(), categoryService.addCategory(dto)); | 
|     } | 
|   | 
|     @PostMapping("/tree/edit") | 
|     @ApiOperation(value = "编辑商品分类") | 
|     public ResponseEntity<ReturnDataDTO> updateCategory(@RequestBody FlowerCategoryUpdateDTO dto) { | 
|         Long category = categoryService.updateCategory(dto); | 
|         flowerService.updateCategoryInfo(category); | 
|         return returnData(R.SUCCESS.getCode(), category); | 
|     } | 
|   | 
|     @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") | 
|     @ApiOperation(value = "删除商品分类") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "Long", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<?>> deleteCategory(Long id){ | 
|         categoryService.deleteCategory(id); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/tree/shown") | 
|     @ApiOperation(value = "显示商品分类") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "Long", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<?>> showCategory(Long id){ | 
|         categoryService.setCategoryShown(id, true); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
|     @GetMapping("/tree/hidden") | 
|     @ApiOperation(value = "隐藏商品分类") | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(name = "id", value = "商品分类id", required = true, dataType = "Long", paramType = "query") | 
|     }) | 
|     public ResponseEntity<ReturnDataDTO<?>> hideCategory(Long id){ | 
|         categoryService.setCategoryShown(id, false); | 
|         return returnData(R.SUCCESS.getCode(), null); | 
|     } | 
|   | 
| } |