Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
257c8d2d
Commit
257c8d2d
authored
Oct 28, 2026
by
wujipeng
Browse files
优化
parent
0562fc83
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/impl/StudentCertificationAdminServiceImpl.java
View file @
257c8d2d
This diff is collapsed.
Click to expand it.
practical-business/src/main/resources/templates/certification/B2-student-training-assessment-registration.rtf
0 → 100644
View file @
257c8d2d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
practical-business/src/test/java/com/platform/business/service/impl/B2TemplateInspectionTest.java
View file @
257c8d2d
...
@@ -9,11 +9,14 @@ import java.io.ByteArrayInputStream;
...
@@ -9,11 +9,14 @@ import java.io.ByteArrayInputStream;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/**
直接验证RTF
正文,防止
测试
只检查文件外壳而
漏掉Word/WPS打开后内容为空的问题
。 */
/**
验证原版式RTF模板的结构和可见
正文,防止只检查文件外壳而
遗漏空白导出
。 */
class
B2TemplateInspectionTest
{
class
B2TemplateInspectionTest
{
@Test
@Test
void
generatedDocumentShouldContainProfileValuesAndWordTableStructure
()
throws
Exception
{
void
generatedDocumentShouldContainProfileValuesAndWordTableStructure
()
throws
Exception
{
...
@@ -36,27 +39,34 @@ class B2TemplateInspectionTest {
...
@@ -36,27 +39,34 @@ class B2TemplateInspectionTest {
byte
[]
bytes
=
new
StudentCertificationAdminServiceImpl
().
createDocument
(
profile
);
byte
[]
bytes
=
new
StudentCertificationAdminServiceImpl
().
createDocument
(
profile
);
String
rtf
=
new
String
(
bytes
,
StandardCharsets
.
US_ASCII
);
String
rtf
=
new
String
(
bytes
,
StandardCharsets
.
US_ASCII
);
//
RTF内容全部以ASCII控制字表达,测试可稳定检查中文对应的Unicode转义值
。
//
原模板固定为33行复杂合并表格;行数变化意味着字段坐标需要重新人工确认
。
assertTrue
(
rtf
.
startsWith
(
"{\\rtf1"
));
assertTrue
(
rtf
.
startsWith
(
"{\\rtf1"
));
assertTrue
(
rtf
.
contains
(
"\\trowd"
));
assertTrue
(
rtf
.
contains
(
"\\trowd"
));
assertEquals
(
33
,
countMatches
(
rtf
,
Pattern
.
compile
(
"\\\\row(?![a-zA-Z])"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"张三"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"张三"
)));
assertTrue
(
rtf
.
contains
(
"310101199506011234"
));
assertTrue
(
rtf
.
contains
(
"13800138000"
));
assertTrue
(
rtf
.
contains
(
"13800138000"
));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"企业培训"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"污水处理工"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"污水处理工"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"[√]企业培训"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"示例水务公司"
)));
assertTrue
(
rtf
.
contains
(
"CERT-001"
));
assertFalse
(
rtf
.
contains
(
"WordDocument"
));
assertFalse
(
rtf
.
contains
(
"WordDocument"
));
// 使用JDK自带RTF解析器
执行一次真实回读,证明输出不是“控制字存在但文档不可解析”
。
// 使用JDK自带RTF解析器
真实回读;去除单元格间空白后,18位身份证必须完整可见
。
DefaultStyledDocument
parsedDocument
=
new
DefaultStyledDocument
();
DefaultStyledDocument
parsedDocument
=
new
DefaultStyledDocument
();
new
RTFEditorKit
().
read
(
new
ByteArrayInputStream
(
bytes
),
parsedDocument
,
0
);
new
RTFEditorKit
().
read
(
new
ByteArrayInputStream
(
bytes
),
parsedDocument
,
0
);
String
visibleText
=
parsedDocument
.
getText
(
0
,
parsedDocument
.
getLength
());
String
visibleText
=
parsedDocument
.
getText
(
0
,
parsedDocument
.
getLength
());
String
compactText
=
visibleText
.
replaceAll
(
"\\s+"
,
""
);
assertTrue
(
visibleText
.
contains
(
"张三"
));
assertTrue
(
visibleText
.
contains
(
"张三"
));
assertTrue
(
visibleText
.
contains
(
"310101199506011234"
));
assertTrue
(
compactText
.
contains
(
"310101199506011234"
));
assertTrue
(
visibleText
.
contains
(
"企业培训"
));
assertTrue
(
visibleText
.
contains
(
"污水处理工"
));
assertTrue
(
visibleText
.
contains
(
"污水处理工"
));
}
}
private
int
countMatches
(
String
source
,
Pattern
pattern
)
{
int
count
=
0
;
Matcher
matcher
=
pattern
.
matcher
(
source
);
while
(
matcher
.
find
())
count
++;
return
count
;
}
/** 与生产代码相同地把中文转换为RTF Unicode控制字,避免测试依赖本机字符集。 */
/** 与生产代码相同地把中文转换为RTF Unicode控制字,避免测试依赖本机字符集。 */
private
String
toRtfUnicode
(
String
value
)
{
private
String
toRtfUnicode
(
String
value
)
{
StringBuilder
escaped
=
new
StringBuilder
();
StringBuilder
escaped
=
new
StringBuilder
();
...
...
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