货运代理列表新增区域匹配
This commit is contained in:
parent
3c6b6fa1ae
commit
bea1d6eafd
@ -3,6 +3,7 @@ package com.red.circle.other.app.service.user.impl;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
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.PageQuery;
|
||||||
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.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.dto.clientobject.user.UserFreightBalanceCO;
|
||||||
import com.red.circle.other.app.service.sys.AppConfigService;
|
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.app.service.user.user.UserRegionService;
|
||||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
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.endpoint.user.user.UserProfileClient;
|
||||||
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
||||||
import com.red.circle.wallet.inner.endpoint.freight.FreightBalanceClient;
|
import com.red.circle.wallet.inner.endpoint.freight.FreightBalanceClient;
|
||||||
@ -40,42 +44,77 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest
|
|||||||
private final UserProfileClient userProfileClient;
|
private final UserProfileClient userProfileClient;
|
||||||
private final AppConfigService appConfigService;
|
private final AppConfigService appConfigService;
|
||||||
private final UserProfileGateway userProfileGateway;
|
private final UserProfileGateway userProfileGateway;
|
||||||
|
private final UserRegionGateway userRegionGateway;
|
||||||
private final UserFreightBalanceConvertor userFreightBalanceConvertor;
|
private final UserFreightBalanceConvertor userFreightBalanceConvertor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<UserFreightBalanceCO> pageFreight(UserFreightBalancePageQryCmd cmd, AppExtCommand appExtCommand) {
|
public PageResult<UserFreightBalanceCO> pageFreight(UserFreightBalancePageQryCmd cmd, AppExtCommand appExtCommand) {
|
||||||
// 写死默认查询条件:H5开启且未关闭
|
// 获取请求用户的国家编码
|
||||||
|
UserProfile userProfile = userProfileGateway.getByUserId(appExtCommand.getReqUserId());
|
||||||
|
String countryCode = userProfile.getCountryCode();
|
||||||
|
|
||||||
cmd.setH5Display(true);
|
cmd.setH5Display(true);
|
||||||
cmd.setClose(false);
|
cmd.setClose(false);
|
||||||
|
|
||||||
|
PageQuery pageQuery = cmd.getPageQuery();
|
||||||
|
|
||||||
|
// 保存原始分页参数
|
||||||
|
int pageNo = pageQuery.getCursor();
|
||||||
|
int pageSize = pageQuery.getLimit();
|
||||||
|
|
||||||
// 1. 查询货运账户分页数据
|
pageQuery.setCursor(1);
|
||||||
|
pageQuery.setLimit(500);
|
||||||
PageResult<UserFreightBalanceDTO> freightPageResult = freightGoldClient.pageFreight(cmd).getBody();
|
PageResult<UserFreightBalanceDTO> freightPageResult = freightGoldClient.pageFreight(cmd).getBody();
|
||||||
|
|
||||||
if (freightPageResult.checkRecordsEmpty()) {
|
if (freightPageResult.checkRecordsEmpty()) {
|
||||||
return freightPageResult.emptyRecords();
|
return freightPageResult.emptyRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据国家编码过滤数据
|
||||||
|
List<UserFreightBalanceDTO> 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<UserFreightBalanceDTO> pagedRecords = filteredRecords.subList(fromIndex, toIndex);
|
||||||
|
|
||||||
|
// 构建分页结果
|
||||||
|
PageResult<UserFreightBalanceDTO> 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<Long> userIds = pagedResult.getRecords().stream()
|
||||||
Set<Long> userIds = freightPageResult.getRecords().stream()
|
|
||||||
.map(UserFreightBalanceDTO::getUserId)
|
.map(UserFreightBalanceDTO::getUserId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 3. 查询用户基本信息
|
// 查询用户基本信息
|
||||||
Map<Long, UserProfileDTO> userBaseInfoMap = ResponseAssert.requiredSuccess(
|
Map<Long, UserProfileDTO> userBaseInfoMap = ResponseAssert.requiredSuccess(userProfileClient.mapByUserIds(userIds));
|
||||||
userProfileClient.mapByUserIds(userIds)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 4. 查询交易次数(type=1)
|
|
||||||
Map<Long, Long> transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody();
|
Map<Long, Long> transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody();
|
||||||
|
|
||||||
// 5. 获取支持的国家配置
|
|
||||||
AppCountryCodeCO appCountryCode = appConfigService.getAppCountryCode();
|
AppCountryCodeCO appCountryCode = appConfigService.getAppCountryCode();
|
||||||
|
|
||||||
// 构建国家代码到国旗URL的映射
|
// 构建国家代码到国旗URL的映射
|
||||||
Map<String, String> countryFlagMap = buildCountryFlagMap(appCountryCode);
|
Map<String, String> countryFlagMap = buildCountryFlagMap(appCountryCode);
|
||||||
|
|
||||||
// 6. 转换并组装数据
|
return pagedResult.convert(dto -> {
|
||||||
return freightPageResult.convert(dto -> {
|
|
||||||
UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto);
|
UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto);
|
||||||
co.setBalance(dto.getBalance());
|
co.setBalance(dto.getBalance());
|
||||||
co.setIsFollow(userProfileGateway.checkFollow(appExtCommand.getReqUserId(), dto.getUserId()));
|
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的映射.
|
* 构建国家代码到国旗URL的映射.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user