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 a05a62e1..24e1d59b 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 @@ -1,10 +1,14 @@ 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.PageResult; import com.red.circle.other.app.convertor.UserFreightBalanceConvertor; +import com.red.circle.other.app.dto.clientobject.sys.AppCountryCodeCO; +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.domain.gateway.user.UserProfileGateway; import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; @@ -36,6 +40,7 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest private final FreightGoldClient freightGoldClient; private final UserProfileClient userProfileClient; + private final AppConfigService appConfigService; private final UserProfileGateway userProfileGateway; private final UserFreightBalanceConvertor userFreightBalanceConvertor; @@ -65,7 +70,13 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest // 4. 查询交易次数(type=1) Map transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody(); - // 5. 转换并组装数据 + // 5. 获取支持的国家配置 + AppCountryCodeCO appCountryCode = appConfigService.getAppCountryCode(); + + // 构建国家代码到国旗URL的映射 + Map countryFlagMap = buildCountryFlagMap(appCountryCode); + + // 6. 转换并组装数据 return freightPageResult.convert(dto -> { UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto); co.setBalance(dto.getBalance()); @@ -85,8 +96,58 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest Optional.ofNullable(transactionCountMap.get(dto.getUserId())).orElse(0L) ); + // 匹配并设置国旗URL + co.setNationalFlag(matchNationalFlag(dto.getSupportedCountries(), countryFlagMap)); + return co; }); } + /** + * 构建国家代码到国旗URL的映射. + */ + private Map buildCountryFlagMap(AppCountryCodeCO appCountryCode) { + if (appCountryCode == null || appCountryCode.getOpenCountry() == null) { + return Map.of(); + } + + return appCountryCode.getOpenCountry().stream() + .filter(country -> StringUtils.isNotBlank(country.getCountryName()) && StringUtils.isNotBlank(country.getNationalFlag())) + .collect(Collectors.toMap( + CountryCodeCO::getCountryName, + CountryCodeCO::getNationalFlag, + (existing, replacement) -> existing + )); + } + + /** + * 匹配国旗URL. + * + * @param supportedCountries 支持的国家(逗号分隔) + * @param countryFlagMap 国家代码到国旗URL的映射 + * @return 所有匹配的国旗URL(逗号分隔),如果没有匹配则返回空字符串 + */ + private String matchNationalFlag(String supportedCountries, Map countryFlagMap) { + if (supportedCountries == null || supportedCountries.isEmpty() || countryFlagMap.isEmpty()) { + return ""; + } + + // 分割支持的国家代码 + String[] countries = supportedCountries.split(","); + + // 收集所有匹配到的国旗URL + StringBuilder flagUrls = new StringBuilder(); + for (String country : countries) { + String countryCode = country.trim(); + if (countryFlagMap.containsKey(countryCode)) { + if (!flagUrls.isEmpty()) { + flagUrls.append(","); + } + flagUrls.append(countryFlagMap.get(countryCode)); + } + } + + return flagUrls.toString(); + } + } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/UserFreightBalanceCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/UserFreightBalanceCO.java index 4bd25560..ea8b48e4 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/UserFreightBalanceCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/UserFreightBalanceCO.java @@ -128,4 +128,9 @@ public class UserFreightBalanceCO extends ClientObject { */ private UserProfileDTO userBaseInfo; + /** + * 支持的国家国旗URL列表(根据supportedCountries匹配所有国旗,逗号分隔). + */ + private String nationalFlag; + }