| | |
| | | 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.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 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.*; |
| | | |
| | |
| | | private FlowerService flowerService; |
| | | |
| | | @PostMapping("/tree/new") |
| | | @OperationLog(value = "新增商品分类",type = "flower_category") |
| | | @ApiOperation(value = "新增商品分类") |
| | | public ResponseEntity<ReturnDataDTO> addCategory(@RequestBody FlowerCategoryCreateDTO dto) { |
| | | return returnData(R.SUCCESS.getCode(), categoryService.addCategory(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); |
| | | return returnData(R.SUCCESS.getCode(), 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") |
| | |
| | | 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); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | 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); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | 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); |
| | | return returnData(R.SUCCESS.getCode(), null); |
| | | FlowerCategory flowerCategory = categoryService.selectCategoryById(id); |
| | | String content = "隐藏商品分类id:【" + id + "】,分类名称:【" + flowerCategory.getName() + "】,等级:【" + flowerCategory.getLevelLimit() + "】"; |
| | | OperationRecord operationRecord = getOperationRecord(content); |
| | | return returnData(R.SUCCESS.getCode(), null, operationRecord); |
| | | } |
| | | |
| | | } |