diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/gift/GiftRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/gift/GiftRestController.java index de839b03..d8e016fc 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/gift/GiftRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/gift/GiftRestController.java @@ -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 activityGiftList(AppExtCommand cmd) { + return giftService.listActivityGifts(cmd); + } + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/query/ActivityGiftListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/query/ActivityGiftListQryExe.java new file mode 100644 index 00000000..08dcd9df --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/query/ActivityGiftListQryExe.java @@ -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 execute(AppExtCommand cmd) { + // 获取进行中的活动 + List activities = activityConfigService.listOngoingActivities(cmd.getReqSysOrigin().getOriginChild()); + + if (CollectionUtils.isEmpty(activities)) { + return new ArrayList<>(); + } + + // 构建 giftId -> bannerId 的映射(取第一个遇到的 bannerId) + Map giftIdToBannerIdMap = new HashMap<>(); + List 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 bannerIds = giftIdToBannerIdMap.values().stream() + .filter(Objects::nonNull).distinct().collect(Collectors.toList()); + + Map bannerUrlMap; + if (!bannerIds.isEmpty()) { + LambdaQueryWrapper query = Wrappers.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 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 giftIdToBannerIdMap, + Map 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; + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/gift/GiftServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/gift/GiftServiceImpl.java index 0d66b233..f1644c9b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/gift/GiftServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/gift/GiftServiceImpl.java @@ -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 listSysOriginEffectiveAllGift(AppExtCommand cmd) { @@ -77,4 +80,9 @@ public class GiftServiceImpl implements GiftService { return blessingsGiftGiveCmdExe.execute(cmd); } + @Override + public List listActivityGifts(AppExtCommand cmd) { + return activityGiftListQryExe.execute(cmd); + } + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/gift/ActivityGiftCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/gift/ActivityGiftCO.java new file mode 100644 index 00000000..8de2568b --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/gift/ActivityGiftCO.java @@ -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; + +/** + *

+ * 活动礼物信息. + *

+ * + * @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; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/gift/GiftService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/gift/GiftService.java index da5d4f4b..41ac0666 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/gift/GiftService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/gift/GiftService.java @@ -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 listActivityGifts(AppExtCommand cmd); + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/sys/ActivityConfig.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/sys/ActivityConfig.java index 2cf1ab82..71694b2b 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/sys/ActivityConfig.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/sys/ActivityConfig.java @@ -78,6 +78,11 @@ public class ActivityConfig implements Serializable { */ private List giftIds; + /** + * banner 配置地址 + */ + private Long bannerId; + /** * 备注. */