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());
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.coupon;
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.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.*;
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert;
@ -59,7 +60,8 @@ public class AppCouponController {
@Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表")
public CommonResult<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) {
// todo: 优化优惠金额倒序
return success(CouponConvert.INSTANCE.convertList(couponService.getMatchCouponList(getLoginUserId(), matchReqVO)));
List<CouponDO> list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO);
return success(BeanUtils.toBean(list, AppCouponMatchRespVO.class));
}
@GetMapping("/page")
@ -68,7 +70,16 @@ public class AppCouponController {
public CommonResult<PageResult<AppCouponRespVO>> getCouponPage(AppCouponPageReqVO pageReqVO) {
PageResult<CouponDO> pageResult = couponService.getCouponPage(
CouponConvert.INSTANCE.convert(pageReqVO, Collections.singleton(getLoginUserId())));
return success(CouponConvert.INSTANCE.convertAppPage(pageResult));
return success(BeanUtils.toBean(pageResult, AppCouponRespVO.class));
}
@GetMapping("/get")
@Operation(summary = "获得优惠劵")
@Parameter(name = "id", description = "优惠劵编号", required = true, example = "1024")
@PreAuthenticated
public CommonResult<AppCouponRespVO> getCoupon(@RequestParam("id") Long id) {
CouponDO coupon = couponService.getCoupon(getLoginUserId(), id);
return success(BeanUtils.toBean(coupon, AppCouponRespVO.class));
}
@GetMapping(value = "/get-unused-count")

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.app.coupon;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
@ -43,6 +44,20 @@ public class AppCouponTemplateController {
@Resource
private ProductSpuApi productSpuApi;
@GetMapping("/get")
@Operation(summary = "获得优惠劵模版")
@Parameter(name = "id", description = "优惠券模板编号", required = true, example = "1024")
public CommonResult<AppCouponTemplateRespVO> getCouponTemplate(Long id) {
CouponTemplateDO template = couponTemplateService.getCouponTemplate(id);
if (template == null) {
return success(null);
}
// 处理是否可领取
Map<Long, Boolean> canCanTakeMap = couponService.getUserCanCanTakeMap(getLoginUserId(), List.of(template));
return success(BeanUtils.toBean(template, AppCouponTemplateRespVO.class)
.setCanTake(canCanTakeMap.get(template.getId())));
}
@GetMapping("/list")
@Operation(summary = "获得优惠劵模版列表")
@Parameters({

View File

@ -5,6 +5,7 @@ import lombok.Data;
import jakarta.validation.constraints.Min;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "用户 App - 优惠劵 Response VO")
@Data
@ -19,10 +20,15 @@ public class AppCouponRespVO {
@Schema(description = "优惠劵状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") // 参见 CouponStatusEnum 枚举
private Integer status;
@Schema(description = "是否设置满多少金额可用", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
// 单位0 - 不限制
@Schema(description = "是否设置满多少金额可用", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") // 单位0 - 不限制
private Integer usePrice;
@Schema(description = "商品范围", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer productScope;
@Schema(description = "商品范围编号的数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private List<Long> productScopeValues;
@Schema(description = "固定日期 - 生效开始时间")
private LocalDateTime validStartTime;

View File

@ -1,10 +1,14 @@
package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.Min;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "用户 App - 优惠劵模板 Response VO")
@Data
@ -19,10 +23,15 @@ public class AppCouponTemplateRespVO {
@Schema(description = "每人限领个数", requiredMode = Schema.RequiredMode.REQUIRED, example = "66") // -1 - 则表示不限制
private Integer takeLimitCount;
@Schema(description = "是否设置满多少金额可用", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
// 单位0 - 不限制
@Schema(description = "是否设置满多少金额可用", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") // 单位0 - 不限制
private Integer usePrice;
@Schema(description = "商品范围", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer productScope;
@Schema(description = "商品范围编号的数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private List<Long> productScopeValues;
@Schema(description = "生效日期类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer validityType;

View File

@ -58,8 +58,4 @@ public interface CouponConvert {
CouponPageReqVO convert(AppCouponPageReqVO pageReqVO, Collection<Long> userIds);
PageResult<AppCouponRespVO> convertAppPage(PageResult<CouponDO> pageResult);
List<AppCouponMatchRespVO> convertList(List<CouponDO> list);
}

View File

@ -168,4 +168,13 @@ public interface CouponService {
*/
Map<Long, Boolean> getUserCanCanTakeMap(Long userId, List<CouponTemplateDO> templates);
/**
* 获得优惠劵
*
* @param userId 用户编号
* @param id 编号
* @return 优惠劵
*/
CouponDO getCoupon(Long userId, Long id);
}

View File

@ -315,6 +315,11 @@ public class CouponServiceImpl implements CouponService {
userIds.removeIf(userId -> MapUtil.getInt(userTakeCountMap, userId, 0) >= couponTemplate.getTakeLimitCount());
}
@Override
public CouponDO getCoupon(Long userId, Long id) {
return couponMapper.selectByIdAndUserId(id, userId);
}
/**
* 获得自身的代理对象解决 AOP 生效问题
*