promotion:修复砍价活动返回的 combinationPrice 为空的问题

This commit is contained in:
YunaiV 2023-10-06 22:29:11 +08:00
parent 1d9db4874f
commit c8f1269d6e
13 changed files with 63 additions and 42 deletions

View File

@ -56,7 +56,7 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> {
}
default Long selectCount() {
return selectCount(new QueryWrapper<T>());
return selectCount(new QueryWrapper<>());
}
default Long selectCount(String field, Object value) {

View File

@ -74,7 +74,7 @@ public class CombinationActivityController {
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")
public CommonResult<CombinationActivityRespVO> getCombinationActivity(@RequestParam("id") Long id) {
CombinationActivityDO activity = combinationActivityService.getCombinationActivity(id);
List<CombinationProductDO> products = combinationActivityService.getCombinationProductsByActivityIds(newArrayList(id));
List<CombinationProductDO> products = combinationActivityService.getCombinationProductListByActivityIds(newArrayList(id));
return success(CombinationActivityConvert.INSTANCE.convert(activity, products));
}
@ -98,7 +98,7 @@ public class CombinationActivityController {
Map<Long, Integer> recordCountMap = combinationRecordService.getCombinationRecordCountMapByActivity(
activityIds, null, null);
// 拼接数据
List<CombinationProductDO> products = combinationActivityService.getCombinationProductsByActivityIds(
List<CombinationProductDO> products = combinationActivityService.getCombinationProductListByActivityIds(
convertSet(pageResult.getList(), CombinationActivityDO::getId));
List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(
convertSet(pageResult.getList(), CombinationActivityDO::getSpuId));

View File

@ -78,7 +78,7 @@ public class CombinationRecordController {
private Map<String, Long> getCombinationRecordSummary0() {
Map<String, Long> hashMap = MapUtil.newHashMap(3);
hashMap.put("userCount", combinationRecordService.getCombinationRecordsCount());// 获取所有拼团记录
hashMap.put("userCount", combinationRecordService.getCombinationRecordCount());// 获取所有拼团记录
hashMap.put("successCount", combinationRecordService.getCombinationRecordsSuccessCount());// 获取成团记录
hashMap.put("virtualGroupCount", combinationRecordService.getRecordsVirtualGroupCount());// 获取虚拟成团记录
return hashMap;

View File

@ -30,7 +30,6 @@ import java.time.Duration;
import java.util.Collections;
import java.util.List;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@ -56,6 +55,7 @@ public class AppCombinationActivityController {
@Resource
private CombinationActivityService activityService;
@Resource
private ProductSpuApi spuApi;
@ -68,40 +68,45 @@ public class AppCombinationActivityController {
}
private List<AppCombinationActivityRespVO> getCombinationActivityList0(Integer count) {
List<CombinationActivityDO> list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6));
if (CollUtil.isEmpty(list)) {
List<CombinationActivityDO> activityList = activityService.getCombinationActivityListByCount(count);
if (CollUtil.isEmpty(activityList)) {
return Collections.emptyList();
}
// 拼接返回
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId));
return CombinationActivityConvert.INSTANCE.convertAppList(list, spuList);
List<CombinationProductDO> productList = activityService.getCombinationProductListByActivityIds(
convertList(activityList, CombinationActivityDO::getId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, CombinationActivityDO::getSpuId));
return CombinationActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList);
}
@GetMapping("/page")
@Operation(summary = "获得拼团活动分页")
public CommonResult<PageResult<AppCombinationActivityRespVO>> getCombinationActivityPage(PageParam pageParam) {
PageResult<CombinationActivityDO> result = activityService.getCombinationActivityPage(pageParam);
if (CollUtil.isEmpty(result.getList())) {
return success(PageResult.empty(result.getTotal()));
PageResult<CombinationActivityDO> pageResult = activityService.getCombinationActivityPage(pageParam);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal()));
}
// 拼接返回
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList));
List<CombinationProductDO> productList = activityService.getCombinationProductListByActivityIds(
convertList(pageResult.getList(), CombinationActivityDO::getId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(pageResult.getList(), CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertAppPage(pageResult, productList, spuList));
}
@GetMapping("/get-detail")
@Operation(summary = "获得拼团活动明细")
@Parameter(name = "id", description = "活动编号", required = true, example = "1024")
public CommonResult<AppCombinationActivityDetailRespVO> getCombinationActivityDetail(@RequestParam("id") Long id) {
// 1获取活动
CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id);
if (combinationActivity == null
|| ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
// 1. 获取活动
CombinationActivityDO activity = activityService.getCombinationActivity(id);
if (activity == null
|| ObjectUtil.equal(activity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) {
return success(null);
}
// 2获取活动商品
List<CombinationProductDO> products = activityService.getCombinationProductsByActivityId(combinationActivity.getId());
return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products));
// 2. 获取活动商品
List<CombinationProductDO> products = activityService.getCombinationProductsByActivityId(activity.getId());
return success(CombinationActivityConvert.INSTANCE.convert3(activity, products));
}
}

