use of com.hxkj.system.service.CodeGeneratorService in project my_curd by qinyou.
the class SysGeneratorController method generate.
/**
* 生成代码 文件
*/
public void generate() {
Ret ret = Ret.create();
String jsonStr = getPara("jsonStr");
if (StrKit.isBlank(jsonStr)) {
ret.setFail();
ret.set("msg", "jsonStr参数不能为空");
renderJson(ret);
return;
}
try {
JSONObject jsonObject = JSON.parseObject(jsonStr, JSONObject.class);
String moduleName = jsonObject.getString("moduleName");
if (moduleName.contains(":)")) {
ret.setFail();
ret.set("msg", "jsonStr 中 moduleName 不合法");
renderJson(ret);
return;
}
JSONArray jsonArray = jsonObject.getJSONArray("tables");
Iterator<Object> it = jsonArray.iterator();
List<Table> tables = new ArrayList<Table>();
while (it.hasNext()) {
JSONObject jsonObjectTemp = (JSONObject) it.next();
Table table = jsonObjectTemp.toJavaObject(Table.class);
tables.add(table);
}
CodeGeneratorService codeGeneratorService = new CodeGeneratorService();
List<String> outputPaths = codeGeneratorService.generate(moduleName, tables);
ret.setOk();
ret.put("outputPaths", outputPaths);
renderJson(ret);
} catch (Exception e) {
LogKit.error(e.getMessage());
ret.setFail();
ret.set("msg", "系统发生异常。");
renderJson(ret);
}
}
Aggregations