管理员中心recharge agency 汇总和列表接口修改

This commit is contained in:
tianfeng 2025-09-26 19:36:37 +08:00
parent 324b8dc2d5
commit 8bdbeabb5b
11 changed files with 79 additions and 70 deletions

View File

@ -7,6 +7,8 @@ import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO;
import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -59,7 +61,7 @@ public interface UserMonthlyRechargeClientApi {
* 获取金币代理本月和上个月的充值汇总.
*/
@GetMapping("/monthly-summary")
ResultResponse<List<MonthlyRechargeSummaryVO>> getMonthlyRechargeSummary();
ResultResponse<List<MonthlyRechargeSummaryVO>> getMonthlyRechargeSummary(@RequestParam("userIds") Set<Long> userIds);
}

View File

@ -3,8 +3,10 @@ package com.red.circle.order.infra.database.rds.dao.count;
import com.red.circle.framework.mybatis.dao.BaseDAO;
import com.red.circle.order.infra.database.rds.entity.count.UserMonthlyRecharge;
import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* <p>
@ -16,5 +18,5 @@ import java.util.List;
*/
public interface UserMonthlyRechargeDAO extends BaseDAO<UserMonthlyRecharge> {
List<MonthlyRechargeSummaryVO> getMonthlyTotalRecharge();
List<MonthlyRechargeSummaryVO> getMonthlyTotalRecharge(@Param("userIds") Set<Long> userIds);
}

View File

@ -72,5 +72,5 @@ public interface UserMonthlyRechargeService extends BaseService<UserMonthlyRecha
/**
* 当月和上个月 金币代理充值汇总
*/
List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary();
List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary(Set<Long> userIds);
}

View File

@ -184,8 +184,8 @@ public class UserMonthlyRechargeServiceImpl extends
}
@Override
public List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary() {
return userMonthlyRechargeDAO.getMonthlyTotalRecharge();
public List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary(Set<Long> userIds) {
return userMonthlyRechargeDAO.getMonthlyTotalRecharge(userIds);
}
private int nowThisMonth() {

View File

@ -14,6 +14,10 @@
FROM user_monthly_recharge_v2 umr
INNER JOIN likei_wallet.user_freight_balance ufb ON umr.user_id = ufb.user_id
WHERE ufb.is_close = 0 -- 只查询未关闭的货运账户
AND ufb.user_id IN
<foreach collection="userIds" open="(" separator="," close=")" item="userId">
#{userId}
</foreach>
AND umr.recharge_date IN (
DATE_FORMAT(CURDATE(), '%Y%m'), -- 当月
DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 MONTH), '%Y%m') -- 上月

View File

@ -9,6 +9,8 @@ import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO;
import com.red.circle.order.inner.service.UserMonthlyRechargeClientService;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
@ -68,8 +70,8 @@ public class UserMonthlyRechargeClientEndpoint implements UserMonthlyRechargeCli
}
@Override
public ResultResponse<List<MonthlyRechargeSummaryVO>> getMonthlyRechargeSummary() {
return ResultResponse.success(userMonthlyRechargeClientService.getMonthlyRechargeSummary());
public ResultResponse<List<MonthlyRechargeSummaryVO>> getMonthlyRechargeSummary(Set<Long> userIds) {
return ResultResponse.success(userMonthlyRechargeClientService.getMonthlyRechargeSummary(userIds));
}
}

View File

@ -6,6 +6,7 @@ import com.red.circle.order.inner.model.dto.MonthlyRechargeSummaryVO;
import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 累计用户每月充值.
@ -43,7 +44,7 @@ public interface UserMonthlyRechargeClientService {
/**
* 批量获取用户上月充值.
*/
List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary();
List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary(Set<Long> userIds);
}

View File

@ -9,6 +9,8 @@ import com.red.circle.order.inner.model.dto.UserMonthlyRechargeDTO;
import com.red.circle.order.inner.service.UserMonthlyRechargeClientService;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@ -62,8 +64,8 @@ public class UserMonthlyRechargeClientServiceImpl implements UserMonthlyRecharge
}
@Override
public List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary() {
return userMonthlyRechargeService.getMonthlyRechargeSummary();
public List<MonthlyRechargeSummaryVO> getMonthlyRechargeSummary(Set<Long> userIds) {
return userMonthlyRechargeService.getMonthlyRechargeSummary(userIds);
}
}

View File

