Commit dd82f13c03560ab8d22fb74d49533a2f8dfc9a60

Authored by puhui999
1 parent e251f2f5

【功能完善】商城: APP 积分商城活动完善 app-api 接口

yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
... ... @@ -290,6 +290,15 @@ public class CollectionUtils {
290 290 return valueFunc.apply(t);
291 291 }
292 292  
  293 + public static <T, V extends Comparable<? super V>> T getMinPropertyObj(List<T> from, Function<T, V> valueFunc) {
  294 + if (CollUtil.isEmpty(from)) {
  295 + return null;
  296 + }
  297 + assert from.size() > 0; // 断言,避免告警
  298 + return from.stream().min(Comparator.comparing(valueFunc)).get();
  299 + }
  300 +
  301 +
293 302 public static <T, V extends Comparable<? super V>> V getSumValue(Collection<T> from, Function<T, V> valueFunc,
294 303 BinaryOperator<V> accumulator) {
295 304 return getSumValue(from, valueFunc, accumulator, null);
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/PointActivityController.java
... ... @@ -28,8 +28,7 @@ import java.util.List;
28 28 import java.util.Map;
29 29  
30 30 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
31   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
32   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  31 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
33 32  
34 33 @Tag(name = "管理后台 - 积分商城活动")
35 34 @RestController
... ... @@ -108,7 +107,10 @@ public class PointActivityController {
108 107 convertSet(pageResult.getList(), PointActivityDO::getSpuId));
109 108 PageResult<PointActivityRespVO> result = BeanUtils.toBean(pageResult, PointActivityRespVO.class);
110 109 result.getList().forEach(activity -> {
111   - activity.setProducts(BeanUtils.toBean(productsMap.get(activity.getId()), PointProductRespVO.class));
  110 + // 设置 product 信息
  111 + PointProductDO minProduct = getMinPropertyObj(productsMap.get(activity.getId()), PointProductDO::getPoint);
  112 + assert minProduct != null;
  113 + activity.setPoint(minProduct.getPoint()).setPrice(minProduct.getPrice());
112 114 MapUtils.findAndThen(spuMap, activity.getSpuId(),
113 115 spu -> activity.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
114 116  
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityRespVO.java
... ... @@ -63,9 +63,6 @@ public class PointActivityRespVO {
63 63  
64 64 //======================= 显示所需兑换积分最少的 sku 信息 =======================
65 65  
66   - @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926")
67   - private Integer maxCount;
68   -
69 66 @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED)
70 67 private Integer point;
71 68  
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/point/AppPointActivityController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.point;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjUtil;
  5 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  6 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  9 +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
  10 +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
  11 +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO;
  12 +import cn.iocoder.yudao.module.promotion.controller.app.point.vo.AppPointActivityDetailRespVO;
  13 +import cn.iocoder.yudao.module.promotion.controller.app.point.vo.AppPointActivityPageReqVO;
  14 +import cn.iocoder.yudao.module.promotion.controller.app.point.vo.AppPointActivityRespVO;
  15 +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO;
  16 +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointProductDO;
  17 +import cn.iocoder.yudao.module.promotion.service.point.PointActivityService;
  18 +import io.swagger.v3.oas.annotations.Operation;
  19 +import io.swagger.v3.oas.annotations.Parameter;
  20 +import io.swagger.v3.oas.annotations.tags.Tag;
  21 +import jakarta.annotation.Resource;
  22 +import org.springframework.validation.annotation.Validated;
  23 +import org.springframework.web.bind.annotation.GetMapping;
  24 +import org.springframework.web.bind.annotation.RequestMapping;
  25 +import org.springframework.web.bind.annotation.RequestParam;
  26 +import org.springframework.web.bind.annotation.RestController;
  27 +
  28 +import java.util.Collections;
  29 +import java.util.List;
  30 +import java.util.Map;
  31 +
  32 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  33 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
  34 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
  35 +
  36 +@Tag(name = "用户 App - 积分商城活动")
  37 +@RestController
  38 +@RequestMapping("/promotion/point-activity")
  39 +@Validated
  40 +public class AppPointActivityController {
  41 +
  42 + @Resource
  43 + private PointActivityService pointActivityService;
  44 +
  45 + @Resource
  46 + private ProductSpuApi productSpuApi;
  47 +
  48 + @GetMapping("/page")
  49 + @Operation(summary = "获得积分商城活动分页")
  50 + public CommonResult<PageResult<AppPointActivityRespVO>> getPointActivityPage(AppPointActivityPageReqVO pageReqVO) {
  51 + // 1. 查询满足当前阶段的活动
  52 + PageResult<PointActivityDO> pageResult = pointActivityService.getPointActivityPage(
  53 + BeanUtils.toBean(pageReqVO, PointActivityPageReqVO.class));
  54 + if (CollUtil.isEmpty(pageResult.getList())) {
  55 + return success(PageResult.empty(pageResult.getTotal()));
  56 + }
  57 +
  58 + // 2. 拼接数据
  59 + List<AppPointActivityRespVO> resultList = buildAppPointActivityRespVOList(pageResult.getList());
  60 + return success(new PageResult<>(resultList, pageResult.getTotal()));
  61 + }
  62 +
  63 + @GetMapping("/get-detail")
  64 + @Operation(summary = "获得积分商城活动明细")
  65 + @Parameter(name = "id", description = "活动编号", required = true, example = "1024")
  66 + public CommonResult<AppPointActivityDetailRespVO> getPointActivity(@RequestParam("id") Long id) {
  67 + // 1. 获取活动
  68 + PointActivityDO activity = pointActivityService.getPointActivity(id);
  69 + if (activity == null
  70 + || ObjUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
  71 + return success(null);
  72 + }
  73 +
  74 + // 2. 拼接数据
  75 + List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(Collections.singletonList(id));
  76 + AppPointActivityDetailRespVO respVO = BeanUtils.toBean(activity, AppPointActivityDetailRespVO.class);
  77 + respVO.setProducts(BeanUtils.toBean(products, AppPointActivityDetailRespVO.Product.class));
  78 + return success(respVO);
  79 + }
  80 +
  81 + @GetMapping("/list-by-ids")
  82 + @Operation(summary = "获得拼团活动列表,基于活动编号数组")
  83 + @Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
  84 + public CommonResult<List<AppPointActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
  85 + // 1. 获得开启的活动列表
  86 + List<PointActivityDO> activityList = pointActivityService.getPointActivityListByIds(ids);
  87 + activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
  88 + if (CollUtil.isEmpty(activityList)) {
  89 + return success(Collections.emptyList());
  90 + }
  91 + // 2. 拼接返回
  92 + List<AppPointActivityRespVO> result = buildAppPointActivityRespVOList(activityList);
  93 + return success(result);
  94 + }
  95 +
  96 + private List<AppPointActivityRespVO> buildAppPointActivityRespVOList(List<PointActivityDO> activityList) {
  97 + List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(
  98 + convertSet(activityList, PointActivityDO::getId));
  99 + Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId);
  100 + Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpusMap(
  101 + convertSet(activityList, PointActivityDO::getSpuId));
  102 + List<AppPointActivityRespVO> result = BeanUtils.toBean(activityList, AppPointActivityRespVO.class);
  103 + result.forEach(activity -> {
  104 + // 设置 product 信息
  105 + PointProductDO minProduct = getMinPropertyObj(productsMap.get(activity.getId()), PointProductDO::getPoint);
  106 + assert minProduct != null;
  107 + activity.setPoint(minProduct.getPoint()).setPrice(minProduct.getPrice());
  108 + findAndThen(spuMap, activity.getSpuId(),
  109 + spu -> activity.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
  110 + });
  111 + return result;
  112 + }
  113 +
  114 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/point/vo/AppPointActivityDetailRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.point.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import java.util.List;
  7 +
  8 +@Schema(description = "用户 App - 积分商城活动的详细 Response VO")
  9 +@Data
  10 +public class AppPointActivityDetailRespVO {
  11 +
  12 + @Schema(description = "积分商城活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11373")
  13 + private Long id;
  14 +
  15 + @Schema(description = "积分商城活动商品", requiredMode = Schema.RequiredMode.REQUIRED, example = "19509")
  16 + private Long spuId;
  17 +
  18 + @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  19 + private Integer status;
  20 +
  21 + @Schema(description = "积分商城活动库存(剩余库存积分兑换时扣减)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  22 + private Integer stock;
  23 +
  24 + @Schema(description = "积分商城活动总库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  25 + private Integer totalStock;
  26 +
  27 + @Schema(description = "备注", example = "你说的对")
  28 + private String remark;
  29 +
  30 + @Schema(description = "商品信息数组", requiredMode = Schema.RequiredMode.REQUIRED)
  31 + private List<Product> products;
  32 +
  33 + @Schema(description = "商品信息")
  34 + @Data
  35 + public static class Product {
  36 +
  37 + @Schema(description = "积分商城商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31718")
  38 + private Long id;
  39 +
  40 + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2736")
  41 + private Long skuId;
  42 +
  43 + @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926")
  44 + private Integer count;
  45 +
  46 + @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED)
  47 + private Integer point;
  48 +
  49 + @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860")
  50 + private Integer price;
  51 +
  52 + @Schema(description = "积分商城商品库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  53 + private Integer stock;
  54 +
  55 + }
  56 +
  57 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/point/vo/AppPointActivityPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.point.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +@Schema(description = "用户 App - 积分商城活动分页 Request VO")
  10 +@Data
  11 +@EqualsAndHashCode(callSuper = true)
  12 +@ToString(callSuper = true)
  13 +public class AppPointActivityPageReqVO extends PageParam {
  14 +
  15 +
  16 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/point/vo/AppPointActivityRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.app.point.vo;
  2 +
  3 +import com.alibaba.excel.annotation.ExcelProperty;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +
  7 +import java.time.LocalDateTime;
  8 +
  9 +@Schema(description = "用户 App - 积分商城活动 Response VO")
  10 +@Data
  11 +public class AppPointActivityRespVO {
  12 +
  13 + @Schema(description = "积分商城活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11373")
  14 + @ExcelProperty("积分商城活动编号")
  15 + private Long id;
  16 +
  17 + @Schema(description = "积分商城活动商品", requiredMode = Schema.RequiredMode.REQUIRED, example = "19509")
  18 + @ExcelProperty("积分商城活动商品")
  19 + private Long spuId;
  20 +
  21 + @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  22 + @ExcelProperty("活动状态")
  23 + private Integer status;
  24 +
  25 + @Schema(description = "积分商城活动库存(剩余库存积分兑换时扣减)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  26 + @ExcelProperty("积分商城活动库存(剩余库存积分兑换时扣减)")
  27 + private Integer stock;
  28 +
  29 + @Schema(description = "积分商城活动总库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  30 + @ExcelProperty("积分商城活动总库存")
  31 + private Integer totalStock;
  32 +
  33 + @Schema(description = "备注", example = "你说的对")
  34 + @ExcelProperty("备注")
  35 + private String remark;
  36 +
  37 + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED)
  38 + @ExcelProperty("排序")
  39 + private Integer sort;
  40 +
  41 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  42 + @ExcelProperty("创建时间")
  43 + private LocalDateTime createTime;
  44 +
  45 + // ========== 商品字段 ==========
  46 +
  47 + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取
  48 + example = "618大促")
  49 + private String spuName;
  50 + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取
  51 + example = "https://www.iocoder.cn/xx.png")
  52 + private String picUrl;
  53 + @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取
  54 + example = "50")
  55 + private Integer marketPrice;
  56 +
  57 + //======================= 显示所需兑换积分最少的 sku 信息 =======================
  58 +
  59 + @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED)
  60 + private Integer point;
  61 +
  62 + @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860")
  63 + private Integer price;
  64 +
  65 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityService.java
... ... @@ -63,6 +63,14 @@ public interface PointActivityService {
63 63 PageResult<PointActivityDO> getPointActivityPage(PointActivityPageReqVO pageReqVO);
64 64  
65 65 /**
  66 + * 获得积分商城活动列表
  67 + *
  68 + * @param ids 活动编号
  69 + * @return 积分商城活动列表
  70 + */
  71 + List<PointActivityDO> getPointActivityListByIds(Collection<Long> ids);
  72 +
  73 + /**
66 74 * 获得活动商品
67 75 *
68 76 * @param activityIds 活动编号
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityServiceImpl.java
... ... @@ -235,6 +235,11 @@ public class PointActivityServiceImpl implements PointActivityService {
235 235 }
236 236  
237 237 @Override
  238 + public List<PointActivityDO> getPointActivityListByIds(Collection<Long> ids) {
  239 + return pointActivityMapper.selectBatchIds(ids);
  240 + }
  241 +
  242 + @Override
238 243 public List<PointProductDO> getPointProductListByActivityIds(Collection<Long> activityIds) {
239 244 return pointProductMapper.selectListByActivityId(activityIds);
240 245 }
... ...