Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fill-system
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
廖旭伟
fill-system
Commits
b849c9e2
Commit
b849c9e2
authored
Nov 30, 2022
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构部分功能模块
parent
6339e40f
Pipeline
#2356
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
29 deletions
+92
-29
fill-manager/src/main/java/com/mortals/xhx/common/plugin/LoopSingleRowTableRenderPolicy.java
...als/xhx/common/plugin/LoopSingleRowTableRenderPolicy.java
+88
-0
fill-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
...hx/module/matter/service/impl/MatterDatumServiceImpl.java
+4
-29
No files found.
fill-manager/src/main/java/com/mortals/xhx/common/plugin/LoopSingleRowTableRenderPolicy.java
0 → 100644
View file @
b849c9e2
package
com.mortals.xhx.common.plugin
;
import
com.deepoove.poi.XWPFTemplate
;
import
com.deepoove.poi.exception.RenderException
;
import
com.deepoove.poi.policy.RenderPolicy
;
import
com.deepoove.poi.template.ElementTemplate
;
import
com.deepoove.poi.template.run.RunTemplate
;
import
com.deepoove.poi.util.TableTools
;
import
org.apache.poi.xwpf.usermodel.*
;
import
java.util.Iterator
;
import
java.util.List
;
/**
* 单行数据填充,不需要定义列元素
*
* @author:
* @date: 2022/11/30 13:34
*/
public
class
LoopSingleRowTableRenderPolicy
implements
RenderPolicy
{
@Override
public
void
render
(
ElementTemplate
eleTemplate
,
Object
data
,
XWPFTemplate
template
)
{
RunTemplate
runTemplate
=
(
RunTemplate
)
eleTemplate
;
XWPFRun
run
=
runTemplate
.
getRun
();
try
{
if
(!
TableTools
.
isInsideTable
(
run
))
{
throw
new
IllegalStateException
(
"The template tag "
+
runTemplate
.
getSource
()
+
" must be inside a table"
);
}
//获取设置标志的单元
XWPFTableCell
tagCell
=
(
XWPFTableCell
)
((
XWPFParagraph
)
run
.
getParent
()).
getBody
();
XWPFTable
table
=
tagCell
.
getTableRow
().
getTable
();
XWPFTableRow
templateRow
=
tagCell
.
getTableRow
();
//重置
run
.
setText
(
""
,
0
);
//获取模板列index
int
templateColIndex
=
getTemplateColIndex
(
tagCell
)
+
1
;
if
(
null
!=
data
&&
data
instanceof
Iterable
)
{
//data数据渲染
Iterator
<?>
iterator
=
((
Iterable
<?>)
data
).
iterator
();
boolean
hasNext
=
iterator
.
hasNext
();
while
(
hasNext
)
{
Object
root
=
iterator
.
next
();
hasNext
=
iterator
.
hasNext
();
//填充当前列元素
setTableRowCol
(
templateRow
,
root
.
toString
(),
templateColIndex
);
templateColIndex
++;
}
}
afterloop
(
table
,
data
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RenderException
(
"HackLoopTable for "
+
eleTemplate
+
"error: "
+
e
.
getMessage
(),
e
);
}
}
private
int
getTemplateColIndex
(
XWPFTableCell
tagCell
)
{
String
text
=
tagCell
.
getText
();
int
col
=
-
1
;
XWPFTableRow
tagRow
=
tagCell
.
getTableRow
();
List
<
XWPFTableCell
>
tableCells
=
tagRow
.
getTableCells
();
for
(
int
i
=
0
;
i
<
tableCells
.
size
();
i
++)
{
if
(
tableCells
.
get
(
i
).
getText
().
equalsIgnoreCase
(
text
))
{
return
i
;
}
}
return
col
;
}
protected
void
afterloop
(
XWPFTable
table
,
Object
data
)
{
}
private
void
setTableRowCol
(
XWPFTableRow
templateRow
,
String
str
,
int
pos
)
{
int
limit
=
templateRow
.
getTableCells
().
size
();
if
(
pos
>
limit
)
{
return
;
}
XWPFTableCell
cell
=
templateRow
.
getCell
(
pos
);
if
(
cell
!=
null
)
{
cell
.
setText
(
str
);
}
}
}
fill-manager/src/main/java/com/mortals/xhx/module/matter/service/impl/MatterDatumServiceImpl.java
View file @
b849c9e2
...
...
@@ -35,6 +35,7 @@ import com.mortals.xhx.common.key.Constant;
import
com.mortals.xhx.common.key.ParamKey
;
import
com.mortals.xhx.common.pdu.Col
;
import
com.mortals.xhx.common.pdu.gen.component.ComponentCons
;
import
com.mortals.xhx.common.plugin.LoopSingleRowTableRenderPolicy
;
import
com.mortals.xhx.common.utils.ExportDocUtil
;
import
com.mortals.xhx.common.utils.WordUtil
;
import
com.mortals.xhx.module.matter.dao.MatterDao
;
...
...
@@ -330,39 +331,13 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
if
(
entry
.
getKey
().
indexOf
(
"dt_"
)
!=
-
1
)
{
builder
.
bind
(
entry
.
getKey
(),
new
MultipleRowTableRenderPolicy
());
}
//绑定转换list list_1_身份证
_18_num
//绑定转换list list_1_身份证
if
(
entry
.
getKey
().
indexOf
(
"list_"
)
!=
-
1
)
{
List
<
String
>
keys
=
StrSplitter
.
split
(
entry
.
getKey
(),
"_"
,
true
,
true
);
Integer
lens
=
18
;
if
(
keys
.
size
()
>
3
)
{
lens
=
DataUtil
.
converStr2Int
(
keys
.
get
(
3
),
18
);
}
String
value
=
entry
.
getValue
().
toString
();
SplitIter
splitIter
=
new
SplitIter
(
value
,
new
LengthFinder
(
1
),
-
1
,
false
);
List
<
String
>
valueList
=
splitIter
.
toList
(
true
);
if
(
valueList
.
size
()
<
lens
)
{
int
sub
=
lens
-
valueList
.
size
();
for
(
int
i
=
0
;
i
<
sub
;
i
++)
{
valueList
.
add
(
""
);
}
}
//StrUtil
List
<
Col
>
colList
=
valueList
.
stream
().
map
(
item
->
{
Col
col
=
new
Col
();
col
.
setCol
(
item
);
return
col
;
/*
Map<String, String> map = new HashMap<>();
String colName = "col";
if (keys.size() > 4) {
colName = keys.get(4);
}
map.put(colName, item);
return map;*/
}).
collect
(
Collectors
.
toList
());
builder
.
bind
(
entry
.
getKey
(),
new
LoopColumnTableRenderPolicy
());
data
.
put
(
entry
.
getKey
(),
colList
);
builder
.
bind
(
entry
.
getKey
(),
new
LoopSingleRowTableRenderPolicy
());
data
.
put
(
entry
.
getKey
(),
valueList
);
}
});
if
(
addMap
.
size
()
>
0
)
{
...
...
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