cloudroam
2024-10-28 617cac9aab814b33a4a0947d7222eae1098028ca
Merge branch 'master-v4' of http://47.96.225.205:8888/r/flowerbackend-v2 into master-v4

 Conflicts:
 src/main/java/com/mzl/flower/dto/response/wallet/WalletBillRecordVO.java
 src/main/java/com/mzl/flower/mapper/wallet/WalletBillRecordMapper.java
 src/main/java/com/mzl/flower/service/impl/wallet/WalletBillRecordServiceImpl.java
 src/main/java/com/mzl/flower/service/impl/wallet/WalletWithdrawRecordServiceImpl.java
 src/main/java/com/mzl/flower/service/wallet/WalletBillRecordService.java
 src/main/java/com/mzl/flower/web/v2/wallet/WalletBillRecordController.java
 src/main/resources/mapper/wallet/WalletBillRecordMapper.xml
已修改16个文件
已添加9个文件
737 ■■■■■ 文件已修改
src/main/java/com/mzl/flower/constant/LockConstants.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/wallet/QueryWalletAmountDTO.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/wallet/QueryWalletBillDTO.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/wallet/QueryWalletReduceDTO.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/wallet/WalletBillRecordVO.java 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/response/wallet/WalletReduceVO.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/wallet/WalletBillRecordMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/wallet/WalletMapper.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/wallet/WalletReduceMapper.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/report/OrderReportServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/wallet/WalletBillRecordServiceImpl.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/wallet/WalletReduceServiceImpl.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java 162 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/impl/wallet/WalletWithdrawRecordServiceImpl.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/wallet/WalletBillRecordService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/wallet/WalletReduceService.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/wallet/WalletService.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/wallet/WalletBillRecordController.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/wallet/WalletController.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/wallet/WalletDeductController.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/report/OrderReportMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/wallet/WalletBillRecordMapper.xml 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/wallet/WalletMapper.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/wallet/WalletReduceMapper.xml 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/wallet/WalletWithdrawRecordMapper.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/constant/LockConstants.java
@@ -3,6 +3,8 @@
public class LockConstants {
    // 钱包ID锁
    public static final String WALLET_ID_KEY = "WALLET_ID_KEY:%s";
    public static final String WALLET_ID_KEY = "com:mzl:flower:constant:WALLET_ID_KEY:%s";
    public static final String WALLET_SUPPLIER_ID_KEY = "com:mzl:flower:constant:WALLET_SUPPLIER_ID_KEY:%s";
}
src/main/java/com/mzl/flower/dto/request/wallet/QueryWalletAmountDTO.java
对比新文件
@@ -0,0 +1,13 @@
package com.mzl.flower.dto.request.wallet;
import lombok.Data;
@Data
public class QueryWalletAmountDTO {
    private String userId;
    private Long SupplierId;
    private String startTime;
}
src/main/java/com/mzl/flower/dto/request/wallet/QueryWalletBillDTO.java
对比新文件
@@ -0,0 +1,30 @@
package com.mzl.flower.dto.request.wallet;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@Data
public class QueryWalletBillDTO {
    @ApiModelProperty(value = "供应商Id")
    private Long supplierId;
//
//    @ApiModelProperty(value = "供应商名称")
//    private String supplierName;
    @ApiModelProperty(value = "开始日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate startDate;
    @ApiModelProperty(value = "结束日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate endDate;
}
src/main/java/com/mzl/flower/dto/request/wallet/QueryWalletReduceDTO.java
对比新文件
@@ -0,0 +1,33 @@
package com.mzl.flower.dto.request.wallet;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@Data
public class QueryWalletReduceDTO {
    @ApiModelProperty(value = "供应商Id")
    private Long supplierId;
//
//    @ApiModelProperty(value = "供应商名称")
//    private String supplierName;
    @ApiModelProperty(value = "审核日期-开始日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate startDate;
    @ApiModelProperty(value = "审核日期-结束日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate endDate;
    @ApiModelProperty(value = "钱包上线时间",hidden = true)
    private String walletOnlineTime;
}
src/main/java/com/mzl/flower/dto/response/wallet/WalletBillRecordVO.java
@@ -17,6 +17,25 @@
    @ApiModelProperty(value = "供应商名称")
    private String supplierName;
    @ApiModelProperty(value = "钱包Id")
    private Long walletId;
    @ApiModelProperty(value = "账单变动类型(提现,结算)")
    @DictTrans(target = "typeName",codeType = "BILL_CHANGE_TYPE")
    private String type;
    @ApiModelProperty(value = "类型明细")
    private String typeDetail;
    @ApiModelProperty(value = "结算单id")
    private String settlementId;
    @ApiModelProperty(value = "转账Id")
    private String transferId;
    @ApiModelProperty(value = "变动方式(增加、减少")
    @DictTrans(target = "methodName",codeType = "BILL_CHANGE_METHOD")
    private String method;
    @ApiModelProperty(value = "原金额")
    private BigDecimal originalAmount;
@@ -27,12 +46,6 @@
    @ApiModelProperty(value = "余额")
    private BigDecimal balance;
    @ApiModelProperty(value = "账单变动类型(提现,结算)")
    @DictTrans(target = "withdrawStateStr", codeType = "BILL_CHANGE_TYPE")
    private String type;
    private String typeStr;
    @ApiModelProperty("提交时间")
    private LocalDateTime createTime;
@@ -41,5 +54,19 @@
    @ApiModelProperty(value = "备注")
    private String remark;
    @ApiModelProperty(value = "转账明细id")
    private String transferDetailId;
    @ApiModelProperty(value = "转账状态")
    private String transferState;
    @ApiModelProperty(value = "openId")
    private String openId;
    @ApiModelProperty(value = "账单变动类型(提现,结算)")
    private String typeName;
    @ApiModelProperty(value = "变动方式(增加、减少")
    private String methodName;
}
src/main/java/com/mzl/flower/dto/response/wallet/WalletReduceVO.java
对比新文件
@@ -0,0 +1,29 @@
package com.mzl.flower.dto.response.wallet;
import com.mzl.flower.base.AbstractTransDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class WalletReduceVO extends AbstractTransDTO {
    // 根据上面的列写属性
    @ApiModelProperty(value = "原主键")
    private String id;
    @ApiModelProperty(value = "费用")
    private BigDecimal fee;
    @ApiModelProperty(value = "审核时间")
    private String auditTime;
    @ApiModelProperty(value = "扣款类型")
    private String type;
    @ApiModelProperty(value = "扣款类型名称")
    private String typeName;
    @ApiModelProperty(value = "订单编号")
    private String orderNo;
    @ApiModelProperty(value = "供应商ID")
    private Long supplierId;
}
src/main/java/com/mzl/flower/mapper/wallet/WalletBillRecordMapper.java
@@ -1,6 +1,10 @@
package com.mzl.flower.mapper.wallet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.wallet.QueryWalletBillDTO;
import com.mzl.flower.dto.response.wallet.WalletBillRecordVO;
import com.mzl.flower.dto.response.wallet.WalletWithdrawRecordVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.wallet.QueryWalletBillRecordDTO;
import com.mzl.flower.dto.response.wallet.WalletBillRecordVO;
import com.mzl.flower.entity.wallet.WalletBillRecordDO;
@@ -24,5 +28,6 @@
    List<WalletBillRecordVO> queryPage(@Param("dto") QueryWalletBillRecordDTO queryWalletBillRecordDTO, Page page);
    List<WalletBillRecordVO> queryWalletBillRecordList(@Param("dto") QueryWalletBillRecordDTO queryWalletBillRecordDTO);
    List<WalletBillRecordVO> getPage(Page page, @Param("dto") QueryWalletBillDTO dto);
}
src/main/java/com/mzl/flower/mapper/wallet/WalletMapper.java
@@ -1,9 +1,13 @@
package com.mzl.flower.mapper.wallet;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.entity.wallet.WalletDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
/**
 * <p>
@@ -19,4 +23,12 @@
    @Select("select * from t_wallet where supplier_id =#{supplierId}")
    public WalletDO getTotalAmount(String supplierId);
    BigDecimal getWaittingSettlementAmount(@Param("dto") WalletDO walletDO);
    @Select("select label from t_code_value where type_code='WALLET_ONLINE_TIME' and value='online'")
    String selectWalletOnlineTime();
    BigDecimal getSupplierTotalTransactionAmount(@Param("dto") QueryWalletAmountDTO queryWalletAmountDTO);
}
src/main/java/com/mzl/flower/mapper/wallet/WalletReduceMapper.java
对比新文件
@@ -0,0 +1,33 @@
package com.mzl.flower.mapper.wallet;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletReduceDTO;
import com.mzl.flower.dto.response.wallet.WalletReduceVO;
import com.mzl.flower.entity.wallet.WalletDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
import java.util.List;
/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author @TaoJie
 * @since 2024-10-22
 */
@Repository
public interface WalletReduceMapper extends BaseMapper<WalletDO> {
    List<WalletReduceVO> getPage(Page page,@Param("dto") QueryWalletReduceDTO dto);
    BigDecimal getCheckReduceAmount(@Param("dto") QueryWalletAmountDTO queryWalletAmountDTO);
    BigDecimal getSaleReduceAmount(@Param("dto")QueryWalletAmountDTO queryWalletAmountDTO);
}
src/main/java/com/mzl/flower/service/impl/report/OrderReportServiceImpl.java
@@ -347,7 +347,7 @@
    @Override
    public AppSupplierStatisticsVO getAppSupplierStatistics(QueryAppSupplierDTO dto) {
        // TODO
        // 总成交:花农售卖全部的底价合计,
        // 本月成交:本月售卖的底价合计,
src/main/java/com/mzl/flower/service/impl/wallet/WalletBillRecordServiceImpl.java
@@ -2,11 +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.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;
@@ -35,6 +38,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.List;
/**
 * <p>
@@ -94,7 +98,7 @@
                walletBillRecordDO.update("sys");
                walletBillRecordMapper.updateById(walletBillRecordDO);
                //更新钱包
                WalletDO walletDO = walletService.getBySupplierId(walletBillRecordDO.getWalletId());
                WalletDO walletDO = walletService.getOrCreateBySupplierId(walletBillRecordDO.getWalletId());
                RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_ID_KEY, walletDO.getId()));
                try {
                    if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
@@ -124,7 +128,7 @@
                walletBillRecordDO.setTransferState(Constants.SETTLEMENT_STATUS.FAILED.name());
                walletBillRecordDO.update("sys");
                walletBillRecordMapper.updateById(walletBillRecordDO);
                WalletDO walletDO = walletService.getBySupplierId(walletBillRecordDO.getWalletId());
                WalletDO walletDO = walletService.getOrCreateBySupplierId(walletBillRecordDO.getWalletId());
                RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_ID_KEY, walletDO.getId()));
                try {
                    if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
@@ -192,4 +196,11 @@
            log.error(e.getMessage(), e);
        }
    }
    @Override
    public Page<WalletBillRecordVO> getPage(Page page, QueryWalletBillDTO dto) {
        List<WalletBillRecordVO> list = walletBillRecordMapper.getPage(page,dto);
        page.setRecords(list);
        return page;
    }
}
src/main/java/com/mzl/flower/service/impl/wallet/WalletReduceServiceImpl.java
对比新文件
@@ -0,0 +1,45 @@
package com.mzl.flower.service.impl.wallet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletReduceDTO;
import com.mzl.flower.dto.response.wallet.WalletReduceVO;
import com.mzl.flower.dto.response.wallet.WalletWithdrawRecordVO;
import com.mzl.flower.mapper.wallet.WalletReduceMapper;
import com.mzl.flower.service.wallet.WalletReduceService;
import com.mzl.flower.service.wallet.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
@Service
public class WalletReduceServiceImpl implements WalletReduceService {
    @Autowired
    private WalletReduceMapper walletReduceMapper;
    @Autowired
    private WalletService walletService;
    @Override
    public Page<WalletReduceVO> getPage(Page page, QueryWalletReduceDTO dto) {
        // 设置查询的时间为钱包的上线时间
        dto.setWalletOnlineTime(walletService.getWalletOnLineTime());
        List<WalletReduceVO> list = walletReduceMapper.getPage(page,dto);
        page.setRecords(list);
        return page;
    }
    @Override
    public BigDecimal getCheckReduceAmount(QueryWalletAmountDTO queryWalletAmountDTO) {
        return walletReduceMapper.getCheckReduceAmount(queryWalletAmountDTO);
    }
    @Override
    public BigDecimal getSaleReduceAmount(QueryWalletAmountDTO queryWalletAmountDTO) {
        return walletReduceMapper.getSaleReduceAmount(queryWalletAmountDTO);
    }
}
src/main/java/com/mzl/flower/service/impl/wallet/WalletServiceImpl.java
@@ -2,20 +2,28 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.LockConstants;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.entity.coupon.CouponTemplateDO;
import com.mzl.flower.entity.wallet.WalletDO;
import com.mzl.flower.enums.TrueOrFalseEnum;
import com.mzl.flower.mapper.wallet.WalletMapper;
import com.mzl.flower.service.supplier.SupplierService;
import com.mzl.flower.service.wallet.WalletReduceService;
import com.mzl.flower.service.wallet.WalletService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
/**
 * <p>
@@ -31,6 +39,29 @@
    @Autowired
    private SupplierService supplierService;
    @Autowired
    private WalletReduceService walletReduceService;
    private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    private static final Pattern dateTimeRegex = Pattern.compile("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
    @Autowired
    RedissonClient redissonClient;
    @Override
    public String getWalletOnLineTime() {
        String walletOnlineTime =baseMapper.selectWalletOnlineTime();
        // 这里需要判断walletOnlineTime是不是一个正确的yyyy-mm-dd hh24:mi:ss的时间
        String startTime;
        if (isValidDateTime(walletOnlineTime)) {
            startTime = walletOnlineTime;
        } else {
            // 如果 walletOnlineTime 无效,则使用当前时间的字符串
            startTime = getCurrentDateTime();
        }
        return startTime;
    }
    @Override
    public WalletDO getCurrentSupplier() {
        final SupplierDTO currentSupplier = supplierService.getCurrentSupplier();
@@ -38,42 +69,121 @@
            // 查询的条件的deleted的字段得为0
            // 下面的单独封装成一个方法
            WalletDO walletDO = getBySupplierId(currentSupplier.getId());
            if(null==walletDO){
                // 先创建一个钱包
                walletDO=new WalletDO();
                walletDO.setUserId(SecurityUtils.getUserId());
                walletDO.setSupplierId(currentSupplier.getId());
                walletDO.setTotalAmount(BigDecimal.ZERO);
                walletDO.setWithdrawableAmount(BigDecimal.ZERO);
                //把所有涉及BigDecimal的金额都设置为0
                walletDO.setWithdrawingAmount(BigDecimal.ZERO);
                walletDO.setWithdrawnAmount(BigDecimal.ZERO);
                walletDO.setSettlingAmount(BigDecimal.ZERO);
                walletDO.setTotalDeduction(BigDecimal.ZERO);
                walletDO.setTotalTransactionAmount(BigDecimal.ZERO);
                walletDO.setSettlingAmount(BigDecimal.ZERO);
                walletDO.create(SecurityUtils.getUserId());
                baseMapper.insert(walletDO);
                // 将再次查询的结果返回
                walletDO=getBySupplierId(currentSupplier.getId());
            }
            WalletDO walletDO = getOrCreateBySupplierId(currentSupplier.getId());
        return walletDO;
    }
    @Override
    public WalletDO getBySupplierId(Long supplierId) {
        // 不用getOne,用获取list的第一个元素
    public WalletDO getOrCreateBySupplierId(Long supplierId) {
        WalletDO walletDO=getBySupplierId(supplierId);
        if(null==walletDO){
            RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_SUPPLIER_ID_KEY, supplierId));
            try {
                if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
                    try {
                        walletDO=getBySupplierId(supplierId);
                        if(null!=walletDO) return walletDO;
                        // 创建一个钱包
                        walletDO =new WalletDO();
                        walletDO.setUserId(SecurityUtils.getUserId());
                        walletDO.setSupplierId(supplierId);
                        walletDO.setTotalAmount(BigDecimal.ZERO);
                        walletDO.setWithdrawableAmount(BigDecimal.ZERO);
                        //把所有涉及BigDecimal的金额都设置为0
                        walletDO.setWithdrawingAmount(BigDecimal.ZERO);
                        walletDO.setWithdrawnAmount(BigDecimal.ZERO);
                        walletDO.setSettlingAmount(BigDecimal.ZERO);
                        walletDO.setTotalDeduction(BigDecimal.ZERO);
                        walletDO.setTotalTransactionAmount(BigDecimal.ZERO);
                        walletDO.setSettlingAmount(BigDecimal.ZERO);
                        walletDO.create(SecurityUtils.getUserId());
                        baseMapper.insert(walletDO);
                        // 将再次查询的结果返回
                        walletDO= getBySupplierId(supplierId);
                        return walletDO;
                    } finally {
                        lock.unlock();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return null;
        }else{
            return walletDO;
        }
    }
    @Override
    public WalletDO getBySupplierId(Long supplierId) {
        List<WalletDO> walletDOS = baseMapper.selectList(new LambdaQueryWrapper<WalletDO>()
                .eq(WalletDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag())
                .eq(WalletDO::getSupplierId, supplierId));
        if(!CollectionUtils.isEmpty(walletDOS)){
            return walletDOS.get(0);
        }else return null;
        }
        return null;
    }
    @Override
    public BigDecimal getWaittingSettlementAmount(WalletDO walletDO) {
        return baseMapper.getWaittingSettlementAmount(walletDO);
    }
    @Override
    public BigDecimal getSupplierTotalTransactionAmount(WalletDO walletDO) {
        QueryWalletAmountDTO queryWalletAmountDTO=new QueryWalletAmountDTO();
        queryWalletAmountDTO.setSupplierId(walletDO.getSupplierId());
        queryWalletAmountDTO.setStartTime(getWalletOnLineTime());
        queryWalletAmountDTO.setUserId(walletDO.getUserId());
        BigDecimal totalTransactionAmount=baseMapper.getSupplierTotalTransactionAmount(queryWalletAmountDTO);
        return totalTransactionAmount;
    }
    @Override
    public BigDecimal getSupplierDeductAmount(WalletDO walletDO) {
        QueryWalletAmountDTO queryWalletAmountDTO=new QueryWalletAmountDTO();
        queryWalletAmountDTO.setSupplierId(walletDO.getSupplierId());
        queryWalletAmountDTO.setStartTime(getWalletOnLineTime());
        queryWalletAmountDTO.setUserId(walletDO.getUserId());
        // 质检扣款
        BigDecimal checkDeduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO);
        checkDeduceAmount = checkDeduceAmount != null ? checkDeduceAmount : BigDecimal.ZERO;
        // 售后扣款
        BigDecimal saleDeduceAmount = walletReduceService.getSaleReduceAmount(queryWalletAmountDTO);
        saleDeduceAmount = saleDeduceAmount != null ? saleDeduceAmount : BigDecimal.ZERO;
        // 总扣款
        BigDecimal deduceAmount = checkDeduceAmount.add(saleDeduceAmount);
        return deduceAmount;
    }
    public static boolean isValidDateTime(String dateTime) {
        if (dateTime == null || !dateTimeRegex.matcher(dateTime).matches()) {
            return false;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_PATTERN);
        sdf.setLenient(false);
        try {
            sdf.parse(dateTime);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    public static String getCurrentDateTime() {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_PATTERN);
        return sdf.format(new Date());
    }
}
src/main/java/com/mzl/flower/service/impl/wallet/WalletWithdrawRecordServiceImpl.java
@@ -117,6 +117,12 @@
                    // 1.新增一条余额提现记录
                    WalletWithdrawRecordDO withdrawRecordDO = new WalletWithdrawRecordDO();
                    //原金额
                    withdrawRecordDO.setOriginalAmount(walletDO.getWithdrawableAmount());
                    // 变动金额
                    withdrawRecordDO.setChangeAmount(dto.getAmount());
                    // 余额
                    withdrawRecordDO.setBalance(walletDO.getWithdrawableAmount().subtract(dto.getAmount()));
                    withdrawRecordDO.setAmount(dto.getAmount());
                    withdrawRecordDO.setSupplierId(supplierDTO.getId());
                    withdrawRecordDO.setWithdrawState(Constants.WALLET_WITHDRAW_STATE.WAITING.name());
@@ -246,7 +252,7 @@
            //更新钱包
            Supplier s = supplierMapper.selectById(withdrawRecordDO.getSupplierId());
            WalletDO walletDO = walletService.getBySupplierId(s.getId());
            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)) {
src/main/java/com/mzl/flower/service/wallet/WalletBillRecordService.java
@@ -4,6 +4,9 @@
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.dto.response.wallet.WalletReduceVO;
import com.mzl.flower.entity.wallet.WalletBillRecordDO;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -27,4 +30,6 @@
    void exportSupplierFinanceList(HttpServletResponse response, QueryWalletBillRecordDTO dto);
    Page<WalletBillRecordVO> getPage(Page page, QueryWalletBillDTO dto);
}
src/main/java/com/mzl/flower/service/wallet/WalletReduceService.java
对比新文件
@@ -0,0 +1,38 @@
package com.mzl.flower.service.wallet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletReduceDTO;
import com.mzl.flower.dto.response.wallet.WalletReduceVO;
import com.mzl.flower.entity.wallet.WalletDO;
import java.math.BigDecimal;
/**
 * <p>
 *  服务类
 * </p>
 *
 * @author @TaoJie
 * @since 2024-10-22
 */
public interface WalletReduceService {
    Page<WalletReduceVO> getPage(Page page, QueryWalletReduceDTO dto);
    /**
     * 获取质检扣款钱
     * @param queryWalletAmountDTO
     * @return
     */
    BigDecimal getCheckReduceAmount(QueryWalletAmountDTO queryWalletAmountDTO);
    /**
     * 获取售后质检扣款钱
     * @param queryWalletAmountDTO
     * @return
     */
    BigDecimal getSaleReduceAmount(QueryWalletAmountDTO queryWalletAmountDTO);
}
src/main/java/com/mzl/flower/service/wallet/WalletService.java
@@ -3,6 +3,8 @@
import com.mzl.flower.entity.wallet.WalletDO;
import com.baomidou.mybatisplus.extension.service.IService;
import java.math.BigDecimal;
/**
 * <p>
 *  服务类
@@ -13,8 +15,47 @@
 */
public interface WalletService extends IService<WalletDO> {
    /**
     * 获取钱包的上线时间
     * @return
     */
    String getWalletOnLineTime();
    /**
     * 获取当前登录供应商的钱包信息
     * @return 钱包信息
     */
    WalletDO getCurrentSupplier();
    /**
     * 先尝试获取,如果不存在则创建。
     * @param supplierId 供应商ID
     * @return 钱包信息
     */
    WalletDO getOrCreateBySupplierId(Long supplierId);
    /**
     * 根据供应商的ID获取钱包信息
     * @param supplierId 供应商ID
     * @return 钱包信息
     */
    WalletDO getBySupplierId(Long supplierId);
    BigDecimal getWaittingSettlementAmount(WalletDO walletDO);
    /**
     * 获取供应商总交易额
     * @param walletDO
     * @return
     */
    BigDecimal getSupplierTotalTransactionAmount(WalletDO walletDO);
    /**
     * 获取供应商总扣款额度
     * @param walletDO
     * @return
     */
    BigDecimal getSupplierDeductAmount(WalletDO walletDO);
}
src/main/java/com/mzl/flower/web/v2/wallet/WalletBillRecordController.java
@@ -10,8 +10,19 @@
import com.mzl.flower.dto.request.wallet.QueryWalletWithdrawDTO;
import com.mzl.flower.dto.response.wallet.WalletBillRecordVO;
import com.mzl.flower.dto.response.wallet.WalletWithdrawRecordVO;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.dto.request.wallet.CreateWalletBillRecordDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletBillDTO;
import com.mzl.flower.dto.response.wallet.WalletBillRecordVO;
import com.mzl.flower.entity.supplier.Supplier;
import com.mzl.flower.entity.wallet.WalletDO;
import com.mzl.flower.mapper.supplier.SupplierMapper;
import com.mzl.flower.service.supplier.SupplierService;
import com.mzl.flower.service.wallet.WalletBillRecordService;
import io.swagger.annotations.ApiOperation;
import com.mzl.flower.service.wallet.WalletReduceService;
import com.mzl.flower.service.wallet.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
@@ -31,6 +42,24 @@
    @Autowired
    private WalletBillRecordService walletBillRecordService;
    @Autowired
    private SupplierService supplierService;
    @PostMapping("")
    public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateWalletBillRecordDTO dto) {
        return returnData(R.SUCCESS.getCode(), null);
    }
    @PutMapping("/{id}")
    public ResponseEntity<ReturnDataDTO>  update(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return returnData(R.SUCCESS.getCode(), null);
    }
    @DeleteMapping("/{id}")
    public ResponseEntity<ReturnDataDTO>  delete(@PathVariable @Positive(message = "{id.positive}") Integer id) {
        return returnData(R.SUCCESS.getCode(), null);
    @GetMapping("/list")
    @ApiOperation(value = "供应商财务-分页", httpMethod = "GET")
@@ -38,6 +67,18 @@
        return returnData(R.SUCCESS.getCode(), walletBillRecordService.queryPage(dto, page));
    }
    @GetMapping("/{id}")
    public WalletBillRecordDO get(@PathVariable(value = "id") @Positive(message = "{id.positive}") Integer id) {
        return null;
    }
    @GetMapping("/page")
    public ResponseEntity<ReturnDataDTO<Page<WalletBillRecordVO>>> page(Page page, QueryWalletBillDTO dto
    ) {
        // 根据当前用户获取供应商
        dto.setSupplierId(supplierService.getCurrentSupplier().getId());
        return returnData(R.SUCCESS.getCode(), walletBillRecordService.getPage(page,dto));
    @GetMapping({"/export"})
    @ApiOperation(value = "供应商财务导出")
    public void partnerExportSales(HttpServletResponse response, @Validated QueryWalletBillRecordDTO dto){
src/main/java/com/mzl/flower/web/v2/wallet/WalletController.java
@@ -19,6 +19,7 @@
import com.mzl.flower.entity.wallet.WalletDO;
import javax.validation.constraints.Positive;
import java.math.BigDecimal;
/**
* @author @TaoJie
@@ -66,9 +67,19 @@
        if(null==currentSupplier){
            throw new ValidationException("供应商不能为空");
        }
        final WalletDO walletDO = walletService.getCurrentSupplier();
        if(null!=walletDO){
            // 根据当前供应商获取待结算的钱
            BigDecimal waittingSettlementAmount = walletService.getWaittingSettlementAmount(walletDO);
            walletDO.setSettlingAmount(waittingSettlementAmount);
            // 总交易额度
            walletDO.setTotalTransactionAmount(walletService.getSupplierTotalTransactionAmount(walletDO));
            // 总扣款数量
            walletDO.setTotalDeduction(walletService.getSupplierDeductAmount(walletDO));
        }
        return returnData(R.SUCCESS.getCode(), walletService.getCurrentSupplier());
        return returnData(R.SUCCESS.getCode(), walletDO);
    }
    @GetMapping("/page")
src/main/java/com/mzl/flower/web/v2/wallet/WalletDeductController.java
对比新文件
@@ -0,0 +1,53 @@
package com.mzl.flower.web.v2.wallet;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.dto.request.wallet.CreateWalletWithdrawRecordDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletReduceDTO;
import com.mzl.flower.dto.request.wallet.QueryWalletWithdrawDTO;
import com.mzl.flower.dto.request.wallet.WalletWithdrawRecordDTO;
import com.mzl.flower.dto.response.wallet.WalletWithdrawRecordVO;
import com.mzl.flower.entity.wallet.WalletWithdrawRecordDO;
import com.mzl.flower.service.supplier.SupplierService;
import com.mzl.flower.service.wallet.WalletBillRecordService;
import com.mzl.flower.service.wallet.WalletReduceService;
import com.mzl.flower.service.wallet.WalletService;
import com.mzl.flower.service.wallet.WalletWithdrawRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.Positive;
/**
* @author @TaoJie
* @since 2024-10-22
*/
@Api(value = "扣款记录", tags = "扣款记录")
@RestController
@RequestMapping("/v2/wallet/reduce-record")
@RequiredArgsConstructor
public class WalletDeductController extends BaseController {
    @Autowired
    private WalletReduceService walletReduceService;
    @Autowired
    private SupplierService supplierService;
    @GetMapping("/supplier/page")
    public ResponseEntity<ReturnDataDTO<Page<WalletWithdrawRecordDO>>> page(Page page, QueryWalletReduceDTO dto
    ) {
        // 根据当前用户获取供应商
        dto.setSupplierId(supplierService.getCurrentSupplier().getId());
        return returnData(R.SUCCESS.getCode(), walletReduceService.getPage(page,dto));
    }
}
src/main/resources/mapper/report/OrderReportMapper.xml
@@ -611,7 +611,7 @@
    <!--供应商总价款-->
    <sql id="all_supplier_amount">
        select IFNULL(sum(oi.supplier_price*oi.num),0) as supplier_amount from t_order_item oi where oi.supplier_id=287
        select IFNULL(sum(oi.supplier_price*oi.num),0) as supplier_amount from t_order_item oi where oi.supplier_id=#{dto.supplierId}
    </sql>
    <!--本月成交:本月售卖的底价合计-->
    <sql id="cur_mon_supplier_amount">
src/main/resources/mapper/wallet/WalletBillRecordMapper.xml
@@ -22,6 +22,21 @@
        <result column="transfer_detail_id" property="transferDetailId" />
        <result column="open_id" property="openId" />
    </resultMap>
    <select id="getPage" 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>
    </select>
    <select id="queryPage" resultType="com.mzl.flower.dto.response.wallet.WalletBillRecordVO">
        select t.* ,s.name supplierName from t_wallet_bill_record t
        left join t_supplier_info s on t.supplier_id = s.id
src/main/resources/mapper/wallet/WalletMapper.xml
@@ -22,5 +22,29 @@
        <result column="settled_amount" property="settledAmount" />
    </resultMap>
    <select id="getWaittingSettlementAmount" resultType="java.math.BigDecimal">
         <include refid="supplier_settlement_amount"></include>
    </select>
    <!--    总交易额-->
    <select id="getSupplierTotalTransactionAmount" resultType="java.math.BigDecimal">
        select IFNULL(sum(oi.supplier_price*oi.num),0) as cur_mon_supplier_amount
        from t_order_item oi
        left join t_order o
        on oi.order_id = o.id
        where oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt; #{dto.startTime}
    </select>
    <!--    待结算-->
    <sql id="supplier_settlement_amount">
        SELECT IFNULL(sum(settlement_amount),0) AS settlement_amount
        FROM t_order_settlement OS
        WHERE OS.DELETED=0
          AND OS.TYPE='supplier'
          AND OS.status='PENDING'
          AND USER_ID=#{dto.userId}
    </sql>
</mapper>
src/main/resources/mapper/wallet/WalletReduceMapper.xml
对比新文件
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mzl.flower.mapper.wallet.WalletReduceMapper">
    <select id="getPage" resultType="com.mzl.flower.dto.response.wallet.WalletReduceVO">
        select *
        from (
                 SELECT si.id as id,si.fee_supplier as fee ,si.audit_time as audit_time,'sale' as type,'售后扣款' as type_name,o.order_no as order_no,oi.supplier_id as supplier_id
                 FROM t_order_item_sales si
                 join t_order_item oi on oi.id = si.order_item_id
                 left join t_order o on oi.order_id=o.id
                 where si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
                and o.payment_time &gt;= #{dto.walletOnlineTime}
                <if test="dto.supplierId != null">
                    and oi.supplier_id = #{dto.supplierId}
                </if>
                <if test="dto.startDate != null">
                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                </if>
                <if test="dto.endDate != null">
                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                </if>
                 union
                 select  oic.id as id ,oic.deduct_amount as fee,oic.audit_time as audit_time,oic.type as type,check_type.label as type_name,o.order_no as order_no,oi.supplier_id as supplier_id
                 from t_order_item_check oic
                 left join t_order_item oi
                 on oic.order_item_id=oi.id
                 left join t_order o
                 on oi.order_id=o.id
                 left join t_code_value check_type
                on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
                 where oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
                    and o.payment_time &gt;= #{dto.walletOnlineTime}
                <if test="dto.supplierId != null">
                    and oi.supplier_id = #{dto.supplierId}
                </if>
                <if test="dto.startDate != null">
                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                </if>
                <if test="dto.endDate != null">
                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                </if>
             ) t
        order by audit_time desc
    </select>
    <select id="getCheckReduceAmount" resultType="java.math.BigDecimal">
        SELECT sum(si.fee_supplier)
        FROM t_order_item_sales si
        join t_order_item oi on oi.id = si.order_item_id
        left join t_order o on oi.order_id=o.id
        where si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
          and oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt;= #{dto.startTime}
    </select>
    <select id="getSaleReduceAmount" resultType="java.math.BigDecimal">
        select  sum(oic.deduct_amount)
        from t_order_item_check oic
        left join t_order_item oi
        on oic.order_item_id=oi.id
        left join t_order o
        on oi.order_id=o.id
        left join t_code_value check_type
        on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
        where oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
          and oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt;= #{dto.startTime}
    </select>
</mapper>
src/main/resources/mapper/wallet/WalletWithdrawRecordMapper.xml
@@ -35,12 +35,12 @@
        </if>
        <if test="dto.createStartDate!=null ">
            <![CDATA[
               AND t.create_time &gt;= #{dto.createStartDate}
               AND DATE_FORMAT(t.create_time, '%Y-%m-%d') &gt;= #{dto.createStartDate}
            ]]>
        </if>
        <if test="dto.endEndDate!=null ">
            <![CDATA[
               AND t.create_time &lt;= #{dto.endEndDate}
               AND DATE_FORMAT(t.create_time, '%Y-%m-%d') &lt;= #{dto.endEndDate}
            ]]>
        </if>
        <if test="dto.approveStartDate!=null ">