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
ed1023e7
Commit
ed1023e7
authored
Sep 03, 2026
by
王蔡翾
Browse files
管理端实验室状态布局查看bug修复
parent
85616b85
Changes
3
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/impl/TrainingRoomBookingServiceImpl.java
View file @
ed1023e7
...
...
@@ -116,10 +116,11 @@ public class TrainingRoomBookingServiceImpl
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
List
<
TrainingRoomSeatVO
>
adminAvailability
(
String
roomId
,
String
bookingDate
,
Integer
slotCode
)
{
synchronizeBookingStatuses
();
TrainingRoomEntity
room
=
requireRoom
(
roomId
);
BookingTime
bookingTime
=
validateBookingTime
(
room
,
bookingDate
,
slotCode
,
false
);
return
trainingRoomSeatMapper
.
selectAvailability
(
roomId
,
bookingTime
.
date
.
format
(
DATE_FORMATTER
),
slotCode
);
requireRoom
(
roomId
);
LocalDate
date
=
parseDate
(
bookingDate
);
// 管理员接口用于查看布局和预约状态,不执行日期范围、开放时间及是否已开始等预约限制。
TrainingRoomTimeSlot
.
fromCode
(
slotCode
);
return
trainingRoomSeatMapper
.
selectAvailability
(
roomId
,
date
.
format
(
DATE_FORMATTER
),
slotCode
);
}
@Override
...
...
@@ -127,7 +128,7 @@ public class TrainingRoomBookingServiceImpl
public
List
<
TrainingRoomSeatVO
>
availability
(
String
roomId
,
String
bookingDate
,
Integer
slotCode
)
{
synchronizeBookingStatuses
();
TrainingRoomEntity
room
=
requireRunningRoom
(
roomId
);
BookingTime
bookingTime
=
validateBookingTime
(
room
,
bookingDate
,
slotCode
,
true
);
BookingTime
bookingTime
=
validateBookingTime
(
room
,
bookingDate
,
slotCode
);
return
trainingRoomSeatMapper
.
selectAvailability
(
roomId
,
bookingTime
.
date
.
format
(
DATE_FORMATTER
),
slotCode
);
}
...
...
@@ -146,7 +147,7 @@ public class TrainingRoomBookingServiceImpl
}
validateStudent
(
student
);
TrainingRoomEntity
room
=
requireRunningRoom
(
request
.
getRoomId
());
BookingTime
bookingTime
=
validateBookingTime
(
room
,
request
.
getBookingDate
(),
request
.
getSlotCode
()
,
true
);
BookingTime
bookingTime
=
validateBookingTime
(
room
,
request
.
getBookingDate
(),
request
.
getSlotCode
());
if
(
request
.
getSeatNo
()
==
null
||
request
.
getSeatNo
()
<
1
||
trainingRoomSeatMapper
.
selectEnabledSeat
(
room
.
getId
(),
request
.
getSeatNo
())
==
null
)
{
throw
new
BusinessException
(
"所选机位不存在"
);
...
...
@@ -323,9 +324,9 @@ public class TrainingRoomBookingServiceImpl
return
room
;
}
/** 校验只能预约今天至后天、
时段
未开始且位于实训室开放时间内。 */
/** 校验
学员
只能预约今天至后天、
尚
未开始且位于实训室开放时间内
的时段
。 */
private
BookingTime
validateBookingTime
(
TrainingRoomEntity
room
,
String
bookingDate
,
Integer
slotCode
,
boolean
rejectStartedSlot
)
{
Integer
slotCode
)
{
LocalDate
date
=
parseDate
(
bookingDate
);
LocalDate
today
=
LocalDate
.
now
(
BUSINESS_ZONE
);
if
(
date
.
isBefore
(
today
)
||
date
.
isAfter
(
today
.
plusDays
(
2
)))
{
...
...
@@ -341,7 +342,7 @@ public class TrainingRoomBookingServiceImpl
}
LocalDateTime
start
=
LocalDateTime
.
of
(
date
,
slot
.
getStartTime
());
LocalDateTime
end
=
LocalDateTime
.
of
(
date
,
slot
.
getEndTime
());
if
(
rejectStartedSlot
&&
!
start
.
isAfter
(
LocalDateTime
.
now
(
BUSINESS_ZONE
)))
{
if
(!
start
.
isAfter
(
LocalDateTime
.
now
(
BUSINESS_ZONE
)))
{
throw
new
BusinessException
(
"已开始或已结束的时段不可预约"
);
}
return
new
BookingTime
(
date
,
start
,
end
);
...
...
practical-business/src/main/resources/training-room-layout-api.md
View file @
ed1023e7
...
...
@@ -34,6 +34,9 @@
`GET /training/room/admin/{roomId}/seats?bookingDate=2026-08-31&slotCode=1`
管理端接口用于查看实验室布局和预约状态,可查询已经开始或已经结束的日期、时段,
不会执行学员端的可预约时间限制。
学员端:
`GET /training/room/student/{roomId}/seats?bookingDate=2026-08-31&slotCode=1`
...
...
practical-business/src/test/java/com/platform/business/service/impl/TrainingRoomBookingServiceImplTest.java
0 → 100644
View file @
ed1023e7
package
com.platform.business.service.impl
;
import
com.platform.business.mapper.TrainingRoomBookingMapper
;
import
com.platform.business.mapper.TrainingRoomSeatMapper
;
import
com.platform.business.model.entity.TrainingRoomEntity
;
import
com.platform.business.model.vo.TrainingRoomSeatVO
;
import
com.platform.business.service.TrainingRoomService
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.util.Collections
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertSame
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 管理员机位状态查询与学员预约校验边界测试。 */
@ExtendWith
(
MockitoExtension
.
class
)
class
TrainingRoomBookingServiceImplTest
{
@Mock
private
TrainingRoomBookingMapper
bookingMapper
;
@Mock
private
TrainingRoomSeatMapper
seatMapper
;
@Mock
private
TrainingRoomService
roomService
;
private
TrainingRoomBookingServiceImpl
service
;
@BeforeEach
void
setUp
()
{
service
=
new
TrainingRoomBookingServiceImpl
();
ReflectionTestUtils
.
setField
(
service
,
"baseMapper"
,
bookingMapper
);
ReflectionTestUtils
.
setField
(
service
,
"trainingRoomSeatMapper"
,
seatMapper
);
ReflectionTestUtils
.
setField
(
service
,
"trainingRoomService"
,
roomService
);
// 查询机位前会补偿预约状态;空集合表示本次测试没有待更新记录。
when
(
bookingMapper
.
selectDueBooked
(
org
.
mockito
.
ArgumentMatchers
.
any
()))
.
thenReturn
(
Collections
.
emptyList
());
when
(
bookingMapper
.
selectDueUsing
(
org
.
mockito
.
ArgumentMatchers
.
any
()))
.
thenReturn
(
Collections
.
emptyList
());
}
@Test
void
adminAvailabilityShouldReturnLayoutForEndedSlot
()
{
String
roomId
=
"room-1"
;
// 与生产代码使用同一业务时区,避免测试环境时区不同导致日期边界偶发失败。
String
endedDate
=
LocalDate
.
now
(
ZoneId
.
of
(
"Asia/Shanghai"
)).
minusDays
(
1
).
toString
();
TrainingRoomEntity
room
=
new
TrainingRoomEntity
();
room
.
setId
(
roomId
);
List
<
TrainingRoomSeatVO
>
expected
=
Collections
.
singletonList
(
new
TrainingRoomSeatVO
());
when
(
roomService
.
getById
(
roomId
)).
thenReturn
(
room
);
when
(
seatMapper
.
selectAvailability
(
roomId
,
endedDate
,
1
)).
thenReturn
(
expected
);
List
<
TrainingRoomSeatVO
>
result
=
service
.
adminAvailability
(
roomId
,
endedDate
,
1
);
// 已结束时段仍应返回实验室布局和机位状态,不能套用学员预约时间限制。
assertSame
(
expected
,
result
);
verify
(
seatMapper
).
selectAvailability
(
roomId
,
endedDate
,
1
);
}
}
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