diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrandBO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/brand/ProductBrandBO.java similarity index 91% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrandBO.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/brand/ProductBrandBO.java index 4bf95a29..6dcdcc99 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrandBO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/brand/ProductBrandBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.product.biz.bo.product; +package cn.iocoder.mall.product.biz.bo.brand; import lombok.Data; import lombok.experimental.Accessors; diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrangPageBO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrangPageBO.java index c80d6b0d..5c3e6d96 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrangPageBO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/bo/product/ProductBrangPageBO.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.product.biz.bo.product; +import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO; import lombok.Data; import lombok.experimental.Accessors; diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/product/ProductBrandConvert.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/brand/ProductBrandConvert.java similarity index 55% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/product/ProductBrandConvert.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/brand/ProductBrandConvert.java index 6e18c841..7c7e64d2 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/product/ProductBrandConvert.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/convert/brand/ProductBrandConvert.java @@ -1,10 +1,13 @@ -package cn.iocoder.mall.product.biz.convert.product; +package cn.iocoder.mall.product.biz.convert.brand; -import cn.iocoder.mall.product.biz.bo.product.ProductBrandBO; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO; import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO; -import cn.iocoder.mall.product.biz.dto.product.ProductBrandAddDTO; -import cn.iocoder.mall.product.biz.dto.product.ProductBrandUpdateDTO; +import cn.iocoder.mall.product.biz.dto.brand.ProductBrandAddDTO; +import cn.iocoder.mall.product.biz.dto.brand.ProductBrandUpdateDTO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; @@ -15,6 +18,9 @@ public interface ProductBrandConvert { ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class); + @Mapping(source = "records", target = "list") + PageResult convertPage(IPage bean); + @Mappings({}) List convert(List brands); @@ -26,5 +32,4 @@ public interface ProductBrandConvert { @Mappings({}) ProductBrandDO convert(ProductBrandAddDTO brand); - } \ No newline at end of file diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/product/ProductBrandMapper.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/product/ProductBrandMapper.java index 5d79a4a1..f83f77c2 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/product/ProductBrandMapper.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dao/product/ProductBrandMapper.java @@ -1,11 +1,25 @@ package cn.iocoder.mall.product.biz.dao.product; import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO; +import cn.iocoder.mall.product.biz.dto.brand.ProductBrandPageDTO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Repository; @Repository public interface ProductBrandMapper extends BaseMapper { - + default IPage selectListByParams(ProductBrandPageDTO productBrandPageDTO) { + Page page = new Page<>(productBrandPageDTO.getPageNo(), productBrandPageDTO.getPageSize()); + LambdaQueryWrapper queryWrapper = Wrappers.query().lambda() + .like(StringUtils.isNotBlank(productBrandPageDTO.getName()), ProductBrandDO::getName, productBrandPageDTO.getName()) + .like(StringUtils.isNotBlank(productBrandPageDTO.getDescription()), ProductBrandDO::getName, productBrandPageDTO.getDescription()) + .eq(null != productBrandPageDTO.getStatus(), ProductBrandDO::getName, productBrandPageDTO.getStatus()) + .eq(ProductBrandDO::getDeleted, false); + return selectPage(page, queryWrapper); + } } \ No newline at end of file diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dataobject/product/ProductBrandDO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dataobject/product/ProductBrandDO.java index 18b3c62a..7ef63576 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dataobject/product/ProductBrandDO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dataobject/product/ProductBrandDO.java @@ -2,12 +2,14 @@ package cn.iocoder.mall.product.biz.dataobject.product; import cn.iocoder.mall.mybatis.dataobject.DeletableDO; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** * Product 品牌 */ @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) public class ProductBrandDO extends DeletableDO { @@ -32,7 +34,7 @@ public class ProductBrandDO extends DeletableDO { /** * 状态 - * + *

* 1-开启 * 2-禁用 */ diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/attr/AdminProductAttrPageDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/attr/ProductAttrPageDTO.java similarity index 86% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/attr/AdminProductAttrPageDTO.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/attr/ProductAttrPageDTO.java index 9b0aa0a8..e6d23c62 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/attr/AdminProductAttrPageDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/attr/ProductAttrPageDTO.java @@ -11,7 +11,7 @@ import lombok.experimental.Accessors; @Data @Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -public class AdminProductAttrPageDTO extends PageParam { +public class ProductAttrPageDTO extends PageParam { /** * 商品规格名字 */ diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandAddDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandAddDTO.java similarity index 93% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandAddDTO.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandAddDTO.java index bda1d92a..9b345eec 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandAddDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandAddDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.product.biz.dto.product; +package cn.iocoder.mall.product.biz.dto.brand; import lombok.Data; import lombok.experimental.Accessors; diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandPageDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandPageDTO.java similarity index 53% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandPageDTO.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandPageDTO.java index cbd50fe8..63255b5e 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandPageDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandPageDTO.java @@ -1,16 +1,17 @@ -package cn.iocoder.mall.product.biz.dto.product; +package cn.iocoder.mall.product.biz.dto.brand; +import cn.iocoder.common.framework.vo.PageParam; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -import javax.validation.constraints.NotNull; - /** * 商品品牌分页 DTO */ @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -public class ProductBrandPageDTO { +public class ProductBrandPageDTO extends PageParam { /** * 名称 @@ -27,10 +28,4 @@ public class ProductBrandPageDTO { */ private Integer status; - @NotNull(message = "页码不能为空") - private Integer pageNo; - - @NotNull(message = "每页条数不能为空") - private Integer pageSize; - } diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandUpdateDTO.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandUpdateDTO.java similarity index 94% rename from product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandUpdateDTO.java rename to product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandUpdateDTO.java index b64d0bd6..c977f8a0 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/product/ProductBrandUpdateDTO.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/dto/brand/ProductBrandUpdateDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.product.biz.dto.product; +package cn.iocoder.mall.product.biz.dto.brand; import lombok.Data; import lombok.experimental.Accessors; diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductAttrService.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductAttrService.java index ccccac87..4cb93a0d 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductAttrService.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductAttrService.java @@ -20,7 +20,7 @@ public interface ProductAttrService { * @param productAttrPageDTO 查询参数 * @return 规格分页信息 */ - PageResult getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO); + PageResult getProductAttrPage(ProductAttrPageDTO productAttrPageDTO); /** * 获得规格属性数组 diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductBrandService.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductBrandService.java new file mode 100644 index 00000000..71115805 --- /dev/null +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/ProductBrandService.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.product.biz.service.product; + + +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; + +public interface ProductBrandService { + + /** + * 获取品牌分页数据 + * + * @param productBrandPageDTO 翻页参数 + * @return + */ + PageResult getProductBrandPage(ProductBrandPageDTO productBrandPageDTO); + + /** + * 获取品牌明细 + * + * @param id 主键 + * @return + */ + ProductBrandBO getProductBrand(Integer id); + + /** + * 添加品牌 + * + * @param productBrandAddDTO 添加参数 + * @return + */ + ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO); + + /** + * 更新品牌 + * + * @param productBrandUpdateDTO 更新参数 + * @return + */ + Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO); + + +} diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductAttrServiceImpl.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductAttrServiceImpl.java index 7abfb38d..2c493eaa 100644 --- a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductAttrServiceImpl.java +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductAttrServiceImpl.java @@ -44,7 +44,7 @@ public class ProductAttrServiceImpl implements ProductAttrService { private ProductAttrValueMapper productAttrValueMapper; @Override - public PageResult getProductAttrPage(AdminProductAttrPageDTO productAttrPageDTO) { + public PageResult getProductAttrPage(ProductAttrPageDTO productAttrPageDTO) { //查询分页 Page page = new Page<>(productAttrPageDTO.getPageNo(), productAttrPageDTO.getPageSize()); LambdaQueryWrapper queryWrapper = Wrappers.query().lambda() diff --git a/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductBrandServiceImpl.java b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductBrandServiceImpl.java new file mode 100644 index 00000000..404fd843 --- /dev/null +++ b/product/product-biz/src/main/java/cn/iocoder/mall/product/biz/service/product/impl/ProductBrandServiceImpl.java @@ -0,0 +1,67 @@ +package cn.iocoder.mall.product.biz.service.product.impl; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; +import cn.iocoder.mall.product.biz.bo.brand.ProductBrandBO; +import cn.iocoder.mall.product.biz.convert.brand.ProductBrandConvert; +import cn.iocoder.mall.product.biz.dao.product.ProductBrandMapper; +import cn.iocoder.mall.product.biz.dataobject.product.ProductBrandDO; +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.enums.ProductErrorCodeEnum; +import cn.iocoder.mall.product.biz.service.product.ProductBrandService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** + * 商品规格 Service 实现类 + * + * @see ProductBrandDO + */ +@Service +public class ProductBrandServiceImpl implements ProductBrandService { + + @Autowired + private ProductBrandMapper productBrandMapper; + + @Override + public PageResult getProductBrandPage(ProductBrandPageDTO productBrandPageDTO) { + IPage brandPage = productBrandMapper.selectListByParams(productBrandPageDTO); + return ProductBrandConvert.INSTANCE.convertPage(brandPage); + } + + @Override + public ProductBrandBO getProductBrand(Integer brandId) { + return ProductBrandConvert.INSTANCE.convert(productBrandMapper.selectById(brandId)); + } + + @Override + public ProductBrandBO addProductBrand(Integer adminId, ProductBrandAddDTO productBrandAddDTO) { + // 校验品牌名不重复 + int count = productBrandMapper.selectCount(Wrappers.query().lambda() + .eq(ProductBrandDO::getName, productBrandAddDTO.getName()) + .eq(ProductBrandDO::getDeleted, false)); + if (count > 0) { + throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_BRAND_EXIST.getCode()); + } + ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandAddDTO); + productBrandDO.setCreateTime(new Date()); + productBrandDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); + productBrandMapper.insert(productBrandDO); + return ProductBrandConvert.INSTANCE.convert(productBrandDO); + } + + @Override + public Boolean updateProductBrand(Integer adminId, ProductBrandUpdateDTO productBrandUpdateDTO) { + ProductBrandDO productBrandDO = ProductBrandConvert.INSTANCE.convert(productBrandUpdateDTO); + productBrandDO.setUpdateTime(new Date()); + productBrandMapper.updateById(productBrandDO); + return true; + } +} diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductAttrController.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductAttrController.java index fd46ee49..7e10229b 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductAttrController.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductAttrController.java @@ -9,13 +9,13 @@ import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO; import cn.iocoder.mall.product.biz.dto.attr.*; import cn.iocoder.mall.product.biz.service.product.ProductAttrService; import cn.iocoder.mall.product.rest.convert.attr.ProductAttrConvert; -import cn.iocoder.mall.product.rest.request.attr.AdminProductAttrPageRequest; +import cn.iocoder.mall.product.rest.request.attr.ProductAttrPageRequest; import cn.iocoder.mall.product.rest.request.attr.ProductAttrAddRequest; import cn.iocoder.mall.product.rest.request.attr.ProductAttrUpdateRequest; import cn.iocoder.mall.product.rest.request.attr.ProductAttrValueAddRequest; import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrPageResponse; import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrSimpleResponse; -import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrVO; +import cn.iocoder.mall.product.rest.response.attr.AdminsProdutAttrResponse; import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrValueResponse; import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder; import io.swagger.annotations.Api; @@ -45,8 +45,8 @@ public class AdminsProductAttrController { @GetMapping("/attr/page") @ApiOperation("获得规格分页") - public CommonResult> attrPage(AdminProductAttrPageRequest request) { - AdminProductAttrPageDTO pageDTO = ProductAttrConvert.INSTANCE.convert(request); + public CommonResult> attrPage(ProductAttrPageRequest request) { + ProductAttrPageDTO pageDTO = ProductAttrConvert.INSTANCE.convert(request); PageResult productAttrPage = productAttrService.getProductAttrPage(pageDTO); PageResult adminPageResponse = ProductAttrConvert.INSTANCE.convertPage(productAttrPage); return CommonResult.success(adminPageResponse); @@ -62,7 +62,7 @@ public class AdminsProductAttrController { @PostMapping("/attr/add") @ApiOperation(value = "创建商品规格") - public CommonResult addAttr(@Validated ProductAttrAddRequest addRequest) { + public CommonResult addAttr(@Validated ProductAttrAddRequest addRequest) { // 创建 ProductAttrAddDTO 对象 ProductAttrAddDTO productAttrAddDTO = new ProductAttrAddDTO().setName(addRequest.getName()); // 添加 diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductBrandController.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductBrandController.java new file mode 100644 index 00000000..8a31cd68 --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/controller/admins/AdminsProductBrandController.java @@ -0,0 +1,90 @@ +package cn.iocoder.mall.product.rest.controller.admins; + +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.product.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 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("商品品牌") +public class AdminsProductBrandController { + + private ProductBrandService productBrandService; + + @PostMapping("/add") + @ApiOperation("创建品牌") + public CommonResult 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") + }) + public CommonResult 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 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> attrPage(ProductBrandPageRequest pageRequest) { + // 创建 ProductBrandPageDTO 对象 + ProductBrandPageDTO productBrandPageDTO = ProductBrandConvert.INSTANCE.convertPageRequest(pageRequest); + // 查询分页 + PageResult productBrandPage = productBrandService.getProductBrandPage(productBrandPageDTO); + PageResult adminPageResponse = ProductBrandConvert.INSTANCE.convertPage(productBrandPage); + return CommonResult.success(adminPageResponse); + } + + +} diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/attr/ProductAttrConvert.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/attr/ProductAttrConvert.java index c6b315c8..0e5e571c 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/attr/ProductAttrConvert.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/attr/ProductAttrConvert.java @@ -5,13 +5,13 @@ import cn.iocoder.mall.product.biz.bo.attr.ProductAttrBO; import cn.iocoder.mall.product.biz.bo.attr.ProductAttrSimpleWithValueBO; import cn.iocoder.mall.product.biz.bo.attr.ProductAttrValueBO; import cn.iocoder.mall.product.biz.bo.attr.ProductAttrWithValueBO; -import cn.iocoder.mall.product.biz.dto.attr.AdminProductAttrPageDTO; +import cn.iocoder.mall.product.biz.dto.attr.ProductAttrPageDTO; import cn.iocoder.mall.product.biz.dto.attr.ProductAttrUpdateDTO; -import cn.iocoder.mall.product.rest.request.attr.AdminProductAttrPageRequest; +import cn.iocoder.mall.product.rest.request.attr.ProductAttrPageRequest; import cn.iocoder.mall.product.rest.request.attr.ProductAttrUpdateRequest; import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrPageResponse; import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrSimpleResponse; -import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrVO; +import cn.iocoder.mall.product.rest.response.attr.AdminsProdutAttrResponse; import cn.iocoder.mall.product.rest.response.attr.AdminsProductAttrValueResponse; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -25,7 +25,7 @@ public interface ProductAttrConvert { ProductAttrConvert INSTANCE = Mappers.getMapper(ProductAttrConvert.class); @Mappings({}) - AdminProductAttrPageDTO convert(AdminProductAttrPageRequest bean); + ProductAttrPageDTO convert(ProductAttrPageRequest bean); @Mappings({}) PageResult convertPage(PageResult productAttrPage); @@ -34,7 +34,7 @@ public interface ProductAttrConvert { List convertSimple(List simpleList); @Mappings({}) - AdminsProductAttrVO convertAttr(ProductAttrBO attrBO); + AdminsProdutAttrResponse convertAttr(ProductAttrBO attrBO); @Mappings({}) ProductAttrUpdateDTO convertUpdate(ProductAttrUpdateRequest updateRequest); diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/brand/ProductBrandConvert.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/brand/ProductBrandConvert.java new file mode 100644 index 00000000..2110b753 --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/convert/brand/ProductBrandConvert.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.product.rest.convert.brand; + +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.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 org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ProductBrandConvert { + + ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class); + + @Mappings({}) + AdminsProductBrandResponse convert(ProductBrandBO brand); + + @Mappings({}) + ProductBrandAddDTO convertAdd(ProductBrandAddRequest addRequest); + + @Mappings({}) + ProductBrandUpdateDTO convertUpdate(ProductBrandUpdateRequest updateRequest); + + @Mappings({}) + ProductBrandPageDTO convertPageRequest(ProductBrandPageRequest pageRequest); + + @Mappings({}) + PageResult convertPage(PageResult productBrandPage); +} \ No newline at end of file diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrAddRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrAddRequest.java index 9ceb12f9..a155d1f6 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrAddRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrAddRequest.java @@ -1,14 +1,13 @@ package cn.iocoder.mall.product.rest.request.attr; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; -/** - * 规格添加 - */ +@ApiModel("商品 - 规格模块 - 商品规格添加 Request") @Data @Accessors(chain = true) public class ProductAttrAddRequest { diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/AdminProductAttrPageRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrPageRequest.java similarity index 89% rename from product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/AdminProductAttrPageRequest.java rename to product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrPageRequest.java index 7b663875..fee12d92 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/AdminProductAttrPageRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrPageRequest.java @@ -11,7 +11,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -public class AdminProductAttrPageRequest extends PageParam { +public class ProductAttrPageRequest extends PageParam { @ApiModelProperty(value = "商品规格名字,模糊匹配", example = "材料") private String name; diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrUpdateRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrUpdateRequest.java index 745a34f5..b7dad4fd 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrUpdateRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrUpdateRequest.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.product.rest.request.attr; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -7,9 +8,7 @@ import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** - * 规格修改 - */ +@ApiModel("商品 - 规格模块 - 商品规格修改 Request") @Data @Accessors(chain = true) public class ProductAttrUpdateRequest { diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueAddRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueAddRequest.java index 244d8f18..c60d4bc7 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueAddRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueAddRequest.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.product.rest.request.attr; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -7,9 +8,7 @@ import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -/** - * Product 规格值添加 DTO - */ +@ApiModel("商品 - 规格模块 - 商品规格值添加 Request") @Data @Accessors(chain = true) public class ProductAttrValueAddRequest { diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueUpdateRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueUpdateRequest.java index e2cabaa8..a12bc81f 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueUpdateRequest.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/attr/ProductAttrValueUpdateRequest.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.product.rest.request.attr; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; @@ -12,6 +13,7 @@ import javax.validation.constraints.NotNull; *

* 注意,不允许修改所属规格 */ +@ApiModel("商品 - 规格模块 - 商品规格值修改 Request") @Data @Accessors(chain = true) public class ProductAttrValueUpdateRequest { diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandAddRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandAddRequest.java new file mode 100644 index 00000000..6eea75cc --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandAddRequest.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.product.rest.request.brand; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; + +@ApiModel("商品 - 品牌模块 - 商品品牌新增 Request") +@Data +@Accessors(chain = true) +public class ProductBrandAddRequest { + + @ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏") + @NotEmpty(message = "品牌名称不能为空") + private String name; + + @ApiModelProperty(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋") + private String description; + + @ApiModelProperty(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn") + private String picUrl; + + @ApiModelProperty(name = "status", value = "状态 1开启 2禁用", required = true, example = "1") + private Integer status; +} diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandPageRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandPageRequest.java new file mode 100644 index 00000000..24c038f6 --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandPageRequest.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.product.rest.request.brand; + +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +@ApiModel("商品 - 品牌模块 - 品牌分页 Request") +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class ProductBrandPageRequest extends PageParam { + + @ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏") + private String name; + + @ApiModelProperty(name = "name", value = "品牌描述", required = true, example = "安踏拖鞋") + private String description; + + @ApiModelProperty(name = "name", value = "状态 1开启 2禁用", required = true, example = "1") + private String status; +} diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandUpdateRequest.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandUpdateRequest.java new file mode 100644 index 00000000..de429c72 --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/request/brand/ProductBrandUpdateRequest.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.product.rest.request.brand; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("商品 - 品牌模块 - 商品品牌更新 Request") +@Data +@Accessors(chain = true) +public class ProductBrandUpdateRequest { + + @ApiModelProperty(name = "id", value = "规格编号", required = true, example = "1") + @NotNull(message = "品牌编号不能为空") + private Integer id; + + @ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏") + @NotEmpty(message = "品牌名称不能为空") + private String name; + + @ApiModelProperty(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋") + private String description; + + @ApiModelProperty(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn") + private String picUrl; + + @ApiModelProperty(name = "status", value = "状态 1开启 2禁用", required = true, example = "1") + private Integer status; +} diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProductAttrVO.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProductAttrVO.java deleted file mode 100644 index 5d62ffb7..00000000 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProductAttrVO.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.mall.product.rest.response.attr; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -@ApiModel(value = "商品规格 VO", description = "不带有规格值数组") -@Data -@Accessors(chain = true) -public class AdminsProductAttrVO { - - @ApiModelProperty(value = "规格编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "规格名", required = true, example = "颜色") - private String name; - @ApiModelProperty(value = "状态", required = true, example = "1") - private Integer status; - @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") - private Date createTime; - -} diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProdutAttrResponse.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProdutAttrResponse.java index 3ca9c333..04d7f6e0 100644 --- a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProdutAttrResponse.java +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/attr/AdminsProdutAttrResponse.java @@ -1,4 +1,24 @@ package cn.iocoder.mall.product.rest.response.attr; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@ApiModel(value = "商品规格 VO", description = "不带有规格值数组") +@Data +@Accessors(chain = true) public class AdminsProdutAttrResponse { + + @ApiModelProperty(value = "规格编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "规格名", required = true, example = "颜色") + private String name; + @ApiModelProperty(value = "状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳") + private Date createTime; + } diff --git a/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/brand/AdminsProductBrandResponse.java b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/brand/AdminsProductBrandResponse.java new file mode 100644 index 00000000..fad12f1c --- /dev/null +++ b/product/product-rest/src/main/java/cn/iocoder/mall/product/rest/response/brand/AdminsProductBrandResponse.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.product.rest.response.brand; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; + +/** + * VO + */ +@ApiModel(value = "商品品牌", description = "商品品牌") +@Data +@Accessors(chain = true) +public class AdminsProductBrandResponse { + /** + * 规格编号 + */ + @ApiModelProperty(value = "品牌编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(name = "name", value = "品牌名称", required = true, example = "安踏") + @NotEmpty(message = "品牌名称不能为空") + private String name; + + @ApiModelProperty(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋") + private String description; + + @ApiModelProperty(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn") + private String picUrl; + + @ApiModelProperty(name = "status", value = "状态 1开启 2禁用", required = true, example = "1") + private Integer status; + +}