package com.sysu.admin.support.system.organ;

import com.xiesx.fastboot.core.jpa.entity.JpaPlusEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.*;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.*;
import java.util.Date;

/**
 * @title Organ.java (generator)
 * @description 机构表
 * @author 谢思贤
 * @date 2020-04-25
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@FieldNameConstants(innerTypeName = "FIELDS")
@Table(name = "sys_organ")
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
@Where(clause = "is_del=0")
@SQLDelete(sql = "update sys_organ set is_del=1 where id = ?")
@SQLDeleteAll(sql = "update sys_organ set is_del=1 where id = ?")
public class Organ extends JpaPlusEntity<Organ> {

    private static final long serialVersionUID = 1L;

    public static final long defaultOrgan = 10216L;

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;



    @Column(name = "parent_id")
    private Long parentId;

    @ManyToOne(cascade= CascadeType.REFRESH)
    @JoinColumn(name = "parent_id",insertable = false,updatable = false)
    private Organ parent;

    /**
     * 是否是县市级单位
     */
    @Column(name = "is_bureau")
    private Integer isBureau;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(updatable = false, nullable = false)
    private Date createDate;

    /**
     * 创建人
     */
    @CreatedBy
    @Column(updatable = false, nullable = false)
    private Long createBy;

    /**
     * 修改时间
     */
    @LastModifiedDate
    @Column(nullable = false)
    private Date updateDate;

    /**
     * 修改人
     */
    @LastModifiedBy
    @Column(nullable = false)
    private Long updateBy;

    /**
     * 省
     */
    @Column
    private Long provinceId;

    @Column
    private String provinceName;

    /**
     * 市
     */
    @Column
    private Long cityId;

    @Column
    private String cityName;

    /**
     * 区
     */
    @Column
    private Long districtId;

    @Column
    private String districtName;

    /**
     * 公司
     */
    @Column
    private String company;


    /**
     * 联系人
     */
    @Column
    private String contacts;


    /**
     * 地址
     */
    @Column
    private String address;

    /**
     * 是否删用（0:正常、1:删除）
     */
    @Column
    private Integer isDel;


    // ==========================================


}
