use of com.jfinal.plugin.activerecord.generator.TableMeta in project jboot by yangfuhai.
the class CodeGenHelpler method excludeTables.
/**
* 排除指定的表,有些表不需要生成的
*
* @param list
* @param excludeTables
*/
public static void excludeTables(List<TableMeta> list, String excludeTables) {
if (StrUtil.isNotBlank(excludeTables)) {
List<TableMeta> newTableMetaList = new ArrayList<>();
Set<String> excludeTableSet = StrUtil.splitToSet(excludeTables.toLowerCase(), ",");
for (TableMeta tableMeta : list) {
if (excludeTableSet.contains(tableMeta.name.toLowerCase())) {
System.out.println("exclude table : " + tableMeta.name);
continue;
}
newTableMetaList.add(tableMeta);
}
list.clear();
list.addAll(newTableMetaList);
}
}
use of com.jfinal.plugin.activerecord.generator.TableMeta in project jboot by yangfuhai.
the class JbootServiceImplGenerator method generate.
public void generate(List<TableMeta> tableMetas) {
System.out.println("Generate Service Impl ...");
System.out.println("Service Impl Output Dir: " + outputDir);
Engine engine = Engine.create("forServiceImpl");
engine.setSourceFactory(new ClassPathSourceFactory());
engine.addSharedMethod(new StrKit());
engine.addSharedObject("getterTypeMap", getterTypeMap);
engine.addSharedObject("javaKeyword", JavaKeyword.me);
for (TableMeta tableMeta : tableMetas) {
genBaseModelContent(tableMeta);
}
writeToFile(tableMetas);
}
use of com.jfinal.plugin.activerecord.generator.TableMeta in project jboot by yangfuhai.
the class ApiJsonGenerator method genMockJson.
/**
* 生成 Mock Json 数据
*
* @param config
*/
public static void genMockJson(JsonGeneratorConfig config) {
Map<String, Map<String, Object>> root = new LinkedHashMap<>();
File file = new File(config.getJsonFilePathPathAbsolute());
// 如果文件存在,则先读取其配置,然后再修改
if (file.exists()) {
String oldJson = FileUtil.readString(file);
JSONObject rootJsonObject = JSONObject.parseObject(oldJson, Feature.OrderedField);
if (rootJsonObject != null && !rootJsonObject.isEmpty()) {
for (String classOrSimpleName : rootJsonObject.keySet()) {
root.put(classOrSimpleName, rootJsonObject.getJSONObject(classOrSimpleName));
}
}
}
MetaBuilder builder = CodeGenHelpler.createMetaBuilder(config.getDatasource(), config.getType(), false);
List<TableMeta> tableMetas = builder.build();
if (config.tableMetaFilter != null) {
tableMetas = tableMetas.stream().filter(config.tableMetaFilter).collect(Collectors.toList());
}
for (TableMeta tableMeta : tableMetas) {
Map<String, Object> classMockData = new LinkedHashMap<>();
for (ColumnMeta columnMeta : tableMeta.columnMetas) {
Object mockData = createMockData(columnMeta);
if (mockData != null && !"".equals(mockData)) {
classMockData.put(columnMeta.attrName, mockData);
}
}
if (!classMockData.isEmpty()) {
root.put(StrKit.firstCharToLowerCase(tableMeta.modelName), classMockData);
}
}
String jsonContent = JSONObject.toJSONString(root, true);
FileUtil.writeString(file, jsonContent);
System.out.println("Gen Remarks Json File ----->" + FileUtil.getCanonicalPath(file));
}
use of com.jfinal.plugin.activerecord.generator.TableMeta in project jboot by yangfuhai.
the class ApiJsonGenerator method genRemarksJson.
/**
* 生成 Model 的字段备注数据
*/
public static void genRemarksJson(JsonGeneratorConfig config) {
Map<String, Map<String, String>> root = new LinkedHashMap<>();
File file = new File(config.getJsonFilePathPathAbsolute());
// 如果文件存在,则先读取其配置,然后再修改
if (file.exists()) {
String oldJson = FileUtil.readString(file);
JSONObject rootJsonObject = JSONObject.parseObject(oldJson, Feature.OrderedField);
if (rootJsonObject != null && !rootJsonObject.isEmpty()) {
for (String classOrSimpleName : rootJsonObject.keySet()) {
Map<String, String> remarks = new LinkedHashMap<>();
JSONObject modelRemarks = rootJsonObject.getJSONObject(classOrSimpleName);
modelRemarks.forEach((k, v) -> remarks.put(k, String.valueOf(v)));
root.put(classOrSimpleName, remarks);
}
}
}
MetaBuilder builder = CodeGenHelpler.createMetaBuilder(config.getDatasource(), config.getType(), false);
List<TableMeta> tableMetas = builder.build();
if (config.tableMetaFilter != null) {
tableMetas = tableMetas.stream().filter(config.tableMetaFilter).collect(Collectors.toList());
}
for (TableMeta tableMeta : tableMetas) {
Map<String, String> modelRemarks = new LinkedHashMap<>();
for (ColumnMeta columnMeta : tableMeta.columnMetas) {
if (StrUtil.isNotBlank(columnMeta.remarks)) {
modelRemarks.put(columnMeta.attrName, columnMeta.remarks);
}
}
if (!modelRemarks.isEmpty()) {
root.put(StrKit.firstCharToLowerCase(tableMeta.modelName), modelRemarks);
}
}
String jsonContent = JSONObject.toJSONString(root, true);
FileUtil.writeString(file, jsonContent);
System.out.println("Gen Remarks Json File ----->" + FileUtil.getCanonicalPath(file));
}
use of com.jfinal.plugin.activerecord.generator.TableMeta in project jboot by yangfuhai.
the class JbootServiceInterfaceGenerator method generate.
@Override
public void generate(List<TableMeta> tableMetas) {
System.out.println("Generate base model ...");
System.out.println("Base Model Output Dir: " + baseModelOutputDir);
Engine engine = Engine.create("forService");
engine.setSourceFactory(new ClassPathSourceFactory());
engine.addSharedMethod(new StrKit());
engine.addSharedObject("getterTypeMap", getterTypeMap);
engine.addSharedObject("javaKeyword", javaKeyword);
for (TableMeta tableMeta : tableMetas) {
genBaseModelContent(tableMeta);
}
writeToFile(tableMetas);
}
Aggregations