product:完善 rpc api 的注解

pull/58/head
YunaiV 2023-10-22 21:43:37 +08:00
parent df7d49a8b1
commit ec49751f25
22 changed files with 173 additions and 469 deletions

View File

@ -1,20 +1,25 @@
package cn.iocoder.yudao.module.product.api.category; package cn.iocoder.yudao.module.product.api.category;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection; import java.util.Collection;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* API @Tag(name = "RPC 服务 - 商品分类")
*
* @author owen
*/
public interface ProductCategoryApi { public interface ProductCategoryApi {
/** String PREFIX = ApiConstants.PREFIX + "/category";
*
* 1. @GetMapping(PREFIX + "/valid")
* 2. @Operation(summary = "校验部门是否合法")
* @Parameter(name = "ids", description = "商品分类编号数组", example = "1,2", required = true)
* @param ids CommonResult<Boolean> validateCategoryList(@RequestParam("ids") Collection<Long> ids);
*/
void validateCategoryList(Collection<Long> ids);
} }

View File

@ -1,20 +1,24 @@
package cn.iocoder.yudao.module.product.api.comment; package cn.iocoder.yudao.module.product.api.comment;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
import cn.iocoder.yudao.module.product.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/** import javax.validation.Valid;
* API
* @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* @author HUIHUI @Tag(name = "RPC 服务 - 产品评论")
*/
public interface ProductCommentApi { public interface ProductCommentApi {
/** String PREFIX = ApiConstants.PREFIX + "/comment";
*
* @PostMapping(PREFIX + "/create")
* @param createReqDTO @Operation(summary = "创建评论")
* @return id CommonResult<Long> createComment(@RequestBody @Valid ProductCommentCreateReqDTO createReqDTO);
*/
Long createComment(ProductCommentCreateReqDTO createReqDTO);
} }

View File

@ -1,59 +1,40 @@
package cn.iocoder.yudao.module.product.api.comment.dto; package cn.iocoder.yudao.module.product.api.comment.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** @Schema(description = "RPC 服务 - 商品评论创建 Request DTO")
* DTO
*
* @author HUIHUI
*/
@Data @Data
public class ProductCommentCreateReqDTO { public class ProductCommentCreateReqDTO {
/** @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
* SKU @NotNull(message = "商品 SKU 编号不能为空")
*/
private Long skuId; private Long skuId;
/** @Schema(description = "订单编号", example = "223")
*
*/
private Long orderId; private Long orderId;
/** @Schema(description = "交易订单项编号", example = "666")
*
*/
private Long orderItemId; private Long orderItemId;
/** @Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
* 1-5 @NotNull(message = "描述星级不能为空")
*/
private Integer scores;
/**
* 1-5
*/
private Integer descriptionScores; private Integer descriptionScores;
/** @Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
* 1-5 @NotNull(message = "服务星级不能为空")
*/
private Integer benefitScores; private Integer benefitScores;
/** @Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "好评")
* @NotNull(message = "评论内容不能为空")
*/
private String content; private String content;
/** @Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", example = "https://www.iocoder.cn/xxx.jpg,http://www.iocoder.cn/yyy.jpg")
* 9
*/
private List<String> picUrls; private List<String> picUrls;
/** @Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
* @NotNull(message = "是否匿名不能为空")
*/
private Boolean anonymous; private Boolean anonymous;
/** @Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "888")
* @NotNull(message = "评价人不能为空")
*/
private Long userId; private Long userId;
} }

View File

@ -1,23 +0,0 @@
package cn.iocoder.yudao.module.product.api.property;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import java.util.Collection;
import java.util.List;
/**
* API
*
* @author
*/
public interface ProductPropertyValueApi {
/**
*
*
* @param ids
* @return
*/
List<ProductPropertyValueDetailRespDTO> getPropertyValueDetailList(Collection<Long> ids);
}

View File

