All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zcj.util.coder.builder.BeanInfo Maven / Gradle / Ivy

package com.zcj.util.coder.builder;

import com.zcj.util.UtilClass;
import com.zcj.util.UtilConvert;
import com.zcj.util.UtilString;
import com.zcj.util.coder.CodeGenerateException;
import com.zcj.util.coder.visual.ClassesInfoDto;

import java.util.Arrays;
import java.util.List;

public class BeanInfo {

    // 包名
    private String packageName;

    // 模块名
    private String moduleName;

    // 类名
    private String classesSimpleName;

    // 项目名
    private String projectName;

    // 数据库名
    private String databaseName;

    // 默认表前缀
    private String defaultTablePrefix;

    // 默认表名
    private String defaultTableName;

    public static BeanInfo initByClassesInfoDto(final ClassesInfoDto classesInfoDto) {
        if (classesInfoDto == null) {
            throw new CodeGenerateException("classesInfoDto 不能为空");
        } else if (UtilString.isBlank(classesInfoDto.getPackageName())) {
            throw new CodeGenerateException("classesInfoDto 中包名不能为空");
        }
        List list = Arrays.asList(classesInfoDto.getPackageName().split("\\."));
        if (list.size() < 3) {
            throw new CodeGenerateException("包路径层级不足");
        }

        BeanInfo result = new BeanInfo();
        result.setPackageName(classesInfoDto.getPackageName().toLowerCase());
        result.setModuleName(classesInfoDto.getModuleName().toLowerCase());
        result.setClassesSimpleName(UtilString.firstUpper(classesInfoDto.getClassesSimpleName()));
        result.setDatabaseName(list.get(2).toLowerCase());
        result.setProjectName(list.get(2).toLowerCase());
        result.setDefaultTablePrefix("t_" + list.get(2).toLowerCase() + "_");
        result.setDefaultTableName("t_" + list.get(2).toLowerCase() + "_" + UtilClass.camelToUnderLine(classesInfoDto.getClassesSimpleName()));
        return result;
    }

    public static BeanInfo initByClass(String className) {
        if (UtilString.isBlank(className)) {
            throw new CodeGenerateException("实体类包路径错误");
        }
        List list = Arrays.asList(className.split("\\."));
        if (list.size() < 6) {
            throw new CodeGenerateException("实体类包路径层级不足");
        }

        BeanInfo result = new BeanInfo();
        result.setPackageName(UtilConvert.collection2String(list.subList(0, list.size() - 3), "."));
        result.setModuleName(list.get(list.size() - 2));
        result.setClassesSimpleName(list.get(list.size() - 1));
        result.setDatabaseName(list.get(2));
        result.setProjectName(list.get(2));
        result.setDefaultTablePrefix("t_" + list.get(2) + "_");
        result.setDefaultTableName("t_" + list.get(2) + "_" + UtilClass.camelToUnderLine(list.get(list.size() - 1)));
        return result;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getModuleName() {
        return moduleName;
    }

    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }

    public String getClassesSimpleName() {
        return classesSimpleName;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }

    public String getDefaultTableName() {
        return defaultTableName;
    }

    public void setDefaultTableName(String defaultTableName) {
        this.defaultTableName = defaultTableName;
    }

    public void setClassesSimpleName(String classesSimpleName) {
        this.classesSimpleName = classesSimpleName;
    }

    public String getDefaultTablePrefix() {
        return defaultTablePrefix;
    }

    public void setDefaultTablePrefix(String defaultTablePrefix) {
        this.defaultTablePrefix = defaultTablePrefix;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy