From 4f1e0b8be1b664d89322250af898ea9cb41b5a91 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 11 Dec 2025 19:10:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=B7=A5=E8=B5=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../freight/api/FreightGoldClientApi.java | 10 +++ .../app/h5/MemberActiveController.java | 3 +- .../command/bd/query/BdTeamSummaryQryExe.java | 19 ++--- .../user/user/RechargeUserServiceImpl.java | 72 +++++++++++++------ .../other/app/dto/h5/RechargePageVO.java | 8 +-- .../other/app/dto/h5/RechargeSummaryVO.java | 26 +++++++ .../service/recharge/RechargeUserService.java | 6 +- .../AdminRechargeAgentRelationService.java | 3 +- ...AdminRechargeAgentRelationServiceImpl.java | 17 ++--- .../FreightBalanceRunningWaterService.java | 12 ++++ ...FreightBalanceRunningWaterServiceImpl.java | 18 +++++ .../freight/FreightGoldClientEndpoint.java | 5 ++ .../freight/FreightGoldClientService.java | 5 ++ .../impl/FreightGoldClientServiceImpl.java | 6 ++ 14 files changed, 151 insertions(+), 59 deletions(-) create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeSummaryVO.java diff --git a/rc-service/rc-inner-api/wallet-inner/wallet-inner-api/src/main/java/com/red/circle/wallet/inner/endpoint/freight/api/FreightGoldClientApi.java b/rc-service/rc-inner-api/wallet-inner/wallet-inner-api/src/main/java/com/red/circle/wallet/inner/endpoint/freight/api/FreightGoldClientApi.java index f30b98e6..1b690d5f 100644 --- a/rc-service/rc-inner-api/wallet-inner/wallet-inner-api/src/main/java/com/red/circle/wallet/inner/endpoint/freight/api/FreightGoldClientApi.java +++ b/rc-service/rc-inner-api/wallet-inner/wallet-inner-api/src/main/java/com/red/circle/wallet/inner/endpoint/freight/api/FreightGoldClientApi.java @@ -146,4 +146,14 @@ public interface FreightGoldClientApi { */ @PostMapping("/mapTransactionCountByUserIds") ResultResponse> mapTransactionCountByUserIds(@RequestBody Set userIds); + + /** + * 查询用户指定时间和类型的总金额. + */ + @GetMapping("/getTotalAmountByCondition") + ResultResponse getTotalAmountByCondition( + @RequestParam("userId") Long userId, + @RequestParam("startTime") String startTime, + @RequestParam(value = "endTime", required = false) String endTime, + @RequestParam(value = "rechargeType", required = false) String rechargeType); } diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java index 9b79efdf..1333997e 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java @@ -12,6 +12,7 @@ import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO; import com.red.circle.other.app.dto.cmd.material.PropsStoreTypeQryCmd; import com.red.circle.other.app.dto.h5.MemberActiveDTO; import com.red.circle.other.app.dto.h5.RechargePageVO; +import com.red.circle.other.app.dto.h5.RechargeSummaryVO; import com.red.circle.other.app.dto.h5.UserIdentityVO; import com.red.circle.other.app.service.h5.MemberActiveService; import com.red.circle.other.app.service.recharge.RechargeUserService; @@ -71,7 +72,7 @@ public class MemberActiveController extends BaseController { * 货运代理充值月度汇总(当月,上月) */ @GetMapping("/recharge-summary") - public List rechargeSummary(AppExtCommand cmd) { + public RechargeSummaryVO rechargeSummary(AppExtCommand cmd) { return rechargeUserService.getRechargeSummary(cmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamSummaryQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamSummaryQryExe.java index 7d9f0a78..fff11003 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamSummaryQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/BdTeamSummaryQryExe.java @@ -7,6 +7,7 @@ import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.BdTeamMemberCO; import com.red.circle.other.app.dto.clientobject.BdTeamSummaryCO; +import com.red.circle.other.app.dto.h5.RechargeSummaryVO; import com.red.circle.other.app.service.recharge.RechargeUserService; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.infra.database.mongo.dto.team.TeamBillMemberTarget; @@ -295,26 +296,16 @@ public class BdTeamSummaryQryExe { cmd.setReqUserId(userId); // 获取充值汇总数据 - List rechargeSummaryList = rechargeUserService.getRechargeSummary(cmd); + RechargeSummaryVO rechargeSummary = rechargeUserService.getRechargeSummary(cmd); - if (CollectionUtils.isEmpty(rechargeSummaryList)) { + if (rechargeSummary == null) { item.setCount(0); item.setTotalIncome(BigDecimal.ZERO); return item; } - // 计算累积的用户数量(去重) - long totalUserCount = rechargeSummaryList.stream() - .mapToLong(MonthlyRechargeSummaryVO::getUserCount) - .sum(); - - // 计算累积的总充值金额 - BigDecimal totalAmount = rechargeSummaryList.stream() - .map(MonthlyRechargeSummaryVO::getTotalAmount) - .reduce(BigDecimal.ZERO, BigDecimal::add); - - item.setCount((int) totalUserCount); - item.setTotalIncome(totalAmount); + item.setCount(rechargeSummary.getCount()); + item.setTotalIncome(rechargeSummary.getCurrentMonthRecharge()); return item; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java index 9f235f73..b236f156 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java @@ -1,5 +1,6 @@ package com.red.circle.other.app.service.user.user; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.common.business.dto.cmd.PageUserIdCmd; @@ -7,24 +8,27 @@ import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.framework.dto.PageResult; import com.red.circle.order.inner.endpoint.UserMonthlyRechargeClient; -import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO; import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO; import com.red.circle.other.app.dto.h5.RechargePageVO; +import com.red.circle.other.app.dto.h5.RechargeSummaryVO; import com.red.circle.other.app.service.recharge.RechargeUserService; import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation; import com.red.circle.other.infra.database.rds.service.sys.AdministratorService; import com.red.circle.other.infra.database.rds.service.team.AdminRechargeAgentRelationService; import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.wallet.inner.endpoint.freight.FreightGoldClient; import com.red.circle.wallet.inner.endpoint.salary.UserSalaryAccountClient; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.HashSet; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; @Service @@ -36,6 +40,8 @@ public class RechargeUserServiceImpl implements RechargeUserService { private final AdministratorService administratorService; private final AdminRechargeAgentRelationService adminRechargeAgentRelationService; private final UserSalaryAccountClient userSalaryAccountClient; + private final FreightGoldClient freightGoldClient; + private final static String RECHARGE_TYPE = "USDT-进货"; @Override public PageResult getRechargePage(PageUserIdCmd page, AppExtCommand cmd) { @@ -47,24 +53,31 @@ public class RechargeUserServiceImpl implements RechargeUserService { Page objectPage = new Page<>(); objectPage.setCurrent(page.getPageQuery().getCursor()); objectPage.setSize(page.getPageQuery().getLimit()); - Page pagedRechargeAgency = adminRechargeAgentRelationService.pageRechargeAgentByAdmin(cmd.getReqUserId(), objectPage); + IPage pagedRechargeAgency = adminRechargeAgentRelationService.pageRechargeAgentByAdmin(cmd.getReqUserId(), objectPage); if (pagedRechargeAgency == null || pagedRechargeAgency.getRecords().isEmpty()) { return null; } - List collect = pagedRechargeAgency.getRecords().stream().toList(); - Map userLastMonthAmountMap = getLastMonthRechargeAmount(collect); + List relations = pagedRechargeAgency.getRecords(); - List list = pagedRechargeAgency.getRecords().stream().map(userId -> { - UserProfileDTO body = userProfileClient.getByUserId(userId).getBody(); - BigDecimal totalIncome = userSalaryAccountClient.getTotalIncome(userId, "ADMIN_SALARY").getBody(); - return new RechargePageVO() - .setUserId(userId) - .setAccount(body.getAccount()) - .setUserNickname(body.getUserNickname()) - .setUserAvatar(body.getUserAvatar()) - .setTotalIncome(totalIncome != null ? totalIncome : BigDecimal.ZERO) - .setThisMonthRecharge(userLastMonthAmountMap.get(userId)); + List list = relations.stream().map(relation -> { + Long userId = relation.getUserId(); + LocalDateTime bindTime = relation.getCreateTime(); + + UserProfileDTO body = userProfileClient.getByUserId(userId).getBody(); + + // 计算绑定日期到当前的总充值(当月) + String bindTimeStr = bindTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + String endTimeStr = YearMonth.now().atEndOfMonth().atTime(23, 59, 59).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + BigDecimal thisMonth = freightGoldClient.getTotalAmountByCondition(userId, bindTimeStr, endTimeStr, RECHARGE_TYPE).getBody(); + + return new RechargePageVO() + .setUserId(userId) + .setAccount(body.getAccount()) + .setUserNickname(body.getUserNickname()) + .setUserAvatar(body.getUserAvatar()) + .setThisMonth(thisMonth != null ? thisMonth : BigDecimal.ZERO) + .setLastMonth(BigDecimal.ZERO); }).toList(); PageResult result = PageResult.newPageResult(list.size()); @@ -76,18 +89,33 @@ public class RechargeUserServiceImpl implements RechargeUserService { } @Override - public List getRechargeSummary(AppExtCommand cmd) { - + public RechargeSummaryVO getRechargeSummary(AppExtCommand cmd) { Page objectPage = new Page<>(); objectPage.setCurrent(1L); objectPage.setSize(3000L); - Page pagedRechargeAgency = adminRechargeAgentRelationService.pageRechargeAgentByAdmin(cmd.getReqUserId(), objectPage); + IPage pagedRechargeAgency = adminRechargeAgentRelationService.pageRechargeAgentByAdmin(cmd.getReqUserId(), objectPage); if (pagedRechargeAgency == null || pagedRechargeAgency.getRecords().isEmpty()) { - return null; + return new RechargeSummaryVO() + .setTotalIncome(BigDecimal.ZERO) + .setCurrentMonthRecharge(BigDecimal.ZERO); } - Set collect = new HashSet<>(pagedRechargeAgency.getRecords()); - return userMonthlyRechargeClient.getMonthlyRechargeSummary(collect).getBody(); + List relations = pagedRechargeAgency.getRecords(); + + + BigDecimal currentMonthRecharge = BigDecimal.ZERO; + for (AdminRechargeAgentRelation relation : relations) { + String monthStart = relation.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + String monthEnd = YearMonth.now().atEndOfMonth().atTime(23, 59, 59).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + + BigDecimal monthRecharge = freightGoldClient.getTotalAmountByCondition(relation.getUserId(), monthStart, monthEnd, RECHARGE_TYPE).getBody(); + currentMonthRecharge = currentMonthRecharge.add(monthRecharge != null ? monthRecharge : BigDecimal.ZERO); + } + + return new RechargeSummaryVO() + .setTotalIncome(userSalaryAccountClient.getTotalIncome(cmd.getReqUserId(), "ADMIN_SALARY").getBody()) + .setCurrentMonthRecharge(currentMonthRecharge) + .setCount(pagedRechargeAgency.getRecords().size()); } private Map getLastMonthRechargeAmount(List collect) { diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java index 79f46127..a1a111ee 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java @@ -33,13 +33,13 @@ public class RechargePageVO implements Serializable { private String userNickname; /** - * 累计收入 + * 这个月金额 */ - private BigDecimal totalIncome; + private BigDecimal thisMonth; /** - * 本月收入 + * 上个月金额 */ - private BigDecimal thisMonthRecharge; + private BigDecimal lastMonth; } \ No newline at end of file diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeSummaryVO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeSummaryVO.java new file mode 100644 index 00000000..6f03963c --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeSummaryVO.java @@ -0,0 +1,26 @@ +package com.red.circle.other.app.dto.h5; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; + +/** + * 充值汇总VO. + */ +@Data +@Accessors(chain = true) +public class RechargeSummaryVO { + + /** + * 总收入. + */ + private BigDecimal totalIncome; + + /** + * 当月总充值. + */ + private BigDecimal currentMonthRecharge; + + private Integer count; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java index b1eebbb3..5de1c3e5 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java @@ -3,10 +3,8 @@ package com.red.circle.other.app.service.recharge; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.common.business.dto.cmd.PageUserIdCmd; import com.red.circle.framework.dto.PageResult; -import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO; import com.red.circle.other.app.dto.h5.RechargePageVO; - -import java.util.List; +import com.red.circle.other.app.dto.h5.RechargeSummaryVO; public interface RechargeUserService { @@ -15,5 +13,5 @@ public interface RechargeUserService { */ PageResult getRechargePage(PageUserIdCmd page, AppExtCommand cmd); - List getRechargeSummary(AppExtCommand cmd); + RechargeSummaryVO getRechargeSummary(AppExtCommand cmd); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java index 6770f38f..6b6cff5f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/AdminRechargeAgentRelationService.java @@ -1,5 +1,6 @@ package com.red.circle.other.infra.database.rds.service.team; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.red.circle.framework.mybatis.service.BaseService; import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation; @@ -41,6 +42,6 @@ public interface AdminRechargeAgentRelationService extends BaseService pageRechargeAgentByAdmin(Long adminUserId, Page page); + IPage pageRechargeAgentByAdmin(Long adminUserId, Page page); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/impl/AdminRechargeAgentRelationServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/impl/AdminRechargeAgentRelationServiceImpl.java index b444fb03..de3572b7 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/impl/AdminRechargeAgentRelationServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/team/impl/AdminRechargeAgentRelationServiceImpl.java @@ -38,19 +38,10 @@ public class AdminRechargeAgentRelationServiceImpl extends } @Override - public Page pageRechargeAgentByAdmin(Long adminUserId, Page page) { - IPage relationPage = page(page, new LambdaQueryWrapper() - .eq(AdminRechargeAgentRelation::getAdminUserId, adminUserId) - .orderByDesc(AdminRechargeAgentRelation::getCreateTime)); - - Page result = new Page<>(); - result.setCurrent(relationPage.getCurrent()); - result.setSize(relationPage.getSize()); - result.setTotal(relationPage.getTotal()); - result.setRecords(relationPage.getRecords().stream() - .map(AdminRechargeAgentRelation::getUserId) - .toList()); - return result; + public IPage pageRechargeAgentByAdmin(Long adminUserId, Page page) { + return page(page, new LambdaQueryWrapper() + .eq(AdminRechargeAgentRelation::getAdminUserId, adminUserId) + .orderByDesc(AdminRechargeAgentRelation::getCreateTime)); } } diff --git a/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/FreightBalanceRunningWaterService.java b/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/FreightBalanceRunningWaterService.java index 5c760d53..7433b7c2 100644 --- a/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/FreightBalanceRunningWaterService.java +++ b/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/FreightBalanceRunningWaterService.java @@ -6,6 +6,7 @@ import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalanceRun import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExportQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightSellerRunningWaterPageQryCmd; +import java.math.BigDecimal; import java.util.List; import java.util.Map; import java.util.Set; @@ -71,4 +72,15 @@ public interface FreightBalanceRunningWaterService extends BaseService 交易次数 */ Map countTransactionsByUserIds(Set userIds); + + /** + * 查询用户指定时间和类型的总金额. + * + * @param userId 用户ID + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param rechargeType 充值类型 + * @return 总金额 + */ + BigDecimal sumAmountByCondition(Long userId, String startTime, String endTime, String rechargeType); } diff --git a/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/impl/FreightBalanceRunningWaterServiceImpl.java b/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/impl/FreightBalanceRunningWaterServiceImpl.java index 51b91b82..7c7f43fe 100644 --- a/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/impl/FreightBalanceRunningWaterServiceImpl.java +++ b/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/database/rds/service/freight/impl/FreightBalanceRunningWaterServiceImpl.java @@ -14,6 +14,8 @@ import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceRu import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExportQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightSellerRunningWaterPageQryCmd; + +import java.math.BigDecimal; import java.sql.Timestamp; import java.util.HashMap; import java.util.List; @@ -152,4 +154,20 @@ public class FreightBalanceRunningWaterServiceImpl extends .list(); return list.stream().collect(Collectors.groupingBy(FreightBalanceRunningWater::getUserId, Collectors.counting())); } + + @Override + public BigDecimal sumAmountByCondition(Long userId, String startTime, String endTime, String rechargeType) { + List list = query() + .select(FreightBalanceRunningWater::getAmount) + .eq(FreightBalanceRunningWater::getUserId, userId) + .eq(Objects.nonNull(rechargeType), FreightBalanceRunningWater::getRechargeType, rechargeType) + .apply(StringUtils.isNotBlank(startTime), "create_time >= {0}", startTime) + .apply(StringUtils.isNotBlank(endTime), "create_time <= {0}", endTime) + .list(); + + return list.stream() + .map(FreightBalanceRunningWater::getAmount) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } } diff --git a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/endpoint/freight/FreightGoldClientEndpoint.java b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/endpoint/freight/FreightGoldClientEndpoint.java index 1ef30155..a78d1d27 100644 --- a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/endpoint/freight/FreightGoldClientEndpoint.java +++ b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/endpoint/freight/FreightGoldClientEndpoint.java @@ -189,4 +189,9 @@ public class FreightGoldClientEndpoint implements FreightGoldClientApi { public ResultResponse> mapTransactionCountByUserIds(Set userIds) { return ResultResponse.success(freightGoldClientService.mapTransactionCountByUserIds(userIds)); } + + @Override + public ResultResponse getTotalAmountByCondition(Long userId, String startTime, String endTime, String rechargeType) { + return ResultResponse.success(freightGoldClientService.getTotalAmountByCondition(userId, startTime, endTime, rechargeType)); + } } diff --git a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/FreightGoldClientService.java b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/FreightGoldClientService.java index a1a5de8a..ad363ae7 100644 --- a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/FreightGoldClientService.java +++ b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/FreightGoldClientService.java @@ -116,4 +116,9 @@ public interface FreightGoldClientService { * 批量查询用户交易次数(type=1的记录数). */ Map mapTransactionCountByUserIds(Set userIds); + + /** + * 查询用户指定时间和类型的总金额. + */ + BigDecimal getTotalAmountByCondition(Long userId, String startTime, String endTime, String rechargeType); } diff --git a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/impl/FreightGoldClientServiceImpl.java b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/impl/FreightGoldClientServiceImpl.java index 2bbae8a1..7e5caed7 100644 --- a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/impl/FreightGoldClientServiceImpl.java +++ b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/service/freight/impl/FreightGoldClientServiceImpl.java @@ -260,4 +260,10 @@ public class FreightGoldClientServiceImpl implements FreightGoldClientService { public Map mapTransactionCountByUserIds(Set userIds) { return freightBalanceRunningWaterService.countTransactionsByUserIds(userIds); } + + @Override + public BigDecimal getTotalAmountByCondition(Long userId, String startTime, String endTime, String rechargeType) { + BigDecimal total = freightBalanceRunningWaterService.sumAmountByCondition(userId, startTime, endTime, rechargeType); + return total != null ? total : BigDecimal.ZERO; + } }