陶杰
2024-10-21 ddca8e96ee1aa47ba33fcf3a9a1e7e964d63ad8b
src/main/java/com/mzl/flower/service/impl/wallet/WalletBillRecordServiceImpl.java
@@ -2,15 +2,14 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.constant.LockConstants;
import com.mzl.flower.dto.request.wallet.CreateWalletBillRecordDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletBillRecordDTO;
import com.mzl.flower.dto.response.wallet.WalletBillRecordVO;
import com.mzl.flower.dto.request.wallet.QueryWalletBillDTO;
import com.mzl.flower.dto.response.wallet.WalletBillRecordVO;
import com.mzl.flower.entity.payment.Transfer;
import com.mzl.flower.entity.payment.TransferDetail;
import com.mzl.flower.entity.wallet.WalletBillRecordDO;
@@ -24,9 +23,9 @@
import com.mzl.flower.service.wallet.WalletBillRecordService;
import com.mzl.flower.service.wallet.WalletService;
import com.mzl.flower.utils.ExcelExportUtil;
import com.mzl.flower.utils.UUIDGenerator;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
@@ -34,11 +33,11 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.List;
/**
 * <p>
@@ -73,6 +72,9 @@
    @Resource
    RedissonClient redissonClient;
    @Resource
    WalletBillRecordService walletBillRecordService;
    @Override
    public void create(CreateWalletBillRecordDTO dto) {
@@ -104,6 +106,21 @@
                    if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
                        try {
                            if (!ObjectUtils.isEmpty(walletDO)) {
                                WalletBillRecordDO walletBillRecordDO2 = new WalletBillRecordDO();
                                walletBillRecordDO2.setId(UUIDGenerator.getUUID());
                                walletBillRecordDO2.setSupplierId(walletDO.getSupplierId());
                                walletBillRecordDO2.setWalletId(walletDO.getId());
                                walletBillRecordDO2.setType(Constants.BILL_CHANGE_TYPE.withdraw.name());
                                // 发起提现
                                walletBillRecordDO2.setWithdrawType(Constants.BILL_WITHDRAW_TYPE.success.name());
                                walletBillRecordDO2.setMethod(Constants.BILL_CHANGE_METHOD.reduce.name());
                                walletBillRecordDO2.setOriginalAmount(walletDO.getWithdrawableAmount());
                                walletBillRecordDO2.setChangeAmount(BigDecimal.ZERO);
                                walletBillRecordDO2.setBalance(walletDO.getWithdrawableAmount());
                                walletBillRecordDO2.create(SecurityUtils.getUserId());
                                walletBillRecordDO.setId(UUIDGenerator.getUUID());
                                // 保存账单明细
                                walletBillRecordService.save(walletBillRecordDO);
                                //提现中金额:减少提现中金额
                                walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(walletBillRecordDO.getChangeAmount()));
                                //已提现金额:增加已提现金额
@@ -121,6 +138,7 @@
                if (StringUtils.isEmpty(walletBillRecordDO.getWithdrawRecordId())) {
                    WalletWithdrawRecordDO withdrawRecordDO = walletWithdrawRecordMapper.selectById(walletBillRecordDO.getWithdrawRecordId());
                    withdrawRecordDO.setWithdrawState(Constants.WALLET_WITHDRAW_STATE.SUCCESS.name());
                    walletBillRecordDO.setRemark("账户资金提现完成");
                    walletWithdrawRecordMapper.updateById(withdrawRecordDO);
                }
@@ -134,10 +152,26 @@
                    if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
                        try {
                            if (!ObjectUtils.isEmpty(walletDO)) {
                                // 2.新增一条账单明细
                                WalletBillRecordDO walletBillRecordDO2 = new WalletBillRecordDO();
                                walletBillRecordDO2.setId(UUIDGenerator.getUUID());
                                walletBillRecordDO2.setSupplierId(walletDO.getSupplierId());
                                walletBillRecordDO2.setWalletId(walletDO.getId());
                                walletBillRecordDO2.setType(Constants.BILL_CHANGE_TYPE.withdraw.name());
                                // 发起提现
                                walletBillRecordDO2.setWithdrawType(Constants.BILL_WITHDRAW_TYPE.fail.name());
                                walletBillRecordDO2.setMethod(Constants.BILL_CHANGE_METHOD.add.name());
                                walletBillRecordDO2.setOriginalAmount(walletDO.getWithdrawableAmount());
                                walletBillRecordDO2.setChangeAmount(walletBillRecordDO.getActualTransferAmount());
                                walletBillRecordDO2.setBalance(walletDO.getWithdrawableAmount().add(walletBillRecordDO.getActualTransferAmount()));
                                walletBillRecordDO2.create(SecurityUtils.getUserId());
                                walletBillRecordDO.setId(UUIDGenerator.getUUID());
                                // 保存账单明细
                                walletBillRecordService.save(walletBillRecordDO);
                                //提现中金额:减少提现中金额
                                walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(walletBillRecordDO.getChangeAmount()));
                                walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(walletBillRecordDO.getActualTransferAmount()));
                                //可提现金额:增加可提现金额
                                walletDO.setWithdrawableAmount(walletDO.getWithdrawableAmount().add(walletBillRecordDO.getChangeAmount()));
                                walletDO.setWithdrawableAmount(walletDO.getWithdrawableAmount().add(walletBillRecordDO.getActualTransferAmount()));
                                walletMapper.updateById(walletDO);
                            }
                        } finally {
@@ -151,6 +185,7 @@
                if (StringUtils.isEmpty(walletBillRecordDO.getWithdrawRecordId())) {
                    WalletWithdrawRecordDO withdrawRecordDO = walletWithdrawRecordMapper.selectById(walletBillRecordDO.getWithdrawRecordId());
                    withdrawRecordDO.setWithdrawState(Constants.WALLET_WITHDRAW_STATE.FAILURE.name());
                    walletBillRecordDO.setRemark("账户资金提现失败");
                    walletWithdrawRecordMapper.updateById(withdrawRecordDO);
                }
            }
@@ -203,4 +238,11 @@
        page.setRecords(list);
        return page;
    }
    @Override
    public Page<WalletBillRecordVO> getPageByDesc(Page page, QueryWalletBillDTO dto) {
        List<WalletBillRecordVO> list = walletBillRecordMapper.getPageByDesc(page,dto);
        page.setRecords(list);
        return page;
    }
}