findme-backend-merchant-java/src/main/java/com/xjhs/findmemerchant/entity/Withdrawal.java
2026-01-09 12:20:44 +08:00

175 lines
4.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.xjhs.findmemerchant.entity;
import com.xjhs.findmemerchant.common.jpa.AbstractBaseEntity;
import com.xjhs.findmemerchant.types.WithdrawalStatus;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 提现申请
* 对应表withdrawals
*/
@Getter
@Setter
@Entity
@Table(
name = "withdrawals",
indexes = {
@Index(name = "idx_withdrawals_merchant_id", columnList = "merchant_id"),
@Index(name = "idx_withdrawals_wallet_id", columnList = "wallet_id"),
@Index(name = "idx_withdrawals_status", columnList = "status"),
@Index(name = "idx_withdrawals_created_at", columnList = "created_at")
}
)
public class Withdrawal extends AbstractBaseEntity {
/**
* 提现金额
*/
@Column(name = "amount", precision = 12, scale = 2)
@Comment("提现金额")
private BigDecimal amount;
/**
* 手续费
*/
@Column(name = "fee", precision = 10, scale = 2)
@Comment("提现手续费")
private BigDecimal fee = BigDecimal.ZERO;
/**
* 实际到账金额
*/
@Column(name = "actual_amount", precision = 12, scale = 2)
@Comment("实际到账金额")
private BigDecimal actualAmount;
/**
* 银行名称
*/
@Column(name = "bank_name", length = 50)
@Comment("银行名称")
private String bankName;
/**
* 银行账号(加密存储)
*/
@Column(name = "bank_account", length = 30)
@Comment("银行账号(加密)")
private String bankAccount;
/**
* 户名
*/
@Column(name = "account_name", length = 50)
@Comment("开户人姓名")
private String accountName;
/**
* 状态0-待审核 1-处理中 2-已完成 3-已拒绝 4-已取消
*/
@Column(name = "status")
@Comment("提现状态")
private Byte status = 0;
/**
* 拒绝原因
*/
@Column(name = "reject_reason", length = 200)
@Comment("拒绝原因")
private String rejectReason;
/**
* 审核/处理时间
*/
@Column(name = "processed_at")
@Comment("审核/处理时间")
private LocalDateTime processedAt;
/**
* 完成时间
*/
@Column(name = "completed_at")
@Comment("完成时间")
private LocalDateTime completedAt;
/**
* 银行流水号
*/
@Column(name = "transaction_no", length = 64)
@Comment("银行流水号")
private String transactionNo;
/**
* 备注
*/
@Column(name = "remark", length = 200)
@Comment("备注")
private String remark;
/**
* 商家
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "merchant_id", insertable = false, updatable = false)
private Merchant merchant;
/**
* 钱包
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "wallet_id", insertable = false, updatable = false)
private Wallet wallet;
// ========= 业务方法 =========
public WithdrawalStatus getStatusEnum() {
return WithdrawalStatus.fromCode(this.status);
}
public void setStatusEnum(WithdrawalStatus statusEnum) {
this.status = statusEnum == null ? null : statusEnum.code();
}
public String getStatusText() {
WithdrawalStatus e = getStatusEnum();
return e != null ? e.getDesc() : "未知";
}
/**
* 是否待审核
*/
public boolean isPending() {
return getStatusEnum() == WithdrawalStatus.PENDING;
}
/**
* 是否已完成
*/
public boolean isCompleted() {
return getStatusEnum() == WithdrawalStatus.COMPLETED;
}
/**
* 是否可以取消
*/
public boolean canCancel() {
return getStatusEnum() == WithdrawalStatus.PENDING;
}
/**
* 脱敏银行卡号
*/
public String getMaskedBankAccount() {
if (bankAccount == null || bankAccount.length() <= 8) {
return bankAccount;
}
return bankAccount.substring(0, 4) + "****" + bankAccount.substring(bankAccount.length() - 4);
}
}