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
6ae40a60
Commit
6ae40a60
authored
Oct 29, 2026
by
wujipeng
Browse files
优化
parent
257c8d2d
Changes
7
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-auth-api/src/main/java/com/platform/auth/model/entity/User.java
View file @
6ae40a60
...
...
@@ -57,7 +57,10 @@ public class User {
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
updateTime
;
/** 管理端账户状态;认证服务在首次登录时负责把PENDING推进为STUDYING。 */
/**
* 管理端账户业务状态。
* PENDING 只能在学员成功提交完整基础信息后推进为 STUDYING,登录认证不得修改该字段。
*/
@TableField
(
"account_status"
)
private
String
accountStatus
;
...
...
practical-auth/src/main/java/com/platform/auth/service/impl/UserServiceImpl.java
View file @
6ae40a60
...
...
@@ -71,9 +71,11 @@ public class UserServiceImpl extends ServiceImpl<USerMapper, User> implements Us
user
.
setLoginFailNum
(
0
);
user
.
setLoginDate
(
new
Date
());
user
.
setFirstLoginFlag
(
false
);
if
(
"PENDING"
.
equalsIgnoreCase
(
user
.
getAccountStatus
()))
{
user
.
setAccountStatus
(
"STUDYING"
);
}
/*
* 登录只更新认证相关信息,不能推进学员的业务状态。
* PENDING 表示学员尚未完成基础信息,必须一直保留到学员成功提交完整资料;
* 该提交动作由业务服务原子地把状态更新为 STUDYING,避免仅登录一次就绕过资料完善页。
*/
updateById
(
user
);
recordLogin
(
user
.
getId
(),
loginName
,
ipAddress
,
device
,
"SUCCESS"
,
null
);
...
...
practical-auth/src/test/java/com/platform/auth/service/impl/UserServiceImplTest.java
0 → 100644
View file @
6ae40a60
package
com.platform.auth.service.impl
;
import
com.platform.auth.mapper.USerMapper
;
import
com.platform.auth.model.dto.UserDTO
;
import
com.platform.auth.model.entity.User
;
import
com.platform.auth.model.vo.UserVO
;
import
com.platform.auth.service.UserRoleService
;
import
com.platform.auth.utils.JwtTokenUtil
;
import
com.platform.auth.utils.PasswordUtil
;
import
com.platform.model.resp.Result
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 验证登录认证不会提前推进由基础信息提交控制的学员业务状态。 */
class
UserServiceImplTest
{
private
UserServiceImpl
service
;
private
USerMapper
userMapper
;
@BeforeEach
void
setUp
()
{
service
=
new
UserServiceImpl
();
userMapper
=
mock
(
USerMapper
.
class
);
PasswordUtil
passwordUtil
=
mock
(
PasswordUtil
.
class
);
JwtTokenUtil
jwtTokenUtil
=
mock
(
JwtTokenUtil
.
class
);
UserRoleService
userRoleService
=
mock
(
UserRoleService
.
class
);
// ServiceImpl 的持久化方法依赖父类 baseMapper,其余登录依赖均通过反射注入隔离为单元测试。
ReflectionTestUtils
.
setField
(
service
,
"baseMapper"
,
userMapper
);
ReflectionTestUtils
.
setField
(
service
,
"passwordUtil"
,
passwordUtil
);
ReflectionTestUtils
.
setField
(
service
,
"jwtTokenUtil"
,
jwtTokenUtil
);
ReflectionTestUtils
.
setField
(
service
,
"userRoleService"
,
userRoleService
);
when
(
passwordUtil
.
matches
(
anyString
(),
anyString
())).
thenReturn
(
true
);
when
(
jwtTokenUtil
.
generateToken
(
anyString
())).
thenReturn
(
"token"
);
when
(
userRoleService
.
queryUserRoleList
(
anyString
())).
thenReturn
(
Collections
.
emptyList
());
}
@Test
void
loginShouldKeepPendingStatusUntilStudentProfileIsSubmitted
()
{
User
pendingStudent
=
new
User
();
pendingStudent
.
setId
(
"student-1"
);
pendingStudent
.
setUsername
(
"student-1"
);
pendingStudent
.
setPhoneNumber
(
"13800000000"
);
pendingStudent
.
setPassword
(
"encoded-password"
);
pendingStudent
.
setFirstLoginFlag
(
true
);
pendingStudent
.
setAccountStatus
(
"PENDING"
);
pendingStudent
.
setDelFlag
(
false
);
when
(
userMapper
.
selectOne
(
any
())).
thenReturn
(
pendingStudent
);
when
(
userMapper
.
updateById
(
any
(
User
.
class
))).
thenReturn
(
1
);
when
(
userMapper
.
insertLoginLog
(
anyString
(),
anyString
(),
anyString
(),
anyString
(),
anyString
(),
any
())).
thenReturn
(
1
);
UserDTO
request
=
new
UserDTO
();
request
.
setPhoneNumber
(
"13800000000"
);
request
.
setPassword
(
"plain-password"
);
Result
<
UserVO
>
result
=
service
.
login
(
request
,
"127.0.0.1"
,
"unit-test"
);
/*
* 登录仍可清除首次登录标记并写入登录时间,但账户业务状态必须保持 PENDING;
* 后续只有完整资料提交接口可以将其更新为 STUDYING。
*/
assertEquals
(
"PENDING"
,
pendingStudent
.
getAccountStatus
());
assertTrue
(
result
.
getData
().
getFirstLogin
());
verify
(
userMapper
).
updateById
(
pendingStudent
);
}
}
practical-business/src/main/java/com/platform/business/service/impl/StudentCertificationAdminServiceImpl.java
View file @
6ae40a60
...
...
@@ -46,6 +46,9 @@ public class StudentCertificationAdminServiceImpl implements StudentCertificatio
private
static
final
int
MAX_EXPORT
=
500
;
private
static
final
Pattern
ROW_END_PATTERN
=
Pattern
.
compile
(
"\\\\row(?![a-zA-Z])"
);
private
static
final
Pattern
CELL_END_PATTERN
=
Pattern
.
compile
(
"\\\\cell(?![a-zA-Z])"
);
/** 新版模板把出生日期拆成“年、月、日”三个值格,兼容数据库常见日期分隔符。 */
private
static
final
Pattern
BIRTHDAY_PATTERN
=
Pattern
.
compile
(
"^(\\d{4})[-/.年](\\d{1,2})[-/.月](\\d{1,2})日?$"
);
@Resource
private
StudentCertificationMapper
mapper
;
@Override
...
...
@@ -184,7 +187,8 @@ public class StudentCertificationAdminServiceImpl implements StudentCertificatio
/** 模板结构变化时立即失败,避免姓名、身份证等字段被写入错误单元格。 */
private
void
validateTemplate
(
String
template
,
List
<
RtfRow
>
rows
)
{
int
[]
expectedCells
=
{
15
,
9
,
8
,
8
,
18
,
10
,
10
,
5
,
5
,
5
,
5
,
7
,
8
,
3
,
3
,
8
,
// 新版原始DOC的出生日期行有11格,身份证行改为一个完整号码格,因此分别是11格和4格。
int
[]
expectedCells
=
{
15
,
11
,
8
,
8
,
4
,
10
,
10
,
5
,
5
,
5
,
5
,
7
,
8
,
3
,
3
,
8
,
8
,
6
,
9
,
3
,
8
,
8
,
2
,
2
,
2
,
2
,
2
,
19
,
16
,
1
,
1
,
1
,
1
};
if
(!
template
.
startsWith
(
"{\\rtf1"
)
||
rows
.
size
()
!=
expectedCells
.
length
)
{
throw
new
BusinessException
(
"B2模板结构已变化,请重新确认字段映射"
);
...
...
@@ -201,7 +205,7 @@ public class StudentCertificationAdminServiceImpl implements StudentCertificatio
putSubmitDate
(
edits
,
rows
,
profile
.
getSubmitTime
());
put
(
edits
,
rows
,
0
,
14
,
profile
.
getClassId
(),
true
);
put
(
edits
,
rows
,
1
,
2
,
profile
.
getName
(),
true
);
put
(
edits
,
rows
,
1
,
4
,
profile
.
getBirthday
()
,
true
);
put
Birthday
(
edits
,
rows
,
profile
.
getBirthday
());
put
(
edits
,
rows
,
2
,
2
,
profile
.
getGender
(),
true
);
// 户口性质、人员类别位于标签的下一行,未选项必须清空模板原有空格或示例勾。
...
...
@@ -245,29 +249,38 @@ public class StudentCertificationAdminServiceImpl implements StudentCertificatio
"五级"
,
"四级"
,
"三级"
,
"二级"
,
"一级"
,
"专项职业能力"
);
}
/**
* 原政府模板为早期15位身份证预留了15格。对于现行18位号码,把多出的前三位均匀放入
* 前三个格(每格两位),剩余格仍保持一格一位,既不丢数据,也不改变模板列宽。
*/
/** 新版模板提供一个横向合并的身份证号码格,直接写入完整号码,避免拆格导致缺位或换行。 */
private
void
putIdCard
(
List
<
RtfEdit
>
edits
,
List
<
RtfRow
>
rows
,
String
value
)
{
String
idCard
=
trim
(
value
);
List
<
String
>
parts
=
new
ArrayList
<>();
if
(
idCard
!=
null
)
{
int
capacity
=
15
;
int
doubleCellCount
=
Math
.
max
(
0
,
idCard
.
length
()
-
capacity
);
int
offset
=
0
;
for
(
int
i
=
0
;
i
<
capacity
;
i
++)
{
int
width
=
i
<
doubleCellCount
?
2
:
1
;
int
end
=
Math
.
min
(
idCard
.
length
(),
offset
+
width
);
parts
.
add
(
offset
<
idCard
.
length
()
?
idCard
.
substring
(
offset
,
end
)
:
""
);
offset
=
end
;
}
if
(
offset
<
idCard
.
length
())
throw
new
BusinessException
(
"身份证号超过B2模板可显示容量"
);
// 9磅字号可以让18位号码在新版合并单元格中保持单行,同时仍便于打印阅读。
putWithFontSize
(
edits
,
rows
,
4
,
2
,
idCard
,
18
);
}
/**
* 新版模板的出生日期值位于第2行的第4、6、8号单元格,三个相邻单元格分别固定显示
* “年、月、日”标签。正常日期拆分填入;无法识别的历史值仍写入年份格,保证数据不丢失。
*/
private
void
putBirthday
(
List
<
RtfEdit
>
edits
,
List
<
RtfRow
>
rows
,
String
birthday
)
{
String
normalized
=
trim
(
birthday
);
if
(
normalized
==
null
)
{
// 无生日时清空三个动态值格,避免模板中的示例日期残留。
put
(
edits
,
rows
,
1
,
4
,
""
,
true
);
put
(
edits
,
rows
,
1
,
6
,
""
,
true
);
put
(
edits
,
rows
,
1
,
8
,
""
,
true
);
return
;
}
for
(
int
i
=
0
;
i
<
15
;
i
++)
{
// 身份证格宽按旧15位号码设计,统一使用7磅字体可让18位号码的双字符格保持单行。
putWithFontSize
(
edits
,
rows
,
4
,
i
+
2
,
i
<
parts
.
size
()
?
parts
.
get
(
i
)
:
""
,
14
);
Matcher
matcher
=
BIRTHDAY_PATTERN
.
matcher
(
normalized
);
if
(
matcher
.
matches
())
{
// putWithFontSize自身会清空单元格,不能再叠加同坐标清空操作,否则RTF坐标会重复收缩。
putWithFontSize
(
edits
,
rows
,
1
,
4
,
matcher
.
group
(
1
),
16
);
putWithFontSize
(
edits
,
rows
,
1
,
6
,
matcher
.
group
(
2
),
16
);
putWithFontSize
(
edits
,
rows
,
1
,
8
,
matcher
.
group
(
3
),
16
);
}
else
{
// 兼容少量非标准历史数据;使用较小字号尽量保持在首个日期值格内。
putWithFontSize
(
edits
,
rows
,
1
,
4
,
normalized
,
12
);
put
(
edits
,
rows
,
1
,
6
,
""
,
true
);
put
(
edits
,
rows
,
1
,
8
,
""
,
true
);
}
}
...
...
practical-business/src/main/resources/templates/certification/B2-student-training-assessment-registration.rtf
View file @
6ae40a60
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 @
6ae40a60
...
...
@@ -6,12 +6,14 @@ import org.junit.jupiter.api.Test;
import
javax.swing.text.DefaultStyledDocument
;
import
javax.swing.text.rtf.RTFEditorKit
;
import
java.io.ByteArrayInputStream
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertArrayEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
...
...
@@ -31,23 +33,29 @@ class B2TemplateInspectionTest {
profile
.
setPreviousOccupation
(
"污水处理工"
);
profile
.
setPreviousLevel
(
"五级"
);
profile
.
setPreviousCertNo
(
"CERT-001"
);
profile
.
setPreviousIssueDate
(
"2024-01-01"
);
profile
.
setPreviousIssueDept
(
"示例机构"
);
profile
.
setJobYears
(
5
);
profile
.
setTrainingOccupation
(
"污水处理工"
);
profile
.
setTrainingLevel
(
"五级"
);
profile
.
setTrainingCategory
(
"企业培训"
);
profile
.
setSubsidyFlag
(
true
);
profile
.
setAssessmentOccupation
(
"污水处理工"
);
profile
.
setAssessmentLevel
(
"五级"
);
// 故意使用与新模板示例值不同的数据,验证模板中的污水处理工和默认勾选会被清除。
profile
.
setTrainingOccupation
(
"焊工"
);
profile
.
setTrainingLevel
(
"三级"
);
profile
.
setTrainingCategory
(
"社会培训"
);
profile
.
setSubsidyFlag
(
false
);
profile
.
setAssessmentOccupation
(
"电工"
);
profile
.
setAssessmentLevel
(
"二级"
);
profile
.
setClassId
(
12
);
profile
.
setSubmitTime
(
new
Date
());
byte
[]
bytes
=
new
StudentCertificationAdminServiceImpl
().
createDocument
(
profile
);
String
rtf
=
new
String
(
bytes
,
StandardCharsets
.
US_ASCII
);
//
原
模板
固定
为33行
复杂合并表格;行数变化意味着字段坐标需要重新人工确认
。
//
新
模板
仍
为33行
,但出生日期行和身份证行分别调整为11格、4格;必须锁定完整结构
。
assertTrue
(
rtf
.
startsWith
(
"{\\rtf1"
));
assertTrue
(
rtf
.
contains
(
"\\trowd"
));
assertEquals
(
33
,
countMatches
(
rtf
,
Pattern
.
compile
(
"\\\\row(?![a-zA-Z])"
)));
assertArrayEquals
(
new
int
[]{
15
,
11
,
8
,
8
,
4
,
10
,
10
,
5
,
5
,
5
,
5
,
7
,
8
,
3
,
3
,
8
,
8
,
6
,
9
,
3
,
8
,
8
,
2
,
2
,
2
,
2
,
2
,
19
,
16
,
1
,
1
,
1
,
1
},
countCellsByRow
(
rtf
));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"张三"
)));
assertTrue
(
rtf
.
contains
(
"13800138000"
));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"污水处理工"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"焊工"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"电工"
)));
assertTrue
(
rtf
.
contains
(
toRtfUnicode
(
"示例水务公司"
)));
assertTrue
(
rtf
.
contains
(
"CERT-001"
));
assertFalse
(
rtf
.
contains
(
toRtfGbkHex
(
"污水处理工(污泥处理工)"
)));
assertFalse
(
rtf
.
contains
(
"WordDocument"
));
// 使用JDK自带RTF解析器真实回读;去除单元格间空白后,18位身份证必须完整可见。
...
...
@@ -57,7 +65,14 @@ class B2TemplateInspectionTest {
String
compactText
=
visibleText
.
replaceAll
(
"\\s+"
,
""
);
assertTrue
(
visibleText
.
contains
(
"张三"
));
assertTrue
(
compactText
.
contains
(
"310101199506011234"
));
assertTrue
(
visibleText
.
contains
(
"污水处理工"
));
// 静态模板文字使用GBK十六进制,JDK解析器会乱码;日期值由Unicode/ASCII动态写入,直接校验三格。
int
birthdayIndex
=
rtf
.
indexOf
(
"1995"
);
assertTrue
(
rtf
.
contains
(
"\\fs16 1995"
),
birthdayIndex
<
0
?
"birthday missing"
:
rtf
.
substring
(
birthdayIndex
-
24
,
birthdayIndex
+
16
));
assertTrue
(
rtf
.
contains
(
"\\fs16 06"
));
assertTrue
(
rtf
.
contains
(
"\\fs16 01"
));
assertTrue
(
visibleText
.
contains
(
"焊工"
));
assertTrue
(
visibleText
.
contains
(
"电工"
));
}
private
int
countMatches
(
String
source
,
Pattern
pattern
)
{
...
...
@@ -67,6 +82,20 @@ class B2TemplateInspectionTest {
return
count
;
}
/** 按RTF真实行、单元格结束符统计结构,避免仅校验总行数而遗漏合并单元格变化。 */
private
int
[]
countCellsByRow
(
String
rtf
)
{
Matcher
rowMatcher
=
Pattern
.
compile
(
"\\\\row(?![a-zA-Z])"
).
matcher
(
rtf
);
int
[]
counts
=
new
int
[
33
];
int
rowStart
=
0
;
int
rowIndex
=
0
;
while
(
rowMatcher
.
find
())
{
String
row
=
rtf
.
substring
(
rowStart
,
rowMatcher
.
start
());
counts
[
rowIndex
++]
=
countMatches
(
row
,
Pattern
.
compile
(
"\\\\cell(?![a-zA-Z])"
));
rowStart
=
rowMatcher
.
end
();
}
return
counts
;
}
/** 与生产代码相同地把中文转换为RTF Unicode控制字,避免测试依赖本机字符集。 */
private
String
toRtfUnicode
(
String
value
)
{
StringBuilder
escaped
=
new
StringBuilder
();
...
...
@@ -76,4 +105,13 @@ class B2TemplateInspectionTest {
}
return
escaped
.
toString
();
}
/** WPS另存的模板静态中文使用GBK十六进制字节,按同一编码构造可重复的原文断言。 */
private
String
toRtfGbkHex
(
String
value
)
{
StringBuilder
escaped
=
new
StringBuilder
();
for
(
byte
valueByte
:
value
.
getBytes
(
Charset
.
forName
(
"GBK"
)))
{
escaped
.
append
(
"\\'"
).
append
(
String
.
format
(
"%02x"
,
valueByte
&
0xff
));
}
return
escaped
.
toString
();
}
}
practical-business/src/test/java/com/platform/business/service/impl/StudentCertificationBatchExportTest.java
View file @
6ae40a60
...
...
@@ -52,6 +52,20 @@ class StudentCertificationBatchExportTest {
assertTrue
(
names
.
get
(
1
).
contains
(
"_2.doc"
));
}
@Test
void
singleExportShouldKeepLegacyDocDownloadContract
()
throws
Exception
{
// B2模板内部使用RTF保存版式,但对管理端仍必须维持原有DOC扩展名和Word媒体类型。
when
(
mapper
.
selectProfile
(
"1"
,
false
)).
thenReturn
(
profile
(
"1"
,
"张三"
,
"310101199506011234"
));
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
service
.
exportOne
(
"1"
,
response
);
assertEquals
(
"application/msword"
,
response
.
getContentType
());
assertTrue
(
response
.
getHeader
(
"Content-Disposition"
).
contains
(
"UTF-8''"
));
assertTrue
(
response
.
getHeader
(
"Content-Disposition"
).
endsWith
(
".doc"
));
assertTrue
(
new
String
(
response
.
getContentAsByteArray
(),
java
.
nio
.
charset
.
StandardCharsets
.
US_ASCII
)
.
startsWith
(
"{\\rtf1"
));
}
@Test
void
moreThanFiveHundredSelectedStudentsShouldBeRejectedBeforeQuery
()
{
StudentCertificationExportDTO
request
=
new
StudentCertificationExportDTO
();
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
501
;
i
++)
ids
.
add
(
String
.
valueOf
(
i
));
request
.
setStudentIds
(
ids
);
...
...
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