package com.qxueyou.scc.exam.service.impl;
|
|
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.service.impl.CommonAppService;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.TraceUtils;
|
import com.qxueyou.scc.base.util.UUIDUtils;
|
import com.qxueyou.scc.exam.model.ExamPaperInfo;
|
import com.qxueyou.scc.exam.service.IExamPaperSectionService;
|
import com.qxueyou.scc.exam.service.IExamPaperService;
|
import com.qxueyou.scc.exercise.model.ExerciseGroup;
|
import com.qxueyou.scc.exercise.model.ExerciseItem;
|
import com.qxueyou.scc.exercise.service.IExerciseGroupService;
|
|
/**
|
* 试卷管理服务层
|
*
|
* @author kevin
|
* @createTime 2017-11-1
|
*/
|
@Service
|
public class ExamPaperService extends CommonAppService implements IExamPaperService {
|
|
@Autowired
|
IExerciseGroupService exerciseGroupService;
|
|
@Autowired
|
IExamPaperSectionService examPaperSectionService;
|
|
@Override
|
public Result addExamPaper(ExamPaperInfo examPaperInfo) {
|
Result result = new Result(true);
|
String examPaperId = null, groupId = null;
|
ExerciseGroup exerciseGroup = null;
|
|
//创建试卷关联题库
|
exerciseGroup = new ExerciseGroup();
|
exerciseGroup.setName(examPaperInfo.getExamPaperName()+"-试卷题库");
|
exerciseGroup.setType(ExerciseGroup.TYPE_EXERCISE_EXAM_ITEM);
|
groupId = exerciseGroupService.addExerciseGroup(exerciseGroup);
|
|
//保存试卷
|
examPaperId = UUIDUtils.generateUUID().replace("-", "");
|
examPaperInfo.setExamPaperId(examPaperId);
|
examPaperInfo.setPaperStatus(ExamPaperInfo.STATUS_DRAFT);
|
examPaperInfo.setGroupId(groupId);
|
TraceUtils.setCreateTrace(examPaperInfo);
|
this.insert(examPaperInfo);
|
|
result.addData("examPaperId", examPaperId);
|
return result;
|
}
|
|
|
@Override
|
public Result deleteExamPaper(String[] examPaperIds) {
|
Result result = new Result(true) ;
|
if(examPaperIds!=null && examPaperIds.length>0 ){
|
String hql = "update ExamPaperInfo set deleteFlag = true where examPaperId=?";
|
result = bulkUpdateInLoop(hql, examPaperIds);
|
}
|
return result;
|
}
|
|
@Override
|
public Result updateExamPaper(ExamPaperInfo param) {
|
ExamPaperInfo examPaperInfo = read(ExamPaperInfo.class, param.getExamPaperId());
|
if(examPaperInfo!=null){
|
TraceUtils.setUpdateTrace(examPaperInfo);
|
examPaperInfo.setDifficultLevel(param.getDifficultLevel());
|
examPaperInfo.setExamPaperName(param.getExamPaperName());
|
}
|
return save(examPaperInfo);
|
}
|
|
@Override
|
public Result doPublishExamPaper(String[] examPaperIds) {
|
Map<String, Object> pramMap = null;
|
if(examPaperIds!=null && examPaperIds.length>0){
|
pramMap = new HashMap<String, Object>(1);
|
pramMap.put("examPaperIds", examPaperIds);
|
String hql = "from ExamPaperInfo where examPaperId in (:examPaperIds)";
|
List<ExamPaperInfo> lstExamPaperInfo = this.findByComplexHql(hql,pramMap, ExamPaperInfo.class);
|
|
for (ExamPaperInfo examPaperInfo : lstExamPaperInfo) {
|
if(ExamPaperInfo.STATUS_DRAFT!=examPaperInfo.getPaperStatus()){
|
return new Result(false, "只有草稿状态的试卷,才能发布。");
|
}
|
|
if(examPaperInfo.getTotalScore()<=0){
|
return new Result(false, "试卷总分大于零,才能发布。");
|
}
|
|
examPaperInfo.setPaperStatus(ExamPaperInfo.STATUS_PUBLISH);
|
TraceUtils.setUpdateTrace(examPaperInfo);
|
save(examPaperInfo);
|
}
|
}else{
|
return new Result(false, "没有选择要发布的试卷。");
|
}
|
return new Result(true);
|
}
|
|
@Override
|
public Result doRevokeExamPaper(String[] examPaperIds) {
|
Map<String, Object> pramMap = null;
|
if(examPaperIds!=null && examPaperIds.length>0){
|
pramMap = new HashMap<String, Object>(1);
|
pramMap.put("examPaperIds", examPaperIds);
|
String hql = "from ExamPaperInfo where examPaperId in (:examPaperIds)";
|
List<ExamPaperInfo> lstExamPaperInfo = this.findByComplexHql(hql,pramMap, ExamPaperInfo.class);
|
for (ExamPaperInfo examPaperInfo : lstExamPaperInfo) {
|
if(ExamPaperInfo.STATUS_PUBLISH!=examPaperInfo.getPaperStatus()){
|
return new Result(false, "只有发布状态的试卷,才能撤回。");
|
}
|
examPaperInfo.setPaperStatus(ExamPaperInfo.STATUS_DRAFT);
|
TraceUtils.setUpdateTrace(examPaperInfo);
|
save(examPaperInfo);
|
}
|
}else{
|
return new Result(false, "没有选择要撤回的试卷。");
|
}
|
|
return new Result(true);
|
}
|
|
@Override
|
public ExamPaperInfo queryExamPaperDetail(String examPaperId) {
|
ExamPaperInfo examPaperInfo= this.read(ExamPaperInfo.class, examPaperId);
|
ExerciseGroup exerciseGroup = exerciseGroupService.queryExerciseGroupDetail(examPaperInfo.getGroupId());
|
examPaperInfo.setExerciseGroup(exerciseGroup);
|
return examPaperInfo;
|
}
|
|
@Override
|
public Map<String,ExamPaperInfo> queryExamPaperItemsStatistic(String[] examPaperIds){
|
Map<String,ExamPaperInfo> resultMap =null;
|
if(examPaperIds!=null &&examPaperIds.length>0){
|
resultMap = new LinkedHashMap<String,ExamPaperInfo>(examPaperIds.length);
|
String hql = " select p.examPaperId, i.type,count(i.type) from ExamPaperInfo p, ExerciseGroupItemRe r,ExerciseItem i where p.examPaperId in (:examPaperIds) "
|
+ "and p.groupId=r.exerciseGroupId and r.exerciseItemId = i.exerciseId and r.deleteFlag is false group by p.examPaperId,i.type";
|
Map<String,Object> param =new HashMap<String,Object>();
|
param.put("examPaperIds", examPaperIds);
|
List<Object[]> lstItemStatics = this.findByComplexHql(hql, param, Object[].class);
|
|
ExamPaperInfo tempPaperInfo = null;
|
String tempPaperId = null;
|
short tempType= 0;
|
int tempCount=0;
|
for(int i=0;i<lstItemStatics.size();i++){
|
tempPaperId= (String) lstItemStatics.get(i)[0];
|
tempType = (Short) lstItemStatics.get(i)[1];
|
tempCount = ((Long) lstItemStatics.get(i)[2]).intValue();
|
|
if(resultMap.get(tempPaperId)==null){
|
tempPaperInfo = new ExamPaperInfo();
|
tempPaperInfo.setExamPaperId(tempPaperId);
|
resultMap.put(tempPaperId, tempPaperInfo);
|
}else{
|
tempPaperInfo = resultMap.get(tempPaperId);
|
}
|
|
if(tempType==ExerciseItem.TYPE_SINGLE_SELECT){
|
tempPaperInfo.setSingleSelectCount(tempCount);
|
}else if(tempType==ExerciseItem.TYPE_MULTI_SELECT){
|
tempPaperInfo.setMultiSelectCount(tempCount);
|
}else if(tempType==ExerciseItem.TYPE_TRUE_OR_FALSE){
|
tempPaperInfo.setJudgeCount(tempCount);
|
}else if(tempType==ExerciseItem.TYPE_ESSAY_QUESTION){
|
tempPaperInfo.setQuestionCount(tempCount);
|
}else if(tempType==ExerciseItem.TYPE_FILL_BLANKS){
|
tempPaperInfo.setFillBlanksCount(tempCount);
|
}
|
}
|
}
|
return resultMap;
|
}
|
|
@Override
|
public ExamPaperInfo queryExamPaperByCode(String examId,String paperCode){
|
return this.findUnique("select p from ExamReExamPaper r,ExamPaperInfo p "
|
+ " where r.examPaperId=p.examPaperId and r.examId = ? and r.relationPaperCode=? and r.deleteFlag is false",
|
CollectionUtils.newList(examId, paperCode), ExamPaperInfo.class);
|
}
|
|
@Override
|
public ExamPaperInfo queryExamPaperByGroupId(String groupId){
|
return this.findUnique("from ExamPaperInfo where groupId=? and deleteFlag is false ",CollectionUtils.newList(groupId), ExamPaperInfo.class);
|
}
|
|
|
|
|
}
|