From fe036be63a23bcfbf29df5e9b644810ff68af9bb Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Tue, 30 Dec 2025 18:10:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=A5=96=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0=E4=B8=8D=E5=8F=AF=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/ActivityRewardConfigQryExe.java | 78 ++++++++++++++++++- .../cmd/activity/ActivityRewardConfigCmd.java | 4 + 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityRewardConfigQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityRewardConfigQryExe.java index 405857f3..d8f2c50f 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityRewardConfigQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/ActivityRewardConfigQryExe.java @@ -1,6 +1,7 @@ package com.red.circle.other.app.command.activity; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.google.common.collect.Lists; import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; @@ -9,13 +10,17 @@ import com.red.circle.other.app.dto.cmd.activity.ActivityRewardConfigCmd; import com.red.circle.other.domain.gateway.props.ActivitySourceGroupGateway; import com.red.circle.other.infra.database.rds.dao.activity.UserActivityRewardClaimDAO; import com.red.circle.other.infra.database.rds.entity.activity.UserActivityRewardClaim; +import com.red.circle.other.infra.database.rds.service.activity.UserActivityRechargeService; import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum; import com.red.circle.other.inner.model.dto.activity.props.ActivityPropsGroup; import com.red.circle.other.inner.model.dto.activity.props.ActivityPropsRule; import com.red.circle.other.inner.model.dto.activity.props.ActivityRewardProps; +import com.red.circle.tool.core.json.JacksonUtils; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.math.BigDecimal; import java.util.List; import java.util.Map; import java.util.Objects; @@ -24,12 +29,14 @@ import java.util.stream.Collectors; /** * 查询活动奖励配置执行器 */ +@Slf4j @Component @RequiredArgsConstructor public class ActivityRewardConfigQryExe { private final ActivitySourceGroupGateway activitySourceGroupGateway; private final UserActivityRewardClaimDAO userActivityRewardClaimDAO; + private final UserActivityRechargeService userActivityRechargeService; public List execute(ActivityRewardConfigCmd cmd) { PropsActivityTypeEnum activityType = PropsActivityTypeEnum.valueOf(cmd.getActivityType()); @@ -43,8 +50,17 @@ public class ActivityRewardConfigQryExe { List ruleIds = ruleConfigs.stream().map(ActivityPropsRule::getId).collect(Collectors.toList()); Map claimMap = getUserClaimMap(cmd.getReqUserId(), ruleIds); + BigDecimal userTotalAmount = userActivityRechargeService.getUserTotalAmount( + cmd.getActivityId(), + cmd.getReqUserId() + ); + if (Objects.isNull(userTotalAmount)) { + userTotalAmount = BigDecimal.ZERO; + } + + BigDecimal finalUserTotalAmount = userTotalAmount; return ruleConfigs.stream() - .map(rule -> buildRewardConfig(rule, cmd.getReqSysOrigin().getOrigin(), claimMap)) + .map(rule -> buildRewardConfig(rule, cmd.getReqSysOrigin().getOrigin(), claimMap, finalUserTotalAmount)) .filter(Objects::nonNull) .collect(Collectors.toList()); } @@ -61,7 +77,8 @@ public class ActivityRewardConfigQryExe { } private ActivityRewardConfigCO buildRewardConfig(ActivityPropsRule rule, String sysOrigin, - Map claimMap) { + Map claimMap, + BigDecimal userTotalAmount) { ActivityPropsGroup group = activitySourceGroupGateway.getActivityPropsGroup( sysOrigin, rule.getResourceGroupId() @@ -82,8 +99,8 @@ public class ActivityRewardConfigQryExe { .setGroupName(group.getName()) .setShelfStatus(group.getShelfStatus()); - UserActivityRewardClaim claim = claimMap.get(rule.getId()); - config.setClaimStatus(Objects.isNull(claim) ? 0 : claim.getStatus()); + int claimStatus = calculateClaimStatus(rule, claimMap, userTotalAmount); + config.setClaimStatus(claimStatus); if (CollectionUtil.isNotEmpty(group.getActivityRewardProps())) { List propsList = group.getActivityRewardProps().stream() @@ -95,6 +112,59 @@ public class ActivityRewardConfigQryExe { return config; } + /** + * 计算领取状态 + * -1: 不可领取(充值金额不足) + * 0: 可领取(充值金额达标且未领取) + * 1: 已领取 + */ + private int calculateClaimStatus(ActivityPropsRule rule, + Map claimMap, + BigDecimal userTotalAmount) { + UserActivityRewardClaim claim = claimMap.get(rule.getId()); + if (Objects.nonNull(claim)) { + return claim.getStatus(); + } + + BigDecimal requiredAmount = parseRequiredAmount(rule.getJsonData()); + if (Objects.isNull(requiredAmount)) { + return -1; + } + + if (userTotalAmount.compareTo(requiredAmount) < 0) { + return -1; + } + + return 0; + } + + private BigDecimal parseRequiredAmount(String jsonData) { + if (StrUtil.isBlank(jsonData)) { + return null; + } + + try { + Map dataMap = JacksonUtils.readValue(jsonData, Map.class); + Object quantity = dataMap.get("quantity"); + if (Objects.isNull(quantity)) { + return null; + } + + if (quantity instanceof Number) { + return new BigDecimal(quantity.toString()); + } + + if (quantity instanceof String) { + return new BigDecimal((String) quantity); + } + + return null; + } catch (Exception e) { + log.error("解析jsonData失败: {}", jsonData, e); + return null; + } + } + private ActivityRewardConfigCO.ActivityRewardPropsCO convertToRewardPropsCO(ActivityRewardProps props) { return new ActivityRewardConfigCO.ActivityRewardPropsCO() .setId(props.getId()) diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/ActivityRewardConfigCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/ActivityRewardConfigCmd.java index 25a2319e..620a6b7f 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/ActivityRewardConfigCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/activity/ActivityRewardConfigCmd.java @@ -2,6 +2,7 @@ package com.red.circle.other.app.dto.cmd.activity; import com.red.circle.common.business.dto.cmd.AppExtCommand; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -16,4 +17,7 @@ public class ActivityRewardConfigCmd extends AppExtCommand { @NotBlank(message = "活动类型不能为空") private String activityType; + + @NotNull(message = "活动ID不能为空") + private Long activityId; }