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
14515178
Commit
14515178
authored
Sep 04, 2026
by
王蔡翾
Browse files
bug修复
parent
98b2beaf
Changes
7
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/entity/TrainingRoomEntity.java
View file @
14515178
package
com.platform.business.model.entity
;
import
com.baomidou.mybatisplus.annotation.FieldFill
;
import
com.baomidou.mybatisplus.annotation.FieldStrategy
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
...
...
@@ -54,9 +55,19 @@ public class TrainingRoomEntity {
@TableField
(
"layout_columns"
)
private
Integer
layoutColumns
;
/** 负责人用户ID,关联 user.id。 */
@TableField
(
"manager_id"
)
private
String
managerId
;
/**
* 管理员姓名,由新增、编辑表单的文本框直接输入,最多100个字符,不关联用户账号。
* 空字符串表示主动清空;NOT_NULL允许保存空字符串,也避免仅更新状态时覆盖联系人。
*/
@TableField
(
value
=
"manager_name"
,
updateStrategy
=
FieldStrategy
.
NOT_NULL
)
private
String
managerName
;
/**
* 联系电话,由文本框直接输入,最多50个字符,保留前导零、区号、加号和分机信息。
* 与管理员姓名一起由DTO接收、VO回显;使用字符串存储,不限定为手机号。
*/
@TableField
(
value
=
"manager_phone"
,
updateStrategy
=
FieldStrategy
.
NOT_NULL
)
private
String
managerPhone
;
/** running:运行中,disabled:已停用。 */
private
String
status
;
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/TrainingRoomVO.java
View file @
14515178
...
...
@@ -9,12 +9,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
TrainingRoomVO
extends
TrainingRoomEntity
{
/** 实训室管理员姓名。 */
private
String
managerName
;
/** 实训室管理员手机号。 */
private
String
managerPhone
;
/** 当前时刻正在使用的机位数。 */
private
Integer
currentUsingCount
;
...
...
practical-business/src/main/java/com/platform/business/service/impl/TrainingRoomServiceImpl.java
View file @
14515178
...
...
@@ -5,12 +5,10 @@ import com.platform.business.constant.TrainingRoomConstants;
import
com.platform.business.mapper.TrainingRoomMapper
;
import
com.platform.business.model.dto.TrainingRoomDTO
;
import
com.platform.business.model.entity.TrainingRoomEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.TrainingRoomStatisticsVO
;
import
com.platform.business.model.vo.TrainingRoomVO
;
import
com.platform.business.service.TrainingRoomSeatService
;
import
com.platform.business.service.TrainingRoomService
;
import
com.platform.business.service.UserService
;
import
com.platform.exception.BusinessException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -36,9 +34,6 @@ public class TrainingRoomServiceImpl extends ServiceImpl<TrainingRoomMapper, Tra
@Resource
private
TrainingRoomSeatService
trainingRoomSeatService
;
@Resource
private
UserService
userService
;
@Override
public
List
<
TrainingRoomVO
>
adminList
(
TrainingRoomDTO
query
,
Date
now
)
{
normalizeQuery
(
query
,
false
);
...
...
@@ -177,7 +172,7 @@ public class TrainingRoomServiceImpl extends ServiceImpl<TrainingRoomMapper, Tra
if
(
room
.
getArea
()
!=
null
&&
room
.
getArea
().
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
throw
new
BusinessException
(
"实训室面积不能小于0"
);
}
validateManager
(
room
.
getManagerId
()
);
normalizeManagerContact
(
room
);
boolean
allDay
=
Boolean
.
TRUE
.
equals
(
room
.
getAllDay
());
room
.
setAllDay
(
allDay
);
...
...
@@ -218,15 +213,22 @@ public class TrainingRoomServiceImpl extends ServiceImpl<TrainingRoomMapper, Tra
room
.
setSeatCount
((
int
)
calculatedSeatCount
);
}
/** 管理员字段可以为空;有值时必须关联到有效的user.id。 */
private
void
validateManager
(
String
managerId
)
{
if
(!
StringUtils
.
hasText
(
managerId
))
{
return
;
/**
* 管理员和联系电话均按独立文本保存,沿用原管理员可为空的规则,不再查询用户表。
* 去除首尾空白后校验数据库字段长度;电话保留原文本,以支持座机、国际区号和分机。
* 空值统一为空字符串,使编辑时能真正清空旧联系人,避免ORM忽略null更新。
*/
private
void
normalizeManagerContact
(
TrainingRoomDTO
room
)
{
String
managerName
=
room
.
getManagerName
()
==
null
?
""
:
room
.
getManagerName
().
trim
();
String
managerPhone
=
room
.
getManagerPhone
()
==
null
?
""
:
room
.
getManagerPhone
().
trim
();
if
(
managerName
.
length
()
>
100
)
{
throw
new
BusinessException
(
"实训室管理员姓名不能超过100个字符"
);
}
UserEntity
manager
=
userService
.
getById
(
managerId
);
if
(
manager
==
null
||
Boolean
.
TRUE
.
equals
(
manager
.
getDelFlag
()))
{
throw
new
BusinessException
(
"实训室管理员不存在"
);
if
(
managerPhone
.
length
()
>
50
)
{
throw
new
BusinessException
(
"实训室联系电话不能超过50个字符"
);
}
room
.
setManagerName
(
managerName
);
room
.
setManagerPhone
(
managerPhone
);
}
/** 实训室状态仅允许running和disabled。 */
...
...
@@ -262,7 +264,8 @@ public class TrainingRoomServiceImpl extends ServiceImpl<TrainingRoomMapper, Tra
target
.
setSeatCount
(
source
.
getSeatCount
());
target
.
setLayoutRows
(
source
.
getLayoutRows
());
target
.
setLayoutColumns
(
source
.
getLayoutColumns
());
target
.
setManagerId
(
StringUtils
.
hasText
(
source
.
getManagerId
())
?
source
.
getManagerId
().
trim
()
:
null
);
target
.
setManagerName
(
source
.
getManagerName
());
target
.
setManagerPhone
(
source
.
getManagerPhone
());
target
.
setRemark
(
StringUtils
.
hasText
(
source
.
getRemark
())
?
source
.
getRemark
().
trim
()
:
null
);
return
target
;
}
...
...
practical-business/src/main/resources/com/platform/business/mapper/TrainingRoomMapper.xml
View file @
14515178
...
...
@@ -2,15 +2,14 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.platform.business.mapper.TrainingRoomMapper"
>
<!-- 当前使用数仅统计
using
,未来 booked 不占用当前机位
。 -->
<!--
联系人直接读取实训室文本字段,供列表和编辑详情回显;
当前使用数仅统计using。 -->
<sql
id=
"roomColumns"
>
r.id, r.name, r.location, r.area,
r.all_day AS allDay, r.open_start AS openStart, r.open_end AS openEnd,
r.seat_count AS seatCount,
r.layout_rows AS layoutRows, r.layout_columns AS layoutColumns,
r.manager_
id
AS manager
Id
, r.status, r.remark,
r.manager_
name AS managerName, r.manager_phone
AS manager
Phone
, r.status, r.remark,
r.create_time AS createTime, r.update_time AS updateTime,
manager.nick_name AS managerName, manager.phone_number AS managerPhone,
(SELECT COUNT(1) FROM training_room_booking current_booking
WHERE current_booking.room_id = r.id AND current_booking.status = 'using'
AND current_booking.del_flag = 0) AS currentUsingCount,
...
...
@@ -52,7 +51,6 @@
<select
id=
"selectAdminList"
resultType=
"com.platform.business.model.vo.TrainingRoomVO"
>
SELECT
<include
refid=
"roomColumns"
/>
FROM training_room r
LEFT JOIN user manager ON manager.id = r.manager_id AND manager.del_flag = 0
WHERE r.del_flag = 0
<include
refid=
"roomFilters"
/>
ORDER BY r.create_time DESC, r.id DESC
...
...
@@ -62,7 +60,6 @@
<select
id=
"selectStudentList"
resultType=
"com.platform.business.model.vo.TrainingRoomVO"
>
SELECT
<include
refid=
"roomColumns"
/>
FROM training_room r
LEFT JOIN user manager ON manager.id = r.manager_id AND manager.del_flag = 0
WHERE r.del_flag = 0 AND r.status = 'running'
<if
test=
"query.keyword != null and query.keyword != ''"
>
AND (r.name LIKE CONCAT('%', #{query.keyword}, '%')
...
...
@@ -78,7 +75,6 @@
<select
id=
"selectDetail"
resultType=
"com.platform.business.model.vo.TrainingRoomVO"
>
SELECT
<include
refid=
"roomColumns"
/>
FROM training_room r
LEFT JOIN user manager ON manager.id = r.manager_id AND manager.del_flag = 0
WHERE r.id = #{id} AND r.del_flag = 0
</select>
...
...
practical-business/src/main/resources/sql/training_room_contact.sql
0 → 100644
View file @
14515178
-- 实训室管理员与联系电话改为独立文本字段(MySQL 5.7+/8.0)。
-- 部署应用前执行:历史联系人从原关联账号回填,之后不再随账号资料变化。
-- 保留manager_id历史列以避免破坏既有数据,新版接口不再读写或依赖该列。
delimiter
$$
drop
procedure
if
exists
migrate_training_room_contact
$$
create
procedure
migrate_training_room_contact
()
begin
if
not
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
and
table_name
=
'training_room'
and
column_name
=
'manager_name'
)
then
alter
table
training_room
add
column
manager_name
varchar
(
100
)
null
comment
'管理员姓名,文本输入'
;
end
if
;
if
not
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
and
table_name
=
'training_room'
and
column_name
=
'manager_phone'
)
then
alter
table
training_room
add
column
manager_phone
varchar
(
50
)
null
comment
'联系电话,文本输入'
;
end
if
;
if
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
and
table_name
=
'training_room'
and
column_name
=
'manager_id'
)
then
-- 只填充尚未迁移的NULL字段:重复执行不会覆盖手工修改或主动清空的空字符串。
-- 与原列表查询保持一致,仅迁移未删除账号的姓名和电话。
update
training_room
r
inner
join
user
manager
on
manager
.
id
=
r
.
manager_id
and
manager
.
del_flag
=
0
set
r
.
manager_name
=
coalesce
(
r
.
manager_name
,
manager
.
nick_name
),
r
.
manager_phone
=
coalesce
(
r
.
manager_phone
,
manager
.
phone_number
)
where
r
.
manager_name
is
null
or
r
.
manager_phone
is
null
;
end
if
;
end
$$
call
migrate_training_room_contact
()
$$
drop
procedure
if
exists
migrate_training_room_contact
$$
delimiter
;
practical-business/src/main/resources/training-room-layout-api.md
View file @
14515178
# 实训室结构化布局接口说明
# 实训室
管理与
结构化布局接口说明
布局不再使用
`layoutDescription`
文本,而是使用整数字段
`layoutRows`
和
`layoutColumns`
。
`seatCount`
由服务端按两者乘积计算,请求可以不传;如果传入,
...
...
@@ -14,7 +14,9 @@
"location"
:
"A101"
,
"allDay"
:
true
,
"layoutRows"
:
3
,
"layoutColumns"
:
4
"layoutColumns"
:
4
,
"managerName"
:
"张老师"
,
"managerPhone"
:
"010-12345678 转 8001"
}
```
...
...
@@ -24,10 +26,30 @@
{
"seatCount"
:
12
,
"layoutRows"
:
3
,
"layoutColumns"
:
4
"layoutColumns"
:
4
,
"managerName"
:
"张老师"
,
"managerPhone"
:
"010-12345678 转 8001"
}
```
## 新增、编辑管理员与联系电话
-
新增:
`POST /training/room/admin`
。
-
编辑:
`PUT /training/room/admin`
,提交完整表单并带上实训室
`id`
。
-
编辑回显:
`GET /training/room/admin/{id}`
;管理员端、学员端列表也返回相同联系人字段。
前端新增和编辑表单均使用两个普通文本框(
`input type="text"`
):
| 标签 | 绑定字段 | 最大长度 | 说明 |
| --- | --- | --- | --- |
| 管理员 |
`managerName`
| 100 | 直接输入姓名,不需要选择系统用户 |
| 联系电话 |
`managerPhone`
| 50 | 按字符串提交,支持手机号、座机、国际区号及分机 |
两项沿用原管理员非必填规则;服务端去除首尾空白,空值保存为空字符串。
编辑提交空字符串、
`null`
或省略字段均会清空对应值,因此前端须将详情中的两个字段
绑定到表单后一起提交。旧数据尚无联系人时,文本框以空字符串回显。
接口不再使用
`managerId`
,联系电话不再从系统用户资料读取。
## 查询机位状态
管理端:
...
...
@@ -78,3 +100,7 @@
部署新版本前执行
`sql/training_room_layout.sql`
。脚本会将可识别的旧布局文本转为
行列数,然后删除
`layout_description`
字段。
联系人字段变更需在部署应用前执行
`sql/training_room_contact.sql`
。
脚本新增
`manager_name`
、
`manager_phone`
并从原有效用户账号回填历史联系人;重复执行
不会覆盖已录入或已清空的文本。历史
`manager_id`
列保留,但新版应用不再读写。
practical-business/src/test/java/com/platform/business/service/impl/TrainingRoomServiceImplTest.java
View file @
14515178
...
...
@@ -4,23 +4,26 @@ import com.platform.business.mapper.TrainingRoomMapper;
import
com.platform.business.model.dto.TrainingRoomDTO
;
import
com.platform.business.model.entity.TrainingRoomEntity
;
import
com.platform.business.service.TrainingRoomSeatService
;
import
com.platform.business.service.UserService
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.params.ParameterizedTest
;
import
org.junit.jupiter.params.provider.CsvSource
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoInteractions
;
import
static
org
.
mockito
.
Mockito
.
when
;
/** 实训室结构化布局
校验和机位同步
测试。 */
/** 实训室结构化布局
、手工联系人保存及编辑清空行为
测试。 */
@ExtendWith
(
MockitoExtension
.
class
)
class
TrainingRoomServiceImplTest
{
...
...
@@ -28,9 +31,6 @@ class TrainingRoomServiceImplTest {
private
TrainingRoomMapper
mapper
;
@Mock
private
TrainingRoomSeatService
seatService
;
@Mock
private
UserService
userService
;
private
TrainingRoomServiceImpl
service
;
@BeforeEach
...
...
@@ -38,12 +38,14 @@ class TrainingRoomServiceImplTest {
service
=
new
TrainingRoomServiceImpl
();
ReflectionTestUtils
.
setField
(
service
,
"baseMapper"
,
mapper
);
ReflectionTestUtils
.
setField
(
service
,
"trainingRoomSeatService"
,
seatService
);
ReflectionTestUtils
.
setField
(
service
,
"userService"
,
userService
);
}
@Test
void
createRoomShouldDeriveSeatCountFromRowsAndColumns
()
{
TrainingRoomDTO
request
=
room
(
3
,
4
);
// 管理员无需存在系统账号,电话作为文本保留区号、前导零和分机。
request
.
setManagerName
(
" 校外管理员 "
);
request
.
setManagerPhone
(
" +86 010-12345678 转 008 "
);
when
(
mapper
.
countSameName
(
"结构化布局实训室"
,
null
)).
thenReturn
(
0
);
when
(
mapper
.
insert
(
any
(
TrainingRoomEntity
.
class
))).
thenReturn
(
1
);
...
...
@@ -56,6 +58,8 @@ class TrainingRoomServiceImplTest {
assertEquals
(
3
,
saved
.
getLayoutRows
());
assertEquals
(
4
,
saved
.
getLayoutColumns
());
assertEquals
(
12
,
saved
.
getSeatCount
());
assertEquals
(
"校外管理员"
,
saved
.
getManagerName
());
assertEquals
(
"+86 010-12345678 转 008"
,
saved
.
getManagerPhone
());
// 机位编号仍保持1至行列乘积的连续编号,供预约状态查询使用。
verify
(
seatService
).
synchronizeSeats
(
saved
.
getId
(),
12
);
}
...
...
@@ -71,7 +75,77 @@ class TrainingRoomServiceImplTest {
assertEquals
(
"机位总数必须等于布局行数乘以列数"
,
exception
.
getMessage
());
}
/** 构造全天开放的最小有效实训室请求,使测试仅聚焦布局规则。 */
/** 编辑必须写入新联系人;空字符串、空白和null都必须能清空已保存的旧值。 */
@ParameterizedTest
@CsvSource
({
"' 新管理员 ', ' 0371-01234567 转 008 ', 新管理员, '0371-01234567 转 008'"
,
"'', '', '', ''"
,
"' ', ' ', '', ''"
,
", , '', ''"
})
void
updateRoomShouldSaveOrClearContactText
(
String
name
,
String
phone
,
String
expectedName
,
String
expectedPhone
)
{
TrainingRoomDTO
request
=
room
(
3
,
4
);
request
.
setId
(
"room-1"
);
request
.
setManagerName
(
name
);
request
.
setManagerPhone
(
phone
);
TrainingRoomEntity
current
=
room
(
3
,
4
);
current
.
setId
(
request
.
getId
());
current
.
setSeatCount
(
12
);
current
.
setStatus
(
"running"
);
current
.
setManagerName
(
"原管理员"
);
current
.
setManagerPhone
(
"010-11111111"
);
when
(
mapper
.
selectById
(
request
.
getId
())).
thenReturn
(
current
);
when
(
mapper
.
updateById
(
any
(
TrainingRoomEntity
.
class
))).
thenReturn
(
1
);
service
.
updateRoom
(
request
);
ArgumentCaptor
<
TrainingRoomEntity
>
captor
=
ArgumentCaptor
.
forClass
(
TrainingRoomEntity
.
class
);
verify
(
mapper
).
updateById
(
captor
.
capture
());
assertEquals
(
expectedName
,
captor
.
getValue
().
getManagerName
());
assertEquals
(
expectedPhone
,
captor
.
getValue
().
getManagerPhone
());
assertEquals
(
"running"
,
captor
.
getValue
().
getStatus
());
}
/** 按数据库列长度拒绝超长输入,避免截断联系人信息后仍提示保存成功。 */
@ParameterizedTest
@CsvSource
({
"101, 50, 实训室管理员姓名不能超过100个字符"
,
"100, 51, 实训室联系电话不能超过50个字符"
})
void
createRoomShouldRejectContactBeyondColumnLength
(
int
nameLength
,
int
phoneLength
,
String
message
)
{
TrainingRoomDTO
request
=
room
(
3
,
4
);
request
.
setManagerName
(
String
.
join
(
""
,
java
.
util
.
Collections
.
nCopies
(
nameLength
,
"张"
)));
request
.
setManagerPhone
(
String
.
join
(
""
,
java
.
util
.
Collections
.
nCopies
(
phoneLength
,
"0"
)));
BusinessException
exception
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
createRoom
(
request
));
assertEquals
(
message
,
exception
.
getMessage
());
verifyNoInteractions
(
mapper
,
seatService
);
}
/** 状态操作只更新状态,联系人保持null以便ORM跳过,防止误清空原联系人。 */
@Test
void
updateStatusShouldNotWriteContactFields
()
{
TrainingRoomEntity
current
=
room
(
3
,
4
);
current
.
setId
(
"room-1"
);
current
.
setStatus
(
"running"
);
current
.
setManagerName
(
"管理员"
);
current
.
setManagerPhone
(
"010-12345678"
);
when
(
mapper
.
selectById
(
current
.
getId
())).
thenReturn
(
current
);
when
(
mapper
.
updateById
(
any
(
TrainingRoomEntity
.
class
))).
thenReturn
(
1
);
service
.
updateStatus
(
current
.
getId
(),
"disabled"
);
ArgumentCaptor
<
TrainingRoomEntity
>
captor
=
ArgumentCaptor
.
forClass
(
TrainingRoomEntity
.
class
);
verify
(
mapper
).
updateById
(
captor
.
capture
());
assertEquals
(
"disabled"
,
captor
.
getValue
().
getStatus
());
assertNull
(
captor
.
getValue
().
getManagerName
());
assertNull
(
captor
.
getValue
().
getManagerPhone
());
}
/** 构造全天开放的最小有效实训室请求,兼容联系人未填写的原有用法。 */
private
TrainingRoomDTO
room
(
int
rows
,
int
columns
)
{
TrainingRoomDTO
room
=
new
TrainingRoomDTO
();
room
.
setName
(
"结构化布局实训室"
);
...
...
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