商品调整

This commit is contained in:
franky 2022-06-05 15:45:36 +08:00
parent 0e3cdda08d
commit 6dca8e082b
19 changed files with 153 additions and 52 deletions

View File

@ -38,7 +38,7 @@ public class ProductSkuController {
@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 ProductSkuCreateReqVO createReqVO) { public CommonResult<Long> createSku(@Valid @RequestBody ProductSkuCreateReqVO createReqVO) {
return success(ProductSkuService.createSku(createReqVO)); return success(ProductSkuService.createSku(createReqVO));
} }
@ -52,18 +52,18 @@ public class ProductSkuController {
@DeleteMapping("/delete") @DeleteMapping("/delete")
@ApiOperation("删除商品sku") @ApiOperation("删除商品sku")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.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") Long id) {
ProductSkuService.deleteSku(id); ProductSkuService.deleteSku(id);
return success(true); return success(true);
} }
@GetMapping("/get") @GetMapping("/get")
@ApiOperation("获得商品sku") @ApiOperation("获得商品sku")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:sku:query')") @PreAuthorize("@ss.hasPermission('product:sku:query')")
public CommonResult<ProductSkuRespVO> getSku(@RequestParam("id") Integer id) { public CommonResult<ProductSkuRespVO> getSku(@RequestParam("id") Long id) {
ProductSkuDO sku = ProductSkuService.getSku(id); ProductSkuDO sku = ProductSkuService.getSku(id);
return success(ProductSkuConvert.INSTANCE.convert(sku)); return success(ProductSkuConvert.INSTANCE.convert(sku));
} }
@ -72,7 +72,7 @@ public class ProductSkuController {
@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<ProductSkuRespVO>> getSkuList(@RequestParam("ids") Collection<Integer> ids) { public CommonResult<List<ProductSkuRespVO>> getSkuList(@RequestParam("ids") Collection<Long> ids) {
List<ProductSkuDO> list = ProductSkuService.getSkuList(ids); List<ProductSkuDO> list = ProductSkuService.getSkuList(ids);
return success(ProductSkuConvert.INSTANCE.convertList(list)); return success(ProductSkuConvert.INSTANCE.convertList(list));
} }

View File

@ -16,8 +16,8 @@ public class ProductSkuBaseVO {
@NotNull(message = "spu编号不能为空") @NotNull(message = "spu编号不能为空")
private Long spuId; private Long spuId;
@ApiModelProperty(value = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]", required = true) @ApiModelProperty(value = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true)
@NotNull(message = "规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]不能为空") @NotNull(message = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空")
private List<Property> properties; private List<Property> properties;
@ApiModelProperty(value = "销售价格,单位:分", required = true) @ApiModelProperty(value = "销售价格,单位:分", required = true)

View File

@ -13,6 +13,6 @@ public class ProductSkuUpdateReqVO extends ProductSkuBaseVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空") @NotNull(message = "主键不能为空")
private Integer id; private Long id;
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.controller.admin.spu; package cn.iocoder.yudao.module.product.controller.admin.spu;
import nonapi.io.github.classgraph.utils.LogNode;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -38,7 +39,7 @@ public class ProductSpuController {
@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 ProductSpuCreateReqVO createReqVO) { public CommonResult<Long> createSpu(@Valid @RequestBody ProductSpuCreateReqVO createReqVO) {
return success(spuService.createSpu(createReqVO)); return success(spuService.createSpu(createReqVO));
} }
@ -52,27 +53,27 @@ public class ProductSpuController {
@DeleteMapping("/delete") @DeleteMapping("/delete")
@ApiOperation("删除商品spu") @ApiOperation("删除商品spu")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('product:spu:delete')") @PreAuthorize("@ss.hasPermission('product:spu:delete')")
public CommonResult<Boolean> deleteSpu(@RequestParam("id") Integer id) { public CommonResult<Boolean> deleteSpu(@RequestParam("id") Long id) {
spuService.deleteSpu(id); spuService.deleteSpu(id);
return success(true); return success(true);
} }
@GetMapping("/get") @GetMapping("/get")
@ApiOperation("获得商品spu") @ApiOperation("获得商品spu")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.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") Long id) {
ProductSpuDO spu = spuService.getSpu(id); ProductSpuDO spu = spuService.getSpu(id);
return success(ProductSpuConvert.INSTANCE.convert(spu)); return success(ProductSpuConvert.INSTANCE.convert(spu));
} }
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("获得商品spu列表") @ApiOperation("获得商品spu列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = Long.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<Long> ids) {
List<ProductSpuDO> list = spuService.getSpuList(ids); List<ProductSpuDO> list = spuService.getSpuList(ids);
return success(ProductSpuConvert.INSTANCE.convertList(list)); return success(ProductSpuConvert.INSTANCE.convertList(list));
} }

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo; package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
import lombok.*; import lombok.*;
import java.util.*; import java.util.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import javax.validation.Valid;
import javax.validation.constraints.*; import javax.validation.constraints.*;
@ApiModel("管理后台 - 商品spu创建 Request VO") @ApiModel("管理后台 - 商品spu创建 Request VO")
@ -11,4 +14,8 @@ import javax.validation.constraints.*;
@ToString(callSuper = true) @ToString(callSuper = true)
public class ProductSpuCreateReqVO extends ProductSpuBaseVO { public class ProductSpuCreateReqVO extends ProductSpuBaseVO {
@ApiModelProperty(value = "sku组合")
@Valid
List<ProductSkuCreateReqVO> productSkuCreateReqVOS;
} }

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo; package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
import lombok.*; import lombok.*;
import java.util.*; import java.util.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import javax.validation.Valid;
import javax.validation.constraints.*; import javax.validation.constraints.*;
@ApiModel("管理后台 - 商品spu更新 Request VO") @ApiModel("管理后台 - 商品spu更新 Request VO")
@ -13,6 +16,10 @@ public class SpuUpdateReqVO extends ProductSpuBaseVO {
@ApiModelProperty(value = "主键", required = true) @ApiModelProperty(value = "主键", required = true)
@NotNull(message = "主键不能为空") @NotNull(message = "主键不能为空")
private Integer id; private Long id;
@ApiModelProperty(value = "sku组合")
@Valid
List<ProductSkuCreateReqVO> productSkuCreateReqVOS;
} }

