package cn.pluss.platform.entity;

import cn.pluss.platform.config.mybatis.SqlConditionExtra;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

/**
 * <p>
 * 商户费率表(新)
 * </p>
 *
 * @author Djh
 * @since 2021-08-09
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_pluss_merchant_rate_new")
public class MerchantRateNew implements Serializable {

    public static final int MIN_LEVEL = 21;

    public static final int MAX_LEVEL = 38;

    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private String userId;

    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;


    /**
     * 通道id
     */
    @TableField("channel")
    private Integer channel;


    /**
     * 用户id
     */
    @TableField("merchantId")
    private String merchantId;


    /**
     * 微信费率等级，费率参考字典表wx_rate
     */
    @TableField("wxRate")
    private Integer wxRate;


    /**
     * 支付宝费率等级，费率参考字典表ali_rate
     */
    @TableField("aliRate")
    private Integer aliRate;


    /**
     * 银联费率等级，费率参考字典表bank_rate
     */
    @TableField("bankRate")
    private Integer bankRate;


    /**
     * 银联1000+费率等级，费率参考字典表bank_rate_1000+, 目前随行付不支持1000+的支付
     */
    @TableField("bankRateLarge")
    private Integer bankRateLarge;


    /**
     * 微信费率等级，费率参考字典表wx_rate
     */
    @TableField(exist = false)
    private BigDecimal wxRateValue;


    /**
     * 支付宝费率等级，费率参考字典表ali_rate
     */
    @TableField(exist = false)
    private BigDecimal aliRateValue;


    /**
     * 银联费率等级，费率参考字典表bank_rate
     */
    @TableField(exist = false)
    private BigDecimal bankRateValue;


    /**
     * 银联1000+费率等级，费率参考字典表bank_rate_1000+, 目前随行付不支持1000+的支付
     */
    @TableField(exist = false)
    private BigDecimal bankRateLargeValue;


    /**
     * 创建时间
     */
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 创建时间 开始时间
     */
    @TableField(select = false, value = "createTime", condition = SqlConditionExtra.GT)
    private Date createTimeStart;

    /**
     * 创建时间 截止时间
     */
    @TableField(select = false, value = "createTime", condition = SqlConditionExtra.LT)
    private Date createTimeEnd;

    /**
     * 更新时间
     */
    @TableField(value = "updateTime", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    /**
     * 更新时间 开始时间
     */
    @TableField(select = false, value = "updateTime", condition = SqlConditionExtra.GT)
    private Date updateTimeStart;

    /**
     * 更新时间 截止时间
     */
    @TableField(select = false, value = "updateTime", condition = SqlConditionExtra.LT)
    private Date updateTimeEnd;

    public static void setRateValue(MerchantRateNew entity) {
        entity.setWxRateValue(BigDecimal.valueOf(entity.wxRate).setScale(3, RoundingMode.HALF_UP));
        entity.setAliRateValue(BigDecimal.valueOf(entity.aliRate).setScale(3, RoundingMode.HALF_UP));
        entity.setBankRateValue(BigDecimal.valueOf(entity.bankRate + 2).setScale(3, RoundingMode.HALF_UP));
        entity.setBankRateLargeValue(BigDecimal.valueOf((entity.bankRateLarge - 21) / 2.0f + 53).setScale(3, RoundingMode.HALF_UP));
    }

}