diff --git a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java index d3b186e4..85b66300 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/UserCpClientApi.java @@ -119,7 +119,7 @@ public interface UserCpClientApi { @RequestParam("userIdTwo") Long userIdTwo); @GetMapping("/getCpUserId") - ResultResponse getCpUserId(@RequestParam("userId") Long userId); + ResultResponse> getCpUserId(@RequestParam("userId") Long userId); @GetMapping("/listLatestCp") ResultResponse> listLatestCp(@RequestParam("sysOrigin") String sysOrigin, diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java index da5aaba1..c32f59b2 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java @@ -20,6 +20,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** *

* 用户cp关系 前端控制器. @@ -38,27 +40,6 @@ public class CpRelationshipRestController extends BaseController { private final UserCpRelationService userCpRelationService; - /** - * 获取cp对象. - * - * @eo.name 获取cp对象. - * @eo.url / - * @eo.method get - * @eo.request-type formdata - */ - @GetMapping - public CpUserProfileCO getCpUser(@Validated UserIdCmd cmd) { - return userCpRelationService.getCpUser(cmd); - } - - /** - * 获取cp对象V4. - */ - @GetMapping("/v4") - public CpCabinUserProfileCO getCpUserV4(@Validated UserIdCommonCmd cmd) { - return userCpRelationService.getCpUserV4(cmd); - } - /** * 获取我的-cp对象. * @@ -68,7 +49,7 @@ public class CpRelationshipRestController extends BaseController { * @eo.request-type formdata */ @GetMapping("/pair") - public CpPairUserProfileCO getCpPairUserProfileCO(AppExtCommand cmd) { + public List getCpPairUserProfileCO(AppExtCommand cmd) { return userCpRelationService.getCpPairUserProfileCO(cmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java index ac1fd2a2..67d669f2 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/activity/query/WeekCpUserGiftQueryExe.java @@ -115,12 +115,13 @@ public class WeekCpUserGiftQueryExe { private ActivityCpUserRankingCO getThisUser(AppExtCommand cmd) { - Long cpUserId = cpRelationshipService.getCpUserId(cmd.getReqUserId()); - if (Objects.isNull(cpUserId)) { + List cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId()); + if (cpUserIdList.isEmpty()) { return new ActivityCpUserRankingCO(); } - WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount( + Long cpUserId = cpUserIdList.get(0); + WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount( cmd.getReqSysOrigin().getOrigin(), cmd.getReqUserId(), cpUserId); if (Objects.isNull(thisUser)) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/BlessingsGiftGiveCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/BlessingsGiftGiveCmdExe.java index 26ca9583..e023f61e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/BlessingsGiftGiveCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/gift/BlessingsGiftGiveCmdExe.java @@ -71,7 +71,7 @@ public class BlessingsGiftGiveCmdExe { // 接受人必须是CP ResponseAssert.isTrue(UserErrorEnum.NOT_CP_ERROR, - cpRelationshipService.existsCp(cmd.getAccepts().get(0).getAcceptUserId())); + cpRelationshipService.existsCp(cmd.getReqUserId(), cmd.getAccepts().get(0).getAcceptUserId())); // 付钱 WalletReceiptResDTO receipt = consumeCandy(cmd, giftConfig); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java index 6813698a..fd47ac89 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java @@ -4,6 +4,7 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.mq.business.model.event.task.TaskApprovalEvent; import com.red.circle.mq.rocket.business.producer.TaskMqMessage; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; import com.red.circle.tool.core.date.DateUtils; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; @@ -15,6 +16,8 @@ import com.red.circle.other.inner.asserts.user.UserErrorCode; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import java.time.ZoneId; +import java.util.Comparator; +import java.util.List; import java.util.Objects; import com.red.circle.tool.core.date.LocalDateTimeUtils; @@ -33,25 +36,31 @@ public class UserCpPairUserProfileQryExe { private final CpRelationshipService cpRelationshipService; private final UserProfileGateway userProfileGateway; private final UserProfileAppConvertor userProfileAppConvertor; + private final CpValueService cpValueService; private final TaskMqMessage taskMqMessage; - public CpPairUserProfileCO execute(AppExtCommand cmd) { + public List execute(AppExtCommand cmd) { UserProfile meUser = userProfileGateway.getByUserId(cmd.requiredReqUserId()); ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, meUser); - CpRelationship cpRelationship = cpRelationshipService.getByUserId(cmd.requiredReqUserId()); - if (Objects.isNull(cpRelationship)) { - return new CpPairUserProfileCO() - .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))); + List cpRelationshipList = cpRelationshipService.getByUserId(cmd.requiredReqUserId()); + if (cpRelationshipList.isEmpty()) { + return List.of( + new CpPairUserProfileCO() + .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) + ); } - return new CpPairUserProfileCO() - .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) - .setCpUserProfile(getUserProfile(cpRelationship.getCpUserId())) - .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())) - .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString()) - ; + return cpRelationshipList.stream() + .map(cpRelationship -> new CpPairUserProfileCO() + .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) + .setCpUserProfile(getUserProfile(cpRelationship.getCpUserId())) + .setCpValue(cpValueService.getCpVal(cpRelationship.getCpValId())) + .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())) + .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString())) + .sorted(Comparator.comparing(CpPairUserProfileCO::getCpValue).reversed()) + .toList(); } private UserProfileDTO getUserProfile(Long cpUserId) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java index 506c52a5..27d675d9 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java @@ -34,12 +34,11 @@ public class UserCpRelationQryExe { private final UserCpValueCacheService userCpValueCacheService; public CpUserProfileCO execute(UserIdCmd cmd) { - return Optional.ofNullable(cpRelationshipService.getByUserId(cmd.getUserId())) + return Optional.ofNullable(cpRelationshipService.getByUserId(cmd.getReqUserId(), cmd.getUserId())) .map(cpRelationship -> new CpUserProfileCO() .setUserProfile(getUserProfile(cpRelationship.getCpUserId())) .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())) .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString()) -// .setLevel(getLevel(cpRelationship.getUserId(), cpRelationship.getCpUserId())) ) .orElse(null); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java index 6faa4d8e..0a5631b3 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java @@ -56,7 +56,7 @@ public class UserCpRelationQueryV4Exe { public CpCabinUserProfileCO execute(UserIdCommonCmd cmd) { - CpRelationship cpRelationship = cpRelationshipService.getByUserId(cmd.getUserId()); + CpRelationship cpRelationship = cpRelationshipService.getByUserId(cmd.getReqUserId(), cmd.getUserId()); if (Objects.isNull(cpRelationship)) { return null; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java index 71657833..863b3fff 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/GiveGiftsListener.java @@ -474,14 +474,7 @@ public class GiveGiftsListener implements MessageListener { private List getRegionGiftAcceptUser(GiveAwayGiftBatchEvent event, List anchorUserIds, GiftValue giftValue) { - //如果系统为朝拜则需要处理代理分成,取消代理分成 - if (event.getSysOrigin().name().equals("YOLO")) { - return getRegionGiftAcceptUserRestsYolo(event, anchorUserIds, giftValue); - } else if (event.getSysOrigin().name().equals(SysOriginPlatformEnum.TWO_FUN.getSysOrigin())||event.getSysOrigin().name().equals(SysOriginPlatformEnum.TARAB.getSysOrigin())) { - return getRegionGiftAcceptUserRestsTwoFun(event, anchorUserIds, giftValue); - } else { - return getRegionGiftAcceptUserRests(event, anchorUserIds, giftValue); - } + return getRegionGiftAcceptUserRests(event, anchorUserIds, giftValue); } @@ -489,7 +482,7 @@ public class GiveGiftsListener implements MessageListener { * 分区. */ private List getRegionGiftAcceptUserRests(GiveAwayGiftBatchEvent event, - List anchorUserIds, GiftValue giftValue) { + List anchorUserIds, GiftValue giftValue) { log.info("getRegionGiftAcceptUserRests: {} anchorUserIds:{} giftValue:{}", JSON.toJSONString(event), anchorUserIds, JSON.toJSONString(giftValue)); @@ -497,12 +490,12 @@ public class GiveGiftsListener implements MessageListener { RegionConfig sendRegion = getUserRegion(event.getSendUserId()); // 幸运礼物比例 - BigDecimal luckyGiftRatio = gameLuckyGiftCommon.getLuckyGiftTargetRatio( - event.getSysOrigin().name()); + BigDecimal luckyGiftRatio = gameLuckyGiftCommon.getLuckyGiftTargetRatio(event.getSysOrigin().name()); // 赠送礼物给自己返还金币比例 - BigDecimal sendAssistRatio = - event.checkLuckyGift() ? luckyGiftRatio : getAssistGiftToOwnGoldRatio(sendRegion.getId()); + BigDecimal sendAssistRatio = event.checkLuckyGift() + ? luckyGiftRatio + : getAssistGiftToOwnGoldRatio(sendRegion.getId()); Map teamMemberMap = teamMemberService.mapByMemberIds(anchorUserIds); @@ -510,208 +503,40 @@ public class GiveGiftsListener implements MessageListener { // 接受人区域与金币比例 RegionConfig acceptRegion = getUserRegion(accept.getAcceptUserId()); + + // 检查是否为冲突区域 + Boolean isConflicts = !Objects.equals( + userRegionGateway.checkBusinessRegionCode(sendRegion.getRegionCode(), acceptRegion.getRegionCode()), + Boolean.TRUE + ); + + // 初始化接收金额和目标金额 + BigDecimal acceptAmount = BigDecimal.ZERO; + BigDecimal targetAmount = BigDecimal.ZERO; BigDecimal acceptAssistRatio = BigDecimal.ZERO; - // 接收金额 - BigDecimal acceptAmount = BigDecimal.ZERO; - // 接收目标 - BigDecimal targetAmount = BigDecimal.ZERO; - - // 不是冲突区域则不清零目标 - Boolean isConflicts = !Objects.equals( - userRegionGateway.checkBusinessRegionCode(sendRegion.getRegionCode(), - acceptRegion.getRegionCode()), Boolean.TRUE); - if (Boolean.FALSE.equals(isConflicts)) { - - // 幸运礼物 不计算金额,GiftPrizeAcceptStrategy不发送 + // 非冲突区域才计算金额 + if (!isConflicts) { if (event.checkLuckyGift()) { - - // 幸运礼物目标 = 礼物价值 * 比例 + // 幸运礼物 + acceptAssistRatio = luckyGiftRatio; targetAmount = giftValue.getGiftValue().multiply(luckyGiftRatio).setScale(0, RoundingMode.DOWN); acceptAmount = targetAmount; - - // 赠送礼物给别人返还金币比例 - acceptAssistRatio = luckyGiftRatio; - - } - - if (!event.checkLuckyGift()) { - // 赠送礼物给别人返还金币比例 - acceptAssistRatio = getAssistGiftToOtherGoldRatio(acceptRegion.getId()); - - // 发送人是普通用户 - BigDecimal sendAssistRatioNormal = null; - if (userRegionGateway.isOrdinaryUser(event.getSendUserId())) { - acceptAssistRatio = getAssistGiftToOtherGoldRatioNormal(acceptRegion.getId()); - sendAssistRatioNormal = getAssistGiftToOwnGoldRatioNormal(acceptRegion.getId()); - - } - - // 普通礼物,接受人可获得金额 - acceptAmount = enumConfigCacheService.giftGoldRatioFormula(Objects.equals(event.getSendUserId(), accept.getAcceptUserId()) - ? (sendAssistRatioNormal != null ? sendAssistRatioNormal : sendAssistRatio) - : acceptAssistRatio, giftValue.getGiftValue()); - - BigDecimal assistGiftTargetRatio = getAssistGiftTargetRatio(acceptRegion.getId()); - - // 普通礼物,接受人可获得目标 - targetAmount = giftValue.getGiftValue().multiply(assistGiftTargetRatio).setScale(0, RoundingMode.DOWN);; - } - } - // 获得主播的账单ID. - Boolean isAnchor = anchorUserIds.contains(accept.getAcceptUserId()); - return new GiftAcceptUser() - .setAcceptUserId(accept.getAcceptUserId()) - .setAnchor(isAnchor) - .setReceiptId(0L) - .setRegionIdStr(sendRegion.getId() + "-" + acceptRegion.getId()) - .setRegion(sendRegion.getRegionName() + "-" + acceptRegion.getRegionName()) - .setRegionEq(Objects.equals(sendRegion.getId(), acceptRegion.getId())) - .setAcceptAmount(acceptAmount) - .setTargetAmount(targetAmount) - .setPercentage(acceptAssistRatio) - .setSelfPercentage(Boolean.TRUE.equals(isConflicts) ? BigDecimal.ZERO : sendAssistRatio) - .setCountTargetAmount(Boolean.FALSE) - .setCountBillId(getTeamBillId(teamMemberMap.get(accept.getAcceptUserId()), isAnchor)) - .setSeatIndex(accept.getSeatIndex()); - - }).collect(Collectors.toList()); - } - - - private List getRegionGiftAcceptUserRestsYolo(GiveAwayGiftBatchEvent event, - List anchorUserIds, GiftValue giftValue) { - - // 发送人区域与金币比例 - RegionConfig sendRegion = getUserRegion(event.getSendUserId()); - - BigDecimal sendGifts = getAssistGiftToOwnGoldRatio(sendRegion.getId()); - - // 幸运礼物比例 - BigDecimal luckyGiftRatio = sendGifts.multiply(BigDecimal.valueOf(0.1)); - - // 赠送礼物给自己返还金币比例 - BigDecimal sendAssistRatio = - event.checkLuckyGift() ? luckyGiftRatio : sendGifts; - - Map teamMemberMap = teamMemberService.mapByMemberIds(anchorUserIds); - - return event.getAccepts().stream().map(accept -> { - - // 接受人区域与金币比例 - RegionConfig acceptRegion = getUserRegion(accept.getAcceptUserId()); - - BigDecimal acceptAssistRatio = - event.checkLuckyGift() ? - getAssistGiftToOtherGoldRatio(acceptRegion.getId()).multiply(BigDecimal.valueOf(0.1)) : getAssistGiftToOtherGoldRatio(acceptRegion.getId()); - // 接收金额 - BigDecimal acceptAmount = BigDecimal.ZERO; - // 接收目标 - BigDecimal targetAmount = BigDecimal.ZERO; - - // 不是冲突区域则不清零目标 - Boolean isConflicts = !Objects.equals( - userRegionGateway.checkBusinessRegionCode(sendRegion.getRegionCode(), - acceptRegion.getRegionCode()), Boolean.TRUE); - if (Boolean.FALSE.equals(isConflicts)) { - - // 普通礼物,接受人可获得金额 - acceptAmount = enumConfigCacheService.giftGoldRatioFormula( - Objects.equals(event.getSendUserId(), accept.getAcceptUserId()) - ? sendAssistRatio : acceptAssistRatio, giftValue.getGiftValue()); - - // 普通礼物,接受人可获得目标 - targetAmount = giftValue.getGiftValue(); - - } - // 获得主播的账单ID. - Boolean isAnchor = anchorUserIds.contains(accept.getAcceptUserId()); - return new GiftAcceptUser() - .setAcceptUserId(accept.getAcceptUserId()) - .setAnchor(isAnchor) - .setReceiptId(0L) - .setRegionIdStr(sendRegion.getId() + "-" + acceptRegion.getId()) - .setRegion(sendRegion.getRegionName() + "-" + acceptRegion.getRegionName()) - .setRegionEq(Objects.equals(sendRegion.getId(), acceptRegion.getId())) - .setAcceptAmount(acceptAmount) - .setTargetAmount(targetAmount) - .setPercentage(acceptAssistRatio) - .setSelfPercentage(Boolean.TRUE.equals(isConflicts) ? BigDecimal.ZERO : sendAssistRatio) - .setCountTargetAmount(Boolean.FALSE) - .setCountBillId(getTeamBillId(teamMemberMap.get(accept.getAcceptUserId()), isAnchor)) - .setSeatIndex(accept.getSeatIndex()); - - }).collect(Collectors.toList()); - } - - /** - * 【TWO_FUN钻石政策】需求:主播代理,收礼不返回金币. - */ - private List getRegionGiftAcceptUserRestsTwoFun(GiveAwayGiftBatchEvent event, - List anchorUserIds, GiftValue giftValue) { - - // 发送人区域与金币比例 - RegionConfig sendRegion = getUserRegion(event.getSendUserId()); - TeamPolicyManager teamPolicyManager = teamPolicyManagerService.getReleaseByRegionAndType(sendRegion.getSysOrigin(), sendRegion.getId(), TeamPolicyTypeEnum.SALARY_DIAMOND.name()); - - // 幸运礼物比例 - BigDecimal luckyGiftRatio = gameLuckyGiftCommon.getLuckyGiftTargetRatio( - event.getSysOrigin().name()); - - // 赠送礼物给自己返还金币比例 - BigDecimal sendAssistRatio = - event.checkLuckyGift() ? luckyGiftRatio : getAssistGiftToOwnGoldRatio(sendRegion.getId()); - - Map teamMemberMap = teamMemberService.mapByMemberIds(anchorUserIds); - - return event.getAccepts().stream().map(accept -> { - - // 接受人区域与金币比例 - RegionConfig acceptRegion = getUserRegion(accept.getAcceptUserId()); - BigDecimal acceptAssistRatio = BigDecimal.ZERO; - - // 接收金额 - BigDecimal acceptAmount = BigDecimal.ZERO; - // 接收目标 - BigDecimal targetAmount = BigDecimal.ZERO; - - // 不是冲突区域则不清零目标 - Boolean isConflicts = !Objects.equals( - userRegionGateway.checkBusinessRegionCode(sendRegion.getRegionCode(), - acceptRegion.getRegionCode()), Boolean.TRUE); - if (Boolean.FALSE.equals(isConflicts)) { - - // 幸运礼物 - if (event.checkLuckyGift()) { - - // 幸运礼物目标 = 礼物价值 * 比例 - targetAmount = giftValue.getGiftValue().multiply(luckyGiftRatio) - .setScale(0, RoundingMode.DOWN); - acceptAmount = targetAmount; - - // 赠送礼物给别人返还金币比例 - acceptAssistRatio = luckyGiftRatio; - } else { + // 普通礼物 + acceptAssistRatio = calculateAcceptAssistRatio(event, acceptRegion); + BigDecimal effectiveSendRatio = calculateEffectiveSendRatio(event, sendRegion, sendAssistRatio, acceptRegion, accept); - // 赠送礼物给别人返还金币比例 - acceptAssistRatio = getAssistGiftToOtherGoldRatio(acceptRegion.getId()); - - // 普通礼物,接受人可获得金额 - acceptAmount = enumConfigCacheService.giftGoldRatioFormula( - Objects.equals(event.getSendUserId(), accept.getAcceptUserId()) - ? sendAssistRatio : acceptAssistRatio, giftValue.getGiftValue()); - - // 普通礼物,接受人可获得目标 - targetAmount = giftValue.getGiftValue(); + acceptAmount = enumConfigCacheService.giftGoldRatioFormula(effectiveSendRatio, giftValue.getGiftValue()); + targetAmount = giftValue.getGiftValue() + .multiply(getAssistGiftTargetRatio(acceptRegion.getId())) + .setScale(0, RoundingMode.DOWN); } } - // 获得主播的账单ID. + + // 获得主播的账单ID Boolean isAnchor = anchorUserIds.contains(accept.getAcceptUserId()); - if(isAnchor && Objects.nonNull(teamPolicyManager)) { - log.warn("地区有钻石政策主播不分金币:" + teamPolicyManager); - acceptAmount = BigDecimal.ZERO; - } + return new GiftAcceptUser() .setAcceptUserId(accept.getAcceptUserId()) .setAnchor(isAnchor) @@ -731,21 +556,30 @@ public class GiveGiftsListener implements MessageListener { } /** - * 朝拜礼物配比处理 - * - * @param event - * @param anchorUserIds - * @param giftValue - * @return + * 计算接收方助力比例. */ - private List getRegionGiftAcceptUserYolo(GiveAwayGiftBatchEvent event, - List anchorUserIds, GiftValue giftValue) { - List giftAcceptUsers = getRegionGiftAcceptUserRestsYolo(event, anchorUserIds, giftValue); - if (CollectionUtils.isNotEmpty(giftAcceptUsers) && giftAcceptUsers.get(0).getAnchor()) { - giftAcceptUsers.addAll(getProxyGiftCalculation(event, anchorUserIds, giftValue)); + private BigDecimal calculateAcceptAssistRatio(GiveAwayGiftBatchEvent event, RegionConfig acceptRegion) { + if (userRegionGateway.isOrdinaryUser(event.getSendUserId())) { + return getAssistGiftToOtherGoldRatioNormal(acceptRegion.getId()); } - return giftAcceptUsers; + return getAssistGiftToOtherGoldRatio(acceptRegion.getId()); + } + /** + * 计算有效发送比例. + */ + private BigDecimal calculateEffectiveSendRatio(GiveAwayGiftBatchEvent event, RegionConfig sendRegion, + BigDecimal sendAssistRatio, RegionConfig acceptRegion, + GiveAwayGiftRoomAccepts accept) { + // 送给自己 + if (Objects.equals(event.getSendUserId(), accept.getAcceptUserId())) { + if (userRegionGateway.isOrdinaryUser(event.getSendUserId())) { + return getAssistGiftToOwnGoldRatioNormal(sendRegion.getId()); + } + return sendAssistRatio; + } + // 送给别人 + return calculateAcceptAssistRatio(event, acceptRegion); } /** diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java index bfb104b9..0f9f1fe5 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java @@ -326,9 +326,8 @@ public class GiftCountStrategy implements GiftStrategy { return; } - CpRelationship cpRelationship = cpRelationshipService.getByUserId( - runningWater.getAcceptUsers().get(0).getAcceptUserId()); - //log.warn("cpRelationship:{}", cpRelationship); + CpRelationship cpRelationship = cpRelationshipService.getByUserId(runningWater.getUserId(), + runningWater.getAcceptUsers().get(0).getAcceptUserId()); if (Objects.isNull(cpRelationship)) { return; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java index 35902243..d3e59f1b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java @@ -315,52 +315,50 @@ public class RankCountStrategy implements GiftStrategy { } private void countCpValue(GiftGiveRunningWater runningWater) { - log.warn("cptesttest runningWater:{}", JacksonUtils.toJson(runningWater)); - CpRelationship cpRelationship = cpRelationshipService.getByUserId( - runningWater.getUserId()); - log.warn("cptesttest countCpValue1:{}", JacksonUtils.toJson(cpRelationship)); - if (Objects.isNull(cpRelationship)) { - return; - } - CpRelationship relationship = cpRelationshipService.getByUserId( - cpRelationship.getCpUserId()); - log.warn("cptesttest countCpValue2:{}", JacksonUtils.toJson(relationship)); - if (Objects.isNull(relationship)) { + List cpRelationshipList = cpRelationshipService.getByUserId(runningWater.getUserId()); + if (cpRelationshipList.isEmpty()) { return; } - List acceptUserIds = runningWater.getAcceptUsers().stream() - .map(GiftAcceptUser::getAcceptUserId) - .toList(); - log.warn("cptesttest countCpValue3:{},{}", JacksonUtils.toJson(acceptUserIds),cpRelationship.getCpUserId()); - if (!acceptUserIds.contains(cpRelationship.getCpUserId())) { - return; - } + Set acceptUserIds = runningWater.getAcceptUsers().stream() + .map(GiftAcceptUser::getAcceptUserId) + .collect(Collectors.toSet()); BigDecimal acceptAmount = runningWater.getGiftValue().getGiftValue(); - cpValueService.incrValue(cpRelationship.getCpValId(), acceptAmount); - log.warn("cptesttest countCpValue4:{},{}", cpRelationship.getCpValId(),acceptAmount); + + List cpUserIdList = cpRelationshipList.stream().map(CpRelationship::getCpUserId).toList(); + if (acceptUserIds.stream().noneMatch(cpUserIdList::contains)) { + return; + } + + cpRelationshipList.stream() + .filter(cp -> acceptUserIds.contains(cp.getCpUserId())) + .forEach(cp -> { + cpValueService.incrValue(cp.getCpValId(), acceptAmount); + + // 累计cp总额 + userCpValueCacheService.incr(cp.getUserId(), + cp.getCpUserId(), + acceptAmount.longValue()); + }); // 更新cp用户赠送的礼物价值 - cpRelationshipService.updateAccountByUserId(cpRelationship.getUserId(), - cpRelationship.getAmount().add(acceptAmount)); +// cpRelationshipService.updateAccountByUserId(cpRelationship.getUserId(), +// cpRelationship.getAmount().add(acceptAmount)); // 根据两个cp用户谁赠送的多确定区域 - String userRegionCode = - cpRelationship.getAmount().add(acceptAmount).compareTo(relationship.getAmount()) >= 0 - ? userRegionGateway.getRegionCode(cpRelationship.getUserId()) : - userRegionGateway.getRegionCode(relationship.getUserId()); +// String userRegionCode = +// cpRelationship.getAmount().add(acceptAmount).compareTo(relationship.getAmount()) >= 0 +// ? userRegionGateway.getRegionCode(cpRelationship.getUserId()) : +// userRegionGateway.getRegionCode(relationship.getUserId()); - weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(), + /*weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(), userRegionCode, cpRelationship.getUserId(), cpRelationship.getCpUserId(), - acceptAmount.longValue()); + acceptAmount.longValue());*/ + - // 累计cp总额 - userCpValueCacheService.incr(cpRelationship.getUserId(), - cpRelationship.getCpUserId(), - acceptAmount.longValue()); } private boolean isWeekStar(GiftValue giftValue) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java index d60686c3..3304acef 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java @@ -79,7 +79,7 @@ public class ActivityCorrectionDataManager { log.warn("correctionActivityData:CHARM_RANK_MONTH-完成"); // cp - CpRelationship cpRelationship = cpRelationshipService.getByUserId(userId); + CpRelationship cpRelationship = cpRelationshipService.getByUserId(userId, null); if (Objects.nonNull(cpRelationship)) { BigDecimal cpVal = cpValueService.getCpVal(cpRelationship.getCpValId()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java index f1a5687d..6fc9b0de 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java @@ -20,6 +20,8 @@ import com.red.circle.other.app.util.DistributedLockUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + /** * 用户cp关系实现. * @@ -44,7 +46,7 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { } @Override - public CpPairUserProfileCO getCpPairUserProfileCO(AppExtCommand cmd) { + public List getCpPairUserProfileCO(AppExtCommand cmd) { return userCpPairUserProfileQryExe.execute(cmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java index 1b293a95..ca9b31a8 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java @@ -45,7 +45,7 @@ public class CpBlessRecordAndUpReadExe { .build(); } - CpRelationship relationship = cpRelationshipService.getByUserId(cmd.getUserId()); + CpRelationship relationship = cpRelationshipService.getByUserId(cmd.getReqUserId(), cmd.getUserId()); if (Objects.isNull(relationship)) { return UserCpCabinUnreadCO.builder() .topClassRecords(Lists.newArrayList()) diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java index 7e91f9ee..5fc829fd 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java @@ -9,6 +9,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import java.math.BigDecimal; + /** * cp用户资料 * @@ -30,6 +32,11 @@ public class CpPairUserProfileCO extends ClientObject { */ private UserProfileDTO cpUserProfile; + /** + * 心动值 + */ + private BigDecimal cpValue; + /** * 组建天数. */ diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java index 9c0343da..6ced1d5f 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java @@ -10,6 +10,8 @@ import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; +import java.util.List; + /** * 用户cp关系. * @@ -19,7 +21,7 @@ public interface UserCpRelationService { CpUserProfileCO getCpUser(UserIdCmd cmd); - CpPairUserProfileCO getCpPairUserProfileCO(AppExtCommand cmd); + List getCpPairUserProfileCO(AppExtCommand cmd); void sendApply(CpApplyCmd cmd); diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java index 62b3c013..1725b381 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java @@ -26,14 +26,6 @@ public interface CpRelationshipService extends BaseService { */ List listLatestCp(String sysOrigin, Set excludeUserId, Integer size); - /** - * 是否存在cp. - * - * @param userIds 用户id - * @return true 存在,false 不存在 - */ - boolean existsCp(Long userIds); - /** * 是否互为cp. */ @@ -45,23 +37,17 @@ public interface CpRelationshipService extends BaseService { * @param userId 用户id * @return cp id */ - Long getCpUserId(Long userId); + List getCpUserId(Long userId); + + /** + * 获取cp信息集合 + */ + List getByUserId(Long userId); /** * 获取cp信息. - * - * @param userId 用户id - * @return cp id */ - CpRelationship getByUserId(Long userId); - - /** - * 获取cp信息. - * - * @param cpUserId 用户id - * @return cp id - */ - CpRelationship getByCpUserId(Long cpUserId); + CpRelationship getByUserId(Long userId, Long cpUserId); /** * 获取cpValId diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java index 647f038b..55668736 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java @@ -44,15 +44,6 @@ public class CpRelationshipServiceImpl extends return cpRelationshipDAO.listLatestCpExcludeUserId(sysOrigin, excludeUserId, size); } - @Override - public boolean existsCp(Long userId) { - return Optional.ofNullable( - query().select(CpRelationship::getId) - .eq(CpRelationship::getUserId, userId) - .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) - .last(PageConstant.LIMIT_ONE).getOne() - ).map(cpRelationship -> Objects.nonNull(cpRelationship.getId())).orElse(Boolean.FALSE); - } @Override public boolean existsCp(Long userId, Long cpUserId) { @@ -70,30 +61,33 @@ public class CpRelationshipServiceImpl extends } @Override - public Long getCpUserId(Long userId) { - return Optional.ofNullable( - query().select(CpRelationship::getCpUserId).eq(CpRelationship::getUserId, userId) - .last(PageConstant.LIMIT_ONE).getOne() - ).map(CpRelationship::getCpUserId).orElse(null); + public List getCpUserId(Long userId) { + return query().select(CpRelationship::getCpUserId) + .eq(CpRelationship::getUserId, userId) + .list() + .stream().map(CpRelationship::getCpUserId) + .toList(); } @Override - public CpRelationship getByUserId(Long userId) { - return Optional.ofNullable(query() - .eq(CpRelationship::getUserId, userId) - .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) - .last(PageConstant.LIMIT_ONE) - .getOne() - ).orElse(null); + public List getByUserId(Long userId) { + return query() + .eq(CpRelationship::getUserId, userId) + .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) + .list(); } @Override - public CpRelationship getByCpUserId(Long cpUserId) { - return Optional.ofNullable(query() - .eq(CpRelationship::getCpUserId, cpUserId) - .last(PageConstant.LIMIT_ONE) - .getOne() - ).orElse(null); + public CpRelationship getByUserId(Long userId, Long cpUserId) { + return query() + .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) + .and(where -> where + .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) + .or() + .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) + ) + .last(PageConstant.LIMIT_ONE) + .getOne(); } @Override diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java index 83065593..9448aba4 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/user/UserCpClientEndpoint.java @@ -130,7 +130,7 @@ public class UserCpClientEndpoint implements UserCpClientApi { @Override - public ResultResponse getCpUserId(Long userId) { + public ResultResponse> getCpUserId(Long userId) { return ResultResponse.success(userCpWeekClientService.getCpUserId(userId)); } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpWeekClientService.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpWeekClientService.java index 4c6a55b7..1b6ef118 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpWeekClientService.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserCpWeekClientService.java @@ -50,7 +50,7 @@ public interface UserCpWeekClientService { * @param userId 用户id * @return cp id */ - Long getCpUserId(Long userId); + List getCpUserId(Long userId); /** * 获取最近cp. diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java index e7227296..8462e8cc 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpClientServiceImpl.java @@ -47,8 +47,8 @@ public class UserCpClientServiceImpl implements UserCpClientService { @Override public CpRelationshipDTO getByUserId(Long userId) { - return userCpInnerConvertor.toCpRelationshipDTO( - cpRelationshipService.getByUserId(userId)); + List cpRelationships = cpRelationshipService.getByUserId(userId); + return userCpInnerConvertor.toCpRelationshipDTO(cpRelationships.isEmpty() ? null : cpRelationships.get(0)); } @Override diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpWeekClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpWeekClientServiceImpl.java index 35d62070..34aa3661 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpWeekClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserCpWeekClientServiceImpl.java @@ -74,7 +74,7 @@ public class UserCpWeekClientServiceImpl implements UserCpWeekClientService { } @Override - public Long getCpUserId(Long userId) { + public List getCpUserId(Long userId) { return cpRelationshipService.getCpUserId(userId); }