diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java new file mode 100644 index 000000000..201690717 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/AppCategoryController.java @@ -0,0 +1,40 @@ +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.AppCategoryListRespVO; +import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; +import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; +import cn.iocoder.yudao.module.product.service.category.CategoryService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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; + +@Api(tags = "用户 APP - 商品分类") +@RestController +@RequestMapping("/product/category") +@Validated +public class AppCategoryController { + + @Resource + private CategoryService categoryService; + + @GetMapping("/list") + @ApiOperation("获得商品分类列表") + public CommonResult> listByQuery() { + List list = categoryService.getCategoryList(); + list.sort(Comparator.comparing(CategoryDO::getSort)); + return success(CategoryConvert.INSTANCE.convertList03(list)); + } + + + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/vo/AppCategoryListRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/vo/AppCategoryListRespVO.java new file mode 100644 index 000000000..e50c53e4d --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/category/vo/AppCategoryListRespVO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.product.controller.app.category.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "App - 商品分类 列表 Request VO", description = "参数和 CategoryBaseVO 是一致的") +public class AppCategoryListRespVO { + + @ApiModelProperty(value = "分类编号", required = true, example = "2") + private Long id; + + @ApiModelProperty(value = "父分类编号", required = true, example = "1") + @NotNull(message = "父分类编号不能为空") + private Long parentId; + + @ApiModelProperty(value = "分类名称", required = true, example = "办公文具") + @NotBlank(message = "分类名称不能为空") + private String name; + + @ApiModelProperty(value = "分类图标") + @NotBlank(message = "分类图标不能为空") + private String icon; + + @ApiModelProperty(value = "分类图片", required = true) + @NotBlank(message = "分类图片不能为空") + private String bannerUrl; + + @ApiModelProperty(value = "分类排序", required = true, example = "1") + private Integer sort; + + @ApiModelProperty(value = "分类描述", required = true, example = "描述") + private String description; +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java new file mode 100644 index 000000000..e56aa3813 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.product.controller.app.spu; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.admin.spu.vo.SpuRespVO; +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.service.spu.ProductSpuService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Api(tags = "用户 APP - 商品spu") +@RestController +@RequestMapping("/product/spu") +@Validated +public class AppProductSpuController { + + @Resource + private ProductSpuService spuService; + + @GetMapping("/page") + @ApiOperation("获得商品spu分页") + public CommonResult> getSpuPage(@Valid AppSpuPageReqVO pageVO) { + return success(spuService.getSpuPage(pageVO)); + } +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageReqVO.java new file mode 100644 index 000000000..38ed4975e --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageReqVO.java @@ -0,0 +1,18 @@ +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; +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java new file mode 100644 index 000000000..0f77fd516 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppSpuPageRespVO.java @@ -0,0 +1,52 @@ +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 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 Boolean status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/CategoryConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/CategoryConvert.java index 2b2cfe99c..9099067e2 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/CategoryConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/category/CategoryConvert.java @@ -4,6 +4,7 @@ import java.util.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryListRespVO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; @@ -31,4 +32,5 @@ public interface CategoryConvert { List convertList02(List list); + List convertList03(List list); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index 92efaf0e8..513e5e50b 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -4,6 +4,8 @@ import java.util.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppSpuPageRespVO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; @@ -40,6 +42,11 @@ public interface ProductSpuConvert { List convertList02(List list); + SpuPageReqVO convert(AppSpuPageReqVO bean); + + @Mapping(source = "picUrls", target = "picUrls", qualifiedByName = "tokenizeToStringArray") + AppSpuPageRespVO convertAppResp(ProductSpuDO list); + @Named("tokenizeToStringArray") default List translatePicUrlsArrayFromString(String picUrls) { return Arrays.asList(StringUtils.tokenizeToStringArray(picUrls, ",")); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java index 4df2f19f9..92c8463dd 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.product.service.category; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.category.vo.*; +import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryListRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import javax.validation.Valid; @@ -83,4 +84,11 @@ public interface CategoryService { * @param categoryId 分类id */ void validatedCategoryById(Long categoryId); + + /** + * app端获得商品分类列表 + * + * @return 商品分类列表 + */ + List getCategoryList(); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java index 3fa441b66..85e456b2c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/category/CategoryServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.service.category; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.ErrorCode; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -13,6 +14,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; @@ -106,4 +108,13 @@ public class CategoryServiceImpl implements CategoryService { return categoryMapper.selectList(treeListReqVO); } + @Override + public List getCategoryList() { + return categoryMapper.selectList() + .stream() + .filter(v->v.getStatus().equals(CommonStatusEnum.ENABLE.getStatus())) + .collect(Collectors.toList()); + } + + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java index e4fc47d56..e66f93fd0 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.product.service.spu; import java.util.*; import javax.validation.*; 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.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -67,4 +69,13 @@ public interface ProductSpuService { */ List getSpuList(SpuExportReqVO exportReqVO); + /** + * 获得商品spu分页 + * + * @param pageReqVO 分页查询 + * @return 商品spu分页 + */ + PageResult getSpuPage(AppSpuPageReqVO pageReqVO); + + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index eb48bed25..0ff02e66f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -8,9 +8,10 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateReqVO; 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.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; -import cn.iocoder.yudao.module.product.dal.dataobject.category.CategoryDO; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; @@ -175,4 +176,17 @@ public class ProductSpuServiceImpl implements ProductSpuService { return ProductSpuMapper.selectList(exportReqVO); } + @Override + public PageResult getSpuPage(AppSpuPageReqVO pageReqVO) { + PageResult productSpuDOPageResult = ProductSpuMapper.selectPage(ProductSpuConvert.INSTANCE.convert(pageReqVO)); + PageResult pageResult = new PageResult<>(); + List collect = productSpuDOPageResult.getList() + .stream() + .map(ProductSpuConvert.INSTANCE::convertAppResp) + .collect(Collectors.toList()); + pageResult.setList(collect); + pageResult.setTotal(productSpuDOPageResult.getTotal()); + return pageResult; + } + } diff --git a/yudao-ui-app/api/category.js b/yudao-ui-app/api/category.js new file mode 100644 index 000000000..630efd29d --- /dev/null +++ b/yudao-ui-app/api/category.js @@ -0,0 +1,5 @@ +//请求工具参考https://ext.dcloud.net.cn/plugin?id=392 +const { http } = uni.$u + +// 查询分类列表 +export const categoryListData = params => http.get('product/category/list', { params }) diff --git a/yudao-ui-app/api/product.js b/yudao-ui-app/api/product.js new file mode 100644 index 000000000..bebd27ca9 --- /dev/null +++ b/yudao-ui-app/api/product.js @@ -0,0 +1,5 @@ +//请求工具参考https://ext.dcloud.net.cn/plugin?id=392 +const { http } = uni.$u + +// 查询商品spu列表 +export const productSpuPage = params => http.get('/product/spu/page', { params }) diff --git a/yudao-ui-app/pages.json b/yudao-ui-app/pages.json index 3ef50a0a9..c6daa7423 100644 --- a/yudao-ui-app/pages.json +++ b/yudao-ui-app/pages.json @@ -12,6 +12,14 @@ "navigationBarTitleText": "分类" } }, + { + "path": "pages/category/product-list", + "style": { + "navigationBarTitleText": "", + "navigationStyle": "custom", + "navigationBarTextStyle": "white" + } + }, { "path": "pages/cart/cart", "style": { @@ -112,7 +120,7 @@ "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "yudao-ui-app", - "navigationBarBackgroundColor": "#F8F8F8", - "backgroundColor": "#FFFFFF" + "navigationBarBackgroundColor": "#ffffff", + "backgroundColor": "#ffffff" } } diff --git a/yudao-ui-app/pages/category/category.vue b/yudao-ui-app/pages/category/category.vue index 8e0decdac..70b993273 100644 --- a/yudao-ui-app/pages/category/category.vue +++ b/yudao-ui-app/pages/category/category.vue @@ -1,176 +1,205 @@ diff --git a/yudao-ui-app/pages/category/product-list.vue b/yudao-ui-app/pages/category/product-list.vue new file mode 100644 index 000000000..d75867fc5 --- /dev/null +++ b/yudao-ui-app/pages/category/product-list.vue @@ -0,0 +1,161 @@ + + + + +