@ -1,33 +1,20 @@
package cn.iocoder.yudao.module.product.api.property.dto; package cn.iocoder.yudao.module.product.api.property.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
/** @Schema(description = "RPC 服务 - 商品属性项的明细 Response DTO")
* Response DTO
*
* @author
*/
@Data @Data
public class ProductPropertyValueDetailRespDTO { public class ProductPropertyValueDetailRespDTO {
/** @Schema(description = "属性的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
*
*/
private Long propertyId; private Long propertyId;
@Schema(description = "属性的名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
/**
*
*/
private String propertyName; private String propertyName;
/** @Schema(description = "属性值的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
*
*/
private Long valueId; private Long valueId;
@Schema(description = "属性值的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "红色")
/**
*
*/
private String valueName; private String valueName;
} }

View File

@ -1,48 +1,45 @@
package cn.iocoder.yudao.module.product.api.sku; package cn.iocoder.yudao.module.product.api.sku;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.product.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.Valid;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* SKU API @Tag(name = "RPC 服务 - 商品 SKU")
*
* @author LeeYan9
* @since 2022-08-26
*/
public interface ProductSkuApi { public interface ProductSkuApi {
/** String PREFIX = ApiConstants.PREFIX + "/sku";
* SKU
*
* @param id SKU
* @return SKU
*/
ProductSkuRespDTO getSku(Long id);
/** @GetMapping(PREFIX + "/get")
* SKU @Operation(summary = "查询 SKU 信息")
* @Parameter(name = "id", description = "SKU 编号", required = true, example = "1024")
* @param ids SKU CommonResult<ProductSkuRespDTO> getSku(@RequestParam("id") Long id);
* @return SKU
*/
List<ProductSkuRespDTO> getSkuList(Collection<Long> ids);
/** @GetMapping(PREFIX + "/list")
* SKU @Operation(summary = "批量查询 SKU 信息")
* @Parameter(name = "ids", description = "SKU 编号列表", required = true, example = "1024,2048")
* @param spuIds SPU CommonResult<List<ProductSkuRespDTO>> getSkuList(@RequestParam("ids") Collection<Long> ids);
* @return SKU
*/
List<ProductSkuRespDTO> getSkuListBySpuId(Collection<Long> spuIds);
/** @GetMapping(PREFIX + "/list-by-spu-id")
* SKU or @Operation(summary = "批量查询 SKU 信息")
* @Parameter(name = "spuIds", description = "SPU 编号列表", required = true, example = "1024,2048")
* @param updateStockReqDTO CommonResult<List<ProductSkuRespDTO>> getSkuListBySpuId(@RequestParam("spuIds") Collection<Long> spuIds);
*/
void updateSkuStock(ProductSkuUpdateStockReqDTO updateStockReqDTO); @PostMapping(PREFIX + "/update-stock")
@Operation(summary = "更新 SKU 库存(增加 or 减少)")
CommonResult<Boolean> updateSkuStock(@RequestBody @Valid ProductSkuUpdateStockReqDTO updateStockReqDTO);
} }

View File

@ -1,71 +1,44 @@
package cn.iocoder.yudao.module.product.api.sku.dto; package cn.iocoder.yudao.module.product.api.sku.dto;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
/** @Schema(description = "RPC 服务 - 商品 SKU 信息 Response DTO")
* SKU Response DTO
*
* @author LeeYan9
* @since 2022-08-26
*/
@Data @Data
public class ProductSkuRespDTO { public class ProductSkuRespDTO {
/** @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
* SKU
*/
private Long id; private Long id;
/** @Schema(description = "SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
* SPU
*/
private Long spuId; private Long spuId;
/** @Schema(description = "属性数组", requiredMode = Schema.RequiredMode.REQUIRED)
*
*/
private List<ProductPropertyValueDetailRespDTO> properties; private List<ProductPropertyValueDetailRespDTO> properties;
/**
* @Schema(description = "销售价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
*/
private Integer price; private Integer price;
/** @Schema(description = "市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
*
*/
private Integer marketPrice; private Integer marketPrice;
/** @Schema(description = "成本价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "300")
*
*/
private Integer costPrice; private Integer costPrice;
/** @Schema(description = "SKU 的条形码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456789")
* SKU
*/
private String barCode; private String barCode;
/** @Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.jpg")
*
*/
private String picUrl; private String picUrl;
/**
* @Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
*/
private Integer stock; private Integer stock;
/** @Schema(description = "商品重量单位kg 千克", requiredMode = Schema.RequiredMode.REQUIRED, example = "1.5")
* kg
*/
private Double weight; private Double weight;
/** @Schema(description = "商品体积单位m^3 平米", requiredMode = Schema.RequiredMode.REQUIRED, example = "3.0")
* m^3
*/
private Double volume; private Double volume;
/**
* @Schema(description = "一级分销的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "550")
*/
private Integer firstBrokeragePrice; private Integer firstBrokeragePrice;
/** @Schema(description = "二级分销的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "250")
*
*/
private Integer secondBrokeragePrice; private Integer secondBrokeragePrice;
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.api.sku.dto; package cn.iocoder.yudao.module.product.api.sku.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -7,40 +8,26 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** @Schema(description = "RPC 服务 - 商品 SKU 更新库存 Request DTO")
* SKU Request DTO
*
* @author LeeYan9
* @since 2022-08-26
*/
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ProductSkuUpdateStockReqDTO { public class ProductSkuUpdateStockReqDTO {
/** @Schema(description = "商品 SKU 数组", requiredMode = Schema.RequiredMode.REQUIRED)
* SKU
*/
@NotNull(message = "商品 SKU 不能为空") @NotNull(message = "商品 SKU 不能为空")
private List<Item> items; private List<Item> items;
@Data @Data
public static class Item { public static class Item {
/** @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
* SKU
*/
@NotNull(message = "商品 SKU 编号不能为空") @NotNull(message = "商品 SKU 编号不能为空")
private Long id; private Long id;
/** @Schema(description = "库存变化数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
*
*
*
*
*/
@NotNull(message = "库存变化数量不能为空") @NotNull(message = "库存变化数量不能为空")
private Integer incrCount; private Integer incrCount; // 正数:增加库存;负数:扣减库存
} }

View File

@ -1,43 +1,37 @@
package cn.iocoder.yudao.module.product.api.spu; package cn.iocoder.yudao.module.product.api.spu;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.product.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
/** @FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
* SPU API @Tag(name = "RPC 服务 - 商品 SPU")
*
* @author LeeYan9
* @since 2022-08-26
*/
public interface ProductSpuApi { public interface ProductSpuApi {
/** String PREFIX = ApiConstants.PREFIX + "/spu";
* SPU
*
* @param ids SPU
* @return SPU
*/
List<ProductSpuRespDTO> getSpuList(Collection<Long> ids);
/** @GetMapping(PREFIX + "/list")
* SPU SPU @Schema(description = "批量查询 SPU 数组")
* @Parameter(name = "ids", description = "SPU 编号列表", required = true, example = "1,3,5")
* CommonResult<List<ProductSpuRespDTO>> getSpuList(@RequestParam("ids") Collection<Long> ids);
* 1.
* 2.
*
* @param ids SPU
* @return SPU
*/
List<ProductSpuRespDTO> validateSpuList(Collection<Long> ids);
/** @GetMapping(PREFIX + "/valid")
* SPU @Schema(description = "批量查询 SPU 数组,并且校验是否 SPU 是否有效")
* @Parameter(name = "ids", description = "SPU 编号列表", required = true, example = "1,3,5")
* @return SPU CommonResult<List<ProductSpuRespDTO>> validateSpuList(@RequestParam("ids") Collection<Long> ids);
*/
ProductSpuRespDTO getSpu(Long id); @GetMapping(PREFIX + "/get")
@Schema(description = "获得 SPU")
@Parameter(name = "id", description = "SPU 编号", required = true, example = "1")
CommonResult<ProductSpuRespDTO> getSpu(@RequestParam("id") Long id);
} }

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.api.spu.dto;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import lombok.Data; import lombok.Data;
import java.util.List; // TODO @LeeYan9: ProductSpuRespDTO
/** /**
* SPU Response DTO * SPU Response DTO
@ -25,55 +25,22 @@ public class ProductSpuRespDTO {
* *
*/ */
private String name; private String name;
/**
*
*/
private String keyword;
/** /**
* *
* *
* product_unit * product_unit
*/ */
private Integer unit; private Integer unit;
/**
*
*/
private String introduction;
/**
*
*/
private String description;
// TODO @芋艿:是不是要删除
/**
*
*/
private String barCode;
/** /**
* *
*/ */
private Long categoryId; private Long categoryId;
/**
*
*/
private Long brandId;
/** /**
* *
*/ */
private String picUrl; private String picUrl;
/**
*
*/
private List<String> sliderPicUrls;
/**
*
*/
private String videoUrl;
/**
*
*/
private Integer sort;
/** /**
* *
* <p> * <p>
@ -123,22 +90,6 @@ public class ProductSpuRespDTO {
*/ */
private Integer giveIntegral; private Integer giveIntegral;
// ========== 统计相关字段 =========
/**
*
*/
private Integer salesCount;
/**
*
*/
private Integer virtualSalesCount;
/**
*
*/
private Integer clickCount;
// ========== 分销相关字段 ========= // ========== 分销相关字段 =========
/** /**

View File

@ -1,38 +0,0 @@
package cn.iocoder.yudao.module.product.enums.group;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
*
*
* @author
*/
@Getter
@AllArgsConstructor
public enum ProductGroupStyleEnum implements IntArrayValuable {
ONE(1, "每列一个"),
TWO(2, "每列两个"),
THREE(2, "每列三个"),;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductGroupStyleEnum::getStyle).toArray();
/**
*
*/
private final Integer style;
/**
*
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.api.category; package cn.iocoder.yudao.module.product.api.category;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -7,6 +8,8 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/** /**
* API * API
* *
@ -20,8 +23,9 @@ public class ProductCategoryApiImpl implements ProductCategoryApi {
private ProductCategoryService productCategoryService; private ProductCategoryService productCategoryService;
@Override @Override
public void validateCategoryList(Collection<Long> ids) { public CommonResult<Boolean> validateCategoryList(Collection<Long> ids) {
productCategoryService.validateCategoryList(ids); productCategoryService.validateCategoryList(ids);
return success(true);
} }
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.product.api.comment; package cn.iocoder.yudao.module.product.api.comment;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -7,6 +8,8 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/** /**
* API * API
* *
@ -20,8 +23,8 @@ public class ProductCommentApiImpl implements ProductCommentApi {
private ProductCommentService productCommentService; private ProductCommentService productCommentService;
@Override @Override
public Long createComment(ProductCommentCreateReqDTO createReqDTO) { public CommonResult<Long> createComment(ProductCommentCreateReqDTO createReqDTO) {
return productCommentService.createComment(createReqDTO); return success(productCommentService.createComment(createReqDTO));
} }
} }

View File

@ -1,31 +0,0 @@
package cn.iocoder.yudao.module.product.api.property;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
/**
* API
*
* @author
*/
@Service
@Validated
public class ProductPropertyValueApiImpl implements ProductPropertyValueApi {
@Resource
private ProductPropertyValueService productPropertyValueService;
@Override
public List<ProductPropertyValueDetailRespDTO> getPropertyValueDetailList(Collection<Long> ids) {
return ProductPropertyValueConvert.INSTANCE.convertList02(
productPropertyValueService.getPropertyValueDetailList(ids));
}
}

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.product.api.sku; package cn.iocoder.yudao.module.product.api.sku;
import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
@ -11,9 +11,10 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/** /**
* SKU API * SKU API
* *
@ -28,32 +29,27 @@ public class ProductSkuApiImpl implements ProductSkuApi {
private ProductSkuService productSkuService; private ProductSkuService productSkuService;
@Override @Override
public ProductSkuRespDTO getSku(Long id) { public CommonResult<ProductSkuRespDTO> getSku(Long id) {
ProductSkuDO sku = productSkuService.getSku(id); ProductSkuDO sku = productSkuService.getSku(id);
return ProductSkuConvert.INSTANCE.convert02(sku); return success(ProductSkuConvert.INSTANCE.convert02(sku));
} }
@Override @Override
public List<ProductSkuRespDTO> getSkuList(Collection<Long> ids) { public CommonResult<List<ProductSkuRespDTO>> getSkuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
List<ProductSkuDO> skus = productSkuService.getSkuList(ids); List<ProductSkuDO> skus = productSkuService.getSkuList(ids);
return ProductSkuConvert.INSTANCE.convertList04(skus); return success(ProductSkuConvert.INSTANCE.convertList04(skus));
} }
@Override @Override
public List<ProductSkuRespDTO> getSkuListBySpuId(Collection<Long> spuIds) { public CommonResult<List<ProductSkuRespDTO>> getSkuListBySpuId(Collection<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return Collections.emptyList();
}
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spuIds); List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spuIds);
return ProductSkuConvert.INSTANCE.convertList04(skus); return success(ProductSkuConvert.INSTANCE.convertList04(skus));
} }
@Override @Override
public void updateSkuStock(ProductSkuUpdateStockReqDTO updateStockReqDTO) { public CommonResult<Boolean> updateSkuStock(ProductSkuUpdateStockReqDTO updateStockReqDTO) {
productSkuService.updateSkuStock(updateStockReqDTO); productSkuService.updateSkuStock(updateStockReqDTO);
return success(true);
} }
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.product.api.spu; package cn.iocoder.yudao.module.product.api.spu;
import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
@ -9,9 +9,10 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/** /**
* SPU API * SPU API
* *
@ -26,21 +27,18 @@ public class ProductSpuApiImpl implements ProductSpuApi {
private ProductSpuService spuService; private ProductSpuService spuService;
@Override @Override
public List<ProductSpuRespDTO> getSpuList(Collection<Long> ids) { public CommonResult<List<ProductSpuRespDTO>> getSpuList(Collection<Long> ids) {
if (CollectionUtil.isEmpty(ids)) { return success(ProductSpuConvert.INSTANCE.convertList2(spuService.getSpuList(ids)));
return Collections.emptyList();
}
return ProductSpuConvert.INSTANCE.convertList2(spuService.getSpuList(ids));
} }
@Override @Override
public List<ProductSpuRespDTO> validateSpuList(Collection<Long> ids) { public CommonResult<List<ProductSpuRespDTO>> validateSpuList(Collection<Long> ids) {
return ProductSpuConvert.INSTANCE.convertList2(spuService.validateSpuList(ids)); return success(ProductSpuConvert.INSTANCE.convertList2(spuService.validateSpuList(ids)));
} }
@Override @Override
public ProductSpuRespDTO getSpu(Long id) { public CommonResult<ProductSpuRespDTO> getSpu(Long id) {
return ProductSpuConvert.INSTANCE.convert02(spuService.getSpu(id)); return success(ProductSpuConvert.INSTANCE.convert02(spuService.getSpu(id)));
} }
} }

View File

@ -1,22 +1,14 @@
package cn.iocoder.yudao.module.product.convert.property; package cn.iocoder.yudao.module.product.convert.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; 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.controller.admin.property.vo.value.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/** /**
* Convert * Convert
@ -38,18 +30,4 @@ public interface ProductPropertyValueConvert {
PageResult<ProductPropertyValueRespVO> convertPage(PageResult<ProductPropertyValueDO> page); PageResult<ProductPropertyValueRespVO> convertPage(PageResult<ProductPropertyValueDO> page);
default List<ProductPropertyValueDetailRespBO> convertList(List<ProductPropertyValueDO> values, List<ProductPropertyDO> keys) {
Map<Long, ProductPropertyDO> keyMap = convertMap(keys, ProductPropertyDO::getId);
return CollectionUtils.convertList(values, value -> {
ProductPropertyValueDetailRespBO valueDetail = new ProductPropertyValueDetailRespBO()
.setValueId(value.getId()).setValueName(value.getName());
// 设置属性项
MapUtils.findAndThen(keyMap, value.getPropertyId(),
key -> valueDetail.setPropertyId(key.getId()).setPropertyName(key.getName()));
return valueDetail;
});
}
List<ProductPropertyValueDetailRespDTO> convertList02(List<ProductPropertyValueDetailRespBO> list);
} }

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -56,14 +55,6 @@ public interface ProductPropertyValueService {
*/ */
List<ProductPropertyValueDO> getPropertyValueListByPropertyId(Collection<Long> propertyIds); List<ProductPropertyValueDO> getPropertyValueListByPropertyId(Collection<Long> propertyIds);
/**
*
*
* @param ids
* @return
*/
List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids);
/** /**
* *
* *

View File

@ -1,15 +1,12 @@
package cn.iocoder.yudao.module.product.service.property; package cn.iocoder.yudao.module.product.service.property;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper; import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -17,11 +14,9 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS;
@ -37,10 +32,6 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
@Resource @Resource
private ProductPropertyValueMapper productPropertyValueMapper; private ProductPropertyValueMapper productPropertyValueMapper;
@Resource
@Lazy // 延迟加载,避免循环依赖
private ProductPropertyService productPropertyService;
@Resource @Resource
@Lazy // 延迟加载,避免循环依赖 @Lazy // 延迟加载,避免循环依赖
private ProductSkuService productSkuService; private ProductSkuService productSkuService;
@ -99,23 +90,6 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
return productPropertyValueMapper.selectListByPropertyId(propertyIds); return productPropertyValueMapper.selectListByPropertyId(propertyIds);
} }
@Override
public List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids) {
// 获得属性值列表
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
List<ProductPropertyValueDO> values = productPropertyValueMapper.selectBatchIds(ids);
if (CollUtil.isEmpty(values)) {
return Collections.emptyList();
}
// 获得属性项列表
List<ProductPropertyDO> keys = productPropertyService.getPropertyList(
convertSet(values, ProductPropertyValueDO::getPropertyId));
// 组装明细
return ProductPropertyValueConvert.INSTANCE.convertList(values, keys);
}
@Override @Override
public Integer getPropertyValueCountByPropertyId(Long propertyId) { public Integer getPropertyValueCountByPropertyId(Long propertyId) {
return productPropertyValueMapper.selectCountByPropertyId(propertyId); return productPropertyValueMapper.selectCountByPropertyId(propertyId);

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.product.service.property.bo;
import lombok.Data;
/**
* Response BO
*
* @author
*/
@Data
public class ProductPropertyValueDetailRespBO {
/**
*
*/
private Long propertyId;
/**
*
*/
private String propertyName;
/**
*
*/
private Long valueId;
/**
*
*/
private String valueName;
}

View File

@ -153,6 +153,9 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override @Override
public List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds) { public List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return Collections.emptyList();
}
return productSkuMapper.selectListBySpuId(spuIds); return productSkuMapper.selectListBySpuId(spuIds);
} }

View File

@ -213,6 +213,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Override @Override
public List<ProductSpuDO> getSpuList(Collection<Long> ids) { public List<ProductSpuDO> getSpuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return productSpuMapper.selectBatchIds(ids); return productSpuMapper.selectBatchIds(ids);
} }