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
9e0dacc7
Commit
9e0dacc7
authored
Aug 10, 2026
by
wujipeng
Browse files
Merge remote-tracking branch 'origin/dev-v1.0' into dev-v1.0
parents
4ff3e0e4
1ea1a030
Changes
91
Expand all
Show whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/ClassSubjectAttendanceSessionService.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.entity.ClassSubjectAttendanceSessionEntity
;
public
interface
ClassSubjectAttendanceSessionService
extends
IService
<
ClassSubjectAttendanceSessionEntity
>
{
}
practical-business/src/main/java/com/platform/business/service/LeaveManagementService.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service
;
import
com.platform.business.model.dto.LeaveApplyDTO
;
import
com.platform.business.model.dto.LeaveQueryDTO
;
import
com.platform.business.model.dto.LeaveReviewDTO
;
import
com.platform.business.model.vo.LeaveApplicationVO
;
import
java.util.List
;
public
interface
LeaveManagementService
{
LeaveApplicationVO
apply
(
LeaveApplyDTO
request
,
String
studentId
);
LeaveApplicationVO
update
(
LeaveApplyDTO
request
,
String
studentId
);
boolean
withdraw
(
String
leaveId
,
String
studentId
);
LeaveApplicationVO
review
(
String
leaveId
,
LeaveReviewDTO
request
,
String
approverId
,
String
approverRole
);
List
<
LeaveApplicationVO
>
queryApplications
(
LeaveQueryDTO
query
);
LeaveApplicationVO
studentDetail
(
String
leaveId
,
String
studentId
);
LeaveApplicationVO
teacherDetail
(
String
leaveId
,
String
teacherId
);
LeaveApplicationVO
adminDetail
(
String
leaveId
);
}
practical-business/src/main/java/com/platform/business/service/TeachingResourceService.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.TeachingResourceDTO
;
import
com.platform.business.model.entity.TeachingResourceEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.TeachingResourceStatisticsVO
;
import
com.platform.business.model.vo.TeachingResourceVO
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
/**
* 教学资源业务接口,分别提供管理员全量视角和学生本人班级视角。
*/
public
interface
TeachingResourceService
extends
IService
<
TeachingResourceEntity
>
{
/** 查询管理员端资源列表。 */
List
<
TeachingResourceVO
>
adminList
(
TeachingResourceDTO
query
);
/** 查询指定学生所在班级课程关联的资源列表。 */
List
<
TeachingResourceVO
>
studentList
(
String
userId
,
TeachingResourceDTO
query
);
/** 统计所有未删除的教学资源。 */
TeachingResourceStatisticsVO
adminStatistics
();
/** 统计指定学生有权查看的教学资源。 */
TeachingResourceStatisticsVO
studentStatistics
(
String
userId
);
/** 上传文件并创建与课程绑定的教学资源记录。 */
TeachingResourceVO
upload
(
MultipartFile
file
,
String
resourceName
,
Integer
courseId
,
UserEntity
uploader
);
/** 只修改资源名称及绑定课程,不替换文件。 */
boolean
updateResource
(
TeachingResourceDTO
resource
);
/** 同时逻辑删除教学资源记录和文件记录,保留物理文件。 */
boolean
deleteResource
(
String
id
);
/** 管理员下载资源并累计下载次数。 */
void
adminDownload
(
String
id
);
/** 校验学生班级课程权限后下载资源并累计下载次数。 */
void
studentDownload
(
String
id
,
String
userId
);
}
practical-business/src/main/java/com/platform/business/service/TrainingRoomBookingService.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.TrainingRoomBookingCreateDTO
;
import
com.platform.business.model.dto.TrainingRoomBookingDTO
;
import
com.platform.business.model.entity.TrainingRoomBookingEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.TrainingRoomBookingDetailVO
;
import
com.platform.business.model.vo.TrainingRoomBookingStatisticsVO
;
import
com.platform.business.model.vo.TrainingRoomBookingVO
;
import
com.platform.business.model.vo.TrainingRoomSeatVO
;
import
com.platform.business.model.vo.TrainingRoomTimeSlotVO
;
import
java.util.List
;
/** 学员与管理员共用的预约业务服务。 */
public
interface
TrainingRoomBookingService
extends
IService
<
TrainingRoomBookingEntity
>
{
/** 管理员分页查询全部预约记录。 */
List
<
TrainingRoomBookingVO
>
adminList
(
TrainingRoomBookingDTO
query
);
/** 学员分页查询自己的预约记录。 */
List
<
TrainingRoomBookingVO
>
studentList
(
String
studentId
,
TrainingRoomBookingDTO
query
);
/** 管理员查看预约详情和完整操作记录。 */
TrainingRoomBookingDetailVO
adminDetail
(
String
id
);
/** 学员查看自己的预约详情和操作记录。 */
TrainingRoomBookingDetailVO
studentDetail
(
String
id
,
String
studentId
);
/** 获取指定实训室各预约状态的统计数量。 */
TrainingRoomBookingStatisticsVO
adminStatistics
(
String
roomId
);
/** 管理员查看指定日期和时段的机位状态,已停用实训室也可查看。 */
List
<
TrainingRoomSeatVO
>
adminAvailability
(
String
roomId
,
String
bookingDate
,
Integer
slotCode
);
/** 学员查看运行中实训室在可预约日期、时段下的全部机位状态。 */
List
<
TrainingRoomSeatVO
>
availability
(
String
roomId
,
String
bookingDate
,
Integer
slotCode
);
/** 获取系统支持的五个固定预约时段。 */
List
<
TrainingRoomTimeSlotVO
>
timeSlots
();
/** 创建预约,并执行机位冲突、学员冲突和数据库并发约束校验。 */
TrainingRoomBookingVO
createBooking
(
TrainingRoomBookingCreateDTO
request
,
UserEntity
student
);
/** 学员取消本人尚未开始的预约。 */
boolean
studentCancel
(
String
id
,
UserEntity
student
);
/** 学员提前结束本人使用中的预约。 */
boolean
studentSignOut
(
String
id
,
UserEntity
student
);
/** 管理员取消尚未开始的预约。 */
boolean
adminCancel
(
String
id
,
UserEntity
administrator
);
/** 管理员结束使用中的预约。 */
boolean
adminEnd
(
String
id
,
UserEntity
administrator
);
/** 定时任务和查询入口共同调用,用于补偿更新预约状态。 */
void
synchronizeBookingStatuses
();
}
practical-business/src/main/java/com/platform/business/service/TrainingRoomSeatService.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.entity.TrainingRoomSeatEntity
;
/** 机位基础数据服务。 */
public
interface
TrainingRoomSeatService
extends
IService
<
TrainingRoomSeatEntity
>
{
/** 按新的机位总数启用、停用或补充编号连续的机位。 */
void
synchronizeSeats
(
String
roomId
,
Integer
seatCount
);
}
practical-business/src/main/java/com/platform/business/service/TrainingRoomService.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.TrainingRoomDTO
;
import
com.platform.business.model.entity.TrainingRoomEntity
;
import
com.platform.business.model.vo.TrainingRoomStatisticsVO
;
import
com.platform.business.model.vo.TrainingRoomVO
;
import
java.util.Date
;
import
java.util.List
;
/** 实训室管理服务。 */
public
interface
TrainingRoomService
extends
IService
<
TrainingRoomEntity
>
{
/** 管理员分页查询实训室,包含运行中和已停用状态。 */
List
<
TrainingRoomVO
>
adminList
(
TrainingRoomDTO
query
,
Date
now
);
/** 学员分页查询运行中的实训室。 */
List
<
TrainingRoomVO
>
studentList
(
TrainingRoomDTO
query
,
Date
now
);
/** 查询实训室详情及当前动态机位统计。 */
TrainingRoomVO
detail
(
String
id
,
Date
now
);
/** 获取管理员端实训室KPI。 */
TrainingRoomStatisticsVO
adminStatistics
(
Date
now
);
/** 获取学员端运行中实训室KPI。 */
TrainingRoomStatisticsVO
studentStatistics
(
Date
now
);
/** 创建实训室并同步生成连续机位编号。 */
TrainingRoomVO
createRoom
(
TrainingRoomDTO
room
);
/** 编辑实训室基本信息并同步机位数量。 */
boolean
updateRoom
(
TrainingRoomDTO
room
);
/** 单独启用或停用实训室;停用前检查未结束预约。 */
boolean
updateStatus
(
String
id
,
String
status
);
}
practical-business/src/main/java/com/platform/business/service/impl/AttendanceServiceImpl.java
0 → 100644
View file @
9e0dacc7
This diff is collapsed.
Click to expand it.
practical-business/src/main/java/com/platform/business/service/impl/BsFileServiceImpl.java
View file @
9e0dacc7
...
@@ -5,71 +5,133 @@ import com.platform.business.mapper.BsFileMapper;
...
@@ -5,71 +5,133 @@ import com.platform.business.mapper.BsFileMapper;
import
com.platform.business.model.entity.BsFileEntity
;
import
com.platform.business.model.entity.BsFileEntity
;
import
com.platform.business.service.BsFileService
;
import
com.platform.business.service.BsFileService
;
import
com.platform.exception.BusinessException
;
import
com.platform.exception.BusinessException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.UUID
;
/**
@Slf4j
* 本地文件存储实现。
* 使用随机存储名避免同名覆盖,数据库保留原始文件名用于下载响应。
*/
@Service
@Service
public
class
BsFileServiceImpl
extends
ServiceImpl
<
BsFileMapper
,
BsFileEntity
>
implements
BsFileService
{
public
class
BsFileServiceImpl
extends
ServiceImpl
<
BsFileMapper
,
BsFileEntity
>
implements
BsFileService
{
private
static
final
String
PREFIX
=
"/home/back/practical-train/file/"
;
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
BsFileServiceImpl
.
class
);
@Value
(
"${business.file.upload-dir:/home/back/practical-train/file}"
)
private
String
uploadDirectory
;
@Resource
private
HttpServletResponse
response
;
@Override
@Override
public
BsFileEntity
uploadFile
(
MultipartFile
file
)
{
public
BsFileEntity
uploadFile
(
MultipartFile
file
)
{
if
(
file
.
isEmpty
())
{
// 业务层校验500MB上限,防止容器上传限制被其他配置覆盖后失效。
throw
new
BusinessException
(
"文件为空"
);
if
(
file
==
null
||
file
.
isEmpty
())
{
throw
new
BusinessException
(
"上传文件不能为空"
);
}
if
(
file
.
getSize
()
>
MAX_FILE_SIZE
)
{
throw
new
BusinessException
(
"单个文件不能超过500MB"
);
}
}
try
{
try
{
//获取时间戳,保证不重复
// 创建并规范化上传目录,所有目标文件必须位于该目录之下。
// String time = System.currentTimeMillis() + "/";
Path
directory
=
Paths
.
get
(
uploadDirectory
).
toAbsolutePath
().
normalize
();
// 确保上传目录存在
Files
.
createDirectories
(
directory
);
// File uploadDir = new File(PREFIX + time);
File
uploadDir
=
new
File
(
PREFIX
);
// 原始文件名只用于展示;磁盘使用UUID文件名,避免重名覆盖和路径穿越。
if
(!
uploadDir
.
exists
())
{
String
originalFilename
=
safeOriginalFilename
(
file
.
getOriginalFilename
());
boolean
mkdir
=
uploadDir
.
mkdirs
();
String
storedFilename
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)
log
.
info
(
"创建文件夹"
+
mkdir
);
+
getExtension
(
originalFilename
);
Path
target
=
directory
.
resolve
(
storedFilename
).
normalize
();
if
(!
target
.
startsWith
(
directory
))
{
throw
new
BusinessException
(
"文件保存路径非法"
);
}
}
// 保存文件到本地
// transferTo 直接流式落盘,避免大文件一次性加载到JVM内存。
// Path path = Paths.get(PREFIX + time + file.getOriginalFilename());
file
.
transferTo
(
target
.
toFile
());
Path
path
=
Paths
.
get
(
PREFIX
+
file
.
getOriginalFilename
());
Files
.
write
(
path
,
file
.
getBytes
());
//获取文件名
String
fileName
=
file
.
getOriginalFilename
();
//获取文件绝对路径
String
fileUrl
=
path
.
toAbsolutePath
().
toString
();
BsFileEntity
bsFile
=
BsFileEntity
.
builder
().
url
(
fileUrl
).
fileName
(
fileName
).
build
();
save
(
bsFile
);
return
bsFile
;
// 文件写入成功后保存元数据;数据库保存失败时清理本次产生的物理文件。
BsFileEntity
bsFile
=
BsFileEntity
.
builder
()
.
url
(
target
.
toString
())
.
fileName
(
originalFilename
)
.
delFlag
(
0
)
.
build
();
if
(!
save
(
bsFile
))
{
Files
.
deleteIfExists
(
target
);
throw
new
BusinessException
(
"文件信息保存失败"
);
}
return
bsFile
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"文件上传失败"
,
e
);
throw
new
BusinessException
(
"文件上传失败"
);
throw
new
BusinessException
(
"文件上传失败"
);
}
}
}
}
@Resource
private
HttpServletResponse
response
;
@Override
@Override
public
void
downloadFile
(
Integer
id
)
{
public
void
downloadFile
(
Integer
id
)
{
try
{
// getById 会自动附带 del_flag=0 条件,已逻辑删除的文件不可下载。
BsFileEntity
bsFile
=
getById
(
id
);
BsFileEntity
bsFile
=
getById
(
id
);
String
url
=
bsFile
.
getUrl
();
if
(
bsFile
==
null
||
!
StringUtils
.
hasText
(
bsFile
.
getUrl
()))
{
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
url
));
throw
new
BusinessException
(
"文件不存在或已删除"
);
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
URLEncoder
.
encode
(
bsFile
.
getFileName
(),
"utf-8"
));
}
response
.
getOutputStream
().
write
(
bytes
);
try
{
Path
path
=
Paths
.
get
(
bsFile
.
getUrl
()).
toAbsolutePath
().
normalize
();
if
(!
Files
.
isRegularFile
(
path
))
{
throw
new
BusinessException
(
"文件不存在或已删除"
);
}
String
contentType
=
Files
.
probeContentType
(
path
);
response
.
setContentType
(
StringUtils
.
hasText
(
contentType
)
?
contentType
:
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
);
response
.
setContentLengthLong
(
Files
.
size
(
path
));
String
encodedFilename
=
URLEncoder
.
encode
(
safeDownloadFilename
(
bsFile
.
getFileName
()),
StandardCharsets
.
UTF_8
.
name
()).
replace
(
"+"
,
"%20"
);
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename*=UTF-8''"
+
encodedFilename
);
// 以流的方式复制到响应,支持接近500MB的大文件且不占用同等堆内存。
Files
.
copy
(
path
,
response
.
getOutputStream
());
response
.
getOutputStream
().
flush
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"文件下载失败,文件ID:{}"
,
id
,
e
);
throw
new
BusinessException
(
"文件下载失败"
);
throw
new
BusinessException
(
"文件下载失败"
);
}
}
}
}
/** 去除客户端路径信息和换行符,仅保留安全的原始文件名。 */
private
String
safeOriginalFilename
(
String
originalFilename
)
{
if
(!
StringUtils
.
hasText
(
originalFilename
))
{
return
"unnamed-file"
;
}
String
normalized
=
originalFilename
.
replace
(
'\\'
,
'/'
);
String
filename
=
normalized
.
substring
(
normalized
.
lastIndexOf
(
'/'
)
+
1
).
trim
();
filename
=
safeDownloadFilename
(
filename
);
return
StringUtils
.
hasText
(
filename
)
?
filename
:
"unnamed-file"
;
}
/** 移除响应头文件名中的换行符,防止响应头注入。 */
private
String
safeDownloadFilename
(
String
filename
)
{
if
(
filename
==
null
)
{
return
"unnamed-file"
;
}
return
filename
.
replace
(
"\r"
,
""
).
replace
(
"\n"
,
""
);
}
/** 保留原始扩展名,使磁盘文件仍可被系统识别类型。 */
private
String
getExtension
(
String
filename
)
{
int
dotIndex
=
filename
.
lastIndexOf
(
'.'
);
return
dotIndex
>=
0
?
filename
.
substring
(
dotIndex
)
:
""
;
}
}
}
practical-business/src/main/java/com/platform/business/service/impl/ClassServiceImpl.java
View file @
9e0dacc7
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.platform.business.mapper.ClassMapper
;
import
com.platform.business.mapper.ClassMapper
;
import
com.platform.business.constant.AttendanceConstants
;
import
com.platform.business.model.dto.CalendarDTO
;
import
com.platform.business.model.dto.CalendarDTO
;
import
com.platform.business.model.dto.ClassDTO
;
import
com.platform.business.model.dto.ClassDTO
;
import
com.platform.business.model.dto.ClassSubjectDTO
;
import
com.platform.business.model.dto.ClassSubjectDTO
;
...
@@ -13,6 +14,7 @@ import com.platform.business.model.entity.ClassSubjectAttendanceEntity;
...
@@ -13,6 +14,7 @@ import com.platform.business.model.entity.ClassSubjectAttendanceEntity;
import
com.platform.business.model.entity.SysLevelEntity
;
import
com.platform.business.model.entity.SysLevelEntity
;
import
com.platform.business.model.vo.*
;
import
com.platform.business.model.vo.*
;
import
com.platform.business.service.*
;
import
com.platform.business.service.*
;
import
com.platform.business.util.ClassSubjectTimeUtils
;
import
com.platform.exception.BusinessException
;
import
com.platform.exception.BusinessException
;
import
com.platform.utils.DozerUtils
;
import
com.platform.utils.DozerUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -103,15 +105,16 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
...
@@ -103,15 +105,16 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectList
)
{
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectList
)
{
if
(
classSubjectVO
.
getDate
().
equals
(
date
))
{
if
(
classSubjectVO
.
getDate
().
equals
(
date
))
{
//判断状态
//判断状态
if
(
isBeforeMinTime
(
now
,
classSubjectVO
.
getDate
(),
classSubjectVO
.
getTimeFrame
()))
{
ClassSubjectTimeUtils
.
TimeWindow
window
=
ClassSubjectTimeUtils
.
resolve
(
classSubjectVO
);
if
(
now
.
before
(
window
.
getStart
()))
{
classSubjectVO
.
setStatus
(
classSubjectVO
.
getType
());
classSubjectVO
.
setStatus
(
classSubjectVO
.
getType
());
}
else
{
}
else
if
(
classSubjectAttendanceMap
.
containsKey
(
classSubjectVO
.
getId
()))
{
if
(
classSubjectAttendanceMap
.
containsKey
(
classSubjectVO
.
getId
()))
{
classSubjectVO
.
setStatus
(
displayAttendanceStatus
(
classSubjectAttendanceMap
.
get
(
classSubjectVO
.
getId
()).
getStatus
()));
classSubjectVO
.
setStatus
(
"已签到"
);
}
else
if
(
now
.
before
(
window
.
getEnd
()))
{
classSubjectVO
.
setStatus
(
"待签到"
);
}
else
{
}
else
{
classSubjectVO
.
setStatus
(
"缺勤"
);
classSubjectVO
.
setStatus
(
"缺勤"
);
}
}
}
classSubjectChildList
.
add
(
classSubjectVO
);
classSubjectChildList
.
add
(
classSubjectVO
);
}
}
}
}
...
@@ -144,16 +147,17 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
...
@@ -144,16 +147,17 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
//设置状态
//设置状态
for
(
ClassSubjectVO
classSubjectVO
:
data
)
{
for
(
ClassSubjectVO
classSubjectVO
:
data
)
{
//判断状态
//判断状态
if
(
isBeforeMinTime
(
now
,
classSubjectVO
.
getDate
(),
classSubjectVO
.
getTimeFrame
()))
{
ClassSubjectTimeUtils
.
TimeWindow
window
=
ClassSubjectTimeUtils
.
resolve
(
classSubjectVO
);
if
(
now
.
before
(
window
.
getStart
()))
{
classSubjectVO
.
setStatus
(
classSubjectVO
.
getType
());
classSubjectVO
.
setStatus
(
classSubjectVO
.
getType
());
}
else
{
}
else
if
(
classSubjectAttendanceMap
.
containsKey
(
classSubjectVO
.
getId
()))
{
if
(
classSubjectAttendanceMap
.
containsKey
(
classSubjectVO
.
getId
()))
{
classSubjectVO
.
setStatus
(
displayAttendanceStatus
(
classSubjectAttendanceMap
.
get
(
classSubjectVO
.
getId
()).
getStatus
()));
classSubjectVO
.
setStatus
(
"已签到"
);
}
else
if
(
now
.
before
(
window
.
getEnd
()))
{
classSubjectVO
.
setStatus
(
"待签到"
);
}
else
{
}
else
{
classSubjectVO
.
setStatus
(
"缺勤"
);
classSubjectVO
.
setStatus
(
"缺勤"
);
}
}
}
}
}
result
.
setData
(
data
);
result
.
setData
(
data
);
result
.
setSubjectNum
(
data
.
size
());
result
.
setSubjectNum
(
data
.
size
());
return
result
;
return
result
;
...
@@ -261,16 +265,20 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
...
@@ -261,16 +265,20 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
List
<
ClassSubjectAttendanceEntity
>
classSubjectAttendanceList
=
classSubjectAttendanceService
.
list
(
List
<
ClassSubjectAttendanceEntity
>
classSubjectAttendanceList
=
classSubjectAttendanceService
.
list
(
new
LambdaQueryWrapper
<
ClassSubjectAttendanceEntity
>().
eq
(
ClassSubjectAttendanceEntity:
:
getUserId
,
userId
)
new
LambdaQueryWrapper
<
ClassSubjectAttendanceEntity
>().
eq
(
ClassSubjectAttendanceEntity:
:
getUserId
,
userId
)
);
);
HashMap
<
Integer
,
Date
>
classSubjectAttendanceMap
=
new
HashMap
<>();
HashMap
<
Integer
,
ClassSubjectAttendanceEntity
>
classSubjectAttendanceMap
=
new
HashMap
<>();
for
(
ClassSubjectAttendanceEntity
classSubjectAttendanceEntity
:
classSubjectAttendanceList
)
{
for
(
ClassSubjectAttendanceEntity
classSubjectAttendanceEntity
:
classSubjectAttendanceList
)
{
classSubjectAttendanceMap
.
put
(
classSubjectAttendanceEntity
.
getSubjectId
(),
classSubjectAttendanceEntity
.
getCheckInTime
()
);
classSubjectAttendanceMap
.
put
(
classSubjectAttendanceEntity
.
getSubjectId
(),
classSubjectAttendanceEntity
);
}
}
for
(
CalendarVO
calendarVO
:
result
)
{
for
(
CalendarVO
calendarVO
:
result
)
{
if
(
classSubjectAttendanceMap
.
containsKey
(
calendarVO
.
getSubjectId
()))
{
if
(
classSubjectAttendanceMap
.
containsKey
(
calendarVO
.
getSubjectId
()))
{
calendarVO
.
setSignInTime
(
classSubjectAttendanceMap
.
get
(
calendarVO
.
getSubjectId
()));
ClassSubjectAttendanceEntity
attendance
=
classSubjectAttendanceMap
.
get
(
calendarVO
.
getSubjectId
());
calendarVO
.
setIsSignIn
(
true
);
calendarVO
.
setSignInTime
(
attendance
.
getCheckInTime
());
calendarVO
.
setAttendanceStatus
(
attendance
.
getStatus
());
calendarVO
.
setCheckInMethod
(
attendance
.
getCheckInMethod
());
calendarVO
.
setIsSignIn
(
AttendanceConstants
.
isPresent
(
attendance
.
getStatus
()));
}
else
{
}
else
{
calendarVO
.
setIsSignIn
(
false
);
calendarVO
.
setIsSignIn
(
false
);
calendarVO
.
setAttendanceStatus
(
"PENDING"
);
}
}
}
}
return
result
;
return
result
;
...
@@ -278,11 +286,7 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
...
@@ -278,11 +286,7 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
@Override
@Override
public
Boolean
todayCourseSignIn
(
CalendarDTO
calendarDTO
)
{
public
Boolean
todayCourseSignIn
(
CalendarDTO
calendarDTO
)
{
ClassSubjectAttendanceEntity
classSubjectAttendance
=
new
ClassSubjectAttendanceEntity
();
throw
new
BusinessException
(
"原签到接口已停用,请使用 /attendance/student/check-in 完成IP和验证码校验"
);
classSubjectAttendance
.
setUserId
(
calendarDTO
.
getUserId
());
classSubjectAttendance
.
setSubjectId
(
calendarDTO
.
getSubjectId
());
classSubjectAttendance
.
setCheckInTime
(
new
Date
());
return
classSubjectAttendanceService
.
save
(
classSubjectAttendance
);
}
}
@Override
@Override
...
@@ -297,15 +301,49 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
...
@@ -297,15 +301,49 @@ public class ClassServiceImpl extends ServiceImpl<ClassMapper, ClassEntity> impl
HashMap
<
String
,
Integer
>
result
=
new
HashMap
<>();
HashMap
<
String
,
Integer
>
result
=
new
HashMap
<>();
//本月课程
//本月课程
result
.
put
(
"本月课程"
,
classSubjectList
.
size
());
result
.
put
(
"本月课程"
,
classSubjectList
.
size
());
//已签到
Map
<
Integer
,
ClassSubjectAttendanceEntity
>
attendanceMap
=
new
HashMap
<>();
result
.
put
(
"已签到"
,
classSubjectAttendanceList
.
size
());
for
(
ClassSubjectAttendanceEntity
attendance
:
classSubjectAttendanceList
)
{
//待签到
attendanceMap
.
put
(
attendance
.
getSubjectId
(),
attendance
);
result
.
put
(
"待签到"
,
classSubjectList
.
size
()
-
classSubjectAttendanceList
.
size
());
}
//出勤率
int
normal
=
0
;
result
.
put
(
"出勤率"
,
classSubjectAttendanceList
.
size
()
/
classSubjectList
.
size
());
int
late
=
0
;
int
absent
=
0
;
int
leave
=
0
;
int
pending
=
0
;
Date
now
=
new
Date
();
for
(
ClassSubjectVO
subject
:
classSubjectList
)
{
ClassSubjectAttendanceEntity
attendance
=
attendanceMap
.
get
(
subject
.
getId
());
if
(
attendance
!=
null
)
{
if
(
AttendanceConstants
.
STATUS_NORMAL
.
equals
(
attendance
.
getStatus
()))
normal
++;
else
if
(
AttendanceConstants
.
STATUS_LATE
.
equals
(
attendance
.
getStatus
()))
late
++;
else
if
(
AttendanceConstants
.
STATUS_ABSENT
.
equals
(
attendance
.
getStatus
()))
absent
++;
else
if
(
AttendanceConstants
.
STATUS_LEAVE
.
equals
(
attendance
.
getStatus
()))
leave
++;
}
else
if
(
now
.
before
(
ClassSubjectTimeUtils
.
resolve
(
subject
).
getEnd
()))
{
pending
++;
}
else
{
absent
++;
}
}
int
signed
=
normal
+
late
;
int
finished
=
signed
+
absent
+
leave
;
result
.
put
(
"已签到"
,
signed
);
result
.
put
(
"正常签到"
,
normal
);
result
.
put
(
"迟到"
,
late
);
result
.
put
(
"缺勤"
,
absent
);
result
.
put
(
"请假"
,
leave
);
result
.
put
(
"待签到"
,
pending
);
result
.
put
(
"出勤率"
,
finished
==
0
?
0
:
(
int
)
Math
.
round
(
signed
*
100.0
/
finished
));
return
result
;
return
result
;
}
}
private
static
String
displayAttendanceStatus
(
String
status
)
{
if
(
AttendanceConstants
.
STATUS_NORMAL
.
equals
(
status
))
return
"已签到"
;
if
(
AttendanceConstants
.
STATUS_LATE
.
equals
(
status
))
return
"迟到"
;
if
(
AttendanceConstants
.
STATUS_ABSENT
.
equals
(
status
))
return
"缺勤"
;
if
(
AttendanceConstants
.
STATUS_LEAVE
.
equals
(
status
))
return
"请假"
;
return
"已签到"
;
}
/**
/**
* 方法2: 使用SimpleDateFormat格式化比较
* 方法2: 使用SimpleDateFormat格式化比较
* 将日期格式化为"yyyyMMdd"后比较字符串
* 将日期格式化为"yyyyMMdd"后比较字符串
...
...
practical-business/src/main/java/com/platform/business/service/impl/ClassSubjectAttendanceSessionServiceImpl.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.ClassSubjectAttendanceSessionMapper
;
import
com.platform.business.model.entity.ClassSubjectAttendanceSessionEntity
;
import
com.platform.business.service.ClassSubjectAttendanceSessionService
;
import
org.springframework.stereotype.Service
;
@Service
public
class
ClassSubjectAttendanceSessionServiceImpl
extends
ServiceImpl
<
ClassSubjectAttendanceSessionMapper
,
ClassSubjectAttendanceSessionEntity
>
implements
ClassSubjectAttendanceSessionService
{
}
practical-business/src/main/java/com/platform/business/service/impl/LeaveManagementServiceImpl.java
0 → 100644
View file @
9e0dacc7
This diff is collapsed.
Click to expand it.
practical-business/src/main/java/com/platform/business/service/impl/TeachingResourceServiceImpl.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.TeachingResourceMapper
;
import
com.platform.business.model.dto.TeachingResourceDTO
;
import
com.platform.business.model.entity.BsFileEntity
;
import
com.platform.business.model.entity.ClassSubjectEntity
;
import
com.platform.business.model.entity.TeachingResourceEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.TeachingResourceStatisticsVO
;
import
com.platform.business.model.vo.TeachingResourceVO
;
import
com.platform.business.service.BsFileService
;
import
com.platform.business.service.ClassSubjectService
;
import
com.platform.business.service.TeachingResourceService
;
import
com.platform.exception.BusinessException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Set
;
/**
* 教学资源核心业务实现。
*
* <p>管理员查询全部资源;学生查询及下载时,均根据当前用户所在班级和
* {@code class_subject.class_id} 限制资源范围。</p>
*/
@Service
public
class
TeachingResourceServiceImpl
extends
ServiceImpl
<
TeachingResourceMapper
,
TeachingResourceEntity
>
implements
TeachingResourceService
{
/** 文件扩展名与原型资源类型之间的映射。未知扩展名统一归为 other。 */
private
static
final
Set
<
String
>
DOCUMENT_EXTENSIONS
=
Collections
.
unmodifiableSet
(
new
HashSet
<>(
Arrays
.
asList
(
"pdf"
,
"doc"
,
"docx"
,
"xls"
,
"xlsx"
,
"ppt"
,
"pptx"
,
"txt"
,
"csv"
)));
private
static
final
Set
<
String
>
VIDEO_EXTENSIONS
=
Collections
.
unmodifiableSet
(
new
HashSet
<>(
Arrays
.
asList
(
"mp4"
,
"avi"
,
"mov"
,
"wmv"
,
"flv"
,
"mkv"
,
"m4v"
,
"webm"
)));
private
static
final
Set
<
String
>
IMAGE_EXTENSIONS
=
Collections
.
unmodifiableSet
(
new
HashSet
<>(
Arrays
.
asList
(
"jpg"
,
"jpeg"
,
"png"
,
"gif"
,
"bmp"
,
"webp"
,
"svg"
)));
private
static
final
Set
<
String
>
RESOURCE_TYPES
=
Collections
.
unmodifiableSet
(
new
HashSet
<>(
Arrays
.
asList
(
"all"
,
"doc"
,
"video"
,
"image"
,
"other"
)));
@Resource
private
BsFileService
bsFileService
;
@Resource
private
ClassSubjectService
classSubjectService
;
@Override
public
List
<
TeachingResourceVO
>
adminList
(
TeachingResourceDTO
query
)
{
// 统一清洗关键字和资源类型,避免各查询入口出现不同筛选规则。
normalizeQuery
(
query
);
return
baseMapper
.
selectAdminList
(
query
);
}
@Override
public
List
<
TeachingResourceVO
>
studentList
(
String
userId
,
TeachingResourceDTO
query
)
{
requireUserId
(
userId
);
normalizeQuery
(
query
);
// Mapper 使用 class_student 与 class_subject 关系限制学生可见范围。
return
baseMapper
.
selectStudentList
(
userId
,
query
);
}
@Override
public
TeachingResourceStatisticsVO
adminStatistics
()
{
return
baseMapper
.
selectAdminStatistics
();
}
@Override
public
TeachingResourceStatisticsVO
studentStatistics
(
String
userId
)
{
requireUserId
(
userId
);
return
baseMapper
.
selectStudentStatistics
(
userId
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
TeachingResourceVO
upload
(
MultipartFile
file
,
String
resourceName
,
Integer
courseId
,
UserEntity
uploader
)
{
// 第一步:先校验展示名称和课程ID,保证资源绑定的是有效 ClassSubjectEntity。
validateResourceName
(
resourceName
);
ClassSubjectEntity
course
=
requireCourse
(
courseId
);
if
(
file
==
null
||
file
.
isEmpty
())
{
throw
new
BusinessException
(
"上传文件不能为空"
);
}
if
(
uploader
==
null
||
!
StringUtils
.
hasText
(
uploader
.
getId
()))
{
throw
new
BusinessException
(
"无法获取当前上传用户"
);
}
// 第二步:根据原始文件扩展名确定类型,再保存文件并取得 bs_file.id。
String
resourceType
=
resolveResourceType
(
file
.
getOriginalFilename
());
BsFileEntity
storedFile
=
bsFileService
.
uploadFile
(
file
);
// 第三步:保存资源业务信息。String 主键由 ASSIGN_ID 雪花算法自动填充。
TeachingResourceEntity
resource
=
new
TeachingResourceEntity
();
resource
.
setFileId
(
storedFile
.
getId
());
resource
.
setResourceName
(
resourceName
.
trim
());
resource
.
setResourceType
(
resourceType
);
resource
.
setCourseId
(
course
.
getId
());
resource
.
setFileSize
(
file
.
getSize
());
resource
.
setUploaderId
(
uploader
.
getId
());
resource
.
setUploaderName
(
resolveUploaderName
(
uploader
));
resource
.
setDownloadCount
(
0L
);
resource
.
setDelFlag
(
0
);
if
(!
save
(
resource
))
{
throw
new
BusinessException
(
"教学资源保存失败"
);
}
// 返回包含课程名、班级名的完整展示对象,上传后前端可直接刷新列表。
return
baseMapper
.
selectAdminById
(
resource
.
getId
());
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
boolean
updateResource
(
TeachingResourceDTO
resource
)
{
// 编辑接口不接收新文件,只允许更新原型要求的资源名称和课程ID。
if
(
resource
==
null
||
resource
.
getId
()
==
null
)
{
throw
new
BusinessException
(
"资源ID不能为空"
);
}
validateResourceName
(
resource
.
getResourceName
());
requireCourse
(
resource
.
getCourseId
());
requireResource
(
resource
.
getId
());
TeachingResourceEntity
update
=
new
TeachingResourceEntity
();
update
.
setId
(
resource
.
getId
());
update
.
setResourceName
(
resource
.
getResourceName
().
trim
());
update
.
setCourseId
(
resource
.
getCourseId
());
if
(!
updateById
(
update
))
{
throw
new
BusinessException
(
"教学资源更新失败"
);
}
return
true
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
boolean
deleteResource
(
String
id
)
{
// 删除前同时确认资源和文件记录存在,避免出现只删除一侧的不一致状态。
TeachingResourceEntity
resource
=
requireResource
(
id
);
BsFileEntity
storedFile
=
bsFileService
.
getById
(
resource
.
getFileId
());
if
(
storedFile
==
null
)
{
throw
new
BusinessException
(
"资源文件不存在或已删除"
);
}
// 两个实体均配置 @TableLogic,此处只更新删除标记,不删除磁盘物理文件。
if
(!
removeById
(
id
))
{
throw
new
BusinessException
(
"教学资源删除失败"
);
}
if
(!
bsFileService
.
removeById
(
resource
.
getFileId
()))
{
throw
new
BusinessException
(
"资源文件删除失败"
);
}
return
true
;
}
@Override
public
void
adminDownload
(
String
id
)
{
TeachingResourceEntity
resource
=
requireResource
(
id
);
downloadAndCount
(
resource
);
}
@Override
public
void
studentDownload
(
String
id
,
String
userId
)
{
requireUserId
(
userId
);
TeachingResourceEntity
resource
=
requireResource
(
id
);
// 列表过滤不能代替下载鉴权,防止学生通过猜测资源ID越权下载。
if
(
baseMapper
.
countStudentResource
(
id
,
userId
)
==
0
)
{
throw
new
BusinessException
(
"无权下载非本人班级课程的资源"
);
}
downloadAndCount
(
resource
);
}
/**
* 文件流成功写出后原子递增下载次数;写出失败时不会累计。
*/
private
void
downloadAndCount
(
TeachingResourceEntity
resource
)
{
bsFileService
.
downloadFile
(
resource
.
getFileId
());
if
(
baseMapper
.
incrementDownloadCount
(
resource
.
getId
())
!=
1
)
{
throw
new
BusinessException
(
"下载次数更新失败"
);
}
}
/** 查询未逻辑删除的资源,不存在时统一抛出业务异常。 */
private
TeachingResourceEntity
requireResource
(
String
id
)
{
if
(!
StringUtils
.
hasText
(
id
))
{
throw
new
BusinessException
(
"资源ID不能为空"
);
}
TeachingResourceEntity
resource
=
getById
(
id
);
if
(
resource
==
null
)
{
throw
new
BusinessException
(
"教学资源不存在或已删除"
);
}
return
resource
;
}
/** 校验上传或编辑时绑定的课程ID真实存在。 */
private
ClassSubjectEntity
requireCourse
(
Integer
courseId
)
{
if
(
courseId
==
null
)
{
throw
new
BusinessException
(
"适用课程不能为空"
);
}
ClassSubjectEntity
course
=
classSubjectService
.
getById
(
courseId
);
if
(
course
==
null
)
{
throw
new
BusinessException
(
"适用课程不存在"
);
}
return
course
;
}
/** 校验必填的资源展示名称及数据库字段长度。 */
private
void
validateResourceName
(
String
resourceName
)
{
if
(!
StringUtils
.
hasText
(
resourceName
))
{
throw
new
BusinessException
(
"资源名称不能为空"
);
}
if
(
resourceName
.
trim
().
length
()
>
200
)
{
throw
new
BusinessException
(
"资源名称不能超过200个字符"
);
}
}
/** 标准化列表查询参数并拒绝原型定义之外的资源类型。 */
private
void
normalizeQuery
(
TeachingResourceDTO
query
)
{
if
(
query
==
null
)
{
throw
new
BusinessException
(
"查询条件不能为空"
);
}
if
(
StringUtils
.
hasText
(
query
.
getKeyword
()))
{
query
.
setKeyword
(
query
.
getKeyword
().
trim
());
}
if
(!
StringUtils
.
hasText
(
query
.
getResourceType
()))
{
query
.
setResourceType
(
"all"
);
}
else
{
String
resourceType
=
query
.
getResourceType
().
trim
().
toLowerCase
(
Locale
.
ROOT
);
if
(!
RESOURCE_TYPES
.
contains
(
resourceType
))
{
throw
new
BusinessException
(
"不支持的资源类型"
);
}
query
.
setResourceType
(
resourceType
);
}
}
/** 根据文件扩展名自动识别 doc、video、image、other 四类资源。 */
private
String
resolveResourceType
(
String
originalFilename
)
{
if
(!
StringUtils
.
hasText
(
originalFilename
))
{
return
"other"
;
}
String
filename
=
originalFilename
.
trim
();
int
dotIndex
=
filename
.
lastIndexOf
(
'.'
);
if
(
dotIndex
<
0
||
dotIndex
==
filename
.
length
()
-
1
)
{
return
"other"
;
}
String
extension
=
filename
.
substring
(
dotIndex
+
1
).
toLowerCase
(
Locale
.
ROOT
);
if
(
DOCUMENT_EXTENSIONS
.
contains
(
extension
))
{
return
"doc"
;
}
if
(
VIDEO_EXTENSIONS
.
contains
(
extension
))
{
return
"video"
;
}
if
(
IMAGE_EXTENSIONS
.
contains
(
extension
))
{
return
"image"
;
}
return
"other"
;
}
/** 按昵称、账号、手机号顺序确定列表中展示的上传者名称。 */
private
String
resolveUploaderName
(
UserEntity
uploader
)
{
if
(
StringUtils
.
hasText
(
uploader
.
getNickName
()))
{
return
uploader
.
getNickName
();
}
if
(
StringUtils
.
hasText
(
uploader
.
getUsername
()))
{
return
uploader
.
getUsername
();
}
return
uploader
.
getPhoneNumber
();
}
/** 学生数据范围查询必须使用服务端从令牌解析出的用户ID。 */
private
void
requireUserId
(
String
userId
)
{
if
(!
StringUtils
.
hasText
(
userId
))
{
throw
new
BusinessException
(
"无法获取当前学生信息"
);
}
}
}
practical-business/src/main/java/com/platform/business/service/impl/TrainingRoomBookingServiceImpl.java
0 → 100644
View file @
9e0dacc7
This diff is collapsed.
Click to expand it.
practical-business/src/main/java/com/platform/business/service/impl/TrainingRoomSeatServiceImpl.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.TrainingRoomSeatMapper
;
import
com.platform.business.model.entity.TrainingRoomSeatEntity
;
import
com.platform.business.service.TrainingRoomSeatService
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/** 机位编号同步实现。 */
@Service
public
class
TrainingRoomSeatServiceImpl
extends
ServiceImpl
<
TrainingRoomSeatMapper
,
TrainingRoomSeatEntity
>
implements
TrainingRoomSeatService
{
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
synchronizeSeats
(
String
roomId
,
Integer
seatCount
)
{
// 先读取包含停用机位在内的全部历史编号,避免扩容时重复插入相同编号。
List
<
TrainingRoomSeatEntity
>
existingSeats
=
baseMapper
.
selectAllByRoom
(
roomId
);
Set
<
Integer
>
existingNumbers
=
new
HashSet
<>();
for
(
TrainingRoomSeatEntity
seat
:
existingSeats
)
{
existingNumbers
.
add
(
seat
.
getSeatNo
());
}
// 扩容时先恢复曾被停用的编号,缩容时停用超出范围的编号。
baseMapper
.
enableSeatsUpTo
(
roomId
,
seatCount
);
baseMapper
.
disableSeatsAbove
(
roomId
,
seatCount
);
List
<
TrainingRoomSeatEntity
>
newSeats
=
new
ArrayList
<>();
// 仅补充数据库中从未创建过的编号,所有新增ID由MyBatis-Plus生成字符串雪花ID。
for
(
int
seatNo
=
1
;
seatNo
<=
seatCount
;
seatNo
++)
{
if
(!
existingNumbers
.
contains
(
seatNo
))
{
TrainingRoomSeatEntity
seat
=
new
TrainingRoomSeatEntity
();
seat
.
setRoomId
(
roomId
);
seat
.
setSeatNo
(
seatNo
);
seat
.
setEnabled
(
true
);
newSeats
.
add
(
seat
);
}
}
if
(!
newSeats
.
isEmpty
())
{
saveBatch
(
newSeats
);
}
}
}
practical-business/src/main/java/com/platform/business/service/impl/TrainingRoomServiceImpl.java
0 → 100644
View file @
9e0dacc7
This diff is collapsed.
Click to expand it.
practical-business/src/main/java/com/platform/business/task/AttendanceAutoCloseTask.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.task
;
import
com.platform.business.service.AttendanceService
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
@Component
public
class
AttendanceAutoCloseTask
{
@Resource
private
AttendanceService
attendanceService
;
/** 每分钟将已结束课程中仍无签到记录的学员自动记为缺勤。 */
@Scheduled
(
cron
=
"0 * * * * ?"
)
public
void
closeEndedSubjects
()
{
attendanceService
.
finalizeEndedSubjects
(
null
,
null
);
}
}
practical-business/src/main/java/com/platform/business/util/ClassSubjectTimeUtils.java
0 → 100644
View file @
9e0dacc7
package
com.platform.business.util
;
import
com.platform.business.model.entity.ClassSubjectEntity
;
import
com.platform.exception.BusinessException
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeParseException
;
import
java.util.Date
;
public
final
class
ClassSubjectTimeUtils
{
private
static
final
DateTimeFormatter
TIME_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"H:mm"
);
private
ClassSubjectTimeUtils
()
{
}
public
static
TimeWindow
resolve
(
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
;
LocalTime
latest
=
null
;
String
normalized
=
subject
.
getTimeFrame
().
replace
(
'—'
,
'-'
).
replace
(
'–'
,
'-'
);
for
(
String
frame
:
normalized
.
split
(
","
))
{
String
[]
times
=
frame
.
trim
().
split
(
"-"
,
-
1
);
if
(
times
.
length
!=
2
)
{
continue
;
}
try
{
LocalTime
start
=
LocalTime
.
parse
(
times
[
0
].
trim
(),
TIME_FORMATTER
);
LocalTime
end
=
LocalTime
.
parse
(
times
[
1
].
trim
(),
TIME_FORMATTER
);
if
(!
end
.
isAfter
(
start
))
{
throw
new
BusinessException
(
"课程结束时间必须晚于开始时间"
);
}
if
(
earliest
==
null
||
start
.
isBefore
(
earliest
))
{
earliest
=
start
;
}
if
(
latest
==
null
||
end
.
isAfter
(
latest
))
{
latest
=
end
;
}
}
catch
(
DateTimeParseException
e
)
{
throw
new
BusinessException
(
"课程时段格式不正确,应为 HH:mm-HH:mm"
);
}
}
if
(
earliest
==
null
||
latest
==
null
)
{
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
()));
}
public
static
final
class
TimeWindow
{
private
final
Date
start
;
private
final
Date
end
;
private
TimeWindow
(
Date
start
,
Date
end
)
{
this
.
start
=
start
;
this
.
end
=
end
;
}
public
Date
getStart
()
{
return
start
;
}
public
Date
getEnd
()
{
return
end
;
}
}
}
practical-business/src/main/java/com/platform/business/util/IpNetworkMatcher.java
0 → 100644
View file @
9e0dacc7
This diff is collapsed.
Click to expand it.
practical-business/src/main/resources/attendance-api.md
0 → 100644
View file @
9e0dacc7
# 出勤管理接口
所有人员均由登录令牌解析出的用户
`id`
标识;响应中的学员、教师展示字段使用完整手机号,不使用学号或教师号。
## 教师端
-
`POST /attendance/teacher/course/{subjectId}/start`
:到达计划开始时间后开始上课。首次调用生成6位验证码;后续调用返回同一课次原验证码。
-
`GET /attendance/teacher/course/{subjectId}/roster`
:查询学员姓名、完整手机号、签到时间、方式、IP和状态。
-
`PUT /attendance/teacher/status`
:教师手动设置
`NORMAL`
、
`LATE`
或
`ABSENT`
。
状态调整请求示例:
```
json
{
"subjectId"
:
1001
,
"studentId"
:
"190000000000000001"
,
"status"
:
"LATE"
}
```
## 学员端
-
`POST /attendance/student/check-in`
:课程开始15分钟内同时校验IP和验证码;超过15分钟且未到课程结束时间时只校验IP并自动记为
`LATE`
。
-
`POST /attendance/student/records`
:查询当前登录学员的出勤记录。
签到请求示例:
```
json
{
"subjectId"
:
1001
,
"verificationCode"
:
"123456"
}
```
## 管理端
-
`POST /attendance/admin/records/page`
:按班级、课程、状态、日期范围分页查询。
-
`POST /attendance/admin/statistics`
:统计应到、正常、迟到、缺勤、请假及出勤率。管理员接口不修改出勤状态。
## IP网段配置
在配置中心为业务服务补充:
```
yaml
attendance
:
verification-code-valid-minutes
:
15
allowed-ip-cidrs
:
-
192.168.10.0/24
trust-forwarded-headers
:
false
```
`allowed-ip-cidrs`
为空时系统会拒绝签到。只有入口网关会清洗并重写转发头时,才能把
`trust-forwarded-headers`
设为
`true`
。
审批通过的请假会把所关联课程的出勤状态同步为
`LEAVE`
。统计时,请假计入应到和请假次数,但不计入出勤人数,因此会降低出勤率。
practical-business/src/main/resources/bootstrap.yml
View file @
9e0dacc7
spring
:
spring
:
profiles
:
profiles
:
active
:
dev
active
:
dev
servlet
:
multipart
:
max-file-size
:
500MB
max-request-size
:
510MB
# 出勤签到配置。allowed-ip-cidrs 为空时签到会安全拒绝,部署前请补充实际网段。
attendance
:
verification-code-valid-minutes
:
15
allowed-ip-cidrs
:
[]
# 只有网关已清洗 X-Forwarded-For / X-Real-IP 时才开启。
trust-forwarded-headers
:
false
Prev
1
2
3
4
5
Next
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