package com.yunfeiyun.agmp.generator.domain;

import javax.validation.constraints.NotBlank;

import com.yunfeiyun.agmp.common.annotation.Excel;
import com.yunfeiyun.agmp.common.core.domain.BaseEntity;
import com.yunfeiyun.agmp.common.utils.StringUtils;

/**
 * 代码生成业务字段表 gen_table_column
 * 
 * @author 杨晓辉
 */
public class GenTableColumn extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 编号 */
    private String cmnId;

    /** 归属表编号 */
    private String tblId;

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

    /** 列描述 */
    private String cmnComment;

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

    /** JAVA类型 */
    private String cmnJavatype;

    /** JAVA字段名 */
    @NotBlank(message = "Java属性不能为空")
    private String cmnJavafield;

    /** 是否主键（1是） */
    private String cmnIspk;

    /** 是否自增（1是） */
    private String cmnIsincrement;

    /** 是否必填（1是） */
    private String cmnIsrequired;

    /** 是否为插入字段（1是） */
    private String cmnIsinsert;

    /** 是否编辑字段（1是） */
    private String cmnIsedit;

    /** 是否列表字段（1是） */
    private String cmnIslist;

    /** 是否查询字段（1是） */
    private String cmnIsquery;

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

    /** 显示类型（input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件） */
    private String cmnHtmltype;

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

    /** 排序 */
    private Integer cmnSeq;


    /** 字段创建者 */
    @Excel(name = "字段创建者")
    private String cmnCreator;

    /** 字段创建时间 */
    @Excel(name = "字段创建时间")
    private String cmnCreateddate;

    /** 字段更新者 */
    @Excel(name = "字段更新者")
    private String cmnModifier;

    /** 字段更新时间 */
    @Excel(name = "字段更新时间")
    private String cmnModifieddate;

    /** 字段备注 */
    @Excel(name = "字段备注")
    private String cmnRemark;


    public void setColumnId(String cmnId)
    {
        this.cmnId = cmnId;
    }

    public String getColumnId()
    {
        return cmnId;
    }

    public void setTableId(String tblId)
    {
        this.tblId = tblId;
    }

    public String getTableId()
    {
        return tblId;
    }

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

    public String getColumnName()
    {
        return cmnName;
    }

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

    public String getColumnComment()
    {
        return cmnComment;
    }

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

    public String getColumnType()
    {
        return cmnType;
    }

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

    public String getJavaType()
    {
        return cmnJavatype;
    }

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

    public String getJavaField()
    {
        return cmnJavafield;
    }

    public String getCapJavaField()
    {
        return StringUtils.capitalize(cmnJavafield);
    }

    public void setIsPk(String cmnIspk)
    {
        this.cmnIspk = cmnIspk;
    }

    public String getIsPk()
    {
        return cmnIspk;
    }

    public boolean isPk()
    {
        return isPk(this.cmnIspk);
    }

    public boolean isPk(String cmnIspk)
    {
        return cmnIspk != null && StringUtils.equals("1", cmnIspk);
    }

    public String getIsIncrement()
    {
        return cmnIsincrement;
    }

    public void setIsIncrement(String cmnIsincrement)
    {
        this.cmnIsincrement = cmnIsincrement;
    }

    public boolean isIncrement()
    {
        return isIncrement(this.cmnIsincrement);
    }

    public boolean isIncrement(String isIncrement)
    {
        return isIncrement != null && StringUtils.equals("1", isIncrement);
    }

    public void setIsRequired(String cmnIsrequired)
    {
        this.cmnIsrequired = cmnIsrequired;
    }

    public String getIsRequired()
    {
        return cmnIsrequired;
    }

    public boolean isRequired()
    {
        return isRequired(this.cmnIsrequired);
    }

    public boolean isRequired(String cmnIsrequired)
    {
        return cmnIsrequired != null && StringUtils.equals("1", cmnIsrequired);
    }

    public void setIsInsert(String cmnIsinsert)
    {
        this.cmnIsinsert = cmnIsinsert;
    }

    public String getIsInsert()
    {
        return cmnIsinsert;
    }

    public boolean isInsert()
    {
        return isInsert(this.cmnIsinsert);
    }

    public boolean isInsert(String cmnIsinsert)
    {
        return cmnIsinsert != null && StringUtils.equals("1", cmnIsinsert);
    }

    public void setIsEdit(String cmnIsedit)
    {
        this.cmnIsedit = cmnIsedit;
    }

    public String getIsEdit()
    {
        return cmnIsedit;
    }

    public boolean isEdit()
    {
        return isInsert(this.cmnIsedit);
    }

    public boolean isEdit(String cmnIsedit)
    {
        return cmnIsedit != null && StringUtils.equals("1", cmnIsedit);
    }

    public void setIsList(String cmnIslist)
    {
        this.cmnIslist = cmnIslist;
    }

    public String getIsList()
    {
        return cmnIslist;
    }

    public boolean isList()
    {
        return isList(this.cmnIslist);
    }

    public boolean isList(String cmnIslist)
    {
        return cmnIslist != null && StringUtils.equals("1", cmnIslist);
    }

    public void setIsQuery(String cmnIsquery)
    {
        this.cmnIsquery = cmnIsquery;
    }

    public String getIsQuery()
    {
        return cmnIsquery;
    }

    public boolean isQuery()
    {
        return isQuery(this.cmnIsquery);
    }

    public boolean isQuery(String cmnIsquery)
    {
        return cmnIsquery != null && StringUtils.equals("1", cmnIsquery);
    }

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

    public String getQueryType()
    {
        return cmnQuerytype;
    }

    public String getHtmlType()
    {
        return cmnHtmltype;
    }

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

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

    public String getDictType()
    {
        return cmnDicttype;
    }

    public void setSeq(Integer cmnSeq)
    {
        this.cmnSeq = cmnSeq;
    }

    public Integer getSeq()
    {
        return cmnSeq;
    }

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

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

    public boolean isUsableColumn()
    {
        return isUsableColumn(cmnJavafield);
    }

    public static boolean isUsableColumn(String javaField)
    {
        // isSuperColumn()中的名单用于避免生成多余Domain属性，若某些属性在生成页面时需要用到不能忽略，则放在此处白名单
        return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
    }



    public String getCmnCreator()
    {
        return cmnCreator;
    }

    public void setCmnCreator(String cmnCreator)
    {
        this.cmnCreator = cmnCreator;
    }

    public String getCmnCreateddate()
    {
        return cmnCreateddate;
    }

    public void setCmnCreateddate(String cmnCreateddate)
    {
        this.cmnCreateddate = cmnCreateddate;
    }

    public String getCmnModifier()
    {
        return cmnModifier;
    }

    public void setCmnModifier(String cmnModifier)
    {
        this.cmnModifier = cmnModifier;
    }

    public String getCmnModifieddate()
    {
        return cmnModifieddate;
    }

    public void setCmnModifieddate(String cmnModifieddate)
    {
        this.cmnModifieddate = cmnModifieddate;
    }

    public String getCmnRemark()
    {
        return cmnRemark;
    }

    public void setCmnRemark(String cmnRemark)
    {
        this.cmnRemark = cmnRemark;
    }


    public String readConverterExp()
    {
        String remarks = StringUtils.substringBetween(this.cmnComment, "（", "）");
        StringBuffer sb = new StringBuffer();
        if (StringUtils.isNotEmpty(remarks))
        {
            for (String value : remarks.split(" "))
            {
                if (StringUtils.isNotEmpty(value))
                {
                    Object startStr = value.subSequence(0, 1);
                    String endStr = value.substring(1);
                    sb.append("").append(startStr).append("=").append(endStr).append(",");
                }
            }
            return sb.deleteCharAt(sb.length() - 1).toString();
        }
        else
        {
            return this.cmnComment;
        }
    }
}
