商品规格 key 的迁移
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package cn.iocoder.mall.product.rest.controller.brand;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO;
|
||||
import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO;
|
||||
import cn.iocoder.mall.product.biz.service.brand.ProductBrandService;
|
||||
import cn.iocoder.mall.product.rest.convert.brand.ProductBrandConvert;
|
||||
import cn.iocoder.mall.product.rest.request.brand.ProductBrandAddRequest;
|
||||
import cn.iocoder.mall.product.rest.request.brand.ProductBrandPageRequest;
|
||||
import cn.iocoder.mall.product.rest.request.brand.ProductBrandUpdateRequest;
|
||||
import cn.iocoder.mall.product.rest.response.brand.AdminsProductBrandResponse;
|
||||
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("admins/brand")
|
||||
@Api("管理员 - 商品品牌 API")
|
||||
@AllArgsConstructor
|
||||
public class AdminsProductBrandController {
|
||||
|
||||
private final ProductBrandService productBrandService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("创建品牌")
|
||||
public CommonResult<AdminsProductBrandResponse> add(@Validated ProductBrandAddRequest addRequest) {
|
||||
// 创建 ProductBrandAddDTO 对象
|
||||
ProductBrandAddDTO productBrandAddDTO = ProductBrandConvert.INSTANCE.convertAdd(addRequest);
|
||||
// 保存品牌
|
||||
ProductBrandBO result = productBrandService.addProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandAddDTO);
|
||||
// 返回结果
|
||||
return success(ProductBrandConvert.INSTANCE.convert(result));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("更新商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
|
||||
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
|
||||
@ApiImplicitParam(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn"),
|
||||
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
|
||||
})
|
||||
// TODO FROM 芋艿 to q2118cs:只要改成了 bean 接收,就不用在写 @ApiImplicitParam 注解啦,直接在 bean 里写就 ok 啦
|
||||
public CommonResult<Boolean> update(@Validated ProductBrandUpdateRequest updateRequest) {
|
||||
// 创建 productBrandUpdateDTO 对象
|
||||
ProductBrandUpdateDTO productBrandUpdateDTO = ProductBrandConvert.INSTANCE.convertUpdate(updateRequest);
|
||||
// 更新商品
|
||||
return success(productBrandService.updateProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandUpdateDTO));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获取品牌")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1")
|
||||
})
|
||||
public CommonResult<AdminsProductBrandResponse> add(@RequestParam("id") Integer id) {
|
||||
// 保存商品
|
||||
ProductBrandBO result = productBrandService.getProductBrand(id);
|
||||
// 返回结果
|
||||
return success(ProductBrandConvert.INSTANCE.convert(result));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得品牌分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
|
||||
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
|
||||
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码", required = true, example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, example = "10")
|
||||
})
|
||||
public CommonResult<PageResult<AdminsProductBrandResponse>> attrPage(ProductBrandPageRequest pageRequest) {
|
||||
// 创建 ProductBrandPageDTO 对象
|
||||
ProductBrandPageDTO productBrandPageDTO = ProductBrandConvert.INSTANCE.convertPageRequest(pageRequest);
|
||||
// 查询分页
|
||||
PageResult<ProductBrandBO> productBrandPage = productBrandService.getProductBrandPage(productBrandPageDTO);
|
||||
PageResult<AdminsProductBrandResponse> adminPageResponse = ProductBrandConvert.INSTANCE.convertPage(productBrandPage);
|
||||
return CommonResult.success(adminPageResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -23,13 +23,6 @@ public interface ProductAttrService {
|
||||
*/
|
||||
List<ProductAttrSimpleBO> getProductAttrList();
|
||||
|
||||
ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO);
|
||||
|
||||
Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO);
|
||||
|
||||
Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId,
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
|
||||
|
||||
ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO);
|
||||
|
||||
Boolean updateProductAttrValue(Integer adminId, ProductAttrValueUpdateDTO productAttrValueUpdateDTO);
|
||||
|
||||
@@ -74,58 +74,6 @@ public class ProductAttrServiceImpl implements ProductAttrService {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductAttrBO addProductAttr(Integer adminId, ProductAttrAddDTO productAttrAddDTO) {
|
||||
// 校验规格名不重复
|
||||
if (productAttrMapper.selectByName(productAttrAddDTO.getName()) != null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
|
||||
}
|
||||
// 插入到数据库
|
||||
ProductAttrDO productAttrDO = ProductAttrConvert.INSTANCE.convert(productAttrAddDTO)
|
||||
.setStatus(ProductAttrConstants.ATTR_STATUS_ENABLE);
|
||||
productAttrDO.setCreateTime(new Date());
|
||||
productAttrDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
productAttrMapper.insert(productAttrDO);
|
||||
// 返回成功
|
||||
return ProductAttrConvert.INSTANCE.convert(productAttrDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateProductAttr(Integer adminId, ProductAttrUpdateDTO productAttrUpdateDTO) {
|
||||
// 校验存在
|
||||
if (productAttrMapper.selectById(productAttrUpdateDTO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
|
||||
}
|
||||
// 校验规格名不重复
|
||||
ProductAttrDO existsAttrDO = productAttrMapper.selectByName(productAttrUpdateDTO.getName());
|
||||
if (existsAttrDO != null && !existsAttrDO.getId().equals(productAttrUpdateDTO.getId())) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_EXISTS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrDO updateProductAttr = ProductAttrConvert.INSTANCE.convert(productAttrUpdateDTO);
|
||||
productAttrMapper.update(updateProductAttr);
|
||||
// 返回成功
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateProductAttrStatus(Integer adminId, Integer productAttrId, Integer status) {
|
||||
// 校验存在
|
||||
ProductAttrDO productAttrDO = productAttrMapper.selectById(productAttrId);
|
||||
if (productAttrDO == null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_NOT_EXIST.getCode());
|
||||
}
|
||||
// 校验状态
|
||||
if (productAttrDO.getStatus().equals(status)) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_ATTR_STATUS_EQUALS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductAttrDO updateProductAttr = new ProductAttrDO().setId(productAttrId).setStatus(status);
|
||||
productAttrMapper.update(updateProductAttr);
|
||||
// 返回成功
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductAttrValueBO addProductAttrValue(Integer adminId, ProductAttrValueAddDTO productAttrValueAddDTO) {
|
||||
// 校验规格名不重复
|
||||
|
||||
@@ -29,66 +29,6 @@ import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
@Api("商品 SPU + SKU")
|
||||
public class AdminsProductSpuController {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.provider.ProductSpuService.version}")
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@PostMapping("/spu/add")
|
||||
@ApiOperation("创建商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "SPU 名字", required = true, example = "厮大牛逼"),
|
||||
@ApiImplicitParam(name = "sellPoint", value = "卖点", required = true, example = "各种 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "description", value = "描述", required = true, example = "你就说强不强 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "cid", value = "分类编号", required = true, example = "反正我是信了"),
|
||||
@ApiImplicitParam(name = "picUrls", value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn"),
|
||||
@ApiImplicitParam(name = "visible", value = "是否上架商品(是否可见)", required = true, example = "true"),
|
||||
@ApiImplicitParam(name = "skuStr", value = "SKU 字符串", required = true, example = "[{\"attrs\": [1,3 ], \"price\": 1, \"quantity\": 100, \"picUrl\": \"http://www.iocoder.cn\"}]"),
|
||||
})
|
||||
public CommonResult<AdminsProductSpuDetailVO> add(@RequestParam("name") String name,
|
||||
@RequestParam("sellPoint") String sellPoint,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("cid") Integer cid,
|
||||
@RequestParam("picUrls") List<String> picUrls,
|
||||
@RequestParam("visible") Boolean visible,
|
||||
@RequestParam("skuStr") String skuStr) { // TODO 芋艿,因为考虑不使用 json 接受参数,所以这里手动转。
|
||||
// 创建 ProductSpuAddDTO 对象
|
||||
ProductSpuAddDTO productSpuAddDTO = new ProductSpuAddDTO().setName(name).setSellPoint(sellPoint)
|
||||
.setDescription(description).setCid(cid).setPicUrls(picUrls).setVisible(visible)
|
||||
.setSkus(parseSkus(skuStr, ProductSkuAddOrUpdateDTO.class));
|
||||
// 保存商品
|
||||
ProductSpuDetailBO result = productSpuService.addProductSpu(AdminSecurityContextHolder.getContext().getAdminId(), productSpuAddDTO);
|
||||
// 返回结果
|
||||
return success(ProductSpuConvert.INSTANCE.convert(result));
|
||||
}
|
||||
|
||||
@PostMapping("/spu/update")
|
||||
@ApiOperation("更新商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "SPU 编号", required = true, example = "100"),
|
||||
@ApiImplicitParam(name = "name", value = "SPU 名字", required = true, example = "厮大牛逼"),
|
||||
@ApiImplicitParam(name = "sellPoint", value = "卖点", required = true, example = "各种 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "description", value = "描述", required = true, example = "你就说强不强 MQ 骚操作"),
|
||||
@ApiImplicitParam(name = "cid", value = "分类编号", required = true, example = "反正我是信了"),
|
||||
@ApiImplicitParam(name = "picUrls", value = "商品主图地址的数组", required = true, example = "http://www.iocoder.cn"),
|
||||
@ApiImplicitParam(name = "visible", value = "是否上架商品(是否可见)", required = true, example = "true"),
|
||||
@ApiImplicitParam(name = "skuStr", value = "SKU 字符串", required = true, example = "[{\"attrs\": [1,3 ], \"price\": 1, \"quantity\": 100, \"picUrl\": \"http://www.iocoder.cn\"}]"),
|
||||
})
|
||||
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("sellPoint") String sellPoint,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("cid") Integer cid,
|
||||
@RequestParam("picUrls") List<String> picUrls,
|
||||
@RequestParam("visible") Boolean visible,
|
||||
@RequestParam("skuStr") String skuStr) { // TODO 芋艿,因为考虑不使用 json 接受参数,所以这里手动转。
|
||||
// 创建 ProductSpuUpdateDTO 对象
|
||||
ProductSpuUpdateDTO productSpuUpdateDTO = new ProductSpuUpdateDTO().setId(id).setName(name).setSellPoint(sellPoint)
|
||||
.setDescription(description).setCid(cid).setPicUrls(picUrls).setVisible(visible)
|
||||
.setSkus(parseSkus(skuStr, ProductSkuAddOrUpdateDTO.class));
|
||||
// 更新商品
|
||||
productSpuService.updateProductSpu(AdminSecurityContextHolder.getContext().getAdminId(), productSpuUpdateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/spu/update_sort")
|
||||
@ApiOperation("更新商品的排序")
|
||||
public CommonResult<Boolean> updateSort(@RequestParam("id") Integer id,
|
||||
@@ -96,39 +36,6 @@ public class AdminsProductSpuController {
|
||||
return success(productSpuService.updateProductSpuSort(AdminSecurityContextHolder.getContext().getAdminId(), id, sort));
|
||||
}
|
||||
|
||||
// TODO 芋艿,删除功能暂时不做。主要原因是,关联的数据太多。删除带来的问题会比较大
|
||||
|
||||
@GetMapping("/spu/page")
|
||||
@ApiOperation("商品 SPU 分页列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "name", value = "商品名称,模糊匹配", example = "小王"),
|
||||
@ApiImplicitParam(name = "status", value = "状态", example = "可选值:1-在售中;2-已售罄;3-仓库中;"),
|
||||
@ApiImplicitParam(name = "cid", value = "商品分类编号", example = "10"),
|
||||
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
||||
})
|
||||
public CommonResult<AdminsProductSpuPageVO> spuPage(@RequestParam(value = "name", required = false) String name,
|
||||
@RequestParam(value = "status") Integer status,
|
||||
@RequestParam(value = "cid", required = false) Integer cid,
|
||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
// 创建 ProductSpuPageDTO 对象
|
||||
ProductSpuPageDTO productSpuPageDTO = new ProductSpuPageDTO().setName(name).setCid(cid).setPageNo(pageNo).setPageSize(pageSize);
|
||||
switch (status) {
|
||||
case 1:
|
||||
productSpuPageDTO.setVisible(true).setHasQuantity(true);
|
||||
break;
|
||||
case 2:
|
||||
productSpuPageDTO.setVisible(true).setHasQuantity(false);
|
||||
break;
|
||||
case 3:
|
||||
productSpuPageDTO.setVisible(false);
|
||||
break;
|
||||
}
|
||||
ProductSpuPageBO result = productSpuService.getProductSpuPage(productSpuPageDTO);
|
||||
return success(ProductSpuConvert.INSTANCE.convert2(result));
|
||||
}
|
||||
|
||||
@GetMapping("/spu/search_list")
|
||||
@ApiOperation("商品 SPU 搜索列表")
|
||||
@ApiImplicitParams({
|
||||
|
||||
Reference in New Issue
Block a user