|
|
@ -1,23 +1,24 @@ |
|
|
package com.qniao.dam.query.walletaccount.impl; |
|
|
package com.qniao.dam.query.walletaccount.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.qniao.dam.api.query.walletaccount.user.request.UserPageWalletAccountRecordQueryParam; |
|
|
import com.qniao.dam.api.query.walletaccount.user.request.UserPageWalletAccountRecordQueryParam; |
|
|
import com.qniao.dam.api.query.walletaccount.user.response.UserGetWalletAccountRecordVo; |
|
|
import com.qniao.dam.api.query.walletaccount.user.response.UserGetWalletAccountRecordVo; |
|
|
import com.qniao.dam.api.query.walletaccount.user.response.WalletAccountAssociateOrderRecordVo; |
|
|
|
|
|
|
|
|
import com.qniao.dam.api.query.walletaccount.user.response.UserGetWalletAccountVo; |
|
|
|
|
|
import com.qniao.dam.domain.aggregate.walletaccount.valueobj.WalletAccountRecord; |
|
|
|
|
|
import com.qniao.dam.domian.aggregate.walletaccount.constant.TradeTypeEnum; |
|
|
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountRecordDao; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.view.WalletAccountViewDao; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.view.WalletAccountViewDao; |
|
|
import com.qniao.dam.query.walletaccount.WalletAccountQueryService; |
|
|
import com.qniao.dam.query.walletaccount.WalletAccountQueryService; |
|
|
import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; |
|
|
import com.qniao.dam.domain.aggregate.walletaccount.entity.WalletAccount; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountDao; |
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.WalletAccountDao; |
|
|
import com.qniao.framework.utils.PageUtil; |
|
|
import com.qniao.framework.utils.PageUtil; |
|
|
|
|
|
import com.qniao.framework.utils.TypeConvertUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class WalletAccountQueryServiceImpl implements WalletAccountQueryService { |
|
|
public class WalletAccountQueryServiceImpl implements WalletAccountQueryService { |
|
|
@ -26,6 +27,8 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService |
|
|
private WalletAccountDao walletAccountDao; |
|
|
private WalletAccountDao walletAccountDao; |
|
|
@Resource |
|
|
@Resource |
|
|
private WalletAccountViewDao walletAccountViewDao; |
|
|
private WalletAccountViewDao walletAccountViewDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private WalletAccountRecordDao walletAccountRecordDao; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WalletAccount queryByUserId(Long userId) { |
|
|
public WalletAccount queryByUserId(Long userId) { |
|
|
@ -36,27 +39,20 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public IPage<UserGetWalletAccountRecordVo> pageWalletAccountRecord(Long userId, UserPageWalletAccountRecordQueryParam queryParam, PageUtil pageUtil) { |
|
|
public IPage<UserGetWalletAccountRecordVo> pageWalletAccountRecord(Long userId, UserPageWalletAccountRecordQueryParam queryParam, PageUtil pageUtil) { |
|
|
IPage<UserGetWalletAccountRecordVo> page = walletAccountViewDao.pageWalletAccountRecord(pageUtil.toPageWithoutOrders(), queryParam, userId); |
|
|
|
|
|
if (page.getRecords().size() > 0) { |
|
|
|
|
|
List<Long> recordIdList = page.getRecords().stream().map(UserGetWalletAccountRecordVo::getWalletAccountId).collect(Collectors.toList()); |
|
|
|
|
|
Map<Long, List<WalletAccountAssociateOrderRecordVo>> associateOrderRecordMap = mapAssociateOrderRecordBy(recordIdList); |
|
|
|
|
|
page.getRecords().forEach(record -> { |
|
|
|
|
|
record.setAssociateOrderRecordList(associateOrderRecordMap.get(record.getId())); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
return page; |
|
|
|
|
|
|
|
|
return walletAccountViewDao.pageWalletAccountRecord(pageUtil.toPageWithoutOrders(), queryParam, userId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private Map<Long, List<WalletAccountAssociateOrderRecordVo>> mapAssociateOrderRecordBy(List<Long> recordIdList) { |
|
|
|
|
|
List<WalletAccountAssociateOrderRecordVo> list = listAssociateOrderRecordBy(recordIdList); |
|
|
|
|
|
return list.stream().collect(Collectors.groupingBy(WalletAccountAssociateOrderRecordVo::getAssociateOrderId)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<WalletAccountAssociateOrderRecordVo> listAssociateOrderRecordBy(List<Long> recordIdList) { |
|
|
|
|
|
List<WalletAccountAssociateOrderRecordVo> list = new ArrayList<>(); |
|
|
|
|
|
if (CollUtil.isNotEmpty(recordIdList)) { |
|
|
|
|
|
list = walletAccountViewDao.listAssociateOrderRecordBy(recordIdList); |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public UserGetWalletAccountVo getWalletAccountView(Long userId) { |
|
|
|
|
|
UserGetWalletAccountVo walletAccountVo = new UserGetWalletAccountVo(); |
|
|
|
|
|
WalletAccount walletAccount = queryByUserId(userId); |
|
|
|
|
|
if (Objects.nonNull(walletAccount)) { |
|
|
|
|
|
walletAccountVo = TypeConvertUtils.convert(walletAccount, UserGetWalletAccountVo.class); |
|
|
|
|
|
walletAccountVo.setTotalWithdraw(walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>() |
|
|
|
|
|
.eq(WalletAccountRecord::getWalletAccountId, walletAccount.getId()) |
|
|
|
|
|
.eq(WalletAccountRecord::getTradeType, TradeTypeEnum.WITHDRAW)) |
|
|
|
|
|
.stream().map(WalletAccountRecord::getTradeAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); |
|
|
} |
|
|
} |
|
|
return list; |
|
|
|
|
|
|
|
|
return walletAccountVo; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |