拼团活动: 完善 app 端获取活动分页、列表、详情接口

This commit is contained in:
puhui999 2023-09-20 10:09:15 +08:00
parent 04a391cd4b
commit 1d2a6ad065
9 changed files with 139 additions and 95 deletions

View File

@ -56,7 +56,7 @@ public interface ErrorCodeConstants {
ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除");
ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭");
ErrorCode SECKILL_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1013008006, "秒杀失败,原因秒杀库存不足");
ErrorCode SECKILL_ACTIVITY_FAIL_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭");
ErrorCode SECKILL_ACTIVITY_APP_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭");
// ========== 秒杀时段 1013009000 ==========
ErrorCode SECKILL_CONFIG_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在");
@ -69,6 +69,7 @@ public interface ErrorCodeConstants {
ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE_NOT_UPDATE = new ErrorCode(1013010002, "拼团活动已关闭不能修改");
ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除");
ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010004, "拼团失败,原因:拼团活动已关闭");
ErrorCode COMBINATION_ACTIVITY_APP_STATUS_DISABLE = new ErrorCode(1013010005, "拼团活动已关闭");
// ========== 拼团记录 1013011000 ==========
ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013011000, "拼团不存在");

View File

@ -1,10 +1,19 @@
package cn.iocoder.yudao.module.promotion.controller.app.combination;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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.app.combination.vo.activity.AppCombinationActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO;
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.service.combination.CombinationActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -14,11 +23,14 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.ArrayList;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_APP_STATUS_DISABLE;
@Tag(name = "用户 APP - 拼团活动")
@RestController
@ -26,104 +38,55 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Validated
public class AppCombinationActivityController {
@Resource
private CombinationActivityService activityService;
@Resource
private ProductSpuApi spuApi;
@GetMapping("/list")
@Operation(summary = "获得拼团活动列表", description = "用于小程序首页")
// TODO 芋艿增加 Spring Cache
// TODO 芋艿缺少 swagger 注解
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppCombinationActivityRespVO>> getCombinationActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
List<AppCombinationActivityRespVO> activityList = new ArrayList<>();
AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO();
activity1.setId(1L);
activity1.setName("618 大拼团");
activity1.setUserSize(3);
activity1.setSpuId(2048L);
activity1.setPicUrl("https://static.iocoder.cn/mall/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
activity1.setMarketPrice(50);
activity1.setCombinationPrice(100);
activityList.add(activity1);
List<CombinationActivityDO> list = activityService.getCombinationActivityAppList(count);
if (CollUtil.isEmpty(list)) {
return success(CombinationActivityConvert.INSTANCE.convertAppList(list));
}
AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO();
activity2.setId(2L);
activity2.setName("双十一拼团");
activity2.setUserSize(5);
activity2.setSpuId(4096L);
activity2.setPicUrl("https://static.iocoder.cn/mall/132.jpeg");
activity2.setMarketPrice(100);
activity2.setCombinationPrice(200);
activityList.add(activity2);
return success(activityList);
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId));
// TODO 芋艿增加 Spring Cache
return success(CombinationActivityConvert.INSTANCE.convertAppList(list, spuList));
}
@GetMapping("/page")
@Operation(summary = "获得拼团活动分页")
public CommonResult<PageResult<AppCombinationActivityRespVO>> getCombinationActivityPage(PageParam pageParam) {
List<AppCombinationActivityRespVO> activityList = new ArrayList<>();
AppCombinationActivityRespVO activity1 = new AppCombinationActivityRespVO();
activity1.setId(1L);
activity1.setName("618 大拼团");
activity1.setUserSize(3);
activity1.setSpuId(2048L);
activity1.setPicUrl("商品图片地址");
activity1.setMarketPrice(50);
activity1.setCombinationPrice(100);
activityList.add(activity1);
PageResult<CombinationActivityDO> result = activityService.getCombinationActivityAppPage(pageParam);
if (CollUtil.isEmpty(result.getList())) {
return success(PageResult.empty(result.getTotal()));
}
AppCombinationActivityRespVO activity2 = new AppCombinationActivityRespVO();
activity2.setId(2L);
activity2.setName("双十一拼团");
activity2.setUserSize(5);
activity2.setSpuId(4096L);
activity2.setPicUrl("商品图片地址");
activity2.setMarketPrice(100);
activity2.setCombinationPrice(200);
activityList.add(activity2);
return success(new PageResult<>(activityList, 2L));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList));
}
@GetMapping("/get-detail")
@Operation(summary = "获得拼团活动明细")
@Parameter(name = "id", description = "活动编号", required = true, example = "1024")
public CommonResult<AppCombinationActivityDetailRespVO> getCombinationActivityDetail(@RequestParam("id") Long id) {
// TODO 芋艿如果禁用的时候需要抛出异常
AppCombinationActivityDetailRespVO obj = new AppCombinationActivityDetailRespVO();
// 设置其属性的值
obj.setId(id);
obj.setName("晚九点限时秒杀");
obj.setStatus(1);
obj.setStartTime(LocalDateTime.of(2023, 6, 15, 0, 0, 0));
obj.setEndTime(LocalDateTime.of(2023, 6, 20, 23, 59, 0));
obj.setUserSize(2);
obj.setSuccessCount(100);
obj.setSpuId(633L);
obj.setSingleLimitCount(2);
obj.setTotalLimitCount(3);
// 1获取活动
CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id);
if (combinationActivity == null) {
return success(null);
}
if (ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
throw exception(COMBINATION_ACTIVITY_APP_STATUS_DISABLE);
}
// 创建一个Product对象的列表
List<AppCombinationActivityDetailRespVO.Product> productList = new ArrayList<>();
// 创建三个新的Product对象并设置其属性的值
AppCombinationActivityDetailRespVO.Product product1 = new AppCombinationActivityDetailRespVO.Product();
product1.setSkuId(1L);
product1.setCombinationPrice(100);
// 将第一个Product对象添加到列表中
productList.add(product1);
// 创建第二个Product对象并设置其属性的值
AppCombinationActivityDetailRespVO.Product product2 = new AppCombinationActivityDetailRespVO.Product();
product2.setSkuId(2L);
product2.setCombinationPrice(200);
// 将第二个Product对象添加到列表中
productList.add(product2);
// 创建第三个Product对象并设置其属性的值
AppCombinationActivityDetailRespVO.Product product3 = new AppCombinationActivityDetailRespVO.Product();
product3.setSkuId(3L);
product3.setCombinationPrice(300);
// 将第三个Product对象添加到列表中
productList.add(product3);
// 将Product列表设置为对象的属性值
obj.setProducts(productList);
return success(obj);
// 2获取活动商品
List<CombinationProductDO> products = activityService.getCombinationProductsByActivityIds(Arrays.asList(combinationActivity.getId()));
return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products));
}
}

