MALL:1)优惠劵增加返回使用范围;2)商品分类增加 id 批量查询

This commit is contained in:
YunaiV
2023-12-16 18:32:54 +08:00
parent 07e610b3f7
commit e1bb546460
15 changed files with 107 additions and 15 deletions

View File

@@ -1,18 +1,25 @@
package cn.iocoder.yudao.module.product.controller.app.category;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
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.Parameter;
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 jakarta.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -32,7 +39,19 @@ public class AppCategoryController {
public CommonResult<List<AppCategoryRespVO>> getProductCategoryList() {
List<ProductCategoryDO> list = categoryService.getEnableCategoryList();
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(ProductCategoryConvert.INSTANCE.convertList03(list));
return success(BeanUtils.toBean(list, AppCategoryRespVO.class));
}
@GetMapping("/list-by-ids")
@Operation(summary = "获得商品分类列表,指定编号")
@Parameter(name = "ids", description = "商品分类编号数组", required = true)
public CommonResult<List<AppCategoryRespVO>> getProductCategoryList(@RequestParam("ids") List<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return success(Collections.emptyList());
}
List<ProductCategoryDO> list = categoryService.getEnableCategoryList(ids);
list.sort(Comparator.comparing(ProductCategoryDO::getSort));
return success(BeanUtils.toBean(list, AppCategoryRespVO.class));
}
}

View File

@@ -78,9 +78,7 @@ public class AppProductSpuController {
@GetMapping("/list-by-ids")
@Operation(summary = "获得商品 SPU 列表")
@Parameters({
@Parameter(name = "ids", description = "编号列表", required = true)
})
@Parameter(name = "ids", description = "编号列表", required = true)
public CommonResult<List<AppProductSpuPageRespVO>> getSpuList(@RequestParam("ids") Set<Long> ids) {
List<ProductSpuDO> list = productSpuService.getSpuList(ids);
if (CollUtil.isEmpty(list)) {

View File

@@ -18,6 +18,7 @@ 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 SORT_FIELD_CREATE_TIME = "createTime";
public static final String RECOMMEND_TYPE_HOT = "hot";
public static final String RECOMMEND_TYPE_BENEFIT = "benefit";

View File

@@ -28,5 +28,4 @@ public interface ProductCategoryConvert {
List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list);
List<AppCategoryRespVO> convertList03(List<ProductCategoryDO> list);
}

View File

@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCateg
import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
@@ -32,4 +33,10 @@ public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> {
return selectList(ProductCategoryDO::getStatus, status);
}
default List<ProductCategoryDO> selectListByIdAndStatus(Collection<Long> ids, Integer status) {
return selectList(new LambdaQueryWrapperX<ProductCategoryDO>()
.in(ProductCategoryDO::getId, ids)
.eq(ProductCategoryDO::getStatus, status));
}
}

View File

@@ -84,6 +84,9 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
} else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_PRICE)) {
query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getPrice)
.orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId);
} else if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_CREATE_TIME)) {
query.orderBy(true, pageReqVO.getSortAsc(), ProductSpuDO::getCreateTime)
.orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId);
} else {
query.orderByDesc(ProductSpuDO::getSort).orderByDesc(ProductSpuDO::getId);
}

View File

@@ -76,6 +76,14 @@ public interface ProductCategoryService {
*/
List<ProductCategoryDO> getEnableCategoryList();
/**
* 获得开启状态的商品分类列表,指定编号
*
* @param ids 商品分类编号数组
* @return 商品分类列表
*/
List<ProductCategoryDO> getEnableCategoryList(List<Long> ids);
/**
* 校验商品分类是否有效。如下情况,视为无效:
* 1. 商品分类编号不存在
@@ -84,4 +92,5 @@ public interface ProductCategoryService {
* @param ids 商品分类编号数组
*/
void validateCategoryList(Collection<Long> ids);
}

View File

@@ -170,4 +170,9 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
return productCategoryMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus());
}
@Override
public List<ProductCategoryDO> getEnableCategoryList(List<Long> ids) {
return productCategoryMapper.selectListByIdAndStatus(ids, CommonStatusEnum.ENABLE.getStatus());
}
}