package com.ff.weijinxiao.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ff.weijinxiao.util.jsonfilter.DateSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 账本
 */
@Data
@Entity
@Table(name = "tb_account_book")
public class AccountBook implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @Column(name = "photo", columnDefinition = "varchar(300) COMMENT '账本图片'")
    @ApiModelProperty(value = "账本图片")
    private String photo;

    @Column(name = "name", columnDefinition = "varchar(50) COMMENT '账本名称'")
    @ApiModelProperty(value = "账本名称")
    private String name;

    @Column(name = "is_public", columnDefinition = "int COMMENT '是否公开(0:不公开；1:公开)'")
    @ApiModelProperty(value = "是否公开(0:不公开；1:公开)")
    private Integer isPublic = 0;

/*    @Column(name = "is_default", columnDefinition = "int COMMENT '是否默认账本(0:否；1:是)'")
    @ApiModelProperty(value = "是否默认账本(0:否；1:是)")
    private Integer isDefault = 1;*/

    @ManyToMany
    @JoinTable(name = "tb_book_user_relation", joinColumns = {
            @JoinColumn(name = "book_id", referencedColumnName = "id")}, inverseJoinColumns = {
            @JoinColumn(name = "uid", referencedColumnName = "uid")})
    List<UserInfo> userInfos;

    //库存价格权限
    @Column(name = "auth_stock_price", columnDefinition = "int COMMENT '库存价格权限1~5(1:进货价，2:员工内部价，3=一级代理价，4=二级代理价，5=三级代理价)'")
    @ApiModelProperty(value = "库存价格权限1~5(1:进货价，2:员工内部价，3=一级代理价，4=二级代理价，5=三级代理价)")
    private Integer authStockPrice = 1;

    //订单浏览
    @Column(name = "auth_view_order", columnDefinition = "int COMMENT '订单浏览权限(1:自己订单；2:全部订单)'")
    @ApiModelProperty(value = "订单浏览权限1~2(1:自己订单；2:全部订单)")
    private Integer authViewOrder = 2;

    //供应商浏览
    @Column(name = "auth_supplier", columnDefinition = "int COMMENT '订单浏览权限(1:自己供应商；2:全部供应商)'")
    @ApiModelProperty(value = "订单浏览权限(1:自己供应商；2:全部供应商)")
    private Integer authSupplier = 2;

    //客户浏览
    @Column(name = "auth_customer", columnDefinition = "int COMMENT '订单浏览权限(1:自己客户；2:全部客户)'")
    @ApiModelProperty(value = "客户浏览权限(1:自己客户；2:全部客户)")
    private Integer authCustomer = 2;

    @Column(name = "uid")
    @ApiModelProperty(value = "用户登录ID")
    private String uid;

    @Transient
    @ApiModelProperty(value = "创建者姓名")
    private String userName;

    @Column(name = "create_time", columnDefinition = "datetime COMMENT '创建时间'")
    @ApiModelProperty(value = "创建时间")
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date createTime;

    @Column(name = "modify_time", columnDefinition = "datetime COMMENT '更新时间'")
    @ApiModelProperty(value = "更新时间")
    @org.hibernate.annotations.UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = DateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")//json序列化实体类处理
    private Date modifyTime;

    @Column(name = "onlyID")
    @ApiModelProperty(value = "onlyID")
    private String onlyID;

    @Column(name = "isDelete")
    @ApiModelProperty(value = "是否是删除状态(0:否；1:是)")
    private Integer isDelete = 0;
}
