product:初始化代码

This commit is contained in:
YunaiV
2023-10-22 17:01:10 +08:00
parent 6a51097e1d
commit 6653c074fa
164 changed files with 10026 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.product;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 项目的启动类
*
* 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
* 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
* 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
*
* @author 芋道源码
*/
@SpringBootApplication
public class ProductServerApplication {
public static void main(String[] args) {
// 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
// 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
// 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
SpringApplication.run(ProductServerApplication.class, args);
// 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
// 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
// 如果你碰到启动的问题,请认真阅读 https://cloud.iocoder.cn/quick-start/ 文章
}
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.product.api.category;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
/**
* 商品分类 API 接口实现类
*
* @author owen
*/
@Service
@Validated
public class ProductCategoryApiImpl implements ProductCategoryApi {
@Resource
private ProductCategoryService productCategoryService;
@Override
public void validateCategoryList(Collection<Long> ids) {
productCategoryService.validateCategoryList(ids);
}
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.product.api.comment;
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
/**
* 商品评论 API 实现类
*
* @author HUIHUI
*/
@Service
@Validated
public class ProductCommentApiImpl implements ProductCommentApi {
@Resource
private ProductCommentService productCommentService;
@Override
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
return productCommentService.createComment(createReqDTO);
}
}

View File

@@ -0,0 +1 @@
package cn.iocoder.yudao.module.product.api;

View File

@@ -0,0 +1,31 @@
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

@@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.product.api.sku;
import cn.hutool.core.collection.CollUtil;
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.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* 商品 SKU API 实现类
*
* @author LeeYan9
* @since 2022-09-06
*/
@Service
@Validated
public class ProductSkuApiImpl implements ProductSkuApi {
@Resource
private ProductSkuService productSkuService;
@Override
public ProductSkuRespDTO getSku(Long id) {
ProductSkuDO sku = productSkuService.getSku(id);
return ProductSkuConvert.INSTANCE.convert02(sku);
}
@Override
public List<ProductSkuRespDTO> getSkuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
List<ProductSkuDO> skus = productSkuService.getSkuList(ids);
return ProductSkuConvert.INSTANCE.convertList04(skus);
}
@Override
public List<ProductSkuRespDTO> getSkuListBySpuId(Collection<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return Collections.emptyList();
}
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spuIds);
return ProductSkuConvert.INSTANCE.convertList04(skus);
}
@Override
public void updateSkuStock(ProductSkuUpdateStockReqDTO updateStockReqDTO) {
productSkuService.updateSkuStock(updateStockReqDTO);
}
}

View File

