派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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);
    }
    
    
    
    
}