From bea1d6eafd33f828a2ab9a4e81fae0f05e1a3089 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Tue, 9 Dec 2025 20:07:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A7=E8=BF=90=E4=BB=A3=E7=90=86=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E5=A2=9E=E5=8C=BA=E5=9F=9F=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserFreightBalanceRestServiceImpl.java | 74 +++++++++++++++---- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/impl/UserFreightBalanceRestServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/impl/UserFreightBalanceRestServiceImpl.java index c79926a9..6a753006 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/impl/UserFreightBalanceRestServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/impl/UserFreightBalanceRestServiceImpl.java @@ -3,6 +3,7 @@ package com.red.circle.other.app.service.user.impl; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.dto.PageQuery; import com.red.circle.framework.dto.PageResult; import com.red.circle.other.app.convertor.UserFreightBalanceConvertor; import com.red.circle.other.app.dto.clientobject.sys.AppCountryCodeCO; @@ -10,7 +11,10 @@ import com.red.circle.other.app.dto.clientobject.sys.CountryCodeCO; import com.red.circle.other.app.dto.clientobject.user.UserFreightBalanceCO; import com.red.circle.other.app.service.sys.AppConfigService; import com.red.circle.other.app.service.user.UserFreightBalanceRestService; +import com.red.circle.other.app.service.user.user.UserRegionService; import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; +import com.red.circle.other.domain.model.user.UserProfile; 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.FreightBalanceClient; @@ -40,42 +44,77 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest private final UserProfileClient userProfileClient; private final AppConfigService appConfigService; private final UserProfileGateway userProfileGateway; + private final UserRegionGateway userRegionGateway; private final UserFreightBalanceConvertor userFreightBalanceConvertor; @Override public PageResult pageFreight(UserFreightBalancePageQryCmd cmd, AppExtCommand appExtCommand) { - // 写死默认查询条件:H5开启且未关闭 + // 获取请求用户的国家编码 + UserProfile userProfile = userProfileGateway.getByUserId(appExtCommand.getReqUserId()); + String countryCode = userProfile.getCountryCode(); + cmd.setH5Display(true); cmd.setClose(false); + + PageQuery pageQuery = cmd.getPageQuery(); + + // 保存原始分页参数 + int pageNo = pageQuery.getCursor(); + int pageSize = pageQuery.getLimit(); - // 1. 查询货运账户分页数据 + pageQuery.setCursor(1); + pageQuery.setLimit(500); PageResult freightPageResult = freightGoldClient.pageFreight(cmd).getBody(); if (freightPageResult.checkRecordsEmpty()) { return freightPageResult.emptyRecords(); } + + // 根据国家编码过滤数据 + List filteredRecords = freightPageResult.getRecords().stream() + .filter(dto -> isCountrySupported(userProfile.getId(), dto.getUserId())) + .collect(Collectors.toList()); + + if (filteredRecords.isEmpty()) { + return PageResult.newPageResult(20); + } + + // 手动分页 + int total = filteredRecords.size(); + int fromIndex = (pageNo - 1) * pageSize; + int toIndex = Math.min(fromIndex + pageSize, total); + + if (fromIndex >= total) { + return PageResult.newPageResult(20); + } + + List pagedRecords = filteredRecords.subList(fromIndex, toIndex); + + // 构建分页结果 + PageResult pagedResult = new PageResult<>(); + pagedResult.setRecords(pagedRecords); + pagedResult.setTotal((long) total); + pagedResult.setCurrent(pageNo); + pagedResult.setSize(pageSize); + + if (pagedResult.checkRecordsEmpty()) { + return pagedResult.emptyRecords(); + } - // 2. 查询用户ID集合 - Set userIds = freightPageResult.getRecords().stream() + Set userIds = pagedResult.getRecords().stream() .map(UserFreightBalanceDTO::getUserId) .collect(Collectors.toSet()); - // 3. 查询用户基本信息 - Map userBaseInfoMap = ResponseAssert.requiredSuccess( - userProfileClient.mapByUserIds(userIds) - ); + // 查询用户基本信息 + Map userBaseInfoMap = ResponseAssert.requiredSuccess(userProfileClient.mapByUserIds(userIds)); - // 4. 查询交易次数(type=1) Map transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody(); - - // 5. 获取支持的国家配置 AppCountryCodeCO appCountryCode = appConfigService.getAppCountryCode(); - + // 构建国家代码到国旗URL的映射 Map countryFlagMap = buildCountryFlagMap(appCountryCode); - // 6. 转换并组装数据 - return freightPageResult.convert(dto -> { + return pagedResult.convert(dto -> { UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto); co.setBalance(dto.getBalance()); co.setIsFollow(userProfileGateway.checkFollow(appExtCommand.getReqUserId(), dto.getUserId())); @@ -105,6 +144,13 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest }); } + /** + * 检查国家是否在支持列表中. + */ + private boolean isCountrySupported(Long userId, Long dtoUserId) { + return userRegionGateway.checkEqRegion(userId, dtoUserId); + } + /** * 构建国家代码到国旗URL的映射. */