Commit 279127298baca6ea442d0b8de7f0bc2a6080a5a0

Authored by franky
1 parent 9f900462

spu和sku 自动代码生成

Showing 29 changed files with 1782 additions and 0 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java
... ... @@ -22,4 +22,10 @@ public interface ErrorCodeConstants {
22 22  
23 23 // ========== 规格值 1008004000 ==========
24 24 ErrorCode ATTR_VALUE_NOT_EXISTS = new ErrorCode(1008004000, "规格值不存在");
  25 +
  26 + // ========== 商品spu 1008005000 ==========
  27 + ErrorCode SPU_NOT_EXISTS = new ErrorCode(1008005000, "商品spu不存在");
  28 +
  29 + // ========== 商品sku 1008006000 ==========
  30 + ErrorCode SKU_NOT_EXISTS = new ErrorCode(1008006000, "商品sku不存在");
25 31 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/SkuController.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku;
  2 +
  3 +import org.springframework.web.bind.annotation.*;
  4 +import javax.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +import org.springframework.security.access.prepost.PreAuthorize;
  7 +import io.swagger.annotations.*;
  8 +
  9 +import javax.validation.constraints.*;
  10 +import javax.validation.*;
  11 +import javax.servlet.http.*;
  12 +import java.util.*;
  13 +import java.io.IOException;
  14 +
  15 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  16 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  17 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  18 +
  19 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  20 +
  21 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  22 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
  23 +
  24 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  25 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
  26 +import cn.iocoder.yudao.module.product.convert.sku.SkuConvert;
  27 +import cn.iocoder.yudao.module.product.service.sku.SkuService;
  28 +
  29 +@Api(tags = "管理后台 - 商品sku")
  30 +@RestController
  31 +@RequestMapping("/product/sku")
  32 +@Validated
  33 +public class SkuController {
  34 +
  35 + @Resource
  36 + private SkuService skuService;
  37 +
  38 + @PostMapping("/create")
  39 + @ApiOperation("创建商品sku")
  40 + @PreAuthorize("@ss.hasPermission('product:sku:create')")
  41 + public CommonResult<Integer> createSku(@Valid @RequestBody SkuCreateReqVO createReqVO) {
  42 + return success(skuService.createSku(createReqVO));
  43 + }
  44 +
  45 + @PutMapping("/update")
  46 + @ApiOperation("更新商品sku")
  47 + @PreAuthorize("@ss.hasPermission('product:sku:update')")
  48 + public CommonResult<Boolean> updateSku(@Valid @RequestBody SkuUpdateReqVO updateReqVO) {
  49 + skuService.updateSku(updateReqVO);
  50 + return success(true);
  51 + }
  52 +
  53 + @DeleteMapping("/delete")
  54 + @ApiOperation("删除商品sku")
  55 + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
  56 + @PreAuthorize("@ss.hasPermission('product:sku:delete')")
  57 + public CommonResult<Boolean> deleteSku(@RequestParam("id") Integer id) {
  58 + skuService.deleteSku(id);
  59 + return success(true);
  60 + }
  61 +
  62 + @GetMapping("/get")
  63 + @ApiOperation("获得商品sku")
  64 + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
  65 + @PreAuthorize("@ss.hasPermission('product:sku:query')")
  66 + public CommonResult<SkuRespVO> getSku(@RequestParam("id") Integer id) {
  67 + SkuDO sku = skuService.getSku(id);
  68 + return success(SkuConvert.INSTANCE.convert(sku));
  69 + }
  70 +
  71 + @GetMapping("/list")
  72 + @ApiOperation("获得商品sku列表")
  73 + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
  74 + @PreAuthorize("@ss.hasPermission('product:sku:query')")
  75 + public CommonResult<List<SkuRespVO>> getSkuList(@RequestParam("ids") Collection<Integer> ids) {
  76 + List<SkuDO> list = skuService.getSkuList(ids);
  77 + return success(SkuConvert.INSTANCE.convertList(list));
  78 + }
  79 +
  80 + @GetMapping("/page")
  81 + @ApiOperation("获得商品sku分页")
  82 + @PreAuthorize("@ss.hasPermission('product:sku:query')")
  83 + public CommonResult<PageResult<SkuRespVO>> getSkuPage(@Valid SkuPageReqVO pageVO) {
  84 + PageResult<SkuDO> pageResult = skuService.getSkuPage(pageVO);
  85 + return success(SkuConvert.INSTANCE.convertPage(pageResult));
  86 + }
  87 +
  88 + @GetMapping("/export-excel")
  89 + @ApiOperation("导出商品sku Excel")
  90 + @PreAuthorize("@ss.hasPermission('product:sku:export')")
  91 + @OperateLog(type = EXPORT)
  92 + public void exportSkuExcel(@Valid SkuExportReqVO exportReqVO,
  93 + HttpServletResponse response) throws IOException {
  94 + List<SkuDO> list = skuService.getSkuList(exportReqVO);
  95 + // 导出 Excel
  96 + List<SkuExcelVO> datas = SkuConvert.INSTANCE.convertList02(list);
  97 + ExcelUtils.write(response, "商品sku.xls", "数据", SkuExcelVO.class, datas);
  98 + }
  99 +
  100 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuBaseVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +/**
  9 +* 商品sku Base VO,提供给添加、修改、详细的子 VO 使用
  10 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  11 +*/
  12 +@Data
  13 +public class SkuBaseVO {
  14 +
  15 + @ApiModelProperty(value = "spu编号", required = true)
  16 + @NotNull(message = "spu编号不能为空")
  17 + private Integer spuId;
  18 +
  19 + @ApiModelProperty(value = "状态: 1-正常 2-禁用")
  20 + private Integer skuStatus;
  21 +
  22 + @ApiModelProperty(value = "规格值数组, 以逗号隔开", required = true)
  23 + @NotNull(message = "规格值数组, 以逗号隔开不能为空")
  24 + private String attrs;
  25 +
  26 + @ApiModelProperty(value = "销售价格,单位:分", required = true)
  27 + @NotNull(message = "销售价格,单位:分不能为空")
  28 + private Integer price;
  29 +
  30 + @ApiModelProperty(value = "原价, 单位: 分", required = true)
  31 + @NotNull(message = "原价, 单位: 分不能为空")
  32 + private Integer originalPrice;
  33 +
  34 + @ApiModelProperty(value = "成本价,单位: 分", required = true)
  35 + @NotNull(message = "成本价,单位: 分不能为空")
  36 + private Integer costPrice;
  37 +
  38 + @ApiModelProperty(value = "条形码", required = true)
  39 + @NotNull(message = "条形码不能为空")
  40 + private String barCode;
  41 +
  42 + @ApiModelProperty(value = "图片地址", required = true)
  43 + @NotNull(message = "图片地址不能为空")
  44 + private String picUrl;
  45 +
  46 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuCreateReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +@ApiModel("管理后台 - 商品sku创建 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class SkuCreateReqVO extends SkuBaseVO {
  13 +
  14 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuExcelVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +
  7 +import com.alibaba.excel.annotation.ExcelProperty;
  8 +
  9 +/**
  10 + * 商品sku Excel VO
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Data
  15 +public class SkuExcelVO {
  16 +
  17 + @ExcelProperty("主键")
  18 + private Integer id;
  19 +
  20 + @ExcelProperty("创建时间")
  21 + private Date createTime;
  22 +
  23 + @ExcelProperty("spu编号")
  24 + private Integer spuId;
  25 +
  26 + @ExcelProperty("状态: 1-正常 2-禁用")
  27 + private Integer skuStatus;
  28 +
  29 + @ExcelProperty("规格值数组, 以逗号隔开")
  30 + private String attrs;
  31 +
  32 + @ExcelProperty("销售价格,单位:分")
  33 + private Integer price;
  34 +
  35 + @ExcelProperty("原价, 单位: 分")
  36 + private Integer originalPrice;
  37 +
  38 + @ExcelProperty("成本价,单位: 分")
  39 + private Integer costPrice;
  40 +
  41 + @ExcelProperty("条形码")
  42 + private String barCode;
  43 +
  44 + @ExcelProperty("图片地址")
  45 + private String picUrl;
  46 +
  47 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuExportReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import org.springframework.format.annotation.DateTimeFormat;
  8 +
  9 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  10 +
  11 +@ApiModel(value = "管理后台 - 商品sku Excel 导出 Request VO", description = "参数和 SkuPageReqVO 是一致的")
  12 +@Data
  13 +public class SkuExportReqVO {
  14 +
  15 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  16 + @ApiModelProperty(value = "开始创建时间")
  17 + private Date beginCreateTime;
  18 +
  19 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  20 + @ApiModelProperty(value = "结束创建时间")
  21 + private Date endCreateTime;
  22 +
  23 + @ApiModelProperty(value = "spu编号")
  24 + private Integer spuId;
  25 +
  26 + @ApiModelProperty(value = "状态: 1-正常 2-禁用")
  27 + private Integer skuStatus;
  28 +
  29 + @ApiModelProperty(value = "规格值数组, 以逗号隔开")
  30 + private String attrs;
  31 +
  32 + @ApiModelProperty(value = "销售价格,单位:分")
  33 + private Integer price;
  34 +
  35 + @ApiModelProperty(value = "原价, 单位: 分")
  36 + private Integer originalPrice;
  37 +
  38 + @ApiModelProperty(value = "成本价,单位: 分")
  39 + private Integer costPrice;
  40 +
  41 + @ApiModelProperty(value = "条形码")
  42 + private String barCode;
  43 +
  44 + @ApiModelProperty(value = "图片地址")
  45 + private String picUrl;
  46 +
  47 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuPageReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import org.springframework.format.annotation.DateTimeFormat;
  8 +
  9 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  10 +
  11 +@ApiModel("管理后台 - 商品sku分页 Request VO")
  12 +@Data
  13 +@EqualsAndHashCode(callSuper = true)
  14 +@ToString(callSuper = true)
  15 +public class SkuPageReqVO extends PageParam {
  16 +
  17 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  18 + @ApiModelProperty(value = "开始创建时间")
  19 + private Date beginCreateTime;
  20 +
  21 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  22 + @ApiModelProperty(value = "结束创建时间")
  23 + private Date endCreateTime;
  24 +
  25 + @ApiModelProperty(value = "spu编号")
  26 + private Integer spuId;
  27 +
  28 + @ApiModelProperty(value = "状态: 1-正常 2-禁用")
  29 + private Integer skuStatus;
  30 +
  31 + @ApiModelProperty(value = "规格值数组, 以逗号隔开")
  32 + private String attrs;
  33 +
  34 + @ApiModelProperty(value = "销售价格,单位:分")
  35 + private Integer price;
  36 +
  37 + @ApiModelProperty(value = "原价, 单位: 分")
  38 + private Integer originalPrice;
  39 +
  40 + @ApiModelProperty(value = "成本价,单位: 分")
  41 + private Integer costPrice;
  42 +
  43 + @ApiModelProperty(value = "条形码")
  44 + private String barCode;
  45 +
  46 + @ApiModelProperty(value = "图片地址")
  47 + private String picUrl;
  48 +
  49 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuRespVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +
  7 +@ApiModel("管理后台 - 商品sku Response VO")
  8 +@Data
  9 +@EqualsAndHashCode(callSuper = true)
  10 +@ToString(callSuper = true)
  11 +public class SkuRespVO extends SkuBaseVO {
  12 +
  13 + @ApiModelProperty(value = "主键", required = true)
  14 + private Integer id;
  15 +
  16 + @ApiModelProperty(value = "创建时间")
  17 + private Date createTime;
  18 +
  19 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/SkuUpdateReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +@ApiModel("管理后台 - 商品sku更新 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class SkuUpdateReqVO extends SkuBaseVO {
  13 +
  14 + @ApiModelProperty(value = "主键", required = true)
  15 + @NotNull(message = "主键不能为空")
  16 + private Integer id;
  17 +
  18 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/SpuController.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu;
  2 +
  3 +import org.springframework.web.bind.annotation.*;
  4 +import javax.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +import org.springframework.security.access.prepost.PreAuthorize;
  7 +import io.swagger.annotations.*;
  8 +
  9 +import javax.validation.constraints.*;
  10 +import javax.validation.*;
  11 +import javax.servlet.http.*;
  12 +import java.util.*;
  13 +import java.io.IOException;
  14 +
  15 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  16 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  17 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  18 +
  19 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  20 +
  21 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  22 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
  23 +
  24 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  25 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
  26 +import cn.iocoder.yudao.module.product.convert.spu.SpuConvert;
  27 +import cn.iocoder.yudao.module.product.service.spu.SpuService;
  28 +
  29 +@Api(tags = "管理后台 - 商品spu")
  30 +@RestController
  31 +@RequestMapping("/product/spu")
  32 +@Validated
  33 +public class SpuController {
  34 +
  35 + @Resource
  36 + private SpuService spuService;
  37 +
  38 + @PostMapping("/create")
  39 + @ApiOperation("创建商品spu")
  40 + @PreAuthorize("@ss.hasPermission('product:spu:create')")
  41 + public CommonResult<Integer> createSpu(@Valid @RequestBody SpuCreateReqVO createReqVO) {
  42 + return success(spuService.createSpu(createReqVO));
  43 + }
  44 +
  45 + @PutMapping("/update")
  46 + @ApiOperation("更新商品spu")
  47 + @PreAuthorize("@ss.hasPermission('product:spu:update')")
  48 + public CommonResult<Boolean> updateSpu(@Valid @RequestBody SpuUpdateReqVO updateReqVO) {
  49 + spuService.updateSpu(updateReqVO);
  50 + return success(true);
  51 + }
  52 +
  53 + @DeleteMapping("/delete")
  54 + @ApiOperation("删除商品spu")
  55 + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
  56 + @PreAuthorize("@ss.hasPermission('product:spu:delete')")
  57 + public CommonResult<Boolean> deleteSpu(@RequestParam("id") Integer id) {
  58 + spuService.deleteSpu(id);
  59 + return success(true);
  60 + }
  61 +
  62 + @GetMapping("/get")
  63 + @ApiOperation("获得商品spu")
  64 + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
  65 + @PreAuthorize("@ss.hasPermission('product:spu:query')")
  66 + public CommonResult<SpuRespVO> getSpu(@RequestParam("id") Integer id) {
  67 + SpuDO spu = spuService.getSpu(id);
  68 + return success(SpuConvert.INSTANCE.convert(spu));
  69 + }
  70 +
  71 + @GetMapping("/list")
  72 + @ApiOperation("获得商品spu列表")
  73 + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
  74 + @PreAuthorize("@ss.hasPermission('product:spu:query')")
  75 + public CommonResult<List<SpuRespVO>> getSpuList(@RequestParam("ids") Collection<Integer> ids) {
  76 + List<SpuDO> list = spuService.getSpuList(ids);
  77 + return success(SpuConvert.INSTANCE.convertList(list));
  78 + }
  79 +
  80 + @GetMapping("/page")
  81 + @ApiOperation("获得商品spu分页")
  82 + @PreAuthorize("@ss.hasPermission('product:spu:query')")
  83 + public CommonResult<PageResult<SpuRespVO>> getSpuPage(@Valid SpuPageReqVO pageVO) {
  84 + PageResult<SpuDO> pageResult = spuService.getSpuPage(pageVO);
  85 + return success(SpuConvert.INSTANCE.convertPage(pageResult));
  86 + }
  87 +
  88 + @GetMapping("/export-excel")
  89 + @ApiOperation("导出商品spu Excel")
  90 + @PreAuthorize("@ss.hasPermission('product:spu:export')")
  91 + @OperateLog(type = EXPORT)
  92 + public void exportSpuExcel(@Valid SpuExportReqVO exportReqVO,
  93 + HttpServletResponse response) throws IOException {
  94 + List<SpuDO> list = spuService.getSpuList(exportReqVO);
  95 + // 导出 Excel
  96 + List<SpuExcelVO> datas = SpuConvert.INSTANCE.convertList02(list);
  97 + ExcelUtils.write(response, "商品spu.xls", "数据", SpuExcelVO.class, datas);
  98 + }
  99 +
  100 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuBaseVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +/**
  9 +* 商品spu Base VO,提供给添加、修改、详细的子 VO 使用
  10 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  11 +*/
  12 +@Data
  13 +public class SpuBaseVO {
  14 +
  15 + @ApiModelProperty(value = "商品名称")
  16 + private String name;
  17 +
  18 + @ApiModelProperty(value = "上下架状态: true 上架,false 下架")
  19 + private Boolean visible;
  20 +
  21 + @ApiModelProperty(value = "卖点", required = true)
  22 + @NotNull(message = "卖点不能为空")
  23 + private String sellPoint;
  24 +
  25 + @ApiModelProperty(value = "描述", required = true)
  26 + @NotNull(message = "描述不能为空")
  27 + private String description;
  28 +
  29 + @ApiModelProperty(value = "分类id", required = true)
  30 + @NotNull(message = "分类id不能为空")
  31 + private Integer cid;
  32 +
  33 + @ApiModelProperty(value = "列表图")
  34 + private String listPicUrl;
  35 +
  36 + @ApiModelProperty(value = "商品主图地址, 数组,以逗号分隔, 最多上传15张", required = true)
  37 + @NotNull(message = "商品主图地址, 数组,以逗号分隔, 最多上传15张不能为空")
  38 + private String picUrls;
  39 +
  40 + @ApiModelProperty(value = "排序字段", required = true)
  41 + @NotNull(message = "排序字段不能为空")
  42 + private Integer sort;
  43 +
  44 + @ApiModelProperty(value = "点赞初始人数")
  45 + private Integer likeCount;
  46 +
  47 + @ApiModelProperty(value = "价格")
  48 + private Integer price;
  49 +
  50 + @ApiModelProperty(value = "库存数量")
  51 + private Integer quantity;
  52 +
  53 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuCreateReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +@ApiModel("管理后台 - 商品spu创建 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class SpuCreateReqVO extends SpuBaseVO {
  13 +
  14 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExcelVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +
  7 +import com.alibaba.excel.annotation.ExcelProperty;
  8 +
  9 +/**
  10 + * 商品spu Excel VO
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Data
  15 +public class SpuExcelVO {
  16 +
  17 + @ExcelProperty("主键")
  18 + private Integer id;
  19 +
  20 + @ExcelProperty("创建时间")
  21 + private Date createTime;
  22 +
  23 + @ExcelProperty("商品名称")
  24 + private String name;
  25 +
  26 + @ExcelProperty("上下架状态: true 上架,false 下架")
  27 + private Boolean visible;
  28 +
  29 + @ExcelProperty("卖点")
  30 + private String sellPoint;
  31 +
  32 + @ExcelProperty("描述")
  33 + private String description;
  34 +
  35 + @ExcelProperty("分类id")
  36 + private Integer cid;
  37 +
  38 + @ExcelProperty("列表图")
  39 + private String listPicUrl;
  40 +
  41 + @ExcelProperty("商品主图地址, 数组,以逗号分隔, 最多上传15张")
  42 + private String picUrls;
  43 +
  44 + @ExcelProperty("排序字段")
  45 + private Integer sort;
  46 +
  47 + @ExcelProperty("点赞初始人数")
  48 + private Integer likeCount;
  49 +
  50 + @ExcelProperty("价格")
  51 + private Integer price;
  52 +
  53 + @ExcelProperty("库存数量")
  54 + private Integer quantity;
  55 +
  56 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuExportReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import org.springframework.format.annotation.DateTimeFormat;
  8 +
  9 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  10 +
  11 +@ApiModel(value = "管理后台 - 商品spu Excel 导出 Request VO", description = "参数和 SpuPageReqVO 是一致的")
  12 +@Data
  13 +public class SpuExportReqVO {
  14 +
  15 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  16 + @ApiModelProperty(value = "开始创建时间")
  17 + private Date beginCreateTime;
  18 +
  19 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  20 + @ApiModelProperty(value = "结束创建时间")
  21 + private Date endCreateTime;
  22 +
  23 + @ApiModelProperty(value = "商品名称")
  24 + private String name;
  25 +
  26 + @ApiModelProperty(value = "上下架状态: true 上架,false 下架")
  27 + private Boolean visible;
  28 +
  29 + @ApiModelProperty(value = "卖点")
  30 + private String sellPoint;
  31 +
  32 + @ApiModelProperty(value = "描述")
  33 + private String description;
  34 +
  35 + @ApiModelProperty(value = "分类id")
  36 + private Integer cid;
  37 +
  38 + @ApiModelProperty(value = "列表图")
  39 + private String listPicUrl;
  40 +
  41 + @ApiModelProperty(value = "商品主图地址, 数组,以逗号分隔, 最多上传15张")
  42 + private String picUrls;
  43 +
  44 + @ApiModelProperty(value = "排序字段")
  45 + private Integer sort;
  46 +
  47 + @ApiModelProperty(value = "点赞初始人数")
  48 + private Integer likeCount;
  49 +
  50 + @ApiModelProperty(value = "价格")
  51 + private Integer price;
  52 +
  53 + @ApiModelProperty(value = "库存数量")
  54 + private Integer quantity;
  55 +
  56 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuPageReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import org.springframework.format.annotation.DateTimeFormat;
  8 +
  9 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  10 +
  11 +@ApiModel("管理后台 - 商品spu分页 Request VO")
  12 +@Data
  13 +@EqualsAndHashCode(callSuper = true)
  14 +@ToString(callSuper = true)
  15 +public class SpuPageReqVO extends PageParam {
  16 +
  17 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  18 + @ApiModelProperty(value = "开始创建时间")
  19 + private Date beginCreateTime;
  20 +
  21 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  22 + @ApiModelProperty(value = "结束创建时间")
  23 + private Date endCreateTime;
  24 +
  25 + @ApiModelProperty(value = "商品名称")
  26 + private String name;
  27 +
  28 + @ApiModelProperty(value = "上下架状态: true 上架,false 下架")
  29 + private Boolean visible;
  30 +
  31 + @ApiModelProperty(value = "卖点")
  32 + private String sellPoint;
  33 +
  34 + @ApiModelProperty(value = "描述")
  35 + private String description;
  36 +
  37 + @ApiModelProperty(value = "分类id")
  38 + private Integer cid;
  39 +
  40 + @ApiModelProperty(value = "列表图")
  41 + private String listPicUrl;
  42 +
  43 + @ApiModelProperty(value = "商品主图地址, 数组,以逗号分隔, 最多上传15张")
  44 + private String picUrls;
  45 +
  46 + @ApiModelProperty(value = "排序字段")
  47 + private Integer sort;
  48 +
  49 + @ApiModelProperty(value = "点赞初始人数")
  50 + private Integer likeCount;
  51 +
  52 + @ApiModelProperty(value = "价格")
  53 + private Integer price;
  54 +
  55 + @ApiModelProperty(value = "库存数量")
  56 + private Integer quantity;
  57 +
  58 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +
  7 +@ApiModel("管理后台 - 商品spu Response VO")
  8 +@Data
  9 +@EqualsAndHashCode(callSuper = true)
  10 +@ToString(callSuper = true)
  11 +public class SpuRespVO extends SpuBaseVO {
  12 +
  13 + @ApiModelProperty(value = "主键", required = true)
  14 + private Integer id;
  15 +
  16 + @ApiModelProperty(value = "创建时间")
  17 + private Date createTime;
  18 +
  19 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuUpdateReqVO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import io.swagger.annotations.*;
  6 +import javax.validation.constraints.*;
  7 +
  8 +@ApiModel("管理后台 - 商品spu更新 Request VO")
  9 +@Data
  10 +@EqualsAndHashCode(callSuper = true)
  11 +@ToString(callSuper = true)
  12 +public class SpuUpdateReqVO extends SpuBaseVO {
  13 +
  14 + @ApiModelProperty(value = "主键", required = true)
  15 + @NotNull(message = "主键不能为空")
  16 + private Integer id;
  17 +
  18 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/SkuConvert.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.convert.sku;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +
  7 +import org.mapstruct.Mapper;
  8 +import org.mapstruct.factory.Mappers;
  9 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  10 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
  11 +
  12 +/**
  13 + * 商品sku Convert
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface SkuConvert {
  19 +
  20 + SkuConvert INSTANCE = Mappers.getMapper(SkuConvert.class);
  21 +
  22 + SkuDO convert(SkuCreateReqVO bean);
  23 +
  24 + SkuDO convert(SkuUpdateReqVO bean);
  25 +
  26 + SkuRespVO convert(SkuDO bean);
  27 +
  28 + List<SkuRespVO> convertList(List<SkuDO> list);
  29 +
  30 + PageResult<SkuRespVO> convertPage(PageResult<SkuDO> page);
  31 +
  32 + List<SkuExcelVO> convertList02(List<SkuDO> list);
  33 +
  34 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/SpuConvert.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.convert.spu;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +
  7 +import org.mapstruct.Mapper;
  8 +import org.mapstruct.factory.Mappers;
  9 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  10 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
  11 +
  12 +/**
  13 + * 商品spu Convert
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface SpuConvert {
  19 +
  20 + SpuConvert INSTANCE = Mappers.getMapper(SpuConvert.class);
  21 +
  22 + SpuDO convert(SpuCreateReqVO bean);
  23 +
  24 + SpuDO convert(SpuUpdateReqVO bean);
  25 +
  26 + SpuRespVO convert(SpuDO bean);
  27 +
  28 + List<SpuRespVO> convertList(List<SpuDO> list);
  29 +
  30 + PageResult<SpuRespVO> convertPage(PageResult<SpuDO> page);
  31 +
  32 + List<SpuExcelVO> convertList02(List<SpuDO> list);
  33 +
  34 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/SkuDO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.dal.dataobject.sku;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import com.baomidou.mybatisplus.annotation.*;
  6 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  7 +
  8 +/**
  9 + * 商品sku DO
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@TableName("product_sku")
  14 +@KeySequence("product_sku_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +@ToString(callSuper = true)
  18 +@Builder
  19 +@NoArgsConstructor
  20 +@AllArgsConstructor
  21 +public class SkuDO extends BaseDO {
  22 +
  23 + /**
  24 + * 主键
  25 + */
  26 + @TableId
  27 + private Integer id;
  28 + /**
  29 + * spu编号
  30 + */
  31 + private Integer spuId;
  32 + /**
  33 + * 状态: 1-正常 2-禁用
  34 + */
  35 + private Integer skuStatus;
  36 + /**
  37 + * 规格值数组, 以逗号隔开
  38 + */
  39 + private String attrs;
  40 + /**
  41 + * 销售价格,单位:分
  42 + */
  43 + private Integer price;
  44 + /**
  45 + * 原价, 单位: 分
  46 + */
  47 + private Integer originalPrice;
  48 + /**
  49 + * 成本价,单位: 分
  50 + */
  51 + private Integer costPrice;
  52 + /**
  53 + * 条形码
  54 + */
  55 + private String barCode;
  56 + /**
  57 + * 图片地址
  58 + */
  59 + private String picUrl;
  60 +
  61 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/SpuDO.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.dal.dataobject.spu;
  2 +
  3 +import lombok.*;
  4 +import java.util.*;
  5 +import com.baomidou.mybatisplus.annotation.*;
  6 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  7 +
  8 +/**
  9 + * 商品spu DO
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@TableName("product_spu")
  14 +@KeySequence("product_spu_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +@ToString(callSuper = true)
  18 +@Builder
  19 +@NoArgsConstructor
  20 +@AllArgsConstructor
  21 +public class SpuDO extends BaseDO {
  22 +
  23 + /**
  24 + * 主键
  25 + */
  26 + @TableId
  27 + private Integer id;
  28 + /**
  29 + * 商品名称
  30 + */
  31 + private String name;
  32 + /**
  33 + * 上下架状态: true 上架,false 下架
  34 + */
  35 + private Boolean visible;
  36 + /**
  37 + * 卖点
  38 + */
  39 + private String sellPoint;
  40 + /**
  41 + * 描述
  42 + */
  43 + private String description;
  44 + /**
  45 + * 分类id
  46 + */
  47 + private Integer cid;
  48 + /**
  49 + * 列表图
  50 + */
  51 + private String listPicUrl;
  52 + /**
  53 + * 商品主图地址, 数组,以逗号分隔, 最多上传15张
  54 + */
  55 + private String picUrls;
  56 + /**
  57 + * 排序字段
  58 + */
  59 + private Integer sort;
  60 + /**
  61 + * 点赞初始人数
  62 + */
  63 + private Integer likeCount;
  64 + /**
  65 + * 价格
  66 + */
  67 + private Integer price;
  68 + /**
  69 + * 库存数量
  70 + */
  71 + private Integer quantity;
  72 +
  73 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/SkuMapper.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.dal.mysql.sku;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  7 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
  9 +import org.apache.ibatis.annotations.Mapper;
  10 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  11 +
  12 +/**
  13 + * 商品sku Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface SkuMapper extends BaseMapperX<SkuDO> {
  19 +
  20 + default PageResult<SkuDO> selectPage(SkuPageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<SkuDO>()
  22 + .betweenIfPresent(SkuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  23 + .eqIfPresent(SkuDO::getSpuId, reqVO.getSpuId())
  24 + .eqIfPresent(SkuDO::getSkuStatus, reqVO.getSkuStatus())
  25 + .eqIfPresent(SkuDO::getAttrs, reqVO.getAttrs())
  26 + .eqIfPresent(SkuDO::getPrice, reqVO.getPrice())
  27 + .eqIfPresent(SkuDO::getOriginalPrice, reqVO.getOriginalPrice())
  28 + .eqIfPresent(SkuDO::getCostPrice, reqVO.getCostPrice())
  29 + .eqIfPresent(SkuDO::getBarCode, reqVO.getBarCode())
  30 + .eqIfPresent(SkuDO::getPicUrl, reqVO.getPicUrl())
  31 + .orderByDesc(SkuDO::getId));
  32 + }
  33 +
  34 + default List<SkuDO> selectList(SkuExportReqVO reqVO) {
  35 + return selectList(new LambdaQueryWrapperX<SkuDO>()
  36 + .betweenIfPresent(SkuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  37 + .eqIfPresent(SkuDO::getSpuId, reqVO.getSpuId())
  38 + .eqIfPresent(SkuDO::getSkuStatus, reqVO.getSkuStatus())
  39 + .eqIfPresent(SkuDO::getAttrs, reqVO.getAttrs())
  40 + .eqIfPresent(SkuDO::getPrice, reqVO.getPrice())
  41 + .eqIfPresent(SkuDO::getOriginalPrice, reqVO.getOriginalPrice())
  42 + .eqIfPresent(SkuDO::getCostPrice, reqVO.getCostPrice())
  43 + .eqIfPresent(SkuDO::getBarCode, reqVO.getBarCode())
  44 + .eqIfPresent(SkuDO::getPicUrl, reqVO.getPicUrl())
  45 + .orderByDesc(SkuDO::getId));
  46 + }
  47 +
  48 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/SpuMapper.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.dal.mysql.spu;
  2 +
  3 +import java.util.*;
  4 +
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  7 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  8 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
  9 +import org.apache.ibatis.annotations.Mapper;
  10 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  11 +
  12 +/**
  13 + * 商品spu Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface SpuMapper extends BaseMapperX<SpuDO> {
  19 +
  20 + default PageResult<SpuDO> selectPage(SpuPageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<SpuDO>()
  22 + .betweenIfPresent(SpuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  23 + .likeIfPresent(SpuDO::getName, reqVO.getName())
  24 + .eqIfPresent(SpuDO::getVisible, reqVO.getVisible())
  25 + .eqIfPresent(SpuDO::getSellPoint, reqVO.getSellPoint())
  26 + .eqIfPresent(SpuDO::getDescription, reqVO.getDescription())
  27 + .eqIfPresent(SpuDO::getCid, reqVO.getCid())
  28 + .eqIfPresent(SpuDO::getListPicUrl, reqVO.getListPicUrl())
  29 + .eqIfPresent(SpuDO::getPicUrls, reqVO.getPicUrls())
  30 + .eqIfPresent(SpuDO::getSort, reqVO.getSort())
  31 + .eqIfPresent(SpuDO::getLikeCount, reqVO.getLikeCount())
  32 + .eqIfPresent(SpuDO::getPrice, reqVO.getPrice())
  33 + .eqIfPresent(SpuDO::getQuantity, reqVO.getQuantity())
  34 + .orderByDesc(SpuDO::getId));
  35 + }
  36 +
  37 + default List<SpuDO> selectList(SpuExportReqVO reqVO) {
  38 + return selectList(new LambdaQueryWrapperX<SpuDO>()
  39 + .betweenIfPresent(SpuDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
  40 + .likeIfPresent(SpuDO::getName, reqVO.getName())
  41 + .eqIfPresent(SpuDO::getVisible, reqVO.getVisible())
  42 + .eqIfPresent(SpuDO::getSellPoint, reqVO.getSellPoint())
  43 + .eqIfPresent(SpuDO::getDescription, reqVO.getDescription())
  44 + .eqIfPresent(SpuDO::getCid, reqVO.getCid())
  45 + .eqIfPresent(SpuDO::getListPicUrl, reqVO.getListPicUrl())
  46 + .eqIfPresent(SpuDO::getPicUrls, reqVO.getPicUrls())
  47 + .eqIfPresent(SpuDO::getSort, reqVO.getSort())
  48 + .eqIfPresent(SpuDO::getLikeCount, reqVO.getLikeCount())
  49 + .eqIfPresent(SpuDO::getPrice, reqVO.getPrice())
  50 + .eqIfPresent(SpuDO::getQuantity, reqVO.getQuantity())
  51 + .orderByDesc(SpuDO::getId));
  52 + }
  53 +
  54 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/SkuService.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.service.sku;
  2 +
  3 +import java.util.*;
  4 +import javax.validation.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  6 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +
  9 +/**
  10 + * 商品sku Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface SkuService {
  15 +
  16 + /**
  17 + * 创建商品sku
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Integer createSku(@Valid SkuCreateReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新商品sku
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateSku(@Valid SkuUpdateReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除商品sku
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteSku(Integer id);
  37 +
  38 + /**
  39 + * 获得商品sku
  40 + *
  41 + * @param id 编号
  42 + * @return 商品sku
  43 + */
  44 + SkuDO getSku(Integer id);
  45 +
  46 + /**
  47 + * 获得商品sku列表
  48 + *
  49 + * @param ids 编号
  50 + * @return 商品sku列表
  51 + */
  52 + List<SkuDO> getSkuList(Collection<Integer> ids);
  53 +
  54 + /**
  55 + * 获得商品sku分页
  56 + *
  57 + * @param pageReqVO 分页查询
  58 + * @return 商品sku分页
  59 + */
  60 + PageResult<SkuDO> getSkuPage(SkuPageReqVO pageReqVO);
  61 +
  62 + /**
  63 + * 获得商品sku列表, 用于 Excel 导出
  64 + *
  65 + * @param exportReqVO 查询条件
  66 + * @return 商品sku列表
  67 + */
  68 + List<SkuDO> getSkuList(SkuExportReqVO exportReqVO);
  69 +
  70 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImpl.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.service.sku;
  2 +
  3 +import org.springframework.stereotype.Service;
  4 +import javax.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +
  7 +import java.util.*;
  8 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
  10 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +
  12 +import cn.iocoder.yudao.module.product.convert.sku.SkuConvert;
  13 +import cn.iocoder.yudao.module.product.dal.mysql.sku.SkuMapper;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
  17 +
  18 +/**
  19 + * 商品sku Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class SkuServiceImpl implements SkuService {
  26 +
  27 + @Resource
  28 + private SkuMapper skuMapper;
  29 +
  30 + @Override
  31 + public Integer createSku(SkuCreateReqVO createReqVO) {
  32 + // 插入
  33 + SkuDO sku = SkuConvert.INSTANCE.convert(createReqVO);
  34 + skuMapper.insert(sku);
  35 + // 返回
  36 + return sku.getId();
  37 + }
  38 +
  39 + @Override
  40 + public void updateSku(SkuUpdateReqVO updateReqVO) {
  41 + // 校验存在
  42 + this.validateSkuExists(updateReqVO.getId());
  43 + // 更新
  44 + SkuDO updateObj = SkuConvert.INSTANCE.convert(updateReqVO);
  45 + skuMapper.updateById(updateObj);
  46 + }
  47 +
  48 + @Override
  49 + public void deleteSku(Integer id) {
  50 + // 校验存在
  51 + this.validateSkuExists(id);
  52 + // 删除
  53 + skuMapper.deleteById(id);
  54 + }
  55 +
  56 + private void validateSkuExists(Integer id) {
  57 + if (skuMapper.selectById(id) == null) {
  58 + throw exception(SKU_NOT_EXISTS);
  59 + }
  60 + }
  61 +
  62 + @Override
  63 + public SkuDO getSku(Integer id) {
  64 + return skuMapper.selectById(id);
  65 + }
  66 +
  67 + @Override
  68 + public List<SkuDO> getSkuList(Collection<Integer> ids) {
  69 + return skuMapper.selectBatchIds(ids);
  70 + }
  71 +
  72 + @Override
  73 + public PageResult<SkuDO> getSkuPage(SkuPageReqVO pageReqVO) {
  74 + return skuMapper.selectPage(pageReqVO);
  75 + }
  76 +
  77 + @Override
  78 + public List<SkuDO> getSkuList(SkuExportReqVO exportReqVO) {
  79 + return skuMapper.selectList(exportReqVO);
  80 + }
  81 +
  82 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/SpuService.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.service.spu;
  2 +
  3 +import java.util.*;
  4 +import javax.validation.*;
  5 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  6 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +
  9 +/**
  10 + * 商品spu Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface SpuService {
  15 +
  16 + /**
  17 + * 创建商品spu
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Integer createSpu(@Valid SpuCreateReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新商品spu
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateSpu(@Valid SpuUpdateReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 删除商品spu
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void deleteSpu(Integer id);
  37 +
  38 + /**
  39 + * 获得商品spu
  40 + *
  41 + * @param id 编号
  42 + * @return 商品spu
  43 + */
  44 + SpuDO getSpu(Integer id);
  45 +
  46 + /**
  47 + * 获得商品spu列表
  48 + *
  49 + * @param ids 编号
  50 + * @return 商品spu列表
  51 + */
  52 + List<SpuDO> getSpuList(Collection<Integer> ids);
  53 +
  54 + /**
  55 + * 获得商品spu分页
  56 + *
  57 + * @param pageReqVO 分页查询
  58 + * @return 商品spu分页
  59 + */
  60 + PageResult<SpuDO> getSpuPage(SpuPageReqVO pageReqVO);
  61 +
  62 + /**
  63 + * 获得商品spu列表, 用于 Excel 导出
  64 + *
  65 + * @param exportReqVO 查询条件
  66 + * @return 商品spu列表
  67 + */
  68 + List<SpuDO> getSpuList(SpuExportReqVO exportReqVO);
  69 +
  70 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/SpuServiceImpl.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.service.spu;
  2 +
  3 +import org.springframework.stereotype.Service;
  4 +import javax.annotation.Resource;
  5 +import org.springframework.validation.annotation.Validated;
  6 +
  7 +import java.util.*;
  8 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  9 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
  10 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  11 +
  12 +import cn.iocoder.yudao.module.product.convert.spu.SpuConvert;
  13 +import cn.iocoder.yudao.module.product.dal.mysql.spu.SpuMapper;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
  17 +
  18 +/**
  19 + * 商品spu Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class SpuServiceImpl implements SpuService {
  26 +
  27 + @Resource
  28 + private SpuMapper spuMapper;
  29 +
  30 + @Override
  31 + public Integer createSpu(SpuCreateReqVO createReqVO) {
  32 + // 插入
  33 + SpuDO spu = SpuConvert.INSTANCE.convert(createReqVO);
  34 + spuMapper.insert(spu);
  35 + // 返回
  36 + return spu.getId();
  37 + }
  38 +
  39 + @Override
  40 + public void updateSpu(SpuUpdateReqVO updateReqVO) {
  41 + // 校验存在
  42 + this.validateSpuExists(updateReqVO.getId());
  43 + // 更新
  44 + SpuDO updateObj = SpuConvert.INSTANCE.convert(updateReqVO);
  45 + spuMapper.updateById(updateObj);
  46 + }
  47 +
  48 + @Override
  49 + public void deleteSpu(Integer id) {
  50 + // 校验存在
  51 + this.validateSpuExists(id);
  52 + // 删除
  53 + spuMapper.deleteById(id);
  54 + }
  55 +
  56 + private void validateSpuExists(Integer id) {
  57 + if (spuMapper.selectById(id) == null) {
  58 + throw exception(SPU_NOT_EXISTS);
  59 + }
  60 + }
  61 +
  62 + @Override
  63 + public SpuDO getSpu(Integer id) {
  64 + return spuMapper.selectById(id);
  65 + }
  66 +
  67 + @Override
  68 + public List<SpuDO> getSpuList(Collection<Integer> ids) {
  69 + return spuMapper.selectBatchIds(ids);
  70 + }
  71 +
  72 + @Override
  73 + public PageResult<SpuDO> getSpuPage(SpuPageReqVO pageReqVO) {
  74 + return spuMapper.selectPage(pageReqVO);
  75 + }
  76 +
  77 + @Override
  78 + public List<SpuDO> getSpuList(SpuExportReqVO exportReqVO) {
  79 + return spuMapper.selectList(exportReqVO);
  80 + }
  81 +
  82 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/sku/SkuServiceImplTest.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.service.sku;
  2 +
  3 +import org.junit.jupiter.api.Disabled;
  4 +import org.junit.jupiter.api.Test;
  5 +import org.springframework.boot.test.mock.mockito.MockBean;
  6 +
  7 +import javax.annotation.Resource;
  8 +
  9 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  10 +
  11 +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*;
  12 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.SkuDO;
  13 +import cn.iocoder.yudao.module.product.dal.mysql.sku.SkuMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import javax.annotation.Resource;
  17 +import org.springframework.context.annotation.Import;
  18 +import java.util.*;
  19 +
  20 +import static cn.hutool.core.util.RandomUtil.*;
  21 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
  22 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  23 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  24 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  25 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
  26 +import static org.junit.jupiter.api.Assertions.*;
  27 +import static org.mockito.Mockito.*;
  28 +
  29 +/**
  30 +* {@link SkuServiceImpl} 的单元测试类
  31 +*
  32 +* @author 芋道源码
  33 +*/
  34 +@Import(SkuServiceImpl.class)
  35 +public class SkuServiceImplTest extends BaseDbUnitTest {
  36 +
  37 + @Resource
  38 + private SkuServiceImpl skuService;
  39 +
  40 + @Resource
  41 + private SkuMapper skuMapper;
  42 +
  43 + @Test
  44 + public void testCreateSku_success() {
  45 + // 准备参数
  46 + SkuCreateReqVO reqVO = randomPojo(SkuCreateReqVO.class);
  47 +
  48 + // 调用
  49 + Integer skuId = skuService.createSku(reqVO);
  50 + // 断言
  51 + assertNotNull(skuId);
  52 + // 校验记录的属性是否正确
  53 + SkuDO sku = skuMapper.selectById(skuId);
  54 + assertPojoEquals(reqVO, sku);
  55 + }
  56 +
  57 + @Test
  58 + public void testUpdateSku_success() {
  59 + // mock 数据
  60 + SkuDO dbSku = randomPojo(SkuDO.class);
  61 + skuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据
  62 + // 准备参数
  63 + SkuUpdateReqVO reqVO = randomPojo(SkuUpdateReqVO.class, o -> {
  64 + o.setId(dbSku.getId()); // 设置更新的 ID
  65 + });
  66 +
  67 + // 调用
  68 + skuService.updateSku(reqVO);
  69 + // 校验是否更新正确
  70 + SkuDO sku = skuMapper.selectById(reqVO.getId()); // 获取最新的
  71 + assertPojoEquals(reqVO, sku);
  72 + }
  73 +
  74 + @Test
  75 + public void testUpdateSku_notExists() {
  76 + // 准备参数
  77 + SkuUpdateReqVO reqVO = randomPojo(SkuUpdateReqVO.class);
  78 +
  79 + // 调用, 并断言异常
  80 + assertServiceException(() -> skuService.updateSku(reqVO), SKU_NOT_EXISTS);
  81 + }
  82 +
  83 + @Test
  84 + public void testDeleteSku_success() {
  85 + // mock 数据
  86 + SkuDO dbSku = randomPojo(SkuDO.class);
  87 + skuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据
  88 + // 准备参数
  89 + Integer id = dbSku.getId();
  90 +
  91 + // 调用
  92 + skuService.deleteSku(id);
  93 + // 校验数据不存在了
  94 + assertNull(skuMapper.selectById(id));
  95 + }
  96 +
  97 + @Test
  98 + public void testDeleteSku_notExists() {
  99 + // 准备参数
  100 + Integer id = 1;
  101 +
  102 + // 调用, 并断言异常spu
  103 + assertServiceException(() -> skuService.deleteSku(id), SKU_NOT_EXISTS);
  104 + }
  105 +
  106 + @Test
  107 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  108 + public void testGetSkuPage() {
  109 + // mock 数据
  110 + SkuDO dbSku = randomPojo(SkuDO.class, o -> { // 等会查询到
  111 + o.setCreateTime(null);
  112 + o.setSpuId(null);
  113 + o.setSkuStatus(null);
  114 + o.setAttrs(null);
  115 + o.setPrice(null);
  116 + o.setOriginalPrice(null);
  117 + o.setCostPrice(null);
  118 + o.setBarCode(null);
  119 + o.setPicUrl(null);
  120 + });
  121 + skuMapper.insert(dbSku);
  122 + // 测试 createTime 不匹配
  123 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null)));
  124 + // 测试 spuId 不匹配
  125 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null)));
  126 + // 测试 skuStatus 不匹配
  127 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSkuStatus(null)));
  128 + // 测试 attrs 不匹配
  129 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setAttrs(null)));
  130 + // 测试 price 不匹配
  131 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null)));
  132 + // 测试 originalPrice 不匹配
  133 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
  134 + // 测试 costPrice 不匹配
  135 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
  136 + // 测试 barCode 不匹配
  137 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
  138 + // 测试 picUrl 不匹配
  139 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null)));
  140 + // 准备参数
  141 + SkuPageReqVO reqVO = new SkuPageReqVO();
  142 + reqVO.setBeginCreateTime(null);
  143 + reqVO.setEndCreateTime(null);
  144 + reqVO.setSpuId(null);
  145 + reqVO.setSkuStatus(null);
  146 + reqVO.setAttrs(null);
  147 + reqVO.setPrice(null);
  148 + reqVO.setOriginalPrice(null);
  149 + reqVO.setCostPrice(null);
  150 + reqVO.setBarCode(null);
  151 + reqVO.setPicUrl(null);
  152 +
  153 + // 调用
  154 + PageResult<SkuDO> pageResult = skuService.getSkuPage(reqVO);
  155 + // 断言
  156 + assertEquals(1, pageResult.getTotal());
  157 + assertEquals(1, pageResult.getList().size());
  158 + assertPojoEquals(dbSku, pageResult.getList().get(0));
  159 + }
  160 +
  161 + @Test
  162 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  163 + public void testGetSkuList() {
  164 + // mock 数据
  165 + SkuDO dbSku = randomPojo(SkuDO.class, o -> { // 等会查询到
  166 + o.setCreateTime(null);
  167 + o.setSpuId(null);
  168 + o.setSkuStatus(null);
  169 + o.setAttrs(null);
  170 + o.setPrice(null);
  171 + o.setOriginalPrice(null);
  172 + o.setCostPrice(null);
  173 + o.setBarCode(null);
  174 + o.setPicUrl(null);
  175 + });
  176 + skuMapper.insert(dbSku);
  177 + // 测试 createTime 不匹配
  178 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCreateTime(null)));
  179 + // 测试 spuId 不匹配
  180 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSpuId(null)));
  181 + // 测试 skuStatus 不匹配
  182 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setSkuStatus(null)));
  183 + // 测试 attrs 不匹配
  184 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setAttrs(null)));
  185 + // 测试 price 不匹配
  186 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPrice(null)));
  187 + // 测试 originalPrice 不匹配
  188 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setOriginalPrice(null)));
  189 + // 测试 costPrice 不匹配
  190 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setCostPrice(null)));
  191 + // 测试 barCode 不匹配
  192 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setBarCode(null)));
  193 + // 测试 picUrl 不匹配
  194 + skuMapper.insert(cloneIgnoreId(dbSku, o -> o.setPicUrl(null)));
  195 + // 准备参数
  196 + SkuExportReqVO reqVO = new SkuExportReqVO();
  197 + reqVO.setBeginCreateTime(null);
  198 + reqVO.setEndCreateTime(null);
  199 + reqVO.setSpuId(null);
  200 + reqVO.setSkuStatus(null);
  201 + reqVO.setAttrs(null);
  202 + reqVO.setPrice(null);
  203 + reqVO.setOriginalPrice(null);
  204 + reqVO.setCostPrice(null);
  205 + reqVO.setBarCode(null);
  206 + reqVO.setPicUrl(null);
  207 +
  208 + // 调用
  209 + List<SkuDO> list = skuService.getSkuList(reqVO);
  210 + // 断言
  211 + assertEquals(1, list.size());
  212 + assertPojoEquals(dbSku, list.get(0));
  213 + }
  214 +
  215 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/spu/SpuServiceImplTest.java 0 → 100755
  1 +package cn.iocoder.yudao.module.product.service.spu;
  2 +
  3 +import org.junit.jupiter.api.Disabled;
  4 +import org.junit.jupiter.api.Test;
  5 +import org.springframework.boot.test.mock.mockito.MockBean;
  6 +
  7 +import javax.annotation.Resource;
  8 +
  9 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  10 +
  11 +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
  12 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.SpuDO;
  13 +import cn.iocoder.yudao.module.product.dal.mysql.spu.SpuMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import javax.annotation.Resource;
  17 +import org.springframework.context.annotation.Import;
  18 +import java.util.*;
  19 +
  20 +import static cn.hutool.core.util.RandomUtil.*;
  21 +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
  22 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  23 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  24 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  25 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
  26 +import static org.junit.jupiter.api.Assertions.*;
  27 +import static org.mockito.Mockito.*;
  28 +
  29 +/**
  30 +* {@link SpuServiceImpl} 的单元测试类
  31 +*
  32 +* @author 芋道源码
  33 +*/
  34 +@Import(SpuServiceImpl.class)
  35 +public class SpuServiceImplTest extends BaseDbUnitTest {
  36 +
  37 + @Resource
  38 + private SpuServiceImpl spuService;
  39 +
  40 + @Resource
  41 + private SpuMapper spuMapper;
  42 +
  43 + @Test
  44 + public void testCreateSpu_success() {
  45 + // 准备参数
  46 + SpuCreateReqVO reqVO = randomPojo(SpuCreateReqVO.class);
  47 +
  48 + // 调用
  49 + Integer spuId = spuService.createSpu(reqVO);
  50 + // 断言
  51 + assertNotNull(spuId);
  52 + // 校验记录的属性是否正确
  53 + SpuDO spu = spuMapper.selectById(spuId);
  54 + assertPojoEquals(reqVO, spu);
  55 + }
  56 +
  57 + @Test
  58 + public void testUpdateSpu_success() {
  59 + // mock 数据
  60 + SpuDO dbSpu = randomPojo(SpuDO.class);
  61 + spuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据
  62 + // 准备参数
  63 + SpuUpdateReqVO reqVO = randomPojo(SpuUpdateReqVO.class, o -> {
  64 + o.setId(dbSpu.getId()); // 设置更新的 ID
  65 + });
  66 +
  67 + // 调用
  68 + spuService.updateSpu(reqVO);
  69 + // 校验是否更新正确
  70 + SpuDO spu = spuMapper.selectById(reqVO.getId()); // 获取最新的
  71 + assertPojoEquals(reqVO, spu);
  72 + }
  73 +
  74 + @Test
  75 + public void testUpdateSpu_notExists() {
  76 + // 准备参数
  77 + SpuUpdateReqVO reqVO = randomPojo(SpuUpdateReqVO.class);
  78 +
  79 + // 调用, 并断言异常
  80 + assertServiceException(() -> spuService.updateSpu(reqVO), SPU_NOT_EXISTS);
  81 + }
  82 +
  83 + @Test
  84 + public void testDeleteSpu_success() {
  85 + // mock 数据
  86 + SpuDO dbSpu = randomPojo(SpuDO.class);
  87 + spuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据
  88 + // 准备参数
  89 + Integer id = dbSpu.getId();
  90 +
  91 + // 调用
  92 + spuService.deleteSpu(id);
  93 + // 校验数据不存在了
  94 + assertNull(spuMapper.selectById(id));
  95 + }
  96 +
  97 + @Test
  98 + public void testDeleteSpu_notExists() {
  99 + // 准备参数
  100 + Integer id = 1;
  101 +
  102 + // 调用, 并断言异常
  103 + assertServiceException(() -> spuService.deleteSpu(id), SPU_NOT_EXISTS);
  104 + }
  105 +
  106 + @Test
  107 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  108 + public void testGetSpuPage() {
  109 + // mock 数据
  110 + SpuDO dbSpu = randomPojo(SpuDO.class, o -> { // 等会查询到
  111 + o.setCreateTime(null);
  112 + o.setName(null);
  113 + o.setVisible(null);
  114 + o.setSellPoint(null);
  115 + o.setDescription(null);
  116 + o.setCid(null);
  117 + o.setListPicUrl(null);
  118 + o.setPicUrls(null);
  119 + o.setSort(null);
  120 + o.setLikeCount(null);
  121 + o.setPrice(null);
  122 + o.setQuantity(null);
  123 + });
  124 + spuMapper.insert(dbSpu);
  125 + // 测试 createTime 不匹配
  126 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null)));
  127 + // 测试 name 不匹配
  128 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null)));
  129 + // 测试 visible 不匹配
  130 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setVisible(null)));
  131 + // 测试 sellPoint 不匹配
  132 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null)));
  133 + // 测试 description 不匹配
  134 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null)));
  135 + // 测试 cid 不匹配
  136 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCid(null)));
  137 + // 测试 listPicUrl 不匹配
  138 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setListPicUrl(null)));
  139 + // 测试 picUrls 不匹配
  140 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null)));
  141 + // 测试 sort 不匹配
  142 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null)));
  143 + // 测试 likeCount 不匹配
  144 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
  145 + // 测试 price 不匹配
  146 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null)));
  147 + // 测试 quantity 不匹配
  148 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
  149 + // 准备参数
  150 + SpuPageReqVO reqVO = new SpuPageReqVO();
  151 + reqVO.setBeginCreateTime(null);
  152 + reqVO.setEndCreateTime(null);
  153 + reqVO.setName(null);
  154 + reqVO.setVisible(null);
  155 + reqVO.setSellPoint(null);
  156 + reqVO.setDescription(null);
  157 + reqVO.setCid(null);
  158 + reqVO.setListPicUrl(null);
  159 + reqVO.setPicUrls(null);
  160 + reqVO.setSort(null);
  161 + reqVO.setLikeCount(null);
  162 + reqVO.setPrice(null);
  163 + reqVO.setQuantity(null);
  164 +
  165 + // 调用
  166 + PageResult<SpuDO> pageResult = spuService.getSpuPage(reqVO);
  167 + // 断言
  168 + assertEquals(1, pageResult.getTotal());
  169 + assertEquals(1, pageResult.getList().size());
  170 + assertPojoEquals(dbSpu, pageResult.getList().get(0));
  171 + }
  172 +
  173 + @Test
  174 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  175 + public void testGetSpuList() {
  176 + // mock 数据
  177 + SpuDO dbSpu = randomPojo(SpuDO.class, o -> { // 等会查询到
  178 + o.setCreateTime(null);
  179 + o.setName(null);
  180 + o.setVisible(null);
  181 + o.setSellPoint(null);
  182 + o.setDescription(null);
  183 + o.setCid(null);
  184 + o.setListPicUrl(null);
  185 + o.setPicUrls(null);
  186 + o.setSort(null);
  187 + o.setLikeCount(null);
  188 + o.setPrice(null);
  189 + o.setQuantity(null);
  190 + });
  191 + spuMapper.insert(dbSpu);
  192 + // 测试 createTime 不匹配
  193 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCreateTime(null)));
  194 + // 测试 name 不匹配
  195 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setName(null)));
  196 + // 测试 visible 不匹配
  197 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setVisible(null)));
  198 + // 测试 sellPoint 不匹配
  199 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSellPoint(null)));
  200 + // 测试 description 不匹配
  201 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setDescription(null)));
  202 + // 测试 cid 不匹配
  203 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setCid(null)));
  204 + // 测试 listPicUrl 不匹配
  205 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setListPicUrl(null)));
  206 + // 测试 picUrls 不匹配
  207 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPicUrls(null)));
  208 + // 测试 sort 不匹配
  209 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setSort(null)));
  210 + // 测试 likeCount 不匹配
  211 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setLikeCount(null)));
  212 + // 测试 price 不匹配
  213 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setPrice(null)));
  214 + // 测试 quantity 不匹配
  215 + spuMapper.insert(cloneIgnoreId(dbSpu, o -> o.setQuantity(null)));
  216 + // 准备参数
  217 + SpuExportReqVO reqVO = new SpuExportReqVO();
  218 + reqVO.setBeginCreateTime(null);
  219 + reqVO.setEndCreateTime(null);
  220 + reqVO.setName(null);
  221 + reqVO.setVisible(null);
  222 + reqVO.setSellPoint(null);
  223 + reqVO.setDescription(null);
  224 + reqVO.setCid(null);
  225 + reqVO.setListPicUrl(null);
  226 + reqVO.setPicUrls(null);
  227 + reqVO.setSort(null);
  228 + reqVO.setLikeCount(null);
  229 + reqVO.setPrice(null);
  230 + reqVO.setQuantity(null);
  231 +
  232 + // 调用
  233 + List<SpuDO> list = spuService.getSpuList(reqVO);
  234 + // 断言
  235 + assertEquals(1, list.size());
  236 + assertPojoEquals(dbSpu, list.get(0));
  237 + }
  238 +
  239 +}
... ...