@@ -0,0 +1,46 @@
package cn.iocoder.yudao.module.product.api.spu;
import cn.hutool.core.collection.CollectionUtil;
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.service.spu.ProductSpuService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* 商品 SPU API 接口实现类
*
* @author LeeYan9
* @since 2022-09-06
*/
@Service
@Validated
public class ProductSpuApiImpl implements ProductSpuApi {
@Resource
private ProductSpuService spuService;
@Override
public List<ProductSpuRespDTO> getSpuList(Collection<Long> ids) {
if (CollectionUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return ProductSpuConvert.INSTANCE.convertList2(spuService.getSpuList(ids));
}
@Override
public List<ProductSpuRespDTO> validateSpuList(Collection<Long> ids) {
return ProductSpuConvert.INSTANCE.convertList2(spuService.validateSpuList(ids));
}
@Override
public ProductSpuRespDTO getSpu(Long id) {
return ProductSpuConvert.INSTANCE.convert02(spuService.getSpu(id));
}
}

View File

@@ -0,0 +1,92 @@
package cn.iocoder.yudao.module.product.controller.admin.brand;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*;
import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Comparator;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 商品品牌")
@RestController
@RequestMapping("/product/brand")
@Validated
public class ProductBrandController {
@Resource
private ProductBrandService brandService;
@PostMapping("/create")
@Operation(summary = "创建品牌")
@PreAuthorize("@ss.hasPermission('product:brand:create')")
public CommonResult<Long> createBrand(@Valid @RequestBody ProductBrandCreateReqVO createReqVO) {
return success(brandService.createBrand(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新品牌")
@PreAuthorize("@ss.hasPermission('product:brand:update')")
public CommonResult<Boolean> updateBrand(@Valid @RequestBody ProductBrandUpdateReqVO updateReqVO) {
brandService.updateBrand(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除品牌")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:brand:delete')")
public CommonResult<Boolean> deleteBrand(@RequestParam("id") Long id) {
brandService.deleteBrand(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得品牌")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:brand:query')")
public CommonResult<ProductBrandRespVO> getBrand(@RequestParam("id") Long id) {
ProductBrandDO brand = brandService.getBrand(id);
return success(ProductBrandConvert.INSTANCE.convert(brand));
}
@GetMapping("/list-all-simple")
@Operation(summary = "获取品牌精简信息列表", description = "主要用于前端的下拉选项")
public CommonResult<List<ProductBrandSimpleRespVO>> getSimpleBrandList() {
// 获取品牌列表,只要开启状态的
List<ProductBrandDO> list = brandService.getBrandListByStatus(CommonStatusEnum.ENABLE.getStatus());
// 排序后,返回给前端
return success(ProductBrandConvert.INSTANCE.convertList1(list));
}
@GetMapping("/page")
@Operation(summary = "获得品牌分页")
@PreAuthorize("@ss.hasPermission('product:brand:query')")
public CommonResult<PageResult<ProductBrandRespVO>> getBrandPage(@Valid ProductBrandPageReqVO pageVO) {
PageResult<ProductBrandDO> pageResult = brandService.getBrandPage(pageVO);
return success(ProductBrandConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/list")
@Operation(summary = "获得品牌列表")
@PreAuthorize("@ss.hasPermission('product:brand:query')")
public CommonResult<List<ProductBrandRespVO>> getBrandList(@Valid ProductBrandListReqVO listVO) {
List<ProductBrandDO> list = brandService.getBrandList(listVO);
list.sort(Comparator.comparing(ProductBrandDO::getSort));
return success(ProductBrandConvert.INSTANCE.convertList(list));
}
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 商品品牌 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class ProductBrandBaseVO {
@Schema(description = "品牌名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "苹果")
@NotNull(message = "品牌名称不能为空")
private String name;
@Schema(description = "品牌图片", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "品牌图片不能为空")
private String picUrl;
@Schema(description = "品牌排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "品牌排序不能为空")
private Integer sort;
@Schema(description = "品牌描述", example = "描述")
private String description;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@NotNull(message = "状态不能为空")
private Integer status;
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 商品品牌创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductBrandCreateReqVO extends ProductBrandBaseVO {
}

View File

@@ -0,0 +1,13 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 商品品牌分页 Request VO")
@Data
public class ProductBrandListReqVO {
@Schema(description = "品牌名称", example = "苹果")
private String name;
}

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 商品品牌分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductBrandPageReqVO extends PageParam {
@Schema(description = "品牌名称", example = "苹果")
private String name;
@Schema(description = "状态", example = "0")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Schema(description = "创建时间")
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 品牌 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductBrandRespVO extends ProductBrandBaseVO {
@Schema(description = "品牌编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Schema(description = "管理后台 - 品牌精简信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductBrandSimpleRespVO {
@Schema(description = "品牌编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "品牌名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "苹果")
private String name;
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.product.controller.admin.brand.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品品牌更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductBrandUpdateReqVO extends ProductBrandBaseVO {
@Schema(description = "品牌编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "品牌编号不能为空")
private Long id;
}

View File

@@ -0,0 +1,76 @@
package cn.iocoder.yudao.module.product.controller.admin.category;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Comparator;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 商品分类")
@RestController
@RequestMapping("/product/category")
@Validated
public class ProductCategoryController {
@Resource
private ProductCategoryService categoryService;
@PostMapping("/create")
@Operation(summary = "创建商品分类")
@PreAuthorize("@ss.hasPermission('product:category:create')")
public CommonResult<Long> createCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) {
return success(categoryService.createCategory(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新商品分类")
@PreAuthorize("@ss.hasPermission('product:category:update')")
public CommonResult<Boolean> updateCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) {
categoryService.updateCategory(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除商品分类")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('product:category:delete')")
public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) {
categoryService.deleteCategory(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得商品分类")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:category:query')")
public CommonResult<ProductCategoryRespVO> getCategory(@RequestParam("id") Long id) {
ProductCategoryDO category = categoryService.getCategory(id);
return success(ProductCategoryConvert.INSTANCE.convert(category));
}
@GetMapping("/list")
@Operation(summary = "获得商品分类列表")
@PreAuthorize("@ss.hasPermission('product:category:query')")
public CommonResult<List<ProductCategoryRespVO>> getCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) {
List<ProductCategoryDO> list = categoryService.getEnableCategoryList(treeListReqVO);
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(ProductCategoryConvert.INSTANCE.convertList(list));
}
}

View File

@@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.product.controller.admin.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 商品分类 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class ProductCategoryBaseVO {
@Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "父分类编号不能为空")
private Long parentId;
@Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "办公文具")
@NotBlank(message = "分类名称不能为空")
private String name;
@Schema(description = "移动端分类图", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "移动端分类图不能为空")
private String picUrl;
@Schema(description = "PC 端分类图")
private String bigPicUrl;
@Schema(description = "分类排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer sort;
@Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
@NotNull(message = "开启状态不能为空")
private Integer status;
}

View File

@@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.product.controller.admin.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotBlank;
@Schema(description = "管理后台 - 商品分类创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductCategoryCreateReqVO extends ProductCategoryBaseVO {
@Schema(description = "分类描述", example = "描述")
private String description;
}

View File

@@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.product.controller.admin.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 商品分类列表查询 Request VO")
@Data
public class ProductCategoryListReqVO {
@Schema(description = "分类名称", example = "办公文具")
private String name;
@Schema(description = "开启状态", example = "0")
private Integer status;
@Schema(description = "父分类编号", example = "1")
private Long parentId;
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 商品分类 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductCategoryRespVO extends ProductCategoryBaseVO {
@Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.product.controller.admin.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品分类更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductCategoryUpdateReqVO extends ProductCategoryBaseVO {
@Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "分类编号不能为空")
private Long id;
@Schema(description = "分类描述", example = "描述")
private String description;
}

View File

@@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.product.controller.admin.comment;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*;
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 商品评价")
@RestController
@RequestMapping("/product/comment")
@Validated
public class ProductCommentController {
@Resource
private ProductCommentService productCommentService;
@GetMapping("/page")
@Operation(summary = "获得商品评价分页")
@PreAuthorize("@ss.hasPermission('product:comment:query')")
public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) {
PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO);
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
}
@PutMapping("/update-visible")
@Operation(summary = "显示 / 隐藏评论")
@PreAuthorize("@ss.hasPermission('product:comment:update')")
public CommonResult<Boolean> updateCommentVisible(@Valid @RequestBody ProductCommentUpdateVisibleReqVO updateReqVO) {
productCommentService.updateCommentVisible(updateReqVO);
return success(true);
}
@PutMapping("/reply")
@Operation(summary = "商家回复")
@PreAuthorize("@ss.hasPermission('product:comment:update')")
public CommonResult<Boolean> commentReply(@Valid @RequestBody ProductCommentReplyReqVO replyVO) {
productCommentService.replyComment(replyVO, getLoginUserId());
return success(true);
}
@PostMapping("/create")
@Operation(summary = "添加自评")
@PreAuthorize("@ss.hasPermission('product:comment:update')")
public CommonResult<Boolean> createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) {
productCommentService.createComment(createReqVO);
return success(true);
}
}

View File

@@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
@Data
public class ProductCommentBaseVO {
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
private Long userId;
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
private Long orderItemId;
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
@NotNull(message = "评价人名称不能为空")
private String userNickname;
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
@NotNull(message = "评价人头像不能为空")
private String userAvatar;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品 SKU 编号不能为空")
private Long skuId;
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "描述星级不能为空")
private Integer descriptionScores;
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "服务星级分不能为空")
private Integer benefitScores;
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
@NotNull(message = "评论内容不能为空")
private String content;
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
private List<String> picUrls;
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 商品评价创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductCommentCreateReqVO extends ProductCommentBaseVO {
}

View File

@@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 商品评价分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductCommentPageReqVO extends PageParam {
@Schema(description = "评价人名称", example = "王二狗")
private String userNickname;
@Schema(description = "交易订单编号", example = "24428")
private Long orderId;
@Schema(description = "商品SPU编号", example = "29502")
private Long spuId;
@Schema(description = "商品SPU名称", example = "感冒药")
private String spuName;
@Schema(description = "评分星级 1-5 分", example = "5")
@InEnum(ProductCommentScoresEnum.class)
private Integer scores;
@Schema(description = "商家是否回复", example = "true")
private Boolean replyStatus;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品评价的商家回复 Request VO")
@Data
@ToString(callSuper = true)
public class ProductCommentReplyReqVO {
@Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
@NotNull(message = "评价编号不能为空")
private Long id;
@Schema(description = "商家回复内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "谢谢亲")
@NotEmpty(message = "商家回复内容不能为空")
private String replyContent;
}

View File

@@ -0,0 +1,63 @@
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 商品评价 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductCommentRespVO extends ProductCommentBaseVO {
@Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
private Long id;
@Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
private Boolean anonymous;
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
private Long orderId;
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean visible;
@Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean replyStatus;
@Schema(description = "回复管理员编号", example = "9527")
private Long replyUserId;
@Schema(description = "商家回复内容", example = "感谢好评哦亲(づ ̄3 ̄)づ╭❤~")
private String replyContent;
@Schema(description = "商家回复时间", example = "2023-08-08 12:20:55")
private LocalDateTime replyTime;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
private Integer scores;
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
@NotNull(message = "商品 SPU 编号不能为空")
private Long spuId;
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
@NotNull(message = "商品 SPU 名称不能为空")
private String spuName;
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
private String skuPicUrl;
@Schema(description = "商品 SKU 规格值数组")
private List<ProductSkuBaseVO.Property> skuProperties;
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品评价可见修改 Request VO")
@Data
@ToString(callSuper = true)
public class ProductCommentUpdateVisibleReqVO {
@Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
@NotNull(message = "评价编号不能为空")
private Long id;
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
@NotNull(message = "是否可见不能为空")
private Boolean visible;
}

View File

@@ -0,0 +1,100 @@
package cn.iocoder.yudao.module.product.controller.admin.property;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
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.service.property.ProductPropertyService;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "管理后台 - 商品属性项")
@RestController
@RequestMapping("/product/property")
@Validated
public class ProductPropertyController {
@Resource
private ProductPropertyService productPropertyService;
@Resource
private ProductPropertyValueService productPropertyValueService;
@PostMapping("/create")
@Operation(summary = "创建属性项")
@PreAuthorize("@ss.hasPermission('product:property:create')")
public CommonResult<Long> createProperty(@Valid @RequestBody ProductPropertyCreateReqVO createReqVO) {
return success(productPropertyService.createProperty(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新属性项")
@PreAuthorize("@ss.hasPermission('product:property:update')")
public CommonResult<Boolean> updateProperty(@Valid @RequestBody ProductPropertyUpdateReqVO updateReqVO) {
productPropertyService.updateProperty(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除属性项")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('product:property:delete')")
public CommonResult<Boolean> deleteProperty(@RequestParam("id") Long id) {
productPropertyService.deleteProperty(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得属性项")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) {
return success(ProductPropertyConvert.INSTANCE.convert(productPropertyService.getProperty(id)));
}
@GetMapping("/list")
@Operation(summary = "获得属性项列表")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<List<ProductPropertyRespVO>> getPropertyList(@Valid ProductPropertyListReqVO listReqVO) {
return success(ProductPropertyConvert.INSTANCE.convertList(productPropertyService.getPropertyList(listReqVO)));
}
@GetMapping("/page")
@Operation(summary = "获得属性项分页")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) {
return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO)));
}
@PostMapping("/get-value-list")
@Operation(summary = "获得属性项列表")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<List<ProductPropertyAndValueRespVO>> getPropertyAndValueList(
@Valid @RequestBody ProductPropertyListReqVO listReqVO) {
// 查询属性项
List<ProductPropertyDO> keys = productPropertyService.getPropertyList(listReqVO);
if (CollUtil.isEmpty(keys)) {
return success(Collections.emptyList());
}
// 查询属性值
List<ProductPropertyValueDO> values = productPropertyValueService.getPropertyValueListByPropertyId(
convertSet(keys, ProductPropertyDO::getId));
return success(ProductPropertyConvert.INSTANCE.convertList(keys, values));
}
}

View File

@@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.product.controller.admin.property;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
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.ProductPropertyValuePageReqVO;
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.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 商品属性值")
@RestController
@RequestMapping("/product/property/value")
@Validated
public class ProductPropertyValueController {
@Resource
private ProductPropertyValueService productPropertyValueService;
@PostMapping("/create")
@Operation(summary = "创建属性值")
@PreAuthorize("@ss.hasPermission('product:property:create')")
public CommonResult<Long> createPropertyValue(@Valid @RequestBody ProductPropertyValueCreateReqVO createReqVO) {
return success(productPropertyValueService.createPropertyValue(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新属性值")
@PreAuthorize("@ss.hasPermission('product:property:update')")
public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody ProductPropertyValueUpdateReqVO updateReqVO) {
productPropertyValueService.updatePropertyValue(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除属性值")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:property:delete')")
public CommonResult<Boolean> deletePropertyValue(@RequestParam("id") Long id) {
productPropertyValueService.deletePropertyValue(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得属性值")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<ProductPropertyValueRespVO> getPropertyValue(@RequestParam("id") Long id) {
return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id)));
}
@GetMapping("/page")
@Operation(summary = "获得属性值分页")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<PageResult<ProductPropertyValueRespVO>> getPropertyValuePage(@Valid ProductPropertyValuePageReqVO pageVO) {
return success(ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueService.getPropertyValuePage(pageVO)));
}
}

View File

@@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 商品属性项 + 属性值 Response VO")
@Data
public class ProductPropertyAndValueRespVO {
@Schema(description = "属性项的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "属性项的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
private String name;
/**
* 属性值的集合
*/
private List<Value> values;
@Schema(description = "管理后台 - 属性值的简单 Response VO")
@Data
public static class Value {
@Schema(description = "属性值的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long id;
@Schema(description = "属性值的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "红色")
private String name;
}
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 商品属性项 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class ProductPropertyBaseVO {
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
@NotBlank(message = "名称不能为空")
private String name;
@Schema(description = "备注", example = "颜色")
private String remark;
}

View File

@@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 属性项创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO {
}

View File

@@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import java.util.List;
@Schema(description = "管理后台 - 属性项 List Request VO")
@Data
@ToString(callSuper = true)
public class ProductPropertyListReqVO {
@Schema(description = "属性名称", example = "颜色")
private String name;
}

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 属性项 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyPageReqVO extends PageParam {
@Schema(description = "名称", example = "颜色")
private String name;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@Schema(description = "创建时间")
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 属性项 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyRespVO extends ProductPropertyBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 属性项更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyUpdateReqVO extends ProductPropertyBaseVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "主键不能为空")
private Long id;
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 属性值 Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class ProductPropertyValueBaseVO {
@Schema(description = "属性项的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "属性项的编号不能为空")
private Long propertyId;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "红色")
@NotEmpty(message = "名称名字不能为空")
private String name;
@Schema(description = "备注", example = "颜色")
private String remark;
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 商品属性值创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValueCreateReqVO extends ProductPropertyValueBaseVO {
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 商品属性值的明细 Response VO")
@Data
public class ProductPropertyValueDetailRespVO {
@Schema(description = "属性的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long propertyId;
@Schema(description = "属性的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
private String propertyName;
@Schema(description = "属性值的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long valueId;
@Schema(description = "属性值的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "红色")
private String valueName;
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 商品属性值分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValuePageReqVO extends PageParam {
@Schema(description = "属性项的编号", example = "1024")
private String propertyId;
@Schema(description = "名称", example = "红色")
private String name;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
}

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 商品属性值 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValueRespVO extends ProductPropertyValueBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Long id;
@Schema(description = "创建时间")
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品属性值更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValueUpdateReqVO extends ProductPropertyValueBaseVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "主键不能为空")
private Long id;
}

View File

@@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.product.controller.admin.sku;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "管理后台 - 商品 SKU")
@RestController
@RequestMapping("/product/sku")
@Validated
public class ProductSkuController {
}

View File

@@ -0,0 +1,82 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 商品 SKU Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*/
@Data
public class ProductSkuBaseVO {
@Schema(description = "商品 SKU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖")
@NotEmpty(message = "商品 SKU 名字不能为空")
private String name;
@Schema(description = "销售价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1999")
@NotNull(message = "销售价格,单位:分不能为空")
private Integer price;
@Schema(description = "市场价", example = "2999")
private Integer marketPrice;
@Schema(description = "成本价", example = "19")
private Integer costPrice;
@Schema(description = "条形码", example = "15156165456")
private String barCode;
@Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
@NotNull(message = "图片地址不能为空")
private String picUrl;
@Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
@NotNull(message = "库存不能为空")
private Integer stock;
@Schema(description = "预警预存", example = "10")
private Integer warnStock;
@Schema(description = "商品重量,单位kg 千克", example = "1.2")
private Double weight;
@Schema(description = "商品体积,单位m^3 平米", example = "2.5")
private Double volume;
@Schema(description = "一级分销的佣金,单位:分", example = "199")
private Integer firstBrokeragePrice;
@Schema(description = "二级分销的佣金,单位:分", example = "19")
private Integer secondBrokeragePrice;
@Schema(description = "属性数组")
private List<Property> properties;
@Schema(description = "商品属性")
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class Property {
@Schema(description = "属性编号", example = "10")
private Long propertyId;
@Schema(description = "属性名字", example = "颜色")
private String propertyName;
@Schema(description = "属性值编号", example = "10")
private Long valueId;
@Schema(description = "属性值名字", example = "红色")
private String valueName;
}
}

View File

@@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
@Schema(description = "管理后台 - 商品 SKU 创建/更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
}

View File

@@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.NotNull;
import java.util.List;
@Schema(description = "管理后台 - 商品 SKU Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSkuRespVO extends ProductSkuBaseVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
}

View File

@@ -0,0 +1,4 @@
### 获得商品 SPU 明细
GET {{baseUrl}}/product/spu/get-detail?id=4
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@@ -0,0 +1,147 @@
package cn.iocoder.yudao.module.product.controller.admin.spu;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
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.enums.spu.ProductSpuStatusEnum;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
//import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi;
//import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
@Tag(name = "管理后台 - 商品 SPU")
@RestController
@RequestMapping("/product/spu")
@Validated
public class ProductSpuController {
@Resource
private ProductSpuService productSpuService;
@Resource
private ProductSkuService productSkuService;
//
// @Resource
// private CouponTemplateApi couponTemplateApi;
@PostMapping("/create")
@Operation(summary = "创建商品 SPU")
@PreAuthorize("@ss.hasPermission('product:spu:create')")
public CommonResult<Long> createProductSpu(@Valid @RequestBody ProductSpuCreateReqVO createReqVO) {
return success(productSpuService.createSpu(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新商品 SPU")
@PreAuthorize("@ss.hasPermission('product:spu:update')")
public CommonResult<Boolean> updateSpu(@Valid @RequestBody ProductSpuUpdateReqVO updateReqVO) {
productSpuService.updateSpu(updateReqVO);
return success(true);
}
@PutMapping("/update-status")
@Operation(summary = "更新商品 SPU Status")
@PreAuthorize("@ss.hasPermission('product:spu:update')")
public CommonResult<Boolean> updateStatus(@Valid @RequestBody ProductSpuUpdateStatusReqVO updateReqVO) {
productSpuService.updateSpuStatus(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除商品 SPU")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:spu:delete')")
public CommonResult<Boolean> deleteSpu(@RequestParam("id") Long id) {
productSpuService.deleteSpu(id);
return success(true);
}
@GetMapping("/get-detail")
@Operation(summary = "获得商品 SPU 明细")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<ProductSpuDetailRespVO> getSpuDetail(@RequestParam("id") Long id) {
// 获得商品 SPU
ProductSpuDO spu = productSpuService.getSpu(id);
if (spu == null) {
throw exception(SPU_NOT_EXISTS);
}
// 查询商品 SKU
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
// 查询优惠卷
// TODO @puhui999优惠劵的信息要不交给前端读取主要是为了避免商品依赖 promotion 模块哈;
// List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(
// spu.getGiveCouponTemplateIds());
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus));
}
@GetMapping("/list-all-simple")
@Operation(summary = "获得商品 SPU 精简列表")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<List<ProductSpuSimpleRespVO>> getSpuSimpleList() {
List<ProductSpuDO> list = productSpuService.getSpuListByStatus(ProductSpuStatusEnum.ENABLE.getStatus());
// 降序排序后,返回给前端
list.sort(Comparator.comparing(ProductSpuDO::getSort).reversed());
return success(ProductSpuConvert.INSTANCE.convertList02(list));
}
@GetMapping("/list")
@Operation(summary = "获得商品 SPU 详情列表")
@Parameter(name = "spuIds", description = "spu 编号列表", required = true, example = "[1,2,3]")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<List<ProductSpuDetailRespVO>> getSpuList(@RequestParam("spuIds") Collection<Long> spuIds) {
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespListVO(
productSpuService.getSpuList(spuIds), productSkuService.getSkuListBySpuId(spuIds)));
}
@GetMapping("/page")
@Operation(summary = "获得商品 SPU 分页")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<PageResult<ProductSpuRespVO>> getSpuPage(@Valid ProductSpuPageReqVO pageVO) {
return success(ProductSpuConvert.INSTANCE.convertPage(productSpuService.getSpuPage(pageVO)));
}
@GetMapping("/get-count")
@Operation(summary = "获得商品 SPU 分页 tab count")
@PreAuthorize("@ss.hasPermission('product:spu:query')")
public CommonResult<Map<Integer, Long>> getSpuCount() {
return success(productSpuService.getTabsCount());
}
@GetMapping("/export")
@Operation(summary = "导出商品")
@PreAuthorize("@ss.hasPermission('product:spu:export')")
@OperateLog(type = EXPORT)
public void exportUserList(@Validated ProductSpuExportReqVO reqVO,
HttpServletResponse response) throws IOException {
List<ProductSpuDO> spuList = productSpuService.getSpuList(reqVO);
// 导出 Excel
List<ProductSpuExcelVO> datas = ProductSpuConvert.INSTANCE.convertList03(spuList);
ExcelUtils.write(response, "商品列表.xls", "数据", ProductSpuExcelVO.class, datas);
}
}

View File

@@ -0,0 +1,126 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 商品 SPU Base VO提供给添加、修改、详细的子 VO 使用
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
*
* @author HUIHUI
*/
@Data
public class ProductSpuBaseVO {
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖")
@NotEmpty(message = "商品名称不能为空")
private String name;
@Schema(description = "关键字", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑不出汗")
@NotEmpty(message = "商品关键字不能为空")
private String keyword;
@Schema(description = "商品简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖简介")
@NotEmpty(message = "商品简介不能为空")
private String introduction;
@Schema(description = "商品详情", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖详情")
@NotEmpty(message = "商品详情不能为空")
private String description;
@Schema(description = "商品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品分类不能为空")
private Long categoryId;
@Schema(description = "商品品牌编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品品牌不能为空")
private Long brandId;
@Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
@NotEmpty(message = "商品封面图不能为空")
private String picUrl;
@Schema(description = "商品轮播图", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
private List<String> sliderPicUrls;
@Schema(description = "商品视频", example = "https://www.iocoder.cn/xx.mp4")
private String videoUrl;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品单位不能为空")
private Integer unit;
@Schema(description = "排序字段", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品排序字段不能为空")
private Integer sort;
// ========== SKU 相关字段 =========
@Schema(description = "规格类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品规格类型不能为空")
private Boolean specType;
// ========== 物流相关字段 =========
@Schema(description = "物流配置模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
@NotNull(message = "物流配置模板编号不能为空")
private Long deliveryTemplateId;
// ========== 营销相关字段 =========
@Schema(description = "是否热卖推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品推荐不能为空")
private Boolean recommendHot;
@Schema(description = "是否优惠推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品推荐不能为空")
private Boolean recommendBenefit;
@Schema(description = "是否精品推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品推荐不能为空")
private Boolean recommendBest;
@Schema(description = "是否新品推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品推荐不能为空")
private Boolean recommendNew;
@Schema(description = "是否优品推荐", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品推荐不能为空")
private Boolean recommendGood;
@Schema(description = "赠送积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
@NotNull(message = "商品赠送积分不能为空")
private Integer giveIntegral;
@Schema(description = "赠送的优惠劵数组包含优惠券编号和名称")
private List<GiveCouponTemplate> giveCouponTemplates;
@Schema(description = "分销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品分销类型不能为空")
private Boolean subCommissionType;
@Schema(description = "活动展示顺序", example = "[1, 3, 2, 4, 5]")
private List<Integer> activityOrders;
// ========== 统计相关字段 =========
@Schema(description = "虚拟销量", example = "66")
private Integer virtualSalesCount;
@Schema(description = "管理后台 - 商品 SPU 赠送的优惠卷")
@Data
public static class GiveCouponTemplate {
@Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "优惠劵名", requiredMode = Schema.RequiredMode.REQUIRED, example = "春节送送送")
private String name;
}
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.Valid;
import java.util.List;
@Schema(description = "管理后台 - 商品 SPU 创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuCreateReqVO extends ProductSpuBaseVO {
// ========== SKU 相关字段 =========
@Schema(description = "SKU 数组")
@Valid
private List<ProductSkuCreateOrUpdateReqVO> skus;
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.List;
@Schema(description = "管理后台 - 商品 SPU 详细 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuDetailRespVO extends ProductSpuBaseVO {
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1212")
private Long id;
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10000")
private Integer salesCount;
@Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20000")
private Integer browseCount;
@Schema(description = "商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
// ========== SKU 相关字段 =========
@Schema(description = "SKU 数组")
private List<ProductSkuRespVO> skus;
}

View File

@@ -0,0 +1,112 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.product.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 商品 Spu Excel 导出 VO TODO 暂定
*
* @author HUIHUI
*/
@Data
public class ProductSpuExcelVO {
@ExcelProperty("商品编号")
private Long id;
@ExcelProperty("商品名称")
private String name;
@ExcelProperty("关键字")
private String keyword;
@ExcelProperty("商品简介")
private String introduction;
@ExcelProperty("商品详情")
private String description;
@ExcelProperty("条形码")
private String barCode;
@ExcelProperty("商品分类编号")
private Long categoryId;
@ExcelProperty("商品品牌编号")
private Long brandId;
@ExcelProperty("商品封面图")
private String picUrl;
@ExcelProperty("商品视频")
private String videoUrl;
@ExcelProperty(value = "商品单位", converter = DictConvert.class)
@DictFormat(DictTypeConstants.PRODUCT_UNIT)
private Integer unit;
@ExcelProperty("排序字段")
private Integer sort;
@ExcelProperty(value = "商品状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.PRODUCT_SPU_STATUS)
private Integer status;
@ExcelProperty("规格类型")
private Boolean specType;
@ExcelProperty("商品价格")
private Integer price;
@ExcelProperty("市场价")
private Integer marketPrice;
@ExcelProperty("成本价")
private Integer costPrice;
@ExcelProperty("库存")
private Integer stock;
@ExcelProperty("物流配置模板编号")
private Long deliveryTemplateId;
@ExcelProperty("是否热卖推荐")
private Boolean recommendHot;
@ExcelProperty("是否优惠推荐")
private Boolean recommendBenefit;
@ExcelProperty("是否精品推荐")
private Boolean recommendBest;
@ExcelProperty("是否新品推荐")
private Boolean recommendNew;
@ExcelProperty("是否优品推荐")
private Boolean recommendGood;
@ExcelProperty("赠送积分")
private Integer giveIntegral;
@ExcelProperty("分销类型")
private Boolean subCommissionType;
@ExcelProperty("商品销量")
private Integer salesCount;
@ExcelProperty("虚拟销量")
private Integer virtualSalesCount;
@ExcelProperty("商品点击量")
private Integer browseCount;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 商品 SPU 导出 Request VO参数和 ProductSpuPageReqVO 是一致的")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductSpuExportReqVO {
@Schema(description = "商品名称", example = "清凉小短袖")
private String name;
@Schema(description = "前端请求的tab类型", example = "1")
private Integer tabType;
@Schema(description = "商品分类编号", example = "100")
private Long categoryId;
@Schema(description = "创建时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,58 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 商品 SPU 分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuPageReqVO extends PageParam {
/**
* 出售中商品
*/
public static final Integer FOR_SALE = 0;
/**
* 仓库中商品
*/
public static final Integer IN_WAREHOUSE = 1;
/**
* 已售空商品
*/
public static final Integer SOLD_OUT = 2;
/**
* 警戒库存
*/
public static final Integer ALERT_STOCK = 3;
/**
* 商品回收站
*/
public static final Integer RECYCLE_BIN = 4;
@Schema(description = "商品名称", example = "清凉小短袖")
private String name;
@Schema(description = "前端请求的tab类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer tabType;
@Schema(description = "商品分类编号", example = "1")
private Long categoryId;
@Schema(description = "创建时间", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 商品 SPU Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuRespVO extends ProductSpuBaseVO {
@Schema(description = "spuId", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
private Long id;
@Schema(description = "商品价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "1999")
private Integer price;
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
private Integer salesCount;
@Schema(description = "市场价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "199")
private Integer marketPrice;
@Schema(description = "成本价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "19")
private Integer costPrice;
@Schema(description = "商品库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "10000")
private Integer stock;
@Schema(description = "商品创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023-05-24 00:00:00")
private LocalDateTime createTime;
@Schema(description = "商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "888")
private Integer browseCount;
}

View File

@@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
@Schema(description = "管理后台 - 商品 SPU 精简 Response VO")
@Data
@ToString(callSuper = true)
public class ProductSpuSimpleRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "213")
private Long id;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖")
private String name;
@Schema(description = "商品价格,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1999")
private Integer price;
@Schema(description = "商品市场价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "199")
private Integer marketPrice;
@Schema(description = "商品成本价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "19")
private Integer costPrice;
@Schema(description = "商品库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
private Integer stock;
// ========== 统计相关字段 =========
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
private Integer salesCount;
@Schema(description = "商品虚拟销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20000")
private Integer virtualSalesCount;
@Schema(description = "商品浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000")
private Integer browseCount;
}

View File

@@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
@Schema(description = "管理后台 - 商品 SPU 更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductSpuUpdateReqVO extends ProductSpuBaseVO {
@Schema(description = "商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品编号不能为空")
private Long id;
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1999")
private Integer salesCount;
@Schema(description = "浏览量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1999")
private Integer browseCount;
@Schema(description = "商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@InEnum(ProductSpuStatusEnum.class)
private Integer status;
// ========== SKU 相关字段 =========
@Schema(description = "SKU 数组")
@Valid
private List<ProductSkuCreateOrUpdateReqVO> skus;
}

View File

@@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.product.controller.admin.spu.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品 SPU Status 更新 Request VO")
@Data
public class ProductSpuUpdateStatusReqVO{
@Schema(description = "商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品编号不能为空")
private Long id;
@Schema(description = "商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品状态不能为空")
@InEnum(ProductSpuStatusEnum.class)
private Integer status;
}

View File

@@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.product.controller.app.category;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO;
import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "用户 APP - 商品分类")
@RestController
@RequestMapping("/product/category")
@Validated
public class AppCategoryController {
@Resource
private ProductCategoryService categoryService;
@GetMapping("/list")
@Operation(summary = "获得商品分类列表")
public CommonResult<List<AppCategoryRespVO>> getProductCategoryList() {
List<ProductCategoryDO> list = categoryService.getEnableCategoryList();
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(ProductCategoryConvert.INSTANCE.convertList03(list));
}
}

View File

@@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.product.controller.app.category.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
@Schema(description = "用户 APP - 商品分类 Response VO")
public class AppCategoryRespVO {
@Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Long id;
@Schema(description = "父分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "父分类编号不能为空")
private Long parentId;
@Schema(description = "分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "办公文具")
@NotBlank(message = "分类名称不能为空")
private String name;
@Schema(description = "分类图片", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "分类图片不能为空")
private String picUrl;
}

View File

@@ -0,0 +1,80 @@
package cn.iocoder.yudao.module.product.controller.app.comment;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "用户 APP - 商品评价")
@RestController
@RequestMapping("/product/comment")
@Validated
public class AppProductCommentController {
@Resource
private ProductCommentService productCommentService;
@Resource
@Lazy
private ProductSkuService productSkuService;
@GetMapping("/list")
@Operation(summary = "获得最近的 n 条商品评价")
@Parameters({
@Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"),
@Parameter(name = "count", description = "数量", required = true, example = "10")
})
public CommonResult<List<AppProductCommentRespVO>> getCommentList(
@RequestParam("spuId") Long spuId,
@RequestParam(value = "count", defaultValue = "10") Integer count) {
return success(productCommentService.getCommentList(spuId, count));
}
@GetMapping("/page")
@Operation(summary = "获得商品评价分页")
public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
// 查询评论分页
PageResult<ProductCommentDO> commentPageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
if (CollUtil.isEmpty(commentPageResult.getList())) {
return success(PageResult.empty(commentPageResult.getTotal()));
}
// 拼接返回
Set<Long> skuIds = convertSet(commentPageResult.getList(), ProductCommentDO::getSkuId);
PageResult<AppProductCommentRespVO> commentVOPageResult = ProductCommentConvert.INSTANCE.convertPage02(
commentPageResult, productSkuService.getSkuList(skuIds));
return success(commentVOPageResult);
}
// TODO 芋艿:需要搞下
@GetMapping("/statistics")
@Operation(summary = "获得商品的评价统计")
public CommonResult<AppCommentStatisticsRespVO> getCommentStatistics(@Valid @RequestParam("spuId") Long spuId) {
return success(productCommentService.getCommentStatistics(spuId, Boolean.TRUE));
}
}

View File

@@ -0,0 +1,38 @@
package cn.iocoder.yudao.module.product.controller.app.comment.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "用户 App - 商品评价分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AppCommentPageReqVO extends PageParam {
/**
* 好评
*/
public static final Integer GOOD_COMMENT = 1;
/**
* 中评
*/
public static final Integer MEDIOCRE_COMMENT = 2;
/**
* 差评
*/
public static final Integer NEGATIVE_COMMENT = 3;
@Schema(description = "商品SPU编号", example = "29502")
@NotNull(message = "商品SPU编号不能为空")
private Long spuId;
@Schema(description = "app 评论页 tab 类型 (0 全部、1 好评、2 中评、3 差评)", example = "0")
@NotNull(message = "商品SPU编号不能为空")
private Integer type;
}

View File

@@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.product.controller.app.comment.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
@Schema(description = "APP - 商品评价页评论分类数统计 Response VO")
@Data
@ToString(callSuper = true)
public class AppCommentStatisticsRespVO {
@Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
private Long goodCount;
@Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
private Long mediocreCount;
@Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
private Long negativeCount;
@Schema(description = "总平均分", requiredMode = Schema.RequiredMode.REQUIRED, example = "3.55")
private Double scores;
}

View File

@@ -0,0 +1,98 @@
package cn.iocoder.yudao.module.product.controller.app.comment.vo;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "用户 App - 商品评价详情 Response VO")
@Data
@ToString(callSuper = true)
public class AppProductCommentRespVO {
@Schema(description = "评价人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
private Long userId;
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
private String userNickname;
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
private String userAvatar;
@Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
private Long id;
@Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
private Boolean anonymous;
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
private Long orderId;
@Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8233")
private Long orderItemId;
@Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean replyStatus;
@Schema(description = "回复管理员编号", example = "22212")
private Long replyUserId;
@Schema(description = "商家回复内容", example = "亲,你的好评就是我的动力(*^▽^*)")
private String replyContent;
@Schema(description = "商家回复时间")
private LocalDateTime replyTime;
@Schema(description = "追加评价内容", example = "穿了很久都很丝滑诶")
private String additionalContent;
@Schema(description = "追评评价图片地址数组,以逗号分隔最多上传 9 张", example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
private List<String> additionalPicUrls;
@Schema(description = "追加评价时间")
private LocalDateTime additionalTime;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "91192")
@NotNull(message = "商品 SPU 编号不能为空")
private Long spuId;
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
@NotNull(message = "商品 SPU 名称不能为空")
private String spuName;
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "81192")
@NotNull(message = "商品 SKU 编号不能为空")
private Long skuId;
@Schema(description = "商品 SKU 属性", requiredMode = Schema.RequiredMode.REQUIRED)
private List<AppProductPropertyValueDetailRespVO> skuProperties;
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "评分星级 1-5 分不能为空")
private Integer scores;
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "描述星级 1-5 分不能为空")
private Integer descriptionScores;
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
@NotNull(message = "服务星级 1-5 分不能为空")
private Integer benefitScores;
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
@NotNull(message = "评论内容不能为空")
private String content;
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
private List<String> picUrls;
}

View File

@@ -0,0 +1,105 @@
package cn.iocoder.yudao.module.product.controller.app.favorite;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteBatchReqVO;
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteReqVO;
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
import cn.iocoder.yudao.module.product.convert.favorite.ProductFavoriteConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.service.favorite.ProductFavoriteService;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "用户 APP - 商品收藏")
@RestController
@RequestMapping("/product/favorite")
public class AppFavoriteController {
@Resource
private ProductFavoriteService productFavoriteService;
@Resource
private ProductSpuService productSpuService;
@PostMapping(value = "/create")
@Operation(summary = "添加商品收藏")
@PreAuthenticated
public CommonResult<Long> createFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) {
return success(productFavoriteService.createFavorite(getLoginUserId(), reqVO.getSpuId()));
}
@PostMapping(value = "/create-list")
@Operation(summary = "添加多个商品收藏")
@PreAuthenticated
public CommonResult<Boolean> createFavoriteList(@RequestBody @Valid AppFavoriteBatchReqVO reqVO) {
// todo @jason待实现如果有已经收藏的不用报错忽略即可
return success(true);
}
@DeleteMapping(value = "/delete")
@Operation(summary = "取消单个商品收藏")
@PreAuthenticated
public CommonResult<Boolean> deleteFavorite(@RequestBody @Valid AppFavoriteReqVO reqVO) {
productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId());
return success(Boolean.TRUE);
}
@DeleteMapping(value = "/delete-list")
@Operation(summary = "取消多个商品收藏")
@PreAuthenticated
public CommonResult<Boolean> deleteFavoriteList(@RequestBody @Valid AppFavoriteBatchReqVO reqVO) {
// todo @jason待实现
// productFavoriteService.deleteFavorite(getLoginUserId(), reqVO.getSpuId());
return success(Boolean.TRUE);
}
@GetMapping(value = "/page")
@Operation(summary = "获得商品收藏分页")
@PreAuthenticated
public CommonResult<PageResult<AppFavoriteRespVO>> getFavoritePage(AppFavoritePageReqVO reqVO) {
PageResult<ProductFavoriteDO> favoritePage = productFavoriteService.getFavoritePage(getLoginUserId(), reqVO);
if (CollUtil.isEmpty(favoritePage.getList())) {
return success(PageResult.empty());
}
// 得到商品 spu 信息
List<ProductFavoriteDO> favorites = favoritePage.getList();
List<Long> spuIds = convertList(favorites, ProductFavoriteDO::getSpuId);
List<ProductSpuDO> spus = productSpuService.getSpuList(spuIds);
// 转换 VO 结果
PageResult<AppFavoriteRespVO> pageResult = new PageResult<>(favoritePage.getTotal());
pageResult.setList(ProductFavoriteConvert.INSTANCE.convertList(favorites, spus));
return success(pageResult);
}
@GetMapping(value = "/exits")
@Operation(summary = "检查是否收藏过商品")
@PreAuthenticated
public CommonResult<Boolean> isFavoriteExists(AppFavoriteReqVO reqVO) {
ProductFavoriteDO favorite = productFavoriteService.getFavorite(getLoginUserId(), reqVO.getSpuId());
return success(favorite != null);
}
@GetMapping(value = "/get-count")
@Operation(summary = "获得商品收藏数量")
@PreAuthenticated
public CommonResult<Long> getFavoriteCount() {
return success(productFavoriteService.getFavoriteCount(getLoginUserId()));
}
}

View File

@@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
@Schema(description = "用户 APP - 商品收藏的批量 Request VO") // 用于收藏、取消收藏、获取收藏
@Data
public class AppFavoriteBatchReqVO {
@Schema(description = "商品 SPU 编号数组", requiredMode = REQUIRED, example = "29502")
@NotEmpty(message = "商品 SPU 编号数组不能为空")
private List<Long> spuIds;
}

View File

@@ -0,0 +1,10 @@
package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 App - 商品收藏分页查询 Request VO")
@Data
public class AppFavoritePageReqVO extends PageParam {
}

View File

@@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
@Schema(description = "用户 APP - 商品收藏的单个 Request VO") // 用于收藏、取消收藏、获取收藏
@Data
public class AppFavoriteReqVO {
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
@NotNull(message = "商品 SPU 编号不能为空")
private Long spuId;
}

View File

@@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.product.controller.app.favorite.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
@Schema(description = "用户 App - 商品收藏 Response VO")
@Data
public class AppFavoriteRespVO {
@Schema(description = "编号", requiredMode = REQUIRED, example = "1")
private Long id;
@Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
private Long spuId;
// ========== 商品相关字段 ==========
@Schema(description = "商品 SPU 名称", example = "赵六")
private String spuName;
@Schema(description = "商品封面图", example = "https://domain/pic.png")
private String picUrl;
@Schema(description = "商品单价", example = "100")
private Integer price;
}

View File

@@ -0,0 +1,4 @@
/**
* 占位符,无时间作用,避免 package 缩进
*/
package cn.iocoder.yudao.module.product.controller.app.property;

View File

@@ -0,0 +1,4 @@
/**
* 占位符,无时间作用,避免 package 缩进
*/
package cn.iocoder.yudao.module.product.controller.app.property.vo.property;

View File

@@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.product.controller.app.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 App - 商品属性值的明细 Response VO")
@Data
public class AppProductPropertyValueDetailRespVO {
@Schema(description = "属性的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long propertyId;
@Schema(description = "属性的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
private String propertyName;
@Schema(description = "属性值的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long valueId;
@Schema(description = "属性值的名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "红色")
private String valueName;
}

View File

@@ -0,0 +1,18 @@
### 获得订单交易的分页(默认)
GET {{appApi}}/product/spu/page?pageNo=1&pageSize=10
Authorization: Bearer {{appToken}}
tenant-id: {{appTenentId}}
### 获得订单交易的分页(价格)
GET {{appApi}}/product/spu/page?pageNo=1&pageSize=10&sortField=price&sortAsc=true
Authorization: Bearer {{appToken}}
tenant-id: {{appTenentId}}
### 获得订单交易的分页(销售)
GET {{appApi}}/product/spu/page?pageNo=1&pageSize=10&sortField=salesCount&sortAsc=true
Authorization: Bearer {{appToken}}
tenant-id: {{appTenentId}}
### 获得商品 SPU 明细
GET {{appApi}}/product/spu/get-detail?id=102
tenant-id: {{appTenentId}}

View File

@@ -0,0 +1,144 @@
package cn.iocoder.yudao.module.product.controller.app.spu;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.level.MemberLevelApi;
import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO;
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.enums.spu.ProductSpuStatusEnum;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_ENABLE;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS;
@Tag(name = "用户 APP - 商品 SPU")
@RestController
@RequestMapping("/product/spu")
@Validated
public class AppProductSpuController {
@Resource
private ProductSpuService productSpuService;
@Resource
private ProductSkuService productSkuService;
@Resource
private MemberLevelApi memberLevelApi;
@Resource
private MemberUserApi memberUserApi;
@GetMapping("/list")
@Operation(summary = "获得商品 SPU 列表")
@Parameters({
@Parameter(name = "recommendType", description = "推荐类型", required = true), // 参见 AppProductSpuPageReqVO.RECOMMEND_TYPE_XXX 常量
@Parameter(name = "count", description = "数量", required = true)
})
public CommonResult<List<AppProductSpuPageRespVO>> getSpuList(
@RequestParam("recommendType") String recommendType,
@RequestParam(value = "count", defaultValue = "10") Integer count) {
List<ProductSpuDO> list = productSpuService.getSpuList(recommendType, count);
if (CollUtil.isEmpty(list)) {
return success(Collections.emptyList());
}
// 拼接返回
List<AppProductSpuPageRespVO> voList = ProductSpuConvert.INSTANCE.convertListForGetSpuList(list);
// 处理 vip 价格
MemberLevelRespDTO memberLevel = getMemberLevel();
voList.forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel)));
return success(voList);
}
@GetMapping("/page")
@Operation(summary = "获得商品 SPU 分页")
public CommonResult<PageResult<AppProductSpuPageRespVO>> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) {
PageResult<ProductSpuDO> pageResult = productSpuService.getSpuPage(pageVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
// 拼接返回
PageResult<AppProductSpuPageRespVO> voPageResult = ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult);
// 处理 vip 价格
MemberLevelRespDTO memberLevel = getMemberLevel();
voPageResult.getList().forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel)));
return success(voPageResult);
}
@GetMapping("/get-detail")
@Operation(summary = "获得商品 SPU 明细")
@Parameter(name = "id", description = "编号", required = true)
public CommonResult<AppProductSpuDetailRespVO> getSpuDetail(@RequestParam("id") Long id) {
// 获得商品 SPU
ProductSpuDO spu = productSpuService.getSpu(id);
if (spu == null) {
throw exception(SPU_NOT_EXISTS);
}
if (!ProductSpuStatusEnum.isEnable(spu.getStatus())) {
throw exception(SPU_NOT_ENABLE);
}
// 拼接返回
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
AppProductSpuDetailRespVO detailVO = ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus);
// 处理 vip 价格
MemberLevelRespDTO memberLevel = getMemberLevel();
detailVO.setVipPrice(calculateVipPrice(detailVO.getPrice(), memberLevel));
return success(detailVO);
}
private MemberLevelRespDTO getMemberLevel() {
Long userId = getLoginUserId();
if (userId == null) {
return null;
}
MemberUserRespDTO user = memberUserApi.getUser(userId).getCheckedData();
if (user.getLevelId() == null || user.getLevelId() <= 0) {
return null;
}
return memberLevelApi.getMemberLevel(user.getLevelId()).getCheckedData();
}
/**
* 计算会员 VIP 优惠价格
*
* @param price 原价
* @param memberLevel 会员等级
* @return 优惠价格
*/
public Integer calculateVipPrice(Integer price, MemberLevelRespDTO memberLevel) {
if (memberLevel == null || memberLevel.getDiscountPercent() == null) {
return 0;
}
Integer newPrice = price * memberLevel.getDiscountPercent() / 100;
return price - newPrice;
}
// TODO 芋艿:商品的浏览记录;
}

View File

@@ -0,0 +1,109 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "用户 App - 商品 SPU 明细 Response VO")
@Data
public class AppProductSpuDetailRespVO {
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
// ========== 基本信息 =========
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
private String name;
@Schema(description = "商品简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是一个快乐简介")
private String introduction;
@Schema(description = "商品详情", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是商品描述")
private String description;
@Schema(description = "商品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long categoryId;
@Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED)
private String picUrl;
@Schema(description = "商品轮播图", requiredMode = Schema.RequiredMode.REQUIRED)
private List<String> sliderPicUrls;
@Schema(description = "商品视频", requiredMode = Schema.RequiredMode.REQUIRED)
private String videoUrl;
@Schema(description = "单位名", requiredMode = Schema.RequiredMode.REQUIRED, example = "")
private String unitName;
// ========== 营销相关字段 =========
@Schema(description = "活动排序数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private List<Integer> activityOrders;
// ========== SKU 相关字段 =========
@Schema(description = "规格类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean specType;
@Schema(description = "商品价格,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer price;
@Schema(description = "市场价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer marketPrice;
@Schema(description = "VIP 价格,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "968") // 通过会员等级,计算出折扣后价格
private Integer vipPrice;
@Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Integer stock;
/**
* SKU 数组
*/
private List<Sku> skus;
// ========== 统计相关字段 =========
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer salesCount;
@Schema(description = "用户 App - 商品 SPU 明细的 SKU 信息")
@Data
public static class Sku {
@Schema(description = "商品 SKU 编号", example = "1")
private Long id;
/**
* 商品属性数组
*/
private List<AppProductPropertyValueDetailRespVO> properties;
@Schema(description = "销售价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer price;
@Schema(description = "市场价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer marketPrice;
@Schema(description = "VIP 价格,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "968") // 通过会员等级,计算出折扣后价格
private Integer vipPrice;
@Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer stock;
@Schema(description = "商品重量", example = "1") // 单位kg 千克
private Double weight;
@Schema(description = "商品体积", example = "1024") // 单位m^3 平米
private Double volume;
}
}

View File

@@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.AssertTrue;
@Schema(description = "用户 App - 商品 SPU 分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AppProductSpuPageReqVO extends PageParam {
public static final String SORT_FIELD_PRICE = "price";
public static final String SORT_FIELD_SALES_COUNT = "salesCount";
public static final String RECOMMEND_TYPE_HOT = "hot";
public static final String RECOMMEND_TYPE_BENEFIT = "benefit";
public static final String RECOMMEND_TYPE_BEST = "best";
public static final String RECOMMEND_TYPE_NEW = "new";
public static final String RECOMMEND_TYPE_GOOD = "good";
@Schema(description = "分类编号", example = "1")
private Long categoryId;
@Schema(description = "关键字", example = "好看")
private String keyword;
@Schema(description = "排序字段", example = "price") // 参见 AppProductSpuPageReqVO.SORT_FIELD_XXX 常量
private String sortField;
@Schema(description = "排序方式", example = "true")
private Boolean sortAsc;
@Schema(description = "推荐类型", example = "hot") // 参见 AppProductSpuPageReqVO.RECOMMEND_TYPE_XXX 常量
private String recommendType;
@AssertTrue(message = "排序字段不合法")
@JsonIgnore
public boolean isSortFieldValid() {
if (StrUtil.isEmpty(sortField)) {
return true;
}
return StrUtil.equalsAny(sortField, SORT_FIELD_PRICE, SORT_FIELD_SALES_COUNT);
}
}

View File

@@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "用户 App - 商品 SPU Response VO")
@Data
public class AppProductSpuPageRespVO {
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
private String name;
@Schema(description = "分类编号", requiredMode = Schema.RequiredMode.REQUIRED)
private Long categoryId;
@Schema(description = "商品封面图", requiredMode = Schema.RequiredMode.REQUIRED)
private String picUrl;
@Schema(description = "商品轮播图", requiredMode = Schema.RequiredMode.REQUIRED)
private List<String> sliderPicUrls;
@Schema(description = "单位名", requiredMode = Schema.RequiredMode.REQUIRED, example = "")
private String unitName;
// ========== SKU 相关字段 =========
@Schema(description = "规格类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean specType;
@Schema(description = "商品价格,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer price;
@Schema(description = "市场价,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer marketPrice;
@Schema(description = "VIP 价格,单位使用:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "968") // 通过会员等级,计算出折扣后价格
private Integer vipPrice;
@Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Integer stock;
// ========== 营销相关字段 =========
@Schema(description = "活动排序数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private List<Integer> activityOrders;
// ========== 统计相关字段 =========
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer salesCount;
}

View File

@@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.product.convert.brand;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandRespVO;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandSimpleRespVO;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 品牌 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductBrandConvert {
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
ProductBrandDO convert(ProductBrandCreateReqVO bean);
ProductBrandDO convert(ProductBrandUpdateReqVO bean);
ProductBrandRespVO convert(ProductBrandDO bean);
List<ProductBrandSimpleRespVO> convertList1(List<ProductBrandDO> list);
List<ProductBrandRespVO> convertList(List<ProductBrandDO> list);
PageResult<ProductBrandRespVO> convertPage(PageResult<ProductBrandDO> page);
}

View File

@@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.product.convert.category;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 商品分类 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductCategoryConvert {
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
ProductCategoryDO convert(ProductCategoryCreateReqVO bean);
ProductCategoryDO convert(ProductCategoryUpdateReqVO bean);
ProductCategoryRespVO convert(ProductCategoryDO bean);
List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list);
List<AppCategoryRespVO> convertList03(List<ProductCategoryDO> list);
}

View File

@@ -0,0 +1,132 @@
package cn.iocoder.yudao.module.product.convert.comment;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO;
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/**
* 商品评价 Convert
*
* @author wangzhs
*/
@Mapper
public interface ProductCommentConvert {
ProductCommentConvert INSTANCE = Mappers.getMapper(ProductCommentConvert.class);
ProductCommentRespVO convert(ProductCommentDO bean);
@Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))")
AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount);
@Named("calculateOverallScore")
default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) {
return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount);
}
List<ProductCommentRespVO> convertList(List<ProductCommentDO> list);
PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page);
PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult);
default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult,
List<ProductSkuDO> skuList) {
Map<Long, ProductSkuDO> skuMap = CollectionUtils.convertMap(skuList, ProductSkuDO::getId);
PageResult<AppProductCommentRespVO> page = convertPage01(pageResult);
page.getList().forEach(item -> {
// 判断用户是否选择匿名
if (ObjectUtil.equal(item.getAnonymous(), true)) {
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
}
// 设置 SKU 规格值
findAndThen(skuMap, item.getSkuId(),
sku -> item.setSkuProperties(convertList01(sku.getProperties())));
});
return page;
}
List<AppProductPropertyValueDetailRespVO> convertList01(List<ProductSkuDO.Property> properties);
/**
* 计算综合评分
*
* @param descriptionScores 描述星级
* @param benefitScores 服务星级
* @return 综合评分
*/
@Named("convertScores")
default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
// 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores);
BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN);
return divide.intValue();
}
ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
@Mapping(target = "scores",
expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, ProductSpuDO spuDO, ProductSkuDO skuDO, MemberUserRespDTO user) {
ProductCommentDO commentDO = convert(createReqDTO);
if (user != null) {
commentDO.setUserId(user.getId());
commentDO.setUserNickname(user.getNickname());
commentDO.setUserAvatar(user.getAvatar());
}
if (spuDO != null) {
commentDO.setSpuId(spuDO.getId());
commentDO.setSpuName(spuDO.getName());
}
if (skuDO != null) {
commentDO.setSkuPicUrl(skuDO.getPicUrl());
commentDO.setSkuProperties(skuDO.getProperties());
}
return commentDO;
}
@Mapping(target = "visible", constant = "true")
@Mapping(target = "replyStatus", constant = "false")
@Mapping(target = "userId", constant = "0L")
@Mapping(target = "orderId", constant = "0L")
@Mapping(target = "orderItemId", constant = "0L")
@Mapping(target = "anonymous", expression = "java(Boolean.FALSE)")
@Mapping(target = "scores",
expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
ProductCommentDO convert(ProductCommentCreateReqVO createReq);
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
ProductCommentDO commentDO = convert(createReq);
if (spu != null) {
commentDO.setSpuId(spu.getId()).setSpuName(spu.getName());
}
if (sku != null) {
commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
}
return commentDO;
}
}

View File

@@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.product.convert.favorite;
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoriteRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@Mapper
public interface ProductFavoriteConvert {
ProductFavoriteConvert INSTANCE = Mappers.getMapper(ProductFavoriteConvert.class);
ProductFavoriteDO convert(Long userId, Long spuId);
@Mapping(target = "id", source = "favorite.id")
@Mapping(target = "spuName", source = "spu.name")
AppFavoriteRespVO convert(ProductSpuDO spu, ProductFavoriteDO favorite);
default List<AppFavoriteRespVO> convertList(List<ProductFavoriteDO> favorites, List<ProductSpuDO> spus) {
List<AppFavoriteRespVO> resultList = new ArrayList<>(favorites.size());
Map<Long, ProductSpuDO> spuMap = convertMap(spus, ProductSpuDO::getId);
for (ProductFavoriteDO favorite : favorites) {
ProductSpuDO spuDO = spuMap.get(favorite.getSpuId());
resultList.add(convert(spuDO, favorite));
}
return resultList;
}
}

View File

@@ -0,0 +1,57 @@
package cn.iocoder.yudao.module.product.convert.property;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
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.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/**
* 属性项 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyConvert {
ProductPropertyConvert INSTANCE = Mappers.getMapper(ProductPropertyConvert.class);
ProductPropertyDO convert(ProductPropertyCreateReqVO bean);
ProductPropertyDO convert(ProductPropertyUpdateReqVO bean);
ProductPropertyRespVO convert(ProductPropertyDO bean);
List<ProductPropertyRespVO> convertList(List<ProductPropertyDO> list);
PageResult<ProductPropertyRespVO> convertPage(PageResult<ProductPropertyDO> page);
default List<ProductPropertyAndValueRespVO> convertList(List<ProductPropertyDO> keys, List<ProductPropertyValueDO> values) {
Map<Long, List<ProductPropertyValueDO>> valueMap = CollectionUtils.convertMultiMap(values, ProductPropertyValueDO::getPropertyId);
return CollectionUtils.convertList(keys, key -> {
ProductPropertyAndValueRespVO respVO = convert02(key);
// 如果属性值为空value不为null,返回空列表
if (CollUtil.isEmpty(values)) {
respVO.setValues(Collections.emptyList());
}else {
respVO.setValues(convertList02(valueMap.get(key.getId())));
}
return respVO;
});
}
ProductPropertyAndValueRespVO convert02(ProductPropertyDO bean);
List<ProductPropertyAndValueRespVO.Value> convertList02(List<ProductPropertyValueDO> list);
}

View File

@@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.product.convert.property;
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.ProductPropertyValueRespVO;
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.service.property.bo.ProductPropertyValueDetailRespBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 属性值 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyValueConvert {
ProductPropertyValueConvert INSTANCE = Mappers.getMapper(ProductPropertyValueConvert.class);
ProductPropertyValueDO convert(ProductPropertyValueCreateReqVO bean);
ProductPropertyValueDO convert(ProductPropertyValueUpdateReqVO bean);
ProductPropertyValueRespVO convert(ProductPropertyValueDO bean);
List<ProductPropertyValueRespVO> convertList(List<ProductPropertyValueDO> list);
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

@@ -0,0 +1,77 @@
package cn.iocoder.yudao.module.product.convert.sku;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
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.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 商品 SKU Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductSkuConvert {
ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class);
ProductSkuDO convert(ProductSkuCreateOrUpdateReqVO bean);
ProductSkuRespVO convert(ProductSkuDO bean);
List<ProductSkuRespVO> convertList(List<ProductSkuDO> list);
List<ProductSkuDO> convertList06(List<ProductSkuCreateOrUpdateReqVO> list);
default List<ProductSkuDO> convertList06(List<ProductSkuCreateOrUpdateReqVO> list, Long spuId) {
List<ProductSkuDO> result = convertList06(list);
result.forEach(item -> item.setSpuId(spuId));
return result;
}
ProductSkuRespDTO convert02(ProductSkuDO bean);
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);
/**
* 获得 SPU 的库存变化 Map
*
* @param items SKU 库存变化
* @param skus SKU 列表
* @return SPU 的库存变化 Map
*/
default Map<Long, Integer> convertSpuStockMap(List<ProductSkuUpdateStockReqDTO.Item> items,
List<ProductSkuDO> skus) {
Map<Long, Long> skuIdAndSpuIdMap = convertMap(skus, ProductSkuDO::getId, ProductSkuDO::getSpuId); // SKU 与 SKU 编号的 Map 关系
Map<Long, Integer> spuIdAndStockMap = new HashMap<>(); // SPU 的库存变化 Map 关系
items.forEach(item -> {
Long spuId = skuIdAndSpuIdMap.get(item.getId());
if (spuId == null) {
return;
}
Integer stock = spuIdAndStockMap.getOrDefault(spuId, 0) + item.getIncrCount();
spuIdAndStockMap.put(spuId, stock);
});
return spuIdAndStockMap;
}
default String buildPropertyKey(ProductSkuDO bean) {
if (CollUtil.isEmpty(bean.getProperties())) {
return StrUtil.EMPTY;
}
List<ProductSkuDO.Property> properties = new ArrayList<>(bean.getProperties());
properties.sort(Comparator.comparing(ProductSkuDO.Property::getValueId));
return properties.stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining());
}
}

View File

@@ -0,0 +1,116 @@
package cn.iocoder.yudao.module.product.convert.spu;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
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.enums.DictTypeConstants;
//import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
/**
* 商品 SPU Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductSpuConvert {
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
ProductSpuDO convert(ProductSpuCreateReqVO bean);
ProductSpuDO convert(ProductSpuUpdateReqVO bean);
List<ProductSpuDO> convertList(List<ProductSpuDO> list);
PageResult<ProductSpuRespVO> convertPage(PageResult<ProductSpuDO> page);
ProductSpuPageReqVO convert(AppProductSpuPageReqVO bean);
List<ProductSpuRespDTO> convertList2(List<ProductSpuDO> list);
List<ProductSpuSimpleRespVO> convertList02(List<ProductSpuDO> list);
@Mapping(target = "price", expression = "java(spu.getPrice() / 100)")
@Mapping(target = "marketPrice", expression = "java(spu.getMarketPrice() / 100)")
@Mapping(target = "costPrice", expression = "java(spu.getCostPrice() / 100)")
ProductSpuExcelVO convert(ProductSpuDO spu);
default List<ProductSpuExcelVO> convertList03(List<ProductSpuDO> list) {
List<ProductSpuExcelVO> spuExcelVOs = new ArrayList<>();
list.forEach(spu -> {
ProductSpuExcelVO spuExcelVO = convert(spu);
spuExcelVOs.add(spuExcelVO);
});
return spuExcelVOs;
}
ProductSpuDetailRespVO convert03(ProductSpuDO spu);
ProductSpuRespDTO convert02(ProductSpuDO bean);
// ========== 用户 App 相关 ==========
PageResult<AppProductSpuPageRespVO> convertPageForGetSpuPage(PageResult<ProductSpuDO> page);
default List<AppProductSpuPageRespVO> convertListForGetSpuList(List<ProductSpuDO> list) {
// 处理虚拟销量
list.forEach(spu -> spu.setSalesCount(spu.getSalesCount() + spu.getVirtualSalesCount()));
// 处理 VO 字段
List<AppProductSpuPageRespVO> voList = convertListForGetSpuList0(list);
for (int i = 0; i < list.size(); i++) {
ProductSpuDO spu = list.get(i);
AppProductSpuPageRespVO spuVO = voList.get(i);
spuVO.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
}
return voList;
}
@Named("convertListForGetSpuList0")
List<AppProductSpuPageRespVO> convertListForGetSpuList0(List<ProductSpuDO> list);
default AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu, List<ProductSkuDO> skus) {
// 处理 SPU
AppProductSpuDetailRespVO spuVO = convertForGetSpuDetail(spu)
.setSalesCount(spu.getSalesCount() + defaultIfNull(spu.getVirtualSalesCount(), 0))
.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()));
// 处理 SKU
spuVO.setSkus(convertListForGetSpuDetail(skus));
return spuVO;
}
AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu);
List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus);
default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus) {
ProductSpuDetailRespVO respVO = convert03(spu);
respVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus));
return respVO;
}
default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) {
Map<Long, List<ProductSkuDO>> skuMultiMap = convertMultiMap(skus, ProductSkuDO::getSpuId);
return CollectionUtils.convertList(spus, spu -> convert03(spu)
.setSkus(ProductSkuConvert.INSTANCE.convertList(skuMultiMap.get(spu.getId()))));
}
}

View File

@@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.product.dal.dataobject.brand;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 商品品牌 DO
*
* @author 芋道源码
*/
@TableName("product_brand")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductBrandDO extends BaseDO {
/**
* 品牌编号
*/
@TableId
private Long id;
/**
* 品牌名称
*/
private String name;
/**
* 品牌图片
*/
private String picUrl;
/**
* 品牌排序
*/
private Integer sort;
/**
* 品牌描述
*/
private String description;
/**
* 状态
*
* 枚举 {@link CommonStatusEnum}
*/
private Integer status;
// TODO 芋艿firstLetter 首字母
}

View File

@@ -0,0 +1,68 @@
package cn.iocoder.yudao.module.product.dal.dataobject.category;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 商品分类 DO
*
* @author 芋道源码
*/
@TableName("product_category")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductCategoryDO extends BaseDO {
/**
* 父分类编号 - 根分类
*/
public static final Long PARENT_ID_NULL = 0L;
/**
* 限定分类层级
*/
public static final int CATEGORY_LEVEL = 2;
/**
* 分类编号
*/
@TableId
private Long id;
/**
* 父分类编号
*/
private Long parentId;
/**
* 分类名称
*/
private String name;
/**
* 移动端分类图
*
* 建议 180*180 分辨率
*/
private String picUrl;
/**
* PC 端分类图
*
* 建议 468*340 分辨率
*/
private String bigPicUrl;
/**
* 分类排序
*/
private Integer sort;
/**
* 开启状态
*
* 枚举 {@link CommonStatusEnum}
*/
private Integer status;
}

View File

@@ -0,0 +1,159 @@
package cn.iocoder.yudao.module.product.dal.dataobject.comment;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import java.time.LocalDateTime;
import java.util.List;
/**
* 商品评论 DO
*
* @author 芋道源码
*/
@TableName(value = "product_comment", autoResultMap = true)
@KeySequence("product_comment_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductCommentDO extends BaseDO {
/**
* 默认匿名昵称
*/
public static final String NICKNAME_ANONYMOUS = "匿名用户";
/**
* 评论编号,主键自增
*/
@TableId
private Long id;
/**
* 评价人的用户编号
*
* 关联 MemberUserDO 的 id 编号
*/
private Long userId;
/**
* 评价人名称
*/
private String userNickname;
/**
* 评价人头像
*/
private String userAvatar;
/**
* 是否匿名
*/
private Boolean anonymous;
/**
* 交易订单编号
*
* 关联 TradeOrderDO 的 id 编号
*/
private Long orderId;
/**
* 交易订单项编号
*
* 关联 TradeOrderItemDO 的 id 编号
*/
private Long orderItemId;
/**
* 商品 SPU 编号
*
* 关联 {@link ProductSpuDO#getId()}
*/
private Long spuId;
/**
* 商品 SPU 名称
*
* 关联 {@link ProductSpuDO#getName()}
*/
private String spuName;
/**
* 商品 SKU 编号
*
* 关联 {@link ProductSkuDO#getId()}
*/
private Long skuId;
/**
* 商品 SKU 图片地址
*
* 关联 {@link ProductSkuDO#getPicUrl()}
*/
private String skuPicUrl;
/**
* 属性数组JSON 格式
*
* 关联 {@link ProductSkuDO#getProperties()}
*/
@TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class)
private List<ProductSkuDO.Property> skuProperties;
/**
* 是否可见
*
* true:显示
* false:隐藏
*/
private Boolean visible;
/**
* 评分星级
*
* 1-5 分
*/
private Integer scores;
/**
* 描述星级
*
* 1-5 星
*/
private Integer descriptionScores;
/**
* 服务星级
*
* 1-5 星
*/
private Integer benefitScores;
/**
* 评论内容
*/
private String content;
/**
* 评论图片地址数组
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> picUrls;
/**
* 商家是否回复
*/
private Boolean replyStatus;
/**
* 回复管理员编号
* 关联 AdminUserDO 的 id 编号
*/
private Long replyUserId;
/**
* 商家回复内容
*/
private String replyContent;
/**
* 商家回复时间
*/
private LocalDateTime replyTime;
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.product.dal.dataobject.favorite;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 商品收藏 DO
*
* @author 芋道源码
*/
@TableName("product_favorite")
@KeySequence("product_favorite_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductFavoriteDO extends BaseDO {
/**
* 编号,主键自增
*/
@TableId
private Long id;
/**
* 用户编号
*
* 关联 MemberUserDO 的 id 编号
*/
private Long userId;
/**
* 商品 SPU 编号
*
* 关联 {@link ProductSpuDO#getId()}
*/
private Long spuId;
}

View File

@@ -0,0 +1,51 @@
package cn.iocoder.yudao.module.product.dal.dataobject.property;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 商品属性项 DO
*
* @author 芋道源码
*/
@TableName("product_property")
@KeySequence("product_property_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductPropertyDO extends BaseDO {
/**
* SPU 单规格时,默认属性 id
*/
public static final Long ID_DEFAULT = 0L;
/**
* SPU 单规格时,默认属性名字
*/
public static final String NAME_DEFAULT = "默认";
/**
* 主键
*/
@TableId
private Long id;
/**
* 名称
*/
private String name;
/**
* 状态
*/
private Integer status;
/**
* 备注
*/
private String remark;
}

View File

@@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.product.dal.dataobject.property;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
/**
* 商品属性值 DO
*
* @author 芋道源码
*/
@TableName("product_property_value")
@KeySequence("product_property_value_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductPropertyValueDO extends BaseDO {
/**
* SPU 单规格时,默认属性值 id
*/
public static final Long ID_DEFAULT = 0L;
/**
* SPU 单规格时,默认属性值名字
*/
public static final String NAME_DEFAULT = "默认";
/**
* 主键
*/
@TableId
private Long id;
/**
* 属性项的编号
*
* 关联 {@link ProductPropertyDO#getId()}
*/
private Long propertyId;
/**
* 名称
*/
private String name;
/**
* 备注
*
*/
private String remark;
}

View File

@@ -0,0 +1,156 @@
package cn.iocoder.yudao.module.product.dal.dataobject.sku;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
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.spu.ProductSpuDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import lombok.*;
import java.util.List;
/**
* 商品 SKU DO
*
* @author 芋道源码
*/
@TableName(value = "product_sku", autoResultMap = true)
@KeySequence("product_sku_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductSkuDO extends BaseDO {
/**
* 商品 SKU 编号,自增
*/
@TableId
private Long id;
/**
* SPU 编号
*
* 关联 {@link ProductSpuDO#getId()}
*/
private Long spuId;
/**
* 属性数组JSON 格式
*/
@TableField(typeHandler = PropertyTypeHandler.class)
private List<Property> properties;
/**
* 商品价格,单位:分
*/
private Integer price;
/**
* 市场价,单位:分
*/
private Integer marketPrice;
/**
* 成本价,单位:分
*/
private Integer costPrice;
/**
* 商品条码
*/
private String barCode;
/**
* 图片地址
*/
private String picUrl;
/**
* 库存
*/
private Integer stock;
/**
* 商品重量单位kg 千克
*/
private Double weight;
/**
* 商品体积单位m^3 平米
*/
private Double volume;
/**
* 一级分销的佣金,单位:分
*/
private Integer firstBrokeragePrice;
/**
* 二级分销的佣金,单位:分
*/
private Integer secondBrokeragePrice;
// ========== 营销相关字段 =========
// ========== 统计相关字段 =========
/**
* 商品销量
*/
private Integer salesCount;
/**
* 商品属性
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class Property {
/**
* 属性编号
* 关联 {@link ProductPropertyDO#getId()}
*/
private Long propertyId;
/**
* 属性名字
* 冗余 {@link ProductPropertyDO#getName()}
*
* 注意:每次属性名字发生变化时,需要更新该冗余
*/
private String propertyName;
/**
* 属性值编号
* 关联 {@link ProductPropertyValueDO#getId()}
*/
private Long valueId;
/**
* 属性值名字
* 冗余 {@link ProductPropertyValueDO#getName()}
*
* 注意:每次属性值名字发生变化时,需要更新该冗余
*/
private String valueName;
}
// TODO @芋艿:可以找一些新的思路
public static class PropertyTypeHandler extends AbstractJsonTypeHandler<Object> {
@Override
protected Object parse(String json) {
return JsonUtils.parseArray(json, Property.class);
}
@Override
protected String toJson(Object obj) {
return JsonUtils.toJsonString(obj);
}
}
// TODO 芋艿integral from y
// TODO 芋艿pinkPrice from y
// TODO 芋艿seckillPrice from y
// TODO 芋艿pinkStock from y
// TODO 芋艿seckillStock from y
}

View File

@@ -0,0 +1,213 @@
package cn.iocoder.yudao.module.product.dal.dataobject.spu;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import java.util.List;
/**
* 商品 SPU DO
*
* @author 芋道源码
*/
@TableName(value = "product_spu", autoResultMap = true)
@KeySequence("product_spu_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductSpuDO extends BaseDO {
/**
* 商品 SPU 编号,自增
*/
@TableId
private Long id;
// ========== 基本信息 =========
/**
* 商品名称
*/
private String name;
/**
* 关键字
*/
private String keyword;
/**
* 商品简介
*/
private String introduction;
/**
* 商品详情
*/
private String description;
// TODO @芋艿:是不是要删除
/**
* 商品条码(一维码)
*/
private String barCode;
/**
* 商品分类编号
*
* 关联 {@link ProductCategoryDO#getId()}
*/
private Long categoryId;
/**
* 商品品牌编号
*
* 关联 {@link ProductBrandDO#getId()}
*/
private Long brandId;
/**
* 商品封面图
*/
private String picUrl;
/**
* 商品轮播图
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> sliderPicUrls;
/**
* 商品视频
*/
private String videoUrl;
/**
* 单位
*
* 对应 product_unit 数据字典
*/
private Integer unit;
/**
* 排序字段
*/
private Integer sort;
/**
* 商品状态
*
* 枚举 {@link ProductSpuStatusEnum}
*/
private Integer status;
// ========== SKU 相关字段 =========
/**
* 规格类型
*
* false - 单规格
* true - 多规格
*/
private Boolean specType;
/**
* 商品价格,单位使用:分
*
* 基于其对应的 {@link ProductSkuDO#getPrice()} sku单价最低的商品的
*/
private Integer price;
/**
* 市场价,单位使用:分
*
* 基于其对应的 {@link ProductSkuDO#getMarketPrice()} sku单价最低的商品的
*/
private Integer marketPrice;
/**
* 成本价,单位使用:分
*
* 基于其对应的 {@link ProductSkuDO#getCostPrice()} sku单价最低的商品的
*/
private Integer costPrice;
/**
* 库存
*
* 基于其对应的 {@link ProductSkuDO#getStock()} 求和
*/
private Integer stock;
// ========== 物流相关字段 =========
/**
* 物流配置模板编号
*
* 对应 TradeDeliveryExpressTemplateDO 的 id 编号
*/
private Long deliveryTemplateId;
// ========== 营销相关字段 =========
/**
* 是否热卖推荐
*/
private Boolean recommendHot;
/**
* 是否优惠推荐
*/
private Boolean recommendBenefit;
/**
* 是否精品推荐
*/
private Boolean recommendBest;
/**
* 是否新品推荐
*/
private Boolean recommendNew;
/**
* 是否优品推荐
*/
private Boolean recommendGood;
/**
* 赠送积分
*/
private Integer giveIntegral;
/**
* 赠送的优惠劵编号的数组
*
* 对应 CouponTemplateDO 的 id 属性
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<Long> giveCouponTemplateIds;
// TODO @puhui999字段估计要改成 brokerageType
/**
* 分销类型
*
* false - 默认
* true - 自行设置
*/
private Boolean subCommissionType;
/**
* 活动展示顺序
*
* 对应 PromotionTypeEnum 枚举
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<Integer> activityOrders; // TODO @芋艿: 活动顺序字段长度需要增加
// ========== 统计相关字段 =========
/**
* 商品销量
*/
private Integer salesCount;
/**
* 虚拟销量
*/
private Integer virtualSalesCount;
/**
* 浏览量
*/
private Integer browseCount;
}

View File

@@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.product.dal.mysql.brand;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandListReqVO;
import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductBrandMapper extends BaseMapperX<ProductBrandDO> {
default PageResult<ProductBrandDO> selectPage(ProductBrandPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductBrandDO>()
.likeIfPresent(ProductBrandDO::getName, reqVO.getName())
.eqIfPresent(ProductBrandDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ProductBrandDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ProductBrandDO::getId));
}
default List<ProductBrandDO> selectList(ProductBrandListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ProductBrandDO>()
.likeIfPresent(ProductBrandDO::getName, reqVO.getName()));
}
default ProductBrandDO selectByName(String name) {
return selectOne(ProductBrandDO::getName, name);
}
default List<ProductBrandDO> selectListByStatus(Integer status) {
return selectList(ProductBrandDO::getStatus, status);
}
}

View File

@@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.product.dal.mysql.category;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 商品分类 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> {
default List<ProductCategoryDO> selectList(ProductCategoryListReqVO listReqVO) {
return selectList(new LambdaQueryWrapperX<ProductCategoryDO>()
.likeIfPresent(ProductCategoryDO::getName, listReqVO.getName())
.eqIfPresent(ProductCategoryDO::getParentId, listReqVO.getParentId())
.eqIfPresent(ProductCategoryDO::getStatus, listReqVO.getStatus())
.orderByDesc(ProductCategoryDO::getId));
}
default Long selectCountByParentId(Long parentId) {
return selectCount(ProductCategoryDO::getParentId, parentId);
}
default List<ProductCategoryDO> selectListByStatus(Integer status) {
return selectList(ProductCategoryDO::getStatus, status);
}
}

View File

@@ -0,0 +1,79 @@
package cn.iocoder.yudao.module.product.dal.mysql.comment;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
default PageResult<ProductCommentDO> selectPage(ProductCommentPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ProductCommentDO>()
.likeIfPresent(ProductCommentDO::getUserNickname, reqVO.getUserNickname())
.eqIfPresent(ProductCommentDO::getOrderId, reqVO.getOrderId())
.eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(ProductCommentDO::getScores, reqVO.getScores())
.eqIfPresent(ProductCommentDO::getReplyStatus, reqVO.getReplyStatus())
.betweenIfPresent(ProductCommentDO::getCreateTime, reqVO.getCreateTime())
.likeIfPresent(ProductCommentDO::getSpuName, reqVO.getSpuName())
.orderByDesc(ProductCommentDO::getId));
}
static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
LambdaQueryWrapperX<ProductCommentDO> queryWrapperX = new LambdaQueryWrapperX<>();
// 构建好评查询语句:好评计算 总评 >= 4
if (ObjectUtil.equal(type, AppCommentPageReqVO.GOOD_COMMENT)) {
queryWrapperX.ge(ProductCommentDO::getScores, 4);
}
// 构建中评查询语句:中评计算 总评 >= 3 且 总评 < 4
if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) {
queryWrapperX.ge(ProductCommentDO::getScores, 3);
queryWrapperX.lt(ProductCommentDO::getScores, 4);
}
// 构建差评查询语句:差评计算 总评 < 3
if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) {
queryWrapperX.lt(ProductCommentDO::getScores, 3);
}
}
default PageResult<ProductCommentDO> selectPage(AppCommentPageReqVO reqVO, Boolean visible) {
LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
.eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(ProductCommentDO::getVisible, visible);
// 构建评价查询语句
appendTabQuery(queryWrapper, reqVO.getType());
// 按评价时间排序最新的显示在前面
queryWrapper.orderByDesc(ProductCommentDO::getCreateTime);
return selectPage(reqVO, queryWrapper);
}
default ProductCommentDO selectByUserIdAndOrderItemId(Long userId, Long orderItemId) {
return selectOne(new LambdaQueryWrapperX<ProductCommentDO>()
.eq(ProductCommentDO::getUserId, userId)
.eq(ProductCommentDO::getOrderItemId, orderItemId));
}
default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) {
LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
.eqIfPresent(ProductCommentDO::getSpuId, spuId)
.eqIfPresent(ProductCommentDO::getVisible, visible);
// 构建评价查询语句
appendTabQuery(queryWrapper, type);
return selectCount(queryWrapper);
}
default PageResult<ProductCommentDO> selectCommentList(Long spuId, Integer count) {
// 构建分页查询条件
return selectPage(new PageParam().setPageSize(count), new LambdaQueryWrapperX<ProductCommentDO>()
.eqIfPresent(ProductCommentDO::getSpuId, spuId)
.orderByDesc(ProductCommentDO::getCreateTime)
);
}
}

View File

@@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.product.dal.mysql.favorite;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.controller.app.favorite.vo.AppFavoritePageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.favorite.ProductFavoriteDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductFavoriteMapper extends BaseMapperX<ProductFavoriteDO> {
default ProductFavoriteDO selectByUserIdAndSpuId(Long userId, Long spuId) {
return selectOne(ProductFavoriteDO::getUserId, userId,
ProductFavoriteDO::getSpuId, spuId);
}
default PageResult<ProductFavoriteDO> selectPageByUserAndType(Long userId, AppFavoritePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapper<ProductFavoriteDO>()
.eq(ProductFavoriteDO::getUserId, userId)
.orderByDesc(ProductFavoriteDO::getId));
}
default Long selectCountByUserId(Long userId) {
return selectCount(ProductFavoriteDO::getUserId, userId);
}
}

Some files were not shown because too many files have changed in this diff Show More