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
cd112ea9
Commit
cd112ea9
authored
Aug 03, 2026
by
wujipeng
Browse files
init
parents
Pipeline
#346
canceled with stages
Changes
327
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/TheoreticalPaperService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.CombinationDTO
;
import
com.platform.business.model.dto.TheoreticalPaperDTO
;
import
com.platform.business.model.entity.TheoreticalPaperEntity
;
import
com.platform.business.model.vo.CombinationVO
;
import
com.platform.business.model.vo.TheoreticalPaperVO
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
/**
* @author : wujipeng
* @date : 2025/11/3 14:10
* @Version: 1.0
* @Desc : 描述信息
*/
public
interface
TheoreticalPaperService
extends
IService
<
TheoreticalPaperEntity
>
{
List
<
TheoreticalPaperVO
>
pageData
(
TheoreticalPaperDTO
theoreticalPaperDTO
);
CombinationVO
auto
(
String
lev
);
Boolean
create
(
CombinationDTO
combinationDTO
);
TheoreticalPaperVO
detail
(
String
id
);
void
export
(
String
id
,
HttpServletResponse
response
);
void
exportWithAnswer
(
String
id
,
HttpServletResponse
response
);
Boolean
delete
(
String
id
);
}
practical-business/src/main/java/com/platform/business/service/TheoreticalPaperStudentDetailService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.TheoreticalPaperStudentDetailDTO
;
import
com.platform.business.model.entity.TheoreticalPaperStudentDetailEntity
;
import
com.platform.business.model.vo.TheoreticalPaperStudentDetailVO
;
import
java.util.List
;
/**
* @author : wujipeng
* @date : 2025/12/29 17:46
* @Version: 1.0
* @Desc : 描述信息
*/
public
interface
TheoreticalPaperStudentDetailService
extends
IService
<
TheoreticalPaperStudentDetailEntity
>
{
List
<
TheoreticalPaperStudentDetailVO
>
process
(
int
examId
,
String
studentId
);
TheoreticalPaperStudentDetailVO
questionDetail
(
String
id
);
TheoreticalPaperStudentDetailVO
gradesQuestionDetail
(
String
id
);
Boolean
leaveBlank
(
TheoreticalPaperStudentDetailDTO
theoreticalPaperStudentDetailDTO
);
}
practical-business/src/main/java/com/platform/business/service/TheoreticalPracticeService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.TheoreticalPracticeDTO
;
import
com.platform.business.model.entity.TheoreticalPracticeEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
import
com.platform.model.resp.Result
;
import
java.util.List
;
/**
* @author : wujipeng
* @date : 2026/4/21 10:13
* @Version: 1.0
* @Desc : 描述信息
*/
public
interface
TheoreticalPracticeService
extends
IService
<
TheoreticalPracticeEntity
>
{
List
<
TheoreticalPracticeVO
>
page
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
TheoreticalPracticeVO
detail
(
String
id
);
Result
<
Boolean
>
saveOrUpdateData
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
Boolean
close
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
}
practical-business/src/main/java/com/platform/business/service/TheoreticalPracticeStudentQuestionBankService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.TheoreticalPracticeStudentQuestionBankDTO
;
import
com.platform.business.model.entity.TheoreticalPracticeStudentQuestionBankEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentQuestionBankVO
;
import
java.util.List
;
public
interface
TheoreticalPracticeStudentQuestionBankService
extends
IService
<
TheoreticalPracticeStudentQuestionBankEntity
>
{
List
<
String
>
groupByStudentId
();
List
<
TheoreticalPracticeStudentQuestionBankVO
>
onePage
(
TheoreticalPracticeStudentQuestionBankDTO
theoreticalPracticeStudentQuestionBankDTO
);
List
<
TheoreticalPracticeStudentQuestionBankVO
>
twoPage
(
TheoreticalPracticeStudentQuestionBankDTO
theoreticalPracticeStudentQuestionBankDTO
);
List
<
TheoreticalPracticeStudentQuestionBankVO
>
overview
(
TheoreticalPracticeStudentQuestionBankDTO
theoreticalPracticeStudentQuestionBankDTO
);
TheoreticalPracticeStudentQuestionBankVO
detail
(
String
id
);
Long
countdown
();
Boolean
reAnswer
(
TheoreticalPracticeStudentQuestionBankDTO
theoreticalPracticeStudentQuestionBankDTO
);
Boolean
edit
(
TheoreticalPracticeStudentQuestionBankDTO
theoreticalPracticeStudentQuestionBankDTO
);
}
practical-business/src/main/java/com/platform/business/service/TheoreticalPracticeStudentService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.entity.TheoreticalPracticeStudentEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentVO
;
import
java.util.List
;
public
interface
TheoreticalPracticeStudentService
extends
IService
<
TheoreticalPracticeStudentEntity
>
{
List
<
TheoreticalPracticeStudentVO
>
selectStudentListByPracticeId
(
String
id
);
}
practical-business/src/main/java/com/platform/business/service/TheoreticalPracticeStudentSimulationDetailService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.entity.TheoreticalPracticeStudentSimulationDetailEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentSimulationDetailVO
;
import
java.util.List
;
public
interface
TheoreticalPracticeStudentSimulationDetailService
extends
IService
<
TheoreticalPracticeStudentSimulationDetailEntity
>
{
List
<
TheoreticalPracticeStudentSimulationDetailVO
>
numberAndScore
(
String
id
);
List
<
TheoreticalPracticeStudentSimulationDetailVO
>
paperOverview
(
String
id
,
String
type
);
void
reAnswer
(
String
id
);
TheoreticalPracticeStudentSimulationDetailVO
questionDetail
(
String
id
);
TheoreticalPracticeStudentSimulationDetailVO
gradesQuestionDetail
(
String
id
);
}
practical-business/src/main/java/com/platform/business/service/TheoreticalPracticeStudentSimulationService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.CombinationDTO
;
import
com.platform.business.model.dto.TheoreticalPracticeStudentSimulationDTO
;
import
com.platform.business.model.dto.TheoreticalPracticeStudentSimulationDetailDTO
;
import
com.platform.business.model.entity.TheoreticalPracticeStudentSimulationEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentSimulationDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentSimulationVO
;
import
java.util.List
;
import
java.util.Map
;
public
interface
TheoreticalPracticeStudentSimulationService
extends
IService
<
TheoreticalPracticeStudentSimulationEntity
>
{
List
<
TheoreticalPracticeStudentSimulationVO
>
pageData
(
TheoreticalPracticeStudentSimulationDTO
theoreticalPracticeStudentSimulationDTO
);
Boolean
create
(
CombinationDTO
combinationDTO
);
Boolean
start
(
String
id
);
Boolean
updateDetail
(
TheoreticalPracticeStudentSimulationDetailDTO
theoreticalPracticeStudentSimulationDetailDTO
);
List
<
TheoreticalPracticeStudentSimulationDetailVO
>
overview
(
String
id
);
Boolean
reAnswer
(
String
id
);
Map
<
String
,
String
>
submitCheck
(
String
id
);
Boolean
submit
(
String
id
);
TheoreticalPracticeStudentSimulationDetailVO
proceedTitleDetail
(
String
id
);
TheoreticalPracticeStudentSimulationDetailVO
analysisTitleDetail
(
String
id
);
Map
<
String
,
String
>
getPaperInformation
(
String
userName
);
}
practical-business/src/main/java/com/platform/business/service/UserService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.dto.UserDTO
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.UserVO
;
import
com.platform.model.resp.Result
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
public
interface
UserService
extends
IService
<
UserEntity
>
{
List
<
UserVO
>
queryList
(
UserDTO
userDTO
);
UserVO
detail
(
String
id
);
Object
saveOrUpdateUser
(
UserDTO
userDTO
);
Object
resetPassword
(
String
id
);
Result
studentImport
(
MultipartFile
file
);
Object
teacherImport
(
MultipartFile
file
);
Result
updatePassword
(
UserDTO
userDTO
);
UserVO
getUserMessage
(
String
userName
);
UserVO
queryByUserName
(
String
userName
);
void
closeExam
(
String
studentId
);
void
closeSimulation
(
String
studentId
);
}
practical-business/src/main/java/com/platform/business/service/UserTeacherService.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.platform.business.model.entity.UserTeacherEntity
;
import
com.platform.business.model.vo.UserTeacherVO
;
public
interface
UserTeacherService
extends
IService
<
UserTeacherEntity
>
{
UserTeacherVO
getByUserId
(
String
id
);
}
practical-business/src/main/java/com/platform/business/service/impl/BsFileServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.BsFileMapper
;
import
com.platform.business.model.entity.BsFileEntity
;
import
com.platform.business.service.BsFileService
;
import
com.platform.exception.BusinessException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
@Slf4j
@Service
public
class
BsFileServiceImpl
extends
ServiceImpl
<
BsFileMapper
,
BsFileEntity
>
implements
BsFileService
{
private
static
final
String
PREFIX
=
"/home/back/practical-train/file/"
;
@Override
public
BsFileEntity
uploadFile
(
MultipartFile
file
)
{
if
(
file
.
isEmpty
())
{
throw
new
BusinessException
(
"文件为空"
);
}
try
{
//获取时间戳,保证不重复
// String time = System.currentTimeMillis() + "/";
// 确保上传目录存在
// File uploadDir = new File(PREFIX + time);
File
uploadDir
=
new
File
(
PREFIX
);
if
(!
uploadDir
.
exists
())
{
boolean
mkdir
=
uploadDir
.
mkdirs
();
log
.
info
(
"创建文件夹"
+
mkdir
);
}
// 保存文件到本地
// Path path = Paths.get(PREFIX + time + file.getOriginalFilename());
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
;
}
catch
(
IOException
e
)
{
throw
new
BusinessException
(
"文件上传失败"
);
}
}
@Resource
private
HttpServletResponse
response
;
@Override
public
void
downloadFile
(
Integer
id
)
{
try
{
BsFileEntity
bsFile
=
getById
(
id
);
String
url
=
bsFile
.
getUrl
();
byte
[]
bytes
=
Files
.
readAllBytes
(
Paths
.
get
(
url
));
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
URLEncoder
.
encode
(
bsFile
.
getFileName
(),
"utf-8"
));
response
.
getOutputStream
().
write
(
bytes
);
}
catch
(
IOException
e
)
{
throw
new
BusinessException
(
"文件下载失败"
);
}
}
}
practical-business/src/main/java/com/platform/business/service/impl/CandidateServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.model.entity.CandidateEntity
;
import
com.platform.business.mapper.CandidateMapper
;
import
com.platform.business.service.CandidateService
;
import
org.springframework.stereotype.Service
;
/**
* @author : wujipeng
* @date : 2025/7/7 17:43
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public
class
CandidateServiceImpl
extends
ServiceImpl
<
CandidateMapper
,
CandidateEntity
>
implements
CandidateService
{
}
practical-business/src/main/java/com/platform/business/service/impl/ClassServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.platform.business.mapper.ClassMapper
;
import
com.platform.business.model.dto.ClassDTO
;
import
com.platform.business.model.entity.ClassEntity
;
import
com.platform.business.model.entity.ClassStudentEntity
;
import
com.platform.business.model.entity.SysLevelEntity
;
import
com.platform.business.model.vo.ClassStudentVO
;
import
com.platform.business.model.vo.ClassSubjectVO
;
import
com.platform.business.model.vo.ClassVO
;
import
com.platform.business.model.vo.ExamStudentVO
;
import
com.platform.business.service.*
;
import
com.platform.exception.BusinessException
;
import
com.platform.utils.DozerUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
javax.annotation.Resource
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
ClassServiceImpl
extends
ServiceImpl
<
ClassMapper
,
ClassEntity
>
implements
ClassService
{
@Resource
private
ClassStudentService
classStudentService
;
@Resource
private
ClassSubjectService
classSubjectService
;
@Resource
private
SysLevelService
sysLevelService
;
@Resource
private
ExamStudentService
examStudentService
;
@Override
public
List
<
ClassVO
>
queryList
(
ClassDTO
classDTO
)
{
return
baseMapper
.
queryList
(
classDTO
);
}
@Override
public
ClassVO
detail
(
String
id
)
{
ClassEntity
classEntity
=
getById
(
id
);
if
(
classEntity
==
null
)
{
throw
new
BusinessException
(
"班级id有误"
);
}
SysLevelEntity
sysLevel
=
sysLevelService
.
getById
(
classEntity
.
getLevel
());
if
(!
ObjectUtils
.
isEmpty
(
sysLevel
))
{
classEntity
.
setLevel
(
sysLevel
.
getName
());
}
ClassVO
classVO
=
DozerUtils
.
convertBean
(
classEntity
,
ClassVO
.
class
);
//查看班级学生
List
<
ClassStudentVO
>
classStudentVOList
=
classStudentService
.
queryList
(
id
);
classVO
.
setClassStudentList
(
classStudentVOList
);
return
classVO
;
}
@Override
public
boolean
saveClass
(
ClassDTO
classDTO
)
{
//保存班级
ClassEntity
classEntity
=
DozerUtils
.
convertBean
(
classDTO
,
ClassEntity
.
class
);
List
<
ClassStudentEntity
>
classStudentEntities
=
classDTO
.
getStudentList
();
if
(
classEntity
.
getId
()
==
null
)
{
classEntity
.
setCreateTime
(
new
Date
());
save
(
classEntity
);
}
else
{
updateById
(
classEntity
);
//先删除班级关联的学生
classStudentService
.
deleteByClassId
(
classEntity
.
getId
());
}
//保存班级学生关联
classStudentEntities
.
forEach
(
classStudentEntity
->
classStudentEntity
.
setClassId
(
classEntity
.
getId
()));
return
classStudentService
.
saveBatch
(
classStudentEntities
);
}
@Override
public
boolean
deleteStu
(
String
studentId
)
{
return
classStudentService
.
removeById
(
studentId
);
}
@Override
public
Object
schedule
(
ClassDTO
classDTO
)
{
//查询考试信息
List
<
ExamStudentVO
>
examStudentList
=
examStudentService
.
queryOneself
(
classDTO
.
getUserId
());
//TODO 加上权限
List
<
ClassSubjectVO
>
classSubjectList
=
classSubjectService
.
queryOneself
(
classDTO
.
getUserId
());
List
<
ClassVO
>
result
=
Lists
.
newArrayList
();
List
<
Date
>
dateList
=
getDatesBetweenTwoDate
(
classDTO
.
getStartDate
(),
classDTO
.
getEndDate
());
for
(
Date
date
:
dateList
)
{
ClassVO
classVO
=
new
ClassVO
();
List
<
ClassSubjectVO
>
classSubjectChildList
=
Lists
.
newArrayList
();
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectList
)
{
if
(
classSubjectVO
.
getDate
().
equals
(
date
))
{
classSubjectChildList
.
add
(
classSubjectVO
);
}
}
List
<
ExamStudentVO
>
examStudentChildList
=
Lists
.
newArrayList
();
for
(
ExamStudentVO
examStudentVO
:
examStudentList
)
{
if
(
isSameDayWithFormat
(
examStudentVO
.
getExamTime
().
split
(
"-"
)[
0
],
date
))
{
examStudentChildList
.
add
(
examStudentVO
);
}
}
classVO
.
setClassSubjectList
(
classSubjectChildList
);
classVO
.
setExamStudentList
(
examStudentChildList
);
classVO
.
setDate
(
date
);
result
.
add
(
classVO
);
}
return
result
;
}
@Override
public
Object
scheduleTeacher
(
ClassDTO
classDTO
)
{
//查询考试信息
List
<
ExamStudentVO
>
examStudentList
=
examStudentService
.
queryOneselfTeacher
(
classDTO
.
getUserId
());
//TODO 加上权限
List
<
ClassSubjectVO
>
classSubjectList
=
classSubjectService
.
queryOneself
(
classDTO
.
getUserId
());
List
<
ClassVO
>
result
=
Lists
.
newArrayList
();
List
<
Date
>
dateList
=
getDatesBetweenTwoDate
(
classDTO
.
getStartDate
(),
classDTO
.
getEndDate
());
for
(
Date
date
:
dateList
)
{
ClassVO
classVO
=
new
ClassVO
();
List
<
ClassSubjectVO
>
classSubjectChildList
=
Lists
.
newArrayList
();
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectList
)
{
if
(
classSubjectVO
.
getDate
().
equals
(
date
))
{
classSubjectChildList
.
add
(
classSubjectVO
);
}
}
List
<
ExamStudentVO
>
examStudentChildList
=
Lists
.
newArrayList
();
for
(
ExamStudentVO
examStudentVO
:
examStudentList
)
{
if
(
isSameDayWithFormat
(
examStudentVO
.
getExamTime
().
split
(
"-"
)[
0
],
date
))
{
examStudentChildList
.
add
(
examStudentVO
);
}
}
classVO
.
setClassSubjectList
(
classSubjectChildList
);
classVO
.
setExamStudentList
(
examStudentChildList
);
classVO
.
setDate
(
date
);
result
.
add
(
classVO
);
}
return
result
;
}
/**
* 方法2: 使用SimpleDateFormat格式化比较
* 将日期格式化为"yyyyMMdd"后比较字符串
*
* @param dateStr 日期字符串,格式:yyyy.MM.dd HH:mm:ss
* @param compareDate 要比较的Date对象
* @return 是否为同一天
*/
public
static
boolean
isSameDayWithFormat
(
String
dateStr
,
Date
compareDate
)
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy.MM.dd HH:mm:ss"
);
Date
inputDate
=
sdf
.
parse
(
dateStr
);
SimpleDateFormat
dayFormat
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
return
dayFormat
.
format
(
inputDate
).
equals
(
dayFormat
.
format
(
compareDate
));
}
catch
(
ParseException
e
)
{
throw
new
IllegalArgumentException
(
"日期格式错误,应为: yyyy.MM.dd HH:mm:ss"
,
e
);
}
}
/**
* 获取两个日期之间的所有日期集合 (包含开始和结束日期)
*
* @param beginDate 开始日期
* @param endDate 结束日期
* @return 包含所有日期的List集合
*/
public
static
List
<
Date
>
getDatesBetweenTwoDate
(
Date
beginDate
,
Date
endDate
)
{
List
<
Date
>
dateList
=
new
ArrayList
<>();
// 将开始日期加入集合
dateList
.
add
(
beginDate
);
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
beginDate
);
// 循环添加日期,直到超过结束日期
while
(
endDate
.
after
(
cal
.
getTime
()))
{
cal
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
// 增加一天
if
(!
endDate
.
before
(
cal
.
getTime
()))
{
dateList
.
add
(
cal
.
getTime
());
}
}
return
dateList
;
}
}
practical-business/src/main/java/com/platform/business/service/impl/ClassStudentServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.ClassStudentMapper
;
import
com.platform.business.model.entity.ClassStudentEntity
;
import
com.platform.business.model.vo.ClassStudentVO
;
import
com.platform.business.model.vo.HomeVO
;
import
com.platform.business.service.ClassStudentService
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
ClassStudentServiceImpl
extends
ServiceImpl
<
ClassStudentMapper
,
ClassStudentEntity
>
implements
ClassStudentService
{
@Override
public
List
<
ClassStudentVO
>
queryList
(
String
id
)
{
return
baseMapper
.
queryList
(
id
);
}
@Override
public
void
deleteByClassId
(
Integer
id
)
{
baseMapper
.
delete
(
new
LambdaQueryWrapper
<
ClassStudentEntity
>()
.
eq
(
ClassStudentEntity:
:
getClassId
,
id
));
}
@Override
public
List
<
HomeVO
>
selectTraineesNumber
()
{
return
baseMapper
.
selectTraineesNumber
();
}
@Override
public
List
<
HomeVO
>
todayCourse
()
{
return
baseMapper
.
todayCourse
();
}
}
practical-business/src/main/java/com/platform/business/service/impl/ClassSubjectServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
cn.hutool.core.collection.CollUtil
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.ClassSubjectMapper
;
import
com.platform.business.model.dto.ClassSubjectDTO
;
import
com.platform.business.model.entity.ClassEntity
;
import
com.platform.business.model.entity.ClassSubjectEntity
;
import
com.platform.business.model.entity.SysLevelEntity
;
import
com.platform.business.model.vo.*
;
import
com.platform.business.service.*
;
import
com.platform.exception.BusinessException
;
import
com.platform.utils.DozerUtils
;
import
com.platform.utils.StringUtils
;
import
org.apache.poi.xwpf.usermodel.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.YearMonth
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
public
class
ClassSubjectServiceImpl
extends
ServiceImpl
<
ClassSubjectMapper
,
ClassSubjectEntity
>
implements
ClassSubjectService
{
@Resource
private
ClassService
classService
;
@Autowired
private
UserService
userService
;
@Resource
private
ExamService
examService
;
@Resource
private
ExamStudentService
examStudentService
;
@Resource
private
SysLevelService
sysLevelService
;
@Override
@Transactional
public
boolean
saveOrUpdateSubject
(
ClassSubjectDTO
classSubjectDTO
)
{
//先删除当天课程数据
baseMapper
.
deleteByClassIdAndDate
(
classSubjectDTO
);
return
saveOrUpdateBatch
(
classSubjectDTO
.
getClassSubjectList
());
}
@Override
public
ClassVO
detail
(
ClassSubjectDTO
classSubjectDTO
)
{
//查看班级详情
ClassEntity
classEntity
=
classService
.
getById
(
classSubjectDTO
.
getClassId
());
if
(
classEntity
==
null
)
{
throw
new
BusinessException
(
"班级编号错误"
);
}
SysLevelEntity
sysLevel
=
sysLevelService
.
getById
(
classEntity
.
getLevel
());
if
(!
ObjectUtils
.
isEmpty
(
sysLevel
))
{
classEntity
.
setLevel
(
sysLevel
.
getName
());
}
ClassVO
classVO
=
DozerUtils
.
convertBean
(
classEntity
,
ClassVO
.
class
);
List
<
ClassSubjectVO
>
classSubjectVOList
=
baseMapper
.
queryByClassAndMonth
(
classSubjectDTO
);
classVO
.
setClassSubjectList
(
classSubjectVOList
);
//计算总课时
int
subjectHour
=
0
;
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectVOList
)
{
if
(!
ObjectUtils
.
isEmpty
(
classSubjectVO
.
getSubjectHour
()))
{
subjectHour
+=
classSubjectVO
.
getSubjectHour
();
}
}
classVO
.
setSubjectHour
(
subjectHour
);
return
classVO
;
}
@Override
public
boolean
updateSubject
(
ClassSubjectDTO
classSubjectDTO
)
{
//先删除当天课程数据
baseMapper
.
deleteByClassIdAndDate
(
classSubjectDTO
);
if
(
CollUtil
.
isNotEmpty
(
classSubjectDTO
.
getClassSubjectList
()))
{
//保存课程数据
return
saveBatch
(
classSubjectDTO
.
getClassSubjectList
());
}
return
true
;
}
@Override
public
List
<
ClassSubjectVO
>
countByTeacherId
(
String
id
)
{
return
baseMapper
.
countByTeacherId
(
id
);
}
@Override
public
void
export
(
ClassSubjectDTO
classSubjectDTO
,
HttpServletResponse
response
)
throws
IOException
{
ClassVO
detail
=
detail
(
classSubjectDTO
);
response
.
setContentType
(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
);
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
URLEncoder
.
encode
(
"课程安排表"
,
"utf-8"
)
+
".docx"
);
XWPFDocument
document
=
new
XWPFDocument
();
//一级标题
XWPFParagraph
oneParagraph
=
document
.
createParagraph
();
XWPFRun
OneTitle
=
oneParagraph
.
createRun
();
oneParagraph
.
setAlignment
(
ParagraphAlignment
.
CENTER
);
OneTitle
.
setBold
(
true
);
OneTitle
.
setFontSize
(
20
);
OneTitle
.
setText
(
"课程安排表"
);
//换行
oneParagraph
.
setSpacingAfter
(
16
);
//二级标题
XWPFParagraph
twoParagraph
=
document
.
createParagraph
();
XWPFRun
twoTitle
=
twoParagraph
.
createRun
();
twoParagraph
.
setAlignment
(
ParagraphAlignment
.
CENTER
);
twoTitle
.
setBold
(
true
);
twoTitle
.
setFontSize
(
13
);
twoTitle
.
setText
(
"班级:"
+
detail
.
getName
()
+
" 总课时:"
+
detail
.
getSubjectHour
()
+
"课时"
);
twoParagraph
.
setSpacingAfter
(
20
);
//课程数据
List
<
ClassSubjectVO
>
classSubjectList
=
detail
.
getClassSubjectList
();
//创建表格
XWPFTable
table
=
document
.
createTable
(
classSubjectList
.
size
()
+
1
,
7
);
for
(
int
rowIndex
=
0
;
rowIndex
<
table
.
getNumberOfRows
();
rowIndex
++)
{
XWPFTableRow
row
=
table
.
getRow
(
rowIndex
);
if
(
row
!=
null
)
{
for
(
int
cellIndex
=
0
;
cellIndex
<
row
.
getTableCells
().
size
();
cellIndex
++)
{
XWPFTableCell
cell
=
row
.
getCell
(
cellIndex
);
// 1. 设置单元格垂直居中
cell
.
setVerticalAlignment
(
XWPFTableCell
.
XWPFVertAlign
.
CENTER
);
// 2. 设置单元格内文本水平居中
// 确保单元格至少有一个段落
if
(
cell
.
getParagraphs
().
isEmpty
())
{
cell
.
addParagraph
();
}
XWPFParagraph
paragraph
=
cell
.
getParagraphs
().
get
(
0
);
paragraph
.
setAlignment
(
ParagraphAlignment
.
CENTER
);
// 如果需要,同时设置文本的字体、加粗等样式,可以通过 Run 进行操作
//if (paragraph.getRuns().isEmpty()) {
// paragraph.createRun();
//}
}
}
}
//创建表头
XWPFTableRow
header
=
table
.
getRow
(
0
);
//设置表头单元格内容
header
.
getCell
(
0
).
setText
(
"日期"
);
header
.
getCell
(
1
).
setText
(
"课次"
);
header
.
getCell
(
2
).
setText
(
"时段"
);
header
.
getCell
(
3
).
setText
(
"课时"
);
header
.
getCell
(
4
).
setText
(
"课程"
);
header
.
getCell
(
5
).
setText
(
"授课教师"
);
header
.
getCell
(
6
).
setText
(
"序号"
);
int
tableTip
=
1
;
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectList
)
{
table
.
createRow
();
XWPFTableRow
content
=
table
.
getRow
(
tableTip
);
//日期
content
.
getCell
(
0
).
setText
(
formatDateToMonthDayWeek
(
classSubjectVO
.
getDate
()));
content
.
getCell
(
1
).
setText
(
String
.
valueOf
(
classSubjectVO
.
getSubjectTimes
()));
//时段
String
timeFrame
=
classSubjectVO
.
getTimeFrame
();
if
(
StringUtils
.
isNotEmpty
(
timeFrame
))
{
String
[]
split
=
timeFrame
.
split
(
","
);
for
(
int
i
=
0
;
i
<
split
.
length
;
i
++)
{
if
(
i
==
0
)
{
XWPFTableCell
cell1
=
content
.
getCell
(
2
);
cell1
.
setText
(
split
[
i
]);
}
else
{
XWPFTableCell
cell1
=
content
.
getCell
(
2
);
XWPFParagraph
paragraph
=
cell1
.
addParagraph
();
paragraph
.
setAlignment
(
ParagraphAlignment
.
CENTER
);
XWPFRun
run
=
paragraph
.
createRun
();
run
.
setText
(
split
[
i
]);
paragraph
.
setWordWrapped
(
true
);
}
}
}
content
.
getCell
(
3
).
setText
(
String
.
valueOf
(
classSubjectVO
.
getSubjectHour
()));
content
.
getCell
(
4
).
setText
(
classSubjectVO
.
getSubjectName
());
content
.
getCell
(
5
).
setText
(
classSubjectVO
.
getTeacherName
());
content
.
getCell
(
6
).
setText
(
String
.
valueOf
(
classSubjectVO
.
getId
()));
tableTip
++;
}
table
.
setWidth
(
"100%"
);
document
.
write
(
response
.
getOutputStream
());
document
.
close
();
}
/**
* 将Date对象转换为 "几月/几号 周几" 格式的字符串(中文环境,短星期)
* 例如:输入 new Date(),输出可能为 "9月12日 周五"(具体取决于当前日期)
*
* @param date 要格式化的日期对象
* @return 格式化后的字符串
*/
public
static
String
formatDateToMonthDayWeek
(
Date
date
)
{
// 创建SimpleDateFormat对象,指定格式为"M月d日 E"
// 其中:M表示月份,d表示月份中的日期,E表示星期几(短格式)
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"M月d日 E"
,
Locale
.
CHINA
);
return
sdf
.
format
(
date
);
}
@Override
public
List
<
ClassSubjectVO
>
queryOneself
(
String
userId
)
{
return
baseMapper
.
queryOneself
(
userId
);
}
@Override
public
SysTeacherCountVO
queryByTeacherUserName
(
String
userName
)
{
UserVO
userVO
=
userService
.
queryByUserName
(
userName
);
String
teacherId
=
userVO
.
getId
();
Integer
count1
=
0
;
//记录当月剩余课时
Integer
count2
=
0
;
//记录待评分试卷
// 获取当前日期和时间
LocalDateTime
now
=
LocalDateTime
.
now
();
// 获取当前年份和月份
YearMonth
currentYearMonth
=
YearMonth
.
from
(
now
);
List
<
ClassSubjectVO
>
classSubjectList
=
baseMapper
.
queryByTeacherId
(
teacherId
);
// 筛选符合条件的记录
List
<
ClassSubjectVO
>
filteredList
=
classSubjectList
.
stream
()
.
filter
(
classSubjectVO
->
{
try
{
// 解析日期字符串为LocalDate
LocalDate
subjectDate
=
LocalDate
.
parse
((
CharSequence
)
classSubjectVO
.
getDate
());
// 检查是否是当月且晚于当前日期
return
YearMonth
.
from
(
subjectDate
).
equals
(
currentYearMonth
)
&&
subjectDate
.
isAfter
(
now
.
toLocalDate
());
}
catch
(
Exception
e
)
{
// 日期格式错误时跳过
return
false
;
}
})
.
collect
(
Collectors
.
toList
());
Set
<
Integer
>
classId
=
new
HashSet
<>();
for
(
ClassSubjectVO
classSubjectVO
:
classSubjectList
)
{
//课时
Integer
subjectHour
=
classSubjectVO
.
getSubjectHour
();
count1
+=
subjectHour
;
classId
.
add
(
classSubjectVO
.
getClassId
());
}
for
(
Integer
classId1
:
classId
)
{
List
<
ExamVO
>
examEntityList
=
examService
.
queryByClassId
(
classId1
);
for
(
ExamVO
examVO
:
examEntityList
)
{
List
<
ExamStudentVO
>
examStudentEntityList
=
examStudentService
.
queryByClassIdAndExamId
(
classId1
,
examVO
.
getId
());
count2
+=
examStudentEntityList
.
size
();
}
}
return
SysTeacherCountVO
.
builder
()
.
remainClassHour
(
count1
)
.
remainMarkCount
(
count2
)
.
build
();
}
}
practical-business/src/main/java/com/platform/business/service/impl/ExamDetailServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.alibaba.fastjson2.JSON
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.ExamDetailMapper
;
import
com.platform.business.model.dto.ExamDetailDTO
;
import
com.platform.business.model.entity.*
;
import
com.platform.business.model.req.ExamQuestionReq
;
import
com.platform.business.model.req.ExamReq
;
import
com.platform.business.model.req.ExamResultReq
;
import
com.platform.business.model.vo.ExamDetailVO
;
import
com.platform.business.model.vo.ExamScoreDetailVO
;
import
com.platform.business.service.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Service
public
class
ExamDetailServiceImpl
extends
ServiceImpl
<
ExamDetailMapper
,
ExamDetailEntity
>
implements
ExamDetailService
{
@Resource
private
UserService
userService
;
@Resource
private
ExamService
examService
;
@Resource
private
ClassService
classService
;
@Resource
private
QuestionThirdService
questionThirdService
;
@Resource
private
BsFileService
bsFileService
;
@Override
public
ExamScoreDetailVO
queryQuestionList
(
ExamDetailDTO
examDetailDTO
)
{
// 查询学生所有答题数据
List
<
ExamDetailVO
>
flatList
=
baseMapper
.
queryQuestionList
(
examDetailDTO
);
ExamScoreDetailVO
resultVO
=
new
ExamScoreDetailVO
();
//学生名
UserEntity
userEntity
=
userService
.
getById
(
examDetailDTO
.
getStudentId
());
resultVO
.
setStudentName
(
userEntity
.
getNickName
());
//阅卷老师
Set
<
String
>
readTeachers
=
new
HashSet
<>();
//考试时间
ExamEntity
examEntity
=
examService
.
getById
(
examDetailDTO
.
getExamId
());
if
(
examEntity
!=
null
)
{
resultVO
.
setExamTime
(
examEntity
.
getExamTime
());
//班级名
ClassEntity
classEntity
=
classService
.
getById
(
examEntity
.
getClassId
());
resultVO
.
setClassName
(
classEntity
.
getName
());
}
//总分
double
resultTotalScore
=
0.0
;
double
questionTotalScore
=
0.0
;
// 设置基本信息(这些可以从第一个记录中获取或单独查询)
if
(!
flatList
.
isEmpty
())
{
ExamDetailVO
examDetailVO
=
flatList
.
get
(
0
);
//等级
resultVO
.
setLevel
(
examDetailVO
.
getLevel
());
}
// 按secondTitle分组创建森林结构
Map
<
String
,
List
<
ExamDetailVO
>>
groupMap
=
flatList
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
ExamDetailVO:
:
getSecondTitle
));
List
<
ExamDetailVO
>
forestStructure
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
List
<
ExamDetailVO
>>
entry
:
groupMap
.
entrySet
())
{
// 创建父节点(二级标题节点)
ExamDetailVO
parentNode
=
new
ExamDetailVO
();
parentNode
.
setSecondTitle
(
entry
.
getKey
());
//获取每题得阅卷老师
readTeachers
=
entry
.
getValue
().
stream
()
.
map
(
ExamDetailVO:
:
getReadTeacher
)
.
collect
(
Collectors
.
toSet
());
// 计算该组的总分和实际得分
double
totalScore
=
entry
.
getValue
().
stream
()
.
mapToDouble
(
ExamDetailVO:
:
getScore
)
.
sum
();
double
resultScore
=
entry
.
getValue
().
stream
()
.
mapToDouble
(
ExamDetailVO:
:
getResultScore
)
.
sum
();
parentNode
.
setTotalScore
(
totalScore
);
parentNode
.
setResultScore
(
resultScore
);
// 累加得分
resultTotalScore
+=
resultScore
;
//累加分值
questionTotalScore
+=
totalScore
;
// 设置子节点列表
parentNode
.
setExamDetailVOS
(
entry
.
getValue
());
forestStructure
.
add
(
parentNode
);
}
// 设置森林结构(得分详情)
resultVO
.
setExamDetailVOS
(
forestStructure
);
resultVO
.
setResultScore
(
resultTotalScore
);
resultVO
.
setTotalScore
(
questionTotalScore
);
resultVO
.
setReadTeachers
(
readTeachers
);
//阅卷老师
return
resultVO
;
}
@Override
@Transactional
public
void
objective
(
ExamReq
examReq
)
{
List
<
ExamDetailEntity
>
examDetailList
=
new
ArrayList
<>();
//学员id
String
userId
=
examReq
.
getUserId
();
//考试id
Integer
examId
=
examReq
.
getExamId
();
//一级题目
examDetailList
.
add
(
ExamDetailEntity
.
builder
()
.
questionNo
(
examReq
.
getId
())
.
studentId
(
userId
)
.
examId
(
examId
)
.
type
(
examReq
.
getType
())
.
level
(
examReq
.
getLevel
())
.
title
(
examReq
.
getTitle
())
.
markFlag
(
true
)
.
layer
(
1
)
.
build
());
List
<
ExamQuestionReq
>
L3
=
new
ArrayList
<>();
//二级题目
List
<
ExamResultReq
>
L2
=
examReq
.
getChild
();
for
(
ExamResultReq
examResultReq
:
L2
)
{
examDetailList
.
add
(
ExamDetailEntity
.
builder
()
.
questionNo
(
examResultReq
.
getId
())
.
studentId
(
userId
)
.
examId
(
examId
)
.
type
(
examResultReq
.
getType
())
.
level
(
examResultReq
.
getLevel
())
.
title
(
examResultReq
.
getTitle
())
.
readTeacher
(
examResultReq
.
getReadTeacher
())
.
content
(
examResultReq
.
getContent
())
.
markFlag
(
true
)
.
layer
(
2
)
.
build
());
List
<
ExamQuestionReq
>
child
=
examResultReq
.
getChild
();
if
(!
ObjectUtils
.
isEmpty
(
child
)
&&
!
child
.
isEmpty
())
{
L3
.
addAll
(
child
);
}
}
//三级题目
List
<
String
>
questionNos
=
new
ArrayList
<>();
for
(
ExamQuestionReq
examQuestionReq
:
L3
)
{
questionNos
.
add
(
examQuestionReq
.
getId
());
examDetailList
.
add
(
ExamDetailEntity
.
builder
()
.
questionNo
(
examQuestionReq
.
getId
())
.
studentId
(
userId
)
.
examId
(
examId
)
.
type
(
examQuestionReq
.
getType
())
.
level
(
examQuestionReq
.
getLevel
())
.
title
(
examQuestionReq
.
getTitle
())
.
judge
(
examQuestionReq
.
getJudge
())
.
content
(
examQuestionReq
.
getContent
())
.
markFlag
(
true
)
.
layer
(
3
)
.
build
());
}
List
<
QuestionThirdEntity
>
questionList
=
questionThirdService
.
selectListInQuestionNo
(
questionNos
);
if
(!
ObjectUtils
.
isEmpty
(
questionList
)
&&
!
questionList
.
isEmpty
())
{
Map
<
String
,
Integer
>
questionMap
=
questionList
.
stream
().
collect
(
Collectors
.
toMap
(
QuestionThirdEntity:
:
getNo
,
QuestionThirdEntity:
:
getScore
));
for
(
ExamQuestionReq
examQuestionReq
:
L3
)
{
if
(
questionMap
.
containsKey
(
examQuestionReq
.
getId
()))
{
examQuestionReq
.
setScore
(
questionMap
.
get
(
examQuestionReq
.
getId
()));
}
}
}
saveBatch
(
examDetailList
);
}
// @Override
// @Transactional
// public void offline(ExamReq examReq) {
// List<ExamDetailEntity> examDetailList = new ArrayList<>();
// //学员id
// String userId = examReq.getUserId();
// //考试id
// Integer examId = examReq.getExamId();
// //一级题目
// examDetailList.add(ExamDetailEntity.builder()
// .questionNo(examReq.getId())
// .studentId(userId)
// .examId(examId)
// .type("线下题")
// .level(examReq.getLevel())
// .title(examReq.getTitle())
// .markFlag(true)
// .layer(1)
// .build());
// List<ExamQuestionReq> L3 = new ArrayList<>();
// //二级题目
// List<ExamResultReq> L2 = examReq.getChild();
// for (ExamResultReq examResultReq : L2) {
// examDetailList.add(ExamDetailEntity.builder()
// .questionNo(examResultReq.getId())
// .studentId(userId)
// .examId(examId)
// .type("线下题")
// .level(examResultReq.getLevel())
// .title(examResultReq.getTitle())
// .markFlag(true)
// .layer(2)
// .build());
// List<ExamQuestionReq> child = examResultReq.getChild();
// if (!ObjectUtils.isEmpty(child) && !child.isEmpty()) {
// L3.addAll(child);
// }
// }
// //三级题目
// List<String> questionNos = new ArrayList<>();
// for (ExamQuestionReq examQuestionReq : L3) {
// questionNos.add(examQuestionReq.getId());
// examDetailList.add(ExamDetailEntity.builder()
// .questionNo(examQuestionReq.getId())
// .studentId(userId)
// .examId(examId)
// .type("线下题")
// .level(examQuestionReq.getLevel())
// .title(examQuestionReq.getTitle())
// .judge(examQuestionReq.getJudge())
// .markFlag(true)
// .layer(3)
// .build());
// }
// List<QuestionThirdEntity> questionList = questionThirdService.selectListInQuestionNo(questionNos);
// if (!ObjectUtils.isEmpty(questionList) && !questionList.isEmpty()) {
// Map<String, Integer> questionMap = questionList.stream().collect(Collectors.toMap(QuestionThirdEntity::getNo, QuestionThirdEntity::getScore));
// for (ExamQuestionReq examQuestionReq : L3) {
// if (questionMap.containsKey(examQuestionReq.getId())) {
// examQuestionReq.setScore(questionMap.get(examQuestionReq.getId()));
// }
// }
// }
// saveBatch(examDetailList);
// }
@Override
@Transactional
public
void
subjective
(
String
content
,
List
<
MultipartFile
>
files
)
{
ExamReq
examReq
=
JSON
.
parseObject
(
content
,
ExamReq
.
class
);
List
<
ExamDetailEntity
>
examDetailList
=
new
ArrayList
<>();
//学员id
String
userId
=
examReq
.
getUserId
();
//考试id
Integer
examId
=
examReq
.
getExamId
();
//一级题目
examDetailList
.
add
(
ExamDetailEntity
.
builder
()
.
questionNo
(
examReq
.
getId
())
.
studentId
(
userId
)
.
examId
(
examId
)
.
type
(
"主观题"
)
.
level
(
examReq
.
getLevel
())
.
title
(
examReq
.
getTitle
())
.
markFlag
(
false
)
.
layer
(
1
)
.
build
());
List
<
ExamQuestionReq
>
L3
=
new
ArrayList
<>();
//二级题目
List
<
ExamResultReq
>
L2
=
examReq
.
getChild
();
for
(
ExamResultReq
examResultReq
:
L2
)
{
examDetailList
.
add
(
ExamDetailEntity
.
builder
()
.
questionNo
(
examResultReq
.
getId
())
.
studentId
(
userId
)
.
examId
(
examId
)
.
type
(
"主观题"
)
.
level
(
examResultReq
.
getLevel
())
.
title
(
examResultReq
.
getTitle
())
.
fileName
(
examResultReq
.
getFileName
())
.
content
(
examResultReq
.
getContent
())
.
markFlag
(
false
)
.
layer
(
2
)
.
build
());
List
<
ExamQuestionReq
>
child
=
examResultReq
.
getChild
();
if
(!
ObjectUtils
.
isEmpty
(
child
)
&&
!
child
.
isEmpty
())
{
L3
.
addAll
(
child
);
}
}
//三级题目
for
(
ExamQuestionReq
examQuestionReq
:
L3
)
{
examDetailList
.
add
(
ExamDetailEntity
.
builder
()
.
questionNo
(
examQuestionReq
.
getId
())
.
studentId
(
userId
)
.
examId
(
examId
)
.
type
(
"主观题"
)
.
level
(
examQuestionReq
.
getLevel
())
.
title
(
examQuestionReq
.
getTitle
())
.
fileName
(
examQuestionReq
.
getFileName
())
.
content
(
examQuestionReq
.
getContent
())
.
markFlag
(
false
)
.
layer
(
3
)
.
build
());
}
//处理文件上传
if
(!
ObjectUtils
.
isEmpty
(
files
)
&&
!
files
.
isEmpty
())
{
for
(
MultipartFile
file
:
files
)
{
bsFileService
.
uploadFile
(
file
);
}
}
saveBatch
(
examDetailList
);
}
}
practical-business/src/main/java/com/platform/business/service/impl/ExamExportServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.platform.business.service.ExamExportService
;
import
org.springframework.stereotype.Service
;
/**
* @author : wujipeng
* @date : 2025/10/23 15:25
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public
class
ExamExportServiceImpl
implements
ExamExportService
{
}
practical-business/src/main/java/com/platform/business/service/impl/ExamServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.platform.business.mapper.ExamMapper
;
import
com.platform.business.model.dto.ExamDTO
;
import
com.platform.business.model.dto.TheoreticalPaperStudentDetailDTO
;
import
com.platform.business.model.entity.*
;
import
com.platform.business.model.vo.ExamStudentVO
;
import
com.platform.business.model.vo.ExamVO
;
import
com.platform.business.model.vo.TheoreticalPaperStudentDetailVO
;
import
com.platform.business.service.*
;
import
com.platform.model.resp.Result
;
import
com.platform.utils.DozerUtils
;
import
com.platform.utils.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
javax.annotation.Resource
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
@Service
public
class
ExamServiceImpl
extends
ServiceImpl
<
ExamMapper
,
ExamEntity
>
implements
ExamService
{
@Resource
private
ExamStudentService
examStudentService
;
@Resource
private
SysLevelService
sysLevelService
;
@Resource
private
TheoreticalPaperService
theoreticalPaperService
;
@Resource
private
TheoreticalPaperDetailService
theoreticalPaperDetailService
;
@Resource
private
UserService
userService
;
@Resource
private
TheoreticalPaperStudentDetailService
theoreticalPaperStudentDetailService
;
@Override
public
List
<
ExamVO
>
queryList
(
ExamDTO
examDTO
)
{
return
baseMapper
.
queryList
(
examDTO
);
}
@Override
@Transactional
public
boolean
saveOrUpdateExam
(
ExamDTO
examDTO
)
{
//保存考试
ExamEntity
examEntity
=
DozerUtils
.
convertBean
(
examDTO
,
ExamEntity
.
class
);
saveOrUpdate
(
examEntity
);
List
<
String
>
studentList
=
examDTO
.
getExamStudentList
();
if
(
CollUtil
.
isNotEmpty
(
studentList
))
{
//删除旧数据
examStudentService
.
remove
(
new
LambdaQueryWrapper
<
ExamStudentEntity
>().
eq
(
ExamStudentEntity:
:
getExamId
,
examEntity
.
getId
()));
//保存学生,初始化学生集合
List
<
ExamStudentEntity
>
examStudentEntityList
=
Lists
.
newArrayList
();
studentList
.
forEach
(
studentId
->
examStudentEntityList
.
add
(
ExamStudentEntity
.
builder
().
studentId
(
studentId
)
.
examId
(
examEntity
.
getId
())
.
classId
(
examEntity
.
getClassId
())
.
build
()));
examStudentService
.
saveBatch
(
examStudentEntityList
);
}
return
true
;
}
@Override
public
ExamVO
detail
(
int
id
)
{
ExamVO
examVO
=
baseMapper
.
getInfoById
(
id
);
//拼接监考教师信息
String
invigilationId
=
examVO
.
getInvigilationId
();
if
(
StringUtils
.
isNotEmpty
(
invigilationId
))
{
StringJoiner
invigilationName
=
new
StringJoiner
(
","
);
String
[]
split
=
invigilationId
.
split
(
","
);
for
(
String
s
:
split
)
{
UserEntity
user
=
userService
.
getById
(
s
);
invigilationName
.
add
(
user
.
getNickName
());
}
examVO
.
setInvigilationName
(
invigilationName
.
toString
());
}
SysLevelEntity
sysLevel
=
sysLevelService
.
getById
(
examVO
.
getLevel
());
if
(!
ObjectUtils
.
isEmpty
(
sysLevel
))
{
examVO
.
setLevel
(
sysLevel
.
getName
());
}
//查看考试关联的学员
List
<
ExamStudentVO
>
examStudentVOList
=
examStudentService
.
queryByExamId
(
id
);
examVO
.
setExamStudentList
(
examStudentVOList
);
return
examVO
;
}
@Override
public
List
<
ExamVO
>
studentGrades
(
ExamDTO
examDTO
)
{
return
baseMapper
.
queryListGroupByClass
(
examDTO
);
}
@Override
public
List
<
ExamVO
>
classExam
(
ExamDTO
examDTO
)
{
return
baseMapper
.
queryList
(
examDTO
);
}
@Override
public
List
<
ExamStudentVO
>
classExamScore
(
ExamDTO
examDTO
)
{
return
examStudentService
.
queryByExamId
(
examDTO
.
getId
());
}
@Override
public
List
<
ExamVO
>
queryByClassId
(
Integer
classId
)
{
return
baseMapper
.
queryByClassId
(
classId
);
}
@Override
public
List
<
ExamVO
>
unfinished
(
String
id
)
{
return
baseMapper
.
unfinished
(
id
);
}
@Override
@Transactional
public
Result
<
Integer
>
startExam
(
ExamDTO
examDTO
)
{
//查询考试详情
ExamEntity
exam
=
this
.
getById
(
examDTO
.
getId
());
//判断有没有到考试时间
long
currentTimeMillis
=
System
.
currentTimeMillis
();
if
(
currentTimeMillis
<
convertToTimestamp
(
exam
.
getExamTime
().
split
(
"-"
)[
0
]))
{
return
Result
.
fail
(
"考试未开始"
);
}
//检查是否已经开始考试
ExamStudentEntity
examStudent
=
examStudentService
.
getOne
(
new
LambdaQueryWrapper
<
ExamStudentEntity
>()
.
eq
(
ExamStudentEntity:
:
getExamId
,
examDTO
.
getId
()).
eq
(
ExamStudentEntity:
:
getStudentId
,
examDTO
.
getUserId
()));
if
(!
ObjectUtils
.
isEmpty
(
examStudent
.
getEndTime
()))
{
return
Result
.
fail
(
"考试已开始"
);
}
//检查是否已经考完试
if
(
examStudent
.
getSubmit
())
{
return
Result
.
fail
(
"考试已结束"
);
}
//检查试卷是否已经生成
long
count
=
theoreticalPaperStudentDetailService
.
count
(
new
LambdaQueryWrapper
<
TheoreticalPaperStudentDetailEntity
>()
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getExamId
,
examStudent
.
getExamId
()).
eq
(
TheoreticalPaperStudentDetailEntity:
:
getStudentId
,
examStudent
.
getId
()));
if
(
count
>
0
)
{
return
Result
.
fail
(
"考试试卷已生成"
);
}
//设置考试开始和结束时间
examStudent
.
setAnswerTime
(
format
(
currentTimeMillis
,
"yyyy.MM.dd HH:mm:ss"
));
examStudent
.
setStartTime
(
currentTimeMillis
);
long
endTime
=
currentTimeMillis
+
exam
.
getDuration
()
*
60
*
1000
;
examStudent
.
setEndTime
(
endTime
);
examStudentService
.
updateById
(
examStudent
);
//创建实际考试试卷详情
//查询理论试卷
TheoreticalPaperEntity
theoreticalPaper
=
theoreticalPaperService
.
getById
(
exam
.
getPaperId
());
List
<
TheoreticalPaperStudentDetailEntity
>
paperStudentDetailList
=
new
ArrayList
<>();
//判断是否需要乱序
List
<
TheoreticalPaperDetailEntity
>
theoreticalPaperDetailList
;
if
(
"乱序"
.
equals
(
theoreticalPaper
.
getSequence
()))
{
theoreticalPaperDetailList
=
theoreticalPaperDetailService
.
selectDisorderly
(
exam
.
getPaperId
());
}
else
{
theoreticalPaperDetailList
=
theoreticalPaperDetailService
.
list
(
new
LambdaQueryWrapper
<
TheoreticalPaperDetailEntity
>()
.
eq
(
TheoreticalPaperDetailEntity:
:
getPaperId
,
exam
.
getPaperId
()));
}
//考生个人试卷详情入库
for
(
TheoreticalPaperDetailEntity
theoreticalPaperDetail
:
theoreticalPaperDetailList
)
{
TheoreticalPaperStudentDetailEntity
theoreticalPaperStudentDetail
=
BeanUtil
.
copyProperties
(
theoreticalPaperDetail
,
TheoreticalPaperStudentDetailEntity
.
class
);
theoreticalPaperStudentDetail
.
setId
(
null
);
theoreticalPaperStudentDetail
.
setStudentId
(
examDTO
.
getUserId
());
theoreticalPaperStudentDetail
.
setExamId
(
examDTO
.
getId
());
paperStudentDetailList
.
add
(
theoreticalPaperStudentDetail
);
}
theoreticalPaperStudentDetailService
.
saveBatch
(
paperStudentDetailList
);
//设置用户信息标识
UserEntity
user
=
userService
.
getById
(
examDTO
.
getUserId
());
user
.
setExamFlag
(
true
);
user
.
setExamOneselfId
(
examStudent
.
getId
());
userService
.
updateById
(
user
);
return
Result
.
data
(
examStudent
.
getId
());
}
/**
* 将 yyyy.MM.dd HH:mm:ss 格式字符串转换为时间戳
*
* @param dateString 日期字符串,格式如 "2023.10.25 14:30:45"
* @return 时间戳(毫秒)
*/
public
static
long
convertToTimestamp
(
String
dateString
)
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy.MM.dd HH:mm:ss"
);
LocalDateTime
localDateTime
=
LocalDateTime
.
parse
(
dateString
,
formatter
);
return
localDateTime
.
atZone
(
java
.
time
.
ZoneId
.
systemDefault
()).
toInstant
().
toEpochMilli
();
}
/**
* 将时间戳转换为指定格式的字符串
*
* @param timestamp 时间戳(毫秒)
* @param pattern 日期时间格式
* @return 格式化后的时间字符串
*/
public
static
String
format
(
long
timestamp
,
String
pattern
)
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
pattern
);
LocalDateTime
dateTime
=
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
timestamp
),
ZoneId
.
systemDefault
());
return
dateTime
.
format
(
formatter
);
}
@Override
public
List
<
TheoreticalPaperStudentDetailVO
>
paperOverview
(
Integer
id
)
{
//查询考生个人信息
ExamStudentEntity
examStudent
=
examStudentService
.
getById
(
id
);
//查询试题数量和分值
List
<
TheoreticalPaperStudentDetailVO
>
result
=
baseMapper
.
numberAndScore
(
examStudent
.
getStudentId
(),
examStudent
.
getExamId
());
for
(
TheoreticalPaperStudentDetailVO
theoreticalPaperStudentDetailVO
:
result
)
{
if
(
StringUtils
.
isNotEmpty
(
theoreticalPaperStudentDetailVO
.
getType
()))
{
List
<
TheoreticalPaperStudentDetailVO
>
data
=
baseMapper
.
paperOverview
(
examStudent
.
getStudentId
(),
examStudent
.
getExamId
(),
theoreticalPaperStudentDetailVO
.
getType
());
theoreticalPaperStudentDetailVO
.
setData
(
data
);
}
}
return
result
;
}
@Override
public
ExamStudentVO
paperDetail
(
Integer
id
)
{
int
finishNum
=
0
;
ExamStudentVO
examStudentVO
=
examStudentService
.
paperDetail
(
id
);
//查询进度
List
<
TheoreticalPaperStudentDetailVO
>
processList
=
theoreticalPaperStudentDetailService
.
process
(
examStudentVO
.
getExamId
(),
examStudentVO
.
getStudentId
());
examStudentVO
.
setTotalNum
(
processList
.
size
());
for
(
TheoreticalPaperStudentDetailVO
process
:
processList
)
{
if
(
StringUtils
.
isNotEmpty
(
process
.
getActualChoice
()))
{
finishNum
++;
}
}
examStudentVO
.
setFinishNum
(
finishNum
);
return
examStudentVO
;
}
@Override
public
TheoreticalPaperStudentDetailVO
questionDetail
(
String
id
)
{
TheoreticalPaperStudentDetailVO
result
=
theoreticalPaperStudentDetailService
.
questionDetail
(
id
);
//查询题数
long
count
=
theoreticalPaperStudentDetailService
.
count
(
new
LambdaQueryWrapper
<
TheoreticalPaperStudentDetailEntity
>()
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getExamId
,
result
.
getExamId
())
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getStudentId
,
result
.
getStudentId
())
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getType
,
result
.
getType
()));
result
.
setNum
((
int
)
count
);
return
result
;
}
@Override
public
Boolean
questionEdit
(
TheoreticalPaperStudentDetailDTO
theoreticalPaperStudentDetailDTO
)
{
if
(
StringUtils
.
isEmpty
(
theoreticalPaperStudentDetailDTO
.
getActualChoice
()))
{
return
theoreticalPaperStudentDetailService
.
leaveBlank
(
theoreticalPaperStudentDetailDTO
);
}
else
{
return
theoreticalPaperStudentDetailService
.
updateById
(
theoreticalPaperStudentDetailDTO
);
}
}
@Override
public
Map
<
String
,
String
>
submitCheck
(
String
id
)
{
Map
<
String
,
String
>
result
=
new
HashMap
<>();
//查询考生个人信息
ExamStudentEntity
examStudent
=
examStudentService
.
getById
(
id
);
//查询考试信息
ExamEntity
exam
=
this
.
getById
(
examStudent
.
getExamId
());
//判断是否在禁止交卷时间内
if
(
examStudent
.
getStartTime
()
+
exam
.
getForbid
()
*
60
*
1000
>
System
.
currentTimeMillis
())
{
result
.
put
(
"first"
,
"暂不支持交卷,请继续作答"
);
result
.
put
(
"second"
,
"考试开始"
+
exam
.
getForbid
()
+
"分钟内,禁止交卷。"
);
return
result
;
}
//判断题目是否都做完
long
count
=
theoreticalPaperStudentDetailService
.
count
(
new
LambdaQueryWrapper
<
TheoreticalPaperStudentDetailEntity
>()
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getExamId
,
examStudent
.
getExamId
())
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getStudentId
,
examStudent
.
getStudentId
())
.
isNull
(
TheoreticalPaperStudentDetailEntity:
:
getActualChoice
));
if
(
count
>
0
)
{
result
.
put
(
"first"
,
"您还有"
+
count
+
"道题目未答,是否交卷?"
);
result
.
put
(
"second"
,
"提示:倒计时结束后会自动保存答案并交卷"
);
}
else
{
result
.
put
(
"first"
,
"您已完成作答,是否交卷?"
);
result
.
put
(
"second"
,
"提示:倒计时结束后会自动保存答案并交卷"
);
}
return
result
;
}
@Override
@Transactional
public
Result
<
Boolean
>
submit
(
String
id
)
{
//总分
double
score
=
0
;
//查询考生个人信息
ExamStudentEntity
examStudent
=
examStudentService
.
getById
(
id
);
//检查是否重复交卷
if
(
examStudent
.
getSubmit
())
{
return
Result
.
fail
(
"请勿重复交卷"
);
}
//修改登陆信息
userService
.
closeExam
(
examStudent
.
getStudentId
());
//判题
List
<
TheoreticalPaperStudentDetailEntity
>
theoreticalPaperStudentDetailList
=
theoreticalPaperStudentDetailService
.
list
(
new
LambdaQueryWrapper
<
TheoreticalPaperStudentDetailEntity
>()
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getExamId
,
examStudent
.
getExamId
())
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getStudentId
,
examStudent
.
getStudentId
()));
for
(
TheoreticalPaperStudentDetailEntity
theoreticalPaperStudentDetail
:
theoreticalPaperStudentDetailList
)
{
if
(
StringUtils
.
isNotEmpty
(
theoreticalPaperStudentDetail
.
getActualChoice
()))
{
if
(
theoreticalPaperStudentDetail
.
getActualChoice
().
equals
(
theoreticalPaperStudentDetail
.
getAnswer
()))
{
theoreticalPaperStudentDetail
.
setResult
(
true
);
score
+=
theoreticalPaperStudentDetail
.
getScore
();
}
else
{
theoreticalPaperStudentDetail
.
setResult
(
false
);
}
}
}
theoreticalPaperStudentDetailService
.
updateBatchById
(
theoreticalPaperStudentDetailList
);
examStudent
.
setSubmit
(
true
);
examStudent
.
setScore
(
score
);
//计算答题时长
long
time
=
System
.
currentTimeMillis
()
-
examStudent
.
getStartTime
();
examStudent
.
setDuration
(
convertWithTimeUnit
(
time
));
examStudent
.
setAnswerTime
(
examStudent
.
getAnswerTime
()
+
"-"
+
format
(
System
.
currentTimeMillis
(),
"yyyy.MM.dd HH:mm:ss"
));
return
Result
.
data
(
examStudentService
.
updateById
(
examStudent
));
}
public
String
convertWithTimeUnit
(
long
milliseconds
)
{
if
(
milliseconds
<
0
)
{
return
"00:00:00"
;
}
long
hours
=
TimeUnit
.
MILLISECONDS
.
toHours
(
milliseconds
);
long
minutes
=
TimeUnit
.
MILLISECONDS
.
toMinutes
(
milliseconds
)
-
TimeUnit
.
HOURS
.
toMinutes
(
hours
);
long
seconds
=
TimeUnit
.
MILLISECONDS
.
toSeconds
(
milliseconds
)
-
TimeUnit
.
MINUTES
.
toSeconds
(
TimeUnit
.
MILLISECONDS
.
toMinutes
(
milliseconds
));
return
String
.
format
(
"%02d:%02d:%02d"
,
hours
,
minutes
,
seconds
);
}
@Override
public
TheoreticalPaperStudentDetailVO
gradesQuestionDetail
(
String
id
)
{
TheoreticalPaperStudentDetailVO
result
=
theoreticalPaperStudentDetailService
.
gradesQuestionDetail
(
id
);
//查询题数
long
count
=
theoreticalPaperStudentDetailService
.
count
(
new
LambdaQueryWrapper
<
TheoreticalPaperStudentDetailEntity
>()
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getExamId
,
result
.
getExamId
())
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getStudentId
,
result
.
getStudentId
())
.
eq
(
TheoreticalPaperStudentDetailEntity:
:
getType
,
result
.
getType
()));
result
.
setNum
((
int
)
count
);
//查询同类型答对数量和得分
TheoreticalPaperStudentDetailVO
same
=
baseMapper
.
same
(
result
.
getExamId
(),
result
.
getStudentId
(),
result
.
getType
());
result
.
setSameRightNum
(
same
.
getSameRightNum
());
result
.
setSameScore
(
same
.
getSameScore
());
return
result
;
}
@Override
public
ExamStudentVO
gradesDetail
(
String
id
)
{
return
baseMapper
.
gradesDetail
(
id
);
}
}
practical-business/src/main/java/com/platform/business/service/impl/ExamStaudentServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.ExamStudentMapper
;
import
com.platform.business.model.entity.ExamStudentEntity
;
import
com.platform.business.model.vo.ExamStudentVO
;
import
com.platform.business.model.vo.UserVO
;
import
com.platform.business.service.ExamStudentService
;
import
com.platform.business.service.UserService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
public
class
ExamStaudentServiceImpl
extends
ServiceImpl
<
ExamStudentMapper
,
ExamStudentEntity
>
implements
ExamStudentService
{
@Resource
private
UserService
userService
;
@Override
public
List
<
ExamStudentVO
>
queryByExamId
(
int
id
)
{
return
baseMapper
.
queryByExamId
(
id
);
}
@Override
public
List
<
ExamStudentVO
>
queryByClassIdAndExamId
(
Integer
classId
,
Integer
examId
)
{
return
baseMapper
.
queryByClassIdAndExamId
(
classId
,
examId
);
}
@Override
public
List
<
ExamStudentVO
>
queryByStudentId
(
String
userName
){
UserVO
userVO
=
userService
.
getUserMessage
(
userName
);
String
studentId
=
userVO
.
getId
();
List
<
ExamStudentVO
>
examStudentVOList
=
baseMapper
.
queryByStudentId
(
studentId
);
for
(
ExamStudentVO
examStudentVO
:
examStudentVOList
){
examStudentVO
.
setStudentName
(
userVO
.
getNickName
());
}
return
examStudentVOList
;
}
@Override
public
ExamStudentVO
paperDetail
(
Integer
id
)
{
return
baseMapper
.
paperDetail
(
id
);
}
@Override
public
List
<
ExamStudentVO
>
queryOneself
(
String
userId
)
{
return
baseMapper
.
queryOneself
(
userId
);
}
@Override
public
List
<
ExamStudentVO
>
queryOneselfTeacher
(
String
userId
)
{
return
baseMapper
.
queryOneselfTeacher
(
userId
);
}
}
practical-business/src/main/java/com/platform/business/service/impl/ExaminerServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.model.entity.ExaminerEntity
;
import
com.platform.business.mapper.ExaminerMapper
;
import
com.platform.business.service.ExaminerService
;
import
org.springframework.stereotype.Service
;
/**
* @author : wujipeng
* @date : 2025/7/7 17:42
* @Version: 1.0
* @Desc : 描述信息
*/
@Service
public
class
ExaminerServiceImpl
extends
ServiceImpl
<
ExaminerMapper
,
ExaminerEntity
>
implements
ExaminerService
{
}
practical-business/src/main/java/com/platform/business/service/impl/ExportExamServiceImpl.java
0 → 100644
View file @
cd112ea9
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.platform.business.model.entity.PaperDistributionEntity
;
import
com.platform.business.model.entity.TheoreticalLibraryEntity
;
import
com.platform.business.service.ExportExamService
;
import
com.platform.business.service.PaperDistributionService
;
import
com.platform.business.service.TheoreticalLibraryService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFParagraph
;
import
org.apache.poi.xwpf.usermodel.XWPFRun
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.StringJoiner
;
/**
* @author : wujipeng
* @date : 2025/10/30 10:37
* @Version: 1.0
* @Desc : 描述信息
*/
@Slf4j
@Service
public
class
ExportExamServiceImpl
implements
ExportExamService
{
@Resource
private
PaperDistributionService
paperDistributionService
;
@Resource
private
TheoreticalLibraryService
theoreticalLibraryService
;
@Override
public
void
exportFour
(
HttpServletResponse
response
,
String
name
)
{
try
(
InputStream
inputStream
=
getClass
().
getClassLoader
().
getResourceAsStream
(
name
+
".docx"
))
{
if
(
inputStream
==
null
)
{
log
.
error
(
"资源文件未找到: "
+
name
+
".docx"
);
response
.
setStatus
(
HttpServletResponse
.
SC_NOT_FOUND
);
return
;
}
// 读取Word文档
XWPFDocument
document
=
new
XWPFDocument
(
inputStream
);
// 替换占位符内容
List
<
PaperDistributionEntity
>
paperRuleList
=
paperDistributionService
.
list
(
new
LambdaQueryWrapper
<
PaperDistributionEntity
>().
eq
(
PaperDistributionEntity:
:
getLev
,
name
));
String
judgmentActual
=
generateJudgmentContent
(
paperRuleList
);
String
choiceActual
=
generateChoiceContent
(
paperRuleList
);
replacePlaceholder
(
document
,
"{judgment}"
,
judgmentActual
);
replacePlaceholder
(
document
,
"{choice}"
,
choiceActual
);
// 设置响应头
String
fileName
=
URLEncoder
.
encode
(
"污水处理工(城镇"
+
name
.
substring
(
0
,
2
)
+
"处理工)("
+
name
.
substring
(
2
)
+
")理论知识试卷.docx"
,
"UTF-8"
);
response
.
setContentType
(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
);
response
.
setCharacterEncoding
(
"UTF-8"
);
// 输出文档到响应流
try
(
OutputStream
outputStream
=
response
.
getOutputStream
())
{
document
.
write
(
outputStream
);
outputStream
.
flush
();
}
document
.
close
();
log
.
info
(
"试卷导出成功"
);
}
catch
(
IOException
e
)
{
log
.
error
(
"导出试卷失败"
,
e
);
response
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
throw
new
RuntimeException
(
"导出试卷失败"
,
e
);
}
}
/**
* 替换文档中的占位符
*/
private
void
replacePlaceholder
(
XWPFDocument
document
,
String
placeholder
,
String
replacement
)
{
// 替换段落中的占位符
for
(
XWPFParagraph
paragraph
:
document
.
getParagraphs
())
{
replaceInParagraphEnhanced
(
paragraph
,
placeholder
,
replacement
);
}
}
/**
* 在段落中替换占位符(增强版)
* 此方法能更好地处理占位符被分割到多个Run的情况,并尽量保留格式
*/
private
void
replaceInParagraphEnhanced
(
XWPFParagraph
paragraph
,
String
placeholder
,
String
replacement
)
{
List
<
XWPFRun
>
runs
=
paragraph
.
getRuns
();
if
(
runs
==
null
||
runs
.
isEmpty
())
{
return
;
}
// 1. 合并段落的文本内容以进行检查
StringBuilder
paragraphText
=
new
StringBuilder
();
for
(
XWPFRun
run
:
runs
)
{
String
text
=
run
.
getText
(
0
);
if
(
text
!=
null
)
{
paragraphText
.
append
(
text
);
}
}
String
fullText
=
paragraphText
.
toString
();
// 2. 如果段落中包含占位符,才进行替换
if
(
fullText
.
contains
(
placeholder
))
{
// 3. 寻找占位符的起始和结束位置(跨Run)
int
startIndex
=
fullText
.
indexOf
(
placeholder
);
int
endIndex
=
startIndex
+
placeholder
.
length
();
// 4. 遍历Run,定位占位符所在的Run范围
int
currentPos
=
0
;
int
startRunIndex
=
-
1
;
int
endRunIndex
=
-
1
;
for
(
int
i
=
0
;
i
<
runs
.
size
();
i
++)
{
XWPFRun
run
=
runs
.
get
(
i
);
String
runText
=
run
.
getText
(
0
);
if
(
runText
==
null
)
continue
;
int
runLength
=
runText
.
length
();
// 判断当前Run是否包含占位符的起始部分
if
(
currentPos
<=
startIndex
&&
currentPos
+
runLength
>
startIndex
)
{
startRunIndex
=
i
;
}
// 判断当前Run是否包含占位符的结束部分
if
(
currentPos
<
endIndex
&&
currentPos
+
runLength
>=
endIndex
)
{
endRunIndex
=
i
;
break
;
// 找到结束Run后跳出循环
}
currentPos
+=
runLength
;
}
// 5. 如果成功定位到占位符所在的Run范围,则进行替换
if
(
startRunIndex
!=
-
1
&&
endRunIndex
!=
-
1
)
{
// 合并占位符所跨越的所有Run的文本
StringBuilder
placeholderText
=
new
StringBuilder
();
for
(
int
i
=
startRunIndex
;
i
<=
endRunIndex
;
i
++)
{
placeholderText
.
append
(
runs
.
get
(
i
).
getText
(
0
));
}
// 在合并的文本中进行替换
String
mergedText
=
placeholderText
.
toString
();
String
newText
=
mergedText
.
replace
(
placeholder
,
replacement
);
// 清空原始Run的文本
for
(
int
i
=
startRunIndex
;
i
<=
endRunIndex
;
i
++)
{
runs
.
get
(
i
).
setText
(
""
,
0
);
}
// 将替换后的文本设置到第一个Run中(尽量保留其格式)
runs
.
get
(
startRunIndex
).
setText
(
newText
,
0
);
// 可选:删除之间多余的Run,但可能会影响格式,建议保留
// for (int i = endRunIndex; i > startRunIndex; i--) {
// paragraph.removeRun(i);
// }
}
}
}
/**
* 生成判断题内容
*/
private
String
generateJudgmentContent
(
List
<
PaperDistributionEntity
>
paperRuleList
)
{
StringJoiner
stringJoiner
=
new
StringJoiner
(
"\r\n"
);
List
<
TheoreticalLibraryEntity
>
resultList
=
new
ArrayList
<>();
for
(
PaperDistributionEntity
paperDistributionEntity
:
paperRuleList
)
{
List
<
TheoreticalLibraryEntity
>
theoreticalLibraryList
=
theoreticalLibraryService
.
randomData
(
paperDistributionEntity
.
getLev
(),
"判断题"
,
paperDistributionEntity
.
getJudgmentCount
(),
paperDistributionEntity
.
getChapter
(),
paperDistributionEntity
.
getSection
());
resultList
.
addAll
(
theoreticalLibraryList
);
}
for
(
int
i
=
0
;
i
<
resultList
.
size
();
i
++)
{
stringJoiner
.
add
(
""
);
stringJoiner
.
add
(
"( ) "
+
(
i
+
1
)
+
"."
+
resultList
.
get
(
i
).
getProblem
());
}
return
stringJoiner
.
toString
();
}
/**
* 生成选择题内容
*/
private
String
generateChoiceContent
(
List
<
PaperDistributionEntity
>
paperRuleList
)
{
StringJoiner
stringJoiner
=
new
StringJoiner
(
"\r\n"
);
List
<
TheoreticalLibraryEntity
>
resultList
=
new
ArrayList
<>();
for
(
PaperDistributionEntity
paperDistributionEntity
:
paperRuleList
)
{
List
<
TheoreticalLibraryEntity
>
theoreticalLibraryList
=
theoreticalLibraryService
.
randomData
(
paperDistributionEntity
.
getLev
(),
"单选题"
,
paperDistributionEntity
.
getSingleCount
(),
paperDistributionEntity
.
getChapter
(),
paperDistributionEntity
.
getSection
());
resultList
.
addAll
(
theoreticalLibraryList
);
}
for
(
int
i
=
0
;
i
<
resultList
.
size
();
i
++)
{
stringJoiner
.
add
(
""
);
stringJoiner
.
add
(
i
+
61
+
". "
+
resultList
.
get
(
i
).
getProblem
());
stringJoiner
.
add
(
" A、"
+
resultList
.
get
(
i
).
getOptionA
());
stringJoiner
.
add
(
" B、"
+
resultList
.
get
(
i
).
getOptionB
());
stringJoiner
.
add
(
" C、"
+
resultList
.
get
(
i
).
getOptionC
());
stringJoiner
.
add
(
" D、"
+
resultList
.
get
(
i
).
getOptionD
());
}
return
stringJoiner
.
toString
();
}
}
Prev
1
…
8
9
10
11
12
13
14
15
16
17
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