mall:code review 商品的代码

This commit is contained in:
YunaiV 2022-09-05 21:02:44 +08:00
parent 2cc60deb97
commit c06077e3a6
27 changed files with 126 additions and 485 deletions

View File

@ -1,27 +1,9 @@
package cn.iocoder.yudao.module.product.controller.admin.sku;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "管理后台 - 商品 sku")
@RestController
@ -29,57 +11,4 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
public class ProductSkuController {
@Resource
private ProductSkuService ProductSkuService;
@PostMapping("/create")
@ApiOperation("创建商品sku")
@PreAuthorize("@ss.hasPermission('product:sku:create')")
public CommonResult<Long> createSku(@Valid @RequestBody ProductSkuCreateOrUpdateReqVO createReqVO) {
return success(ProductSkuService.createSku(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新商品sku")
@PreAuthorize("@ss.hasPermission('product:sku:update')")
public CommonResult<Boolean> updateSku(@Valid @RequestBody ProductSkuUpdateReqVO updateReqVO) {
ProductSkuService.updateSku(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除商品sku")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:sku:delete')")
public CommonResult<Boolean> deleteSku(@RequestParam("id") Long id) {
ProductSkuService.deleteSku(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得商品sku")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<ProductSkuRespVO> getSku(@RequestParam("id") Long id) {
ProductSkuDO sku = ProductSkuService.getSku(id);
return success(ProductSkuConvert.INSTANCE.convert(sku));
}
@GetMapping("/list")
@ApiOperation("获得商品sku列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<List<ProductSkuRespVO>> getSkuList(@RequestParam("ids") Collection<Long> ids) {
List<ProductSkuDO> list = ProductSkuService.getSkuList(ids);
return success(ProductSkuConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得商品sku分页")
@PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<PageResult<ProductSkuRespVO>> getSkuPage(@Valid ProductSkuPageReqVO pageVO) {
PageResult<ProductSkuDO> pageResult = ProductSkuService.getSkuPage(pageVO);
return success(ProductSkuConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -8,7 +8,6 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 商品 SKU Base VO提供给添加修改详细的子 VO 使用
@ -21,11 +20,6 @@ public class ProductSkuBaseVO {
@NotEmpty(message = "商品 SKU 名字不能为空")
private String name;
/**
* 规格值数组
*/
private List<Property> properties;
@ApiModelProperty(value = "销售价格,单位:分", required = true, example = "1024", notes = "单位:分")
@NotNull(message = "销售价格,单位:分不能为空")
private Integer price;

View File

@ -6,6 +6,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
@ApiModel("管理后台 - 商品 SKU 创建/更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ -16,4 +18,9 @@ public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "商品 id 更新时须有", example = "1")
private Long id;
/**
* 规格值数组
*/
private List<Property> properties;
}

View File

@ -1,53 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 商品sku Excel VO
*
* @author 芋道源码
*/
@Data
public class ProductSkuExcelVO {
@ExcelProperty("主键")
private Long id;
@ExcelProperty("spu编号")
private Long spuId;
// TODO @franky这个单元格可能会有点展示的问题
@ExcelProperty("规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]")
private List<Property> properties;
@ExcelProperty("销售价格,单位:分")
private Integer price;
@ExcelProperty("原价, 单位: 分")
private Integer originalPrice;
@ExcelProperty("成本价,单位: 分")
private Integer costPrice;
@ExcelProperty("条形码")
private String barCode;
@ExcelProperty("图片地址")
private String picUrl;
@ExcelProperty("状态: 0-正常 1-禁用")
private Integer status;
@ExcelProperty("创建时间")
private Date createTime;
@Data
public static class Property {
private Integer propertyId;
private Integer valueId;
}
}

View File

@ -1,43 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel(value = "管理后台 - 商品sku Excel 导出 Request VO", description = "参数和 SkuPageReqVO 是一致的")
@Data
public class ProductSkuExportReqVO {
@ApiModelProperty(value = "spu编号")
private Long spuId;
@ApiModelProperty(value = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]")
private String properties;
@ApiModelProperty(value = "销售价格,单位:分")
private Integer price;
@ApiModelProperty(value = "原价, 单位: 分")
private Integer originalPrice;
@ApiModelProperty(value = "成本价,单位: 分")
private Integer costPrice;
@ApiModelProperty(value = "条形码")
private String barCode;
@ApiModelProperty(value = "图片地址")
private String picUrl;
@ApiModelProperty(value = "状态: 0-正常 1-禁用")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "创建时间")
private Date[] createTime;
}

View File

@ -1,45 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("管理后台 - 商品sku分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSkuPageReqVO extends PageParam {
@ApiModelProperty(value = "spu编号")
private Long spuId;
@ApiModelProperty(value = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]")
private String properties;
@ApiModelProperty(value = "销售价格,单位:分")
private Integer price;
@ApiModelProperty(value = "原价, 单位: 分")
private Integer originalPrice;
@ApiModelProperty(value = "成本价,单位: 分")
private Integer costPrice;
@ApiModelProperty(value = "条形码")
private String barCode;
@ApiModelProperty(value = "图片地址")
private String picUrl;
@ApiModelProperty(value = "状态: 0-正常 1-禁用")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ApiModelProperty(value = "创建时间")
private Date[] createTime;
}

View File

@ -1,8 +1,13 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Date;
import java.util.List;
@ApiModel("管理后台 - 商品sku Response VO")
@Data
@ -10,10 +15,15 @@ import io.swagger.annotations.*;
@ToString(callSuper = true)
public class ProductSkuRespVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "主键", required = true)
@ApiModelProperty(value = "主键", required = true, example = "1024")
private Long id;
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 规格值数组
*/
private List<Property> properties;
}

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import lombok.*;
import java.util.*;
import io.swagger.annotations.*;
import javax.validation.constraints.*;
@ApiModel("管理后台 - 商品sku更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSkuUpdateReqVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空")
private Long id;
}

View File

@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.product.controller.admin.spu;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
@ -48,7 +48,7 @@ public class ProductSpuController {
}
@DeleteMapping("/delete")
@ApiOperation("删除商品spu")
@ApiOperation("删除商品 SPU")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:spu:delete')")
public CommonResult<Boolean> deleteSpu(@RequestParam("id") Long id) {
@ -57,26 +57,28 @@ public class ProductSpuController {
}
@GetMapping("/get")
@ApiOperation("获得商品spu")
@ApiOperation("获得商品 SPU")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<SpuRespVO> getSpu(@RequestParam("id") Long id) {
public CommonResult<ProductSpuRespVO> getSpu(@RequestParam("id") Long id) {
return success(spuService.getSpu(id));
}
// TODO @luowenfeng新增 get-detail返回 SpuDetailRespVO
@GetMapping("/list")
@ApiOperation("获得商品spu列表")
@ApiOperation("获得商品 SPU 列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<List<SpuRespVO>> getSpuList(@RequestParam("ids") Collection<Long> ids) {
public CommonResult<List<ProductSpuRespVO>> getSpuList(@RequestParam("ids") Collection<Long> ids) {
List<ProductSpuDO> list = spuService.getSpuList(ids);
return success(ProductSpuConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得商品spu分页")
@ApiOperation("获得商品 SPU 分页")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<PageResult<SpuRespVO>> getSpuPage(@Valid SpuPageReqVO pageVO) {
public CommonResult<PageResult<ProductSpuRespVO>> getSpuPage(@Valid ProductSpuPageReqVO pageVO) {
return success(spuService.getSpuPage(pageVO));
}

View File

@ -35,8 +35,7 @@ public class ProductSpuBaseVO {
@NotNull(message = "商品分类编号不能为空")
private Long categoryId;
@ApiModelProperty(value = "商品品牌编号", required = true, example = "1")
// @NotNull(message = "商品品牌编号不能为空")
@ApiModelProperty(value = "商品品牌编号", example = "1")
private Long brandId;
@ApiModelProperty(value = "商品图片的数组", required = true)

View File

@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Date;
import java.util.List;
@ApiModel(value = "管理后台 - 商品 SPU 详细 Response VO", description = "包括关联的 SKU 等信息")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuDetailRespVO extends ProductSpuBaseVO {
@ApiModelProperty(value = "主键", required = true, example = "1")
private Long id;
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* SKU 数组
*/
private List<Sku> skus;
@ApiModel(value = "管理后台 - 商品 SKU 详细 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public static class Sku extends ProductSkuBaseVO {
/**
* 规格的数组
*/
private List<ProductSpuDetailRespVO.Property> properties;
}
@ApiModel(value = "管理后台 - 商品规格的详细 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public static class Property extends ProductSkuBaseVO.Property {
@ApiModelProperty(value = "规格的名字", required = true, example = "颜色")
private String propertyName;
@ApiModelProperty(value = "规格值的名字", required = true, example = "蓝色")
private String valueName;
}
}

View File

@ -8,11 +8,11 @@ import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("管理后台 - 商品spu分页 Request VO")
@ApiModel("管理后台 - 商品 SPU 分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SpuPageReqVO extends PageParam {
public class ProductSpuPageReqVO extends PageParam {
@ApiModelProperty(value = "商品名称")
private String name;

View File

@ -9,16 +9,14 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ApiModel("管理后台 - 商品spu Response VO")
// TODO @Luowenfeng这个类只返回 SPU 相关的信息删除 skuscategoryIdsproductPropertyViews明细使用 SpuDetailRespVO 替代
@ApiModel("管理后台 - 商品 SPU Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SpuRespVO extends ProductSpuBaseVO {
// TODO @franky注解要完整
public class ProductSpuRespVO extends ProductSpuBaseVO {
@ApiModelProperty(value = "主键", required = true, example = "1")
private Long id;
@ -33,7 +31,7 @@ public class SpuRespVO extends ProductSpuBaseVO {
private List<ProductSkuRespVO> skus;
@ApiModelProperty(value = "分类id数组一直递归到一级父节点", example = "[1,2,4]")
private LinkedList<Long> categoryIds;
private List<Long> categoryIds;
// TODO @芋艿再琢磨下 这个 VO 其实变成 SpuRespVO 内嵌的 VO 类会更好一点然后把 SpuRespVO 改成 SpuDetailSpuVO

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.controller.app.spu;
import cn.hutool.core.bean.BeanUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuRespVO;

View File

@ -1,10 +1,9 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuRespVO;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* <p>
@ -16,7 +15,7 @@ import lombok.ToString;
@ApiModel("App - 商品spu Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class AppSpuRespVO extends SpuRespVO {
public class AppSpuRespVO extends ProductSpuRespVO {
}

View File

@ -1,17 +1,15 @@
package cn.iocoder.yudao.module.product.convert.property;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyAndValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyExcelVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 规格名称 Convert
*
@ -32,6 +30,4 @@ public interface ProductPropertyConvert {
PageResult<ProductPropertyAndValueRespVO> convertPage(PageResult<ProductPropertyDO> page);
List<ProductPropertyExcelVO> convertList02(List<ProductPropertyDO> list);
}

View File

@ -1,10 +1,7 @@
package cn.iocoder.yudao.module.product.convert.sku;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuExcelVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
@ -24,8 +21,6 @@ public interface ProductSkuConvert {
ProductSkuDO convert(ProductSkuCreateOrUpdateReqVO bean);
ProductSkuDO convert(ProductSkuUpdateReqVO bean);
@Mapping(source = "properties", target = "properties")
ProductSkuRespVO convert(ProductSkuDO bean);
@ -33,8 +28,4 @@ public interface ProductSkuConvert {
List<ProductSkuDO> convertSkuDOList(List<ProductSkuCreateOrUpdateReqVO> list);
PageResult<ProductSkuRespVO> convertPage(PageResult<ProductSkuDO> page);
List<ProductSkuExcelVO> convertList02(List<ProductSkuDO> list);
}

View File

@ -24,13 +24,13 @@ public interface ProductSpuConvert {
ProductSpuDO convert(ProductSpuUpdateReqVO bean);
SpuRespVO convert(ProductSpuDO bean);
ProductSpuRespVO convert(ProductSpuDO bean);
List<SpuRespVO> convertList(List<ProductSpuDO> list);
List<ProductSpuRespVO> convertList(List<ProductSpuDO> list);
PageResult<SpuRespVO> convertPage(PageResult<ProductSpuDO> page);
PageResult<ProductSpuRespVO> convertPage(PageResult<ProductSpuDO> page);
SpuPageReqVO convert(AppSpuPageReqVO bean);
ProductSpuPageReqVO convert(AppSpuPageReqVO bean);
AppSpuPageRespVO convertAppResp(ProductSpuDO list);

View File

@ -1,11 +1,8 @@
package cn.iocoder.yudao.module.product.dal.mysql.property;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyExportReqVO;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import org.apache.ibatis.annotations.Mapper;
@ -26,12 +23,4 @@ public interface ProductPropertyMapper extends BaseMapperX<ProductPropertyDO> {
.orderByDesc(ProductPropertyDO::getId));
}
default List<ProductPropertyDO> selectList(ProductPropertyExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ProductPropertyDO>()
.likeIfPresent(ProductPropertyDO::getName, reqVO.getName())
.eqIfPresent(ProductPropertyDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductPropertyDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ProductPropertyDO::getId));
}
}

View File

@ -1,37 +1,20 @@
package cn.iocoder.yudao.module.product.dal.mysql.sku;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 商品sku Mapper
* 商品 SKU Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> {
default PageResult<ProductSkuDO> selectPage(ProductSkuPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductSkuDO>()
.eqIfPresent(ProductSkuDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(ProductSkuDO::getProperties, reqVO.getProperties())
.eqIfPresent(ProductSkuDO::getPrice, reqVO.getPrice())
// .eqIfPresent(ProductSkuDO::getOriginalPrice, reqVO.getOriginalPrice())
// .eqIfPresent(ProductSkuDO::getCostPrice, reqVO.getCostPrice())
.eqIfPresent(ProductSkuDO::getBarCode, reqVO.getBarCode())
.eqIfPresent(ProductSkuDO::getPicUrl, reqVO.getPicUrl())
.eqIfPresent(ProductSkuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductSkuDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ProductSkuDO::getId));
}
// TODO @franky方法名 selectList; 可以直接调用 selectList
default List<ProductSkuDO> selectListBySpuIds(List<Long> spuIds) {
return selectList(ProductSkuDO::getSpuId, spuIds);

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.dal.mysql.spu;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import org.apache.ibatis.annotations.Mapper;
@ -15,7 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
default PageResult<ProductSpuDO> selectPage(SpuPageReqVO reqVO) {
default PageResult<ProductSpuDO> selectPage(ProductSpuPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>()
.likeIfPresent(ProductSpuDO::getName, reqVO.getName())
.eqIfPresent(ProductSpuDO::getSellPoint, reqVO.getSellPoint())

View File

@ -1,9 +1,6 @@
package cn.iocoder.yudao.module.product.service.sku;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import javax.validation.Valid;
@ -17,21 +14,6 @@ import java.util.List;
*/
public interface ProductSkuService {
/**
* 创建商品 SKU
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createSku(@Valid ProductSkuCreateOrUpdateReqVO createReqVO);
/**
* 更新商品sku
*
* @param updateReqVO 更新信息
*/
void updateSku(@Valid ProductSkuUpdateReqVO updateReqVO);
/**
* 删除商品sku
*
@ -55,14 +37,6 @@ public interface ProductSkuService {
*/
List<ProductSkuDO> getSkuList(Collection<Long> ids);
/**
* 获得商品sku分页
*
* @param pageReqVO 分页查询
* @return 商品sku分页
*/
PageResult<ProductSkuDO> getSkuPage(ProductSkuPageReqVO pageReqVO);
/**
* sku 的组合的属性等进行合法性校验
*

View File

@ -2,14 +2,11 @@ package cn.iocoder.yudao.module.product.service.sku;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyAndValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
@ -42,24 +39,6 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Resource
private ProductPropertyService productPropertyService;
@Override
public Long createSku(ProductSkuCreateOrUpdateReqVO createReqVO) {
// 插入
ProductSkuDO sku = ProductSkuConvert.INSTANCE.convert(createReqVO);
productSkuMapper.insert(sku);
// 返回
return sku.getId();
}
@Override
public void updateSku(ProductSkuUpdateReqVO updateReqVO) {
// 校验存在
this.validateSkuExists(updateReqVO.getId());
// 更新
ProductSkuDO updateObj = ProductSkuConvert.INSTANCE.convert(updateReqVO);
productSkuMapper.updateById(updateObj);
}
@Override
public void deleteSku(Long id) {
// 校验存在
@ -84,11 +63,6 @@ public class ProductSkuServiceImpl implements ProductSkuService {
return productSkuMapper.selectBatchIds(ids);
}
@Override
public PageResult<ProductSkuDO> getSkuPage(ProductSkuPageReqVO pageReqVO) {
return productSkuMapper.selectPage(pageReqVO);
}
@Override
public void validateSkus(List<ProductSkuCreateOrUpdateReqVO> skus, Integer specType) {
// 非多规格不需要校验

View File

@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.product.service.spu;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
@ -48,7 +48,7 @@ public interface ProductSpuService {
* @param id 编号
* @return 商品spu
*/
SpuRespVO getSpu(Long id);
ProductSpuRespVO getSpu(Long id);
/**
* 获得商品spu列表
@ -64,7 +64,7 @@ public interface ProductSpuService {
* @param pageReqVO 分页查询
* @return 商品spu分页
*/
PageResult<SpuRespVO> getSpuPage(SpuPageReqVO pageReqVO);
PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO);
/**
* 获得商品spu分页

View File

@ -9,9 +9,9 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
@ -125,9 +125,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Override
// TODO @芋艿需要再 review
public SpuRespVO getSpu(Long id) {
public ProductSpuRespVO getSpu(Long id) {
ProductSpuDO spu = ProductSpuMapper.selectById(id);
SpuRespVO spuVO = ProductSpuConvert.INSTANCE.convert(spu);
ProductSpuRespVO spuVO = ProductSpuConvert.INSTANCE.convert(spu);
if (null != spuVO) {
List<ProductSkuRespVO> skuReqs = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuId(id));
spuVO.setSkus(skuReqs);
@ -179,10 +179,10 @@ public class ProductSpuServiceImpl implements ProductSpuService {
}
@Override
public PageResult<SpuRespVO> getSpuPage(SpuPageReqVO pageReqVO) {
PageResult<SpuRespVO> spuVOs = ProductSpuConvert.INSTANCE.convertPage(ProductSpuMapper.selectPage(pageReqVO));
public PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
PageResult<ProductSpuRespVO> spuVOs = ProductSpuConvert.INSTANCE.convertPage(ProductSpuMapper.selectPage(pageReqVO));
// 查询 sku 的信息
List<Long> spuIds = spuVOs.getList().stream().map(SpuRespVO::getId).collect(Collectors.toList());
List<Long> spuIds = spuVOs.getList().stream().map(ProductSpuRespVO::getId).collect(Collectors.toList());
List<ProductSkuRespVO> skus = ProductSkuConvert.INSTANCE.convertList(productSkuService.getSkusBySpuIds(spuIds));
// TODO @franky使用 CollUtil 里的方法替代哈
// TODO 芋艿临时注释

View File

@ -1,24 +1,17 @@
package cn.iocoder.yudao.module.product.service.sku;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertNull;
/**
* {@link ProductSkuServiceImpl} 的单元测试类
@ -34,46 +27,6 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
@Resource
private ProductSkuMapper ProductSkuMapper;
@Test
public void testCreateSku_success() {
// 准备参数
ProductSkuCreateOrUpdateReqVO reqVO = randomPojo(ProductSkuCreateOrUpdateReqVO.class);
// 调用
Long skuId = ProductSkuService.createSku(reqVO);
// 断言
assertNotNull(skuId);
// 校验记录的属性是否正确
ProductSkuDO sku = ProductSkuMapper.selectById(skuId);
assertPojoEquals(reqVO, sku);
}
@Test
public void testUpdateSku_success() {
// mock 数据
ProductSkuDO dbSku = randomPojo(ProductSkuDO.class);
ProductSkuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据
// 准备参数
ProductSkuUpdateReqVO reqVO = randomPojo(ProductSkuUpdateReqVO.class, o -> {
o.setId(dbSku.getId()); // 设置更新的 ID
});
// 调用
ProductSkuService.updateSku(reqVO);
// 校验是否更新正确
ProductSkuDO sku = ProductSkuMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, sku);
}
@Test
public void testUpdateSku_notExists() {
// 准备参数
ProductSkuUpdateReqVO reqVO = randomPojo(ProductSkuUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> ProductSkuService.updateSku(reqVO), SKU_NOT_EXISTS);
}
@Test
public void testDeleteSku_success() {
// mock 数据
@ -97,58 +50,4 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
assertServiceException(() -> ProductSkuService.deleteSku(id), SKU_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetSkuPage() {
// mock 数据
ProductSkuDO dbSku = randomPojo(ProductSkuDO.class, o -> { // 等会查询到
o.setSpuId(null);
o.setProperties(null);
o.setPrice(null);
// o.setOriginalPrice(null);
// o.setCostPrice(null);
o.setBarCode(null);
o.setPicUrl(null);
o.setStatus(null);
o.setCreateTime(null);
});
ProductSkuMapper.insert(dbSku);
// 测试 spuId 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null)));
// 测试 properties 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null)));
// 测试 price 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null)));
// 测试 originalPrice 不匹配
// ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
// 测试 costPrice 不匹配
// ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
// 测试 barCode 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
// 测试 picUrl 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null)));
// 测试 status 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null)));
// 测试 createTime 不匹配
ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null)));
// 准备参数
ProductSkuPageReqVO reqVO = new ProductSkuPageReqVO();
reqVO.setSpuId(null);
reqVO.setProperties(null);
reqVO.setPrice(null);
reqVO.setOriginalPrice(null);
reqVO.setCostPrice(null);
reqVO.setBarCode(null);
reqVO.setPicUrl(null);
reqVO.setStatus(null);
reqVO.setCreateTime(null);
// 调用
PageResult<ProductSkuDO> pageResult = ProductSkuService.getSkuPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbSku, pageResult.getList().get(0));
}
}

View File

@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.product.service.spu;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuRespVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
@ -139,7 +139,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
// 测试 createTime 不匹配
ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null)));
// 准备参数
SpuPageReqVO reqVO = new SpuPageReqVO();
ProductSpuPageReqVO reqVO = new ProductSpuPageReqVO();
reqVO.setName(null);
reqVO.setSellPoint(null);
reqVO.setDescription(null);
@ -153,7 +153,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
reqVO.setCreateTime(null);
// 调用
PageResult<SpuRespVO> pageResult = spuService.getSpuPage(reqVO);
PageResult<ProductSpuRespVO> pageResult = spuService.getSpuPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());