Commit cd127be2 authored by yanzg's avatar yanzg

SQL层级处理的支持

parent fcc5778a
...@@ -11,9 +11,10 @@ public interface StringFormatHandle { ...@@ -11,9 +11,10 @@ public interface StringFormatHandle {
* 对模板进行格式化处理 * 对模板进行格式化处理
* *
* @param sb 返回得结果模板 * @param sb 返回得结果模板
* @param group 带{xxx}的全格式
* @param fieldFull 全格式 * @param fieldFull 全格式
* @param field 字段 * @param field 字段
* @param command 字段格式化 * @param command 字段格式化
*/ */
void addPos(StringBuilder sb, String fieldFull, String field, String command); void addPos(StringBuilder sb, String group, String fieldFull, String field, String command);
} }
...@@ -1060,22 +1060,16 @@ public class StringHelper { ...@@ -1060,22 +1060,16 @@ public class StringHelper {
*/ */
public static String getCodeString(String from, Object target) { public static String getCodeString(String from, Object target) {
return getFormat(from, StringHelper.EMPTY, new StringFormatHandle() { return getFormat(from, StringHelper.EMPTY, new StringFormatHandle() {
/**
* 对模板进行格式化处理
*
* @param sb 返回得结果模板
* @param fieldFull 全格式
* @param field 字段
* @param command 字段格式化
*/
@Override @Override
public void addPos(StringBuilder sb, String fieldFull, String field, String command) { public void addPos(StringBuilder sb, String gorup, String fieldFull, String field, String command) {
String value = StringHelper.getFirst(ObjectHelper.getString(target, field), EMPTY); String value = StringHelper.getFirst(ObjectHelper.getString(target, field), EMPTY);
sb.append(value); sb.append(value);
} }
}); });
} }
private static Pattern reg = Pattern.compile("\\{(.+?)\\}");
/** /**
* 进行字段格式化处理 * 进行字段格式化处理
* *
...@@ -1086,7 +1080,6 @@ public class StringHelper { ...@@ -1086,7 +1080,6 @@ public class StringHelper {
*/ */
public static String getFormat(String format, String defaultField, StringFormatHandle fieldFormatHandle) { public static String getFormat(String format, String defaultField, StringFormatHandle fieldFormatHandle) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Pattern reg = Pattern.compile("\\{(.+?)\\}");
Matcher matches = reg.matcher(format); Matcher matches = reg.matcher(format);
int start = 0; int start = 0;
while (matches.find()) { while (matches.find()) {
...@@ -1094,6 +1087,7 @@ public class StringHelper { ...@@ -1094,6 +1087,7 @@ public class StringHelper {
if (len > 0) { if (len > 0) {
sb.append(format.substring(start, matches.start())); sb.append(format.substring(start, matches.start()));
} }
String group = matches.group(0);
String fieldFull = matches.group(1); String fieldFull = matches.group(1);
if (fieldFull.startsWith("0") && !StringHelper.isEmpty(defaultField)) { if (fieldFull.startsWith("0") && !StringHelper.isEmpty(defaultField)) {
fieldFull = defaultField + fieldFull.substring(1); fieldFull = defaultField + fieldFull.substring(1);
...@@ -1104,7 +1098,7 @@ public class StringHelper { ...@@ -1104,7 +1098,7 @@ public class StringHelper {
if (fields.length > 1) { if (fields.length > 1) {
fieldFormat = fieldFull.substring(field.length() + 1); fieldFormat = fieldFull.substring(field.length() + 1);
} }
fieldFormatHandle.addPos(sb, fieldFull, field, fieldFormat); fieldFormatHandle.addPos(sb, group, fieldFull, field, fieldFormat);
start = matches.end(); start = matches.end();
} }
sb.append(format.substring(start)); sb.append(format.substring(start));
......
...@@ -586,11 +586,11 @@ public abstract class BaseDaoSql { ...@@ -586,11 +586,11 @@ public abstract class BaseDaoSql {
sql = StringHelper.getFormat(sql, StringHelper.EMPTY, new StringFormatHandle() { sql = StringHelper.getFormat(sql, StringHelper.EMPTY, new StringFormatHandle() {
@Override @Override
public void addPos(StringBuilder sb, String fieldFull, String field, String command) { public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) {
// 设置寻找到标签 // 设置寻找到标签
find[0] = true; find[0] = true;
// 寻找到的代码片段 不包含分括号 // 寻找到的代码片段 不包含分括号
String name = fieldFull; String name = group;
List<String> codes = codeMap.containsKey(name) ? codeMap.get(name) : new ArrayList<>(); List<String> codes = codeMap.containsKey(name) ? codeMap.get(name) : new ArrayList<>();
for (String code : codes) { for (String code : codes) {
sb.append(" "); sb.append(" ");
......
...@@ -88,7 +88,7 @@ public class PrinterHelper { ...@@ -88,7 +88,7 @@ public class PrinterHelper {
// 生成目标格式化字符串 // 生成目标格式化字符串
String format = StringHelper.getFormat(item.getFormat(), item.getName(), new StringFormatHandle() { String format = StringHelper.getFormat(item.getFormat(), item.getName(), new StringFormatHandle() {
@Override @Override
public void addPos(StringBuilder sb, String fieldFull, String field, String command) { public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) {
// 对现有的字段进行加密 // 对现有的字段进行加密
sb.append("{"); sb.append("{");
String fieldTo = field; String fieldTo = field;
...@@ -131,7 +131,7 @@ public class PrinterHelper { ...@@ -131,7 +131,7 @@ public class PrinterHelper {
String format, String defaultField) { String format, String defaultField) {
return StringHelper.getFormat(format, defaultField, new StringFormatHandle() { return StringHelper.getFormat(format, defaultField, new StringFormatHandle() {
@Override @Override
public void addPos(StringBuilder sb, String fieldFull, String field, String command) { public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) {
sb.append("{"); sb.append("{");
Object fieldValue = ObjectHelper.get(resultFrom, field); Object fieldValue = ObjectHelper.get(resultFrom, field);
String fieldTo = field; String fieldTo = field;
...@@ -155,7 +155,7 @@ public class PrinterHelper { ...@@ -155,7 +155,7 @@ public class PrinterHelper {
public static String getResult(Object resultFrom, String format) { public static String getResult(Object resultFrom, String format) {
return StringHelper.getFormat(format, StringHelper.EMPTY, new StringFormatHandle() { return StringHelper.getFormat(format, StringHelper.EMPTY, new StringFormatHandle() {
@Override @Override
public void addPos(StringBuilder sb, String fieldFull, String field, String command) { public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) {
Object fieldValue = ObjectHelper.get(resultFrom, field); Object fieldValue = ObjectHelper.get(resultFrom, field);
sb.append(fieldValue); sb.append(fieldValue);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment