Skip to content

Commit

Permalink
l流程开发完成待测试
Browse files Browse the repository at this point in the history
  • Loading branch information
吴学文 authored and 吴学文 committed Jul 30, 2019
1 parent c503665 commit 33eec7b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void generator(JSONObject data) {

}

private void genneratorAddHtml(JSONObject data, String componentName){
private void genneratorAddHtml(JSONObject data, String componentName) {
StringBuffer sb = readFile(GeneratorStart.class.getResource("/relationship/add/add.html").getFile());
String fileContext = sb.toString();

Expand Down Expand Up @@ -61,22 +61,22 @@ private void genneratorAddHtml(JSONObject data, String componentName){

}

inputStr = "<select class=\"custom-select\" v-model=\"" + _currentObj.getString("templateCode") + "ViewInfo."+column.getString("code")+"\">\n" +
" <option selected disabled value=\"\">"+ required + ",请选择" + column.getString("cnCode") + "</option>\n" +
" " +option+
inputStr = "<select class=\"custom-select\" v-model=\"" + _currentObj.getString("templateCode") + "ViewInfo." + column.getString("code") + "\">\n" +
" <option selected disabled value=\"\">" + required + ",请选择" + column.getString("cnCode") + "</option>\n" +
" " + option +
" </select>";
} else if("textarea".equals(column.getString("inputType"))){
inputStr = "<textarea placeholder=\"" + required + ",请填写" + column.getString("cnCode") + "\" class=\"form-control\""+
" v-model=\"" + _currentObj.getString("templateCode") + "ViewInfo."+column.getString("code")+"\">"+
} else if ("textarea".equals(column.getString("inputType"))) {
inputStr = "<textarea placeholder=\"" + required + ",请填写" + column.getString("cnCode") + "\" class=\"form-control\"" +
" v-model=\"" + _currentObj.getString("templateCode") + "ViewInfo." + column.getString("code") + "\">" +
"</textarea>";
}else {
inputStr = " <input v-model=\"" + _currentObj.getString("templateCode") + "ViewInfo."+column.getString("code")+"\" " +
} else {
inputStr = " <input v-model=\"" + _currentObj.getString("templateCode") + "ViewInfo." + column.getString("code") + "\" " +
" type=\"text\" placeholder=\"" + required + ",请填写" + column.getString("cnCode") + "\" class=\"form-control\">\n";
}
thSb.append("<div class=\"form-group row\">\n" +
" <label class=\"col-sm-2 col-form-label\">" + column.getString("cnCode") + "</label>\n" +
" <div class=\"col-sm-10\">\n" +
inputStr+
inputStr +
" </div>\n" +
"</div>\n");

Expand All @@ -86,7 +86,7 @@ private void genneratorAddHtml(JSONObject data, String componentName){


String writePath = this.getClass().getResource("/").getPath()
+ "out/relationship/component/"+_currentObj.getString("package")+"/" + _currentObj.getString("templateCode") + "View/" + toUpperCaseFirstOne(_currentObj.getString("templateCode")) + "View.html";
+ "out/relationship/component/" + _currentObj.getString("package") + "/" + _currentObj.getString("templateCode") + "View/" + toUpperCaseFirstOne(_currentObj.getString("templateCode")) + "View.html";
System.out.printf("writePath: " + writePath);
writeFile(writePath,
fileContext);
Expand Down Expand Up @@ -122,33 +122,33 @@ private void generatorAddJs(JSONObject data, String componentName) {
defaultValue = "'" + defaultValue + "'";
variable.append(column.getString("code") + ":" + defaultValue + ",\n");

validateInfo += "'"+_currentObj.getString("templateCode")+"ViewInfo."+column.getString("code")+"':[\n" ;
if(column.getBoolean("required")) {
validateInfo +="{\n" +
validateInfo += "'" + _currentObj.getString("templateCode") + "ViewInfo." + column.getString("code") + "':[\n";
if (column.getBoolean("required")) {
validateInfo += "{\n" +
" limit:\"required\",\n" +
" param:\"\",\n" +
" errInfo:\""+column.getString("cnCode")+"不能为空\"\n" +
" errInfo:\"" + column.getString("cnCode") + "不能为空\"\n" +
" },\n";
}

if(column.containsKey("limit") && !StringUtils.isEmpty(column.getString("limit"))) {
validateInfo +=" {\n" +
" limit:\""+column.getString("limit")+"\",\n" +
" param:\""+column.getString("limitParam")+"\",\n" +
" errInfo:\""+column.getString("limitErrInfo")+"\"\n" +
if (column.containsKey("limit") && !StringUtils.isEmpty(column.getString("limit"))) {
validateInfo += " {\n" +
" limit:\"" + column.getString("limit") + "\",\n" +
" param:\"" + column.getString("limitParam") + "\",\n" +
" errInfo:\"" + column.getString("limitErrInfo") + "\"\n" +
" },\n" +
" ],\n";
}

}
fileContext = fileContext.replace("@@templateCodeColumns@@", variable.toString());
fileContext = fileContext.replace("@@templateCodeColumns@@", variable.toString());
fileContext = fileContext.replace("@@addTemplateCodeValidate@@", validateInfo);

// 替换 数据校验部分代码


String writePath = this.getClass().getResource("/").getPath()
+ "out/relationship/component/"+_currentObj.getString("package")+"/" + _currentObj.getString("templateCode") + "View/" + toUpperCaseFirstOne(_currentObj.getString("templateCode")) + "View.js";
+ "out/relationship/component/" + _currentObj.getString("package") + "/" + _currentObj.getString("templateCode") + "View/" + toUpperCaseFirstOne(_currentObj.getString("templateCode")) + "View.js";
System.out.printf("writePath: " + writePath);
writeFile(writePath,
fileContext);
Expand Down Expand Up @@ -202,7 +202,7 @@ private void generatorComponentHtml(JSONObject data) {
" ></vc:create>\n" +
" </div>\n");
//如果相应组件不存在,则根据组件配置自动生成
if(!flow.getBoolean("existsComponent")){
if (!flow.getBoolean("existsComponent")) {
genneratorAddHtml(data, flow.getString("vcName"));
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ private void generatorComponentJs(JSONObject data) {
validateInfo.append("vc.emit('" + flow.getString("vcName") + "', 'onIndex', vc.component.serviceBindingInfo.index);\n");

//如果相应组件不存在,则根据组件配置自动生成
if(!flow.getBoolean("existsComponent")){
if (!flow.getBoolean("existsComponent")) {
generatorAddJs(data, flow.getString("vcName"));
}

Expand Down Expand Up @@ -331,11 +331,11 @@ private void genneratorListSmoImpl(JSONObject data) {

JSONArray flows = data.getJSONArray("flows");
StringBuffer validateStr = new StringBuffer();
for(int flowIndex = 0 ; flowIndex < flows.size() ; flowIndex ++) {
for (int flowIndex = 0; flowIndex < flows.size(); flowIndex++) {

JSONObject flowObj = flows.getJSONObject(flowIndex);

if(flowObj.containsKey("existsComponent") && flowObj.getBoolean("existsComponent")){
if (flowObj.containsKey("existsComponent") && flowObj.getBoolean("existsComponent")) {
continue;
}

Expand All @@ -348,7 +348,7 @@ private void genneratorListSmoImpl(JSONObject data) {
for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
JSONObject column = columns.getJSONObject(columnIndex);
if (column.getBoolean("required")) {
validateStr.append("Assert.hasKeyByFlowData(infos, \""+ flowObj.getString("vcName") +"\", \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
validateStr.append("Assert.hasKeyByFlowData(infos, \"" + flowObj.getString("vcName") + "\", \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
}
}
}
Expand All @@ -372,20 +372,46 @@ private void genneratorListListener(JSONObject data) {
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();
for(int flowIndex = 0 ; flowIndex < flows.size() ; flowIndex ++) {
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);

if(flowObj.containsKey("existsComponent") && flowObj.getBoolean("existsComponent")){
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);

Expand All @@ -394,16 +420,18 @@ private void genneratorListListener(JSONObject data) {
for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
JSONObject column = columns.getJSONObject(columnIndex);
if (column.getBoolean("required")) {
validateStr.append("Assert.hasKeyByFlowData(infos, \""+ flowObj.getString("vcName") +"\", \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
validateStr.append("Assert.hasKeyByFlowData(infos, \"" + flowObj.getString("vcName") + "\", \"" + column.getString("code") + "\", \"" + column.getString("desc") + "\");\n");
}
}
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context,

@@doSoService@@

JSONObject appInfo = getObj(infos, "APP"); //应用信息
JSONObject serviceInfo = getObj(infos, "SERVICE"); // 服务信息

//处理 应用信息
if(!hasKey(appInfo, "appId")){
appInfo.put("appId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_appId));
businesses.add(addViewUnitInfo(reqJson, context));
}

JSONObject paramInObj = super.restToCenterProtocol(businesses, context.getRequestCurrentHeaders());

Expand Down Expand Up @@ -85,24 +77,7 @@ public int getOrder() {

@@bindingMethod@@

/**
* 添加小区信息
*
* @param paramInJson 接口调用放传入入参
* @param dataFlowContext 数据上下文
* @return 订单服务能够接受的报文
*/
private JSONObject addViewUnitInfo(JSONObject paramInJson, DataFlowContext dataFlowContext) {
JSONObject business = JSONObject.parseObject("{\"datas\":{}}");
business.put(CommonConstant.HTTP_BUSINESS_TYPE_CD, BusinessTypeConstant.BUSINESS_TYPE_BIND_@@TEMPLATECODE@@);
business.put(CommonConstant.HTTP_SEQ, DEFAULT_SEQ);
business.put(CommonConstant.HTTP_INVOKE_MODEL, CommonConstant.HTTP_INVOKE_MODEL_S);
JSONObject businessObj = new JSONObject();
businessObj.putAll(paramInJson);
//计算 应收金额
business.getJSONObject(CommonConstant.HTTP_BUSINESS_DATAS).put("businessRoom", businessObj);
return business;
}



private boolean hasKey(JSONObject info, String key){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"cnCode":"选择楼",
"vcName":"viewFloorInfo",
"businessName": "businessFloor",
"businessType": "BUSINESS_TYPE_SAVE_FLOOR_INFO",
"existsComponent": true
},
{
Expand All @@ -23,6 +24,7 @@
"cnCode":"选择单元",
"vcName":"viewUnitInfo",
"businessName": "businessUnit",
"businessType": "BUSINESS_TYPE_SAVE_UNIT_INFO",
"existsComponent": true
},
{
Expand All @@ -32,6 +34,7 @@
"cnCode":"添加房屋",
"vcName":"addRoomView",
"businessName": "businessRoom",
"businessType": "BUSINESS_TYPE_SAVE_ROOM_INFO",
"existsComponent": false
}
],
Expand Down

0 comments on commit 33eec7b

Please sign in to comment.