Quellcode durchsuchen

加入 流程页面代码生成器 GeneratorRelationShipStart

wuxw vor 6 Jahren
Ursprung
Commit
514c18649d

+ 1 - 1
WebService/src/main/resources/components/pageFramePackage/copyright/copyright.html

@@ -3,6 +3,6 @@
         <strong>{{copyrightInfo.otherInfo}}</strong>
     </div>
     <div>
-        <strong>Copyright</strong> {{copyrightInfo.company}} &copy; {{copyrightInfo.date}}
+        <strong>Copyright</strong> {{copyrightInfo.company}} &copy; {{copyrightInfo.date}} | {{copyrightInfo.openSource}}
     </div>
 </div>

+ 2 - 1
WebService/src/main/resources/components/pageFramePackage/copyright/copyright.js

@@ -8,7 +8,8 @@
            copyrightInfo:{
                 otherInfo:'HC小区管理系统',
                 company:'java110官方团队',
-                date:'2017-2019'
+                date:'2017-2019',
+                openSource:'代码 https://github.com/java110/MicroCommunity'
            }
        }
     });

+ 11 - 1
WebService/src/main/resources/static/css/common.css

@@ -48,4 +48,14 @@
     background: #fff;
     color: #888;
     cursor: default;
-}
+}
+
+
+.wizard > .steps > ul > li {
+    width: 33.33%;
+}
+
+.java110_step{
+    width:80%;
+    margin: 20px auto 50px auto;
+}

+ 10 - 0
java110-code-generator/src/main/java/com/java110/code/BaseGenerator.java

@@ -68,6 +68,16 @@ public class BaseGenerator {
         }
     }
 
