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
af8007ec
"git@gitlab.ruzhoukj.com:wujipeng/relation.git" did not exist on "15b200231620983edac5a94e83865ef7aeb4bf60"
Commit
af8007ec
authored
Sep 04, 2026
by
wujipeng
Browse files
Merge remote-tracking branch 'origin/dev-v1.0' into dev-v1.0
parents
61470e0e
a531d308
Changes
13
Show whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/dto/LeaveApplyDTO.java
View file @
af8007ec
package
com.platform.business.model.dto
;
package
com.platform.business.model.dto
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -18,11 +19,13 @@ public class LeaveApplyDTO {
...
@@ -18,11 +19,13 @@ public class LeaveApplyDTO {
private
String
leaveType
;
private
String
leaveType
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@ApiModelProperty
(
value
=
"请假开始时间,不允许早于或等于当前时间"
,
required
=
true
)
@JsonDeserialize
(
using
=
LeaveApplyDateDeserializer
.
class
)
@ApiModelProperty
(
value
=
"请假开始时间,支持yyyy-MM-dd HH:mm或yyyy-MM-dd HH:mm:ss,不允许早于或等于当前时间"
,
required
=
true
)
private
Date
startTime
;
private
Date
startTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@ApiModelProperty
(
value
=
"请假结束时间,必须晚于开始时间"
,
required
=
true
)
@JsonDeserialize
(
using
=
LeaveApplyDateDeserializer
.
class
)
@ApiModelProperty
(
value
=
"请假结束时间,支持yyyy-MM-dd HH:mm或yyyy-MM-dd HH:mm:ss,必须晚于开始时间"
,
required
=
true
)
private
Date
endTime
;
private
Date
endTime
;
@ApiModelProperty
(
value
=
"请假原因,10至200个字符"
,
required
=
true
)
@ApiModelProperty
(
value
=
"请假原因,10至200个字符"
,
required
=
true
)
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/dto/LeaveApplyDateDeserializer.java
0 → 100644
View file @
af8007ec
package
com.platform.business.model.dto
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonToken
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.JsonDeserializer
;
import
java.io.IOException
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeParseException
;
import
java.time.format.ResolverStyle
;
import
java.util.Date
;
/**
* 请假表单专用时间解析器,兼容页面分钟精度和原接口秒精度,避免 JSON 绑定阶段直接返回 400。
* 仅由 LeaveApplyDTO 的两个时间字段使用,不改变其他接口或响应的日期格式。
*/
public
class
LeaveApplyDateDeserializer
extends
JsonDeserializer
<
Date
>
{
// 可选的秒缺省为 00;严格解析防止 2 月 30 日、25 点等非法输入被自动调整成另一个时间。
private
static
final
DateTimeFormatter
FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"uuuu-MM-dd HH:mm[:ss]"
).
withResolverStyle
(
ResolverStyle
.
STRICT
);
private
static
final
ZoneId
BUSINESS_ZONE
=
ZoneId
.
of
(
"Asia/Shanghai"
);
@Override
public
Date
deserialize
(
JsonParser
parser
,
DeserializationContext
context
)
throws
IOException
{
// 保留 Jackson Date 原有的整数毫秒时间戳兼容性;字符串仍要求明确的日期时间格式。
if
(
parser
.
hasToken
(
JsonToken
.
VALUE_NUMBER_INT
))
{
return
new
Date
(
parser
.
getLongValue
());
}
if
(!
parser
.
hasToken
(
JsonToken
.
VALUE_STRING
))
{
return
(
Date
)
context
.
handleUnexpectedToken
(
Date
.
class
,
parser
);
}
String
value
=
parser
.
getText
().
trim
();
if
(
value
.
isEmpty
())
{
// 缺失、null 和空字符串交给现有业务校验,统一提示“请假开始时间和结束时间不能为空”。
return
null
;
}
try
{
return
Date
.
from
(
LocalDateTime
.
parse
(
value
,
FORMATTER
).
atZone
(
BUSINESS_ZONE
).
toInstant
());
}
catch
(
DateTimeParseException
exception
)
{
return
(
Date
)
context
.
handleWeirdStringValue
(
Date
.
class
,
value
,
"请假时间格式应为 yyyy-MM-dd HH:mm 或 yyyy-MM-dd HH:mm:ss,且必须是有效日期时间"
);
}
}
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/entity/EvaluationRecordEntity.java
View file @
af8007ec
...
@@ -46,6 +46,7 @@ public class EvaluationRecordEntity {
...
@@ -46,6 +46,7 @@ public class EvaluationRecordEntity {
private
Date
submittedAt
;
private
Date
submittedAt
;
/** 发起时与任务 createdTime 一致且保持不变,用于排除任务发起之后补入的学员。 */
private
Date
createdTime
;
private
Date
createdTime
;
private
Date
updateTime
;
private
Date
updateTime
;
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/EvaluationTaskVO.java
View file @
af8007ec
...
@@ -42,17 +42,18 @@ public class EvaluationTaskVO {
...
@@ -42,17 +42,18 @@ public class EvaluationTaskVO {
private
String
status
;
private
String
status
;
/** 发起评议时固化的目标学员人数,取自 evaluation_record,不是班级当前人数。 */
private
Integer
totalCount
;
private
Integer
totalCount
;
private
Integer
pendingCount
;
private
Integer
pendingCount
;
private
Integer
submittedCount
;
private
Integer
submittedCount
;
/** 已评人数 /
总
人数,返回0到100之间的百分比。 */
/** 已评人数 /
发起时目标学员
人数,返回0到100之间的百分比
;后续班级增减员不影响分母
。 */
private
Double
completionRate
;
private
Double
completionRate
;
/**
/**
* 管理端列表直接展示的评议进度,固定为“已评人数/
总
人数”。
* 管理端列表直接展示的评议进度,固定为“已评人数/
发起时目标学员
人数”。
*
*
* <p>该值由已有统计字段实时计算,不额外持久化;即使数据库聚合结果为空,也会稳定
* <p>该值由已有统计字段实时计算,不额外持久化;即使数据库聚合结果为空,也会稳定
* 返回 {@code 0/0},避免前端混用 pendingCount、submittedCount 和 totalCount。</p>
* 返回 {@code 0/0},避免前端混用 pendingCount、submittedCount 和 totalCount。</p>
...
...
practical-business/src/main/java/com/platform/business/controller/LeaveController.java
View file @
af8007ec
...
@@ -60,6 +60,10 @@ public class LeaveController extends BaseController {
...
@@ -60,6 +60,10 @@ public class LeaveController extends BaseController {
return
Result
.
data
(
bsFileService
.
uploadFile
(
file
));
return
Result
.
data
(
bsFileService
.
uploadFile
(
file
));
}
}
/**
* 新增申请使用 POST;Spring MVC 以 HTTP 方法和路径共同匹配接口,
* 因而与同路径的 PUT 修改接口不冲突。调用方必须按操作选择请求方法。
*/
@ApiOperation
(
"学员端-提交请假申请并自动关联时间重叠课程"
)
@ApiOperation
(
"学员端-提交请假申请并自动关联时间重叠课程"
)
@PostMapping
(
"/student/apply"
)
@PostMapping
(
"/student/apply"
)
public
Result
<
LeaveApplicationVO
>
apply
(
@RequestBody
LeaveApplyDTO
body
,
public
Result
<
LeaveApplicationVO
>
apply
(
@RequestBody
LeaveApplyDTO
body
,
...
@@ -67,6 +71,7 @@ public class LeaveController extends BaseController {
...
@@ -67,6 +71,7 @@ public class LeaveController extends BaseController {
return
Result
.
data
(
leaveManagementService
.
apply
(
body
,
currentUser
(
request
).
getId
()));
return
Result
.
data
(
leaveManagementService
.
apply
(
body
,
currentUser
(
request
).
getId
()));
}
}
/** 修改使用 PUT,申请 ID 从请求体读取;不能以 POST 代替,否则会进入新增流程。 */
@ApiOperation
(
"学员端-修改待审批请假申请"
)
@ApiOperation
(
"学员端-修改待审批请假申请"
)
@PutMapping
(
"/student/apply"
)
@PutMapping
(
"/student/apply"
)
public
Result
<
LeaveApplicationVO
>
update
(
@RequestBody
LeaveApplyDTO
body
,
public
Result
<
LeaveApplicationVO
>
update
(
@RequestBody
LeaveApplyDTO
body
,
...
...
practical-business/src/main/java/com/platform/business/service/impl/EvaluationServiceImpl.java
View file @
af8007ec
...
@@ -139,7 +139,9 @@ public class EvaluationServiceImpl implements EvaluationService {
...
@@ -139,7 +139,9 @@ public class EvaluationServiceImpl implements EvaluationService {
record
.
setTaskId
(
task
.
getId
());
record
.
setTaskId
(
task
.
getId
());
record
.
setStudentId
(
studentId
);
record
.
setStudentId
(
studentId
);
record
.
setStatus
(
EvaluationConstants
.
RECORD_PENDING
);
record
.
setStatus
(
EvaluationConstants
.
RECORD_PENDING
);
record
.
setCreatedTime
(
now
);
// 必须与任务创建时间一致:查询用此时间界定发起时的学员范围,排除后续补入的记录。
// 提交只更新 updateTime/submittedAt,不能改写这份发起时间快照。
record
.
setCreatedTime
(
task
.
getCreatedTime
());
record
.
setUpdateTime
(
now
);
record
.
setUpdateTime
(
now
);
records
.
add
(
record
);
records
.
add
(
record
);
}
}
...
...
practical-business/src/main/resources/com/platform/business/mapper/EvaluationRecordMapper.xml
View file @
af8007ec
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
submitted_at, created_time, update_time
submitted_at, created_time, update_time
from evaluation_record
from evaluation_record
where task_id = #{taskId} and student_id = #{studentId}
where task_id = #{taskId} and student_id = #{studentId}
<!-- 提交资格与管理端统计范围保持一致,拒绝发起之后补入的学员记录。 -->
and created_time
<
= (select created_time from evaluation_task where id = #{taskId})
for update
for update
</select>
</select>
...
@@ -56,6 +58,8 @@
...
@@ -56,6 +58,8 @@
r.comment,
r.comment,
r.submitted_at as submittedAt
r.submitted_at as submittedAt
from evaluation_record r
from evaluation_record r
<!-- 姓名筛选、维度统计、详情及导出均只包含发起时的学员记录。 -->
inner join evaluation_task t on t.id = r.task_id and r.created_time
<
= t.created_time
inner join user u on u.id = r.student_id
inner join user u on u.id = r.student_id
where r.task_id = #{taskId}
where r.task_id = #{taskId}
<if
test=
"studentName != null and studentName.trim() != ''"
>
<if
test=
"studentName != null and studentName.trim() != ''"
>
...
...
practical-business/src/main/resources/com/platform/business/mapper/EvaluationTaskMapper.xml
View file @
af8007ec
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.platform.business.mapper.EvaluationTaskMapper"
>
<mapper
namespace=
"com.platform.business.mapper.EvaluationTaskMapper"
>
<!-- 公共展示字段:
任务自身、课程/班级/教师信息以及记录表实时统计
。 -->
<!-- 公共展示字段:
列表、详情和导出共用。人数来自发起时固化的评价记录,只有提交状态实时变化
。 -->
<sql
id=
"taskViewColumns"
>
<sql
id=
"taskViewColumns"
>
t.id,
t.id,
t.subject_id as subjectId,
t.subject_id as subjectId,
...
@@ -37,13 +37,20 @@
...
@@ -37,13 +37,20 @@
left join user teacher on teacher.id = cs.teacher_id
left join user teacher on teacher.id = cs.teacher_id
left join user creator on creator.id = t.created_by
left join user creator on creator.id = t.created_by
left join user revoker on revoker.id = t.revoked_by
left join user revoker on revoker.id = t.revoked_by
<!--
发起任务时,任务和目标学员记录使用同一个 created_time。
仅统计发起时已存在的记录:后续即便向旧任务补入新学员,也不增加总人数、已评或待评人数。
不能使用 update_time 或 submitted_at 判断范围,原学员提交时这两个时间会正常变化。
-->
left join (
left join (
select task_id,
select
r.
task_id,
count(*) as total_count,
count(*) as total_count,
sum(case when status = 'PENDING' then 1 else 0 end) as pending_count,
sum(case when r.status = 'PENDING' then 1 else 0 end) as pending_count,
sum(case when status = 'SUBMITTED' then 1 else 0 end) as submitted_count
sum(case when r.status = 'SUBMITTED' then 1 else 0 end) as submitted_count
from evaluation_record
from evaluation_record r
group by task_id
inner join evaluation_task snapshot on snapshot.id = r.task_id
and r.created_time
<
= snapshot.created_time
group by r.task_id
) stat on stat.task_id = t.id
) stat on stat.task_id = t.id
</sql>
</sql>
...
@@ -112,6 +119,8 @@
...
@@ -112,6 +119,8 @@
inner join class c on c.id = cs.class_id
inner join class c on c.id = cs.class_id
left join user teacher on teacher.id = cs.teacher_id
left join user teacher on teacher.id = cs.teacher_id
where r.student_id = #{studentId}
where r.student_id = #{studentId}
<!-- 后加入班级的学员不参与已发起的历史任务,即便存在后补的记录也不展示。 -->
and r.created_time
<
= t.created_time
and t.status != 'REVOKED'
and t.status != 'REVOKED'
<if
test=
"query != null and query.status != null and query.status.trim() != ''"
>
<if
test=
"query != null and query.status != null and query.status.trim() != ''"
>
<choose>
<choose>
...
@@ -168,6 +177,7 @@
...
@@ -168,6 +177,7 @@
left join user teacher on teacher.id = cs.teacher_id
left join user teacher on teacher.id = cs.teacher_id
where r.task_id = #{taskId}
where r.task_id = #{taskId}
and r.student_id = #{studentId}
and r.student_id = #{studentId}
and r.created_time
<
= t.created_time
and t.status != 'REVOKED'
and t.status != 'REVOKED'
</select>
</select>
...
@@ -204,6 +214,8 @@
...
@@ -204,6 +214,8 @@
and not exists (
and not exists (
select 1 from evaluation_record r
select 1 from evaluation_record r
where r.task_id = t.id and r.status = 'PENDING'
where r.task_id = t.id and r.status = 'PENDING'
<!-- 仅等待发起时的学员提交,后补记录不能阻止原任务完成。 -->
and r.created_time
<
= t.created_time
)
)
</update>
</update>
...
...
practical-business/src/main/resources/evaluation-api.md
View file @
af8007ec
...
@@ -105,6 +105,13 @@
...
@@ -105,6 +105,13 @@
`1/3`
;
`completionRate`
为 0~100 的数值,例如
`33.33`
。列表应直接展示
`1/3`
;
`completionRate`
为 0~100 的数值,例如
`33.33`
。列表应直接展示
`evaluationProgress`
,不要自行交换
`pendingCount/submittedCount/totalCount`
的顺序。
`evaluationProgress`
,不要自行交换
`pendingCount/submittedCount/totalCount`
的顺序。
`totalCount`
是发起任务时写入
`evaluation_record`
的目标学员人数,不是班级当前人数。
任务与初始学员记录使用同一创建时间,查询仅纳入记录创建时间不晚于任务创建时间的学员;
后补进旧任务的记录不计入已评、待评、总人数,也不能参与该任务的提交和完成状态判断。
列表、详情及导出均采用该口径;前端应直接使用
`evaluationProgress`
和
`completionRate`
,
不要用班级接口返回的最新人数重新计算。例如发起时有 2 人、已评 1 人,之后班级新增 1 人,
旧任务仍为
`1/2`
、
`50.0`
,新增学员不参与旧任务;重新发起的新任务才读取当时的班级名单。
### 查看实名详情
### 查看实名详情
`GET /evaluation/admin/{taskId}?studentName=张`
`GET /evaluation/admin/{taskId}?studentName=张`
...
...
practical-business/src/main/resources/leave-api.md
View file @
af8007ec
...
@@ -11,6 +11,13 @@
...
@@ -11,6 +11,13 @@
-
`POST /leave/student/page`
:分页查询本人申请。
-
`POST /leave/student/page`
:分页查询本人申请。
-
`GET /leave/student/{leaveId}`
:查看本人申请详情。
-
`GET /leave/student/{leaveId}`
:查看本人申请详情。
新增与修改共用路径,但 HTTP 方法分别为
`POST`
、
`PUT`
,Spring MVC 会分别路由,不会冲突。
前端和网关需要保留对应请求方法;修改时传入
`id`
也不能把
`PUT`
改成
`POST`
。
`startTime`
、
`endTime`
均支持
`yyyy-MM-dd HH:mm`
和
`yyyy-MM-dd HH:mm:ss`
,按北京时间解析。
分钟格式的秒数按
`00`
处理,传入秒数则完整保留;响应仍使用
`yyyy-MM-dd HH:mm:ss`
。
非法日历日期或时间返回 HTTP 400。格式正确后仍须满足开始时间晚于当前时间等业务规则。
提交或修改示例:
提交或修改示例:
```
json
```
json
...
...
practical-business/src/test/java/com/platform/business/controller/LeaveControllerTest.java
0 → 100644
View file @
af8007ec
package
com.platform.business.controller
;
import
com.platform.business.model.dto.LeaveApplyDTO
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.service.LeaveManagementService
;
import
com.platform.business.service.UserService
;
import
com.platform.business.utils.JwtTokenUtil
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.ArgumentCaptor
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
;
import
org.springframework.web.context.support.StaticWebApplicationContext
;
import
java.time.Instant
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoInteractions
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/** 使用 Spring 的真实路由解析确认同路径的新增、修改申请可同时注册并正确分派。 */
class
LeaveControllerTest
{
@Test
void
applyAndUpdateShouldAcceptMinuteAndSecondPrecisionWithoutLosingSeconds
()
throws
Exception
{
LeaveManagementService
service
=
mock
(
LeaveManagementService
.
class
);
MockMvc
mvc
=
leaveMvc
(
service
);
// 使用请求中的原始日期验证 JSON 绑定;业务层被 mock,不创建申请,也不受当前时间影响。
mvc
.
perform
(
post
(
"/leave/student/apply"
).
header
(
"Authorization"
,
"test-token"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"leaveType\":\"PERSONAL\",\"startTime\":\"2026-09-04 08:00\","
+
"\"endTime\":\"2026-09-04 10:00\",\"reason\":\"fhqifhqifhaifhaif\"}"
))
.
andExpect
(
status
().
isOk
());
mvc
.
perform
(
put
(
"/leave/student/apply"
).
header
(
"Authorization"
,
"test-token"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"id\":\"L1\",\"startTime\":\"2026-09-04 08:00:15\","
+
"\"endTime\":\"2026-09-04 10:00:45\"}"
))
.
andExpect
(
status
().
isOk
());
ArgumentCaptor
<
LeaveApplyDTO
>
create
=
ArgumentCaptor
.
forClass
(
LeaveApplyDTO
.
class
);
ArgumentCaptor
<
LeaveApplyDTO
>
update
=
ArgumentCaptor
.
forClass
(
LeaveApplyDTO
.
class
);
verify
(
service
).
apply
(
create
.
capture
(),
eq
(
"S1"
));
verify
(
service
).
update
(
update
.
capture
(),
eq
(
"S1"
));
// 两种格式均按北京时间解析;原来的秒精度客户端不能因兼容分钟而丢失秒数。
assertEquals
(
Instant
.
parse
(
"2026-09-04T00:00:00Z"
),
create
.
getValue
().
getStartTime
().
toInstant
());
assertEquals
(
Instant
.
parse
(
"2026-09-04T02:00:00Z"
),
create
.
getValue
().
getEndTime
().
toInstant
());
assertEquals
(
Instant
.
parse
(
"2026-09-04T00:00:15Z"
),
update
.
getValue
().
getStartTime
().
toInstant
());
assertEquals
(
Instant
.
parse
(
"2026-09-04T02:00:45Z"
),
update
.
getValue
().
getEndTime
().
toInstant
());
}
@Test
void
invalidDatesShouldFailBeforeCallingLeaveService
()
throws
Exception
{
LeaveManagementService
service
=
mock
(
LeaveManagementService
.
class
);
MockMvc
mvc
=
leaveMvc
(
service
);
// 非法日历日期、溢出时间和尾随字符都不能被自动纠正后进入业务层。
for
(
String
invalid
:
new
String
[]{
"2026-02-30 08:00"
,
"2026-09-04 25:00"
,
"2026-09-04 08:00:00junk"
})
{
mvc
.
perform
(
post
(
"/leave/student/apply"
).
header
(
"Authorization"
,
"test-token"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
)
.
content
(
"{\"startTime\":\""
+
invalid
+
"\"}"
))
.
andExpect
(
status
().
isBadRequest
());
}
verifyNoInteractions
(
service
);
}
/** 装配真实 Controller 和 JSON 转换器,只替换认证与业务依赖,不使用真实令牌或外部服务。 */
private
MockMvc
leaveMvc
(
LeaveManagementService
service
)
{
LeaveController
controller
=
new
LeaveController
();
JwtTokenUtil
jwt
=
mock
(
JwtTokenUtil
.
class
);
UserService
users
=
mock
(
UserService
.
class
);
UserEntity
student
=
new
UserEntity
();
student
.
setId
(
"S1"
);
when
(
jwt
.
getUsernameFromToken
(
"test-token"
)).
thenReturn
(
"test-phone"
);
when
(
users
.
getOne
(
any
(),
eq
(
false
))).
thenReturn
(
student
);
ReflectionTestUtils
.
setField
(
controller
,
"leaveManagementService"
,
service
);
ReflectionTestUtils
.
setField
(
controller
,
"jwtTokenUtil"
,
jwt
);
ReflectionTestUtils
.
setField
(
controller
,
"userService"
,
users
);
return
MockMvcBuilders
.
standaloneSetup
(
controller
).
build
();
}
@Test
void
sameApplyPathShouldRouteByHttpMethod
()
throws
Exception
{
try
(
StaticWebApplicationContext
context
=
new
StaticWebApplicationContext
())
{
// 仅解析 Controller 路由,不执行请假业务,因此不需要数据库、JWT 或服务依赖。
context
.
registerSingleton
(
"leaveController"
,
LeaveController
.
class
);
context
.
refresh
();
RequestMappingHandlerMapping
mapping
=
new
RequestMappingHandlerMapping
();
mapping
.
setApplicationContext
(
context
);
mapping
.
afterPropertiesSet
();
MockHttpServletRequest
create
=
new
MockHttpServletRequest
(
"POST"
,
"/leave/student/apply"
);
MockHttpServletRequest
update
=
new
MockHttpServletRequest
(
"PUT"
,
"/leave/student/apply"
);
assertNotNull
(
mapping
.
getHandler
(
create
));
assertNotNull
(
mapping
.
getHandler
(
update
));
assertEquals
(
"apply"
,
((
HandlerMethod
)
mapping
.
getHandler
(
create
).
getHandler
()).
getMethod
().
getName
());
assertEquals
(
"update"
,
((
HandlerMethod
)
mapping
.
getHandler
(
update
).
getHandler
()).
getMethod
().
getName
());
}
}
}
practical-business/src/test/java/com/platform/business/mapper/EvaluationTaskMapperXmlTest.java
0 → 100644
View file @
af8007ec
package
com.platform.business.mapper
;
import
com.platform.business.model.dto.EvaluationTaskQueryDTO
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.Configuration
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 校验实际展开的列表、详情 SQL,防止统计口径退回班级最新人数。 */
class
EvaluationTaskMapperXmlTest
{
@Test
void
listAndDetailShouldCountTaskSnapshotInsteadOfCurrentClassRoster
()
throws
Exception
{
String
resource
=
"com/platform/business/mapper/EvaluationTaskMapper.xml"
;
Configuration
configuration
=
new
Configuration
();
try
(
InputStream
input
=
Resources
.
getResourceAsStream
(
resource
))
{
new
XMLMapperBuilder
(
input
,
configuration
,
resource
,
configuration
.
getSqlFragments
()).
parse
();
}
String
namespace
=
"com.platform.business.mapper.EvaluationTaskMapper."
;
String
listSql
=
configuration
.
getMappedStatement
(
namespace
+
"queryAdminTasks"
)
.
getBoundSql
(
new
EvaluationTaskQueryDTO
()).
getSql
();
String
detailSql
=
configuration
.
getMappedStatement
(
namespace
+
"selectTaskView"
)
.
getBoundSql
(
Collections
.
singletonMap
(
"taskId"
,
"T1"
)).
getSql
();
for
(
String
sql
:
new
String
[]{
listSql
,
detailSql
})
{
String
normalized
=
sql
.
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
();
// 后补的任务记录也必须被排除;只是不关联 class_student 无法保证分母固定。
assertTrue
(
normalized
.
contains
(
"count(*) as total_count"
));
assertTrue
(
normalized
.
contains
(
"from evaluation_record r"
));
assertTrue
(
normalized
.
contains
(
"r.created_time <= snapshot.created_time"
));
assertTrue
(
normalized
.
contains
(
"stat.submitted_count * 100.0 / stat.total_count"
));
assertFalse
(
normalized
.
contains
(
"class_student"
));
}
}
@Test
void
participationAndCompletionShouldUseTheSameSnapshotBoundary
()
throws
Exception
{
Configuration
configuration
=
new
Configuration
();
for
(
String
mapper
:
new
String
[]{
"EvaluationTaskMapper"
,
"EvaluationRecordMapper"
})
{
String
resource
=
"com/platform/business/mapper/"
+
mapper
+
".xml"
;
try
(
InputStream
input
=
Resources
.
getResourceAsStream
(
resource
))
{
new
XMLMapperBuilder
(
input
,
configuration
,
resource
,
configuration
.
getSqlFragments
()).
parse
();
}
}
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"taskId"
,
"T1"
);
parameters
.
put
(
"studentId"
,
"S3"
);
// 动态条件全部缺省,验证没有筛选时使用的真实 SQL,不依赖 XML 注释中的说明。
for
(
String
statement
:
new
String
[]{
"EvaluationTaskMapper.queryStudentTasks"
,
"EvaluationTaskMapper.selectStudentTask"
,
"EvaluationTaskMapper.completeIfAllSubmitted"
,
"EvaluationRecordMapper.queryTaskRecords"
})
{
String
sql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper."
+
statement
)
.
getBoundSql
(
parameters
).
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
();
assertTrue
(
sql
.
contains
(
"r.created_time <= t.created_time"
),
statement
);
}
String
submitSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.EvaluationRecordMapper.selectByTaskAndStudentForUpdate"
)
.
getBoundSql
(
parameters
).
getSql
().
replaceAll
(
"\\s+"
,
" "
).
toLowerCase
();
assertTrue
(
submitSql
.
contains
(
"created_time <= (select created_time from evaluation_task"
));
}
}
practical-business/src/test/java/com/platform/business/service/impl/EvaluationServiceImplTest.java
View file @
af8007ec
...
@@ -29,6 +29,8 @@ import java.util.Arrays;
...
@@ -29,6 +29,8 @@ import java.util.Arrays;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
...
@@ -93,7 +95,17 @@ class EvaluationServiceImplTest {
...
@@ -93,7 +95,17 @@ class EvaluationServiceImplTest {
service
.
createTask
(
request
,
"A1"
,
"管理员甲"
);
service
.
createTask
(
request
,
"A1"
,
"管理员甲"
);
// 评价记录必须按班级人数批量固化,通知接收人也必须使用同一份学员快照。
// 评价记录必须按班级人数批量固化,通知接收人也必须使用同一份学员快照。
verify
(
recordMapper
).
batchInsert
(
any
());
ArgumentCaptor
<
List
<
EvaluationRecordEntity
>>
recordsCaptor
=
ArgumentCaptor
.
forClass
(
List
.
class
);
verify
(
recordMapper
).
batchInsert
(
recordsCaptor
.
capture
());
List
<
EvaluationRecordEntity
>
records
=
recordsCaptor
.
getValue
();
ArgumentCaptor
<
EvaluationTaskEntity
>
taskCaptor
=
ArgumentCaptor
.
forClass
(
EvaluationTaskEntity
.
class
);
verify
(
taskMapper
).
insert
(
taskCaptor
.
capture
());
assertEquals
(
Arrays
.
asList
(
"S1"
,
"S2"
),
records
.
stream
()
.
map
(
EvaluationRecordEntity:
:
getStudentId
).
collect
(
Collectors
.
toList
()));
// 每位目标学员在发起时即有记录,尚未提交的人也必须进入进度分母。
records
.
forEach
(
record
->
assertEquals
(
EvaluationConstants
.
RECORD_PENDING
,
record
.
getStatus
()));
// 查询依赖创建时间识别发起时名单,必须确保任务与每条初始记录都使用同一个时间值。
records
.
forEach
(
record
->
assertEquals
(
taskCaptor
.
getValue
().
getCreatedTime
(),
record
.
getCreatedTime
()));
ArgumentCaptor
<
NotificationPublishDTO
>
messageCaptor
=
ArgumentCaptor
.
forClass
(
NotificationPublishDTO
.
class
);
ArgumentCaptor
<
NotificationPublishDTO
>
messageCaptor
=
ArgumentCaptor
.
forClass
(
NotificationPublishDTO
.
class
);
verify
(
notificationPublisher
).
publish
(
messageCaptor
.
capture
(),
eq
(
"A1"
),
eq
(
"管理员甲"
));
verify
(
notificationPublisher
).
publish
(
messageCaptor
.
capture
(),
eq
(
"A1"
),
eq
(
"管理员甲"
));
assertEquals
(
Arrays
.
asList
(
"S1"
,
"S2"
),
messageCaptor
.
getValue
().
getRecipientUserIds
());
assertEquals
(
Arrays
.
asList
(
"S1"
,
"S2"
),
messageCaptor
.
getValue
().
getRecipientUserIds
());
...
...
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