Commit 90538b7f authored by yanzg's avatar yanzg

修复bug

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