mall:完善商品分类的 APP 后端接口

pull/2/head
YunaiV 2022-07-30 21:24:05 +08:00
parent 969c387764
commit efd4942129
8 changed files with 43 additions and 27 deletions

View File

@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCateg
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; 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.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -61,7 +61,7 @@ public class ProductCategoryController {
@PreAuthorize("@ss.hasPermission('product:category:query')") @PreAuthorize("@ss.hasPermission('product:category:query')")
public CommonResult<ProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) { public CommonResult<ProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) {
ProductCategoryDO category = categoryService.getProductCategory(id); ProductCategoryDO category = categoryService.getProductCategory(id);
return success(CategoryConvert.INSTANCE.convert(category)); return success(ProductCategoryConvert.INSTANCE.convert(category));
} }
@GetMapping("/list") @GetMapping("/list")
@ -70,7 +70,7 @@ public class ProductCategoryController {
public CommonResult<List<ProductCategoryRespVO>> getProductCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) { public CommonResult<List<ProductCategoryRespVO>> getProductCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) {
List<ProductCategoryDO> list = categoryService.getEnableProductCategoryList(treeListReqVO); List<ProductCategoryDO> list = categoryService.getEnableProductCategoryList(treeListReqVO);
list.sort(Comparator.comparing(ProductCategoryDO::getSort)); list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(CategoryConvert.INSTANCE.convertList(list)); return success(ProductCategoryConvert.INSTANCE.convertList(list));
} }
} }

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.product.controller.app.category; package cn.iocoder.yudao.module.product.controller.app.category;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; 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.controller.app.category.vo.AppCategoryRespVO;
import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; 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.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -29,10 +29,10 @@ public class AppCategoryController {
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("获得商品分类列表") @ApiOperation("获得商品分类列表")
public CommonResult<List<AppCategoryListRespVO>> listByQuery() { public CommonResult<List<AppCategoryRespVO>> getProductCategoryList() {
List<ProductCategoryDO> list = categoryService.getEnableProductCategoryList(); List<ProductCategoryDO> list = categoryService.getEnableProductCategoryList();
list.sort(Comparator.comparing(ProductCategoryDO::getSort)); list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(CategoryConvert.INSTANCE.convertList03(list)); return success(ProductCategoryConvert.INSTANCE.convertList03(list));
} }
} }

View File

