Commit 104408a6 authored by YangZhaoJun1's avatar YangZhaoJun1

练习需求完成

parent edb7d68c
...@@ -362,6 +362,13 @@ ...@@ -362,6 +362,13 @@
<version>2.2.1</version> <version>2.2.1</version>
</dependency> </dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies> </dependencies>
......
truncate b_carousel; truncate b_carousel;
truncate b_chapter; truncate b_chapter;
truncate b_class; truncate b_class;
truncate b_direction;
truncate b_file; truncate b_file;
truncate b_image; truncate b_image;
truncate b_lesson; truncate b_lesson;
...@@ -20,10 +19,18 @@ truncate s_log; ...@@ -20,10 +19,18 @@ truncate s_log;
truncate t_exam_detail; truncate t_exam_detail;
truncate t_exam_info; truncate t_exam_info;
truncate t_paper; truncate t_paper;
truncate t_paper_chapter_section;
truncate t_paper_chapter; truncate t_paper_chapter;
truncate t_paper_detail; truncate t_paper_detail;
truncate t_paper_section; truncate t_paper_section;
truncate t_question; truncate t_question;
truncate t_question_options; truncate t_question_options;
DELETE FROM b_direction where code !='001' and code != '002';
DELETE FROM s_user WHERE login_name != 'admin'; DELETE FROM s_user WHERE login_name != 'admin';
DELETE FROM s_r_user_role where user_id != '333e421d32d9425ea99afce95b603902'; DELETE FROM s_r_user_role where user_id != '333e421d32d9425ea99afce95b603902';
alter table t_exam_detail AUTO_INCREMENT 1;
alter table t_paper AUTO_INCREMENT 1;
alter table t_paper_chapter_section AUTO_INCREMENT 1;
alter table t_paper_detail AUTO_INCREMENT 1;
alter table t_paper_section AUTO_INCREMENT 1;
\ No newline at end of file
...@@ -163,12 +163,12 @@ public interface BChapterRepository extends BaseMapper<BChapter> { ...@@ -163,12 +163,12 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
"(create_date,create_by,update_date,update_by," + "(create_date,create_by,update_date,update_by," +
"del_flag,flag,business_id," + "del_flag,flag,business_id," +
"sl_id,chapter_name,chapter_level,pid," + "sl_id,chapter_name,chapter_level,pid," +
"chapter_url,md_file,is_test,lesson_or_sl,class_hour,sort)VALUES" + "chapter_url,md_file,is_test,lesson_or_sl,class_hour,sort,experiment_type)VALUES" +
"<foreach collection=\"list\" item=\"item\" separator=\",\">" + "<foreach collection=\"list\" item=\"item\" separator=\",\">" +
"(#{item.createDate},#{item.createBy},#{item.updateDate},#{item.updateBy}," + "(#{item.createDate},#{item.createBy},#{item.updateDate},#{item.updateBy}," +
"#{item.delFlag},#{item.flag},#{item.businessId}," + "#{item.delFlag},#{item.flag},#{item.businessId}," +
"#{item.slId},#{item.chapterName},#{item.chapterLevel},#{item.pid}," + "#{item.slId},#{item.chapterName},#{item.chapterLevel},#{item.pid}," +
"#{item.chapterUrl},#{item.mdFile},#{item.isTest},#{item.lessonOrSl},#{item.classHour},#{item.sort})" + "#{item.chapterUrl},#{item.mdFile},#{item.isTest},#{item.lessonOrSl},#{item.classHour},#{item.sort},#{item.experimentType})" +
"</foreach></script>") "</foreach></script>")
int insertChapterList(List<BChapter> slList); int insertChapterList(List<BChapter> slList);
...@@ -314,16 +314,24 @@ public interface BChapterRepository extends BaseMapper<BChapter> { ...@@ -314,16 +314,24 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
"<if test=\"pdfFinish !=null and pdfFinish != '' \"> set pdf_finish = '1' </if>" + "<if test=\"pdfFinish !=null and pdfFinish != '' \"> set pdf_finish = '1' </if>" +
"<if test=\"videoFinish !=null and videoFinish != ''\"> set video_finish = '1' </if>" + "<if test=\"videoFinish !=null and videoFinish != ''\"> set video_finish = '1' </if>" +
"<if test=\"paperFinish !=null and paperFinish != ''\"> set paper_finish = '1' </if>" + "<if test=\"paperFinish !=null and paperFinish != ''\"> set paper_finish = '1' </if>" +
"<if test=\"score !=null and score != ''\"> set score = #{score} </if>" + "<if test=\"score !=null and score != ''\"> set score = #{score}, </if>" +
"<if test=\"isComplete !=null and isComplete != ''\"> set is_complete = #{isComplete} </if>" + "<if test=\"isComplete !=null and isComplete != ''\"> is_complete = #{isComplete} </if>" +
"where student_id = #{studentId} and chapter_id = #{chapterId} </script>") "where student_id = #{studentId} and chapter_id = #{chapterId} </script>")
int updateToFinish(ScoreInfoDTO scoreInfoDTO); int updateToFinish(ScoreInfoDTO scoreInfoDTO);
@Select(" SELECT business_id AS businessId,\n" + @Select(" SELECT business_id AS businessId\n" +
" from b_r_student_chapter \n" + " from b_r_student_chapter \n" +
" where student_id = #{stuId} \n" + " where student_id = #{stuId} \n" +
" and chapter_id = #{chapterId} LIMIT 1") " and chapter_id = #{chapterId} LIMIT 1")
ScoreInfoDTO queryStudentChapter(@Param("chapterId") String chapterId, @Param("stuId") String stuId); ScoreInfoDTO queryStudentChapter(@Param("chapterId") String chapterId, @Param("stuId") String stuId);
@Select("select paper_finish from b_r_student_chapter where chapter_id = #{chapterId} and student_id = #{userId}")
String queryPaperFinish(@Param("chapterId") String chapterId, @Param("userId")String userId);
@Insert("<script>insert into b_r_student_chapter" +
"(business_id,student_id,chapter_id,is_complete,sl_id,score,ppt_finish,pdf_finish,video_finish,paper_finish)" +
" values " +
"(#{businessId},#{studentId},#{chapterId},#{isComplete},#{slId},#{score},#{pptFinish},#{pdfFinish},#{videoFinish},#{paperFinish})</script>")
int insertStudentChapter(ScoreInfoDTO scoreInfoDTO);
} }
...@@ -535,7 +535,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -535,7 +535,7 @@ public class BChapterServiceImpl implements BChapterService {
scoreInfoDTO.setSlId(slId); scoreInfoDTO.setSlId(slId);
scoreInfoDTO.setScore(-1); scoreInfoDTO.setScore(-1);
UserUtil.setCurrentPersistOperation(scoreInfoDTO); UserUtil.setCurrentPersistOperation(scoreInfoDTO);
return bChapterRepository.updateIsComplete(scoreInfoDTO); return bChapterRepository.insertStudentChapter(scoreInfoDTO);
} }
} }
......
...@@ -30,9 +30,9 @@ public interface BLessonRepository extends BaseMapper<BLesson> { ...@@ -30,9 +30,9 @@ public interface BLessonRepository extends BaseMapper<BLesson> {
"left join b_lesson_direction bld on bld.lession_id = b.business_id " + "left join b_lesson_direction bld on bld.lession_id = b.business_id " +
"left join b_direction bd on bd.business_id = bld.direction_id "+ "left join b_direction bd on bd.business_id = bld.direction_id "+
"where b.del_flag != 1 and b.flag = 1 " + "where b.del_flag != 1 and b.flag = 1 " +
"<if test=\"lessonName!=null and lessonName != ''\">and b.`lesson_name` like LIKE CONCAT('%',#{lessonName},'%')</if>"+ "<if test=\"lessonName!=null and lessonName != ''\">and b.`lesson_name` LIKE CONCAT('%',#{lessonName},'%') </if>"+
"<if test=\"directionId!=null and directionId != ''\">and bld.direction_id = #{directionId}</if>"+ "<if test=\"directionId!=null and directionId != ''\">and bld.direction_id = #{directionId} </if>"+
"<if test=\"code!=null and code != ''\">and b.`code` like LIKE CONCAT('%',#{code},'%')</if></script>") "<if test=\"code!=null and code != ''\">and b.`code` LIKE CONCAT('%',#{code},'%') </if></script>")
@ResultMap(value = "BaseResultMap") @ResultMap(value = "BaseResultMap")
List<BLesson> queryBLessons(BLesson param); List<BLesson> queryBLessons(BLesson param);
......
...@@ -128,7 +128,7 @@ public interface BStudentRepository extends BaseMapper<BStudent> { ...@@ -128,7 +128,7 @@ public interface BStudentRepository extends BaseMapper<BStudent> {
"(CONCAT((SELECT COUNT(*) from b_r_student_chapter " + "(CONCAT((SELECT COUNT(*) from b_r_student_chapter " +
"where student_id = t4.business_id and sl_id = #{slId} and is_complete = '1')," + "where student_id = t4.business_id and sl_id = #{slId} and is_complete = '1')," +
"'/'," + "'/'," +
"(SELECT COUNT(*) from b_chapter where is_test like '1' and sl_id = #{slId})) \n" + "(SELECT COUNT(*) from b_chapter where is_test like CONCAT('%','1','%') and sl_id = #{slId})) \n" +
") AS finishNum " + ") AS finishNum " +
"FROM\n" + "FROM\n" +
"b_r_sl_student t2\n" + "b_r_sl_student t2\n" +
......
package org.rcisoft.business.texaminfo;
import lombok.Data;
import org.rcisoft.business.tquestion.entity.TQuestion;
import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* Created by Administrator on 2018/2/1.
*/
@Data
public class OptionsDto {
private String choiceOptions;
private String multiSelectOptions;
private String judgmentOptions;
private String chapterId;
private String slId;
private String studentCode;
private String examInfoId;
}
...@@ -5,6 +5,11 @@ package org.rcisoft.business.texaminfo.controller; ...@@ -5,6 +5,11 @@ package org.rcisoft.business.texaminfo.controller;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.texaminfo.OptionsDto;
import org.rcisoft.business.tquestion.entity.TQuestion;
import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -92,4 +97,24 @@ public class TExamInfoController extends PaginationController<TExamInfo> { ...@@ -92,4 +97,24 @@ public class TExamInfoController extends PaginationController<TExamInfo> {
tExamInfoServiceImpl.findAllByPagination(getPaginationUtility(), tExamInfo); tExamInfoServiceImpl.findAllByPagination(getPaginationUtility(), tExamInfo);
return getGridModelResponse(); return getGridModelResponse();
} }
@ApiOperation(value="学生完成练习", notes="完成练习")
@ApiImplicitParams({@ApiImplicitParam(name = "choiceOptions", value = "单选题数组", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "multiSelectOptions", value = "多选题数组", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "judgmentOptions", value = "判断题数组", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "examInfoId", value = "考试信息表Id", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "studentCode", value = "学号", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "chapterId", value = "章节ID", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "slId", value = "开课ID", required = true, dataType = "varchar")})
@PostMapping("/finishPractice")
@PreAuthorize("hasRole('ROLE_1003')")
public Result finishPractice(OptionsDto options) {
PersistModel data = tExamInfoServiceImpl.finishPractice(options,UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
options);
}
} }
package org.rcisoft.business.texaminfo.dao; package org.rcisoft.business.texaminfo.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.rcisoft.business.texaminfo.entity.TExamDetail; import org.rcisoft.business.texaminfo.entity.TExamDetail;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.apache.ibatis.annotations.ResultMap; import org.apache.ibatis.annotations.ResultMap;
...@@ -25,5 +27,15 @@ public interface TExamDetailRepository extends BaseMapper<TExamDetail> { ...@@ -25,5 +27,15 @@ public interface TExamDetailRepository extends BaseMapper<TExamDetail> {
+ "</script>") + "</script>")
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
List<TExamDetail> queryTExamDetails(TExamDetail tExamDetail); List<TExamDetail> queryTExamDetails(TExamDetail tExamDetail);
@Insert("<script>INSERT INTO t_exam_detail " +
"(p_id,e_id,q_id,u_id,u_answer,qtype)VALUES" +
"<foreach collection=\"list\" item=\"item\" separator=\",\">" +
"( #{item.pId},#{item.eId},#{item.qId},#{item.uId},#{item.uAnswer},#{item.qtype})" +
"</foreach></script>")
int insertList(List<TExamDetail> examDetails);
@Select("select u_answer from t_exam_detail where e_id = #{eId} and q_id = #{qId} and u_id = #{userId}")
String queryUAnswer(@Param("qId") String qId, @Param("userId") String userId, @Param("eId") String eId);
} }
package org.rcisoft.business.texaminfo.dao; package org.rcisoft.business.texaminfo.dao;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Update; import org.rcisoft.business.texaminfo.entity.TExamDetail;
import org.rcisoft.core.base.BaseMapper; import org.rcisoft.core.base.BaseMapper;
import org.rcisoft.business.texaminfo.entity.TExamInfo; import org.rcisoft.business.texaminfo.entity.TExamInfo;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -32,10 +30,18 @@ public interface TExamInfoRepository extends BaseMapper<TExamInfo> { ...@@ -32,10 +30,18 @@ public interface TExamInfoRepository extends BaseMapper<TExamInfo> {
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
TExamInfo selectExamInfoByPid(String paperId); TExamInfo selectExamInfoByPid(String paperId);
@Select("<script> select business_id from t_paper where chap_id = #{chapterId} and status = '0' </script>") @Select("<script> select business_id from t_paper where chap_id = #{chapterId} order by status asc </script>")
List<String> queryPidByChapterId( @Param("chapterId") String chapterId); List<String> queryPidByChapterId( @Param("chapterId") String chapterId);
@Update("<script> update t_paper set status = '1' where business_id = #{pId} </script>") @Update("<script> update t_paper set status = '1' where business_id = #{pId} </script>")
void updateStatus( @Param("pId") String pId); void updateStatus( @Param("pId") String pId);
@Select("<script> select business_id from t_exam_info where u_id = #{userId} </script>")
@ResultMap(value = "BaseResultMap" )
TExamInfo queryIdByUserId(String userId);
@Select("<script> select p_id from t_exam_info where business_id = #{examInfoId} </script>")
String queryPaperIdById(String examInfoId);
} }
...@@ -20,7 +20,7 @@ import java.util.List; ...@@ -20,7 +20,7 @@ import java.util.List;
@Table(name = "t_exam_detail") @Table(name = "t_exam_detail")
public class TExamDetail extends IdEntity<TExamDetail> { public class TExamDetail extends IdEntity<TExamDetail> {
private static final long serialVersionUID = -3767007435655705399L;
private String pId; private String pId;
......
package org.rcisoft.business.texaminfo.service; package org.rcisoft.business.texaminfo.service;
import org.apache.tools.ant.taskdefs.condition.Http; import org.apache.tools.ant.taskdefs.condition.Http;
import org.rcisoft.business.texaminfo.OptionsDto;
import org.rcisoft.business.texaminfo.entity.TExamInfo; import org.rcisoft.business.texaminfo.entity.TExamInfo;
import org.rcisoft.business.tquestion.entity.TQuestion;
import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
...@@ -50,6 +53,5 @@ public interface TExamInfoService { ...@@ -50,6 +53,5 @@ public interface TExamInfoService {
TExamInfo tExamInfo); TExamInfo tExamInfo);
PersistModel finishPractice(OptionsDto options, String userId);
} }
package org.rcisoft.business.texaminfo.service.impl; package org.rcisoft.business.texaminfo.service.impl;
import net.sf.json.JSONArray;
import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.rcisoft.business.bchapter.service.BChapterService;
import org.rcisoft.business.bchapter.service.impl.BChapterServiceImpl;
import org.rcisoft.business.texaminfo.OptionsDto;
import org.rcisoft.business.texaminfo.dao.TExamDetailRepository;
import org.rcisoft.business.texaminfo.entity.TExamDetail;
import org.rcisoft.business.tquestion.entity.TQuestion;
import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.service.SerializationUtils;
import org.rcisoft.core.util.IpUtil; import org.rcisoft.core.util.IpUtil;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
...@@ -17,6 +30,7 @@ import org.springframework.transaction.annotation.Propagation; ...@@ -17,6 +30,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -33,6 +47,14 @@ public class TExamInfoServiceImpl implements TExamInfoService { ...@@ -33,6 +47,14 @@ public class TExamInfoServiceImpl implements TExamInfoService {
@Autowired @Autowired
private TExamInfoRepository tExamInfoRepository; private TExamInfoRepository tExamInfoRepository;
@Autowired
private TExamDetailRepository tExamDetailRepository;
@Autowired
private BChapterService bChapterService;
@Autowired
private RcRedisService rcRedisServiceImpl;
/** /**
* 保存 tExamInfo * 保存 tExamInfo
...@@ -44,17 +66,19 @@ public class TExamInfoServiceImpl implements TExamInfoService { ...@@ -44,17 +66,19 @@ public class TExamInfoServiceImpl implements TExamInfoService {
public PersistModel save(String chapterId, String userId, HttpServletRequest request){ public PersistModel save(String chapterId, String userId, HttpServletRequest request){
TExamInfo tExamInfo = new TExamInfo(); TExamInfo tExamInfo = new TExamInfo();
List<String> list = tExamInfoRepository.queryPidByChapterId(chapterId); List<String> list = tExamInfoRepository.queryPidByChapterId(chapterId);
if(list.size()>0){
String pId = list.get(0); String pId = list.get(0);
tExamInfo.setCommonBusinessId();
tExamInfo.setPId(pId); tExamInfo.setPId(pId);
tExamInfoRepository.updateStatus(pId);
tExamInfo.setUId(userId); tExamInfo.setUId(userId);
tExamInfo.setIp(IpUtil.getIpAddr(request)); tExamInfo.setIp(IpUtil.getIpAddr(request));
UserUtil.setCurrentPersistOperation(tExamInfo); UserUtil.setCurrentPersistOperation(tExamInfo);
int line = tExamInfoRepository.insertSelective(tExamInfo); int line = tExamInfoRepository.insertSelective(tExamInfo);
log.info(UserUtil.getUserInfoProp(tExamInfo.getToken(),UserUtil.USER_USERNAME)+"新增了ID为"+ tExamInfoRepository.updateStatus(pId);
tExamInfo.getBusinessId()+"的信息");
return new PersistModel(line); return new PersistModel(line);
}else{
throw new ServiceException(ResultServiceEnums.NO_PAPER_EXISTS);
}
} }
...@@ -107,4 +131,56 @@ public class TExamInfoServiceImpl implements TExamInfoService { ...@@ -107,4 +131,56 @@ public class TExamInfoServiceImpl implements TExamInfoService {
return tExamInfoRepository.queryTExamInfos(tExamInfo); return tExamInfoRepository.queryTExamInfos(tExamInfo);
} }
@Override
public PersistModel finishPractice(OptionsDto options, String userId) {
String paperId = tExamInfoRepository.queryPaperIdById(options.getExamInfoId());
List<TExamDetail> examDetails = new ArrayList<>();
//遍历单选
JSONArray choiceJson = JSONArray.fromObject(options.getChoiceOptions());
List<TQuestion> choiceOptions= (List<TQuestion>)JSONArray.toCollection(choiceJson, TQuestion.class);
JSONArray multiSelectJson = JSONArray.fromObject(options.getMultiSelectOptions());
List<TQuestion> multiSelectOptions= (List<TQuestion>)JSONArray.toCollection(multiSelectJson, TQuestion.class);
JSONArray judgmentJson = JSONArray.fromObject(options.getJudgmentOptions());
List<TQuestion> judgmentOptions= (List<TQuestion>)JSONArray.toCollection(judgmentJson, TQuestion.class);
for(TQuestion choiceOption : choiceOptions){
TExamDetail examDetail = new TExamDetail();
examDetail.setPId(paperId);
examDetail.setEId(options.getExamInfoId());
examDetail.setUId(userId);
examDetail.setQId(choiceOption.getBusinessId());
examDetail.setUAnswer(choiceOption.getUanswer());
examDetail.setQtype("1");
examDetails.add(examDetail);
}
//遍历多选
for(TQuestion multiSelectOption : multiSelectOptions){
TExamDetail examDetail = new TExamDetail();
examDetail.setPId(paperId);
examDetail.setEId(options.getExamInfoId());
examDetail.setUId(userId);
examDetail.setQId(multiSelectOption.getBusinessId());
examDetail.setUAnswer(multiSelectOption.getUanswer());
examDetail.setQtype("2");
examDetails.add(examDetail);
}
//遍历判断
for(TQuestion judgmentOption : judgmentOptions){
TExamDetail examDetail = new TExamDetail();
examDetail.setPId(paperId);
examDetail.setEId(options.getExamInfoId());
examDetail.setUId(userId);
examDetail.setQId(judgmentOption.getBusinessId());
examDetail.setUAnswer(judgmentOption.getUanswer());
examDetail.setQtype("3");
examDetails.add(examDetail);
}
int result = tExamDetailRepository.insertList(examDetails);
//清除缓存
rcRedisServiceImpl.remove(userId + "_" + options.getChapterId());
//更改练习状态为完成
bChapterService.updateToFinish("4",options.getStudentCode(),options.getChapterId(),options.getSlId());
return new PersistModel(result);
}
} }
...@@ -34,5 +34,8 @@ public interface TPaperChapterRepository extends BaseMapper<TPaperChapter> { ...@@ -34,5 +34,8 @@ public interface TPaperChapterRepository extends BaseMapper<TPaperChapter> {
@Select("SELECT * from t_paper_chapter WHERE chap_id = #{chapterId} and sl_id = #{slId}") @Select("SELECT * from t_paper_chapter WHERE chap_id = #{chapterId} and sl_id = #{slId}")
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
List<TPaperChapter> queryTPaperChapterInfo(@Param("slId") String slId, @Param("chapterId") String chapterId); List<TPaperChapter> queryTPaperChapterInfo(@Param("slId") String slId, @Param("chapterId") String chapterId);
@Select("SELECT pdesc from t_paper_chapter WHERE chap_id = #{chapterId}")
String queryDescByChapId(String chapterId);
} }
...@@ -174,6 +174,9 @@ public class TPaperChapterServiceImpl implements TPaperChapterService { ...@@ -174,6 +174,9 @@ public class TPaperChapterServiceImpl implements TPaperChapterService {
tPaperDetails.add(tPaperDetail); tPaperDetails.add(tPaperDetail);
k++; k++;
} }
if(tPaperDetails.size()<1){
throw new ServiceException(ResultServiceEnums.PARAM_NO_QUESTION);
}
tPaperDetailRepository.insertList(tPaperDetails); tPaperDetailRepository.insertList(tPaperDetails);
}else{ }else{
throw new ServiceException(ResultServiceEnums.INSERT_ERROR); throw new ServiceException(ResultServiceEnums.INSERT_ERROR);
...@@ -263,6 +266,15 @@ public class TPaperChapterServiceImpl implements TPaperChapterService { ...@@ -263,6 +266,15 @@ public class TPaperChapterServiceImpl implements TPaperChapterService {
List<TPaperChapter> tPaperChapters = tPaperChapterRepository.queryTPaperChapterInfo(slId,chapterId); List<TPaperChapter> tPaperChapters = tPaperChapterRepository.queryTPaperChapterInfo(slId,chapterId);
//查询全部的题型数量 //查询全部的题型数量
QuestionNumDto questionNumDto = tQuestionRepository.queryQuestionNum(slId,chapterId); QuestionNumDto questionNumDto = tQuestionRepository.queryQuestionNum(slId,chapterId);
if(questionNumDto==null){
questionNumDto = new QuestionNumDto();
questionNumDto.setChapChoiceNum("0");
questionNumDto.setChapMultiSelectNum("0");
questionNumDto.setChapJudgmentNum("0");
questionNumDto.setSlChoiceNum("0");
questionNumDto.setSlMultiSelectNum("0");
questionNumDto.setSlJudgmentNum("0");
}
if(tPaperChapters.size()>0){ if(tPaperChapters.size()>0){
tPaperChapter = tPaperChapters.get(0); tPaperChapter = tPaperChapters.get(0);
//查询已添加的题型数量 //查询已添加的题型数量
......
...@@ -2,36 +2,27 @@ package org.rcisoft.business.tquestion.controller; ...@@ -2,36 +2,27 @@ package org.rcisoft.business.tquestion.controller;
/*固定导入*/ /*固定导入*/
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.map.HashedMap; import org.rcisoft.business.tquestion.dto.QuestionListAndNumDto;
import org.json.JSONArray;
import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.rcisoft.business.tquestion.service.impl.TQuestionServiceImpl;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.rcisoft.core.result.Result; import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.common.controller.PaginationController; import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
import org.rcisoft.common.model.GridModel; import org.rcisoft.common.model.GridModel;
import org.rcisoft.core.exception.ServiceException;
import javax.validation.Valid; import javax.servlet.http.HttpServletRequest;
import org.rcisoft.business.tquestion.entity.TQuestion; import org.rcisoft.business.tquestion.entity.TQuestion;
import org.rcisoft.business.tquestion.service.TQuestionService; import org.rcisoft.business.tquestion.service.TQuestionService;
import java.util.List;
import java.util.Map;
/** /**
* Created by yangzhaojun on 2018-1-15 19:49:07. * Created by yangzhaojun on 2018-1-15 19:49:07.
*/ */
...@@ -172,17 +163,14 @@ public class TQuestionController extends PaginationController<TQuestion> { ...@@ -172,17 +163,14 @@ public class TQuestionController extends PaginationController<TQuestion> {
@ApiOperation(value="根据条件查询试题", notes="根据条件查询试题") @ApiOperation(value="根据条件查询试题", notes="根据条件查询试题")
@GetMapping(value = "/queryQuestionsByChap_IdAndQtype") @GetMapping(value = "/queryQuestionsByChap_IdAndQtype")
public Result queryBChapters(String chapterId) { public Result queryBChapters(String chapterId, HttpServletRequest request) {
Map<String, Object> map = new HashedMap(); QuestionListAndNumDto questionListAndNum = tQuestionServiceImpl.queryQuestionsByChap_IdAndQtype(chapterId,UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID),request);
map.put("ChoiceList",tQuestionServiceImpl.queryQuestionsByChap_IdAndQtype(chapterId, "1"));
map.put("MultiSelectList",tQuestionServiceImpl.queryQuestionsByChap_IdAndQtype(chapterId, "2"));
map.put("JudgmentList",tQuestionServiceImpl.queryQuestionsByChap_IdAndQtype(chapterId, "3"));
map.put("NumOfChoice" , tQuestionServiceImpl.queryNumByType("1",chapterId));
map.put("NumOfMultiSelect",tQuestionServiceImpl.queryNumByType("2",chapterId));
map.put("NumOfJudgment",tQuestionServiceImpl.queryNumByType("3",chapterId));
return Result.builder(new PersistModel(1), return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
map); questionListAndNum);
} }
} }
...@@ -51,16 +51,16 @@ public interface TQuestionRepository extends BaseMapper<TQuestion> { ...@@ -51,16 +51,16 @@ public interface TQuestionRepository extends BaseMapper<TQuestion> {
"</foreach></script>") "</foreach></script>")
int insertOptionsList(List<TQuestionOptions> optionList); int insertOptionsList(List<TQuestionOptions> optionList);
@Select("<script>select q.qtype,q.business_id,q.qtitle,q.qdesc\n" + @Select("<script>select q.qanswer,q.qtype,q.business_id,q.qtitle,q.qdesc\n" +
"from t_paper_chapter pc \n" + "from t_paper_chapter pc \n" +
"left join t_paper p on p.pc_id = pc.business_id \n" + "left join t_paper p on p.pc_id = pc.business_id \n" +
"left join t_paper_detail pd on pd.p_id = p.business_id \n" + "left join t_paper_detail pd on pd.p_id = p.business_id \n" +
"left join t_paper_section ps on ps.business_id = pd.ps_id \n" + "left join t_paper_section ps on ps.business_id = pd.ps_id \n" +
"left join t_question q on q.business_id = pd.q_id " "left join t_question q on q.business_id = pd.q_id "
+"where pc.chap_id = #{chapterId} and q.qtype = #{qtype}</script>" +"where pc.chap_id = #{chapterId}</script>"
) )
@ResultMap(value = "BaseResultMap" ) @ResultMap(value = "BaseResultMap" )
List<TQuestion> queryQuestionsByChap_IdAndQtype( @Param("chapterId") String chapterId, @Param("qtype") String qtype); List<TQuestion> queryQuestionsByChap_IdAndQtype( @Param("chapterId") String chapterId);
@Select("<script>select q_num from t_paper_chapter_section pcs " + @Select("<script>select q_num from t_paper_chapter_section pcs " +
...@@ -77,21 +77,21 @@ public interface TQuestionRepository extends BaseMapper<TQuestion> { ...@@ -77,21 +77,21 @@ public interface TQuestionRepository extends BaseMapper<TQuestion> {
List<TQuestion> queryChapterQuestionsByChapterId(String chapterId); List<TQuestion> queryChapterQuestionsByChapterId(String chapterId);
@Select("<script>SELECT DISTINCT(sl_id),\n" + @Select("<script>SELECT DISTINCT(sl_id),\n" +
"(SELECT COUNT(*) from t_question where sl_id = #{slId}\n" + "IFNULL((SELECT COUNT(*) from t_question where sl_id = #{slId}\n" +
" and chap_id = #{chapterId}\n" + " and chap_id = #{chapterId}\n" +
" and qtype = '1') as chapChoiceNum,\n" + " and qtype = '1'),0) as chapChoiceNum,\n" +
"(SELECT COUNT(*) from t_question where sl_id = #{slId}\n" + "IFNULL((SELECT COUNT(*) from t_question where sl_id = #{slId}\n" +
" and chap_id = #{chapterId}\n" + " and chap_id = #{chapterId}\n" +
" and qtype = '2') as chapMultiSelectNum,\n" + " and qtype = '2'),0) as chapMultiSelectNum,\n" +
"(SELECT COUNT(*) from t_question where sl_id = #{slId}\n" + "IFNULL((SELECT COUNT(*) from t_question where sl_id = #{slId}\n" +
" and chap_id = #{chapterId}\n" + " and chap_id = #{chapterId}\n" +
" and qtype = '3') as chapJudgmentNum,\n" + " and qtype = '3'),0) as chapJudgmentNum,\n" +
"(SELECT COUNT(*) from t_question where sl_id = #{slId}\n" + "IFNULL((SELECT COUNT(*) from t_question where sl_id = #{slId}\n" +
" and qtype = '1') as slChoiceNum,\n" + " and qtype = '1'),0) as slChoiceNum,\n" +
"(SELECT COUNT(*) from t_question where sl_id = #{slId}\n" + "IFNULL((SELECT COUNT(*) from t_question where sl_id = #{slId}\n" +
" and qtype = '2') as slMultiSelectNum,\n" + " and qtype = '2'),0) as slMultiSelectNum,\n" +
"(SELECT COUNT(*) from t_question where sl_id = #{slId}\n" + "IFNULL((SELECT COUNT(*) from t_question where sl_id = #{slId}\n" +
" and qtype = '3') as slJudgmentNum\n" + " and qtype = '3'),0) as slJudgmentNum\n" +
" from t_question WHERE sl_id = #{slId}</script>") " from t_question WHERE sl_id = #{slId}</script>")
QuestionNumDto queryQuestionNum(@Param("slId") String slId, @Param("chapterId") String chapterId); QuestionNumDto queryQuestionNum(@Param("slId") String slId, @Param("chapterId") String chapterId);
} }
......
package org.rcisoft.business.tquestion.dto;
import lombok.Data;
import org.rcisoft.business.tquestion.entity.TQuestion;
import java.util.List;
/**
* Created by Administrator on 2018/2/5.
*/
@Data
public class QuestionListAndNumDto {
private List<TQuestion> ChoiceList;
private List<TQuestion> MultiSelectList;
private List<TQuestion> JudgmentList;
private String explain;
private String examInfoId;
private String NumOfChoice;
private String NumOfMultiSelect;
private String NumOfJudgment;
}
...@@ -53,6 +53,9 @@ public class TQuestion extends IdEntity<TQuestion> { ...@@ -53,6 +53,9 @@ public class TQuestion extends IdEntity<TQuestion> {
@Transient @Transient
private String pcompose; private String pcompose;
@Transient
private String userId;
@Transient @Transient
List<TQuestionOptions> options; List<TQuestionOptions> options;
...@@ -63,6 +66,9 @@ public class TQuestion extends IdEntity<TQuestion> { ...@@ -63,6 +66,9 @@ public class TQuestion extends IdEntity<TQuestion> {
@Transient @Transient
private String inUse; private String inUse;
@Transient
private String uanswer;
public TQuestion(String businessId) { public TQuestion(String businessId) {
this.businessId = businessId; this.businessId = businessId;
} }
......
package org.rcisoft.business.tquestion.service; package org.rcisoft.business.tquestion.service;
import org.rcisoft.business.tquestion.dto.QuestionListAndNumDto;
import org.rcisoft.business.tquestion.entity.TQuestion; import org.rcisoft.business.tquestion.entity.TQuestion;
import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by yangzhaojun on 2018-1-15 19:49:07. * Created by yangzhaojun on 2018-1-15 19:49:07.
...@@ -58,12 +58,10 @@ public interface TQuestionService { ...@@ -58,12 +58,10 @@ public interface TQuestionService {
/** /**
* 根据章节ID和题目类型查询题目 * 根据章节ID和题目类型查询题目
* @param chapterId * @param chapterId
* @param qtype
* @return * @return
*/ */
List<TQuestion> queryQuestionsByChap_IdAndQtype(String chapterId, String qtype); QuestionListAndNumDto queryQuestionsByChap_IdAndQtype(String chapterId, String userId, HttpServletRequest request);
String queryNumByType(String type, String chapId);
List<TQuestion> queryTQuestionBySlId(TQuestion tQuestion); List<TQuestion> queryTQuestionBySlId(TQuestion tQuestion);
} }
package org.rcisoft.business.tquestion.service.impl; package org.rcisoft.business.tquestion.service.impl;
import com.google.gson.Gson; import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.apache.commons.collections.MapUtils; import org.rcisoft.business.bstudent.dao.BStudentRepository;
import org.json.JSONArray; import org.rcisoft.business.texaminfo.dao.TExamDetailRepository;
import org.rcisoft.business.tpaper.dao.TPaperRepository; import org.rcisoft.business.texaminfo.dao.TExamInfoRepository;
import org.rcisoft.business.tpaperchapter.entity.TPaperChapter; import org.rcisoft.business.texaminfo.entity.TExamInfo;
import org.rcisoft.business.texaminfo.service.TExamInfoService;
import org.rcisoft.business.tpaperchapter.dao.TPaperChapterRepository;
import org.rcisoft.business.tquestion.dto.QuestionListAndNumDto;
import org.rcisoft.business.tquestion.dao.TQuestionOptionsRepository; import org.rcisoft.business.tquestion.dao.TQuestionOptionsRepository;
import org.rcisoft.business.tquestion.entity.TQuestionOptions; import org.rcisoft.business.tquestion.entity.TQuestionOptions;
import org.rcisoft.core.constant.MessageConstant; import org.rcisoft.core.service.RcRedisService;
import org.rcisoft.core.service.SerializationUtils;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
...@@ -27,6 +31,8 @@ import java.util.*; ...@@ -27,6 +31,8 @@ import java.util.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest;
/** /**
* Created by yangzhaojun on 2018-1-15 19:49:07. * Created by yangzhaojun on 2018-1-15 19:49:07.
*/ */
...@@ -41,6 +47,27 @@ public class TQuestionServiceImpl implements TQuestionService { ...@@ -41,6 +47,27 @@ public class TQuestionServiceImpl implements TQuestionService {
@Autowired @Autowired
private TQuestionOptionsRepository tQuestionOptionsRepository; private TQuestionOptionsRepository tQuestionOptionsRepository;
@Autowired
private TExamInfoRepository tExamInfoRepository;
@Autowired
private TExamDetailRepository tExamDetailRepository;
@Autowired
private TExamInfoService tExamInfoService;
@Autowired
private BStudentRepository bStudentRepository;
@Autowired
private BChapterRepository bChapterRepository;
@Autowired
private TPaperChapterRepository tPaperChapterRepository;
@Autowired
private RcRedisService rcRedisServiceImpl;
/** /**
* 保存 tQuestion * 保存 tQuestion
* @param tQuestion * @param tQuestion
...@@ -189,20 +216,71 @@ public class TQuestionServiceImpl implements TQuestionService { ...@@ -189,20 +216,71 @@ public class TQuestionServiceImpl implements TQuestionService {
} }
@Override @Override
public List<TQuestion> queryQuestionsByChap_IdAndQtype(String chapterId, String qtype) { public QuestionListAndNumDto queryQuestionsByChap_IdAndQtype(String chapterId, String userId, HttpServletRequest request) {
List<TQuestion> tQuestions = tQuestionRepository.queryQuestionsByChap_IdAndQtype(chapterId,qtype); //从缓存中获取数据
for(TQuestion tQuestion : tQuestions){ byte[] results = rcRedisServiceImpl.getBytes(userId + "_" + chapterId);
if(!qtype.equals("3")){ QuestionListAndNumDto questionListAndNum = new QuestionListAndNumDto();
List<TQuestionOptions> options = tQuestionOptionsRepository.queryTQuestionOptions(tQuestion.getBusinessId()); //判断缓存中是否有数据,有数据直接返回;没有数据先查询数据,再放入缓存
tQuestion.setOptions(options); if(results!=null){
questionListAndNum = SerializationUtils.deserializer(results, QuestionListAndNumDto.class);
if(questionListAndNum!=null)
return questionListAndNum;
} }
TExamInfo tExamInfo = tExamInfoRepository.queryIdByUserId(userId);
String explain = tPaperChapterRepository.queryDescByChapId(chapterId);
if(tExamInfo==null){
//占卷子
tExamInfoService.save(chapterId, userId,request);
} }
return tQuestions; String stuId = bStudentRepository.queryStudentByUserId(userId);
//判断是否已做过练习
String isFinish = bChapterRepository.queryPaperFinish(chapterId,stuId);
List<TQuestion> choiceList = new ArrayList<>();
List<TQuestion> multiSelectList = new ArrayList<>();
List<TQuestion> judgmentList = new ArrayList<>();
List<TQuestion> questionList = tQuestionRepository.queryQuestionsByChap_IdAndQtype(chapterId);
for(TQuestion question : questionList){
if(question!=null){
if(question.getQtype().equals("1")){
//获取全部选项
List<TQuestionOptions> options = tQuestionOptionsRepository.queryTQuestionOptions(question.getBusinessId());
question.setOptions(options);
if(isFinish!=null&&isFinish.equals("1")){
//获取学生选择的选项
String uAnswer = tExamDetailRepository.queryUAnswer(question.getBusinessId(),userId,tExamInfo.getBusinessId());
question.setUanswer(uAnswer);
}
choiceList.add(question);
}else if(question.getQtype().equals("2")){
//获取全部选项
List<TQuestionOptions> options = tQuestionOptionsRepository.queryTQuestionOptions(question.getBusinessId());
question.setOptions(options);
if(isFinish!=null&&isFinish.equals("1")){
//获取学生选择的选项
String uAnswer = tExamDetailRepository.queryUAnswer(question.getBusinessId(),userId,tExamInfo.getBusinessId());
question.setUanswer(uAnswer);
}
multiSelectList.add(question);
}else {
if(isFinish!=null&&isFinish.equals("1")){
String uAnswer = tExamDetailRepository.queryUAnswer(question.getBusinessId(),userId,tExamInfo.getBusinessId());
question.setUanswer(uAnswer);
}
judgmentList.add(question);
} }
}
@Override }
public String queryNumByType(String qtype,String chapId) { questionListAndNum.setChoiceList(choiceList);
return tQuestionRepository.queryNumByType(qtype,chapId); questionListAndNum.setMultiSelectList(multiSelectList);
questionListAndNum.setJudgmentList(judgmentList);
questionListAndNum.setExamInfoId(tExamInfo.getBusinessId());
questionListAndNum.setExplain(explain);
questionListAndNum.setNumOfChoice(tQuestionRepository.queryNumByType("1",chapterId));
questionListAndNum.setNumOfMultiSelect(tQuestionRepository.queryNumByType("2",chapterId));
questionListAndNum.setNumOfJudgment(tQuestionRepository.queryNumByType("3",chapterId));
//将数据放入缓存中
rcRedisServiceImpl.setBytes(userId + "_" + chapterId,SerializationUtils.serializer(questionListAndNum));
return questionListAndNum;
} }
@Override @Override
...@@ -223,5 +301,4 @@ public class TQuestionServiceImpl implements TQuestionService { ...@@ -223,5 +301,4 @@ public class TQuestionServiceImpl implements TQuestionService {
return questions; return questions;
} }
} }
...@@ -138,7 +138,11 @@ public enum ResultServiceEnums { ...@@ -138,7 +138,11 @@ public enum ResultServiceEnums {
UPLOAD_ERROR (75,"上传失败"), UPLOAD_ERROR (75,"上传失败"),
PAPER_IN_USE (76,"该练习已被学生使用,不可修改") PAPER_IN_USE (76,"该练习已被学生使用,不可修改"),
PARAM_NO_QUESTION (77,"请至少添加一个问题"),
NO_PAPER_EXISTS (78,"未查询到试卷")
; ;
private Integer code; private Integer code;
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
<select id="scoreReportChildList" parameterType="java.util.Map" resultMap="ScoreReportResultMap"> <select id="scoreReportChildList" parameterType="java.util.Map" resultMap="ScoreReportResultMap">
SELECT DISTINCT bc.business_id, SELECT DISTINCT bc.business_id,
bc.chapter_name, bc.automatic,bc.sl_id, bc.chapter_name, bc.automatic,bc.sl_id,bc.experiment_type,
ROUND((SELECT AVG(bsc.score) from b_r_student_chapter bsc ROUND((SELECT AVG(bsc.score) from b_r_student_chapter bsc
where bsc.chapter_id = bc.business_id and score != '-1'),2) as average, where bsc.chapter_id = bc.business_id and score != '-1'),2) as average,
(SELECT MAX(bsc.score) from b_r_student_chapter bsc (SELECT MAX(bsc.score) from b_r_student_chapter bsc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment