|
|
@ -15,10 +15,13 @@ 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 com.qniao.framework.utils.TypeConvertUtils; |
|
|
|
|
|
import com.thoughtworks.xstream.converters.time.LocalDateTimeConverter; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@ -56,15 +59,47 @@ public class WalletAccountQueryServiceImpl implements WalletAccountQueryService |
|
|
if (Objects.nonNull(walletAccount)) { |
|
|
if (Objects.nonNull(walletAccount)) { |
|
|
walletAccountVo = TypeConvertUtils.convert(walletAccount, UserGetWalletAccountVo.class); |
|
|
walletAccountVo = TypeConvertUtils.convert(walletAccount, UserGetWalletAccountVo.class); |
|
|
if (Objects.nonNull(walletAccount.getId())) { |
|
|
if (Objects.nonNull(walletAccount.getId())) { |
|
|
|
|
|
//已提现金额 |
|
|
walletAccountVo.setTotalWithdrawBalance(walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>() |
|
|
walletAccountVo.setTotalWithdrawBalance(walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>() |
|
|
.eq(WalletAccountRecord::getWalletAccountId, walletAccount.getId()) |
|
|
.eq(WalletAccountRecord::getWalletAccountId, walletAccount.getId()) |
|
|
.eq(WalletAccountRecord::getTradeType, TradeTypeEnum.WITHDRAW)) |
|
|
.eq(WalletAccountRecord::getTradeType, TradeTypeEnum.WITHDRAW)) |
|
|
.stream().map(WalletAccountRecord::getTradeAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); |
|
|
.stream().map(WalletAccountRecord::getTradeAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); |
|
|
|
|
|
//可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) |
|
|
|
|
|
walletAccountVo.setAvailableWithdrawBalance(countAvailableWithdrawBalance(walletAccount)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return walletAccountVo; |
|
|
return walletAccountVo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 可提现金额(参考工资为例,15号后结上一个月之前的,15-1-14则结算前两个月之前的) |
|
|
|
|
|
* |
|
|
|
|
|
* @param walletAccount |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private BigDecimal countAvailableWithdrawBalance(WalletAccount walletAccount) { |
|
|
|
|
|
BigDecimal availableBalance = walletAccount.getAvailableBalance(); |
|
|
|
|
|
LocalDate date = LocalDate.now(); |
|
|
|
|
|
int month = 0; |
|
|
|
|
|
if (date.getDayOfMonth() < 15) { |
|
|
|
|
|
//可结算上一个月 |
|
|
|
|
|
month = 1; |
|
|
|
|
|
} |
|
|
|
|
|
//不可提现的金额 |
|
|
|
|
|
BigDecimal unavailableWithdrawBalance = countUnavailableWithdrawBalance(walletAccount.getId(), date, month); |
|
|
|
|
|
return availableBalance.compareTo(unavailableWithdrawBalance) > 0 ? availableBalance.subtract(unavailableWithdrawBalance) : BigDecimal.ZERO; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private BigDecimal countUnavailableWithdrawBalance(Long walletAccountId, LocalDate date, int month) { |
|
|
|
|
|
LocalDateTime dateTime = date.minusMonths(month).withDayOfMonth(1).atStartOfDay(); |
|
|
|
|
|
return walletAccountRecordDao.selectList(new LambdaQueryWrapper<WalletAccountRecord>() |
|
|
|
|
|
.eq(WalletAccountRecord::getWalletAccountId, walletAccountId) |
|
|
|
|
|
.eq(WalletAccountRecord::getIsIncome, true) |
|
|
|
|
|
.ge(WalletAccountRecord::getCreateTime, dateTime)) |
|
|
|
|
|
.stream().map(WalletAccountRecord::getTradeAmount) |
|
|
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WalletAccount queryByType(Long identityId, |
|
|
public WalletAccount queryByType(Long identityId, |
|
|
IdentityTypeEnum identityType) { |
|
|
IdentityTypeEnum identityType) { |
|
|
|