Commit 4bcc6c374ecd419ece438b033c40f5de117763e6
1 parent
f07bf8b0
spu 保存,propertyValue合并到productProperty中
Showing
16 changed files
with
60 additions
and
187 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/propertyvalue/vo/ProductPropertyValueRespVO.java
| @@ -11,7 +11,7 @@ import io.swagger.annotations.*; | @@ -11,7 +11,7 @@ import io.swagger.annotations.*; | ||
| 11 | public class ProductPropertyValueRespVO extends ProductPropertyValueBaseVO { | 11 | public class ProductPropertyValueRespVO extends ProductPropertyValueBaseVO { |
| 12 | 12 | ||
| 13 | @ApiModelProperty(value = "主键", required = true) | 13 | @ApiModelProperty(value = "主键", required = true) |
| 14 | - private Integer id; | 14 | + private Long id; |
| 15 | 15 | ||
| 16 | @ApiModelProperty(value = "创建时间") | 16 | @ApiModelProperty(value = "创建时间") |
| 17 | private Date createTime; | 17 | private Date createTime; |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java
| @@ -12,8 +12,7 @@ import javax.validation.constraints.*; | @@ -12,8 +12,7 @@ import javax.validation.constraints.*; | ||
| 12 | @Data | 12 | @Data |
| 13 | public class ProductSkuBaseVO { | 13 | public class ProductSkuBaseVO { |
| 14 | 14 | ||
| 15 | - @ApiModelProperty(value = "spu编号", required = true) | ||
| 16 | - @NotNull(message = "spu编号不能为空") | 15 | + @ApiModelProperty(value = "spu编号") |
| 17 | private Long spuId; | 16 | private Long spuId; |
| 18 | 17 | ||
| 19 | @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) | 18 | @ApiModelProperty(value = "规格值数组-json格式, [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) |
| @@ -46,9 +45,9 @@ public class ProductSkuBaseVO { | @@ -46,9 +45,9 @@ public class ProductSkuBaseVO { | ||
| 46 | @Data | 45 | @Data |
| 47 | public static class Property { | 46 | public static class Property { |
| 48 | @NotNull(message = "规格属性名id不能为空") | 47 | @NotNull(message = "规格属性名id不能为空") |
| 49 | - private Integer propertyId; | 48 | + private Long propertyId; |
| 50 | @NotNull(message = "规格属性值id不能为空") | 49 | @NotNull(message = "规格属性值id不能为空") |
| 51 | - private Integer valueId; | 50 | + private Long valueId; |
| 52 | } | 51 | } |
| 53 | 52 | ||
| 54 | } | 53 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuExcelVO.java
| @@ -15,7 +15,7 @@ import com.alibaba.excel.annotation.ExcelProperty; | @@ -15,7 +15,7 @@ import com.alibaba.excel.annotation.ExcelProperty; | ||
| 15 | public class ProductSkuExcelVO { | 15 | public class ProductSkuExcelVO { |
| 16 | 16 | ||
| 17 | @ExcelProperty("主键") | 17 | @ExcelProperty("主键") |
| 18 | - private Integer id; | 18 | + private Long id; |
| 19 | 19 | ||
| 20 | @ExcelProperty("spu编号") | 20 | @ExcelProperty("spu编号") |
| 21 | private Long spuId; | 21 | private Long spuId; |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuRespVO.java
| @@ -11,7 +11,7 @@ import io.swagger.annotations.*; | @@ -11,7 +11,7 @@ import io.swagger.annotations.*; | ||
| 11 | public class ProductSkuRespVO extends ProductSkuBaseVO { | 11 | public class ProductSkuRespVO extends ProductSkuBaseVO { |
| 12 | 12 | ||
| 13 | @ApiModelProperty(value = "主键", required = true) | 13 | @ApiModelProperty(value = "主键", required = true) |
| 14 | - private Integer id; | 14 | + private Long id; |
| 15 | 15 | ||
| 16 | @ApiModelProperty(value = "创建时间") | 16 | @ApiModelProperty(value = "创建时间") |
| 17 | private Date createTime; | 17 | private Date createTime; |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| @@ -65,8 +65,7 @@ public class ProductSpuController { | @@ -65,8 +65,7 @@ public class ProductSpuController { | ||
| 65 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) | 65 | @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
| 66 | @PreAuthorize("@ss.hasPermission('product:spu:query')") | 66 | @PreAuthorize("@ss.hasPermission('product:spu:query')") |
| 67 | public CommonResult<SpuRespVO> getSpu(@RequestParam("id") Long id) { | 67 | public CommonResult<SpuRespVO> getSpu(@RequestParam("id") Long id) { |
| 68 | - ProductSpuDO spu = spuService.getSpu(id); | ||
| 69 | - return success(ProductSpuConvert.INSTANCE.convert(spu)); | 68 | + return success(spuService.getSpu(id)); |
| 70 | } | 69 | } |
| 71 | 70 | ||
| 72 | @GetMapping("/list") | 71 | @GetMapping("/list") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuRespVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.spu.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | ||
| 3 | import lombok.*; | 4 | import lombok.*; |
| 4 | import java.util.*; | 5 | import java.util.*; |
| 5 | import io.swagger.annotations.*; | 6 | import io.swagger.annotations.*; |
| @@ -16,4 +17,6 @@ public class SpuRespVO extends ProductSpuBaseVO { | @@ -16,4 +17,6 @@ public class SpuRespVO extends ProductSpuBaseVO { | ||
| 16 | @ApiModelProperty(value = "创建时间") | 17 | @ApiModelProperty(value = "创建时间") |
| 17 | private Date createTime; | 18 | private Date createTime; |
| 18 | 19 | ||
| 20 | + List<ProductSkuRespVO> productSkuRespVOS; | ||
| 21 | + | ||
| 19 | } | 22 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/propertyvalue/ProductPropertyValueDO.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java
| @@ -5,6 +5,7 @@ import java.util.*; | @@ -5,6 +5,7 @@ import java.util.*; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 8 | +import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | ||
| 8 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 9 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| 10 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; | 11 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.*; |
| @@ -45,4 +46,9 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | @@ -45,4 +46,9 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | ||
| 45 | .orderByDesc(ProductSkuDO::getId)); | 46 | .orderByDesc(ProductSkuDO::getId)); |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 49 | + default List<ProductSkuDO> selectBySpuId(Long spuId) { | ||
| 50 | + return selectList(new LambdaQueryWrapperX<ProductSkuDO>() | ||
| 51 | + .eqIfPresent(ProductSkuDO::getSpuId, spuId) | ||
| 52 | + ); | ||
| 53 | + } | ||
| 48 | } | 54 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java
| @@ -81,5 +81,5 @@ public interface ProductPropertyService { | @@ -81,5 +81,5 @@ public interface ProductPropertyService { | ||
| 81 | * @param propertyIds 属性名id集合 | 81 | * @param propertyIds 属性名id集合 |
| 82 | * @return | 82 | * @return |
| 83 | */ | 83 | */ |
| 84 | - List<ProductPropertyRespVO> selectByIds(List<Integer> propertyIds); | 84 | + List<ProductPropertyRespVO> selectByIds(List<Long> propertyIds); |
| 85 | } | 85 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.property; | 1 | package cn.iocoder.yudao.module.product.service.property; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.*; | 4 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.*; |
| 6 | -import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO; | ||
| 8 | import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO; | 5 | import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO; |
| 9 | import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO; |
| 10 | import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; | 7 | import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; |
| @@ -12,7 +9,7 @@ import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValu | @@ -12,7 +9,7 @@ import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValu | ||
| 12 | import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; |
| 13 | import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; | 10 | import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; |
| 14 | import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; | 11 | import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper; |
| 15 | -import cn.iocoder.yudao.module.product.service.propertyvalue.ProductPropertyValueService; | 12 | +import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.ProductPropertyValueMapper; |
| 16 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 17 | import org.springframework.transaction.annotation.Transactional; | 14 | import org.springframework.transaction.annotation.Transactional; |
| 18 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| @@ -21,6 +18,7 @@ import javax.annotation.Resource; | @@ -21,6 +18,7 @@ import javax.annotation.Resource; | ||
| 21 | import java.util.Arrays; | 18 | import java.util.Arrays; |
| 22 | import java.util.Collection; | 19 | import java.util.Collection; |
| 23 | import java.util.List; | 20 | import java.util.List; |
| 21 | +import java.util.Map; | ||
| 24 | import java.util.stream.Collectors; | 22 | import java.util.stream.Collectors; |
| 25 | 23 | ||
| 26 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 24 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -39,7 +37,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -39,7 +37,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 39 | private ProductPropertyMapper productPropertyMapper; | 37 | private ProductPropertyMapper productPropertyMapper; |
| 40 | 38 | ||
| 41 | @Resource | 39 | @Resource |
| 42 | - private ProductPropertyValueService productPropertyValueService; | 40 | + private ProductPropertyValueMapper productPropertyValueMapper; |
| 43 | 41 | ||
| 44 | @Override | 42 | @Override |
| 45 | @Transactional(rollbackFor = Exception.class) | 43 | @Transactional(rollbackFor = Exception.class) |
| @@ -52,7 +50,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -52,7 +50,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 52 | List<ProductPropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList(); | 50 | List<ProductPropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList(); |
| 53 | List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList); | 51 | List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList); |
| 54 | productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId())); | 52 | productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId())); |
| 55 | - productPropertyValueService.batchInsert(productPropertyValueDOList); | 53 | + productPropertyValueMapper.insertBatch(productPropertyValueDOList); |
| 56 | // 返回 | 54 | // 返回 |
| 57 | return property.getId(); | 55 | return property.getId(); |
| 58 | } | 56 | } |
| @@ -66,11 +64,11 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -66,11 +64,11 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 66 | ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); | 64 | ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); |
| 67 | productPropertyMapper.updateById(updateObj); | 65 | productPropertyMapper.updateById(updateObj); |
| 68 | //更新属性值,先删后加 | 66 | //更新属性值,先删后加 |
| 69 | - productPropertyValueService.deletePropertyValueByPropertyId(updateReqVO.getId()); | 67 | + productPropertyValueMapper.deletePropertyValueByPropertyId(updateReqVO.getId()); |
| 70 | List<ProductPropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList(); | 68 | List<ProductPropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList(); |
| 71 | List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList); | 69 | List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList); |
| 72 | productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId())); | 70 | productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId())); |
| 73 | - productPropertyValueService.batchInsert(productPropertyValueDOList); | 71 | + productPropertyValueMapper.insertBatch(productPropertyValueDOList); |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | @Override | 74 | @Override |
| @@ -80,7 +78,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -80,7 +78,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 80 | // 删除 | 78 | // 删除 |
| 81 | productPropertyMapper.deleteById(id); | 79 | productPropertyMapper.deleteById(id); |
| 82 | //同步删除属性值 | 80 | //同步删除属性值 |
| 83 | - productPropertyValueService.deletePropertyValueByPropertyId(id); | 81 | + productPropertyValueMapper.deletePropertyValueByPropertyId(id); |
| 84 | } | 82 | } |
| 85 | 83 | ||
| 86 | private void validatePropertyExists(Long id) { | 84 | private void validatePropertyExists(Long id) { |
| @@ -117,7 +115,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -117,7 +115,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 117 | List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(ProductPropertyRespVO::getId).collect(Collectors.toList()); | 115 | List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(ProductPropertyRespVO::getId).collect(Collectors.toList()); |
| 118 | 116 | ||
| 119 | //获取属性值列表 | 117 | //获取属性值列表 |
| 120 | - List<ProductPropertyValueDO> productPropertyValueDOList = productPropertyValueService.getPropertyValueListByPropertyId(propertyIds); | 118 | + List<ProductPropertyValueDO> productPropertyValueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds); |
| 121 | List<ProductPropertyValueRespVO> propertyValueRespVOList = ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueDOList); | 119 | List<ProductPropertyValueRespVO> propertyValueRespVOList = ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueDOList); |
| 122 | //组装一对多 | 120 | //组装一对多 |
| 123 | propertyRespVOPageResult.getList().forEach(x->{ | 121 | propertyRespVOPageResult.getList().forEach(x->{ |
| @@ -128,13 +126,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -128,13 +126,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 128 | return propertyRespVOPageResult; | 126 | return propertyRespVOPageResult; |
| 129 | } | 127 | } |
| 130 | 128 | ||
| 129 | + private List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) { | ||
| 130 | + return productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds); | ||
| 131 | + } | ||
| 132 | + | ||
| 131 | @Override | 133 | @Override |
| 132 | public ProductPropertyRespVO getPropertyResp(Long id) { | 134 | public ProductPropertyRespVO getPropertyResp(Long id) { |
| 133 | //查询规格 | 135 | //查询规格 |
| 134 | ProductPropertyDO property = getProperty(id); | 136 | ProductPropertyDO property = getProperty(id); |
| 135 | ProductPropertyRespVO propertyRespVO = ProductPropertyConvert.INSTANCE.convert(property); | 137 | ProductPropertyRespVO propertyRespVO = ProductPropertyConvert.INSTANCE.convert(property); |
| 136 | //查询属性值 | 138 | //查询属性值 |
| 137 | - List<ProductPropertyValueDO> valueDOList = productPropertyValueService.getPropertyValueListByPropertyId(Arrays.asList(id)); | 139 | + List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(Arrays.asList(id)); |
| 138 | List<ProductPropertyValueRespVO> propertyValueRespVOS = ProductPropertyValueConvert.INSTANCE.convertList(valueDOList); | 140 | List<ProductPropertyValueRespVO> propertyValueRespVOS = ProductPropertyValueConvert.INSTANCE.convertList(valueDOList); |
| 139 | //组装 | 141 | //组装 |
| 140 | propertyRespVO.setPropertyValueList(propertyValueRespVOS); | 142 | propertyRespVO.setPropertyValueList(propertyValueRespVOS); |
| @@ -142,7 +144,12 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | @@ -142,7 +144,12 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { | ||
| 142 | } | 144 | } |
| 143 | 145 | ||
| 144 | @Override | 146 | @Override |
| 145 | - public List<ProductPropertyRespVO> selectByIds(List<Integer> propertyIds) { | ||
| 146 | - return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(propertyIds)); | 147 | + public List<ProductPropertyRespVO> selectByIds(List<Long> propertyIds) { |
| 148 | + List<ProductPropertyRespVO> productPropertyRespVO = ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(propertyIds)); | ||
| 149 | + //查询属性值 | ||
| 150 | + List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds); | ||
| 151 | + Map<Long, List<ProductPropertyValueDO>> propertyValuesMap = valueDOList.stream().collect(Collectors.groupingBy(ProductPropertyValueDO::getPropertyId)); | ||
| 152 | + productPropertyRespVO.forEach(p -> p.setPropertyValueList(ProductPropertyValueConvert.INSTANCE.convertList(propertyValuesMap.get(p.getId())))); | ||
| 153 | + return productPropertyRespVO; | ||
| 147 | } | 154 | } |
| 148 | } | 155 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/propertyvalue/ProductProductPropertyValueServiceImpl.java deleted
| 1 | -package cn.iocoder.yudao.module.product.service.propertyvalue; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*; | ||
| 4 | -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; | ||
| 5 | -import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; | ||
| 6 | -import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.ProductPropertyValueMapper; | ||
| 7 | -import org.springframework.stereotype.Service; | ||
| 8 | -import org.springframework.validation.annotation.Validated; | ||
| 9 | - | ||
| 10 | -import javax.annotation.Resource; | ||
| 11 | -import java.util.Collection; | ||
| 12 | -import java.util.List; | ||
| 13 | - | ||
| 14 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 15 | -import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS; | ||
| 16 | - | ||
| 17 | -/** | ||
| 18 | - * 规格值 Service 实现类 | ||
| 19 | - * | ||
| 20 | - * @author 芋道源码 | ||
| 21 | - */ | ||
| 22 | -@Service | ||
| 23 | -@Validated | ||
| 24 | -public class ProductProductPropertyValueServiceImpl implements ProductPropertyValueService { | ||
| 25 | - | ||
| 26 | - @Resource | ||
| 27 | - private ProductPropertyValueMapper productPropertyValueMapper; | ||
| 28 | - | ||
| 29 | - // TODO @franky:这个合并到 property 中。他们本身是在一起的哈。基本不存在只查询规格,而不查询规格值。 | ||
| 30 | - | ||
| 31 | - @Override | ||
| 32 | - public Integer createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) { | ||
| 33 | - // 插入 | ||
| 34 | - ProductPropertyValueDO propertyValue = ProductPropertyValueConvert.INSTANCE.convert(createReqVO); | ||
| 35 | - productPropertyValueMapper.insert(propertyValue); | ||
| 36 | - // 返回 | ||
| 37 | - return propertyValue.getId(); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - @Override | ||
| 41 | - public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) { | ||
| 42 | - // 校验存在 | ||
| 43 | - this.validatePropertyValueExists(updateReqVO.getId()); | ||
| 44 | - // 更新 | ||
| 45 | - ProductPropertyValueDO updateObj = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO); | ||
| 46 | - productPropertyValueMapper.updateById(updateObj); | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - @Override | ||
| 50 | - public void deletePropertyValue(Integer id) { | ||
| 51 | - // 校验存在 | ||
| 52 | - this.validatePropertyValueExists(id); | ||
| 53 | - // 删除 | ||
| 54 | - productPropertyValueMapper.deleteById(id); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - private void validatePropertyValueExists(Integer id) { | ||
| 58 | - if (productPropertyValueMapper.selectById(id) == null) { | ||
| 59 | - throw exception(PROPERTY_VALUE_NOT_EXISTS); | ||
| 60 | - } | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - @Override | ||
| 64 | - public ProductPropertyValueDO getPropertyValue(Integer id) { | ||
| 65 | - return productPropertyValueMapper.selectById(id); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - @Override | ||
| 69 | - public List<ProductPropertyValueDO> getPropertyValueList(Collection<Integer> ids) { | ||
| 70 | - return productPropertyValueMapper.selectBatchIds(ids); | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - @Override | ||
| 74 | - public void batchInsert(List<ProductPropertyValueDO> propertyValues) { | ||
| 75 | - productPropertyValueMapper.insertBatch(propertyValues); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - @Override | ||
| 79 | - public List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) { | ||
| 80 | - return productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - @Override | ||
| 84 | - public void deletePropertyValueByPropertyId(Long propertyId) { | ||
| 85 | - productPropertyValueMapper.deletePropertyValueByPropertyId(propertyId); | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | -} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/propertyvalue/ProductPropertyValueService.java deleted
| 1 | -package cn.iocoder.yudao.module.product.service.propertyvalue; | ||
| 2 | - | ||
| 3 | -import java.util.*; | ||
| 4 | -import javax.validation.*; | ||
| 5 | -import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.*; | ||
| 6 | -import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * 规格值 Service 接口 | ||
| 10 | - * | ||
| 11 | - * @author 芋道源码 | ||
| 12 | - */ | ||
| 13 | -public interface ProductPropertyValueService { | ||
| 14 | - | ||
| 15 | - /** | ||
| 16 | - * 创建规格值 | ||
| 17 | - * | ||
| 18 | - * @param createReqVO 创建信息 | ||
| 19 | - * @return 编号 | ||
| 20 | - */ | ||
| 21 | - Integer createPropertyValue(@Valid ProductPropertyValueCreateReqVO createReqVO); | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | - * 更新规格值 | ||
| 25 | - * | ||
| 26 | - * @param updateReqVO 更新信息 | ||
| 27 | - */ | ||
| 28 | - void updatePropertyValue(@Valid ProductPropertyValueUpdateReqVO updateReqVO); | ||
| 29 | - | ||
| 30 | - /** | ||
| 31 | - * 删除规格值 | ||
| 32 | - * | ||
| 33 | - * @param id 编号 | ||
| 34 | - */ | ||
| 35 | - void deletePropertyValue(Integer id); | ||
| 36 | - | ||
| 37 | - /** | ||
| 38 | - * 获得规格值 | ||
| 39 | - * | ||
| 40 | - * @param id 编号 | ||
| 41 | - * @return 规格值 | ||
| 42 | - */ | ||
| 43 | - ProductPropertyValueDO getPropertyValue(Integer id); | ||
| 44 | - | ||
| 45 | - /** | ||
| 46 | - * 获得规格值列表 | ||
| 47 | - * | ||
| 48 | - * @param ids 编号 | ||
| 49 | - * @return 规格值列表 | ||
| 50 | - */ | ||
| 51 | - List<ProductPropertyValueDO> getPropertyValueList(Collection<Integer> ids); | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | - * 批量插入属性值 | ||
| 55 | - * @param propertyValues | ||
| 56 | - */ | ||
| 57 | - void batchInsert(List<ProductPropertyValueDO> propertyValues); | ||
| 58 | - | ||
| 59 | - /** | ||
| 60 | - * 根据属性id查询 | ||
| 61 | - * @param propertyIds | ||
| 62 | - * @return | ||
| 63 | - */ | ||
| 64 | - List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds); | ||
| 65 | - | ||
| 66 | - /** | ||
| 67 | - * 根据属性id 删除 | ||
| 68 | - * @param propertyId | ||
| 69 | - */ | ||
| 70 | - void deletePropertyValueByPropertyId(Long propertyId); | ||
| 71 | -} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
| @@ -79,4 +79,12 @@ public interface ProductSkuService { | @@ -79,4 +79,12 @@ public interface ProductSkuService { | ||
| 79 | * @return | 79 | * @return |
| 80 | */ | 80 | */ |
| 81 | void batchSave(List<ProductSkuDO> skuDOList); | 81 | void batchSave(List<ProductSkuDO> skuDOList); |
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 获得商品sku 集合 | ||
| 85 | + * | ||
| 86 | + * @param spuId spu 编号 | ||
| 87 | + * @return 商品sku 集合 | ||
| 88 | + */ | ||
| 89 | + List<ProductSkuDO> getSkusBySpuId(Long spuId); | ||
| 82 | } | 90 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| @@ -92,7 +92,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -92,7 +92,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 92 | public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) { | 92 | public void validatedSkuReq(List<ProductSkuCreateReqVO> skuCreateReqList) { |
| 93 | List<ProductSkuBaseVO.Property> skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); | 93 | List<ProductSkuBaseVO.Property> skuPropertyList = skuCreateReqList.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); |
| 94 | // 校验规格属性以及规格值是否存在 | 94 | // 校验规格属性以及规格值是否存在 |
| 95 | - List<Integer> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList()); | 95 | + List<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList()); |
| 96 | List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds); | 96 | List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds); |
| 97 | if (propertyAndValueList.isEmpty()) | 97 | if (propertyAndValueList.isEmpty()) |
| 98 | throw ServiceExceptionUtil.exception(PROPERTY_NOT_EXISTS); | 98 | throw ServiceExceptionUtil.exception(PROPERTY_NOT_EXISTS); |
| @@ -122,4 +122,9 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -122,4 +122,9 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 122 | public void batchSave(List<ProductSkuDO> skuDOList) { | 122 | public void batchSave(List<ProductSkuDO> skuDOList) { |
| 123 | productSkuMapper.insertBatch(skuDOList); | 123 | productSkuMapper.insertBatch(skuDOList); |
| 124 | } | 124 | } |
| 125 | + | ||
| 126 | + @Override | ||
| 127 | + public List<ProductSkuDO> getSkusBySpuId(Long spuId) { | ||
| 128 | + return productSkuMapper.selectBySpuId(spuId); | ||
| 129 | + } | ||
| 125 | } | 130 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
| @@ -41,7 +41,7 @@ public interface ProductSpuService { | @@ -41,7 +41,7 @@ public interface ProductSpuService { | ||
| 41 | * @param id 编号 | 41 | * @param id 编号 |
| 42 | * @return 商品spu | 42 | * @return 商品spu |
| 43 | */ | 43 | */ |
| 44 | - ProductSpuDO getSpu(Long id); | 44 | + SpuRespVO getSpu(Long id); |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| 47 | * 获得商品spu列表 | 47 | * 获得商品spu列表 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.spu; | 1 | package cn.iocoder.yudao.module.product.service.spu; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; | 3 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; |
| 4 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | ||
| 4 | import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | 5 | import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; |
| 5 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 6 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 6 | import cn.iocoder.yudao.module.product.service.category.CategoryService; | 7 | import cn.iocoder.yudao.module.product.service.category.CategoryService; |
| @@ -89,8 +90,12 @@ public class ProductSpuServiceImpl implements ProductSpuService { | @@ -89,8 +90,12 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | @Override | 92 | @Override |
| 92 | - public ProductSpuDO getSpu(Long id) { | ||
| 93 | - return ProductSpuMapper.selectById(id); | 93 | + public SpuRespVO getSpu(Long id) { |
| 94 | + ProductSpuDO spu = ProductSpuMapper.selectById(id); | ||
| 95 | + SpuRespVO spuVO = ProductSpuConvert.INSTANCE.convert(spu); | ||
| 96 | + List<ProductSkuRespVO> skuReqs = ProductSkuConvert.INSTANCE.convertList( productSkuService.getSkusBySpuId(id)); | ||
| 97 | + spuVO.setProductSkuRespVOS(skuReqs); | ||
| 98 | + return spuVO; | ||
| 94 | } | 99 | } |
| 95 | 100 | ||
| 96 | @Override | 101 | @Override |