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

shz.jdbc.generate.template.DefaultAddVoTemplate Maven / Gradle / Ivy

There is a newer version: 2024.0.1
Show newest version
package shz.jdbc.generate.template;

import shz.core.NullHelp;
import shz.core.ToSet;
import shz.core.orm.entity.TreeEntity;
import shz.jdbc.generate.FieldNames;
import shz.jdbc.generate.FileTemplate;
import shz.jdbc.model.Table;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class DefaultAddVoTemplate extends FileTemplate {
    @Override
    protected String path() {
        return "api/api-" + info.getModuleName();
    }

    @Override
    public String packageName() {
        return info.getBasePackage() + ".api." + info.getModuleName() + ".model.vo";
    }

    @Override
    public String className() {
        return "Add" + info.getTemplates().entityTemplate().className() + "Vo";
    }

    @Override
    protected List annotations() {
        List annotations = new LinkedList<>();

        annotations.add("@Getter");
        annotations.add("@Setter");
        annotations.add("@ToString");

        imports.add("import lombok.Getter;");
        imports.add("import lombok.Setter;");
        imports.add("import lombok.ToString;");

        return annotations;
    }

    @Override
    protected String classDescription() {
        return "public class " + className();
    }

    @Override
    protected List content() {
        List content = new LinkedList<>();

        Set excludedFieldNames = excludedFieldNames();

        info.getTable().getColumns().forEach(column -> {
            String fieldName = fieldName(column);
            if (excludedFieldNames.contains(fieldName)) return;

            if (NullHelp.nonBlank(column.getRemarks())) {
                content.add("    /**");
                content.add("     * " + column.getRemarks());
                content.add("     */");
            }

            String type = getType(column);

            if (column.getNullable() != 1 && column.getColumnDef() == null) {
                if ("String".equals(type)) {
                    content.add("    @NotBlank(message = \"" + column.getRemarks() + "不能为空\")");
                    imports.add(info.getImports().notBlankImport());
                } else {
                    content.add("    @NotNull(message = \"" + column.getRemarks() + "不能为空\")");
                    imports.add(info.getImports().notNullImport());
                }
            }

            content.add("    private " + type + " " + fieldName + ";");
        });

        return content;
    }

    protected Set excludedFieldNames() {
        FieldNames fieldNames = info.getFieldNames();
        Table table = info.getTable();
        Set set = ToSet.asSet(
                fieldNames.id(table),
                fieldNames.delFlag(table),
                fieldNames.version(table),
                fieldNames.createTime(table),
                fieldNames.updateTime(table),
                fieldNames.createBy(table),
                fieldNames.updateBy(table)
        );

        if (info.getSuperEntityClass() != null && TreeEntity.class.isAssignableFrom(info.getSuperEntityClass()))
            set.addAll(ToSet.asSet("rootId", "level", "tag"));
        return set;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy