派生自 projectDept/qhighschool

Administrator
2022-11-03 c0bac2ef6b9d0399334623a41e9188b7e6adde24
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);
    }
    
    
    
    
}