+    protected String replaceBindingTemplateContext(String srcStr, JSONObject data){
+        return srcStr.replace("@@templateName@@", data.getString("templateName"))
+                .replace("@@templateCode@@", data.getString("templateCode"))
+                .replace("@@TemplateCode@@", toUpperCaseFirstOne(data.getString("templateCode")))
+                .replace("@@templateKey@@", data.getString("templateKey"))
+                .replace("@@TemplateKey@@", toUpperCaseFirstOne(data.getString("templateKey")))
+                .replace("@@templateKeyName@@", data.getString("templateKeyName"))
+                .replace("@@TEMPLATECODE@@", data.getString("templateCode").toUpperCase());
+    }
+
     protected String replaceTemplateContext(String srcStr, JSONObject data){
         return srcStr.replace("@@templateName@@", data.getString("templateName"))
                 .replace("@@templateCode@@", data.getString("templateCode"))

+ 242 - 0
java110-code-generator/src/main/java/com/java110/code/relationship/GeneratorBindingComponent.java

@@ -0,0 +1,242 @@
+package com.java110.code.relationship;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.code.BaseGenerator;
+import com.java110.code.web.GeneratorStart;
+import org.springframework.util.StringUtils;
+
+public class GeneratorBindingComponent extends BaseGenerator {
+
+    public void generator(JSONObject data) {
+
+        //处理组件
+        generatorComponentHtml(data);
+        generatorComponentJs(data);
+       /* generatorComponentJava(data);
+        genneratorIListSmo(data);
+        genneratorListSmoImpl(data);
+        genneratorListListener(data);
+
+        genneratorServiceCodeConstant(data);*/
+
+
+    }
+
+    /**
+     * 生成常量类
+     *
+     * @param data
+     */
+    private void genneratorServiceCodeConstant(JSONObject data) {
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/web/constant/ServiceCodeConstant.java").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceTemplateContext(fileContext, data);
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/web/constant/" + data.getString("templateCode") + "/ServiceCode" + toUpperCaseFirstOne(data.getString("templateCode")) + "Constant.java";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+
+    }
+
+    /**
+     * 生成 html js java 类
+     *
+     * @param data
+     */
+    private void generatorComponentHtml(JSONObject data) {
+
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/relationship/binding/binding.html").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceBindingTemplateContext(fileContext, data);
+
+        //  @@allStep@@
+
+        StringBuffer allStep = new StringBuffer();
+
+        JSONArray flows = data.getJSONArray("flows");
+        for (int flowIndex = 0; flowIndex < flows.size(); flowIndex++) {
+            JSONObject flow = flows.getJSONObject(flowIndex);
+            String showAffirmPage = data.getBoolean("needAffirm") ? " || " + data.getString("templateCode") + "Info.index == " + flows.size() : "";
+            allStep.append("<div v-if=\"" + data.getString("templateCode") + "Info.index == " + flowIndex + showAffirmPage + "\">\n" +
+                    "        <vc:create name=\"" + flow.getString("vcName") + "\"\n" +
+                    "                   callBackListener=\"" + data.getString("templateCode") + "\"\n" +
+                    "                   callBackFunction=\"notify\"\n" +
+                    "        ></vc:create>\n" +
+                    "    </div>\n");
+
+        }
+
+        int stepLastIndex = data.getBoolean("needAffirm") ? flows.size() : flows.size() - 1;
+        fileContext = fileContext.replace(" @@allStep@@", allStep.toString())
+                .replace("@@stepLastIndex@@", stepLastIndex + "");
+
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/relationship/component/" + data.getString("package") + "/" + data.getString("templateCode") + "/" + data.getString("templateCode") + ".html";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+
+
+    }
+
+    /**
+     * 生成 html js java 类
+     *
+     * @param data
+     */
+    private void generatorComponentJs(JSONObject data) {
+
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/relationship/binding/binding.js").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceBindingTemplateContext(fileContext, data);
+
+        //替换 变量@@templateCodeColumns@@
+        JSONArray columns = data.getJSONArray("columns");
+
+        StringBuffer variable = new StringBuffer();
+        String defaultValue = "";
+
+        StringBuffer validateInfo = new StringBuffer();
+        StringBuffer allStep = new StringBuffer("[");
+        JSONArray flows = data.getJSONArray("flows");
+        for (int flowIndex = 0; flowIndex < flows.size(); flowIndex++) {
+            JSONObject flow = flows.getJSONObject(flowIndex);
+            allStep.append("\"" + flow.getString("cnCode") + "\"");
+            if (flowIndex < flows.size() - 1) {
+                allStep.append(",");
+            }
+
+
+            validateInfo.append("vc.emit('" + flow.getString("vcName") + "', 'onIndex', vc.component.serviceBindingInfo.index);\n");
+
+        }
+        String showAffirmPage = data.getBoolean("needAffirm") ? "确认信息" : "";
+        allStep.append(showAffirmPage);
+        allStep.append("]");
+        fileContext = fileContext.replace("@@stepTitle@@", allStep.toString());
+        fileContext = fileContext.replace("@@notifyOnIndex@@", validateInfo.toString());
+        fileContext = fileContext.replace("@@jumpUrl@@", data.getString("successUrl"));
+
+        // 替换 数据校验部分代码
+
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/relationship/component/" + data.getString("package") + "/" + data.getString("templateCode") + "/" + data.getString("templateCode") + ".js";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+
+
+    }
+
+    /**
+     * 生成 html js java 类
+     *
+     * @param data
+     */
+    private void generatorComponentJava(JSONObject data) {
+
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/web/add/AddComponent.java").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceTemplateContext(fileContext, data);
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/web/component/java/" + data.getString("templateCode") + "/Add" + toUpperCaseFirstOne(data.getString("templateCode")) + "Component.java";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+
+
+    }
+
+    /**
+     * 生成接口类
+     *
+     * @param data
+     */
+    private void genneratorIListSmo(JSONObject data) {
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/web/add/IAddSMO.java").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceTemplateContext(fileContext, data);
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/web/smo/" + data.getString("templateCode") + "/IAdd" + toUpperCaseFirstOne(data.getString("templateCode")) + "SMO.java";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+    }
+
+    /**
+     * 生成接口类
+     *
+     * @param data
+     */
+    private void genneratorListSmoImpl(JSONObject data) {
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/web/add/AddSMOImpl.java").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceTemplateContext(fileContext, data);
+
+        //替换校验部分代码 @@validateTemplateColumns@@
+        JSONArray columns = data.getJSONArray("columns");
+        StringBuffer validateStr = new StringBuffer();
+        for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
+            JSONObject column = columns.getJSONObject(columnIndex);
+            if (column.getBoolean("required")) {
+                validateStr.append("Assert.hasKeyAndValue(paramIn, \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
+            }
+        }
+
+        fileContext = fileContext.replace("@@validateTemplateColumns@@", validateStr.toString());
+
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/web/smo/" + data.getString("templateCode") + "/impl/Add" + toUpperCaseFirstOne(data.getString("templateCode")) + "SMOImpl.java";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+    }
+
+    /**
+     * 生成API 侦听处理类
+     *
+     * @param data
+     */
+    private void genneratorListListener(JSONObject data) {
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/web/add/SaveListener.java").getFile());
+        String fileContext = sb.toString();
+
+        fileContext = super.replaceTemplateContext(fileContext, data);
+
+        //替换校验部分代码 @@validateTemplateColumns@@
+        JSONArray columns = data.getJSONArray("columns");
+        StringBuffer validateStr = new StringBuffer();
+        for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
+            JSONObject column = columns.getJSONObject(columnIndex);
+            if (column.getBoolean("required")) {
+                validateStr.append("Assert.hasKeyAndValue(reqJson, \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
+            }
+        }
+
+        fileContext = fileContext.replace("@@validateTemplateColumns@@", validateStr.toString());
+
+
+        String writePath = this.getClass().getResource("/").getPath()
+                + "out/api/listener/" + data.getString("templateCode") + "/Save" + toUpperCaseFirstOne(data.getString("templateCode")) + "Listener.java";
+        System.out.printf("writePath: " + writePath);
+        writeFile(writePath,
+                fileContext);
+    }
+
+
+}

+ 8 - 0
java110-code-generator/src/main/java/com/java110/code/relationship/GeneratorRelationShipStart.java

@@ -1,6 +1,8 @@
 package com.java110.code.relationship;
 
+import com.alibaba.fastjson.JSONObject;
 import com.java110.code.BaseGenerator;
+import com.java110.code.web.GeneratorStart;
 
 /**
  * @ClassName GeneratorRelationShipStart
@@ -14,5 +16,11 @@ public class GeneratorRelationShipStart extends BaseGenerator {
 
     public static void main(String[] args) {
 
+        StringBuffer sb = readFile(GeneratorStart.class.getResource("/relationship/template_1.json").getFile());
+
+        JSONObject data = JSONObject.parseObject(sb.toString());
+
+        GeneratorBindingComponent generatorBindingComponent = new GeneratorBindingComponent();
+        generatorBindingComponent.generator(data);
     }
 }

+ 20 - 0
java110-code-generator/src/main/resources/relationship/binding/binding.html

@@ -0,0 +1,20 @@
+<div id="component" >
+
+    <div class="java110_step">
+        <div id="step" ></div>
+    </div>
+
+    <!-- 选择 应用信息 -->
+    @@allStep@@
+
+
+    <div class="row">
+        <div class="col-md-10"></div>
+        <div class="col-md-2 " style="margin-bottom:10px; text-align:right">
+            <button type="button" class="btn btn-secondary" v-on:click="_prevStep()">上一步</button>
+            <button v-if="@@templateCode@@Info.index != @@stepLastIndex@@" type="button" class="btn btn-primary" style="margin-left:10px;" v-on:click="_nextStep()">下一步</button>
+            <button v-if="@@templateCode@@Info.index == @@stepLastIndex@@" type="button" class="btn btn-primary" style="margin-left:10px;" v-on:click="_finishStep()">完成</button>
+        </div>
+    </div>
+
+</div>

+ 80 - 0
java110-code-generator/src/main/resources/relationship/binding/binding.js

@@ -0,0 +1,80 @@
+/**
+    入驻小区
+**/
+(function(vc){
+    vc.extends({
+        data:{
+            @@templateCode@@Info:{
+                $step:{},
+                index:0,
+                infos:[]
+            }
+        },
+        _initMethod:function(){
+            vc.component._initStep();
+        },
+        _initEvent:function(){
+            vc.on("@@templateCode@@", "notify", function(_info){
+                vc.component.@@templateCode@@Info.infos[vc.component.@@templateCode@@Info.index] = _info;
+            });
+
+        },
+        methods:{
+            _initStep:function(){
+                vc.component.@@templateCode@@Info.$step = $("#step");
+                vc.component.@@templateCode@@Info.$step.step({
+                    index: 0,
+                    time: 500,
+                    title: @@stepTitle@@
+                });
+                vc.component.@@templateCode@@Info.index = vc.component.@@templateCode@@Info.$step.getIndex();
+            },
+            _prevStep:function(){
+                vc.component.@@templateCode@@Info.$step.prevStep();
+                vc.component.@@templateCode@@Info.index = vc.component.@@templateCode@@Info.$step.getIndex();
+
+                @@notifyOnIndex@@
+            },
+            _nextStep:function(){
+                var _currentData = vc.component.@@templateCode@@Info.infos[vc.component.@@templateCode@@Info.index];
+                if( _currentData == null || _currentData == undefined){
+                    vc.message("请选择相关信息");
+                    return ;
+                }
+                vc.component.@@templateCode@@Info.$step.nextStep();
+                vc.component.@@templateCode@@Info.index = vc.component.@@templateCode@@Info.$step.getIndex();
+
+                 @@notifyOnIndex@@
+            },
+            _finishStep:function(){
+
+                var param = {
+                    data:vc.component.@@templateCode@@Info.infos
+                }
+
+               vc.http.post(
+                   '@@templateCode@@',
+                   'binding',
+                   JSON.stringify(param),
+                   {
+                       emulateJSON:true
+                    },
+                    function(json,res){
+                       if(res.status == 200){
+
+                           vc.message('处理成功',true);
+                           //关闭model
+                           vc.jumpToPage("@@jumpUrl@@?" + vc.objToGetParam(JSON.parse(json)));
+                           return ;
+                       }
+                       vc.message(json);
+                    },
+                    function(errInfo,error){
+                       console.log('请求失败处理');
+
+                       vc.message(errInfo);
+                    });
+            }
+        }
+    });
+})(window.vc);

+ 9 - 6
java110-code-generator/src/main/resources/relationship/template_1.json

@@ -1,8 +1,11 @@
 {
-  "templateName":"服务",
-  "templateCode":"service",
-  "templateKey":"serviceId",
-  "templateKeyName":"服务ID",
+  "templateName":"添加房屋",
+  "templateCode":"addRoomBinding",
+  "templateKey":"roomId",
+  "templateKeyName":"房屋ID",
+  "package": "roomPackage",
+  "successUrl": "/",
+  "needAffirm": false,
   "flows":[
     {
       "index": 0,
@@ -12,14 +15,14 @@
       "existsComponent": true
     },
     {
-      "index": 0,
+      "index": 1,
       "code":"unit",
       "cnCode":"选择单元",
       "vcName":"viewUnitInfo",
       "existsComponent": true
     },
     {
-      "index": 0,
+      "index": 2,
       "code":"room",
       "cnCode":"添加房屋",
       "vcName":"addRoomView",