View File

@ -2,12 +2,16 @@ package cn.iocoder.yudao.module.product.convert.sku;
import java.util.*; import java.util.*;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
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.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import org.springframework.util.StringUtils;
/** /**
* 商品sku Convert * 商品sku Convert
@ -19,16 +23,36 @@ public interface ProductSkuConvert {
ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class); ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
@Mapping(source = "properties", target = "properties", qualifiedByName = "translateStringFromList")
ProductSkuDO convert(ProductSkuCreateReqVO bean); ProductSkuDO convert(ProductSkuCreateReqVO bean);
@Mapping(source = "properties", target = "properties", qualifiedByName = "translateStringFromList")
ProductSkuDO convert(ProductSkuUpdateReqVO bean); ProductSkuDO convert(ProductSkuUpdateReqVO bean);
@Mapping(source = "properties", target = "properties", qualifiedByName = "tokenizeToBeanArray")
ProductSkuRespVO convert(ProductSkuDO bean); ProductSkuRespVO convert(ProductSkuDO bean);
@Mapping(source = "properties", target = "properties", qualifiedByName = "tokenizeToExcelBeanArray")
ProductSkuExcelVO convertToExcelVO(ProductSkuDO bean);
List<ProductSkuRespVO> convertList(List<ProductSkuDO> list); List<ProductSkuRespVO> convertList(List<ProductSkuDO> list);
PageResult<ProductSkuRespVO> convertPage(PageResult<ProductSkuDO> page); PageResult<ProductSkuRespVO> convertPage(PageResult<ProductSkuDO> page);
List<ProductSkuExcelVO> convertList02(List<ProductSkuDO> list); List<ProductSkuExcelVO> convertList02(List<ProductSkuDO> list);
@Named("tokenizeToBeanArray")
default List<ProductSkuBaseVO.Property> translatePropertyArrayFromString(String properties) {
return JSONUtil.toList(properties, ProductSkuBaseVO.Property.class);
}
@Named("tokenizeToExcelBeanArray")
default List<ProductSkuExcelVO.Property> translateExcelPropertyArrayFromString(String properties) {
return JSONUtil.toList(properties, ProductSkuExcelVO.Property.class);
}
@Named("translateStringFromList")
default String translatePropertyStringFromList(List<ProductSkuBaseVO.Property> properties) {
return JSONUtil.toJsonStr(properties);
}
} }

View File

@ -5,9 +5,12 @@ import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
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.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import org.springframework.util.StringUtils;
/** /**
* 商品spu Convert * 商品spu Convert
@ -19,16 +22,31 @@ public interface ProductSpuConvert {
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class); ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "translatePicUrlsFromStringList")
ProductSpuDO convert(ProductSpuCreateReqVO bean); ProductSpuDO convert(ProductSpuCreateReqVO bean);
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "translatePicUrlsFromStringList")
ProductSpuDO convert(SpuUpdateReqVO bean); ProductSpuDO convert(SpuUpdateReqVO bean);
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "tokenizeToStringArray")
SpuRespVO convert(ProductSpuDO bean); SpuRespVO convert(ProductSpuDO bean);
@Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "tokenizeToStringArray")
SpuExcelVO convertToExcelVO(ProductSpuDO bean);
List<SpuRespVO> convertList(List<ProductSpuDO> list); List<SpuRespVO> convertList(List<ProductSpuDO> list);
PageResult<SpuRespVO> convertPage(PageResult<ProductSpuDO> page); PageResult<SpuRespVO> convertPage(PageResult<ProductSpuDO> page);
List<SpuExcelVO> convertList02(List<ProductSpuDO> list); List<SpuExcelVO> convertList02(List<ProductSpuDO> list);
@Named("tokenizeToStringArray")
default List<String> translatePicUrlsArrayFromString(String picUrls) {
return Arrays.asList(StringUtils.tokenizeToStringArray(picUrls, ","));
}
@Named("translatePicUrlsFromStringList")
default String translatePicUrlsFromList(List<String> picUrls) {
return StringUtils.collectionToCommaDelimitedString(picUrls);
}
} }

View File

@ -27,7 +27,7 @@ public class ProductSkuDO extends BaseDO {
* 主键 * 主键
*/ */
@TableId @TableId
private Integer id; private Long id;
/** /**
* spu编号 * spu编号
*/ */
@ -36,7 +36,7 @@ public class ProductSkuDO extends BaseDO {
* 规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }] * 规格值数组-json格式 [{propertId: , valueId: }, {propertId: , valueId: }]
*/ */
// TODO franky可以定义一个内部的 Property 然后 List<Property> // TODO franky可以定义一个内部的 Property 然后 List<Property>
private List<Property> properties; private String properties;
/** /**
* 销售价格单位 * 销售价格单位
*/ */
@ -62,11 +62,5 @@ public class ProductSkuDO extends BaseDO {
*/ */
private Integer status; private Integer status;
@Data
public static class Property {
private Integer propertyId;
private Integer valueId;
}
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.dal.dataobject.spu; package cn.iocoder.yudao.module.product.dal.dataobject.spu;
import cn.hutool.log.Log;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
@ -27,7 +28,7 @@ public class ProductSpuDO extends BaseDO {
* 主键 * 主键
*/ */
@TableId @TableId
private Integer id; private Long id;
/** /**
* 商品名称 * 商品名称
*/ */
@ -48,7 +49,7 @@ public class ProductSpuDO extends BaseDO {
* 商品主图地址,* 数组以逗号分隔,最多上传15张 * 商品主图地址,* 数组以逗号分隔,最多上传15张
*/ */
// TODO frankyList<String> // TODO frankyList<String>
private List<String> picUrls; private String picUrls;
/** /**
* 排序字段 * 排序字段
*/ */

View File

@ -76,4 +76,10 @@ public interface CategoryService {
* @return 商品分类列表 * @return 商品分类列表
*/ */
List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO); List<CategoryDO> getCategoryTreeList(CategoryTreeListReqVO treeListReqVO);
/**
* 验证选择的分类的合法性
* @param categoryId 分类id
*/
void validatedCategoryById(Long categoryId);
} }

View File

@ -65,6 +65,9 @@ public class CategoryServiceImpl implements CategoryService {
} }
private CategoryDO validateCategoryExists(Long id, ErrorCode errorCode) { private CategoryDO validateCategoryExists(Long id, ErrorCode errorCode) {
if (id == 0) {
return new CategoryDO().setId(id);
}
CategoryDO categoryDO = categoryMapper.selectById(id); CategoryDO categoryDO = categoryMapper.selectById(id);
if (categoryDO == null) { if (categoryDO == null) {
throw exception(errorCode); throw exception(errorCode);
@ -72,6 +75,11 @@ public class CategoryServiceImpl implements CategoryService {
return categoryDO; return categoryDO;
} }
@Override
public void validatedCategoryById(Long categoryId) {
this.validateCategoryExists(categoryId, CATEGORY_NOT_EXISTS);
}
@Override @Override
public CategoryDO getCategory(Long id) { public CategoryDO getCategory(Long id) {
return categoryMapper.selectById(id); return categoryMapper.selectById(id);

View File

@ -19,7 +19,7 @@ public interface ProductSkuService {
* @param createReqVO 创建信息 * @param createReqVO 创建信息
* @return 编号 * @return 编号
*/ */
Integer createSku(@Valid ProductSkuCreateReqVO createReqVO); Long createSku(@Valid ProductSkuCreateReqVO createReqVO);
/** /**
* 更新商品sku * 更新商品sku
@ -33,7 +33,7 @@ public interface ProductSkuService {
* *
* @param id 编号 * @param id 编号
*/ */
void deleteSku(Integer id); void deleteSku(Long id);
/** /**
* 获得商品sku * 获得商品sku
@ -41,7 +41,7 @@ public interface ProductSkuService {
* @param id 编号 * @param id 编号
* @return 商品sku * @return 商品sku
*/ */
ProductSkuDO getSku(Integer id); ProductSkuDO getSku(Long id);
/** /**
* 获得商品sku列表 * 获得商品sku列表
@ -49,7 +49,7 @@ public interface ProductSkuService {
* @param ids 编号 * @param ids 编号
* @return 商品sku列表 * @return 商品sku列表
*/ */
List<ProductSkuDO> getSkuList(Collection<Integer> ids); List<ProductSkuDO> getSkuList(Collection<Long> ids);
/** /**
* 获得商品sku分页 * 获得商品sku分页
@ -67,4 +67,9 @@ public interface ProductSkuService {
*/ */
List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO); List<ProductSkuDO> getSkuList(ProductSkuExportReqVO exportReqVO);
/**
*对sku的组合的属性等进行合法性校验
* @param skuCreateReqList sku组合的集合
*/
void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList);
} }

View File

@ -5,6 +5,8 @@ import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
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.ProductSkuDO; 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;
@ -28,7 +30,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
private ProductSkuMapper ProductSkuMapper; private ProductSkuMapper ProductSkuMapper;
@Override @Override
public Integer createSku(ProductSkuCreateReqVO createReqVO) { public Long createSku(ProductSkuCreateReqVO createReqVO) {
// 插入 // 插入
ProductSkuDO sku = ProductSkuConvert.INSTANCE.convert(createReqVO); ProductSkuDO sku = ProductSkuConvert.INSTANCE.convert(createReqVO);
ProductSkuMapper.insert(sku); ProductSkuMapper.insert(sku);
@ -46,26 +48,26 @@ public class ProductSkuServiceImpl implements ProductSkuService {
} }
@Override @Override
public void deleteSku(Integer id) { public void deleteSku(Long id) {
// 校验存在 // 校验存在
this.validateSkuExists(id); this.validateSkuExists(id);
// 删除 // 删除
ProductSkuMapper.deleteById(id); ProductSkuMapper.deleteById(id);
} }
private void validateSkuExists(Integer id) { private void validateSkuExists(Long id) {
if (ProductSkuMapper.selectById(id) == null) { if (ProductSkuMapper.selectById(id) == null) {
throw exception(SKU_NOT_EXISTS); throw exception(SKU_NOT_EXISTS);
} }
} }
@Override @Override
public ProductSkuDO getSku(Integer id) { public ProductSkuDO getSku(Long id) {
return ProductSkuMapper.selectById(id); return ProductSkuMapper.selectById(id);
} }
@Override @Override
public List<ProductSkuDO> getSkuList(Collection<Integer> ids) { public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
return ProductSkuMapper.selectBatchIds(ids); return ProductSkuMapper.selectBatchIds(ids);
} }
@ -79,4 +81,11 @@ public class ProductSkuServiceImpl implements ProductSkuService {
return ProductSkuMapper.selectList(exportReqVO); return ProductSkuMapper.selectList(exportReqVO);
} }
@Override
public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) {
// 校验规格属性以及规格值是否存在
List<Integer> propertyIds = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList());
// 校验是否有重复的sku组合
}
} }

