diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCountRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCountRestController.java index 3c02021b..6c0de8c0 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCountRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCountRestController.java @@ -1,9 +1,15 @@ package com.red.circle.other.adapter.app.user.user; import com.red.circle.common.business.dto.cmd.UserIdCmd; +import com.red.circle.order.inner.endpoint.TotalRechargeClient; +import com.red.circle.order.inner.model.dto.UserTotalRechargeDTO; import com.red.circle.other.app.dto.clientobject.user.user.UserGuardCountCO; import com.red.circle.other.app.service.user.user.UserCountService; -import java.util.List; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; + import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; @@ -25,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController; public class UserCountRestController { private final UserCountService userCountService; + private final TotalRechargeClient totalRechargeClient; /** * 守护列表. @@ -40,4 +47,20 @@ public class UserCountRestController { return userCountService.listUserGuardCountTop(cmd); } + /** + * 用户累计充值 + */ + @GetMapping("/total-recharge") + public BigDecimal getTotalRecharge(UserIdCmd cmd) { + Set uIdSet = new HashSet<>(); + uIdSet.add(cmd.getReqUserId()); + Map> userTotalRechargeMap = totalRechargeClient.mapGroup(uIdSet).getBody(); + + return Optional.ofNullable(userTotalRechargeMap.get(cmd.getReqUserId())) + .map(totalRecharges -> totalRecharges.stream().map(UserTotalRechargeDTO::getAmount) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .setScale(2, RoundingMode.DOWN)) + .orElse(BigDecimal.ZERO); + } + }