From 49f2eff2cf52e0f1719dfad43cafff11b378252c Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 20 十二月 2024 18:14:26 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/BalanceChangeRecordServiceImpl.java | 108 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 97 insertions(+), 11 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/BalanceChangeRecordServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/BalanceChangeRecordServiceImpl.java index 1a3ca07..e317ae3 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/BalanceChangeRecordServiceImpl.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/BalanceChangeRecordServiceImpl.java @@ -1,26 +1,27 @@ package com.ruoyi.account.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ruoyi.account.api.model.AppUser; import com.ruoyi.account.api.model.BalanceChangeRecord; -import com.ruoyi.account.api.model.UserClickLog; -import com.ruoyi.account.api.model.WithdrawalRequests; import com.ruoyi.account.dto.BalanceQuery; import com.ruoyi.account.mapper.BalanceChangeRecordMapper; -import com.ruoyi.account.service.AppUserService; import com.ruoyi.account.service.BalanceChangeRecordService; import com.ruoyi.account.vo.CommissionStatistics; -import com.ruoyi.common.core.utils.StringUtils; -import com.ruoyi.other.api.domain.ShopPoint; +import com.ruoyi.account.vo.WalletStatistics; +import com.ruoyi.account.vo.WalletStatisticsDetail; +import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.bean.BeanUtils; +import com.ruoyi.other.api.domain.ShopBalanceStatement; +import com.ruoyi.other.api.feignClient.ShopClient; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -28,15 +29,14 @@ @Service public class BalanceChangeRecordServiceImpl extends ServiceImpl<BalanceChangeRecordMapper, BalanceChangeRecord> implements BalanceChangeRecordService { @Resource - private AppUserService appUserService; + private ShopClient shopClient; @Override public IPage<BalanceChangeRecord> pageList(BalanceQuery agentQuery) { Page<BalanceChangeRecord> page = new Page<>(); page.setCurrent(agentQuery.getPageNum()); page.setSize(agentQuery.getPageSize()); - IPage<BalanceChangeRecord> shopIPage = this.baseMapper.pageList(page, agentQuery); - return shopIPage; + return this.baseMapper.pageList(page, agentQuery); } @Override @@ -51,4 +51,90 @@ IPage<BalanceChangeRecord> balanceChangeRecordIPage = this.baseMapper.queryCommissionStatistics(page, balanceChangeRecord); return new CommissionStatistics(totalCommission, balanceChangeRecordIPage); } + + @Override + public WalletStatistics walletStatistics(Page<BalanceChangeRecord> page, BalanceChangeRecord balanceChangeRecord) { + ShopBalanceStatement shopBalanceStatement = new ShopBalanceStatement(); + shopBalanceStatement.setType(4); + + R<List<ShopBalanceStatement>> r; + try { + r = shopClient.getShopBalanceStatementList(shopBalanceStatement); + } catch (Exception e) { + log.error("获取店铺余额对账单列表时出错", e); + return null; + } + + if (R.isError(r)) { + return null; + } + + List<BalanceChangeRecord> balanceChangeRecordList = this.baseMapper.selectBalanceChangeRecordList(balanceChangeRecord); + + List<WalletStatisticsDetail> walletStatisticsDetailList = new ArrayList<>(); + for (BalanceChangeRecord changeRecord : balanceChangeRecordList) { + WalletStatisticsDetail walletStatisticsDetail = new WalletStatisticsDetail(); + BeanUtils.copyBeanProp(walletStatisticsDetail, changeRecord); + walletStatisticsDetailList.add(walletStatisticsDetail); + } + + walletStatisticsDetailList.addAll(r.getData().stream().map(this::createWalletStatisticsDetail).collect(Collectors.toList())); + + // 按时间排序(倒序) + walletStatisticsDetailList.sort(Comparator.comparing(WalletStatisticsDetail::getCreateTime).reversed()); + + long current = page.getCurrent(); + long size = page.getSize(); + if (current < 1) { + current = 1; + } + int fromIndex = (int) ((current - 1) * size); + int toIndex = (int) Math.min(fromIndex + size, walletStatisticsDetailList.size()); + + if (fromIndex >= walletStatisticsDetailList.size()) { + throw new ServiceException("页面参数无效"); + } + + List<WalletStatisticsDetail> walletStatisticsDetailList2 = walletStatisticsDetailList.subList(fromIndex, toIndex); + + + Map<Integer, BigDecimal> shopCommissionMap = walletStatisticsDetailList.stream() + .collect(Collectors.groupingBy( + WalletStatisticsDetail::getChangeType, + Collectors.reducing( + BigDecimal.ZERO, + WalletStatisticsDetail::getChangeAmount, + BigDecimal::add + ) + )); + + BigDecimal totalRecharge = shopCommissionMap.get(1); + BigDecimal totalWithdraw = shopCommissionMap.get(2); + BigDecimal totalShopWithdraw = shopCommissionMap.get(7); + + + WalletStatistics walletStatistics = new WalletStatistics(); + Page<WalletStatisticsDetail> page1 = new Page<>(); + page1.setRecords(walletStatisticsDetailList2); + page1.setTotal(walletStatisticsDetailList.size()); + page1.setCurrent(current); + page1.setSize(size); + walletStatistics.setPage(page1); + walletStatistics.setTotalRecharge(totalRecharge); + walletStatistics.setTotalWithdraw(totalWithdraw); + walletStatistics.setTotalShopWithdraw(totalShopWithdraw); + return walletStatistics; + } + + private WalletStatisticsDetail createWalletStatisticsDetail(ShopBalanceStatement item) { + WalletStatisticsDetail walletStatisticsDetail = new WalletStatisticsDetail(); + walletStatisticsDetail.setShopName(item.getShopName()); + walletStatisticsDetail.setUserName(item.getShopManagerName()); + walletStatisticsDetail.setUserPhone(item.getPhone()); + walletStatisticsDetail.setChangeType(4); + walletStatisticsDetail.setCreateTime(item.getCreateTime()); + walletStatisticsDetail.setChangeAmount(item.getVariableAmount()); + return walletStatisticsDetail; + } + } -- Gitblit v1.7.1