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

cn.mybatis.mp.generator.template.ServiceTemplateBuilder Maven / Gradle / Ivy

package cn.mybatis.mp.generator.template;

import cn.mybatis.mp.generator.config.GeneratorConfig;
import cn.mybatis.mp.generator.database.meta.EntityInfo;
import cn.mybatis.mp.generator.util.GeneratorUtil;
import cn.mybatis.mp.generator.util.PathUtils;

import java.io.File;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

public class ServiceTemplateBuilder extends AbstractTemplateBuilder {

    public ServiceTemplateBuilder(GeneratorConfig generatorConfig, EntityInfo entityInfo) {
        super(generatorConfig, entityInfo);
    }

    @Override
    public boolean enable() {
        return generatorConfig.getServiceConfig().isEnable();
    }

    @Override
    public String targetFilePath() {
        return PathUtils.buildFilePath(
                generatorConfig.getBaseFilePath(),
                generatorConfig.getJavaPath(),
                entityInfo.getServicePackage().replaceAll("\\.", File.separator),
                entityInfo.getServiceName())
                + ".java";
    }

    @Override
    public String templateFilePath() {
        return generatorConfig.getTemplateRootPath() + "/service";
    }

    @Override
    public Map contextData() {
        Map data = new HashMap<>();
        data.put("imports", GeneratorUtil.buildServiceImports(generatorConfig, entityInfo));
        if (generatorConfig.getServiceConfig().getSuperClass() != null) {
            int dotIndex = generatorConfig.getServiceConfig().getSuperClass().lastIndexOf(".");
            String superName;
            if (dotIndex > 0) {
                superName = generatorConfig.getServiceConfig().getSuperClass().substring(dotIndex + 1);
            } else {
                superName = generatorConfig.getServiceConfig().getSuperClass();
            }
            data.put("superExtend", " extends " + superName);
        } else {
            data.put("superExtend", "");
        }
        data.put("date", LocalDate.now().toString());
        data.put("author", generatorConfig.getAuthor());
        data.put("entityInfo", entityInfo);
        data.put("entityConfig", generatorConfig.getEntityConfig());
        data.put("mapperConfig", generatorConfig.getMapperConfig());
        data.put("daoConfig", generatorConfig.getDaoConfig());
        data.put("daoImplConfig", generatorConfig.getDaoImplConfig());
        data.put("serviceConfig", generatorConfig.getServiceConfig());
        data.put("serviceImplConfig", generatorConfig.getServiceImplConfig());
        data.put("generatorConfig", generatorConfig);
        data.put("containerType", generatorConfig.getContainerType());
        return data;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy