mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
【功能优化】商城:秒杀装修重构(PC端)
This commit is contained in:
parent
74492d65f0
commit
9f271c3d96
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
|
package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.ProductSpuApi;
|
||||||
@ -13,15 +14,17 @@ import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import java.util.Collections;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
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.framework.common.util.collection.CollectionUtils.convertSet;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 秒杀活动")
|
@Tag(name = "管理后台 - 秒杀活动")
|
||||||
@ -89,11 +92,27 @@ public class SeckillActivityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拼接数据
|
// 拼接数据
|
||||||
List<SeckillProductDO> products = seckillActivityService.getSeckillProductListByActivityId(
|
List<SeckillProductDO> products = seckillActivityService.getSeckillProductListByActivityIds(
|
||||||
convertSet(pageResult.getList(), SeckillActivityDO::getId));
|
convertSet(pageResult.getList(), SeckillActivityDO::getId));
|
||||||
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(
|
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(
|
||||||
convertSet(pageResult.getList(), SeckillActivityDO::getSpuId));
|
convertSet(pageResult.getList(), SeckillActivityDO::getSpuId));
|
||||||
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, products, spuList));
|
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, products, spuList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list-by-ids")
|
||||||
|
@Operation(summary = "获得秒杀活动列表,基于活动编号数组")
|
||||||
|
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
|
||||||
|
public CommonResult<List<SeckillActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
|
||||||
|
// 1. 获得开启的活动列表
|
||||||
|
List<SeckillActivityDO> activityList = seckillActivityService.getSeckillActivityListByIds(ids);
|
||||||
|
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
|
||||||
|
if (CollUtil.isEmpty(activityList)) {
|
||||||
|
return success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
// 2. 拼接返回
|
||||||
|
List<SeckillProductDO> productList = seckillActivityService.getSeckillProductListByActivityIds(
|
||||||
|
convertList(activityList, SeckillActivityDO::getId));
|
||||||
|
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
|
||||||
|
return success(SeckillActivityConvert.INSTANCE.convertList(activityList, productList, spuList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,8 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
|
|||||||
example = "50")
|
example = "50")
|
||||||
private Integer marketPrice;
|
private Integer marketPrice;
|
||||||
|
|
||||||
|
@Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||||
|
private Integer seckillPrice; // 从 products 获取最小 price 读取
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import com.google.common.cache.LoadingCache;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -30,7 +31,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -86,7 +86,7 @@ public class AppSeckillActivityController {
|
|||||||
|
|
||||||
// 2.1 查询满足当前阶段的活动
|
// 2.1 查询满足当前阶段的活动
|
||||||
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus());
|
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus());
|
||||||
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId(
|
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
|
||||||
convertList(activityList, SeckillActivityDO::getId));
|
convertList(activityList, SeckillActivityDO::getId));
|
||||||
// 2.2 获取 spu 信息
|
// 2.2 获取 spu 信息
|
||||||
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
|
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
|
||||||
@ -101,7 +101,7 @@ public class AppSeckillActivityController {
|
|||||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||||
return success(PageResult.empty(pageResult.getTotal()));
|
return success(PageResult.empty(pageResult.getTotal()));
|
||||||
}
|
}
|
||||||
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId(
|
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
|
||||||
convertList(pageResult.getList(), SeckillActivityDO::getId));
|
convertList(pageResult.getList(), SeckillActivityDO::getId));
|
||||||
|
|
||||||
// 2. 拼接数据
|
// 2. 拼接数据
|
||||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.seckill;
|
|||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
|
||||||
import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO;
|
import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
|
||||||
@ -87,6 +88,22 @@ public interface SeckillActivityConvert {
|
|||||||
return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus()));
|
return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<SeckillActivityRespVO> convertList(List<SeckillActivityDO> list,
|
||||||
|
List<SeckillProductDO> productList,
|
||||||
|
List<ProductSpuRespDTO> spuList) {
|
||||||
|
List<SeckillActivityRespVO> activityList = BeanUtils.toBean(list, SeckillActivityRespVO.class);
|
||||||
|
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
|
||||||
|
Map<Long, List<SeckillProductDO>> productMap = convertMultiMap(productList, SeckillProductDO::getActivityId);
|
||||||
|
return CollectionUtils.convertList(activityList, item -> {
|
||||||
|
// 设置 product 信息
|
||||||
|
item.setSeckillPrice(getMinValue(productMap.get(item.getId()), SeckillProductDO::getSeckillPrice));
|
||||||
|
// 设置 SPU 信息
|
||||||
|
findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())
|
||||||
|
.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list);
|
List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list);
|
||||||
|
|
||||||
List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList);
|
List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList);
|
||||||
|
@ -8,8 +8,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.Se
|
|||||||
import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO;
|
import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -98,7 +98,7 @@ public interface SeckillActivityService {
|
|||||||
* @param activityIds 活动编号
|
* @param activityIds 活动编号
|
||||||
* @return 活动商品列表
|
* @return 活动商品列表
|
||||||
*/
|
*/
|
||||||
List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> activityIds);
|
List<SeckillProductDO> getSeckillProductListByActivityIds(Collection<Long> activityIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过活动时段编号获取指定 status 的秒杀活动
|
* 通过活动时段编号获取指定 status 的秒杀活动
|
||||||
@ -139,4 +139,12 @@ public interface SeckillActivityService {
|
|||||||
*/
|
*/
|
||||||
List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection<Long> spuIds, Integer status, LocalDateTime dateTime);
|
List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection<Long> spuIds, Integer status, LocalDateTime dateTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得拼团活动列表
|
||||||
|
*
|
||||||
|
* @param ids 拼团活动 ids
|
||||||
|
* @return 拼团活动的列表
|
||||||
|
*/
|
||||||
|
List<SeckillActivityDO> getSeckillActivityListByIds(Collection<Long> ids);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillConfigDO;
|
|||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper;
|
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillActivityMapper;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper;
|
import cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity.SeckillProductMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -276,7 +276,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> activityIds) {
|
public List<SeckillProductDO> getSeckillProductListByActivityIds(Collection<Long> activityIds) {
|
||||||
return seckillProductMapper.selectListByActivityId(activityIds);
|
return seckillProductMapper.selectListByActivityId(activityIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,4 +336,9 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
|||||||
convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime);
|
convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId")), dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SeckillActivityDO> getSeckillActivityListByIds(Collection<Long> ids) {
|
||||||
|
return seckillActivityMapper.selectList(SeckillActivityDO::getId, ids);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user