trade:调整拼团活动列表接口

This commit is contained in:
YunaiV 2023-10-06 21:04:37 +08:00
parent a76760c419
commit 34bf360da6
15 changed files with 165 additions and 61 deletions

View File

@ -5,14 +5,14 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.*;
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -23,6 +23,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static cn.hutool.core.collection.CollectionUtil.newArrayList;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -36,6 +38,8 @@ public class CombinationActivityController {
@Resource
private CombinationActivityService combinationActivityService;
@Resource
private CombinationRecordService combinationRecordService;
@Resource
private ProductSpuApi productSpuApi;
@ -77,7 +81,7 @@ public class CombinationActivityController {
@GetMapping("/page")
@Operation(summary = "获得拼团活动分页")
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
public CommonResult<PageResult<CombinationActivityRespVO>> getCombinationActivityPage(
public CommonResult<PageResult<CombinationActivityPageItemRespVO>> getCombinationActivityPage(
@Valid CombinationActivityPageReqVO pageVO) {
// 查询拼团活动
PageResult<CombinationActivityDO> pageResult = combinationActivityService.getCombinationActivityPage(pageVO);
@ -85,12 +89,21 @@ public class CombinationActivityController {
return success(PageResult.empty(pageResult.getTotal()));
}
// 统计数据
Set<Long> activityIds = convertSet(pageResult.getList(), CombinationActivityDO::getId);
Map<Long, Integer> groupCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, null, CombinationRecordDO.HEAD_ID_GROUP);
Map<Long, Integer> groupSuccessCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, CombinationRecordStatusEnum.SUCCESS.getStatus(), CombinationRecordDO.HEAD_ID_GROUP);
Map<Long, Integer> recordCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, null, null);
// 拼接数据
List<CombinationProductDO> products = combinationActivityService.getCombinationProductsByActivityIds(
convertSet(pageResult.getList(), CombinationActivityDO::getId));
List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(
convertSet(pageResult.getList(), CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, products, spus));
return success(CombinationActivityConvert.INSTANCE.convertPage(pageResult, products,
groupCountMap, groupSuccessCountMap, recordCountMap, spus));
}
}

View File

@ -48,6 +48,9 @@ public class CombinationActivityBaseVO {
@NotNull(message = "开团人数不能为空")
private Integer userSize;
@Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Boolean virtualGroup = false; // TODO @puhui999这个字段界面没做呀
@Schema(description = "限制时长(小时)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "限制时长不能为空")
private Integer limitDuration;

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 拼团活动的分页项 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CombinationActivityPageItemRespVO extends CombinationActivityBaseVO {
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer status;
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<CombinationProductRespVO> products;
// ========== 商品字段 ==========
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // SPU name 读取
example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
// ========== 统计字段 ==========
@Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "33")
private Integer groupCount;
@Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
private Integer groupSuccessCount;
@Schema(description = "购买次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer recordCount;
}

View File

@ -15,8 +15,7 @@ public class CombinationActivityPageReqVO extends PageParam {
@Schema(description = "拼团名称", example = "赵六")
private String name;
@Schema(description = "活动状态0开启 1关闭", example = "0")
@Schema(description = "活动状态", example = "0")
private Integer status;
}

View File

@ -6,8 +6,6 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;
@ -20,30 +18,12 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO {
@Schema(description = "活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22901")
private Long id;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "618 大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "开团人数", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private Integer userSize;
@Schema(description = "开团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "33")
private Integer totalCount;
@Schema(description = "成团组数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
private Integer successCount;
@Schema(description = "虚拟成团", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
private Integer virtualGroup;
@Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer status;
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<CombinationProductRespVO> products;

View File

@ -18,16 +18,6 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "秒杀活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // SPU name 读取
example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
@Schema(description = "秒杀商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<SeckillProductRespVO> products;
@ -52,4 +42,16 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
// ========== 商品字段 ==========
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // SPU name 读取
example = "618大促")
private String spuName;
@Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png")
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // SPU marketPrice 读取
example = "50")
private Integer marketPrice;
}

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageItemRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO;
@ -53,19 +54,27 @@ public interface CombinationActivityConvert {
List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list);
PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page);
default PageResult<CombinationActivityRespVO> convertPage(PageResult<CombinationActivityDO> page,
List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) {
default PageResult<CombinationActivityPageItemRespVO> convertPage(PageResult<CombinationActivityDO> page,
List<CombinationProductDO> productList,
Map<Long, Integer> groupCountMap,
Map<Long, Integer> groupSuccessCountMap,
Map<Long, Integer> recordCountMap,
List<ProductSpuRespDTO> spuList) {
PageResult<CombinationActivityPageItemRespVO> pageResult = convertPage(page);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
PageResult<CombinationActivityRespVO> pageResult = convertPage(page);
pageResult.getList().forEach(item -> {
MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()));
MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())
.setMarketPrice(spu.getMarketPrice()));
item.setProducts(convertList2(productList));
// 设置统计字段
item.setGroupCount(groupCountMap.getOrDefault(item.getId(), 0))
.setGroupSuccessCount(groupSuccessCountMap.getOrDefault(item.getId(), 0))
.setRecordCount(recordCountMap.getOrDefault(item.getId(), 0));
});
return pageResult;
}
PageResult<CombinationActivityPageItemRespVO> convertPage(PageResult<CombinationActivityDO> page);
List<CombinationProductRespVO> convertList2(List<CombinationProductDO> productDOs);

