|
@@ -3,6 +3,8 @@ package org.geek.szbay.assistant.code.generator;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URL;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
@@ -22,6 +24,12 @@ public class UpdateFtlMaker {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static String space(int tabNum) {
|
|
|
+ char a[] = new char[tabNum];
|
|
|
+ Arrays.fill(a, '\t');
|
|
|
+ return String.valueOf(a);
|
|
|
+ }
|
|
|
+
|
|
|
public static String parseList(String tableComment, String keyName, List<String> attrNames, List<String> colTypes,
|
|
|
List<String> colComments) {
|
|
|
updateAttrNames(attrNames);
|
|
@@ -36,13 +44,12 @@ public class UpdateFtlMaker {
|
|
|
}
|
|
|
StringBuilder sb1 = new StringBuilder();
|
|
|
StringBuilder sb2 = new StringBuilder();
|
|
|
- sb1.append(
|
|
|
- "\t\t\t\t\t\t\t\t\t<th><input type=\"button\" value=\"全选\" onclick=\"multiSelectCheck()\" /></th>\r\n");
|
|
|
- sb2.append("\t\t\t\t\t\t\t\t\t<td><input type=\"checkbox\" name=\"multiSelect\" value=\"${item." + keyName
|
|
|
+ sb1.append(space(9)).append("<th><input type=\"button\" value=\"全选\" onclick=\"multiSelectCheck()\" /></th>\r\n");
|
|
|
+ sb2.append(space(9)).append("<td><input type=\"checkbox\" name=\"multiSelect\" value=\"${item." + keyName
|
|
|
+ "}\" /></td>\r\n");
|
|
|
- sb1.append("\t\t\t\t\t\t\t\t\t<th>序号</th>\r\n");
|
|
|
+ sb1.append(space(9)).append("<th>序号</th>\r\n");
|
|
|
sb2.append(String.format(
|
|
|
- "\t\t\t\t\t\t\t\t\t<td>${item_index+1}<input type=\"hidden\" name=\"%s\" value=\"${item.%s}\" /></td>\r\n",
|
|
|
+ space(9) + "<td>${item_index+1}<input type=\"hidden\" name=\"%s\" value=\"${item.%s}\" /></td>\r\n",
|
|
|
keyName, keyName));
|
|
|
int size = attrNames.size();
|
|
|
for (int i = 0; i < size; i++) {
|
|
@@ -61,25 +68,41 @@ public class UpdateFtlMaker {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- sb1.append(String.format("\t\t\t\t\t\t\t\t\t<th>%s</th>\r\n", attrDescr));
|
|
|
+ sb1.append(String.format(space(9) + "<th>%s</th>\r\n", attrDescr));
|
|
|
if (attrType.contains("Date")) {
|
|
|
- sb2.append(String.format("\t\t\t\t\t\t\t\t\t<th>${(item.%s?string('yyyy-MM-dd HH:mm:ss'))!}</th>\r\n",
|
|
|
+ sb2.append(String.format(space(9) + "<th>${(item.%s?string('yyyy-MM-dd HH:mm:ss'))!}</th>\r\n",
|
|
|
attrName));
|
|
|
} else {
|
|
|
if (attrType.toLowerCase().contains("int")) {
|
|
|
sb2.append(String.format(
|
|
|
- "\t\t\t\t\t\t\t\t\t<td><#if globalDict['%s']?exists && globalDict['%s'][item.%s?c]?exists> ${globalDict['%s'][item.%s?c]!} <#else> ${item.%s!} </#if></td>\r\n",
|
|
|
- attrName, attrName, attrName, attrName, attrName, attrName));
|
|
|
+ space(9) + "<td>\r\n"
|
|
|
+ + space(10) + "<#if item.%s?? \r\n"
|
|
|
+ + space(12) + "&& globalDict['%s']?exists \r\n"
|
|
|
+ + space(12) + "&& globalDict['%s'][item.%s?c]?exists> \r\n"
|
|
|
+ + space(11) + "${globalDict['%s'][item.%s?c]!} \r\n"
|
|
|
+ + space(10) + "<#else> \r\n"
|
|
|
+ + space(11) + "${item.%s!} \r\n"
|
|
|
+ + space(10) + "</#if>\r\n"
|
|
|
+ + space(9) + "</td>\r\n",
|
|
|
+ attrName, attrName, attrName, attrName, attrName, attrName, attrName));
|
|
|
} else {
|
|
|
sb2.append(String.format(
|
|
|
- "\t\t\t\t\t\t\t\t\t<td><#if globalDict['%s']?exists && globalDict['%s'][item.%s]?exists> ${globalDict['%s'][item.%s]!} <#else> ${item.%s!} </#if></td>\r\n",
|
|
|
- attrName, attrName, attrName, attrName, attrName, attrName));
|
|
|
+ space(9) + "<td>\r\n"
|
|
|
+ + space(10) + "<#if item.%s?? \r\n"
|
|
|
+ + space(12) + "&& globalDict['%s']?exists \r\n"
|
|
|
+ + space(12) + "&& globalDict['%s'][item.%s]?exists> \r\n"
|
|
|
+ + space(11) + "${globalDict['%s'][item.%s]!} \r\n"
|
|
|
+ + space(10) + "<#else> \r\n"
|
|
|
+ + space(11) + "${item.%s!} \r\n"
|
|
|
+ + space(10) + "</#if>\r\n"
|
|
|
+ + space(9) + "</td>\r\n",
|
|
|
+ attrName, attrName, attrName, attrName, attrName, attrName, attrName));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- sb1.append("\t\t\t\t\t\t\t\t\t<th>操作</th>");
|
|
|
+ sb1.append(space(9) + "<th>操作</th>");
|
|
|
sb2.append(String.format(
|
|
|
- "\t\t\t\t\t\t\t\t\t<td><a href=\"###\" onclick=\"showModal('updatePage?%s=${item.%s}')\">编辑</a></td>",
|
|
|
+ space(9) + "<td><a href=\"###\" onclick=\"showModal('updatePage?%s=${item.%s}')\">编辑</a></td>",
|
|
|
keyName, keyName));
|
|
|
return String.format(fileContent, sb1.toString(), sb2.toString());
|
|
|
}
|
|
@@ -122,25 +145,31 @@ public class UpdateFtlMaker {
|
|
|
update ? String.format("${(ret.model.%s?string('yyyy-MM-dd HH:mm:ss'))!}", attrName) : ""));
|
|
|
} else {
|
|
|
sb.append(String.format(
|
|
|
- "\t\t\t<#if globalDict['%s']?exists> <select class=\"form-control\" name=\"%s\">\r\n",
|
|
|
+ "\t\t\t<#if globalDict['%s']?exists> \r\n"
|
|
|
+ + "\t\t\t\t<select class=\"form-control\" name=\"%s\">\r\n",
|
|
|
attrName, attrName));
|
|
|
|
|
|
- sb.append(String.format("\t\t\t\t<#list globalDict['%s']?keys as key>\r\n", attrName));
|
|
|
+ sb.append("\t\t\t\t\t<option value=\"\">请选择</option>\r\n");
|
|
|
+
|
|
|
+ sb.append(String.format("\t\t\t\t\t<#list globalDict['%s']?keys as key>\r\n", attrName));
|
|
|
|
|
|
if (attrType.toLowerCase().contains("int")) {
|
|
|
- sb.append(String.format("\t\t\t\t<option value=\"${key}\"%s>${globalDict['%s'][key]!}</option>\r\n",
|
|
|
- update ? (" ${(key==ret.model." + attrName + "?c)?string( 'selected=\"selected\"','')}") : "",
|
|
|
+ sb.append(String.format("\t\t\t\t\t<option value=\"${key}\"%s>${globalDict['%s'][key]!}</option>\r\n",
|
|
|
+ update ? (" ${(ret.model." + attrName + "?? && key==ret.model." + attrName + "?c)?string( 'selected=\"selected\"','')}") : "",
|
|
|
attrName));
|
|
|
} else {
|
|
|
- sb.append(String.format("\t\t\t\t<option value=\"${key}\"%s>${globalDict['%s'][key]!}</option>\r\n",
|
|
|
- update ? (" ${(key==ret.model." + attrName + ")?string( 'selected=\"selected\"','')}") : "",
|
|
|
+ sb.append(String.format("\t\t\t\t\t<option value=\"${key}\"%s>${globalDict['%s'][key]!}</option>\r\n",
|
|
|
+ update ? (" ${(ret.model." + attrName + "?? && key==ret.model." + attrName + ")?string( 'selected=\"selected\"','')}") : "",
|
|
|
attrName));
|
|
|
}
|
|
|
|
|
|
- sb.append("\t\t\t\t</#list>\r\n");
|
|
|
+ sb.append("\t\t\t\t\t</#list>\r\n");
|
|
|
|
|
|
sb.append(String.format(
|
|
|
- "\t\t\t</select> <#else /> <input type=\"text\" class=\"form-control\" name=\"%s\" value=\"%s\" /> </#if>\r\n",
|
|
|
+ "\t\t\t\t</select> \r\n"
|
|
|
+ + "\t\t\t<#else>\r\n"
|
|
|
+ + "\t\t\t\t<input type=\"text\" class=\"form-control\" name=\"%s\" value=\"%s\" />\r\n"
|
|
|
+ + "\t\t\t</#if>\r\n",
|
|
|
attrName, update ? "${ret.model." + attrName + "!}" : ""));
|
|
|
}
|
|
|
|