货运代理列表接口新增支持的国家国旗字段
This commit is contained in:
parent
fcd78d79b0
commit
4e6358c0fb
@ -1,10 +1,14 @@
|
|||||||
package com.red.circle.other.app.service.user.impl;
|
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.common.business.dto.cmd.AppExtCommand;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
import com.red.circle.framework.dto.PageResult;
|
import com.red.circle.framework.dto.PageResult;
|
||||||
import com.red.circle.other.app.convertor.UserFreightBalanceConvertor;
|
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.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.UserFreightBalanceRestService;
|
||||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||||
import com.red.circle.other.inner.endpoint.user.user.UserProfileClient;
|
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 FreightGoldClient freightGoldClient;
|
||||||
private final UserProfileClient userProfileClient;
|
private final UserProfileClient userProfileClient;
|
||||||
|
private final AppConfigService appConfigService;
|
||||||
private final UserProfileGateway userProfileGateway;
|
private final UserProfileGateway userProfileGateway;
|
||||||
private final UserFreightBalanceConvertor userFreightBalanceConvertor;
|
private final UserFreightBalanceConvertor userFreightBalanceConvertor;
|
||||||
|
|
||||||
@ -65,7 +70,13 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest
|
|||||||
// 4. 查询交易次数(type=1)
|
// 4. 查询交易次数(type=1)
|
||||||
Map<Long, Long> transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody();
|
Map<Long, Long> transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody();
|
||||||
|
|
||||||
// 5. 转换并组装数据
|
// 5. 获取支持的国家配置
|
||||||
|
AppCountryCodeCO appCountryCode = appConfigService.getAppCountryCode();
|
||||||
|
|
||||||
|
// 构建国家代码到国旗URL的映射
|
||||||
|
Map<String, String> countryFlagMap = buildCountryFlagMap(appCountryCode);
|
||||||
|
|
||||||
|
// 6. 转换并组装数据
|
||||||
return freightPageResult.convert(dto -> {
|
return freightPageResult.convert(dto -> {
|
||||||
UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto);
|
UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto);
|
||||||
co.setBalance(dto.getBalance());
|
co.setBalance(dto.getBalance());
|
||||||
@ -85,8 +96,58 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest
|
|||||||
Optional.ofNullable(transactionCountMap.get(dto.getUserId())).orElse(0L)
|
Optional.ofNullable(transactionCountMap.get(dto.getUserId())).orElse(0L)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 匹配并设置国旗URL
|
||||||
|
co.setNationalFlag(matchNationalFlag(dto.getSupportedCountries(), countryFlagMap));
|
||||||
|
|
||||||
return co;
|
return co;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建国家代码到国旗URL的映射.
|
||||||
|
*/
|
||||||
|
private Map<String, String> 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<String, String> 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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,4 +128,9 @@ public class UserFreightBalanceCO extends ClientObject {
|
|||||||
*/
|
*/
|
||||||
private UserProfileDTO userBaseInfo;
|
private UserProfileDTO userBaseInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支持的国家国旗URL列表(根据supportedCountries匹配所有国旗,逗号分隔).
|
||||||
|
*/
|
||||||
|
private String nationalFlag;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user