派生自 projectDept/qhighschool

yn147
2023-05-10 96286178ee1c257c130cb2ad964a781f36c4eee5
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package com.qxueyou.scc.exam.action;
 
import java.util.List;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.qxueyou.scc.base.dao.CommonDAO;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.service.ICommonService;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.exam.model.ExamPaperSectionInfo;
import com.qxueyou.scc.exam.service.IExamPaperSectionService;
import com.qxueyou.scc.exercise.model.ExerciseGroup;
import com.qxueyou.scc.exercise.service.IExerciseGroupService;
 
import io.swagger.annotations.Api;
 
 
/**
 * exam paper section controller.
 *
 * @author kevin
 * @history 2018-03-11 create kevin
 */
@Api(tags = "试卷部分管理接口")
@Controller
@RequestMapping(value = "/exam/papersection")
public class ExamPaperSectionController {
    //分页查询中,默认记录条数和页数
    private static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
    private static final int DEFAULT_PAGE_NUM = 1;
 
    @Autowired
    private CommonDAO commonDAO;
 
    @Autowired
    @Qualifier("commonAppService")
    ICommonService commonService;
 
    @Autowired
    IExamPaperSectionService examPaperSectionService;
 
    @Autowired
    IExerciseGroupService exerciseGroupService;
 
    /**
     * 试卷部分列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public @ResponseBody
    Result pageList(String examPaperId, Integer pageSize, Integer pageNum) {
        Result result = new Result(Boolean.TRUE);
        Pager pager = new Pager();
        // 查询记录数
        String hqlCount = "from ExamPaperSectionInfo where examPaperId=? and deleteFlag is false";
        int totalCount = commonDAO.findCount(hqlCount, CollectionUtils.newList(examPaperId));
 
        // page赋值
        pager.setTotalCount(totalCount);
        pager.setPageSize(pageSize != null && pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE);
        pager.setPageNum(pageNum != null && pageNum > 0 ? pageNum : DEFAULT_PAGE_NUM);
 
        String hql = "from ExamPaperSectionInfo where examPaperId=? and deleteFlag is false order by sectionOrder asc";
        List<ExamPaperSectionInfo> list = commonDAO.findList(hql, pager, CollectionUtils.newList(examPaperId), ExamPaperSectionInfo.class);
        result.addData("list", list);
        result.addData("pager", pager);
        return result;
    }
 
    /**
     * 详情
     *
     * @param examPaperSectionId
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public @ResponseBody
    Result detail(String examPaperSectionId) {
        Result result = new Result(true);
        result.addData("detail", examPaperSectionService.queryExamPaperSectionDetail(examPaperSectionId));
        return result;
    }
 
    /**
     * 保存
     *
     * @param examPaperSectionInfo
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public @ResponseBody
    Result save(@RequestBody ExamPaperSectionInfo examPaperSectionInfo) {
        Result result = null;
        if (StringUtils.isEmpty(examPaperSectionInfo.getSectionId())) {
            String sectionId = examPaperSectionService.addExamPaperSection(examPaperSectionInfo);
            result = new Result(true);
            result.addData("sectionId", sectionId);
        } else {
            result = examPaperSectionService.updateExamPaperSection(examPaperSectionInfo);
        }
        return result;
    }
 
    /**
     * 删除
     *
     * @param examPaperSectionIds
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public @ResponseBody
    Result publish(String examPaperSectionIds) {
        Result result = new Result(true);
        if (StringUtils.isNotEmpty(examPaperSectionIds)) {
            result = examPaperSectionService.deleteExamPaperSection(examPaperSectionIds.split(","));
        }
        return result;
    }
 
    /**
     * 设置题库
     *
     * @param examPaperSectionInfo
     * @return
     * @throws Exception
     */
    @Deprecated
    @RequestMapping(value = "/group/save", method = RequestMethod.GET)
    public @ResponseBody
    Result saveSectionGroup(String sectionId, String selectedGroupIds, String selectedItemTypes) throws Exception {
        if (StringUtils.isEmpty(sectionId) || StringUtils.isEmpty(selectedGroupIds) || StringUtils.isEmpty(selectedItemTypes)) {
            return new Result(false, "请求参数错误!");
        }
 
        String[] arrGroupIds = selectedGroupIds.split(",");
 
        String[] arrItemType = selectedItemTypes.split(",");
        Short[] itemTypes = new Short[arrItemType.length];
        for (int i = 0; i < arrItemType.length; i++) {
            itemTypes[i] = Short.valueOf(arrItemType[i]);
        }
 
        return examPaperSectionService.saveExamPaperSectionGroup(sectionId, arrGroupIds, itemTypes);
    }
 
