package com.qiuguo.iot.customer.http.api.mysql;



public class FieldBean {

    private String field;// 数据库字段名
    private String type;// 数据库字段烈性
    private String lenth;// 长度

    private String precision;//jingdu
    private String comment;// 注释

    private String javaCode;// java名
    private String javaType;// java类型
    private String javaTypeFull;// ...

    private String extra;//shi fou wei zi zheng shi jian shi mo renzhi

    private String columnKey;//shifouweizhujian
    private String columnDefault;//mo ren zhi
    private String isNullAble;


    public FieldBean(String field, String type, String comment, String extra, String columnKey,
                     String columnType, String columnDefault, String isNullAble) {
        this.field = field;
        this.type = type;
        //this.lenth = lenth;
        this.comment = comment;
        this.extra = extra;//
        this.columnKey = columnKey;
        this.isNullAble = isNullAble;
        int index = columnType.indexOf("(");
        if(index > 0){
            String v = columnType.substring(index + 1, columnType.indexOf(")"));
            index = v.indexOf(",");
            if(index > 0){
                this.lenth = v.substring(0, index);
                precision = v.substring(index + 1);
            }else{
                this.lenth = v;
            }

        }
        this.columnDefault = columnDefault;

        this.javaCode = MysqlUtil.field2JavaCode(this.field);
        this.javaTypeFull = MysqlUtil.type2JavaTypeFull(this.type);
        if(field.contains("_id") || field.startsWith("id")){
            this.javaTypeFull = "Long";
        }
        this.javaType = MysqlUtil.type2JavaType(this.type);
        if(field.contains("_id") || field.startsWith("id")){
            this.javaType = "Long";
        }

    }


    public String getJavaCodeForGet() {
        return "get" + javaCode.substring(0, 1).toUpperCase()
                + javaCode.substring(1);
    }

    public String getJavaCodeForSet() {
        return "set" + javaCode.substring(0, 1).toUpperCase()
                + javaCode.substring(1);
    }

    // --------------------------------------------------------------------

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getLenth() {
        return lenth;
    }

    public void setLenth(String lenth) {
        this.lenth = lenth;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getJavaCode() {
        return javaCode;
    }

    public void setJavaCode(String javaCode) {
        this.javaCode = javaCode;
    }

    public String getJavaType() {
        if (StringUtil.isEmpty(javaType)) {
            return "String";
        }
        return javaType;
    }

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

    public String getJavaTypeFull() {
        return javaTypeFull;
    }

    public void setJavaTypeFull(String javaTypeFull) {
        this.javaTypeFull = javaTypeFull;
    }

    public String getPrecision(){return precision;}
    public String getExtra(){return extra;}
    public String getColumnKey(){return columnKey;}
    public String getColumnDefault(){return columnDefault;}

    public String getIsNullAble(){return isNullAble;}

}
