吴学文
2019-07-30 33eec7baf940021f0bc21edfc52d60cd3ae83ce3
java110-code-generator/src/main/java/com/java110/code/relationship/GeneratorBindingComponent.java
@@ -372,20 +372,46 @@
        StringBuffer sb = readFile(GeneratorStart.class.getResource("/relationship/binding/BindingListener.java").getFile());
        String fileContext = sb.toString();
        fileContext = super.replaceTemplateContext(fileContext, data);
        fileContext = super.replaceBindingTemplateContext(fileContext, data);
        //替换校验部分代码 @@validateTemplateColumns@@
        JSONArray flows = data.getJSONArray("flows");
        StringBuffer validateStr = new StringBuffer();
        StringBuffer variableStr = new StringBuffer();
        StringBuffer ifCode = new StringBuffer();
        StringBuffer methodCode = new StringBuffer();
        for(int flowIndex = 0 ; flowIndex < flows.size() ; flowIndex ++) {
            JSONObject flowObj = flows.getJSONObject(flowIndex);
            String vcName = flowObj.getString("vcName");
            variableStr.append("JSONObject " + vcName + " = getObj(infos, \"" + vcName + "\");\n");
            ifCode.append("" +
                    "        if(!hasKey("+vcName+", \"" + flowObj.getString("flowKey") + "\")){\n" +
                    "             "+vcName+".put(\"" + flowObj.getString("flowKey") + "\", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_" + flowObj.getString("flowKey") + "));\n" +
                    "             businesses.add(add" + toUpperCaseFirstOne(flowObj.getString("businessName")) + "("+vcName+", context));\n" +
                    "        }\n");
            methodCode.append("private JSONObject add"+toUpperCaseFirstOne(flowObj.getString("businessName"))+"(JSONObject paramInJson, DataFlowContext dataFlowContext) {\n" +
                    "        JSONObject business = JSONObject.parseObject(\"{\\\"datas\\\":{}}\");\n" +
                    "        business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant."+flowObj.getString("businessType")+");\n" +
                    "        business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);\n" +
                    "        business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);\n" +
                    "        JSONObject businessObj = new JSONObject();\n" +
                    "        businessObj.putAll(paramInJson);\n" +
                    "        //计算 应收金额\n" +
                    "        business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put(\""+flowObj.getString("businessName")+"\", businessObj);\n" +
                    "        return business;\n" +
                    "    }\n");
            if(flowObj.containsKey("existsComponent") && flowObj.getBoolean("existsComponent")){
                continue;
            }
            String vcName = flowObj.getString("vcName");
            JSONObject vcObject = data.getJSONObject("components").getJSONObject(vcName);
@@ -400,10 +426,12 @@
        }
        fileContext = fileContext.replace("@@validateTemplateColumns@@", validateStr.toString());
        fileContext = fileContext.replace("@@doSoService@@", variableStr.toString() + ifCode.toString());
        fileContext = fileContext.replace("@@bindingMethod@@", methodCode.toString());
        String writePath = this.getClass().getResource("/").getPath()
                + "out/api/listener/" + data.getString("templateCode") + "/Save" + toUpperCaseFirstOne(data.getString("templateCode")) + "Listener.java";
                + "out/api/listener/" + data.getString("templateCode") + "/Binding" + toUpperCaseFirstOne(data.getString("templateCode")) + "Listener.java";
        System.out.printf("writePath: " + writePath);
        writeFile(writePath,
                fileContext);