diff --git a/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/category/CategoryController.java b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/category/CategoryController.java new file mode 100644 index 000000000..b4778fe73 --- /dev/null +++ b/yudao-module-mall/yudao-module-shop-biz/src/main/java/cn/iocoder/yudao/module/shop/controller/admin/category/CategoryController.java @@ -0,0 +1,186 @@ +package cn.iocoder.yudao.module.shop.controller.admin.category; + +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.string.StrUtils; +import cn.iocoder.yudao.module.shop.dal.dataobject.category.Category; +import cn.iocoder.yudao.module.shop.request.category.CategoryRequest; +import cn.iocoder.yudao.module.shop.request.category.CategorySearchRequest; +import cn.iocoder.yudao.module.shop.service.category.CategoryService; +import cn.iocoder.yudao.module.shop.vo.category.CategoryTreeVo; +import com.github.pagehelper.PageInfo; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +/** + * 分类表 前端控制器 + * +---------------------------------------------------------------------- + * | CRMEB [ CRMEB赋能开发者,助力企业发展 ] + * +---------------------------------------------------------------------- + * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 + * +---------------------------------------------------------------------- + * | Author: CRMEB Team + * +---------------------------------------------------------------------- + */ +@Slf4j +@RestController +@RequestMapping("api/admin/category") +@Tag(name = "管理后台 - 分类服务") +public class CategoryController { + + @Autowired + private CategoryService categoryService; + + + /** + * 分页显示分类表 + * @param request 搜索条件 + * @param pageParamRequest 分页参数 + * @author Mr.Zhang + * @since 2020-04-16 + */ + @PreAuthorize("hasAuthority('admin:category:list')") + @Operation(summary = "分页分类列表") + @RequestMapping(value = "/list", method = RequestMethod.GET) + public CommonResult> getList(@ModelAttribute CategorySearchRequest request, @ModelAttribute PageParam pageParamRequest) { + return CommonResult.success(categoryService.getList(request, pageParamRequest)); + } + + /** + * 新增分类表 + * @param categoryRequest 新增参数 + */ + @PreAuthorize("hasAuthority('admin:category:save')") + @Operation(summary = "新增") + @RequestMapping(value = "/save", method = RequestMethod.POST) + public CommonResult save(@Validated CategoryRequest categoryRequest) { + if (categoryService.create(categoryRequest)) { + return CommonResult.success(true); + } else { + return CommonResult.error(GlobalErrorCodeConstants.ERROR); + } + } + + /** + * 删除分类表 + * @param id Integer + * @author Mr.Zhang + * @since 2020-04-16 + */ + @PreAuthorize("hasAuthority('admin:category:delete')") + @Operation(summary = "删除") + @RequestMapping(value = "/delete", method = RequestMethod.GET) + @Parameter(name="id", description="分类ID") + public CommonResult delete(@RequestParam(value = "id") Integer id) { + if (categoryService.delete(id) > 0) { + return CommonResult.success(true); + } else { + return CommonResult.error(GlobalErrorCodeConstants.ERROR); + } + } + + /** + * 修改分类表 + * @param id integer id + * @param categoryRequest 修改参数 + * @author Mr.Zhang + * @since 2020-04-16 + */ + @PreAuthorize("hasAuthority('admin:category:update')") + @Operation(summary = "修改") + @RequestMapping(value = "/update", method = RequestMethod.POST) + @Parameter(name="id", description="分类ID") + public CommonResult update(@RequestParam Integer id, @ModelAttribute CategoryRequest categoryRequest) { + if (null == id || id <= 0) throw new ServiceException("id 参数不合法"); + categoryRequest.setExtra(categoryRequest.getExtra()); + if (categoryService.update(categoryRequest, id)) { + return CommonResult.success(true); + } else { + return CommonResult.error(GlobalErrorCodeConstants.ERROR); + } + } + + /** + * 查询分类表信息 + * @param id Integer + * @author Mr.Zhang + * @since 2020-04-16 + */ + @PreAuthorize("hasAuthority('admin:category:info')") + @Operation(summary = "分类详情") + @RequestMapping(value = "/info", method = RequestMethod.GET) + @Parameter(name="id", description="分类ID") + public CommonResult info(@RequestParam(value = "id") Integer id) { + Category category = categoryService.getById(id); + return CommonResult.success(category); + } + + + /** + * 查询分类表信息 + * @author Mr.Zhang + * @since 2020-04-16 + */ + @PreAuthorize("hasAuthority('admin:category:list:tree')") + @Operation(summary = "获取tree结构的列表") + @RequestMapping(value = "/list/tree", method = RequestMethod.GET) + @Parameters({ + @Parameter(name="type", description="类型ID | 类型,1 产品分类,2 附件分类,3 文章分类, 4 设置分类, 5 菜单分类, 6 配置分类, 7 秒杀配置", example = "1"), + @Parameter(name="status", description="-1=全部,0=未生效,1=已生效", example = "1"), + @Parameter(name="name", description="模糊搜索", example = "电视") + }) + public CommonResult> getListTree(@RequestParam(name = "type") Integer type, + @RequestParam(name = "status") Integer status, + @RequestParam(name = "name", required = false) String name) { + List listTree = categoryService.getListTree(type,status,name); + return CommonResult.success(listTree); + } + + /** + * 根据分类id集合获取分类数据 + * @param ids String id集合字符串 + * @since 2020-04-16 + */ + @PreAuthorize("hasAuthority('admin:category:list:ids')") + @Operation(summary = "根据id集合获取分类列表") + @RequestMapping(value = "/list/ids", method = RequestMethod.GET) + @Parameter(name = "ids", description="分类id集合") + public CommonResult> getByIds(@Validated @RequestParam(name = "ids") String ids) { + return CommonResult.success(categoryService.getByIds(StrUtils.stringToArray(ids))); + } + + /** + * 更改分类状态 + * @param id Integer 分类id + * @since 2020-04-16 + * @return + */ + @PreAuthorize("hasAuthority('admin:category:update:status')") + @Operation(summary = "更改分类状态") + @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.GET) + @Parameter(name = "id", description="分类id") + public CommonResult getByIds(@Validated @PathVariable(name = "id") Integer id) { + if (categoryService.updateStatus(id)) { + return CommonResult.success("修改成功"); + } else { + return CommonResult.error(GlobalErrorCodeConstants.ERROR); + } + } +} + + +