陶杰
2024-10-21 ddca8e96ee1aa47ba33fcf3a9a1e7e964d63ad8b
fix: 钱包供应商财务1
已修改8个文件
238 ■■■■ 文件已修改
src/main/java/com/mzl/flower/constant/LockConstants.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/entity/wallet/WalletBillRecordDO.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/wallet/WalletBillRecordMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/wallet/WalletBillRecordServiceImpl.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/wallet/WalletWithdrawRecordServiceImpl.java 153 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/wallet/WalletBillRecordService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/wallet/WalletBillRecordController.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/wallet/WalletBillRecordMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/constant/LockConstants.java
@@ -7,4 +7,6 @@
    public static final String WALLET_SUPPLIER_ID_KEY = "com:mzl:flower:constant:WALLET_SUPPLIER_ID_KEY:%s";
    public static final String WALLET_WITHDRAW_RECORD_KEY = "com:mzl:flower:constant:WALLET_WITHDRAW_RECORD_KEY:%s";
}
src/main/java/com/mzl/flower/entity/wallet/WalletBillRecordDO.java
@@ -76,4 +76,7 @@
    @ApiModelProperty(value = "备注")
    private String remark;
    @ApiModelProperty(value = "实际转账金额")
    private BigDecimal actualTransferAmount;
}
src/main/java/com/mzl/flower/mapper/wallet/WalletBillRecordMapper.java
@@ -26,5 +26,7 @@
    List<WalletBillRecordVO> queryWalletBillRecordList(@Param("dto") QueryWalletBillRecordDTO queryWalletBillRecordDTO);
    List<WalletBillRecordVO> getPage(Page page, @Param("dto") QueryWalletBillDTO dto);
    List<WalletBillRecordVO> getPageByDesc(Page page, @Param("dto") QueryWalletBillDTO dto);
}
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,6 +23,7 @@
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.stereotype.Service;
@@ -33,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>
@@ -72,6 +72,9 @@
    @Resource
    RedissonClient redissonClient;
    @Resource
    WalletBillRecordService walletBillRecordService;
    @Override
    public void create(CreateWalletBillRecordDTO dto) {
@@ -103,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()));
                                //已提现金额:增加已提现金额
