Skip to content

Commit

Permalink
加入 流程页面代码生成器 GeneratorRelationShipStart
Browse files Browse the repository at this point in the history
  • Loading branch information
928255095 committed Jul 29, 2019
1 parent ae725e6 commit 514c186
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
copyrightInfo:{
otherInfo:'HC小区管理系统',
company:'java110官方团队',
date:'2017-2019'
date:'2017-2019',
openSource:'代码 https://github.com/java110/MicroCommunity'
}
}
});
Expand Down
12 changes: 11 additions & 1 deletion WebService/src/main/resources/static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static void writeFile(String filePath,String fileName) {
}
}

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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}


}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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>
Loading

0 comments on commit 514c186

Please sign in to comment.