@ -1,41 +1,28 @@
package com.red.circle.other.app.service.user.user;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.MonthlyRechargeSummaryVO;
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.entity.team.BusinessDevelopmentBaseInfo;
import com.red.circle.other.infra.database.rds.dao.team.BusinessDevelopmentTeamDAO;
import com.red.circle.other.infra.database.rds.service.sys.AdministratorService;
import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentBaseInfoService;
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.tool.core.text.StringUtils;
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.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Service
@ -43,10 +30,9 @@ import java.util.stream.Collectors;
public class RechargeUserServiceImpl implements RechargeUserService {
private final UserMonthlyRechargeClient userMonthlyRechargeClient;
private final FreightGoldClient freightGoldClient;
private final UserProfileClient userProfileClient;
private final AdministratorService administratorService;
private final BusinessDevelopmentBaseInfoService businessDevelopmentBaseInfoService;
private final BusinessDevelopmentTeamDAO businessDevelopmentTeamDAO;
@Override
public PageResult<RechargePageVO> getRechargePage(PageUserIdCmd page, AppExtCommand cmd) {
@ -55,54 +41,50 @@ public class RechargeUserServiceImpl implements RechargeUserService {
ResponseAssert.failure(CommonErrorCode.OPERATING_FAILURE);
}
List<Long> collect = getBdGoldUserIdList(cmd);
if (collect == null) return null;
Page<Object> objectPage = new Page<>();
objectPage.setCurrent(page.getPageQuery().getCursor());
objectPage.setSize(page.getPageQuery().getLimit());
Page<Long> pagedRechargeAgency = businessDevelopmentTeamDAO.pageRechargeAgency(cmd.getReqUserId(), objectPage);
if (pagedRechargeAgency == null || pagedRechargeAgency.getRecords().isEmpty()) {
return null;
}
Map<Long, BigDecimal> userMonthlyAmountMap = getThisMonthRechargeAmount(collect);
Map<Long, BigDecimal> userLastMonthAmountMap = getLastMonthRechargeAmount(collect);
List<Long> collect = pagedRechargeAgency.getRecords().stream().toList();
Map<Long, BigDecimal> userMonthlyAmountMap = getThisMonthRechargeAmount(collect);
Map<Long, BigDecimal> userLastMonthAmountMap = getLastMonthRechargeAmount(collect);
List<RechargePageVO> list = collect.stream().map(userId -> {
UserProfileDTO body = userProfileClient.getByUserId(userId).getBody();
return new RechargePageVO()
.setUserId(userId)
.setAccount(body.getAccount())
.setUserNickname(body.getUserNickname())
.setUserAvatar(body.getUserAvatar())
.setThisMonth(userMonthlyAmountMap.get(userId))
.setLastMonth(userLastMonthAmountMap.get(userId));
}).toList();
List<RechargePageVO> list = pagedRechargeAgency.getRecords().stream().map(userId -> {
UserProfileDTO body = userProfileClient.getByUserId(userId).getBody();
return new RechargePageVO()
.setUserId(userId)
.setAccount(body.getAccount())
.setUserNickname(body.getUserNickname())
.setUserAvatar(body.getUserAvatar())
.setThisMonth(userMonthlyAmountMap.get(userId))
.setLastMonth(userLastMonthAmountMap.get(userId));
}).toList();
PageResult<RechargePageVO> result = PageResult.newPageResult(list.size());
result.setCurrent(1L);
result.setTotal(list.size());
result.setRecords(list);
return result;
}
private List<Long> getBdGoldUserIdList(AppExtCommand cmd) {
List<BusinessDevelopmentBaseInfo> bdList = businessDevelopmentBaseInfoService.query()
.eq(BusinessDevelopmentBaseInfo::getSysOrigin, cmd.getReqSysOrigin().getOrigin())
.eq(BusinessDevelopmentBaseInfo::getBdLeadUserId, cmd.getReqUserId())
.orderByDesc(BusinessDevelopmentBaseInfo::getCreateTime)
.list();
if (bdList.isEmpty()) {
return null;
}
List<Long> collect = bdList.stream().map(e -> {
UserFreightBalanceDTO result = freightGoldClient.getByUserId(e.getUserId()).getBody();
return result != null ? result.getUserId() : null;
}).filter(Objects::nonNull).toList();
if (CollectionUtils.isEmpty(collect)) {
return null;
}
return collect;
PageResult<RechargePageVO> result = PageResult.newPageResult(list.size());
result.setCurrent(pagedRechargeAgency.getCurrent());
result.setTotal(pagedRechargeAgency.getTotal());
result.setSize(pagedRechargeAgency.getSize());
result.setRecords(list);
return result;
}
@Override
public List<MonthlyRechargeSummaryVO> getRechargeSummary(AppExtCommand cmd) {
return userMonthlyRechargeClient.getMonthlyRechargeSummary().getBody();
Page<Object> objectPage = new Page<>();
objectPage.setCurrent(1L);
objectPage.setSize(3000L);
Page<Long> pagedRechargeAgency = businessDevelopmentTeamDAO.pageRechargeAgency(cmd.getReqUserId(), objectPage);
if (pagedRechargeAgency == null || pagedRechargeAgency.getRecords().isEmpty()) {
return null;
}
Set<Long> collect = new HashSet<>(pagedRechargeAgency.getRecords());
return userMonthlyRechargeClient.getMonthlyRechargeSummary(collect).getBody();
}
private Map<Long, BigDecimal> getThisMonthRechargeAmount(List<Long> collect) {

View File

@ -1,8 +1,11 @@
package com.red.circle.other.infra.database.rds.dao.team;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.red.circle.framework.mybatis.dao.BaseDAO;
import com.red.circle.other.infra.database.rds.entity.team.BusinessDevelopmentTeam;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
/**
@ -23,4 +26,9 @@ public interface BusinessDevelopmentTeamDAO extends BaseDAO<BusinessDevelopmentT
*/
BigDecimal countAgentTotalTarget(@Param("userId") Long userId,
@Param("dateNumber") Integer dateNumber);
/**
* bd下的金币代理(排除自己的)
*/
Page<Long> pageRechargeAgency(@Param("userId") Long userId, @Param("page")Page page);
}

View File

@ -12,4 +12,10 @@
AND rbdt.user_id = #{userId}
</select>
<select id="pageRechargeAgency" resultType="java.lang.Long">
SELECT ufb.user_id
FROM room_business_development_team bdt
INNER JOIN likei_wallet.user_freight_balance ufb ON bdt.agent_id = ufb.user_id
WHERE bdt.user_id = #{userId} AND ufb.user_id != #{userId}
</select>
</mapper>