package cn.pluss.platform.entity;

import cn.pluss.platform.util.DateUtils;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 用户考核表
 * </p>
 *
 * @author bzg
 * @since 2022-07-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_pluss_user_assess")
@NoArgsConstructor
public class UserAssess implements Serializable {

    private static final long serialVersionUID = 1L;

    public static int DEFAULT_IS_WHITE_YES = 1;

    public static int DEFAULT_IS_WHITE_NO = -1;

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


    /**
     * 用户ID
     */
    @TableField("userId")
    private Long userId;


    /**
     * 用户角色
     */
    @TableField("roleCode")
    private String roleCode;


    /**
     * 直推商户数
     */
    @TableField("directMercNum")
    private Integer directMercNum;


    /**
     * 有效商户数
     */
    @TableField("validMercNum")
    private Integer validMercNum;


    /**
     * 过期时间
     */
    @TableField("expireTime")
    private Date expireTime;

    /**
     * 过期时间 开始时间
     */
    @TableField(exist = false, condition = "expireTime &gt; #{%s}")
    private Date expireTimeStart;

    /**
     * 过期时间 截止时间
     */
    @TableField(exist = false, condition = "expireTime &lt; #{%s}")
    private Date expireTimeEnd;

    /**
     * 是否白名单 -1不是 1：是
     */
    @TableField("isWhite")
    private Integer isWhite;


    /**
     * 原因
     */
    @TableField("reason")
    private String reason;


    /**
     * 备注
     */
    @TableField("remark")
    private String remark;


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

    /**
     * 创建时间 开始时间
     */
    @TableField(exist = false, condition = "createTime &gt; #{%s}")
    private Date createTimeStart;

    /**
     * 创建时间 截止时间
     */
    @TableField(exist = false, condition = "createTime &lt; #{%s}")
    private Date createTimeEnd;

    public UserAssess(UserApp user, UserRole role) {
        this.userId = user.getUserId();
        this.roleCode = user.getRoleCode();
        Date date = DateUtils.currentDate();
        date = DateUtils.add(Calendar.DAY_OF_MONTH,date,role.getProtectDayNum());
        this.expireTime = date;
        this.directMercNum = BigInteger.ZERO.intValue();
        this.validMercNum = BigInteger.ZERO.intValue();
    }
}