product:完善 App 商品分页接口

pull/2/head
YunaiV 2022-12-15 19:48:21 +08:00
parent 652428a723
commit d453301455
15 changed files with 132 additions and 115 deletions

View File

@ -19,7 +19,7 @@ public class ProductSpuPageReqVO extends PageParam {
@ApiModelProperty(value = "商品编码", example = "yudaoyuanma")
private String code;
@ApiModelProperty(value = "分类id", example = "1")
@ApiModelProperty(value = "分类编号", example = "1")
private Long categoryId;
@ApiModelProperty(value = "商品品牌编号", example = "1")

View File

@ -1,5 +1,5 @@
### 获得订单交易的分页 TODO
GET {{appApi}}/trade/order/page?pageNo=1&pageSize=10
GET {{appApi}}/product/spu/page?pageNo=1&pageSize=10
Authorization: Bearer {{appToken}}
tenant-id: {{appTenentId}}

View File

@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.product.controller.app.spu;
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.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuDetailRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageItemRespVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
@ -47,9 +47,10 @@ public class AppProductSpuController {
private ProductPropertyValueService productPropertyValueService;
@GetMapping("/page")
@ApiOperation("获得商品spu分页")
public CommonResult<PageResult<AppSpuPageRespVO>> getSpuPage(@Valid AppSpuPageReqVO pageVO) {
return success(productSpuService.getSpuPage(pageVO));
@ApiOperation("获得商品 SPU 分页")
public CommonResult<PageResult<AppSpuPageItemRespVO>> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) {
PageResult<ProductSpuDO> pageResult = productSpuService.getSpuPage(pageVO, ProductSpuStatusEnum.ENABLE.getStatus());
return success(ProductSpuConvert.INSTANCE.convertPage02(pageResult));
}
@GetMapping("/get-detail")

View File

@ -0,0 +1,44 @@
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.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.AssertTrue;
@ApiModel("用户 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";
@ApiModelProperty(value = "分类编号", example = "1")
private Long categoryId;
@ApiModelProperty(value = "关键字", example = "好看")
private String keyword;
@ApiModelProperty(value = "排序字段", example = "price", notes = "参见 AppSpuPageReqVO.SORT_FIELD_XXX 常量")
private String sortField;
@ApiModelProperty(value = "排序方式", example = "true", notes = "true - 升序false - 降序")
private Boolean sortAsc;
@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,40 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
@ApiModel("用户 App - 商品 SPU 分页项 Response VO")
@Data
public class AppSpuPageItemRespVO {
@ApiModelProperty(value = "商品 SPU 编号", required = true, example = "1")
private Long id;
@ApiModelProperty(value = "商品名称", required = true, example = "芋道")
@NotEmpty(message = "商品名称不能为空")
private String name;
@ApiModelProperty(value = "分类编号", required = true)
@NotNull(message = "分类编号不能为空")
private Long categoryId;
@ApiModelProperty(value = "商品图片的数组", required = true)
private List<String> picUrls;
@ApiModelProperty(value = " 最小价格,单位使用:分", required = true, example = "1024")
private Integer minPrice;
@ApiModelProperty(value = "最大价格,单位使用:分", required = true, example = "1024")
private Integer maxPrice;
// ========== 统计相关字段 =========
@ApiModelProperty(value = "商品销量", example = "1024")
private Integer salesCount;
}

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ApiModel("App - 商品spu分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AppSpuPageReqVO extends PageParam {
@ApiModelProperty(value = "分类id")
private Long categoryId;
}

View File

@ -1,52 +0,0 @@
package cn.iocoder.yudao.module.product.controller.app.spu.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
@ApiModel("App - 商品spu分页 Request VO")
@Data
public class AppSpuPageRespVO {
@ApiModelProperty(value = "主键", required = true, example = "1")
private Long id;
@ApiModelProperty(value = "商品名称")
private String name;
@ApiModelProperty(value = "卖点", required = true)
@NotNull(message = "卖点不能为空")
private String sellPoint;
@ApiModelProperty(value = "描述", required = true)
@NotNull(message = "描述不能为空")
private String description;
@ApiModelProperty(value = "分类id", required = true)
@NotNull(message = "分类id不能为空")
private Long categoryId;
@ApiModelProperty(value = "商品主图地址,* 数组,以逗号分隔,最多上传15张", required = true)
@NotNull(message = "商品主图地址,* 数组,以逗号分隔,最多上传15张不能为空")
private List<String> picUrls;
@ApiModelProperty(value = "排序字段", required = true)
@NotNull(message = "排序字段不能为空")
private Integer sort;
@ApiModelProperty(value = "点赞初始人数")
private Integer likeCount;
@ApiModelProperty(value = "价格 单位使用:分")
private Integer price;
@ApiModelProperty(value = "库存数量")
private Integer quantity;
@ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
private Integer status;
}

View File

@ -5,9 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.property.vo.value.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuDetailRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageItemRespVO;
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.service.property.bo.ProductPropertyValueDetailRespBO;
@ -22,7 +22,7 @@ import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* spu Convert
* SPU Convert
*
* @author
*/
@ -39,10 +39,7 @@ public interface ProductSpuConvert {
PageResult<ProductSpuRespVO> convertPage(PageResult<ProductSpuDO> page);
ProductSpuPageReqVO convert(AppSpuPageReqVO bean);
// TODO 芋艿:修改下
AppSpuPageRespVO convertAppResp(ProductSpuDO list);
ProductSpuPageReqVO convert(AppProductSpuPageReqVO bean);
List<ProductSpuRespDTO> convertList2(List<ProductSpuDO> list);
@ -77,4 +74,6 @@ public interface ProductSpuConvert {
List<AppSpuDetailRespVO.Sku> convertList03(List<ProductSkuDO> skus);
AppProductPropertyValueDetailRespVO convert03(ProductPropertyValueDetailRespBO propertyValue);
PageResult<AppSpuPageItemRespVO> convertPage02(PageResult<ProductSpuDO> page);
}

View File

@ -4,10 +4,12 @@ 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.spu.vo.ProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Objects;
import java.util.Set;
/**
@ -44,6 +46,19 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
.orderByDesc(ProductSpuDO::getSort));
}
default PageResult<ProductSpuDO> selectPage(AppProductSpuPageReqVO pageReqVO, Integer status) {
LambdaQueryWrapperX<ProductSpuDO> query = new LambdaQueryWrapperX<ProductSpuDO>()
.eqIfPresent(ProductSpuDO::getCategoryId, pageReqVO.getCategoryId())
.eqIfPresent(ProductSpuDO::getStatus, status);
// 排序逻辑
if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_PRICE)) {
query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getMaxPrice);
} else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) {
query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getSalesCount);
}
return selectPage(pageReqVO, query);
}
/**
* SPU
*

View File

@ -2,8 +2,7 @@ package cn.iocoder.yudao.module.product.service.spu;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import javax.validation.Valid;
@ -95,9 +94,10 @@ public interface ProductSpuService {
* SPU
*
* @param pageReqVO
* @return spu
* @param status
* @return SPU
*/
PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO);
PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO, Integer status);
/**
* SPU

View File

@ -9,8 +9,7 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
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.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
@ -195,6 +194,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
return productSpuMapper.selectList();
}
// TODO 芋艿:改成 DO 返回
@Override
public PageResult<ProductSpuRespVO> getSpuPage(ProductSpuPageReqVO pageReqVO) {
// 库存告警的 SPU 编号的集合
@ -210,18 +210,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
}
@Override
public PageResult<AppSpuPageRespVO> getSpuPage(AppSpuPageReqVO pageReqVO) {
// TODO 芋艿:貌似实现不太合理
PageResult<ProductSpuDO> productSpuDOPageResult = productSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO));
PageResult<AppSpuPageRespVO> pageResult = new PageResult<>();
// TODO @芋艿 这里用convert如何解决
List<AppSpuPageRespVO> collect = productSpuDOPageResult.getList()
.stream()
.map(ProductSpuConvert.INSTANCE::convertAppResp)
.collect(Collectors.toList());
pageResult.setList(collect);
pageResult.setTotal(productSpuDOPageResult.getTotal());
return pageResult;
public PageResult<ProductSpuDO> getSpuPage(AppProductSpuPageReqVO pageReqVO, Integer status) {
return productSpuMapper.selectPage(pageReqVO, status);
}
@Override

View File

@ -12,8 +12,8 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.Pro
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO;
import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageItemRespVO;
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;
@ -339,15 +339,15 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
productSpuMapper.insert(createReqVO);
// 调用
AppSpuPageReqVO appSpuPageReqVO = new AppSpuPageReqVO();
AppProductSpuPageReqVO appSpuPageReqVO = new AppProductSpuPageReqVO();
appSpuPageReqVO.setCategoryId(2L);
PageResult<AppSpuPageRespVO> spuPage = productSpuService.getSpuPage(appSpuPageReqVO);
PageResult<AppSpuPageItemRespVO> spuPage = productSpuService.getSpuPage(appSpuPageReqVO);
PageResult<ProductSpuDO> result = productSpuMapper.selectPage(
ProductSpuConvert.INSTANCE.convert(appSpuPageReqVO));
List<AppSpuPageRespVO> collect = result.getList()
List<AppSpuPageItemRespVO> collect = result.getList()
.stream()
.map(ProductSpuConvert.INSTANCE::convertAppResp)
.collect(Collectors.toList());

View File

@ -5,4 +5,4 @@ const { http } = uni.$u
export const productSpuPage = params => http.get('product/spu/page', { params })
// 查询商品
export const productSpu = params => http.get('product/spu/', { params })
export const productSpu = id => http.get('product/spu/get-detail?id=' + id, { })

View File

@ -15,11 +15,11 @@
<image :src="item.picUrls[0]" mode='widthFix' />
</view>
<view class="product-button">
<view class="product-text">{{ item.sellPoint }}{{ item.name }}</view>
<view class="product-text">{{ item.name }}</view>
<view class="product-price-button">
<text class="product-price">
<text class="price-size">{{ towNumber(item.price) }}</text></text>
<text class="product-like-ccount">销量 {{ item.likeCount }}</text>
<text class="price-size">{{ towNumber(item.minPrice) }}</text></text>
<text class="product-like-count">销量 {{ item.salesCount }}</text>
</view>
</view>
</view>
@ -144,7 +144,7 @@
}
}
.product-like-ccount {
.product-like-count {
font-size: 16rpx;
margin-left: 10rpx;
}

View File

@ -305,9 +305,7 @@ export default {
},
methods: {
loadProductData() {
let param = {}
param.spuId = this.product.id
productSpu(param).then(res => {
productSpu(this.product.id).then(res => {
this.product.images = res.data.picUrls;
this.product.sku = res.data.skus;
this.product.desc = res.data.description.replace(/<[^>]*>/g,'');