package cn.pluss.platform.entity;

import cn.pluss.platform.util.DateUtils;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * CREATE TABLE `tb_pluss_merchant_rate` (
 *   ` id` int(11) NOT NULL AUTO_INCREMENT,
 *   `userId` int(11) DEFAULT NULL COMMENT '商户id',
 *   `rate` int(11) DEFAULT NULL COMMENT '费率',
 *   `updateTime` datetime DEFAULT NULL COMMENT '更新时间',
 *   `previousRate` int(11) DEFAULT NULL COMMENT '修改前的费率',
 *   PRIMARY KEY (`id`),
 *   UNIQUE KEY `idx_userId` (`userId`) USING BTREE
 * ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商户费率表，用于代理服务商推广的商户';
 */
@Data
@Accessors(chain = true)
public class MerchantRate {

    public static int MAX_RATE = 25;

    public static int MIN_RATE = 21;

    private Integer id;

    private String userId;

    private Integer previousRate;

    private Integer rate;

    private Date updateTime;

    public Integer getCurrentRate() {
        Date updateTime = getUpdateTime();
        Date now = new Date();
        if (DateUtils.formatDateDefault(updateTime, "yyyy-MM-dd").compareTo(DateUtils.formatDateDefault(now, "yyyy-MM-dd")) >= 0) {
            rate = getPreviousRate();
            if (rate == null || rate == 0) {
                rate = 38;
            }
        }
        return rate;
    }

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String isFixedRate;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date startTime;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date endTime;
}
