diff --git a/rc-service/rc-inner-api/order-inner/order-inner-api/src/main/java/com/red/circle/order/inner/endpoint/api/UserMonthlyRechargeClientApi.java b/rc-service/rc-inner-api/order-inner/order-inner-api/src/main/java/com/red/circle/order/inner/endpoint/api/UserMonthlyRechargeClientApi.java index 6919d358..438f753f 100644 --- a/rc-service/rc-inner-api/order-inner/order-inner-api/src/main/java/com/red/circle/order/inner/endpoint/api/UserMonthlyRechargeClientApi.java +++ b/rc-service/rc-inner-api/order-inner/order-inner-api/src/main/java/com/red/circle/order/inner/endpoint/api/UserMonthlyRechargeClientApi.java @@ -42,4 +42,16 @@ public interface UserMonthlyRechargeClientApi { @GetMapping("/listThisMonth") ResultResponse> listThisMonth(@RequestParam("userId") Long userId); + /** + * 批量获取用户本月充值. + */ + @GetMapping("/listThisMonthByIds") + ResultResponse> listThisMonthByIds(@RequestParam("userIds") List userIds); + + /** + * 批量获取用户本月充值. + */ + @GetMapping("/listLastMonthByIds") + ResultResponse> listLastMonthByIds(@RequestParam("userIds") List userIds); + } diff --git a/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/UserMonthlyRechargeService.java b/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/UserMonthlyRechargeService.java index 668a4338..2ef759bb 100644 --- a/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/UserMonthlyRechargeService.java +++ b/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/UserMonthlyRechargeService.java @@ -58,4 +58,14 @@ public interface UserMonthlyRechargeService extends BaseService listThisMonth(Long userId); + /** + * 批量获取用户本月充值. + */ + List listThisMonthByIds(List userIds); + + /** + * 批量获取用户上月充值. + */ + List listLastMonthByIds(List userIds); + } diff --git a/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/impl/UserMonthlyRechargeServiceImpl.java b/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/impl/UserMonthlyRechargeServiceImpl.java index 7583d352..91c92695 100644 --- a/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/impl/UserMonthlyRechargeServiceImpl.java +++ b/rc-service/rc-service-order/order-infrastructure/src/main/java/com/red/circle/order/infra/database/rds/service/count/impl/UserMonthlyRechargeServiceImpl.java @@ -11,6 +11,8 @@ import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.LocalDateUtils; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; import java.util.Objects; @@ -160,9 +162,30 @@ public class UserMonthlyRechargeServiceImpl extends .list(); } + @Override + public List listThisMonthByIds(List userIds) { + return query() + .in(UserMonthlyRecharge::getUserId, userIds) + .eq(UserMonthlyRecharge::getRechargeDate, nowThisMonth()) + .orderByAsc(UserMonthlyRecharge::getType) + .list(); + } + + @Override + public List listLastMonthByIds(List userIds) { + return query() + .in(UserMonthlyRecharge::getUserId, userIds) + .eq(UserMonthlyRecharge::getRechargeDate, lastMonth()) + .orderByAsc(UserMonthlyRecharge::getType) + .list(); + } + private int nowThisMonth() { return LocalDateUtils.nowThisMonthToInteger(); } + private String lastMonth() { + return LocalDate.now().minusMonths(1).format(DateTimeFormatter.ofPattern("yyyy-MM")); + } } diff --git a/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/endpoint/UserMonthlyRechargeClientEndpoint.java b/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/endpoint/UserMonthlyRechargeClientEndpoint.java index 1126faac..0816b700 100644 --- a/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/endpoint/UserMonthlyRechargeClientEndpoint.java +++ b/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/endpoint/UserMonthlyRechargeClientEndpoint.java @@ -52,4 +52,18 @@ public class UserMonthlyRechargeClientEndpoint implements UserMonthlyRechargeCli ); } + @Override + public ResultResponse> listThisMonthByIds(List userIds) { + return ResultResponse.success( + userMonthlyRechargeClientService.listThisMonthByIds(userIds) + ); + } + + @Override + public ResultResponse> listLastMonthByIds(List userIds) { + return ResultResponse.success( + userMonthlyRechargeClientService.listLastMonthByIds(userIds) + ); + } + } diff --git a/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/UserMonthlyRechargeClientService.java b/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/UserMonthlyRechargeClientService.java index 56b13636..fb345ff2 100644 --- a/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/UserMonthlyRechargeClientService.java +++ b/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/UserMonthlyRechargeClientService.java @@ -29,4 +29,14 @@ public interface UserMonthlyRechargeClientService { */ List listThisMonth(Long userId); + /** + * 批量获取用户本月充值. + */ + List listThisMonthByIds(List userIds); + + /** + * 批量获取用户上月充值. + */ + List listLastMonthByIds(List userIds); + } diff --git a/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/impl/UserMonthlyRechargeClientServiceImpl.java b/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/impl/UserMonthlyRechargeClientServiceImpl.java index a82c1d07..c89bd5bd 100644 --- a/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/impl/UserMonthlyRechargeClientServiceImpl.java +++ b/rc-service/rc-service-order/order-inner-endpoint/src/main/java/com/red/circle/order/inner/service/impl/UserMonthlyRechargeClientServiceImpl.java @@ -46,4 +46,18 @@ public class UserMonthlyRechargeClientServiceImpl implements UserMonthlyRecharge ); } + @Override + public List listThisMonthByIds(List userIds) { + return userMonthlyRechargeInnerConvertor.toListUserMonthlyRechargeDTO( + userMonthlyRechargeService.listThisMonthByIds(userIds) + ); + } + + @Override + public List listLastMonthByIds(List userIds) { + return userMonthlyRechargeInnerConvertor.toListUserMonthlyRechargeDTO( + userMonthlyRechargeService.listLastMonthByIds(userIds) + ); + } + } diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java index 7fe1e953..a9e41c4f 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/h5/MemberActiveController.java @@ -1,10 +1,17 @@ package com.red.circle.other.adapter.app.h5; import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.common.business.dto.cmd.PageUserIdCmd; +import com.red.circle.framework.dto.PageResult; import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.order.inner.endpoint.UserFreightRechargeRecordClient; +import com.red.circle.order.inner.endpoint.UserMonthlyRechargeClient; +import com.red.circle.order.inner.endpoint.api.UserMonthlyRechargeClientApi; import com.red.circle.other.app.dto.h5.MemberActiveDTO; +import com.red.circle.other.app.dto.h5.RechargePageVO; import com.red.circle.other.app.dto.h5.UserIdentityVO; import com.red.circle.other.app.service.h5.MemberActiveService; +import com.red.circle.other.app.service.recharge.RechargeUserService; import com.red.circle.other.app.service.user.user.UserCountService; import com.red.circle.other.app.service.user.user.UserIdentityService; import lombok.RequiredArgsConstructor; @@ -18,6 +25,7 @@ public class MemberActiveController extends BaseController { private final MemberActiveService memberActiveService; private final UserIdentityService userIdentityService; + private final RechargeUserService rechargeUserService; /** * 工会裂变活动列表、 @@ -46,4 +54,12 @@ public class MemberActiveController extends BaseController { return userIdentityService.getUserIdentity(cmd.getReqUserId()); } + /** + * 货运代理分页列表 + */ + @GetMapping("/recharge-page") + public PageResult rechargePage(PageUserIdCmd page, AppExtCommand cmd) { + return rechargeUserService.getRechargePage(page, cmd); + } + } diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java index 724c036d..83319bb9 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamBdRestController.java @@ -214,7 +214,7 @@ public class TeamBdRestController extends BaseController { /** * BD 列表接口 */ - @GetMapping("/page") + @GetMapping("/page2") public PageResult bdPage(BdTeamPageQryCmd qryCmd) { return teamBdService.bdPage(qryCmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java new file mode 100644 index 00000000..ba081296 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/RechargeUserServiceImpl.java @@ -0,0 +1,102 @@ +package com.red.circle.other.app.service.user.user; + +import cn.hutool.core.lang.Assert; +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.common.business.dto.cmd.PageUserIdCmd; +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.core.response.CommonErrorCode; +import com.red.circle.framework.dto.PageQuery; +import com.red.circle.framework.dto.PageResult; +import com.red.circle.framework.dto.ResultResponse; +import com.red.circle.order.inner.endpoint.UserMonthlyRechargeClient; +import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO; +import com.red.circle.other.app.dto.h5.RechargePageVO; +import com.red.circle.other.app.dto.h5.RechargeVO; +import com.red.circle.other.app.service.recharge.RechargeUserService; +import com.red.circle.other.infra.database.rds.service.sys.AdministratorService; +import com.red.circle.other.inner.endpoint.user.user.UserProfileClient; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.tool.core.collection.CollectionUtils; +import com.red.circle.tool.core.date.LocalDateUtils; +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 lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class RechargeUserServiceImpl implements RechargeUserService { + + private final UserMonthlyRechargeClient userMonthlyRechargeClient; + private final FreightGoldClient freightGoldClient; + private final UserProfileClient userProfileClient; + private final AdministratorService administratorService; + + @Override + public PageResult getRechargePage(PageUserIdCmd page, AppExtCommand cmd) { + boolean b = administratorService.existsAdmin(cmd.getReqUserId()); + if(!b) { + ResponseAssert.failure(CommonErrorCode.OPERATING_FAILURE); + } + + UserFreightBalancePageQryCmd qryCmd = new UserFreightBalancePageQryCmd(); + qryCmd.setClose(false); + qryCmd.setDisplay(false); + qryCmd.setSysOrigin(cmd.getReqSysOrigin().getOrigin()); + qryCmd.setPageQuery(page.getPageQuery()); + PageResult pageResult = freightGoldClient.pageFreight(qryCmd).getBody(); + + + if (pageResult == null || pageResult.getRecords().isEmpty()) { + return null; + } + + List collect = pageResult.getRecords().stream().map(UserFreightBalanceDTO::getUserId).toList(); + Map userMonthlyAmountMap = getThisMonthRechargeAmount(collect); + Map userLastMonthAmountMap = getLastMonthRechargeAmount(collect); + + return pageResult.convert(e -> { + UserProfileDTO body = userProfileClient.getByUserId(e.getUserId()).getBody(); + + return new RechargePageVO() + .setUserId(e.getUserId()) + .setAccount(body.getAccount()) + .setUserNickname(body.getUserNickname()) + .setUserAvatar(body.getUserAvatar()) + .setThisMonth(userMonthlyAmountMap.get(e.getUserId())) + .setLastMonth(userLastMonthAmountMap.get(e.getUserId())); + }); + } + + private Map getThisMonthRechargeAmount(List collect) { + List recharges = userMonthlyRechargeClient.listThisMonthByIds(collect).getBody(); + return getLongBigDecimalMap(recharges); + } + + private Map getLastMonthRechargeAmount(List collect) { + List recharges = userMonthlyRechargeClient.listLastMonthByIds(collect).getBody(); + return getLongBigDecimalMap(recharges); + } + + private static Map getLongBigDecimalMap(List recharges) { + Map> userMonthlyMap = recharges.stream() + .collect(Collectors.groupingBy(UserMonthlyRechargeDTO::getUserId)); + + return userMonthlyMap.entrySet().stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> entry.getValue().stream() + .map(UserMonthlyRechargeDTO::getAmount) + .reduce(BigDecimal.ZERO, BigDecimal::add) + )); + } + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java new file mode 100644 index 00000000..a1a111ee --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargePageVO.java @@ -0,0 +1,45 @@ +package com.red.circle.other.app.dto.h5; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; + +@Data +@Accessors(chain = true) +public class RechargePageVO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private Long userId; + + /** + * 账号. + */ + private String account; + + /** + * 头像. + */ + private String userAvatar; + + /** + * 用户昵称. + */ + private String userNickname; + + /** + * 这个月金额 + */ + private BigDecimal thisMonth; + + /** + * 上个月金额 + */ + private BigDecimal lastMonth; + +} \ No newline at end of file diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeVO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeVO.java new file mode 100644 index 00000000..7b5517dc --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/h5/RechargeVO.java @@ -0,0 +1,50 @@ +package com.red.circle.other.app.dto.h5; + +import com.red.circle.framework.dto.ClientObject; +import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.List; + +/** + * 累计用户每月充值 + * + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +public class RechargeVO extends ClientObject { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 充值信息. + */ + private List recharges; + + /** + * 总额. + */ + private BigDecimal totalAmount; + + /** + * 充值年月(yyyyMM). + */ + private Integer rechargeDate; + + /** + * 创建时间. + */ + private Timestamp createTime; + + /** + * 修改时间. + */ + private Timestamp updateTime; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java new file mode 100644 index 00000000..dd596c8f --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/recharge/RechargeUserService.java @@ -0,0 +1,15 @@ +package com.red.circle.other.app.service.recharge; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.common.business.dto.cmd.PageUserIdCmd; +import com.red.circle.framework.dto.PageResult; +import com.red.circle.other.app.dto.h5.RechargePageVO; + +public interface RechargeUserService { + + /** + * 货运代理用户列表 + */ + PageResult getRechargePage(PageUserIdCmd page, AppExtCommand cmd); + +}