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 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 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> getCategory(@NotBlank(message = "id不能为空") String id){ return returnData(R.SUCCESS.getCode(), categoryService.getCategory(id)); } @GetMapping("/tree") @ApiOperation(value = "获取商品分类树") public ResponseEntity>> selectCategoryTree(FlowerCategoryQueryDTO dto){ return returnData(R.SUCCESS.getCode(), categoryService.selectCategoryTree(dto)); } @GetMapping("/list") @ApiOperation(value = "获取商品分类列表") public ResponseEntity>> 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> 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> 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> 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); } }