商品管理

pull/2/head
perry 2023-05-10 23:38:51 +08:00
parent 3e6f21dadd
commit b175639c15
1 changed files with 186 additions and 0 deletions

View File

@ -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 CRMEBCRMEB
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
@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<PageInfo<Category>> 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<Boolean> 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<Boolean> 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<Boolean> 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<Category> 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<List<CategoryTreeVo>> getListTree(@RequestParam(name = "type") Integer type,
@RequestParam(name = "status") Integer status,
@RequestParam(name = "name", required = false) String name) {
List<CategoryTreeVo> 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<List<Category>> 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<Object> getByIds(@Validated @PathVariable(name = "id") Integer id) {
if (categoryService.updateStatus(id)) {
return CommonResult.success("修改成功");
} else {
return CommonResult.error(GlobalErrorCodeConstants.ERROR);
}
}
}