View File

@ -28,7 +28,6 @@ public class AppCombinationActivityRespVO {
private Integer marketPrice;
@Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
// 从拼团商品里取最低价
private Integer combinationPrice;
}

View File

@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
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.app.seckill.vo.activity.AppSeckillActivityDetailRespVO;
@ -33,10 +32,9 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_FAIL_STATUS_CLOSED;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_APP_STATUS_CLOSED;
@Tag(name = "用户 App - 秒杀活动")
@RestController
@ -53,8 +51,7 @@ public class AppSeckillActivityController {
private ProductSpuApi spuApi;
@GetMapping("/get-now")
@Operation(summary = "获得当前秒杀活动") // 提供给首页使用
// TODO 芋艿需要增加 spring cache
@Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用")
public CommonResult<AppSeckillActivityNowRespVO> getNowSeckillActivity() {
// 1获取当前时间处在哪个秒杀阶段
List<SeckillConfigDO> configList = configService.getSeckillConfigList();
@ -69,7 +66,8 @@ public class AppSeckillActivityController {
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIds(Arrays.asList(filteredConfig.getId()));
List<SeckillActivityDO> filteredList = filterList(activityList, item -> ObjectUtil.equal(item.getStatus(), CommonStatusEnum.ENABLE.getStatus()));
// 21 获取 spu 信息
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(filteredList, SeckillActivityDO::getSpuId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(filteredList, SeckillActivityDO::getSpuId));
// TODO 芋艿需要增加 spring cache
return success(SeckillActivityConvert.INSTANCE.convert(filteredConfig, filteredList, spuList));
}
@ -79,7 +77,7 @@ public class AppSeckillActivityController {
// 1查询满足当前阶段的活动
PageResult<SeckillActivityDO> pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO);
// 11 获取 spu 信息
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(CollectionUtils.convertList(pageResult.getList(), SeckillActivityDO::getSpuId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(pageResult.getList(), SeckillActivityDO::getSpuId));
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, spuList));
}
@ -101,9 +99,8 @@ public class AppSeckillActivityController {
if (seckillActivity == null) {
return success(null);
}
// TODO 芋艿如果禁用的时候需要抛出异常
if (ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
throw exception(SECKILL_ACTIVITY_FAIL_STATUS_CLOSED);
throw exception(SECKILL_ACTIVITY_APP_STATUS_CLOSED);
}
// 3获取活动商品

View File

@ -13,6 +13,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activit
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductBaseVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.product.CombinationProductRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.activity.AppCombinationActivityRespVO;
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;
@ -25,6 +27,7 @@ import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/**
* 拼团活动 Convert
@ -109,4 +112,44 @@ public interface CombinationActivityConvert {
List<CombinationRecordRespDTO> convert(List<CombinationRecordDO> bean);
List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list);
default List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list, List<ProductSpuRespDTO> spuList) {
List<AppCombinationActivityRespVO> activityList = convertAppList(list);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
return CollectionUtils.convertList(activityList, item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
});
return item;
});
}
PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result);
default PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result, List<ProductSpuRespDTO> spuList) {
PageResult<AppCombinationActivityRespVO> appPage = convertAppPage(result);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
List<AppCombinationActivityRespVO> list = CollectionUtils.convertList(appPage.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl());
item.setMarketPrice(spu.getMarketPrice());
});
return item;
});
appPage.setList(list);
return appPage;
}
AppCombinationActivityDetailRespVO convert2(CombinationActivityDO combinationActivity);
List<AppCombinationActivityDetailRespVO.Product> convertList1(List<CombinationProductDO> products);
default AppCombinationActivityDetailRespVO convert3(CombinationActivityDO combinationActivity, List<CombinationProductDO> products) {
AppCombinationActivityDetailRespVO detailRespVO = convert2(combinationActivity);
detailRespVO.setProducts(convertList1(products));
return detailRespVO;
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.combination;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -28,4 +29,9 @@ public interface CombinationActivityMapper extends BaseMapperX<CombinationActivi
return selectList(CombinationActivityDO::getStatus, status);
}
default PageResult<CombinationActivityDO> selectAppPage(PageParam pageParam, Integer status) {
return selectPage(pageParam, new LambdaQueryWrapperX<CombinationActivityDO>()
.eq(CombinationActivityDO::getStatus, status));
}
}

View File

@ -75,7 +75,8 @@ public interface BargainActivityService {
* 获取 APP 端活动展示数据
*
* @param count 需要的数量
* @return
* @return 活动列表
*/
List<BargainActivityDO> getBargainActivityAppList(Integer count);
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.service.combination;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO;
@ -82,4 +83,20 @@ public interface CombinationActivityService {
*/
void validateCombination(Long activityId, Long userId, Long skuId, Integer count);
/**
* 获取 APP 端活动展示数据
*
* @param count 需要的数量
* @return 活动列表
*/
List<CombinationActivityDO> getCombinationActivityAppList(Integer count);
/**
* 获取 APP 端活动分页数据
*
* @param pageParam 分页参数
* @return 活动分页数据
*/
PageResult<CombinationActivityDO> getCombinationActivityAppPage(PageParam pageParam);
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.combination;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
@ -245,4 +246,20 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
}
@Override
public List<CombinationActivityDO> getCombinationActivityAppList(Integer count) {
if (count == null) {
count = 6;
}
PageResult<CombinationActivityDO> result = combinationActivityMapper.selectAppPage(new PageParam().setPageSize(count),
CommonStatusEnum.ENABLE.getStatus());
return result.getList();
}
@Override
public PageResult<CombinationActivityDO> getCombinationActivityAppPage(PageParam pageParam) {
return combinationActivityMapper.selectAppPage(pageParam, CommonStatusEnum.ENABLE.getStatus());
}
}