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
b5d4d905
Commit
b5d4d905
authored
Sep 08, 2026
by
王蔡翾
Browse files
短信消息接入其他模块
parent
c1404eed
Changes
3
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/impl/LeaveManagementServiceImpl.java
View file @
b5d4d905
...
...
@@ -346,13 +346,15 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
.
le
(
ClassSubjectEntity:
:
getDate
,
dayEnd
));
Date
now
=
new
Date
();
List
<
ClassSubjectEntity
>
matched
=
candidates
.
stream
()
.
filter
(
subject
->
overlaps
(
ClassSubjectTimeUtils
.
resolve
(
subject
),
request
.
getStartTime
(),
request
.
getEndTime
()))
.
filter
(
subject
->
overlapsAnyFrame
(
subject
,
request
.
getStartTime
(),
request
.
getEndTime
()))
.
sorted
(
Comparator
.
comparing
(
subject
->
ClassSubjectTimeUtils
.
resolve
(
subject
).
getStart
()))
.
collect
(
Collectors
.
toList
());
if
(
matched
.
isEmpty
())
{
throw
new
BusinessException
(
"请假时间内没有需要出勤的课程"
);
}
if
(
matched
.
stream
().
anyMatch
(
subject
->
!
ClassSubjectTimeUtils
.
resolve
(
subject
).
getStart
().
after
(
now
)))
{
if
(
matched
.
stream
().
anyMatch
(
subject
->
overlappingFrameHasStarted
(
subject
,
request
.
getStartTime
(),
request
.
getEndTime
(),
now
)))
{
throw
new
BusinessException
(
"不能为已经开始或结束的课程补交请假"
);
}
return
matched
;
...
...
@@ -508,6 +510,20 @@ public class LeaveManagementServiceImpl implements LeaveManagementService {
return
window
.
getStart
().
before
(
end
)
&&
window
.
getEnd
().
after
(
start
);
}
/** 多时段课程逐段判断,请假落在课间空档时不能关联该课程及其授课教师。 */
static
boolean
overlapsAnyFrame
(
ClassSubjectEntity
subject
,
Date
start
,
Date
end
)
{
return
ClassSubjectTimeUtils
.
resolveAll
(
subject
).
stream
()
.
anyMatch
(
window
->
overlaps
(
window
,
start
,
end
));
}
/** 只检查与本次请假真正重叠的时段,不能因同一课程较早的其他时段已开始而误判。 */
private
static
boolean
overlappingFrameHasStarted
(
ClassSubjectEntity
subject
,
Date
start
,
Date
end
,
Date
now
)
{
return
ClassSubjectTimeUtils
.
resolveAll
(
subject
).
stream
()
.
filter
(
window
->
overlaps
(
window
,
start
,
end
))
.
anyMatch
(
window
->
!
window
.
getStart
().
after
(
now
));
}
/** 返回指定日期的当天起点,用于缩小候选课程查询范围。 */
private
static
Date
startOfDay
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
...
...
practical-business/src/main/java/com/platform/business/util/ClassSubjectTimeUtils.java
View file @
b5d4d905
...
...
@@ -10,7 +10,10 @@ import java.time.LocalTime;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeParseException
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
/** 将课程日期和timeFrame文本解析成可比较的计划开始、结束时间。 */
public
final
class
ClassSubjectTimeUtils
{
...
...
@@ -25,14 +28,31 @@ public final class ClassSubjectTimeUtils {
* 多段时段取最早开始和最晚结束,例如09:00-10:00,10:30-12:00解析为09:00-12:00。
*/
public
static
TimeWindow
resolve
(
ClassSubjectEntity
subject
)
{
List
<
TimeWindow
>
windows
=
resolveAll
(
subject
);
Date
latestEnd
=
windows
.
get
(
0
).
getEnd
();
for
(
TimeWindow
window
:
windows
)
{
if
(
window
.
getEnd
().
after
(
latestEnd
))
{
latestEnd
=
window
.
getEnd
();
}
}
return
new
TimeWindow
(
windows
.
get
(
0
).
getStart
(),
latestEnd
);
}
/**
* 将课程的每个实际授课时段分别解析为时间窗口。
*
* <p>请假等需要精确判断时间重叠的业务必须使用本方法,不能把多个时段之间的休息时间
* 也视为授课时间;只关心课程整体起止边界的签到、评价等业务可以继续使用{@link #resolve}。</p>
*/
public
static
List
<
TimeWindow
>
resolveAll
(
ClassSubjectEntity
subject
)
{
if
(
subject
==
null
||
subject
.
getDate
()
==
null
||
subject
.
getTimeFrame
()
==
null
||
subject
.
getTimeFrame
().
trim
().
isEmpty
())
{
throw
new
BusinessException
(
"课程日期或上课时段未配置"
);
}
LocalDate
date
=
Instant
.
ofEpochMilli
(
subject
.
getDate
().
getTime
())
.
atZone
(
ZoneId
.
systemDefault
()).
toLocalDate
();
LocalTime
earliest
=
null
;
L
ocalTime
latest
=
null
;
ZoneId
zone
=
ZoneId
.
systemDefault
()
;
L
ist
<
TimeWindow
>
windows
=
new
ArrayList
<>()
;
String
normalized
=
subject
.
getTimeFrame
().
replace
(
'—'
,
'-'
).
replace
(
'–'
,
'-'
);
for
(
String
frame
:
normalized
.
split
(
","
))
{
String
[]
times
=
frame
.
trim
().
split
(
"-"
,
-
1
);
...
...
@@ -45,23 +65,18 @@ public final class ClassSubjectTimeUtils {
if
(!
end
.
isAfter
(
start
))
{
throw
new
BusinessException
(
"课程结束时间必须晚于开始时间"
);
}
if
(
earliest
==
null
||
start
.
isBefore
(
earliest
))
{
earliest
=
start
;
}
if
(
latest
==
null
||
end
.
isAfter
(
latest
))
{
latest
=
end
;
}
windows
.
add
(
new
TimeWindow
(
Date
.
from
(
LocalDateTime
.
of
(
date
,
start
).
atZone
(
zone
).
toInstant
()),
Date
.
from
(
LocalDateTime
.
of
(
date
,
end
).
atZone
(
zone
).
toInstant
())));
}
catch
(
DateTimeParseException
e
)
{
throw
new
BusinessException
(
"课程时段格式不正确,应为 HH:mm-HH:mm"
);
}
}
if
(
earliest
==
null
||
latest
==
null
)
{
if
(
windows
.
isEmpty
()
)
{
throw
new
BusinessException
(
"课程时段格式不正确,应为 HH:mm-HH:mm"
);
}
ZoneId
zone
=
ZoneId
.
systemDefault
();
return
new
TimeWindow
(
Date
.
from
(
LocalDateTime
.
of
(
date
,
earliest
).
atZone
(
zone
).
toInstant
()),
Date
.
from
(
LocalDateTime
.
of
(
date
,
latest
).
atZone
(
zone
).
toInstant
()));
windows
.
sort
(
Comparator
.
comparing
(
TimeWindow:
:
getStart
));
return
windows
;
}
/** 不可变的课程计划时间窗口。 */
...
...
practical-business/src/test/java/com/platform/business/service/impl/LeaveManagementNotificationTest.java
View file @
b5d4d905
...
...
@@ -12,11 +12,14 @@ import org.mockito.InjectMocks;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
java.sql.Timestamp
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -49,6 +52,20 @@ class LeaveManagementNotificationTest {
assertNull
(
messageCaptor
.
getValue
().
getRecipientRoleNames
());
}
@Test
void
leavePeriodShouldNotMatchGapBetweenCourseFrames
()
{
ClassSubjectEntity
subject
=
subject
(
"teacher-1"
);
subject
.
setDate
(
Timestamp
.
valueOf
(
"2099-09-18 00:00:00"
));
subject
.
setTimeFrame
(
"09:00-10:00,14:00-15:00"
);
assertFalse
(
LeaveManagementServiceImpl
.
overlapsAnyFrame
(
subject
,
Timestamp
.
valueOf
(
"2099-09-18 11:00:00"
),
Timestamp
.
valueOf
(
"2099-09-18 12:00:00"
)));
assertTrue
(
LeaveManagementServiceImpl
.
overlapsAnyFrame
(
subject
,
Timestamp
.
valueOf
(
"2099-09-18 14:30:00"
),
Timestamp
.
valueOf
(
"2099-09-18 14:45:00"
)));
}
@Test
void
reviewShouldSendSeparateAdminOpinionOnlyWhenApproved
()
{
LeaveApplicationVO
leave
=
leave
();
...
...
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