logger.error("模板设置失败");
}
Map<String,ERTable> map = findAllTable(project);
//生成所有Entity
for(ERTable erTable:map.values()) {
SourceTable sourceTable = new SourceTable(project,erTable);
if(sourceTable.getPhysicalNames().contains("id")) {
// 定义模板变量
Map<String, Object> model = Maps.newHashMap();
TreeSet<String> importList = Sets.newTreeSet();
for(SourceColumn sourceColumn:sourceTable.getSourceColumnList()) {
//计算需要import的项目
if(Collections3.isEmpty(sourceColumn.getNormalColumn().getRelationList())){
String importName = sourceColumn.getImportName();
if(StringUtils.isNotBlank(importName)) {
importList.add(importName);
}
}
if(!Collections3.isEmpty(sourceColumn.getSourceRelationList())) {
for(SourceRelation sourceRelation:sourceColumn.getSourceRelationList()) {
importList.addAll(sourceRelation.getImportList(project));
}
}
}
importList.addAll(SourceUtils.getImportList(SourceUtils.SOURCE_TYPE_ENTITY));
model.put("sourceTable", sourceTable);
model.put("importList", importList);
// 生成 Entity
Template template=null;
try {
template = cfg.getTemplate("entity.ftl");
} catch (IOException e) {
logger.error("获取模板出错");
}
String content = FreeMarkers.renderTemplate(template, model);
String filePath = generateRootPath+"\\src\\main\\java\\"+ project.getRootPackage().replace(".", "\\") + "\\modules\\" + sourceTable.getModuleName() + "\\entity\\"+ sourceTable.getEntityClassName() +".java";
FileUtils.writeFile(content, filePath);
}
}
//生成所有Dao
for(ERTable erTable:map.values()) {
SourceTable sourceTable = new SourceTable(project,erTable);
if(sourceTable.getPhysicalNames().contains("id")) {
// 定义模板变量
Map<String, Object> model = Maps.newHashMap();
TreeSet<String> importList = Sets.newTreeSet();
model.put("sourceTable", sourceTable);
model.put("importList", importList);
importList.add(sourceTable.getEntityPackage() + "." + sourceTable.getEntityClassName());
importList.addAll(SourceUtils.getImportList(SourceUtils.SOURCE_TYPE_DAO));
// 生成 Entity
Template template=null;
try {
template = cfg.getTemplate("dao.ftl");
} catch (IOException e) {
logger.error("获取模板出错");
}
String content = FreeMarkers.renderTemplate(template, model);
String filePath = generateRootPath+"\\src\\main\\java\\"+ project.getRootPackage().replace(".", "\\") + "\\modules\\" + sourceTable.getModuleName() + "\\dao\\"+ sourceTable.getDaoClassName() +".java";
FileUtils.writeFile(content, filePath);
}
}
FileUtils.zipFiles(generateRootPath, "", zipPath);