Search in sources :

Example 1 with CodeGeneratorService

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);
    }
}
Also used : Ret(com.jfinal.kit.Ret) Table(com.hxkj.common.util.code_generator.Table) JSONObject(com.alibaba.fastjson.JSONObject) CodeGeneratorService(com.hxkj.system.service.CodeGeneratorService) JSONArray(com.alibaba.fastjson.JSONArray) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Table (com.hxkj.common.util.code_generator.Table)1 CodeGeneratorService (com.hxkj.system.service.CodeGeneratorService)1 Ret (com.jfinal.kit.Ret)1 ArrayList (java.util.ArrayList)1