新增活动礼物列表接口

This commit is contained in:
tianfeng 2026-02-11 17:59:54 +08:00
parent 833ff1c588
commit 301c183b5e
6 changed files with 222 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import com.red.circle.common.business.core.ControllerRedisKeyConstant;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.gift.ActivityGiftCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftConfigCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftConfigGroupByTabCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftWallCO;
@ -166,5 +167,18 @@ public class GiftRestController extends BaseController {
return giftService.giveBlessingsGift(cmd);
}
/**
* 获取活动礼物列表.
*
* @eo.name 获取活动礼物列表.
* @eo.url /activity/list
* @eo.method get
* @eo.request-type formdata
*/
@GetMapping("/activity/list")
public List<ActivityGiftCO> activityGiftList(AppExtCommand cmd) {
return giftService.listActivityGifts(cmd);
}
}

View File

@ -0,0 +1,112 @@
package com.red.circle.other.app.command.gift.query;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.gift.ActivityGiftCO;
import com.red.circle.other.infra.database.cache.service.other.BannerCacheService;
import com.red.circle.other.infra.database.mongo.entity.sys.ActivityConfig;
import com.red.circle.other.infra.database.mongo.service.sys.ActivityConfigService;
import com.red.circle.other.infra.database.rds.entity.gift.GiftConfig;
import com.red.circle.other.infra.database.rds.entity.sys.BannerConfig;
import com.red.circle.other.infra.database.rds.service.gift.GiftConfigService;
import com.red.circle.other.infra.database.rds.service.sys.BannerConfigService;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 获取活动礼物列表.
*
* @author system
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ActivityGiftListQryExe {
private final ActivityConfigService activityConfigService;
private final GiftConfigService giftConfigService;
private final BannerConfigService bannerConfigService;
public List<ActivityGiftCO> execute(AppExtCommand cmd) {
// 获取进行中的活动
List<ActivityConfig> activities = activityConfigService.listOngoingActivities(cmd.getReqSysOrigin().getOriginChild());
if (CollectionUtils.isEmpty(activities)) {
return new ArrayList<>();
}
// 构建 giftId -> bannerId 的映射取第一个遇到的 bannerId
Map<Long, Long> giftIdToBannerIdMap = new HashMap<>();
List<Long> giftIds = new ArrayList<>();
for (ActivityConfig activity : activities) {
Long bannerId = activity.getBannerId();
if (CollectionUtils.isNotEmpty(activity.getGiftIds())) {
for (Object giftIdObj : activity.getGiftIds()) {
Long giftId = Long.valueOf(giftIdObj.toString());
if (!giftIdToBannerIdMap.containsKey(giftId)) {
giftIdToBannerIdMap.put(giftId, bannerId);
giftIds.add(giftId);
}
}
}
}
if (giftIds.isEmpty()) {
return new ArrayList<>();
}
// 收集所有需要查询的 bannerId去重
List<Long> bannerIds = giftIdToBannerIdMap.values().stream()
.filter(Objects::nonNull).distinct().collect(Collectors.toList());
Map<Long, String> bannerUrlMap;
if (!bannerIds.isEmpty()) {
LambdaQueryWrapper<BannerConfig> query = Wrappers.<BannerConfig>lambdaQuery()
.in(BannerConfig::getId, bannerIds);
bannerUrlMap = bannerConfigService.list(query).stream()
.collect(Collectors.toMap(BannerConfig::getId, BannerConfig::getCover, (u1, u2) -> u1));
} else {
bannerUrlMap = new HashMap<>();
}
// 查询礼物配置
List<GiftConfig> giftConfigs = giftConfigService.listByIds(giftIds);
if (CollectionUtils.isEmpty(giftConfigs)) {
return new ArrayList<>();
}
// 转换为 CO并设置 bannerUrl
return giftConfigs.stream()
.map(giftConfig -> convertToActivityGiftCO(giftConfig, giftIdToBannerIdMap, bannerUrlMap))
.collect(Collectors.toList());
}
private ActivityGiftCO convertToActivityGiftCO(GiftConfig giftConfig,
Map<Long, Long> giftIdToBannerIdMap,
Map<Long, String> bannerUrlMap) {
ActivityGiftCO activityGiftCO = new ActivityGiftCO();
activityGiftCO.setId(giftConfig.getId());
activityGiftCO.setGiftCode(giftConfig.getGiftCode());
activityGiftCO.setGiftPhoto(giftConfig.getGiftPhoto());
activityGiftCO.setGiftSourceUrl(giftConfig.getGiftSourceUrl());
activityGiftCO.setGiftCandy(giftConfig.getGiftCandy());
activityGiftCO.setSpecial(giftConfig.getSpecial());
activityGiftCO.setType(giftConfig.getType());
activityGiftCO.setGiftTab(giftConfig.getGiftTab());
activityGiftCO.setGiftName(giftConfig.getGiftName());
activityGiftCO.setExpiredTime(giftConfig.getExpiredTime());
// 设置 bannerUrl
Long bannerId = giftIdToBannerIdMap.get(giftConfig.getId());
String bannerUrl = (bannerId != null) ? bannerUrlMap.get(bannerId) : null;
activityGiftCO.setBannerUrl(bannerUrl);
return activityGiftCO;
}
}

