Commit 90538b7f authored by yanzg's avatar yanzg

修复bug

parent 9d206b9d
...@@ -3,7 +3,6 @@ package com.yanzuoguang.util; ...@@ -3,7 +3,6 @@ package com.yanzuoguang.util;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.helper.JsonHelper; import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringFormatHandle;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.printer.ConvertPlan; import com.yanzuoguang.util.printer.ConvertPlan;
import com.yanzuoguang.util.printer.format.FormatCenter; import com.yanzuoguang.util.printer.format.FormatCenter;
...@@ -25,25 +24,25 @@ public class PrinterHelper { ...@@ -25,25 +24,25 @@ public class PrinterHelper {
/** /**
* 将来源模板与数据转换为目标模板和数据 * 将来源模板与数据转换为目标模板和数据
* *
* @param pager 来源模板 * @param pager 来源模板
* @param datas 来源数据 * @param dataList 来源数据
* @return * @return 转换后的结果
*/ */
public static ConvertPlan convertArray(String pager, double left, double top, Object... datas) { public static ConvertPlan<MapRow> convertArray(String pager, double left, double top, Object... dataList) {
return convertList(pager, left, top, Arrays.asList(datas)); return convertList(pager, left, top, Arrays.asList(dataList));
} }
/** /**
* 将来源模板与数据转换为目标模板和数据 * 将来源模板与数据转换为目标模板和数据
* *
* @param pager 来源模板 * @param pager 来源模板
* @param datas 来源数据 * @param list 来源数据
* @return * @return 转换后的结果
*/ */
public static ConvertPlan convertList(String pager, double left, double top, List datas) { public static <T> ConvertPlan<MapRow> convertList(String pager, double left, double top, List<T> list) {
ConvertPlan from = new ConvertPlan(); ConvertPlan<T> from = new ConvertPlan<>();
from.setPager(pager); from.setPager(pager);
from.setDatas(datas); from.setDatas(list);
return convert(from, left, top); return convert(from, left, top);
} }
...@@ -53,11 +52,11 @@ public class PrinterHelper { ...@@ -53,11 +52,11 @@ public class PrinterHelper {
* @param from 来源计划 * @param from 来源计划
* @param left 左边距离 * @param left 左边距离
* @param top 右边距离 * @param top 右边距离
* @return * @return 打印结果
*/ */
public static ConvertPlan<MapRow> convert(ConvertPlan from, double left, double top) { public static ConvertPlan<MapRow> convert(ConvertPlan<?> from, double left, double top) {
// 设置生成结果 // 设置生成结果
ConvertPlan<MapRow> to = new ConvertPlan(); ConvertPlan<MapRow> to = new ConvertPlan<>();
// 判断是否为空 // 判断是否为空
if (StringHelper.isEmpty(from.getPager()) || from.getDatas() == null || from.getDatas().size() < 1) { if (StringHelper.isEmpty(from.getPager()) || from.getDatas() == null || from.getDatas().size() < 1) {
return to; return to;
...@@ -85,29 +84,26 @@ public class PrinterHelper { ...@@ -85,29 +84,26 @@ public class PrinterHelper {
item.setFormat("{0}"); item.setFormat("{0}");
} }
// 生成目标格式化字符串 // 生成目标格式化字符串
String format = StringHelper.getFormat(item.getFormat(), item.getName(), new StringFormatHandle() { String format = StringHelper.getFormat(item.getFormat(), item.getName(), (sb, group, fieldFull, field, command) -> {
@Override // 对现有的字段进行加密
public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) { sb.append("{");
// 对现有的字段进行加密 String fieldTo = field;
sb.append("{"); if (!StringHelper.isEmpty(command)) {
String fieldTo = field; fieldTo = StringHelper.md5(fieldFull);
if (!StringHelper.isEmpty(command)) { }
fieldTo = StringHelper.md5(fieldFull); sb.append(fieldTo);
} sb.append("}");
sb.append(fieldTo);
sb.append("}");
// 写入加密后的数目 // 写入加密后的数目
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Object rowFrom = from.getDatas().get(i); Object rowFrom = from.getDatas().get(i);
String fromValue = ObjectHelper.getString(rowFrom, field); String fromValue = ObjectHelper.getString(rowFrom, field);
String toValue = fromValue; String toValue = fromValue;
if (!StringHelper.isEmpty(command)) { if (!StringHelper.isEmpty(command)) {
toValue = FormatCenter.getFormatValue(command, fromValue); toValue = FormatCenter.getFormatValue(command, fromValue);
}
MapRow rowTo = to.getDatas().get(i);
rowTo.put(fieldTo, toValue);
} }
MapRow rowTo = to.getDatas().get(i);
rowTo.put(fieldTo, toValue);
} }
}); });
item.setFormat(format); item.setFormat(format);
...@@ -124,23 +120,20 @@ public class PrinterHelper { ...@@ -124,23 +120,20 @@ public class PrinterHelper {
* @param resultFrom 结果来源 * @param resultFrom 结果来源
* @param format 格式化 * @param format 格式化
* @param defaultField 默认字段 * @param defaultField 默认字段
* @return * @return 格式化后的字符串
*/ */
public static String getFormatTo(Map<String, Object> resultTo, Object resultFrom, public static String getFormatTo(Map<String, Object> resultTo, Object resultFrom,
String format, String defaultField) { String format, String defaultField) {
return StringHelper.getFormat(format, defaultField, new StringFormatHandle() { return StringHelper.getFormat(format, defaultField, (sb, group, fieldFull, field, command) -> {
@Override sb.append("{");
public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) { Object fieldValue = ObjectHelper.get(resultFrom, field);
sb.append("{"); String fieldTo = field;
Object fieldValue = ObjectHelper.get(resultFrom, field); if (!StringHelper.isEmpty(command)) {
String fieldTo = field; fieldTo = StringHelper.md5(fieldFull);
if (!StringHelper.isEmpty(command)) {
fieldTo = StringHelper.md5(fieldFull);
}
sb.append(fieldTo);
resultTo.put(fieldTo, fieldValue);
sb.append("}");
} }
sb.append(fieldTo);
resultTo.put(fieldTo, fieldValue);
sb.append("}");
}); });
} }
...@@ -149,15 +142,12 @@ public class PrinterHelper { ...@@ -149,15 +142,12 @@ public class PrinterHelper {
* *
* @param resultFrom 来源字符 * @param resultFrom 来源字符
* @param format 格式化字符串 * @param format 格式化字符串
* @return * @return 获取结果字符串
*/ */
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, (sb, group, fieldFull, field, command) -> {
@Override Object fieldValue = ObjectHelper.get(resultFrom, field);
public void addPos(StringBuilder sb, String group, String fieldFull, String field, String command) { sb.append(fieldValue);
Object fieldValue = ObjectHelper.get(resultFrom, field);
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