diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index a3d64d42c..86875b119 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java @@ -24,9 +24,11 @@ public interface ErrorCodeConstants { // ========== 商品规格名称 1008003000 ========== ErrorCode PROPERTY_NOT_EXISTS = new ErrorCode(1008003000, "规格名称不存在"); + ErrorCode PROPERTY_EXISTS = new ErrorCode(1008003001, "规格名称已存在"); // ========== 规格值 1008004000 ========== ErrorCode PROPERTY_VALUE_NOT_EXISTS = new ErrorCode(1008004000, "规格值不存在"); + ErrorCode PROPERTY_VALUE_EXISTS = new ErrorCode(1008004001, "规格值已存在"); // ========== 商品 SPU 1008005000 ========== ErrorCode SPU_NOT_EXISTS = new ErrorCode(1008005000, "商品 SPU 不存在"); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java index 72a8bf603..9a4c20c58 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyController.java @@ -56,7 +56,7 @@ public class ProductPropertyController { @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('product:property:query')") public CommonResult getProperty(@RequestParam("id") Long id) { - return success(productPropertyService.getPropertyResp(id)); + return success(productPropertyService.getProperty(id)); } @GetMapping("/list") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java index b29eb85f4..40696455a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuDetailRespVO.java @@ -55,9 +55,8 @@ public class ProductSpuDetailRespVO extends ProductSpuBaseVO { } - // TODO @luowenfeng: 只返回 categoryId 可以么? 如果是为了前端修改时使用, 会拿到下拉列表, 自动选中合适的. 可以微信讨论下, 我也不完全确定哈; @ApiModelProperty(value = "分类 id 数组,一直递归到一级父节点", example = "[1,2,4]") - private List categoryIds; + private Long categoryIds; @ApiModelProperty(value = "规格属性修改和详情展示组合", example = "[{\"propertyId\":2,\"name\":\"内存\",\"propertyValues\":[{\"v1\":11,\"v2\":\"64G\"},{\"v1\":10,\"v2\":\"32G\"}]},{\"propertyId\":3,\"name\":\"尺寸\",\"propertyValues\":[{\"v1\":16,\"v2\":\"6.1\"},{\"v1\":15,\"v2\":\"5.7\"}]}]") private List productPropertyViews; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java index 9f7c46745..f780f72c7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyConvert.java @@ -1,10 +1,13 @@ package cn.iocoder.yudao.module.product.convert.property; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyAndValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; +import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -23,6 +26,8 @@ public interface ProductPropertyConvert { ProductPropertyDO convert(ProductPropertyCreateReqVO bean); ProductPropertyDO convert(ProductPropertyUpdateReqVO bean); + ProductPropertyAndValueRespVO convert(ProductPropertyRespVO bean); + ProductPropertyRespVO convert(ProductPropertyDO bean); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java index bd088466f..1b58a88e7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyMapper.java @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.Pro import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 规格名称 Mapper * @@ -23,4 +25,9 @@ public interface ProductPropertyMapper extends BaseMapperX { .orderByDesc(ProductPropertyDO::getId)); } + default ProductPropertyDO selectByName(String name) { + return selectOne(new LambdaQueryWrapperX() + .likeIfPresent(ProductPropertyDO::getName, name)); + } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java index 23f09aa2a..c392bb81d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/property/ProductPropertyValueMapper.java @@ -17,19 +17,20 @@ import java.util.List; @Mapper public interface ProductPropertyValueMapper extends BaseMapperX { - // TODO @luowenfeng:方法名,selectListByXXX。mapper 的操作都是 crud - default List getPropertyValueListByPropertyId(List propertyIds) { - // TODO @franky:调用父类的 selectList + default List selectListByPropertyValueListByPropertyId(List propertyIds) { return selectList(new LambdaQueryWrapperX() .inIfPresent(ProductPropertyValueDO::getPropertyId, propertyIds)); } + default ProductPropertyValueDO selectByName(Long propertyId, String name) { + return selectOne(new LambdaQueryWrapperX() + .eq(ProductPropertyValueDO::getPropertyId, propertyId) + .eq(ProductPropertyValueDO::getName, name)); + } + default void deletePropertyValueByPropertyId(Long propertyId) { - // TODO @luowenfeng:delete(new ) 即可 - LambdaQueryWrapperX queryWrapperX = new LambdaQueryWrapperX<>(); - queryWrapperX.eq(ProductPropertyValueDO::getPropertyId, propertyId) - .eq(ProductPropertyValueDO::getDeleted, false); - delete(queryWrapperX); + delete(new LambdaQueryWrapperX().eq(ProductPropertyValueDO::getPropertyId, propertyId) + .eq(ProductPropertyValueDO::getDeleted, false)); } default PageResult selectPage(ProductPropertyValuePageReqVO reqVO) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java index 41ba75090..f74f04b92 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.product.api.sku.dto.SkuDecrementStockBatchReqDTO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; @@ -17,20 +18,13 @@ import java.util.List; @Mapper public interface ProductSkuMapper extends BaseMapperX { - // TODO @franky:方法名 selectList; 可以直接调用 selectList - default List selectListBySpuIds(List spuIds) { - return selectList(ProductSkuDO::getSpuId, spuIds); - } - default List selectListBySpuId(Long spuId) { return selectList(ProductSkuDO::getSpuId, spuId); } default void deleteBySpuId(Long spuId) { - // TODO @franky:直接 delete(new XXX) 即可,更简洁一些 - LambdaQueryWrapperX lambdaQueryWrapperX = new LambdaQueryWrapperX() - .eqIfPresent(ProductSkuDO::getSpuId, spuId); - delete(lambdaQueryWrapperX); + delete(new LambdaQueryWrapperX() + .eqIfPresent(ProductSkuDO::getSpuId, spuId)); } default void decrementStockBatch(List items) { @@ -45,4 +39,7 @@ public interface ProductSkuMapper extends BaseMapperX { this.update(null, lambdaUpdateWrapper); } } + default List selectRemindSpuIds(){ + return selectList(new QueryWrapper().apply("stock <= warn_stock")); + } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java index 2579acc7e..f9c18758f 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/ProductCategoryServiceImpl.java @@ -93,18 +93,15 @@ public class ProductCategoryServiceImpl implements ProductCategoryService { @Override public void validateCategoryLevel(Long id) { Long parentId = id; - for (int i = 0; i < 3; i++) { // TODO @luowenfeng: 建议还是先获得 level; 然后判断 level 是不是满足; 这样逻辑会更清晰一些; - if (Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)) { - throw exception(CATEGORY_LEVEL_ERROR); - } + int i = 2; + for (; i >= 0; --i) { ProductCategoryDO category = productCategoryMapper.selectById(parentId); - if (category == null) { - // TODO @luowenfeng: 应该抛出 CATEGORY_LEVEL_ERROR - throw exception(CATEGORY_NOT_EXISTS); - } parentId = category.getParentId(); + if(Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)){ + break; + } } - if (!Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL)) { + if (!Objects.equals(parentId, ProductCategoryDO.PARENT_ID_NULL) || i != 0) { throw exception(CATEGORY_LEVEL_ERROR); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java index aec4b9ed2..2d991a861 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyService.java @@ -38,14 +38,6 @@ public interface ProductPropertyService { */ void deleteProperty(Long id); - /** - * 获得规格名称 - * - * @param id 编号 - * @return 规格名称 - */ - ProductPropertyDO getProperty(Long id); - /** * 获得规格名称列表 * @param listReqVO 集合查询 @@ -61,8 +53,12 @@ public interface ProductPropertyService { */ PageResult getPropertyPage(ProductPropertyPageReqVO pageReqVO); - // TODO luowenfeng: getProperty 就可以拉, 不用到 Resp - ProductPropertyRespVO getPropertyResp(Long id); + /** + * + * @param id 编号 + * @return 规格名称 + */ + ProductPropertyRespVO getProperty(Long id); /** * 根据规格属性编号的集合,获得对应的规格 + 规格值的集合 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java index e070a7140..9bc34bbd7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyServiceImpl.java @@ -1,13 +1,10 @@ package cn.iocoder.yudao.module.product.service.property; -import cn.hutool.core.bean.BeanUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert; import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; @@ -19,13 +16,12 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_NOT_EXISTS; /** @@ -46,7 +42,10 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { @Override @Transactional(rollbackFor = Exception.class) public Long createProperty(ProductPropertyCreateReqVO createReqVO) { - // TODO @luowenfeng: 插入和更新的时候, 要校验 name 的唯一性; + // 校验存在 + if(productPropertyMapper.selectByName(createReqVO.getName()) != null){ + throw exception(PROPERTY_EXISTS); + } // 插入 ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO); productPropertyMapper.insert(property); @@ -59,6 +58,9 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) { // 校验存在 this.validatePropertyExists(updateReqVO.getId()); + if(productPropertyMapper.selectByName(updateReqVO.getName()) != null){ + throw exception(PROPERTY_EXISTS); + } // 更新 ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO); productPropertyMapper.updateById(updateObj); @@ -80,11 +82,6 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { } } - @Override - public ProductPropertyDO getProperty(Long id) { - return productPropertyMapper.selectById(id); - } - @Override public List getPropertyList(ProductPropertyListReqVO listReqVO) { return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectList(new LambdaQueryWrapperX() @@ -96,29 +93,16 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { public PageResult getPropertyPage(ProductPropertyPageReqVO pageReqVO) { //获取属性列表 PageResult pageResult = productPropertyMapper.selectPage(pageReqVO); - PageResult propertyRespVOPageResult = ProductPropertyConvert.INSTANCE.convertPage(pageResult); - // TODO @luofengwen: 下面的代码, 如果不要,可以删除哈; git 可以拿到记录的 -// List propertyIds = propertyRespVOPageResult.getList().stream().map(ProductPropertyAndValueRespVO::getId).collect(Collectors.toList()); -// -// //获取属性值列表 -// List productPropertyValueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds); -// List propertyValueRespVOList = ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueDOList); -// //组装一对多 -// propertyRespVOPageResult.getList().forEach(x->{ -// Long propertyId = x.getId(); -// List valueDOList = propertyValueRespVOList.stream().filter(v -> v.getPropertyId().equals(propertyId)).collect(Collectors.toList()); -// x.setValues(valueDOList); -// }); - return propertyRespVOPageResult; + return ProductPropertyConvert.INSTANCE.convertPage(pageResult); } private List getPropertyValueListByPropertyId(List propertyIds) { - return productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds); + return productPropertyValueMapper.selectListByPropertyValueListByPropertyId(propertyIds); } @Override - public ProductPropertyRespVO getPropertyResp(Long id) { - ProductPropertyDO property = getProperty(id); + public ProductPropertyRespVO getProperty(Long id) { + ProductPropertyDO property = productPropertyMapper.selectById(id); return ProductPropertyConvert.INSTANCE.convert(property); } @@ -132,17 +116,12 @@ public class ProductPropertyServiceImpl implements ProductPropertyService { List propertyList = getPropertyList(listReqVO); // 查询属性值 - List valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId)); -// CollectionUtils.convertMultiMap() // TODO @luofengwen: 可以使用这个方法哈 - Map> valueDOMap = valueDOList.stream() - .map(ProductPropertyValueConvert.INSTANCE::convert) - .collect(Collectors.groupingBy(ProductPropertyValueRespVO::getPropertyId)); - // 组装 TODO @luowenfeng: CollectionUtils 转换哈; - return propertyList.stream().map(m -> { - // TODO @luowenfeng: 使用 mapstruct convert 哈 - ProductPropertyAndValueRespVO productPropertyAndValueRespVO = BeanUtil.copyProperties(m, ProductPropertyAndValueRespVO.class); - productPropertyAndValueRespVO.setValues(valueDOMap.get(m.getId())); + List valueDOList = productPropertyValueMapper.selectListByPropertyValueListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId)); + Map> valueDOMap = CollectionUtils.convertMultiMap(valueDOList, ProductPropertyValueDO::getPropertyId); + return CollectionUtils.convertList(propertyList, m -> { + ProductPropertyAndValueRespVO productPropertyAndValueRespVO = ProductPropertyConvert.INSTANCE.convert(m); + productPropertyAndValueRespVO.setValues(ProductPropertyValueConvert.INSTANCE.convertList(valueDOMap.get(m.getId()))); return productPropertyAndValueRespVO; - }).collect(Collectors.toList()); + }); } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java index 4d2f27ee2..9dcbd72e7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueService.java @@ -10,7 +10,7 @@ import java.util.List; /** *

- * + * 规格值 Service 接口 *

* * @author LuoWenFeng diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java index db99c2881..f954d763a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java @@ -15,9 +15,12 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS; + /** - *

TODO @luowenfeng: 类注释 - * + *

+ * 规格值 Service 实现类 *

* * @author LuoWenFeng @@ -31,7 +34,9 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ @Override public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) { - // TODO @luowenfeng: 需要校验下在这个 propertyId, 新增和更新, name 都要唯一 + if (productPropertyValueMapper.selectByName(createReqVO.getPropertyId(), createReqVO.getName()) != null) { + throw exception(PROPERTY_VALUE_EXISTS); + } ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(createReqVO); productPropertyValueMapper.insert(convert); return convert.getId(); @@ -39,6 +44,9 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ @Override public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) { + if (productPropertyValueMapper.selectByName(updateReqVO.getPropertyId(), updateReqVO.getName()) != null) { + throw exception(PROPERTY_VALUE_EXISTS); + } ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO); productPropertyValueMapper.updateById(convert); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java index 9de133a3f..9da746427 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java @@ -83,12 +83,11 @@ public interface ProductSkuService { */ void deleteSkuBySpuId(Long spuId); - // TODO @luowenfeng: 可以改成返回 ProductSkuDO 列表; 然后, 上层业务在做处理; /** * 获得商品预警中的 SPU 集合 * * @return 商品spuId集合 */ - List getRemindSpuIds(); + List getRemindSpuIds(); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index b1b1dfa3f..cd9b68bff 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -124,12 +124,12 @@ public class ProductSkuServiceImpl implements ProductSkuService { @Override public List getSkusBySpuId(Long spuId) { - return productSkuMapper.selectListBySpuIds(Collections.singletonList(spuId)); + return productSkuMapper.selectList(ProductSkuDO::getSpuId, spuId); } @Override public List getSkusBySpuIds(List spuIds) { - return productSkuMapper.selectListBySpuIds(spuIds); + return productSkuMapper.selectList(ProductSkuDO::getSpuId, spuIds); } @Override @@ -138,10 +138,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { } @Override - public List getRemindSpuIds() { - // TODO @luowenfeng: mybatis plus 不能出现在 Service 哈; 把这个查询, 下沉一个方法到 mapper 里 - List productSkuDOS = productSkuMapper.selectList(new QueryWrapper().apply("stock <= warn_stock")); - return productSkuDOS.stream().map(ProductSkuDO::getSpuId).distinct().collect(Collectors.toList()); + public List getRemindSpuIds() { + return productSkuMapper.selectRemindSpuIds(); } @Override @@ -160,12 +158,6 @@ public class ProductSkuServiceImpl implements ProductSkuService { return String.join("-", collect, String.valueOf(v.getId())); }) .collect(Collectors.toMap(v -> v.split("-")[0], v -> Long.valueOf(v.split("-")[1]))); -// Map existsSkuMap2 = CollectionUtils.convertMap(existsSkus, productSkuDO -> { -// if (CollUtil.isEmpty(productSkuDO.getProperties())) { -// return ""; -// } -// return StrUtil.join("-", convertList(productSkuDO.getProperties(), ProductSkuDO.Property::getValueId)); -// }, ProductSkuDO::getId); // 拆分三个集合,新插入的、需要更新的、需要删除的 List insertSkus = new ArrayList<>(); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java index 6b7c7358b..2c5a9af91 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java @@ -72,7 +72,7 @@ public interface ProductSpuService { PageResult getSpuPage(ProductSpuPageReqVO pageReqVO); /** - * 获得商品 SPU 分页 // TODO @luowenfeng: 中文和英文之间, 要有一个空格; 这样, 阅读起来会更清晰; 我已经都改啦 + * 获得商品 SPU 分页 * * @param pageReqVO 分页查询 * @return 商品spu分页 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index d901047d1..9b714fef7 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum; @@ -134,7 +135,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { List skuReqs = ProductSkuConvert.INSTANCE.convertList03(productSkuService.getSkusBySpuId(id)); respVO.setSkus(skuReqs); // 组合 sku 规格属性 - if(spu.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { + if (spu.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { List properties = new ArrayList<>(); for (ProductSpuDetailRespVO.Sku productSkuRespVO : skuReqs) { properties.addAll(productSkuRespVO.getProperties()); @@ -162,18 +163,19 @@ public class ProductSpuServiceImpl implements ProductSpuService { respVO.setProductPropertyViews(productPropertyViews); } // 组合分类 - if (null != respVO.getCategoryId()) { - LinkedList categoryArray = new LinkedList<>(); - Long parentId = respVO.getCategoryId(); - categoryArray.addFirst(parentId); - while (parentId != 0) { - parentId = categoryService.getCategory(parentId).getParentId(); - if (parentId > 0) { - categoryArray.addFirst(parentId); - } - } - respVO.setCategoryIds(categoryArray); - } +// if (null != respVO.getCategoryId()) { +// LinkedList categoryArray = new LinkedList<>(); +// Long parentId = respVO.getCategoryId(); +// categoryArray.addFirst(parentId); +// while (parentId != 0) { +// parentId = categoryService.getCategory(parentId).getParentId(); +// if (parentId > 0) { +// categoryArray.addFirst(parentId); +// } +// } +// +// } + respVO.setCategoryIds(respVO.getCategoryId()); } return respVO; } @@ -190,12 +192,10 @@ public class ProductSpuServiceImpl implements ProductSpuService { @Override public PageResult getSpuPage(ProductSpuPageReqVO pageReqVO) { - List remindSpuIds= null; - // todo @yunai 预警类型的判断应该可以优化,看下怎么处理 - // TODO @luowenfeng: 先这么简单处理; 性能应该影响不大的; - if(pageReqVO.getTabStatus() != null && pageReqVO.getTabStatus() == 2){ - remindSpuIds= productSkuService.getRemindSpuIds(); - if(remindSpuIds.isEmpty()){ + List remindSpuIds = null; + if (pageReqVO.getTabStatus() != null && pageReqVO.getTabStatus() == 2) { + remindSpuIds = productSkuService.getRemindSpuIds().stream().map(ProductSkuDO::getSpuId).distinct().collect(Collectors.toList()); + if (remindSpuIds.isEmpty()) { remindSpuIds.add(null); } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java index 5d79ea77f..6f2556d35 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/order/PayOrderApiImpl.java @@ -1,19 +1,19 @@ -package cn.iocoder.yudao.module.pay.api.order; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * @author LeeYan9 - * @since 2022-09-06 - */ -@Service -public class PayOrderApiImpl implements PayOrderApi { - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createPayOrder(PayOrderInfoCreateReqDTO reqDTO) { - return null; - } - -} +//package cn.iocoder.yudao.module.pay.api.order; +// +//import org.springframework.stereotype.Service; +//import org.springframework.transaction.annotation.Transactional; +// +///** +// * @author LeeYan9 +// * @since 2022-09-06 +// */ +//@Service +//public class PayOrderApiImpl implements PayOrderApi { +// +// @Override +// @Transactional(rollbackFor = Exception.class) +// public Long createPayOrder(PayOrderInfoCreateReqDTO reqDTO) { +// return null; +// } +// +//} diff --git a/yudao-ui-admin/src/views/mall/product/spu/save.vue b/yudao-ui-admin/src/views/mall/product/spu/save.vue index e454da482..ea08de23b 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/save.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/save.vue @@ -39,8 +39,7 @@ - - + @@ -67,7 +66,7 @@ -