Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
90538b7f
Commit
90538b7f
authored
May 07, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复bug
parent
9d206b9d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
55 deletions
+45
-55
PrinterHelper.java
...int/src/main/java/com/yanzuoguang/util/PrinterHelper.java
+45
-55
No files found.
yzg-util-print/src/main/java/com/yanzuoguang/util/PrinterHelper.java
View file @
90538b7f
...
...
@@ -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 data
s
来源数据
* @return
* @param data
List
来源数据
* @return
转换后的结果
*/
public
static
ConvertPlan
convertArray
(
String
pager
,
double
left
,
double
top
,
Object
...
datas
)
{
return
convertList
(
pager
,
left
,
top
,
Arrays
.
asList
(
data
s
));
public
static
ConvertPlan
<
MapRow
>
convertArray
(
String
pager
,
double
left
,
double
top
,
Object
...
dataList
)
{
return
convertList
(
pager
,
left
,
top
,
Arrays
.
asList
(
data
List
));
}
/**
* 将来源模板与数据转换为目标模板和数据
*
* @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
);
}
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment