package com.example.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONObject;
import com.example.dao.NxQuestionInfoDao;
import com.example.dao.NxTestpaperInfoDao;
import com.example.entity.NxTestpaperInfo;
import com.example.exception.CustomException;
import com.example.vo.NxQuestionInfoVo;
import com.example.vo.NxTestpaperInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class NxTestpaperInfoService {
@Resource
private NxQuestionInfoDao nxQuestionInfoDao;
@Resource
private NxTestpaperInfoDao nxTestpaperInfoDao;
public NxTestpaperInfo add(NxTestpaperInfo nxTestpaperInfo) {
nxTestpaperInfoDao.insertSelective(nxTestpaperInfo);
return nxTestpaperInfo;
}
/**
* 生成试卷
*
* @param nxTestpaperInfoVo
* @return
*/
public NxTestpaperInfo generatePaper(NxTestpaperInfoVo nxTestpaperInfoVo) {
// 试卷的type
String type = nxTestpaperInfoVo.getType();
List<NxQuestionInfoVo> finalSelectQuestions = CollUtil.newArrayList();
if (nxTestpaperInfoVo.getSelectQuestion() != null) {
List<NxQuestionInfoVo> selectQuestions = nxQuestionInfoDao.findByQuestionType("单选题", type);
if (nxTestpaperInfoVo.getSelectQuestion() <= 0) {
throw new CustomException("-1", "单选题设置需大于0");
}
if (nxTestpaperInfoVo.getSelectQuestion() > selectQuestions.size()) {
throw new CustomException("-1", "单选题库数量不足");
}
// 选择题题目集合
List<Integer> selectIndexList = getIndexList(selectQuestions.size(), nxTestpaperInfoVo.getSelectQuestion());
selectIndexList.forEach(i -> finalSelectQuestions.add(selectQuestions.get(i)));
}
List<NxQuestionInfoVo> finalJudgeQuestions = CollUtil.newArrayList();
if (nxTestpaperInfoVo.getJudgeQuestion() != null) {
List<NxQuestionInfoVo> judgeQuestions = nxQuestionInfoDao.findByQuestionType("判断题", type);
if (nxTestpaperInfoVo.getJudgeQuestion() <= 0) {
throw new CustomException("-1", "判断题设置需大于0");
}
if (nxTestpaperInfoVo.getJudgeQuestion() > judgeQuestions.size()) {
throw new CustomException("-1", "判断题库数量不足");
}
// 判断题题目集合
List<Integer> judgeIndexList = getIndexList(judgeQuestions.size(), nxTestpaperInfoVo.getJudgeQuestion());
judgeIndexList.forEach(i -> finalJudgeQuestions.add(judgeQuestions.get(i)));
}
List<NxQuestionInfoVo> finalAnswerQuestions = CollUtil.newArrayList();
if (nxTestpaperInfoVo.getAnswerQuestion() != null) {
List<NxQuestionInfoVo> answerQuestions = nxQuestionInfoDao.findByQuestionType("简答题", type);
if (nxTestpaperInfoVo.getAnswerQuestion() <= 0) {
throw new CustomException("-1", "简答题设置需大于0");
}
if (nxTestpaperInfoVo.getAnswerQuestion() > answerQuestions.size()) {
throw new CustomException("-1", "简答题库数量不足");
}
// 简答题题题目集合
List<Integer> answerIndexList = getIndexList(answerQuestions.size(), nxTestpaperInfoVo.getAnswerQuestion());
answerIndexList.forEach(i -> finalAnswerQuestions.add(answerQuestions.get(i)));
}
// 多选题
List<NxQuestionInfoVo> finalMulSelectQuestions = CollUtil.newArrayList();
if (nxTestpaperInfoVo.getMulSelectQuestion() != null) {
List<NxQuestionInfoVo> mulSelectQuestions = nxQuestionInfoDao.findByQuestionType("多选题", type);
if (nxTestpaperInfoVo.getMulSelectQuestion() <= 0) {
throw new CustomException("-1", "多选题设置需大于0");
}
if (nxTestpaperInfoVo.getMulSelectQuestion() > mulSelectQuestions.size()) {
throw new CustomException("-1", "多选题库数量不足");
}
// 多选题题题目集合
List<Integer> answerIndexList = getIndexList(mulSelectQuestions.size(), nxTestpaperInfoVo.getMulSelectQuestion());
answerIndexList.forEach(i -> finalMulSelectQuestions.add(mulSelectQuestions.get(i)));
}
// 填空题
List<NxQuestionInfoVo> finalFillQuestions = CollUtil.newArrayList();
if (nxTestpaperInfoVo.getFillQuestion() != null) {
List<NxQuestionInfoVo> fillQuestions = nxQuestionInfoDao.findByQuestionType("填空题", type);
if (nxTestpaperInfoVo.getFillQuestion() <= 0) {
throw new CustomException("-1", "填空题设置需大于0");
}
if (nxTestpaperInfoVo.getFillQuestion() > fillQuestions.size()) {
throw new CustomException("-1", "填空题库数量不足");
}
// 填空题题题目集合
List<Integer> answerIndexList = getIndexList(fillQuestions.size(), nxTestpaperInfoVo.getFillQuestion());
answerIndexList.forEach(i -> finalFillQuestions.add(fillQuestions.get(i)));
}
// 校验,不能全部为空
if (CollectionUtil.isEmpty(finalSelectQuestions) && CollectionUtil.isEmpty(finalJudgeQuestions) && CollectionUtil.isEmpty(finalAnswerQuestions)
&& CollectionUtil.isEmpty(finalMulSelectQuestions) && CollectionUtil.isEmpty(finalFillQuestions)) {
throw new CustomException("-1", "请至少确定一种题型数量");
}
// 生成试卷html
Map<String, String> map = getPaperHtml(nxTestpaperInfoVo, finalSelectQuestions, finalJudgeQuestions, finalAnswerQuestions,
finalMulSelectQuestions, finalFillQuestions);
nxTestpaperInfoVo.setContent(map.get("page"));
nxTestpaperInfoVo.setAnswer(map.get("answer"));
//插入表
add(nxTestpaperInfoVo);
return nxTestpaperInfoVo;
}
/**
* 生成试卷html
*
* @param selects
* @param judges
* @param answers
* @return
*/
private Map<String, String> getPaperHtml(NxTestpaperInfoVo nxTestpaperInfoVo, List<NxQuestionInfoVo> selects,
List<NxQuestionInfoVo> judges, List<NxQuestionInfoVo> answers,
List<NxQuestionInfoVo> mulSelect, List<NxQuestionInfoVo> fill) {
Map<String, String> map = new HashMap<>();
StringBuilder pageBuilder = new StringBuilder();
JSONObject answerBuilder = new JSONObject();
pageBuilder.append("<div class=\"panel-heading\">\n")
.append("<span style=\"font-size: 14px\">试卷名称:</span><span style=\"color: orangered\">" + nxTestpaperInfoVo.getName() + "</span>\n")
.append("<span style=\"font-size: 14px; margin-left: 20px\">试卷编号:</span><span style=\"color: orangered\">" + nxTestpaperInfoVo.getCode() + "</span>\n")
.append("<span style=\"font-size: 14px; margin-left: 20px\">考试剩余时间:</span><span id=\"time\" style=\"color: orangered\">" + nxTestpaperInfoVo.getTime() + "分</span>\n")
.append("</div>\n")
.append("<div class=\"panel-body\">\n")
.append("<div style=\"border: 1px solid #1E9FFF;\">
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.登录 账号注册(学生/老师) 登录(学生/老师/管理员) 学生:登录后可以选择一套试卷在线答题,也可以在搜索框根据名称搜索试题。有时间倒计时,到点会自动交卷,也可以提前交卷 教师:添加习题 浏览所有习题 删除习题 按照输入各种题型的数量,随机从习题库里生成一套模拟试卷出来 管理员: 管理用户账号,可注销学生或老师账号 2.试卷生成:教师或者管理员可以指定各种题型的题目数量,系统自动从习题库里根据选择的数量,随机抽取对应数量以及题型的习题组装成试卷。例如:指定单选题2题,填空题2题,简答题1题,判断题两题,然后系统会自动从题库里抽这些出来,组成试卷 3.添加习题 将习题添加到习题库当中,可以添加各种题型的题(比如单选,多选,判断,填空,简答五种) 添加的时候有选择添加到那个科目题库的选项
资源推荐
资源详情
资源评论
收起资源包目录
JAVA,数据库最好时mysql习题检索系统 (420个子文件)
$PRODUCT_WORKSPACE_FILE$ 489B
NxTestpaperInfoService.class 15KB
AccountController.class 12KB
AdminInfoController.class 10KB
EchartsController.class 9KB
UserInfoController.class 9KB
TeacherInfoController.class 9KB
NxTestpaperInfoController.class 8KB
NxSystemFileController.class 8KB
AdvertiserInfoController.class 8KB
NxQuestionTypeInfoController.class 8KB
NxQuestionInfoController.class 8KB
NxTypeInfoController.class 7KB
MenuController.class 5KB
FileInfoController.class 5KB
NxScoreInfoController.class 4KB
MessageInfoCommentService.class 4KB
XinwenInfoCommentService.class 4KB
FileInfoCommentService.class 4KB
TeacherInfoService.class 4KB
AdminInfoService.class 4KB
UserInfoService.class 4KB
MessageInfoCommentController.class 4KB
XinwenInfoCommentController.class 4KB
FileInfoCommentController.class 4KB
NxScoreInfoService.class 4KB
MessageInfoService.class 4KB
NxQuestionInfoService.class 3KB
MessageInfoController.class 3KB
AdminInfo.class 3KB
XinwenInfoController.class 3KB
AdvertiserInfoService.class 3KB
TeacherInfo.class 3KB
UserInfo.class 3KB
NxQuestionTypeInfoService.class 3KB
NxScoreInfo.class 3KB
NxTypeInfoService.class 3KB
XinwenInfoService.class 3KB
Account.class 3KB
NxSystemFileInfoService.class 3KB
FileInfoService.class 3KB
NxTestpaperInfo.class 2KB
Result.class 2KB
NxQuestionInfo.class 2KB
FileInfo.class 2KB
EchartsData.class 2KB
ResultCode.class 2KB
MessageInfoComment.class 2KB
XinwenInfoComment.class 2KB
FileInfoComment.class 2KB
MyInterceptor.class 2KB
GlobalExceptionHandler.class 2KB
MessageInfo.class 2KB
EchartsData$Data.class 2KB
WebMvcConfig.class 2KB
AdvertiserInfo.class 2KB
NxTestpaperInfoVo.class 1KB
EchartsData$Series.class 1KB
AuthorityInfo.class 1KB
MyInterceptorConfig.class 1KB
NxQuestionTypeInfo.class 1KB
NxSystemFileInfo.class 1KB
NxTypeInfo.class 1KB
XinwenInfo.class 1KB
NxScoreInfoDao.class 1KB
MessageInfoCommentVo.class 1KB
AuthorityInfo$Model.class 1KB
XinwenInfoCommentVo.class 1KB
FileInfoCommentVo.class 1KB
CustomException.class 1KB
NxQuestionInfoDao.class 1KB
TeacherInfoDao.class 930B
NxTestpaperInfoDao.class 925B
AdminInfoDao.class 920B
UserInfoDao.class 915B
MessageInfoCommentDao.class 903B
XinwenInfoCommentDao.class 898B
FileInfoCommentDao.class 888B
MessageInfoVo.class 831B
MessageInfoDao.class 798B
Application.class 793B
NxSystemFileInfoDao.class 773B
FileInfoDao.class 682B
NxQuestionTypeInfoDao.class 665B
AdvertiserInfoDao.class 649B
XinwenInfoDao.class 633B
NxTypeInfoDao.class 633B
NxQuestionTypeInfoVo.class 336B
AdvertiserInfoVo.class 320B
NxQuestionInfoVo.class 320B
NxScoreInfoVo.class 308B
TeacherInfoVo.class 308B
XinwenInfoVo.class 304B
NxTypeInfoVo.class 304B
AdminInfoVo.class 300B
FileInfoVo.class 296B
UserInfoVo.class 296B
index.css 227KB
index.css 227KB
bootstrap.min.css 119KB
共 420 条
- 1
- 2
- 3
- 4
- 5
资源评论
- 山乔峤峤2023-06-03资源使用价值高,内容详实,给了我很多新想法,感谢大佬分享~
程序员入门进阶
- 粉丝: 2331
- 资源: 968
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功