@@ -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 {
@@ -204,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;
    }
}
src/main/java/com/mzl/flower/service/impl/wallet/WalletWithdrawRecordServiceImpl.java
@@ -215,61 +215,99 @@
        //审批通过之后写转账信息
        if (Constants.WALLET_APPROVE_STATE.APPROVE.name().equals(walletWithdrawRecordDTO.getApproveState())) {
            Supplier s = supplierMapper.selectById(withdrawRecordDO.getSupplierId());
            String name = "";
            name = "供应商" + s.getName();
            UserWechat wechat = wechatMapper.selectOne(new QueryWrapper<UserWechat>().eq("user_id", s.getUserId()));
            RLock recordLock = redissonClient.getLock(String.format(LockConstants.WALLET_WITHDRAW_RECORD_KEY, walletWithdrawRecordDTO.getId()));
            try {
                if (recordLock.tryLock(10, 30, TimeUnit.SECONDS)) {
                    try {
                        if(!walletWithdrawRecordDTO.getApproveState().equals(Constants.WALLET_APPROVE_STATE.WAITING)){
                            String msg =  "重复通过";
                            throw new ValidationException(msg);
                        }
                        Supplier s = supplierMapper.selectById(withdrawRecordDO.getSupplierId());
                        WalletDO walletDO = walletService.getOrCreateBySupplierId(s.getId());
                        RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_ID_KEY, walletDO.getId()));
                        try {
                            if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
                                try {
                                    if (!ObjectUtils.isEmpty(walletDO)) {
                                        String name = "";
                                        name = "供应商" + s.getName();
                                        UserWechat wechat = wechatMapper.selectOne(new QueryWrapper<UserWechat>().eq("user_id", s.getUserId()));
            if (wechat == null) {
                String msg = name + "未绑定账号无法提现";
                log.error(msg);
                throw new ValidationException(msg);
            }
                                        if (wechat == null) {
                                            String msg = name + "未绑定账号无法提现";
                                            log.error(msg);
                                            throw new ValidationException(msg);
                                        }
            LocalDateTime now = LocalDateTime.now();
            String day = format(now, "yyyy-MM-dd");
            String remarks = name + "钱包提现";
            String appId = PyamentV3Configurer.supplier_app_id;
            TransferReqDTO transferReqDTO = new TransferReqDTO();
            transferReqDTO.setId(UUIDGenerator.getUUID());
            transferReqDTO.setAppId(appId);
            transferReqDTO.setName(day + "日" + remarks);
            transferReqDTO.setRemarks(remarks);
                                        LocalDateTime now = LocalDateTime.now();
                                        String day = format(now, "yyyy-MM-dd");
                                        String remarks = name + "钱包提现";
                                        String appId = PyamentV3Configurer.supplier_app_id;
                                        TransferReqDTO transferReqDTO = new TransferReqDTO();
                                        transferReqDTO.setId(UUIDGenerator.getUUID());
                                        transferReqDTO.setAppId(appId);
                                        transferReqDTO.setName(day + "日" + remarks);
                                        transferReqDTO.setRemarks(remarks);
            //保存账单信息
            WalletBillRecordDO walletBillRecordDO = new WalletBillRecordDO();
            walletBillRecordDO.setSupplierId(s.getId());
            walletBillRecordDO.setType(Constants.BILL_CHANGE_TYPE.withdraw.name());
            walletBillRecordDO.setMethod(Constants.BILL_CHANGE_METHOD.reduce.name());
            walletBillRecordDO.setTransferId(transferReqDTO.getId());
            walletBillRecordDO.setWithdrawRecordId(withdrawRecordDO.getId());
            walletBillRecordDO.create();
            //提现金额
            BigDecimal withdrawAmount = withdrawRecordDO.getAmount();
                                        //保存账单信息
                                        WalletBillRecordDO walletBillRecordDO = new WalletBillRecordDO();
                                        walletBillRecordDO.setSupplierId(s.getId());
                                        walletBillRecordDO.setType(Constants.BILL_CHANGE_TYPE.withdraw.name());
                                        walletBillRecordDO.setMethod(Constants.BILL_CHANGE_METHOD.reduce.name());
                                        walletBillRecordDO.setTransferId(transferReqDTO.getId());
                                        walletBillRecordDO.setWithdrawRecordId(withdrawRecordDO.getId());
                                        walletBillRecordDO.create();
                                        walletBillRecordDO.setOriginalAmount(walletDO.getWithdrawableAmount());
                                        walletBillRecordDO.setChangeAmount(BigDecimal.ZERO);
                                        walletBillRecordDO.setBalance(walletDO.getWithdrawableAmount());
                                        //提现金额
                                        BigDecimal withdrawAmount = withdrawRecordDO.getAmount();
            if (withdrawAmount.doubleValue() > 0) {//结算金额>0时才去转账
                TransferDetailReqDTO dr = new TransferDetailReqDTO();
                dr.setId(UUIDGenerator.getUUID());
                dr.setAmount(withdrawAmount.multiply(new BigDecimal(100)).longValue());
                dr.setOpenId(wechat.getOpenId());
                dr.setRemarks(remarks);
                if (withdrawAmount.doubleValue() >= 2000) {
                    dr.setUserName(wechat.getRealName());
                                        if (withdrawAmount.doubleValue() > 0) {//结算金额>0时才去转账
                                            TransferDetailReqDTO dr = new TransferDetailReqDTO();
                                            dr.setId(UUIDGenerator.getUUID());
                                            dr.setAmount(withdrawAmount.multiply(new BigDecimal(100)).longValue());
                                            dr.setOpenId(wechat.getOpenId());
                                            dr.setRemarks(remarks);
                                            if (withdrawAmount.doubleValue() >= 2000) {
                                                dr.setUserName(wechat.getRealName());
                                            }
                                            List<TransferDetailReqDTO> details = new ArrayList<>();
                                            details.add(dr);
                                            walletBillRecordDO.setTransferDetailId(dr.getId());
                                            log.info("发起转账");
                                            transferReqDTO.setDetails(details);
                                            try {
                                                //发起转账
                                               // paymentV3Service.doBatchTransfer(transferReqDTO, SecurityUtils.getUserId());
                                            } catch (Exception e) {
                                                throw new ValidationException(e.getMessage());
                                            }
                                        }
                                        //记录转账状态,定时任务定时获取状态并更新钱包交易记录表信息
                                        walletBillRecordDO.setRemark("账户资金提现中");
                                        walletBillRecordDO.setActualTransferAmount(withdrawAmount);
                                        walletBillRecordDO.setId(UUIDGenerator.getUUID());
                                        walletBillRecordMapper.insert(walletBillRecordDO);
                                        //不需要更新结算单了,此时提现的金额和计算单上的金额不一致
                                    }
                                } finally {
                                    lock.unlock();
                                }
                            }
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    } finally {
                        recordLock.unlock();
                    }
                }
                List<TransferDetailReqDTO> details = new ArrayList<>();
                details.add(dr);
                walletBillRecordDO.setTransferDetailId(dr.getId());
                log.info("发起转账");
                transferReqDTO.setDetails(details);
                //发起转账
                paymentV3Service.doBatchTransfer(transferReqDTO, SecurityUtils.getUserId());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //记录转账状态,定时任务定时获取状态并更新钱包交易记录表信息
            walletBillRecordDO.setRemark("账户资金提现中");
            walletBillRecordMapper.insert(walletBillRecordDO);
            //不需要更新结算单了,此时提现的金额和计算单上的金额不一致
        }
        if (Constants.WALLET_APPROVE_STATE.REJECT.name().equals(walletWithdrawRecordDTO.getApproveState())) {
@@ -282,6 +320,23 @@
                if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
                    try {
                        if (!ObjectUtils.isEmpty(walletDO)) {
                            // 2.新增一条账单明细
                            WalletBillRecordDO walletBillRecordDO = new WalletBillRecordDO();
                            walletBillRecordDO.setId(UUIDGenerator.getUUID());
                            walletBillRecordDO.setSupplierId(walletDO.getSupplierId());
                            walletBillRecordDO.setWalletId(walletDO.getId());
                            walletBillRecordDO.setType(Constants.BILL_CHANGE_TYPE.withdraw.name());
                            // 发起提现
                            walletBillRecordDO.setWithdrawType(Constants.BILL_WITHDRAW_TYPE.fail.name());
                            walletBillRecordDO.setMethod(Constants.BILL_CHANGE_METHOD.add.name());
                            walletBillRecordDO.setOriginalAmount(walletDO.getWithdrawableAmount());
                            walletBillRecordDO.setChangeAmount(withdrawRecordDO.getAmount());
                            walletBillRecordDO.setBalance(walletDO.getWithdrawableAmount().add(withdrawRecordDO.getAmount()));
                            walletBillRecordDO.create(SecurityUtils.getUserId());
                            walletBillRecordDO.setId(UUIDGenerator.getUUID());
                            // 保存账单明细
                            walletBillRecordService.save(walletBillRecordDO);
                            //提现中金额:审核失败体现中金额扣减
                            walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(withdrawRecordDO.getAmount()));
                            //可提现金额:审核失败可提现金额增加
src/main/java/com/mzl/flower/service/wallet/WalletBillRecordService.java
@@ -32,4 +32,6 @@
    void exportSupplierFinanceList(HttpServletResponse response, QueryWalletBillRecordDTO dto);
    Page<WalletBillRecordVO> getPage(Page page, QueryWalletBillDTO dto);
    Page<WalletBillRecordVO> getPageByDesc(Page page, QueryWalletBillDTO dto);
}
src/main/java/com/mzl/flower/web/v2/wallet/WalletBillRecordController.java
@@ -47,6 +47,15 @@
        return returnData(R.SUCCESS.getCode(), walletBillRecordService.getPage(page, dto));
    }
    @GetMapping("/pageByDesc")
    public ResponseEntity<ReturnDataDTO<Page<WalletBillRecordVO>>> pageByDesc(Page page, QueryWalletBillDTO dto
    ) {
        // 根据当前用户获取供应商
        dto.setSupplierId(supplierService.getCurrentSupplier().getId());
        return returnData(R.SUCCESS.getCode(), walletBillRecordService.getPageByDesc(page, dto));
    }
    @GetMapping({"/export"})
    @ApiOperation(value = "供应商财务导出")
    public void partnerExportSales(HttpServletResponse response, @Validated QueryWalletBillRecordDTO dto) {
src/main/resources/mapper/wallet/WalletBillRecordMapper.xml
@@ -38,7 +38,23 @@
        <if test="dto.endDate != null">
            and DATE_FORMAT(wbr.create_time, '%Y-%m-%d') &lt;= #{dto.endDate}
        </if>
        order by wbr.create_time asc
    </select>
    <select id="getPageByDesc" resultType="com.mzl.flower.dto.response.wallet.WalletBillRecordVO">
        select *
        from t_wallet_bill_record wbr
        where wbr.DELETED=0
        <if test="dto.supplierId != null and dto.supplierId != ''">
            and wbr.supplier_id= #{dto.supplierId}
        </if>
        <if test="dto.startDate != null">
            and DATE_FORMAT(wbr.create_time, '%Y-%m-%d') &gt;= #{dto.startDate}
        </if>
        <if test="dto.endDate != null">
            and DATE_FORMAT(wbr.create_time, '%Y-%m-%d') &lt;= #{dto.endDate}
        </if>
        order by wbr.create_time desc
    </select>
    <select id="queryPage" resultType="com.mzl.flower.dto.response.wallet.WalletBillRecordVO">
        select t.* ,s.name supplierName ,w.approve_time as approveTime  from t_wallet_bill_record t