    /**
     * 自主选题
     *
     * @param examPaperSectionInfo
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/item/selectedadd", method = RequestMethod.GET)
    public @ResponseBody
    Result saveSectionSeletedItems(String sectionId, String sourceGroupId, String selectedItemIds) throws Exception {
        if (StringUtils.isEmpty(sectionId) || StringUtils.isEmpty(sourceGroupId) || StringUtils.isEmpty(selectedItemIds)) {
            return new Result(false, "请求参数错误!");
        }
 
        String[] arrItemIds = selectedItemIds.split(",");
        return examPaperSectionService.saveExamPaperSectionItems(sectionId, sourceGroupId, arrItemIds);
    }
 
    /**
     * 交换题目顺序
     *
     * @param examPaperSectionInfo
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/item/changeOrder", method = RequestMethod.GET)
    public @ResponseBody
    Result changeItemOrder(String paperGroupId, String exerciseItemId1, String exerciseItemId2) throws Exception {
        return exerciseGroupService.doExchangeExamPaperGroupItemOrder(paperGroupId, exerciseItemId1, exerciseItemId2);
    }
 
    /**
     * 删除题目
     *
     * @param examPaperSectionInfo
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/item/delete", method = RequestMethod.GET)
    public @ResponseBody
    Result deleteSectionGroupItem(String sectionId, String groupId, String exerciseItemId) throws Exception {
        return examPaperSectionService.deleteSectionItem(sectionId, groupId, exerciseItemId.split(","));
    }
 
    /**
     * 考试保存题目
     *
     * @return
     */
    @RequestMapping(value = "/item/save", method = RequestMethod.POST)
    @ResponseBody
    public Result addOrUpdateItem(@RequestBody ExerciseGroup exerciseGroup) {
        Result result = examPaperSectionService.saveSectionItem(exerciseGroup);
        result.addData("totalScore", examPaperSectionService.updatePaperScore(exerciseGroup.getGroupId()));
        return result;
    }
 
 
    /**
     * 查询当前题组中被选中的题目ID
     */
    @RequestMapping(value = "/group/itemIds", method = RequestMethod.GET)
    public @ResponseBody
    Result querySectionSelectedItemIds(String sectionId, String sourceGroupId) {
        Result result = new Result(Boolean.TRUE);
        ExamPaperSectionInfo sectionInfo = this.commonDAO.read(ExamPaperSectionInfo.class, sectionId);
        String hql = "select r.exerciseItemId from ExerciseGroupItemRe r where r.deleteFlag is false and r.exerciseGroupId=:paperGroupId and r.itemOrder>:startIdx and r.itemOrder<=:endIdx and exists ("
                + " select 1 from ExerciseGroupItemRe r2 where r2.deleteFlag is false and r2.exerciseItemId = r.exerciseItemId  and r2.exerciseGroupId =:sourceGroupId ) order by r.itemOrder asc";
        List<String> list = commonDAO.findByComplexHql(hql, CollectionUtils.newObjectMap("paperGroupId", sectionInfo.getGroupId(), "startIdx", Integer.valueOf(sectionInfo.getItemStartOrder()), "endIdx", Integer.valueOf(sectionInfo.getItemEndOrder()), "sourceGroupId", sourceGroupId), String.class);
        result.addData("list", list);
        return result;
    }
 
 
}