View File

@ -19,7 +19,7 @@ public interface ProductSpuService {
* @param createReqVO 创建信息 * @param createReqVO 创建信息
* @return 编号 * @return 编号
*/ */
Integer createSpu(@Valid ProductSpuCreateReqVO createReqVO); Long createSpu(@Valid ProductSpuCreateReqVO createReqVO);
/** /**
* 更新商品spu * 更新商品spu
@ -33,7 +33,7 @@ public interface ProductSpuService {
* *
* @param id 编号 * @param id 编号
*/ */
void deleteSpu(Integer id); void deleteSpu(Long id);
/** /**
* 获得商品spu * 获得商品spu
@ -41,7 +41,7 @@ public interface ProductSpuService {
* @param id 编号 * @param id 编号
* @return 商品spu * @return 商品spu
*/ */
ProductSpuDO getSpu(Integer id); ProductSpuDO getSpu(Long id);
/** /**
* 获得商品spu列表 * 获得商品spu列表
@ -49,7 +49,7 @@ public interface ProductSpuService {
* @param ids 编号 * @param ids 编号
* @return 商品spu列表 * @return 商品spu列表
*/ */
List<ProductSpuDO> getSpuList(Collection<Integer> ids); List<ProductSpuDO> getSpuList(Collection<Long> ids);
/** /**
* 获得商品spu分页 * 获得商品spu分页

View File

@ -1,7 +1,13 @@
package cn.iocoder.yudao.module.product.service.spu; package cn.iocoder.yudao.module.product.service.spu;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO;
import cn.iocoder.yudao.module.product.service.category.CategoryService;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.util.*; import java.util.*;
@ -27,10 +33,25 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Resource @Resource
private ProductSpuMapper ProductSpuMapper; private ProductSpuMapper ProductSpuMapper;
@Resource
private CategoryService categoryService;
@Resource
private ProductSkuService productSkuService;
@Override @Override
public Integer createSpu(ProductSpuCreateReqVO createReqVO) { @Transactional
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
// 校验分类
categoryService.validatedCategoryById(createReqVO.getCategoryId());
// 校验SKU
List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getProductSkuCreateReqVOS();
productSkuService.validatedSkuReq(skuCreateReqList);
// 插入 // 插入
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
skuCreateReqList.forEach(p -> {
p.setSpuId(spu.getId());
});
ProductSpuMapper.insert(spu); ProductSpuMapper.insert(spu);
// 返回 // 返回
return spu.getId(); return spu.getId();
@ -46,26 +67,26 @@ public class ProductSpuServiceImpl implements ProductSpuService {
} }
@Override @Override
public void deleteSpu(Integer id) { public void deleteSpu(Long id) {
// 校验存在 // 校验存在
this.validateSpuExists(id); this.validateSpuExists(id);
// 删除 // 删除
ProductSpuMapper.deleteById(id); ProductSpuMapper.deleteById(id);
} }
private void validateSpuExists(Integer id) { private void validateSpuExists(Long id) {
if (ProductSpuMapper.selectById(id) == null) { if (ProductSpuMapper.selectById(id) == null) {
throw exception(SPU_NOT_EXISTS); throw exception(SPU_NOT_EXISTS);
} }
} }
@Override @Override
public ProductSpuDO getSpu(Integer id) { public ProductSpuDO getSpu(Long id) {
return ProductSpuMapper.selectById(id); return ProductSpuMapper.selectById(id);
} }
@Override @Override
public List<ProductSpuDO> getSpuList(Collection<Integer> ids) { public List<ProductSpuDO> getSpuList(Collection<Long> ids) {
return ProductSpuMapper.selectBatchIds(ids); return ProductSpuMapper.selectBatchIds(ids);
} }

View File

@ -46,7 +46,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
ProductSkuCreateReqVO reqVO = randomPojo(ProductSkuCreateReqVO.class); ProductSkuCreateReqVO reqVO = randomPojo(ProductSkuCreateReqVO.class);
// 调用 // 调用
Integer skuId = ProductSkuService.createSku(reqVO); Long skuId = ProductSkuService.createSku(reqVO);
// 断言 // 断言
assertNotNull(skuId); assertNotNull(skuId);
// 校验记录的属性是否正确 // 校验记录的属性是否正确
@ -86,7 +86,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
ProductSkuDO dbSku = randomPojo(ProductSkuDO.class); ProductSkuDO dbSku = randomPojo(ProductSkuDO.class);
ProductSkuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据 ProductSkuMapper.insert(dbSku);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
Integer id = dbSku.getId(); Long id = dbSku.getId();
// 调用 // 调用
ProductSkuService.deleteSku(id); ProductSkuService.deleteSku(id);
@ -97,7 +97,7 @@ public class SkuServiceImplTest extends BaseDbUnitTest {
@Test @Test
public void testDeleteSku_notExists() { public void testDeleteSku_notExists() {
// 准备参数 // 准备参数
Integer id = 1; Long id = 1L;
// 调用, 并断言异常 // 调用, 并断言异常
assertServiceException(() -> ProductSkuService.deleteSku(id), SKU_NOT_EXISTS); assertServiceException(() -> ProductSkuService.deleteSku(id), SKU_NOT_EXISTS);

View File

@ -46,7 +46,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
ProductSpuCreateReqVO reqVO = randomPojo(ProductSpuCreateReqVO.class); ProductSpuCreateReqVO reqVO = randomPojo(ProductSpuCreateReqVO.class);
// 调用 // 调用
Integer spuId = spuService.createSpu(reqVO); Long spuId = spuService.createSpu(reqVO);
// 断言 // 断言
assertNotNull(spuId); assertNotNull(spuId);
// 校验记录的属性是否正确 // 校验记录的属性是否正确
@ -86,7 +86,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class); ProductSpuDO dbSpu = randomPojo(ProductSpuDO.class);
ProductSpuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据 ProductSpuMapper.insert(dbSpu);// @Sql: 先插入出一条存在的数据
// 准备参数 // 准备参数
Integer id = dbSpu.getId(); Long id = dbSpu.getId();
// 调用 // 调用
spuService.deleteSpu(id); spuService.deleteSpu(id);
@ -97,7 +97,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
@Test @Test
public void testDeleteSpu_notExists() { public void testDeleteSpu_notExists() {
// 准备参数 // 准备参数
Integer id = 1; Long id = 1L;
// 调用, 并断言异常 // 调用, 并断言异常
assertServiceException(() -> spuService.deleteSpu(id), SPU_NOT_EXISTS); assertServiceException(() -> spuService.deleteSpu(id), SPU_NOT_EXISTS);

View File

@ -95,7 +95,7 @@
<el-input v-model="form.categoryId" placeholder="请输入分类id" /> <el-input v-model="form.categoryId" placeholder="请输入分类id" />
</el-form-item> </el-form-item>
<el-form-item label="商品主图地址" prop="picUrls"> <el-form-item label="商品主图地址" prop="picUrls">
<el-input v-model="form.picUrls" placeholder="请输入商品主图地址" /> <ImageUpload v-model="form.picUrls" :limit="1"/>
</el-form-item> </el-form-item>
<el-form-item label="排序字段" prop="sort"> <el-form-item label="排序字段" prop="sort">
<el-input v-model="form.sort" placeholder="请输入排序字段" /> <el-input v-model="form.sort" placeholder="请输入排序字段" />