package cn.pluss.platform.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

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

/**
 * <p>
 * 用户积分详情表
 * </p>
 *
 * @author crystal
 * @since 2022-05-17
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_pluss_user_integral")
@NoArgsConstructor
public class UserIntegral implements Serializable {

    private static final long serialVersionUID = 1L;

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


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


    /**
     * 订单号
     */
    @TableField("orderNumber")
    private String orderNumber;


    /**
     * 积分数额
     */
    @TableField("integral")
    private BigDecimal integral;


    /**
     * 交易金额
     */
    @TableField("orderAmt")
    private BigDecimal orderAmt;


    /**
     * 类型 1交易积分 2：机具活动积分 3：任务积分 4：签到积分
     */
    @TableField("type")
    private String type;


    /**
     * 来源 1：交易订单 2：云音箱 3：完成任务 4 签到打卡 5:扫码王
     */
    @TableField("source")
    private String source;

    /**
     * 积分状态 1：正常 -1：过期
     */
    private Integer status;


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


    /**
     * 创建时间
     */
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    @JsonFormat(locale = "zh",timezone = "GMT+8",pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;

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

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

    /**
     * 日期条件
     */
    @TableField(exist = false)
    private String queryDate;


    @TableField(exist = false)
    private String name;

    public UserIntegral(String orderNumber,BigDecimal orderAmt, Long userId, String type,String source, BigDecimal integral) {
        this.userId = userId;
        this.orderNumber = orderNumber;
        this.integral = integral;
        this.orderAmt = orderAmt;
        this.type = type;
        this.source = source;
    }

    public UserIntegral(Long userId, BigDecimal integral, String type,String source, String remark) {
        this.userId = userId;
        this.integral = integral;
        this.type = type;
        this.remark = remark;
        this.source = source;
    }

    public String getName() {
        String name = "";
        switch (this.type){
            case "1":
                name = "交易积分";
                break;
            case "2":
                name = "活动积分";
                break;
            case "3":
                name = "任务积分";
                break;
            case "4":
                name = "签到积分";
                break;
            default:
                name = "其他积分";
                break;
        }
        return name;
    }
}