SPU名字重构

pull/2/head
franky 2022-05-31 18:39:44 +08:00
parent e1c08c4661
commit eb5bdda344
32 changed files with 454 additions and 432 deletions

View File

@ -22,31 +22,31 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.convert.sku.SkuConvert; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.service.sku.SkuService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
@Api(tags = "管理后台 - 商品sku") @Api(tags = "管理后台 - 商品sku")
@RestController @RestController
@RequestMapping("/product/sku") @RequestMapping("/product/sku")
@Validated @Validated
public class SkuController { public class ProductSkuController {
@Resource @Resource
private SkuService skuService; private ProductSkuService ProductSkuService;
@PostMapping("/create") @PostMapping("/create")
@ApiOperation("创建商品sku") @ApiOperation("创建商品sku")
@PreAuthorize("@ss.hasPermission('product:sku:create')") @PreAuthorize("@ss.hasPermission('product:sku:create')")
public CommonResult<Integer> createSku(@Valid @RequestBody SkuCreateReqVO createReqVO) { public CommonResult<Integer> createSku(@Valid @RequestBody ProductSkuCreateReqVO createReqVO) {
return success(skuService.createSku(createReqVO)); return success(ProductSkuService.createSku(createReqVO));
} }
@PutMapping("/update") @PutMapping("/update")
@ApiOperation("更新商品sku") @ApiOperation("更新商品sku")
@PreAuthorize("@ss.hasPermission('product:sku:update')") @PreAuthorize("@ss.hasPermission('product:sku:update')")
public CommonResult<Boolean> updateSku(@Valid @RequestBody SkuUpdateReqVO updateReqVO) { public CommonResult<Boolean> updateSku(@Valid @RequestBody ProductSkuUpdateReqVO updateReqVO) {
skuService.updateSku(updateReqVO); ProductSkuService.updateSku(updateReqVO);
return success(true); return success(true);
} }
@ -55,7 +55,7 @@ public class SkuController {
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
@PreAuthorize("@ss.hasPermission('product:sku:delete')") @PreAuthorize("@ss.hasPermission('product:sku:delete')")
public CommonResult<Boolean> deleteSku(@RequestParam("id") Integer id) { public CommonResult<Boolean> deleteSku(@RequestParam("id") Integer id) {
skuService.deleteSku(id); ProductSkuService.deleteSku(id);
return success(true); return success(true);
} }
@ -63,38 +63,38 @@ public class SkuController {
@ApiOperation("获得商品sku") @ApiOperation("获得商品sku")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
@PreAuthorize("@ss.hasPermission('product:sku:query')") @PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<SkuRespVO> getSku(@RequestParam("id") Integer id) { public CommonResult<ProductSkuRespVO> getSku(@RequestParam("id") Integer id) {
SkuDO sku = skuService.getSku(id); ProductSkuDO sku = ProductSkuService.getSku(id);
return success(SkuConvert.INSTANCE.convert(sku)); return success(ProductSkuConvert.INSTANCE.convert(sku));
} }
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("获得商品sku列表") @ApiOperation("获得商品sku列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('product:sku:query')") @PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<List<SkuRespVO>> getSkuList(@RequestParam("ids") Collection<Integer> ids) { public CommonResult<List<ProductSkuRespVO>> getSkuList(@RequestParam("ids") Collection<Integer> ids) {
List<SkuDO> list = skuService.getSkuList(ids); List<ProductSkuDO> list = ProductSkuService.getSkuList(ids);
return success(SkuConvert.INSTANCE.convertList(list)); return success(ProductSkuConvert.INSTANCE.convertList(list));
} }
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得商品sku分页") @ApiOperation("获得商品sku分页")
@PreAuthorize("@ss.hasPermission('product:sku:query')") @PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<PageResult<SkuRespVO>> getSkuPage(@Valid SkuPageReqVO pageVO) { public CommonResult<PageResult<ProductSkuRespVO>> getSkuPage(@Valid ProductSkuPageReqVO pageVO) {
PageResult<SkuDO> pageResult = skuService.getSkuPage(pageVO); PageResult<ProductSkuDO> pageResult = ProductSkuService.getSkuPage(pageVO);
return success(SkuConvert.INSTANCE.convertPage(pageResult)); return success(ProductSkuConvert.INSTANCE.convertPage(pageResult));
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ApiOperation("导出商品sku Excel") @ApiOperation("导出商品sku Excel")
@PreAuthorize("@ss.hasPermission('product:sku:export')") @PreAuthorize("@ss.hasPermission('product:sku:export')")
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void exportSkuExcel(@Valid SkuExportReqVO exportReqVO, public void exportSkuExcel(@Valid ProductSkuExportReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
List<SkuDO> list = skuService.getSkuList(exportReqVO); List<ProductSkuDO> list = ProductSkuService.getSkuList(exportReqVO);
// 导出 Excel // 导出 Excel
List<SkuExcelVO> datas = SkuConvert.INSTANCE.convertList02(list); List<ProductSkuExcelVO> datas = ProductSkuConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "商品sku.xls", "数据", SkuExcelVO.class, datas); ExcelUtils.write(response, "商品sku.xls", "数据", ProductSkuExcelVO.class, datas);
} }
} }

View File

@ -10,7 +10,7 @@ import javax.validation.constraints.*;
* VO Swagger * VO Swagger
*/ */
@Data @Data
public class SkuBaseVO { public class ProductSkuBaseVO {
@ApiModelProperty(value = "spu编号", required = true) @ApiModelProperty(value = "spu编号", required = true)
@NotNull(message = "spu编号不能为空") @NotNull(message = "spu编号不能为空")
@ -18,7 +18,7 @@ public class SkuBaseVO {
@ApiModelProperty(value = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]", required = true) @ApiModelProperty(value = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]", required = true)
@NotNull(message = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]不能为空") @NotNull(message = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]不能为空")
private String properties; private List<Property> properties;
@ApiModelProperty(value = "销售价格,单位:分", required = true) @ApiModelProperty(value = "销售价格,单位:分", required = true)
@NotNull(message = "销售价格,单位:分不能为空") @NotNull(message = "销售价格,单位:分不能为空")
@ -43,4 +43,10 @@ public class SkuBaseVO {
@ApiModelProperty(value = "状态: 0-正常 1-禁用") @ApiModelProperty(value = "状态: 0-正常 1-禁用")
private Integer status; private Integer status;
@Data
public static class Property {
private Integer propertyId;
private Integer valueId;
}
} }

View File

@ -9,6 +9,6 @@ import javax.validation.constraints.*;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SkuCreateReqVO extends SkuBaseVO { public class ProductSkuCreateReqVO extends ProductSkuBaseVO {
} }

View File

@ -12,7 +12,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
* @author * @author
*/ */
@Data @Data
public class SkuExcelVO { public class ProductSkuExcelVO {
@ExcelProperty("主键") @ExcelProperty("主键")
private Integer id; private Integer id;
@ -21,7 +21,7 @@ public class SkuExcelVO {
private Long spuId; private Long spuId;
@ExcelProperty("规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]") @ExcelProperty("规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]")
private String properties; private List<Property> properties;
@ExcelProperty("销售价格,单位:分") @ExcelProperty("销售价格,单位:分")
private Integer price; private Integer price;
@ -44,4 +44,9 @@ public class SkuExcelVO {
@ExcelProperty("创建时间") @ExcelProperty("创建时间")
private Date createTime; private Date createTime;
@Data
public static class Property {
private Integer propertyId;
private Integer valueId;
}
} }

View File

@ -10,7 +10,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@ApiModel(value = "管理后台 - 商品sku Excel 导出 Request VO", description = "参数和 SkuPageReqVO 是一致的") @ApiModel(value = "管理后台 - 商品sku Excel 导出 Request VO", description = "参数和 SkuPageReqVO 是一致的")
@Data @Data
public class SkuExportReqVO { public class ProductSkuExportReqVO {
@ApiModelProperty(value = "spu编号") @ApiModelProperty(value = "spu编号")
private Long spuId; private Long spuId;

View File

@ -12,7 +12,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SkuPageReqVO extends PageParam { public class ProductSkuPageReqVO extends PageParam {
@ApiModelProperty(value = "spu编号") @ApiModelProperty(value = "spu编号")
private Long spuId; private Long spuId;

View File

@ -8,7 +8,7 @@ import io.swagger.annotations.*;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SkuRespVO extends SkuBaseVO { public class ProductSkuRespVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
private Integer id; private Integer id;

View File

@ -9,7 +9,7 @@ import javax.validation.constraints.*;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SkuUpdateReqVO extends SkuBaseVO { public class ProductSkuUpdateReqVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空") @NotNull(message = "主键不能为空")

View File

@ -22,23 +22,23 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.convert.spu.SpuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.service.spu.SpuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
@Api(tags = "管理后台 - 商品spu") @Api(tags = "管理后台 - 商品spu")
@RestController @RestController
@RequestMapping("/product/spu") @RequestMapping("/product/spu")
@Validated @Validated
public class SpuController { public class ProductSpuController {
@Resource @Resource
private SpuService spuService; private ProductSpuService spuService;
@PostMapping("/create") @PostMapping("/create")
@ApiOperation("创建商品spu") @ApiOperation("创建商品spu")
@PreAuthorize("@ss.hasPermission('product:spu:create')") @PreAuthorize("@ss.hasPermission('product:spu:create')")
public CommonResult<Integer> createSpu(@Valid @RequestBody SpuCreateReqVO createReqVO) { public CommonResult<Integer> createSpu(@Valid @RequestBody ProductSpuCreateReqVO createReqVO) {
return success(spuService.createSpu(createReqVO)); return success(spuService.createSpu(createReqVO));
} }
@ -64,8 +64,8 @@ public class SpuController {
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
@PreAuthorize("@ss.hasPermission('product:spu:query')") @PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<SpuRespVO> getSpu(@RequestParam("id") Integer id) { public CommonResult<SpuRespVO> getSpu(@RequestParam("id") Integer id) {
SpuDO spu = spuService.getSpu(id); ProductSpuDO spu = spuService.getSpu(id);
return success(SpuConvert.INSTANCE.convert(spu)); return success(ProductSpuConvert.INSTANCE.convert(spu));
} }
@GetMapping("/list") @GetMapping("/list")
@ -73,16 +73,16 @@ public class SpuController {
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('product:spu:query')") @PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<List<SpuRespVO>> getSpuList(@RequestParam("ids") Collection<Integer> ids) { public CommonResult<List<SpuRespVO>> getSpuList(@RequestParam("ids") Collection<Integer> ids) {
List<SpuDO> list = spuService.getSpuList(ids); List<ProductSpuDO> list = spuService.getSpuList(ids);
return success(SpuConvert.INSTANCE.convertList(list)); return success(ProductSpuConvert.INSTANCE.convertList(list));
} }
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得商品spu分页") @ApiOperation("获得商品spu分页")
@PreAuthorize("@ss.hasPermission('product:spu:query')") @PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<PageResult<SpuRespVO>> getSpuPage(@Valid SpuPageReqVO pageVO) { public CommonResult<PageResult<SpuRespVO>> getSpuPage(@Valid SpuPageReqVO pageVO) {
PageResult<SpuDO> pageResult = spuService.getSpuPage(pageVO); PageResult<ProductSpuDO> pageResult = spuService.getSpuPage(pageVO);
return success(SpuConvert.INSTANCE.convertPage(pageResult)); return success(ProductSpuConvert.INSTANCE.convertPage(pageResult));
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ -91,9 +91,9 @@ public class SpuController {
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void exportSpuExcel(@Valid SpuExportReqVO exportReqVO, public void exportSpuExcel(@Valid SpuExportReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
List<SpuDO> list = spuService.getSpuList(exportReqVO); List<ProductSpuDO> list = spuService.getSpuList(exportReqVO);
// 导出 Excel // 导出 Excel
List<SpuExcelVO> datas = SpuConvert.INSTANCE.convertList02(list); List<SpuExcelVO> datas = ProductSpuConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "商品spu.xls", "数据", SpuExcelVO.class, datas); ExcelUtils.write(response, "商品spu.xls", "数据", SpuExcelVO.class, datas);
} }

View File

@ -10,7 +10,7 @@ import javax.validation.constraints.*;
* VO Swagger * VO Swagger
*/ */
@Data @Data
public class SpuBaseVO { public class ProductSpuBaseVO {
@ApiModelProperty(value = "商品名称") @ApiModelProperty(value = "商品名称")
private String name; private String name;
@ -29,7 +29,7 @@ public class SpuBaseVO {
@ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张", required = true) @ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张", required = true)
@NotNull(message = "商品主图地址,* 数组,以逗号分隔,最多上传15张不能为空") @NotNull(message = "商品主图地址,* 数组,以逗号分隔,最多上传15张不能为空")
private String picUrls; private List<String> picUrls;
@ApiModelProperty(value = "排序字段", required = true) @ApiModelProperty(value = "排序字段", required = true)
@NotNull(message = "排序字段不能为空") @NotNull(message = "排序字段不能为空")

View File

@ -9,6 +9,6 @@ import javax.validation.constraints.*;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SpuCreateReqVO extends SpuBaseVO { public class ProductSpuCreateReqVO extends ProductSpuBaseVO {
} }

View File

@ -30,7 +30,7 @@ public class SpuExcelVO {
private Long categoryId; private Long categoryId;
@ExcelProperty("商品主图地址,* 数组,以逗号分隔,最多上传15张") @ExcelProperty("商品主图地址,* 数组,以逗号分隔,最多上传15张")
private String picUrls; private List<String> picUrls;
@ExcelProperty("排序字段") @ExcelProperty("排序字段")
private Integer sort; private Integer sort;

View File

@ -25,7 +25,7 @@ public class SpuExportReqVO {
private Long categoryId; private Long categoryId;
@ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张") @ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张")
private String picUrls; private List<String> picUrls;
@ApiModelProperty(value = "排序字段") @ApiModelProperty(value = "排序字段")
private Integer sort; private Integer sort;

View File

@ -8,7 +8,7 @@ import io.swagger.annotations.*;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SpuRespVO extends SpuBaseVO { public class SpuRespVO extends ProductSpuBaseVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
private Integer id; private Integer id;

View File

@ -9,7 +9,7 @@ import javax.validation.constraints.*;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class SpuUpdateReqVO extends SpuBaseVO { public class SpuUpdateReqVO extends ProductSpuBaseVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空") @NotNull(message = "主键不能为空")

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.convert.sku;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
/**
* sku Convert
*
* @author
*/
@Mapper
public interface ProductSkuConvert {
ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
ProductSkuDO convert(ProductSkuCreateReqVO bean);
ProductSkuDO convert(ProductSkuUpdateReqVO bean);
ProductSkuRespVO convert(ProductSkuDO bean);
List<ProductSkuRespVO> convertList(List<ProductSkuDO> list);
PageResult<ProductSkuRespVO> convertPage(PageResult<ProductSkuDO> page);
List<ProductSkuExcelVO> convertList02(List<ProductSkuDO> list);
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.product.convert.sku;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
/**
* sku Convert
*
* @author
*/
@Mapper
public interface SkuConvert {
SkuConvert INSTANCE = Mappers.getMapper(SkuConvert.class);
SkuDO convert(SkuCreateReqVO bean);
SkuDO convert(SkuUpdateReqVO bean);
SkuRespVO convert(SkuDO bean);
List<SkuRespVO> convertList(List<SkuDO> list);
PageResult<SkuRespVO> convertPage(PageResult<SkuDO> page);
List<SkuExcelVO> convertList02(List<SkuDO> list);
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.convert.spu;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
/**
* spu Convert
*
* @author
*/
@Mapper
public interface ProductSpuConvert {
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
ProductSpuDO convert(ProductSpuCreateReqVO bean);
ProductSpuDO convert(SpuUpdateReqVO bean);
SpuRespVO convert(ProductSpuDO bean);
List<SpuRespVO> convertList(List<ProductSpuDO> list);
PageResult<SpuRespVO> convertPage(PageResult<ProductSpuDO> page);
List<SpuExcelVO> convertList02(List<ProductSpuDO> list);
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.product.convert.spu;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
/**
* spu Convert
*
* @author
*/
@Mapper
public interface SpuConvert {
SpuConvert INSTANCE = Mappers.getMapper(SpuConvert.class);
SpuDO convert(SpuCreateReqVO bean);
SpuDO convert(SpuUpdateReqVO bean);
SpuRespVO convert(SpuDO bean);
List<SpuRespVO> convertList(List<SpuDO> list);
PageResult<SpuRespVO> convertPage(PageResult<SpuDO> page);
List<SpuExcelVO> convertList02(List<SpuDO> list);
}

View File

@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
import java.util.List;
/** /**
* sku DO * sku DO
* *
@ -19,7 +21,7 @@ import lombok.*;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class SkuDO extends BaseDO { public class ProductSkuDO extends BaseDO {
/** /**
* *
@ -34,7 +36,7 @@ public class SkuDO extends BaseDO {
* -json [{propertId: , valueId: }, {propertId: , valueId: }] * -json [{propertId: , valueId: }, {propertId: , valueId: }]
*/ */
// TODO franky可以定义一个内部的 Property 类,然后 List<Property> // TODO franky可以定义一个内部的 Property 类,然后 List<Property>
private String properties; private List<Property> properties;
/** /**
* *
*/ */
@ -60,4 +62,11 @@ public class SkuDO extends BaseDO {
*/ */
private Integer status; private Integer status;
@Data
public static class Property {
private Integer propertyId;
private Integer valueId;
}
} }

View File

@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
import java.util.List;
/** /**
* spu DO * spu DO
* *
@ -19,7 +21,7 @@ import lombok.*;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class SpuDO extends BaseDO { public class ProductSpuDO extends BaseDO {
/** /**
* *
@ -46,7 +48,7 @@ public class SpuDO extends BaseDO {
* ,* ,15 * ,* ,15
*/ */
// TODO frankyList<String> // TODO frankyList<String>
private String picUrls; private List<String> picUrls;
/** /**
* *
*/ */

View File

@ -0,0 +1,48 @@
package cn.iocoder.yudao.module.product.dal.mysql.sku;
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.dal.dataobject.sku.ProductSkuDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
/**
* 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.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(ProductSkuDO::getId));
}
default List<ProductSkuDO> selectList(ProductSkuExportReqVO reqVO) {
return selectList(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.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(ProductSkuDO::getId));
}
}

View File

@ -1,48 +0,0 @@
package cn.iocoder.yudao.module.product.dal.mysql.sku;
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.dal.dataobject.sku.SkuDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
/**
* sku Mapper
*
* @author
*/
@Mapper
public interface SkuMapper extends BaseMapperX<SkuDO> {
default PageResult<SkuDO> selectPage(SkuPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<SkuDO>()
.eqIfPresent(SkuDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(SkuDO::getProperties, reqVO.getProperties())
.eqIfPresent(SkuDO::getPrice, reqVO.getPrice())
.eqIfPresent(SkuDO::getOriginalPrice, reqVO.getOriginalPrice())
.eqIfPresent(SkuDO::getCostPrice, reqVO.getCostPrice())
.eqIfPresent(SkuDO::getBarCode, reqVO.getBarCode())
.eqIfPresent(SkuDO::getPicUrl, reqVO.getPicUrl())
.eqIfPresent(SkuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(SkuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(SkuDO::getId));
}
default List<SkuDO> selectList(SkuExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<SkuDO>()
.eqIfPresent(SkuDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(SkuDO::getProperties, reqVO.getProperties())
.eqIfPresent(SkuDO::getPrice, reqVO.getPrice())
.eqIfPresent(SkuDO::getOriginalPrice, reqVO.getOriginalPrice())
.eqIfPresent(SkuDO::getCostPrice, reqVO.getCostPrice())
.eqIfPresent(SkuDO::getBarCode, reqVO.getBarCode())
.eqIfPresent(SkuDO::getPicUrl, reqVO.getPicUrl())
.eqIfPresent(SkuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(SkuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(SkuDO::getId));
}
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.product.dal.mysql.spu;
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.dal.dataobject.spu.ProductSpuDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
/**
* spu Mapper
*
* @author
*/
@Mapper
public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
default PageResult<ProductSpuDO> selectPage(SpuPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>()
.likeIfPresent(ProductSpuDO::getName, reqVO.getName())
.eqIfPresent(ProductSpuDO::getSellPoint, reqVO.getSellPoint())
.eqIfPresent(ProductSpuDO::getDescription, reqVO.getDescription())
.eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls())
.eqIfPresent(ProductSpuDO::getSort, reqVO.getSort())
.eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount())
.eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice())
.eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity())
.eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(ProductSpuDO::getId));
}
default List<ProductSpuDO> selectList(SpuExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ProductSpuDO>()
.likeIfPresent(ProductSpuDO::getName, reqVO.getName())
.eqIfPresent(ProductSpuDO::getSellPoint, reqVO.getSellPoint())
.eqIfPresent(ProductSpuDO::getDescription, reqVO.getDescription())
.eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls())
.eqIfPresent(ProductSpuDO::getSort, reqVO.getSort())
.eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount())
.eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice())
.eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity())
.eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(ProductSpuDO::getId));
}
}

View File

@ -1,52 +0,0 @@
package cn.iocoder.yudao.module.product.dal.mysql.spu;
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.dal.dataobject.spu.SpuDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
/**
* spu Mapper
*
* @author
*/
@Mapper
public interface SpuMapper extends BaseMapperX<SpuDO> {
default PageResult<SpuDO> selectPage(SpuPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<SpuDO>()
.likeIfPresent(SpuDO::getName, reqVO.getName())
.eqIfPresent(SpuDO::getSellPoint, reqVO.getSellPoint())
.eqIfPresent(SpuDO::getDescription, reqVO.getDescription())
.eqIfPresent(SpuDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(SpuDO::getPicUrls, reqVO.getPicUrls())
.eqIfPresent(SpuDO::getSort, reqVO.getSort())
.eqIfPresent(SpuDO::getLikeCount, reqVO.getLikeCount())
.eqIfPresent(SpuDO::getPrice, reqVO.getPrice())
.eqIfPresent(SpuDO::getQuantity, reqVO.getQuantity())
.eqIfPresent(SpuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(SpuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(SpuDO::getId));
}
default List<SpuDO> selectList(SpuExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<SpuDO>()
.likeIfPresent(SpuDO::getName, reqVO.getName())
.eqIfPresent(SpuDO::getSellPoint, reqVO.getSellPoint())
.eqIfPresent(SpuDO::getDescription, reqVO.getDescription())
.eqIfPresent(SpuDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(SpuDO::getPicUrls, reqVO.getPicUrls())
.eqIfPresent(SpuDO::getSort, reqVO.getSort())
.eqIfPresent(SpuDO::getLikeCount, reqVO.getLikeCount())
.eqIfPresent(SpuDO::getPrice, reqVO.getPrice())
.eqIfPresent(SpuDO::getQuantity, reqVO.getQuantity())
.eqIfPresent(SpuDO::getStatus, reqVO.getStatus())
.betweenIfPresent(SpuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(SpuDO::getId));
}
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.service.sku;
import java.util.*; import java.util.*;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
/** /**
@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
* *
* @author * @author
*/ */
public interface SkuService { public interface ProductSkuService {
/** /**
* sku * sku
@ -19,14 +19,14 @@ public interface SkuService {
* @param createReqVO * @param createReqVO
* @return * @return
*/ */
Integer createSku(@Valid SkuCreateReqVO createReqVO); Integer createSku(@Valid ProductSkuCreateReqVO createReqVO);
/** /**
* sku * sku
* *
* @param updateReqVO * @param updateReqVO
*/ */
void updateSku(@Valid SkuUpdateReqVO updateReqVO); void updateSku(@Valid ProductSkuUpdateReqVO updateReqVO);
/** /**
* sku * sku
@ -41,7 +41,7 @@ public interface SkuService {
* @param id * @param id
* @return sku * @return sku
*/ */
SkuDO getSku(Integer id); ProductSkuDO getSku(Integer id);
/** /**
* sku * sku
@ -49,7 +49,7 @@ public interface SkuService {
* @param ids * @param ids
* @return sku * @return sku
*/ */
List<SkuDO> getSkuList(Collection<Integer> ids); List<ProductSkuDO> getSkuList(Collection<Integer> ids);
/** /**
* sku * sku
@ -57,7 +57,7 @@ public interface SkuService {
* @param pageReqVO * @param pageReqVO
* @return sku * @return sku
*/ */
PageResult<SkuDO> getSkuPage(SkuPageReqVO pageReqVO); PageResult<ProductSkuDO> getSkuPage(ProductSkuPageReqVO pageReqVO);
/** /**
* sku, Excel * sku, Excel
@ -65,6 +65,6 @@ public interface SkuService {
* @param exportReqVO * @param exportReqVO
* @return sku * @return sku
*/ */
List<SkuDO> getSkuList(SkuExportReqVO exportReqVO); List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO);
} }

View File

@ -0,0 +1,82 @@
package cn.iocoder.yudao.module.product.service.sku;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
/**
* sku Service
*
* @author
*/
@Service
@Validated
public class ProductSkuServiceImpl implements ProductSkuService {
@Resource
private ProductSkuMapper ProductSkuMapper;
@Override
public Integer createSku(ProductSkuCreateReqVO 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(Integer id) {
// 校验存在
this.validateSkuExists(id);
// 删除
ProductSkuMapper.deleteById(id);
}
private void validateSkuExists(Integer id) {
if (ProductSkuMapper.selectById(id) == null) {
throw exception(SKU_NOT_EXISTS);
}
}
@Override
public ProductSkuDO getSku(Integer id) {
return ProductSkuMapper.selectById(id);
}
@Override
public List<ProductSkuDO> getSkuList(Collection<Integer> ids) {
return ProductSkuMapper.selectBatchIds(ids);
}
@Override
public PageResult<ProductSkuDO> getSkuPage(ProductSkuPageReqVO pageReqVO) {
return ProductSkuMapper.selectPage(pageReqVO);
}
@Override
public List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO) {
return ProductSkuMapper.selectList(exportReqVO);
}
}

View File

@ -1,82 +0,0 @@
package cn.iocoder.yudao.module.product.service.sku;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.convert.sku.SkuConvert;
import cn.iocoder.yudao.module.product.dal.mysql.sku.SkuMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
/**
* sku Service
*
* @author
*/
@Service
@Validated
public class SkuServiceImpl implements SkuService {
@Resource
private SkuMapper skuMapper;
@Override
public Integer createSku(SkuCreateReqVO createReqVO) {
// 插入
SkuDO sku = SkuConvert.INSTANCE.convert(createReqVO);
skuMapper.insert(sku);
// 返回
return sku.getId();
}
@Override
public void updateSku(SkuUpdateReqVO updateReqVO) {
// 校验存在
this.validateSkuExists(updateReqVO.getId());
// 更新
SkuDO updateObj = SkuConvert.INSTANCE.convert(updateReqVO);
skuMapper.updateById(updateObj);
}
@Override
public void deleteSku(Integer id) {
// 校验存在
this.validateSkuExists(id);
// 删除
skuMapper.deleteById(id);
}
private void validateSkuExists(Integer id) {
if (skuMapper.selectById(id) == null) {
throw exception(SKU_NOT_EXISTS);
}
}
@Override
public SkuDO getSku(Integer id) {
return skuMapper.selectById(id);
}
@Override
public List<SkuDO> getSkuList(Collection<Integer> ids) {
return skuMapper.selectBatchIds(ids);
}
@Override
public PageResult<SkuDO> getSkuPage(SkuPageReqVO pageReqVO) {
return skuMapper.selectPage(pageReqVO);
}
@Override
public List<SkuDO> getSkuList(SkuExportReqVO exportReqVO) {
return skuMapper.selectList(exportReqVO);
}
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.service.spu;
import java.util.*; import java.util.*;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
/** /**
@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
* *
* @author * @author
*/ */
public interface SpuService { public interface ProductSpuService {
/** /**
* spu * spu
@ -19,7 +19,7 @@ public interface SpuService {
* @param createReqVO * @param createReqVO
* @return * @return
*/ */
Integer createSpu(@Valid SpuCreateReqVO createReqVO); Integer createSpu(@Valid ProductSpuCreateReqVO createReqVO);
/** /**
* spu * spu
@ -41,7 +41,7 @@ public interface SpuService {
* @param id * @param id
* @return spu * @return spu
*/ */
SpuDO getSpu(Integer id); ProductSpuDO getSpu(Integer id);
/** /**
* spu * spu
@ -49,7 +49,7 @@ public interface SpuService {
* @param ids * @param ids
* @return spu * @return spu
*/ */
List<SpuDO> getSpuList(Collection<Integer> ids); List<ProductSpuDO> getSpuList(Collection<Integer> ids);
/** /**
* spu * spu
@ -57,7 +57,7 @@ public interface SpuService {
* @param pageReqVO * @param pageReqVO
* @return spu * @return spu
*/ */
PageResult<SpuDO> getSpuPage(SpuPageReqVO pageReqVO); PageResult<ProductSpuDO> getSpuPage(SpuPageReqVO pageReqVO);
/** /**
* spu, Excel * spu, Excel
@ -65,6 +65,6 @@ public interface SpuService {
* @param exportReqVO * @param exportReqVO
* @return spu * @return spu
*/ */
List<SpuDO> getSpuList(SpuExportReqVO exportReqVO); List<ProductSpuDO> getSpuList(SpuExportReqVO exportReqVO);
} }

View File

@ -6,11 +6,11 @@ import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.convert.spu.SpuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.dal.mysql.spu.SpuMapper; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
@ -22,16 +22,16 @@ import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
*/ */
@Service @Service
@Validated @Validated
public class SpuServiceImpl implements SpuService { public class ProductSpuServiceImpl implements ProductSpuService {
@Resource @Resource
private SpuMapper spuMapper; private ProductSpuMapper ProductSpuMapper;
@Override @Override
public Integer createSpu(SpuCreateReqVO createReqVO) { public Integer createSpu(ProductSpuCreateReqVO createReqVO) {
// 插入 // 插入
SpuDO spu = SpuConvert.INSTANCE.convert(createReqVO); ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
spuMapper.insert(spu); ProductSpuMapper.insert(spu);
// 返回 // 返回
return spu.getId(); return spu.getId();
} }
@ -41,8 +41,8 @@ public class SpuServiceImpl implements SpuService {
// 校验存在 // 校验存在
this.validateSpuExists(updateReqVO.getId()); this.validateSpuExists(updateReqVO.getId());
// 更新 // 更新
SpuDO updateObj = SpuConvert.INSTANCE.convert(updateReqVO); ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
spuMapper.updateById(updateObj); ProductSpuMapper.updateById(updateObj);
} }
@Override @Override
@ -50,33 +50,33 @@ public class SpuServiceImpl implements SpuService {
// 校验存在 // 校验存在
this.validateSpuExists(id); this.validateSpuExists(id);
// 删除 // 删除
spuMapper.deleteById(id); ProductSpuMapper.deleteById(id);
} }
private void validateSpuExists(Integer id) { private void validateSpuExists(Integer id) {
if (spuMapper.selectById(id) == null) { if (ProductSpuMapper.selectById(id) == null) {
throw exception(SPU_NOT_EXISTS); throw exception(SPU_NOT_EXISTS);
} }
} }
@Override @Override
public SpuDO getSpu(Integer id) { public ProductSpuDO getSpu(Integer id) {
return spuMapper.selectById(id); return ProductSpuMapper.selectById(id);
} }
@Override @Override
public List<SpuDO> getSpuList(Collection<Integer> ids) { public List<ProductSpuDO> getSpuList(Collection<Integer> ids) {
return spuMapper.selectBatchIds(ids); return ProductSpuMapper.selectBatchIds(ids);
} }
@Override @Override
public PageResult<SpuDO> getSpuPage(SpuPageReqVO pageReqVO) { public PageResult<ProductSpuDO> getSpuPage(SpuPageReqVO pageReqVO) {
return spuMapper.selectPage(pageReqVO); return ProductSpuMapper.selectPage(pageReqVO);
} }
@Override @Override
public List<SpuDO> getSpuList(SpuExportReqVO exportReqVO) { public List<ProductSpuDO> getSpuList(SpuExportReqVO exportReqVO) {
return spuMapper.selectList(exportReqVO); return ProductSpuMapper.selectList(exportReqVO);
} }
} }

View File

@ -9,8 +9,8 @@ import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.mysql.sku.SkuMapper; import cn.iocoder.yudao.module.product.dal.mysql.sku.ProductSkuMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -27,71 +27,71 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
/** /**
* {@link SkuServiceImpl} * {@link ProductSkuServiceImpl}
* *
* @author * @author
*/ */
@Import(SkuServiceImpl.class) @Import(ProductSkuServiceImpl.class)
public class SkuServiceImplTest extends BaseDbUnitTest { public class SkuServiceImplTest extends BaseDbUnitTest {
@Resource @Resource
private SkuServiceImpl skuService; private ProductSkuServiceImpl ProductSkuService;
@Resource @Resource
private SkuMapper skuMapper; private ProductSkuMapper ProductSkuMapper;
@Test @Test
public void testCreateSku_success() { public void testCreateSku_success() {
// 准备参数 // 准备参数
SkuCreateReqVO reqVO = randomPojo(SkuCreateReqVO.class); ProductSkuCreateReqVO reqVO = randomPojo(ProductSkuCreateReqVO.class);
// 调用 // 调用
Integer skuId = skuService.createSku(reqVO); Integer skuId = ProductSkuService.createSku(reqVO);
// 断言 // 断言
assertNotNull(skuId); assertNotNull(skuId);
// 校验记录的属性是否正确 // 校验记录的属性是否正确
SkuDO sku = skuMapper.selectById(skuId); ProductSkuDO sku = ProductSkuMapper.selectById(skuId);
assertPojoEquals(reqVO, sku); assertPojoEquals(reqVO, sku);
} }
@Test @Test
public void testUpdateSku_success() { public void testUpdateSku_success() {
// mock 数据 // mock 数据
SkuDO dbSku = randomPojo(SkuDO.class); ProductSkuDO dbSku = randomPojo(ProductSkuDO.class);
skuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据 ProductSkuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
SkuUpdateReqVO reqVO = randomPojo(SkuUpdateReqVO.class, o -> { ProductSkuUpdateReqVO reqVO = randomPojo(ProductSkuUpdateReqVO.class, o -> {
o.setId(dbSku.getId()); // 设置更新的 ID o.setId(dbSku.getId()); // 设置更新的 ID
}); });
// 调用 // 调用
skuService.updateSku(reqVO); ProductSkuService.updateSku(reqVO);
// 校验是否更新正确 // 校验是否更新正确
SkuDO sku = skuMapper.selectById(reqVO.getId()); // 获取最新的 ProductSkuDO sku = ProductSkuMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, sku); assertPojoEquals(reqVO, sku);
} }
@Test @Test
public void testUpdateSku_notExists() { public void testUpdateSku_notExists() {
// 准备参数 // 准备参数
SkuUpdateReqVO reqVO = randomPojo(SkuUpdateReqVO.class); ProductSkuUpdateReqVO reqVO = randomPojo(ProductSkuUpdateReqVO.class);
// 调用, 并断言异常 // 调用, 并断言异常
assertServiceException(() -> skuService.updateSku(reqVO), SKU_NOT_EXISTS); assertServiceException(() -> ProductSkuService.updateSku(reqVO), SKU_NOT_EXISTS);
} }
@Test @Test
public void testDeleteSku_success() { public void testDeleteSku_success() {
// mock 数据 // mock 数据
SkuDO dbSku = randomPojo(SkuDO.class); ProductSkuDO dbSku = randomPojo(ProductSkuDO.class);
skuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据 ProductSkuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
Integer id = dbSku.getId(); Integer id = dbSku.getId();
// 调用 // 调用
skuService.deleteSku(id); ProductSkuService.deleteSku(id);
// 校验数据不存在了 // 校验数据不存在了
assertNull(skuMapper.selectById(id)); assertNull(ProductSkuMapper.selectById(id));
} }
@Test @Test
@ -100,14 +100,14 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
Integer id = 1; Integer id = 1;
// 调用, 并断言异常 // 调用, 并断言异常
assertServiceException(() -> skuService.deleteSku(id), SKU_NOT_EXISTS); assertServiceException(() -> ProductSkuService.deleteSku(id), SKU_NOT_EXISTS);
} }
@Test @Test
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSkuPage() { public void testGetSkuPage() {
// mock 数据 // mock 数据
SkuDO dbSku = randomPojo(SkuDO.class, o -> { // 等会查询到 ProductSkuDO dbSku = randomPojo(ProductSkuDO.class, o -> { // 等会查询到
o.setSpuId(null); o.setSpuId(null);
o.setProperties(null); o.setProperties(null);
o.setPrice(null); o.setPrice(null);
@ -118,27 +118,27 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
o.setStatus(null); o.setStatus(null);
o.setCreateTime(null); o.setCreateTime(null);
}); });
skuMapper.insert(dbSku); ProductSkuMapper.insert(dbSku);
// 测试 spuId 不匹配 // 测试 spuId 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null)));
// 测试 properties 不匹配 // 测试 properties 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null)));
// 测试 price 不匹配 // 测试 price 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null)));
// 测试 originalPrice 不匹配 // 测试 originalPrice 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
// 测试 costPrice 不匹配 // 测试 costPrice 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
// 测试 barCode 不匹配 // 测试 barCode 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
// 测试 picUrl 不匹配 // 测试 picUrl 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null)));
// 测试 status 不匹配 // 测试 status 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null)));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null)));
// 准备参数 // 准备参数
SkuPageReqVO reqVO = new SkuPageReqVO(); ProductSkuPageReqVO reqVO = new ProductSkuPageReqVO();
reqVO.setSpuId(null); reqVO.setSpuId(null);
reqVO.setProperties(null); reqVO.setProperties(null);
reqVO.setPrice(null); reqVO.setPrice(null);
@ -151,7 +151,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
reqVO.setEndCreateTime(null); reqVO.setEndCreateTime(null);
// 调用 // 调用
PageResult<SkuDO> pageResult = skuService.getSkuPage(reqVO); PageResult<ProductSkuDO> pageResult = ProductSkuService.getSkuPage(reqVO);
// 断言 // 断言
assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size()); assertEquals(1, pageResult.getList().size());
@ -162,7 +162,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSkuList() { public void testGetSkuList() {
// mock 数据 // mock 数据
SkuDO dbSku = randomPojo(SkuDO.class, o -> { // 等会查询到 ProductSkuDO dbSku = randomPojo(ProductSkuDO.class, o -> { // 等会查询到
o.setSpuId(null); o.setSpuId(null);
o.setProperties(null); o.setProperties(null);
o.setPrice(null); o.setPrice(null);
@ -173,27 +173,27 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
o.setStatus(null); o.setStatus(null);
o.setCreateTime(null); o.setCreateTime(null);
}); });
skuMapper.insert(dbSku); ProductSkuMapper.insert(dbSku);
// 测试 spuId 不匹配 // 测试 spuId 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null)));
// 测试 properties 不匹配 // 测试 properties 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setProperties(null)));
// 测试 price 不匹配 // 测试 price 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null)));
// 测试 originalPrice 不匹配 // 测试 originalPrice 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
// 测试 costPrice 不匹配 // 测试 costPrice 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
// 测试 barCode 不匹配 // 测试 barCode 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
// 测试 picUrl 不匹配 // 测试 picUrl 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null)));
// 测试 status 不匹配 // 测试 status 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setStatus(null)));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null))); ProductSkuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null)));
// 准备参数 // 准备参数
SkuExportReqVO reqVO = new SkuExportReqVO(); ProductSkuExportReqVO reqVO = new ProductSkuExportReqVO();
reqVO.setSpuId(null); reqVO.setSpuId(null);
reqVO.setProperties(null); reqVO.setProperties(null);
reqVO.setPrice(null); reqVO.setPrice(null);
@ -206,7 +206,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
reqVO.setEndCreateTime(null); reqVO.setEndCreateTime(null);
// 调用 // 调用
List<SkuDO> list = skuService.getSkuList(reqVO); List<ProductSkuDO> list = ProductSkuService.getSkuList(reqVO);
// 断言 // 断言
assertEquals(1, list.size()); assertEquals(1, list.size());
assertPojoEquals(dbSku, list.get(0)); assertPojoEquals(dbSku, list.get(0));

View File

@ -9,8 +9,8 @@ import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.dal.mysql.spu.SpuMapper; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -27,38 +27,38 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
/** /**
* {@link SpuServiceImpl} * {@link ProductSpuServiceImpl}
* *
* @author * @author
*/ */
@Import(SpuServiceImpl.class) @Import(ProductSpuServiceImpl.class)
public class SpuServiceImplTest extends BaseDbUnitTest { public class ProductSpuServiceImplTest extends BaseDbUnitTest {
@Resource @Resource
private SpuServiceImpl spuService; private ProductSpuServiceImpl spuService;
@Resource @Resource
private SpuMapper spuMapper; private ProductSpuMapper ProductSpuMapper;
@Test @Test
public void testCreateSpu_success() { public void testCreateSpu_success() {
// 准备参数 // 准备参数
SpuCreateReqVO reqVO = randomPojo(SpuCreateReqVO.class); ProductSpuCreateReqVO reqVO = randomPojo(ProductSpuCreateReqVO.class);
// 调用 // 调用
Integer spuId = spuService.createSpu(reqVO); Integer spuId = spuService.createSpu(reqVO);
// 断言 // 断言
assertNotNull(spuId); assertNotNull(spuId);
// 校验记录的属性是否正确 // 校验记录的属性是否正确
SpuDO spu = spuMapper.selectById(spuId); ProductSpuDO spu = ProductSpuMapper.selectById(spuId);
assertPojoEquals(reqVO, spu); assertPojoEquals(reqVO, spu);
} }
@Test @Test
public void testUpdateSpu_success() { public void testUpdateSpu_success() {
// mock 数据 // mock 数据
SpuDO dbSpu = randomPojo(SpuDO.class); ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class);
spuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据 ProductSpuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
SpuUpdateReqVO reqVO = randomPojo(SpuUpdateReqVO.class, o -> { SpuUpdateReqVO reqVO = randomPojo(SpuUpdateReqVO.class, o -> {
o.setId(dbSpu.getId()); // 设置更新的 ID o.setId(dbSpu.getId()); // 设置更新的 ID
@ -67,7 +67,7 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
// 调用 // 调用
spuService.updateSpu(reqVO); spuService.updateSpu(reqVO);
// 校验是否更新正确 // 校验是否更新正确
SpuDO spu = spuMapper.selectById(reqVO.getId()); // 获取最新的 ProductSpuDO spu = ProductSpuMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, spu); assertPojoEquals(reqVO, spu);
} }
@ -83,15 +83,15 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
@Test @Test
public void testDeleteSpu_success() { public void testDeleteSpu_success() {
// mock 数据 // mock 数据
SpuDO dbSpu = randomPojo(SpuDO.class); ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class);
spuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据 ProductSpuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
Integer id = dbSpu.getId(); Integer id = dbSpu.getId();
// 调用 // 调用
spuService.deleteSpu(id); spuService.deleteSpu(id);
// 校验数据不存在了 // 校验数据不存在了
assertNull(spuMapper.selectById(id)); assertNull(ProductSpuMapper.selectById(id));
} }
@Test @Test
@ -107,7 +107,7 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSpuPage() { public void testGetSpuPage() {
// mock 数据 // mock 数据
SpuDO dbSpu = randomPojo(SpuDO.class, o -> { // 等会查询到 ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class, o -> { // 等会查询到
o.setName(null); o.setName(null);
o.setSellPoint(null); o.setSellPoint(null);
o.setDescription(null); o.setDescription(null);
@ -120,29 +120,29 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
o.setStatus(null); o.setStatus(null);
o.setCreateTime(null); o.setCreateTime(null);
}); });
spuMapper.insert(dbSpu); ProductSpuMapper.insert(dbSpu);
// 测试 name 不匹配 // 测试 name 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null)));
// 测试 sellPoint 不匹配 // 测试 sellPoint 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null)));
// 测试 description 不匹配 // 测试 description 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null)));
// 测试 categoryId 不匹配 // 测试 categoryId 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCategoryId(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCategoryId(null)));
// 测试 picUrls 不匹配 // 测试 picUrls 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null)));
// 测试 sort 不匹配 // 测试 sort 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null)));
// 测试 likeCount 不匹配 // 测试 likeCount 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
// 测试 price 不匹配 // 测试 price 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null)));
// 测试 quantity 不匹配 // 测试 quantity 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
// 测试 status 不匹配 // 测试 status 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null)));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null)));
// 准备参数 // 准备参数
SpuPageReqVO reqVO = new SpuPageReqVO(); SpuPageReqVO reqVO = new SpuPageReqVO();
reqVO.setName(null); reqVO.setName(null);
@ -159,7 +159,7 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
reqVO.setEndCreateTime(null); reqVO.setEndCreateTime(null);
// 调用 // 调用
PageResult<SpuDO> pageResult = spuService.getSpuPage(reqVO); PageResult<ProductSpuDO> pageResult = spuService.getSpuPage(reqVO);
// 断言 // 断言
assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size()); assertEquals(1, pageResult.getList().size());
@ -170,7 +170,7 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
public void testGetSpuList() { public void testGetSpuList() {
// mock 数据 // mock 数据
SpuDO dbSpu = randomPojo(SpuDO.class, o -> { // 等会查询到 ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class, o -> { // 等会查询到
o.setName(null); o.setName(null);
o.setSellPoint(null); o.setSellPoint(null);
o.setDescription(null); o.setDescription(null);
@ -183,29 +183,29 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
o.setStatus(null); o.setStatus(null);
o.setCreateTime(null); o.setCreateTime(null);
}); });
spuMapper.insert(dbSpu); ProductSpuMapper.insert(dbSpu);
// 测试 name 不匹配 // 测试 name 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null)));
// 测试 sellPoint 不匹配 // 测试 sellPoint 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null)));
// 测试 description 不匹配 // 测试 description 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null)));
// 测试 categoryId 不匹配 // 测试 categoryId 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCategoryId(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCategoryId(null)));
// 测试 picUrls 不匹配 // 测试 picUrls 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null)));
// 测试 sort 不匹配 // 测试 sort 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null)));
// 测试 likeCount 不匹配 // 测试 likeCount 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
// 测试 price 不匹配 // 测试 price 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null)));
// 测试 quantity 不匹配 // 测试 quantity 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
// 测试 status 不匹配 // 测试 status 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setStatus(null)));
// 测试 createTime 不匹配 // 测试 createTime 不匹配
spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null))); ProductSpuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null)));
// 准备参数 // 准备参数
SpuExportReqVO reqVO = new SpuExportReqVO(); SpuExportReqVO reqVO = new SpuExportReqVO();
reqVO.setName(null); reqVO.setName(null);
@ -222,7 +222,7 @@ public class SpuServiceImplTest extends BaseDbUnitTest {
reqVO.setEndCreateTime(null); reqVO.setEndCreateTime(null);
// 调用 // 调用
List<SpuDO> list = spuService.getSpuList(reqVO); List<ProductSpuDO> list = spuService.getSpuList(reqVO);
// 断言 // 断言
assertEquals(1, list.size()); assertEquals(1, list.size());
assertPojoEquals(dbSpu, list.get(0)); assertPojoEquals(dbSpu, list.get(0));