forked from java110/MicroCommunity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
加入 流程页面代码生成器 GeneratorRelationShipStart
- Loading branch information
Showing
9 changed files
with
383 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
242 changes: 242 additions & 0 deletions
242
...code-generator/src/main/java/com/java110/code/relationship/GeneratorBindingComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
java110-code-generator/src/main/resources/relationship/binding/binding.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.