View File

@ -59,22 +59,10 @@ public class CombinationActivityDO extends BaseDO {
* 几人团
*/
private Integer userSize;
/**
* 开团组数
*/
private Integer totalCount;
/**
* 成团组数
*/
private Integer successCount;
/**
* 参与人数
*/
private Integer orderUserCount;
/**
* 虚拟成团
*/
private Integer virtualGroup;
private Boolean virtualGroup;
/**
* 活动状态
*

View File

@ -28,6 +28,11 @@ import java.time.LocalDateTime;
@AllArgsConstructor
public class CombinationRecordDO extends BaseDO {
/**
* 团长编号 - 团长
*/
public static final Integer HEAD_ID_GROUP = 0;
/**
* 编号主键自增
*/
@ -84,6 +89,8 @@ public class CombinationRecordDO extends BaseDO {
* 团长编号
*
* 关联 {@link CombinationRecordDO#getId()}
*
* 如果是团长则它的值是 {@link #HEAD_ID_GROUP}
*/
private Long headId;
/**

View File

@ -1,11 +1,18 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.combination;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* 拼团记录 Mapper
@ -90,4 +97,22 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
.last("LIMIT " + count));
}
default Map<Long, Integer> selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(Collection<Long> activityIds,
Integer status, Integer headId) {
// SQL count 查询
List<Map<String, Object>> result = selectMaps(new QueryWrapper<CombinationRecordDO>()
.select("COUNT(DISTINCT(user_id)) AS recordCount, activity_id AS activityId")
.in("activity_id", activityIds)
.eq(status != null, "status", status)
.eq(headId != null, "head_id", headId)
.groupBy("activity_id"));
if (CollUtil.isEmpty(result)) {
return Collections.emptyMap();
}
// 转换数据
return CollectionUtils.convertMap(result,
record -> MapUtil.getLong(record, "activityId"),
record -> MapUtil.getInt(record, "recordCount" ));
}
}

View File

@ -101,7 +101,7 @@ public interface CombinationActivityService {
PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam);
/**
* 获取指定活动指定 sku 编号的商品
* 获取指定活动指定 sku 编号的商品
*
* @param activityId 活动编号
* @param skuId sku 编号

View File

@ -65,13 +65,11 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
// 插入拼团活动
CombinationActivityDO activity = CombinationActivityConvert.INSTANCE.convert(createReqVO)
.setStatus(CommonStatusEnum.ENABLE.getStatus())
.setTotalCount(0).setSuccessCount(0).setOrderUserCount(0).setVirtualGroup(0);
.setStatus(CommonStatusEnum.ENABLE.getStatus());
combinationActivityMapper.insert(activity);
// 插入商品
List<CombinationProductDO> products = CombinationActivityConvert.INSTANCE.convertList(createReqVO.getProducts(), activity);
combinationProductMapper.insertBatch(products);
// 返回
return activity.getId();
}

View File

@ -7,9 +7,13 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationA
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import javax.annotation.Nullable;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
// todo @PUHUI方法名还是带下 Combination
/**
* 拼团记录 Service 接口
*
@ -127,4 +131,16 @@ public interface CombinationRecordService {
*/
List<CombinationRecordDO> getRecordListByHeadId(Long headId);
/**
* 拼团活动获得拼团记录数量 Map
*
* @param activityIds 活动记录编号数组
* @param status 拼团状态允许空
* @param headId 团长编号允许空目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 可以设置
* @return 拼团记录数量 Map
*/
Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds,
@Nullable Integer status,
@Nullable Integer headId);
}

View File

@ -25,9 +25,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
@ -203,6 +206,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) {
// TODO puhui999:这里直接获得不适合调用校验的接口
return validateCombinationRecord(userId, orderId);
}
@ -245,4 +249,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
return recordMapper.selectList(CombinationRecordDO::getHeadId, headId);
}
@Override
public Map<Long, Integer> getCombinationRecordCountMapByActivity(Collection<Long> activityIds,
@Nullable Integer status, @Nullable Integer headId) {
return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId);
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
// TODO @puhui999单测可以后补下
/**
* 拼团活动的 {@link TradePriceCalculator} 实现类
*