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;
|
}
|
|
|
}
|