View File

@ -6,10 +6,12 @@ import com.red.circle.other.app.command.gift.BlessingsGiftGiveCmdExe;
import com.red.circle.other.app.command.gift.GiftGiveAwayBatchCmdExe;
import com.red.circle.other.app.command.gift.GiveAwayGiftBackpackCmdExe;
import com.red.circle.other.app.command.gift.LuckyGiftGiveCmdExe;
import com.red.circle.other.app.command.gift.query.ActivityGiftListQryExe;
import com.red.circle.other.app.command.gift.query.PremiumGiftWallListQryExe;
import com.red.circle.other.app.command.gift.query.SysGiftConfigListQryExe;
import com.red.circle.other.app.command.gift.query.UserGiftBackpackQryExe;
import com.red.circle.other.app.command.gift.query.UserGiftWallListQryExe;
import com.red.circle.other.app.dto.clientobject.gift.ActivityGiftCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftConfigCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftWallCO;
import com.red.circle.other.app.dto.clientobject.gift.PremiumGiftWallCO;
@ -36,6 +38,7 @@ public class GiftServiceImpl implements GiftService {
private final PremiumGiftWallListQryExe premiumGiftWallListQryExe;
private final GiveAwayGiftBackpackCmdExe giveAwayGiftBackpackCmdExe;
private final BlessingsGiftGiveCmdExe blessingsGiftGiveCmdExe;
private final ActivityGiftListQryExe activityGiftListQryExe;
@Override
public List<GiftConfigCO> listSysOriginEffectiveAllGift(AppExtCommand cmd) {
@ -77,4 +80,9 @@ public class GiftServiceImpl implements GiftService {
return blessingsGiftGiveCmdExe.execute(cmd);
}
@Override
public List<ActivityGiftCO> listActivityGifts(AppExtCommand cmd) {
return activityGiftListQryExe.execute(cmd);
}
}

View File

@ -0,0 +1,80 @@
package com.red.circle.other.app.dto.clientobject.gift;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.framework.dto.ClientObject;
import java.math.BigDecimal;
import java.sql.Timestamp;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 活动礼物信息.
* </p>
*
* @author system
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ActivityGiftCO extends ClientObject {
/**
* 礼物id.
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
/**
* 礼物code.
*/
private String giftCode;
/**
* 礼物图片.
*/
private String giftPhoto;
/**
* 礼物图片资源.
*/
private String giftSourceUrl;
/**
* 礼物价值/糖果.
*/
private BigDecimal giftCandy;
/**
* 特效.
*/
private String special;
/**
* 类型.
*/
private String type;
/**
* 礼物tab.
*/
private String giftTab;
/**
* 礼物名称.
*/
private String giftName;
/**
* 过期时间.
*/
private Timestamp expiredTime;
/**
* banner地址.
*/
private String bannerUrl;
}

View File

@ -2,6 +2,7 @@ package com.red.circle.other.app.service.gift;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.other.app.dto.clientobject.gift.ActivityGiftCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftConfigCO;
import com.red.circle.other.app.dto.clientobject.gift.GiftWallCO;
import com.red.circle.other.app.dto.clientobject.gift.PremiumGiftWallCO;
@ -34,4 +35,6 @@ public interface GiftService {
BigDecimal giveBlessingsGift(GiveAwayGiftBatchCmd cmd);
List<ActivityGiftCO> listActivityGifts(AppExtCommand cmd);
}

View File

@ -78,6 +78,11 @@ public class ActivityConfig implements Serializable {
*/
private List<String> giftIds;
/**
* banner 配置地址
*/
private Long bannerId;
/**
* 备注.
*/