From 675b5ebc65d8b32cf8e277b7c40519b5086a52b0 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Thu, 23 Oct 2025 11:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A7=E8=BF=90=E8=B4=A6=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../freight/api/FreightGoldClientApi.java | 6 +++ .../model/dto/UserFreightBalanceDTO.java | 10 +++++ .../UserFreightBalanceRestController.java | 5 ++- .../UserFreightBalanceRestServiceImpl.java | 39 +++++++++++++++---- .../user/UserFreightBalanceCO.java | 15 +++++++ .../user/UserFreightBalanceRestService.java | 3 +- .../FreightBalanceRunningWaterService.java | 10 +++++ ...FreightBalanceRunningWaterServiceImpl.java | 21 ++++++++++ .../freight/FreightGoldClientEndpoint.java | 5 +++ .../freight/FreightGoldClientService.java | 5 +++ .../impl/FreightGoldClientServiceImpl.java | 5 +++ 11 files changed, 114 insertions(+), 10 deletions(-) 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 d65b4292..f30b98e6 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 @@ -140,4 +140,10 @@ public interface FreightGoldClientApi { */ @PostMapping("/updateFreightBalanceInfo") ResultResponse updateFreightBalanceInfo(@RequestBody @Validated UpdateFreightBalanceInfoCmd cmd); + + /** + * 批量查询用户交易次数(type=1的记录数). + */ + @PostMapping("/mapTransactionCountByUserIds") + ResultResponse> mapTransactionCountByUserIds(@RequestBody Set userIds); } diff --git a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/dto/UserFreightBalanceDTO.java b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/dto/UserFreightBalanceDTO.java index dee563f1..04b831e2 100644 --- a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/dto/UserFreightBalanceDTO.java +++ b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/dto/UserFreightBalanceDTO.java @@ -107,6 +107,16 @@ public class UserFreightBalanceDTO implements Serializable { */ private Long realSellerQuantity; + /** + * 成为代理天数(根据createTime计算). + */ + private Integer becomeDays; + + /** + * 交易数量(出货次数,type=1). + */ + private Long transactionCount; + public BigDecimal getBalance() { return earnPoints.subtract(consumptionPoints).setScale(2, RoundingMode.DOWN); } diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserFreightBalanceRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserFreightBalanceRestController.java index 0aa0a116..8e53df0f 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserFreightBalanceRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserFreightBalanceRestController.java @@ -1,5 +1,6 @@ package com.red.circle.other.adapter.app.user.user; +import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.web.controller.BaseController; import com.red.circle.other.app.dto.clientobject.user.UserFreightBalanceCO; @@ -38,8 +39,8 @@ public class UserFreightBalanceRestController extends BaseController { * @eo.request-type formdata */ @GetMapping("/page") - public PageResult pageFreight(UserFreightBalancePageQryCmd cmd) { - return userFreightBalanceRestService.pageFreight(cmd); + public PageResult pageFreight(UserFreightBalancePageQryCmd cmd, AppExtCommand appExtCommand) { + return userFreightBalanceRestService.pageFreight(cmd, appExtCommand); } } 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 b824527e..a05a62e1 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,18 +1,23 @@ package com.red.circle.other.app.service.user.impl; +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.user.UserFreightBalanceCO; 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; 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.FreightGoldClient; import com.red.circle.wallet.inner.model.cmd.UserFreightBalancePageQryCmd; import com.red.circle.wallet.inner.model.dto.UserFreightBalanceDTO; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -31,10 +36,11 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest private final FreightGoldClient freightGoldClient; private final UserProfileClient userProfileClient; + private final UserProfileGateway userProfileGateway; private final UserFreightBalanceConvertor userFreightBalanceConvertor; @Override - public PageResult pageFreight(UserFreightBalancePageQryCmd cmd) { + public PageResult pageFreight(UserFreightBalancePageQryCmd cmd, AppExtCommand appExtCommand) { // 写死默认查询条件:H5开启且未关闭 cmd.setH5Display(true); cmd.setClose(false); @@ -46,20 +52,39 @@ public class UserFreightBalanceRestServiceImpl implements UserFreightBalanceRest return freightPageResult.emptyRecords(); } + // 2. 查询用户ID集合 + Set userIds = freightPageResult.getRecords().stream() + .map(UserFreightBalanceDTO::getUserId) + .collect(Collectors.toSet()); + // 3. 查询用户基本信息 Map userBaseInfoMap = ResponseAssert.requiredSuccess( - userProfileClient.mapByUserIds( - freightPageResult.getRecords().stream() - .map(UserFreightBalanceDTO::getUserId) - .collect(Collectors.toSet()) - ) + userProfileClient.mapByUserIds(userIds) ); - // 4. 转换并组装数据 + // 4. 查询交易次数(type=1) + Map transactionCountMap = freightGoldClient.mapTransactionCountByUserIds(userIds).getBody(); + + // 5. 转换并组装数据 return freightPageResult.convert(dto -> { UserFreightBalanceCO co = userFreightBalanceConvertor.toUserFreightBalanceCO(dto); co.setBalance(dto.getBalance()); + co.setIsFollow(userProfileGateway.checkFollow(appExtCommand.getReqUserId(), dto.getUserId())); co.setUserBaseInfo(userBaseInfoMap.get(dto.getUserId())); + + // 计算成为代理天数 + if (dto.getCreateTime() != null) { + LocalDateTime createTime = dto.getCreateTime().toLocalDateTime(); + LocalDateTime now = LocalDateTime.now(); + long days = ChronoUnit.DAYS.between(createTime, now); + co.setBecomeDays((int) days); + } + + // 设置交易次数 + co.setTransactionCount( + Optional.ofNullable(transactionCountMap.get(dto.getUserId())).orElse(0L) + ); + return co; }); } 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 eadb3ba4..4bd25560 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 @@ -88,6 +88,11 @@ public class UserFreightBalanceCO extends ClientObject { */ private String supportedCountries; + /** + * 是否关注 + */ + private Boolean isFollow; + /** * 联系方式. */ @@ -108,6 +113,16 @@ public class UserFreightBalanceCO extends ClientObject { */ private Long realSellerQuantity; + /** + * 成为代理天数(根据createTime计算). + */ + private Integer becomeDays; + + /** + * 交易数量(出货次数,type=1). + */ + private Long transactionCount; + /** * 用户基本信息. */ diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/UserFreightBalanceRestService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/UserFreightBalanceRestService.java index d843f403..c5510e25 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/UserFreightBalanceRestService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/UserFreightBalanceRestService.java @@ -1,5 +1,6 @@ package com.red.circle.other.app.service.user; +import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.dto.PageResult; import com.red.circle.other.app.dto.clientobject.user.UserFreightBalanceCO; import com.red.circle.wallet.inner.model.cmd.UserFreightBalancePageQryCmd; @@ -15,6 +16,6 @@ public interface UserFreightBalanceRestService { /** * 分页查询用户货运账户. */ - PageResult pageFreight(UserFreightBalancePageQryCmd cmd); + PageResult pageFreight(UserFreightBalancePageQryCmd cmd, AppExtCommand appExtCommand); } 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 409ff6d4..4d9bde4d 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 @@ -7,6 +7,8 @@ import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExpor import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightSellerRunningWaterPageQryCmd; import java.util.List; +import java.util.Map; +import java.util.Set; /** *

@@ -61,4 +63,12 @@ public interface FreightBalanceRunningWaterService extends BaseService listExportBalanceRunningWater( UserFreightBalanceRunningWaterExportQryCmd query); + + /** + * 批量统计用户交易次数(type=1的记录数). + * + * @param userIds 用户ID集合 + * @return 用户ID -> 交易次数 + */ + Map countTransactionsByUserIds(Set userIds); } 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 de096182..080c47e1 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 @@ -1,8 +1,10 @@ package com.red.circle.wallet.infra.database.rds.service.freight.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.mybatis.constant.PageConstant; import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; +import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.text.StringUtils; import com.red.circle.wallet.infra.database.rds.dao.FreightBalanceRunningWaterDAO; @@ -12,8 +14,13 @@ import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterExpor import com.red.circle.wallet.inner.model.cmd.UserFreightBalanceRunningWaterPageQryCmd; import com.red.circle.wallet.inner.model.cmd.UserFreightSellerRunningWaterPageQryCmd; import java.sql.Timestamp; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; /** @@ -115,4 +122,18 @@ public class FreightBalanceRunningWaterServiceImpl extends .apply("DATE_FORMAT(create_time,'%Y%m')={0}", query.getMonthDate()) .list(); } + + @Override + public Map countTransactionsByUserIds(Set userIds) { + if (CollectionUtils.isEmpty(userIds)) { + return new HashMap<>(); + } + + List list = query() + .select(FreightBalanceRunningWater::getUserId) + .in(FreightBalanceRunningWater::getUserId, userIds) + .eq(FreightBalanceRunningWater::getType, 1) + .list(); + return list.stream().collect(Collectors.groupingBy(FreightBalanceRunningWater::getUserId, Collectors.counting())); + } } 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 6be09f28..1ef30155 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 @@ -184,4 +184,9 @@ public class FreightGoldClientEndpoint implements FreightGoldClientApi { public ResultResponse updateFreightBalanceInfo(UpdateFreightBalanceInfoCmd cmd) { return ResultResponse.success(freightGoldClientService.updateFreightBalanceInfo(cmd)); } + + @Override + public ResultResponse> mapTransactionCountByUserIds(Set userIds) { + return ResultResponse.success(freightGoldClientService.mapTransactionCountByUserIds(userIds)); + } } 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 58d504e1..a1a5de8a 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 @@ -111,4 +111,9 @@ public interface FreightGoldClientService { * 更新货运代理账户信息(国家和联系方式). */ Boolean updateFreightBalanceInfo(UpdateFreightBalanceInfoCmd cmd); + + /** + * 批量查询用户交易次数(type=1的记录数). + */ + Map mapTransactionCountByUserIds(Set userIds); } 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 8df86601..2bbae8a1 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 @@ -255,4 +255,9 @@ public class FreightGoldClientServiceImpl implements FreightGoldClientService { .set(FreightBalance::getContactInfo, cmd.getContactInfo()) .execute(); } + + @Override + public Map mapTransactionCountByUserIds(Set userIds) { + return freightBalanceRunningWaterService.countTransactionsByUserIds(userIds); + } }