package com.cool.bang.modules.generate.domain.po;

import org.apache.commons.lang3.StringUtils;

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

/**
 * database table column info
 *
 * @author PeiZhi Guo
 * 2021-4-12 16:30
 */
public class TableColumnInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;

    /** 数据库表 */
    private Long tableId;

    /** 列名称 */
    private String columnName;

    /** 列注释 */
    private String columnComment;

    /** 列类型 */
    private String columnType;

    /** java类型 */
    private String javaType;

    /** java字段名 */
    private String javaField;

    /** jdbc类型 */
    private String jdbcType;

    /** 是否主键 */
    private Integer isPk;

    /** 是否自增 1是 0否 */
    private Integer isIncrement;

    /** 是否必填 1是 0否 */
    private Integer isRequired;

    /** 是否为插入字段 */
    private Integer isInsert;

    /** 是否编辑字段 */
    private Integer isEdit;

    /** 是否列表字段 */
    private Integer isList;

    /** 是否查询字段*/
    private Integer isQuery;

    /**
     * 查询方式
     * EQ 等于、NE 不等于、GT 大于、LT 小于、LIKE 模糊、BETWEEN 范围;
     */
    private String queryType;

    /**
     * 显示类型
     * input 文本框、textarea 文本域、select 下拉框、checkbox 复选框、radio 单选框、datetime 日期控件、upload 上传控件;
     */
    private String htmlType;

    /** 字典类型 */
    private String dictType;

    /** 排序 */
    private Integer sort;

    /** 创建时间 */
    private Date createTime;

    /** 创建人 */
    private Long createBy;

    /** 更新时间 */
    private Date updateTime;

    /** 更新人 */
    private Long updateBy;

    public boolean isSuperColumn() {
        return isSuperColumn(this.javaField);
    }

    public static boolean isSuperColumn(String javaField) {
        return StringUtils.equalsAnyIgnoreCase(javaField,
                // BaseEntity
                "createBy", "createTime", "updateBy", "updateTime", "remark",
                // TreeEntity
                "parentName", "parentId", "orderNum", "ancestors");
    }

    public void nullConversionZero() {
        if (null == this.isPk) {
            this.isPk = 0;
        }
        if (null == this.isIncrement) {
            this.isIncrement = 0;
        }
        if (null == this.isRequired) {
            this.isRequired = 0;
        }
        if (null == this.isInsert) {
            this.isInsert = 0;
        }
        if (null == this.isEdit) {
            this.isEdit = 0;
        }
        if (null == this.isList) {
            this.isList = 0;
        }
        if (null == this.isQuery) {
            this.isQuery = 0;
        }
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Long getTableId() {
        return tableId;
    }

    public void setTableId(Long tableId) {
        this.tableId = tableId;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getColumnComment() {
        return columnComment;
    }

    public void setColumnComment(String columnComment) {
        this.columnComment = columnComment;
    }

    public String getColumnType() {
        return columnType;
    }

    public void setColumnType(String columnType) {
        this.columnType = columnType;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getJavaField() {
        return javaField;
    }

    public void setJavaField(String javaField) {
        this.javaField = javaField;
    }

    public String getJdbcType() {
        return jdbcType;
    }

    public void setJdbcType(String jdbcType) {
        this.jdbcType = jdbcType;
    }

    public Integer getIsPk() {
        return isPk;
    }

    public void setIsPk(Integer isPk) {
        this.isPk = isPk;
    }

    public Integer getIsIncrement() {
        return isIncrement;
    }

    public void setIsIncrement(Integer isIncrement) {
        this.isIncrement = isIncrement;
    }

    public Integer getIsRequired() {
        return isRequired;
    }

    public void setIsRequired(Integer isRequired) {
        this.isRequired = isRequired;
    }

    public Integer getIsInsert() {
        return isInsert;
    }

    public void setIsInsert(Integer isInsert) {
        this.isInsert = isInsert;
    }

    public Integer getIsEdit() {
        return isEdit;
    }

    public void setIsEdit(Integer isEdit) {
        this.isEdit = isEdit;
    }

    public Integer getIsList() {
        return isList;
    }

    public void setIsList(Integer isList) {
        this.isList = isList;
    }

    public Integer getIsQuery() {
        return isQuery;
    }

    public void setIsQuery(Integer isQuery) {
        this.isQuery = isQuery;
    }

    public String getQueryType() {
        return queryType;
    }

    public void setQueryType(String queryType) {
        this.queryType = queryType;
    }

    public String getHtmlType() {
        return htmlType;
    }

    public void setHtmlType(String htmlType) {
        this.htmlType = htmlType;
    }

    public String getDictType() {
        return dictType;
    }

    public void setDictType(String dictType) {
        this.dictType = dictType;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }
}