View File

@ -39,21 +39,21 @@ public class AppCombinationRecordController {
@GetMapping("/get-summary")
@Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页")
// TODO 芋艿增加 @Cache 缓存1 分钟过期
public CommonResult<AppCombinationRecordSummaryRespVO> getCombinationRecordSummary() {
// 获取所有拼团记录
Long count = combinationRecordService.getCombinationRecordsCount();
AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO();
if (count == null || count == 0L) {
// 1. 获得拼团记录数量
Long count = combinationRecordService.getCombinationRecordCount();
if (count == 0) {
summary.setAvatars(Collections.emptyList());
summary.setUserCount(count);
return success(summary);
}
summary.setUserCount(count);
// TODO 只返回最近的 7
int num = 7;
summary.setAvatars(convertList(combinationRecordService.getLatestCombinationRecordList(num), CombinationRecordDO::getAvatar));
// 2. 获得拼团记录头像
List<CombinationRecordDO> records = combinationRecordService.getLatestCombinationRecordList(
AppCombinationRecordSummaryRespVO.AVATAR_COUNT);
summary.setAvatars(convertList(records, CombinationRecordDO::getAvatar));
return success(summary);
}

View File

@ -9,6 +9,11 @@ import java.util.List;
@Data
public class AppCombinationRecordSummaryRespVO {
/**
* 加载 {@link #avatars} 的数量
*/
public static final Integer AVATAR_COUNT = 7;
@Schema(description = "拼团用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long userCount;

View File

@ -86,7 +86,8 @@ public class AppSeckillActivityController {
// 2.1 查询满足当前阶段的活动
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus());
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId(convertList(activityList, SeckillActivityDO::getId));
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId(
convertList(activityList, SeckillActivityDO::getId));
// 2.2 获取 spu 信息
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
return SeckillActivityConvert.INSTANCE.convert(config, activityList, productList, spuList);

View File

@ -28,7 +28,7 @@ import org.mapstruct.factory.Mappers;
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.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/**
@ -120,10 +120,16 @@ public interface CombinationActivityConvert {
List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list);
default List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list, List<ProductSpuRespDTO> spuList) {
default List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list,
List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) {
List<AppCombinationActivityRespVO> activityList = convertAppList(list);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
return CollectionUtils.convertList(activityList, item -> {
// 设置 product 信息
item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice));
// 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item;
});
@ -131,13 +137,17 @@ public interface CombinationActivityConvert {
PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result);
default PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result, List<ProductSpuRespDTO> spuList) {
default PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result,
List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) {
PageResult<AppCombinationActivityRespVO> appPage = convertAppPage(result);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
List<AppCombinationActivityRespVO> list = CollectionUtils.convertList(appPage.getList(), item -> {
findAndThen(spuMap, item.getSpuId(), spu -> {
item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice());
});
// 设置 product 信息
item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice));
// 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item;
});
appPage.setList(list);

View File

@ -77,7 +77,7 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO
*/
default List<CombinationRecordDO> selectLatestList(int count) {
return selectList(new LambdaQueryWrapperX<CombinationRecordDO>()
.orderByDesc(CombinationRecordDO::getCreateTime)
.orderByDesc(CombinationRecordDO::getId)
.last("LIMIT " + count));
}

View File

@ -73,7 +73,7 @@ public interface CombinationActivityService {
* @return 拼团活动的商品列表
*/
default List<CombinationProductDO> getCombinationProductsByActivityId(Long activityId) {
return getCombinationProductsByActivityIds(Collections.singletonList(activityId));
return getCombinationProductListByActivityIds(Collections.singletonList(activityId));
}
/**
@ -82,7 +82,7 @@ public interface CombinationActivityService {
* @param activityIds 拼团活动 ids
* @return 拼团活动的商品列表
*/
List<CombinationProductDO> getCombinationProductsByActivityIds(Collection<Long> activityIds);
List<CombinationProductDO> getCombinationProductListByActivityIds(Collection<Long> activityIds);
/**
* 获取正在进行的活动分页数据

View File

@ -200,7 +200,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
}
@Override
public List<CombinationProductDO> getCombinationProductsByActivityIds(Collection<Long> activityIds) {
public List<CombinationProductDO> getCombinationProductListByActivityIds(Collection<Long> activityIds) {
return combinationProductMapper.selectListByActivityIds(activityIds);
}

View File

@ -96,7 +96,7 @@ public interface CombinationRecordService {
*
* @return 记录数
*/
Long getCombinationRecordsCount();
Long getCombinationRecordCount();
/**
* 获取成功记录数

View File

@ -227,7 +227,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
}
@Override
public Long getCombinationRecordsCount() {
public Long getCombinationRecordCount() {
return recordMapper.selectCount();
}