@ -8,8 +8,8 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@Data @Data
@ApiModel(value = "App - 商品分类 Response VO") @ApiModel(value = "用户 APP - 商品分类 Response VO")
public class AppCategoryListRespVO { public class AppCategoryRespVO {
@ApiModelProperty(value = "分类编号", required = true, example = "2") @ApiModelProperty(value = "分类编号", required = true, example = "2")
private Long id; private Long id;

View File

@ -3,7 +3,7 @@ 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.ProductCategoryCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; 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.admin.category.vo.ProductCategoryUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryListRespVO; import cn.iocoder.yudao.module.product.controller.app.category.vo.AppCategoryRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -16,9 +16,9 @@ import java.util.List;
* @author * @author
*/ */
@Mapper @Mapper
public interface CategoryConvert { public interface ProductCategoryConvert {
CategoryConvert INSTANCE = Mappers.getMapper(CategoryConvert.class); ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
ProductCategoryDO convert(ProductCategoryCreateReqVO bean); ProductCategoryDO convert(ProductCategoryCreateReqVO bean);
@ -28,5 +28,5 @@ public interface CategoryConvert {
List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list); List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list);
List<AppCategoryListRespVO> convertList03(List<ProductCategoryDO> list); List<AppCategoryRespVO> convertList03(List<ProductCategoryDO> list);
} }

View File

@ -9,9 +9,9 @@ import lombok.*;
/** /**
* DO * DO
* *
* *
* 1{@link #parentId} 0 * 1{@link #parentId} 0
* 2{@link #parentId} * 2 + {@link #parentId} 0
* *
* @author * @author
*/ */
@ -46,7 +46,7 @@ public class ProductCategoryDO extends BaseDO {
* *
* *
* 200 x 100 * 200 x 100
* 100 x 100 * + 100 x 100
*/ */
private String picUrl; private String picUrl;
/** /**

View File

@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryCreateReqVO; 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.ProductCategoryListReqVO;
import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO; import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.category.CategoryConvert; 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.dal.dataobject.category.ProductCategoryDO;
import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper; import cn.iocoder.yudao.module.product.dal.mysql.category.ProductCategoryMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -37,7 +37,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
validateParentProductCategory(createReqVO.getParentId()); validateParentProductCategory(createReqVO.getParentId());
// 插入 // 插入
ProductCategoryDO category = CategoryConvert.INSTANCE.convert(createReqVO); ProductCategoryDO category = ProductCategoryConvert.INSTANCE.convert(createReqVO);
productCategoryMapper.insert(category); productCategoryMapper.insert(category);
// 返回 // 返回
return category.getId(); return category.getId();
@ -51,7 +51,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
validateParentProductCategory(updateReqVO.getParentId()); validateParentProductCategory(updateReqVO.getParentId());
// 更新 // 更新
ProductCategoryDO updateObj = CategoryConvert.INSTANCE.convert(updateReqVO); ProductCategoryDO updateObj = ProductCategoryConvert.INSTANCE.convert(updateReqVO);
productCategoryMapper.updateById(updateObj); productCategoryMapper.updateById(updateObj);
} }

View File

@ -61,15 +61,15 @@
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="上级分类" prop="parentId"> <el-form-item label="上级分类" prop="parentId">
<el-select v-model="form.parentId" placeholder="请选择上级分类" clearable size="small"> <Treeselect v-model="form.parentId" :options="parentCategoryOptions" :normalizer="normalizer"
<el-option :key="0" label="顶级分类" :value="0"/> :show-count="true"
<el-option v-for="item in list.filter(v => v.parentId === 0)" :key="item.id" :label="item.name" :value="item.id"/> :defaultExpandLevel="1"
</el-select> placeholder="上级分类"/>
</el-form-item> </el-form-item>
<el-form-item label="分类名称" prop="name"> <el-form-item label="分类名称" prop="name">
<el-input v-model="form.name" placeholder="请输入分类名称"/> <el-input v-model="form.name" placeholder="请输入分类名称"/>
</el-form-item> </el-form-item>
<el-form-item label="分类图片" prop="bannerUrl"> <el-form-item label="分类图片" prop="picUrl">
<ImageUpload v-model="form.picUrl" :limit="1" :is-show-tip="false" /> <ImageUpload v-model="form.picUrl" :limit="1" :is-show-tip="false" />
<div v-if="form.parentId === 0" style="font-size: 10px"> 200x100 </div> <div v-if="form.parentId === 0" style="font-size: 10px"> 200x100 </div>
<div v-else style="font-size: 10px">推荐 100x100 图片分辨率</div> <div v-else style="font-size: 10px">推荐 100x100 图片分辨率</div>
@ -164,6 +164,11 @@ export default {
getProductCategoryList(params).then(response => { getProductCategoryList(params).then(response => {
this.list = this.handleTree(response.data, "id", "parentId"); this.list = this.handleTree(response.data, "id", "parentId");
this.loading = false; this.loading = false;
//
this.parentCategoryOptions = [];
const menu = {id: 0, name: '顶级分类', children: []};
menu.children = this.handleTree(response.data, "id", "parentId");
this.parentCategoryOptions.push(menu);
}); });
}, },
/** 取消按钮 */ /** 取消按钮 */
@ -202,6 +207,17 @@ export default {
this.refreshTable = true; this.refreshTable = true;
}); });
}, },
/** 转换菜单数据结构 */
normalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.id,
label: node.name,
children: node.children
};
},
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset();

View File

@ -20,7 +20,7 @@
<!-- 右侧分类内容 --> <!-- 右侧分类内容 -->
<scroll-view scroll-y="true" class="box-right"> <scroll-view scroll-y="true" class="box-right">
<view class="category-image"> <view class="category-image">
<image :showLoading="true" :src="categoryList[currentIndex].bannerUrl" mode='widthFix' @click="click"></image> <image :showLoading="true" :src="categoryList[currentIndex].picUrl" mode='widthFix' @click="click"></image>
</view> </view>
<view class="sub-category-box" v-for="(item, index) in categoryList[currentIndex].children" :key="item.id"> <view class="sub-category-box" v-for="(item, index) in categoryList[currentIndex].children" :key="item.id">
@ -33,8 +33,8 @@
<u-grid col="3"> <u-grid col="3">
<u-grid-item v-for="(subItem, subIndex) in item.children" :key="subItem.id"> <u-grid-item v-for="(subItem, subIndex) in item.children" :key="subItem.id">
<view class="sub-category-item" @click="handleCategory(item, subIndex)"> <view class="sub-category-item" @click="handleCategory(item, subIndex)">
<u-icon name="photo" :size="80" v-if="subItem.bannerUrl === null"></u-icon> <u-icon name="photo" :size="80" v-if="subItem.picUrl === null"></u-icon>
<image :src="item.bannerUrl" v-if="subItem.bannerUrl != null" mode='widthFix' /> <image :src="item.picUrl" v-if="subItem.picUrl != null" mode='widthFix' />
<text class="sub-category-title">{{ subItem.name }}</text> <text class="sub-category-title">{{ subItem.name }}</text>
</view> </view>
</u-grid-item> </u-grid-item>