|
@@ -1,301 +1,301 @@
|
|
-package cn.com.qmth.examcloud.service.examwork.api;
|
|
|
|
-
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-import java.util.stream.Stream;
|
|
|
|
-
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
-
|
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
|
-import org.springframework.data.domain.Sort.Direction;
|
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
-
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.common.support.ControllerSupport;
|
|
|
|
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
-import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.dao.CourseGroupRepo;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.dao.ExamStudentRepo;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.entity.CourseGroup;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.entity.Exam;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.enums.ExamType;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.service.ExamService;
|
|
|
|
-import cn.com.qmth.examcloud.service.examwork.service.ExamStudentService;
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 考试服务API Created by songyue on 17/1/13.
|
|
|
|
- */
|
|
|
|
-@RestController
|
|
|
|
-@RequestMapping("${app.api.root}")
|
|
|
|
-public class ExamApi extends ControllerSupport {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamRepo examRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamService examService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamStudentRepo examStudentRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamStudentService examStudentService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- CourseGroupRepo courseGroupRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "查询所有考试批次", notes = "分页带查询")
|
|
|
|
- @GetMapping("/exam/all/{curPage}/{pageSize}")
|
|
|
|
- public ResponseEntity getAllExam(HttpServletRequest request, @ModelAttribute Exam examCriteria,
|
|
|
|
- @PathVariable Integer curPage, @PathVariable Integer pageSize) {
|
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- examCriteria.setOrgId(accessUser.getRootOrgId());
|
|
|
|
- } else {
|
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(examService.getAllExam(examCriteria,
|
|
|
|
- new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "id"))), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "查询所有考试批次(包含有效)", notes = "不分页带查询")
|
|
|
|
- @GetMapping("/exam/all")
|
|
|
|
- public ResponseEntity getEnableExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
|
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- examCriteria.setOrgId(accessUser.getRootOrgId());
|
|
|
|
- }
|
|
|
|
- examCriteria.setEnable(true);
|
|
|
|
- return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "根据机构ID和考试类型查询所有有效考试批次", notes = "根据机构ID和考试类型查询所有有效考试批次")
|
|
|
|
- @GetMapping("/exam/rootOrgId/{orgId}/{examType}")
|
|
|
|
- public ResponseEntity getEnableExamByRootOrgId(@PathVariable Long orgId, @PathVariable String examType) {
|
|
|
|
- if (orgId == null) {
|
|
|
|
- return new ResponseEntity(new ErrorMsg("机构ID不能为空"), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
- Exam examCriteria = new Exam();
|
|
|
|
- examCriteria.setOrgId(orgId);
|
|
|
|
- if (StringUtils.isNotBlank(examType)) {
|
|
|
|
- examCriteria.setExamType(ExamType.valueOf(examType));
|
|
|
|
- }
|
|
|
|
- examCriteria.setEnable(true);
|
|
|
|
- return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "查询所有考试批次(包含有效无效)", notes = "不分页带查询")
|
|
|
|
- @GetMapping("/exam/all/both")
|
|
|
|
- public ResponseEntity getAllExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
|
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- examCriteria.setOrgId(accessUser.getRootOrgId());
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
|
|
|
|
- @GetMapping("/exam/{id}")
|
|
|
|
- public ResponseEntity<Exam> getExamById(@PathVariable Long id) {
|
|
|
|
- return new ResponseEntity<Exam>(examService.getExamById(id), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "新增考试批次", notes = "新增")
|
|
|
|
- @PostMapping("/exam")
|
|
|
|
- public ResponseEntity addExam(HttpServletRequest request, @RequestBody Exam exam) {
|
|
|
|
- Map<String, String> errorMap = new HashMap<String, String>();
|
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- exam.setOrgId(accessUser.getOrgId());
|
|
|
|
- exam.setRootOrgId(accessUser.getRootOrgId());
|
|
|
|
- exam.setCreateTime(new Date());
|
|
|
|
- exam.setCanStuDel(true);
|
|
|
|
- if (!examService.checkExamName(exam)) {
|
|
|
|
- errorMap.put("errorMsg", "考试名称已存在,请重新填写");
|
|
|
|
- return new ResponseEntity(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(examService.insertExam(exam, accessUser), HttpStatus.OK);
|
|
|
|
- } else {
|
|
|
|
- errorMap.put("errorMsg", "accessUser为空");
|
|
|
|
- return new ResponseEntity(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "更新考试批次", notes = "更新")
|
|
|
|
- @PutMapping("/exam")
|
|
|
|
- public ResponseEntity updateExam(@RequestBody Exam exam) {
|
|
|
|
- Map<String, String> errorMap = new HashMap<String, String>();
|
|
|
|
- if (!examService.checkExamName(exam)) {
|
|
|
|
- errorMap.put("errorMsg", "考试名称已存在,请重新填写");
|
|
|
|
- return new ResponseEntity(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(examService.saveExam(exam), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "按ID删除考试批次", notes = "删除")
|
|
|
|
- @DeleteMapping("/exam/{id}")
|
|
|
|
- public ResponseEntity deleteExam(@PathVariable String id) {
|
|
|
|
- try {
|
|
|
|
- List<Long> examIds = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- examService.deleteExam(examIds);
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("删除失败:", e);
|
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "启用考试", notes = "启用考试")
|
|
|
|
- @PutMapping("/exam/enable/{ids}")
|
|
|
|
- public ResponseEntity enableUser(@PathVariable String ids) {
|
|
|
|
- List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
|
- for (Long examId : examIds) {
|
|
|
|
- Exam exam = examRepo.findOne(examId);
|
|
|
|
- exam.setEnable(true);
|
|
|
|
- examRepo.save(exam);
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "禁用考试", notes = "禁用考试")
|
|
|
|
- @PutMapping("/exam/disable/{ids}")
|
|
|
|
- public ResponseEntity disableUser(@PathVariable String ids) {
|
|
|
|
- List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
|
- for (Long examId : examIds) {
|
|
|
|
- Exam exam = examRepo.findOne(examId);
|
|
|
|
- exam.setEnable(false);
|
|
|
|
- examRepo.save(exam);
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "回填考生不可删除标志", notes = "回填考生不可删除标志")
|
|
|
|
- @PutMapping("/exam/canNotDel/{id}")
|
|
|
|
- public ResponseEntity disableUser(@PathVariable Long id) {
|
|
|
|
- examRepo.canNotDel(id);
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "网考初始化更新考务信息", notes = "网考初始化更新考务信息")
|
|
|
|
- @PutMapping("/exam/updateExamInfo")
|
|
|
|
- public ResponseEntity updateExamInfo(@RequestParam Long examId, @RequestParam Long examStuId) {
|
|
|
|
- examRepo.canNotDel(examId);
|
|
|
|
- examStudentService.updateExamStudentInfo(examStuId);
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "网考更新考务信息", notes = "网考更新考务信息")
|
|
|
|
- @PutMapping("/exam/updateExamStudent")
|
|
|
|
- public ResponseEntity updateExamStudent(@RequestParam Long examId, @RequestParam Long examStuId) {
|
|
|
|
- examRepo.canNotDel(examId);
|
|
|
|
- ExamStudent examStudent = examStudentRepo.findOne(examStuId);
|
|
|
|
- examStudent.setFinished(true);
|
|
|
|
- examStudentRepo.save(examStudent);
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "查询课程组", notes = "查询课程组")
|
|
|
|
- @GetMapping("/exam/allCourseGroups/{examId}/{curPage}/{pageSize}")
|
|
|
|
- public ResponseEntity<?> queryAllCourseGroups(@PathVariable Long examId, @PathVariable Integer curPage,
|
|
|
|
- @PathVariable Integer pageSize) {
|
|
|
|
-
|
|
|
|
- List<CourseGroup> groupList = courseGroupRepo.findByExamId(examId, (curPage - 1) * pageSize, pageSize);
|
|
|
|
-
|
|
|
|
- for (CourseGroup courseGroup : groupList) {
|
|
|
|
- List<Long> courseIdList = Lists.newArrayList();
|
|
|
|
- courseGroup.setCourseIdList(courseIdList);
|
|
|
|
-
|
|
|
|
- List<Map<String, Object>> queryList = jdbcTemplate.queryForList(
|
|
|
|
- "select t.course_id from ecs_exam_course_group_course t where t.group_id=?", courseGroup.getId());
|
|
|
|
- if (CollectionUtils.isNotEmpty(queryList)) {
|
|
|
|
- for (Map<String, Object> map : queryList) {
|
|
|
|
- Long courseId = Long.valueOf(map.get("COURSE_ID").toString());
|
|
|
|
- courseIdList.add(courseId);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return new ResponseEntity<List<CourseGroup>>(groupList, HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "查询课程组", notes = "查询课程组")
|
|
|
|
- @GetMapping("/exam/queryCourseGroupsByCourseId/{courseId}")
|
|
|
|
- public ResponseEntity<?> queryCourseGroupsByCourseId(@PathVariable Long courseId) {
|
|
|
|
- List<CourseGroup> groupList = courseGroupRepo.queryCourseGroupsByCourseId(courseId);
|
|
|
|
-
|
|
|
|
- for (CourseGroup courseGroup : groupList) {
|
|
|
|
- List<Long> courseIdList = Lists.newArrayList();
|
|
|
|
- courseGroup.setCourseIdList(courseIdList);
|
|
|
|
-
|
|
|
|
- List<Map<String, Object>> queryList = jdbcTemplate.queryForList(
|
|
|
|
- "select t.course_id from ecs_exam_course_group_course t where t.group_id=?", courseGroup.getId());
|
|
|
|
- if (CollectionUtils.isNotEmpty(queryList)) {
|
|
|
|
- for (Map<String, Object> map : queryList) {
|
|
|
|
- Long curCourseId = Long.valueOf(map.get("COURSE_ID").toString());
|
|
|
|
- courseIdList.add(curCourseId);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return new ResponseEntity<Object>(groupList, HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "更新课程组", notes = "更新课程组")
|
|
|
|
- @PutMapping("/exam/courseGroup")
|
|
|
|
- public ResponseEntity<?> updateCourseGroup(@RequestBody CourseGroup courseGroup, HttpServletRequest request) {
|
|
|
|
-
|
|
|
|
- courseGroupRepo.save(courseGroup);
|
|
|
|
- Long groupId = courseGroup.getId();
|
|
|
|
- Long examId = courseGroup.getExamId();
|
|
|
|
-
|
|
|
|
- List<Long> courseIdList = courseGroup.getCourseIdList();
|
|
|
|
- jdbcTemplate.update("delete from ecs_exam_course_group_course where group_id=?", groupId);
|
|
|
|
-
|
|
|
|
- if (CollectionUtils.isNotEmpty(courseIdList)) {
|
|
|
|
- for (Long courseId : courseIdList) {
|
|
|
|
- jdbcTemplate.update("delete from ecs_exam_course_group_course where exam_id=? and course_id=?",
|
|
|
|
- groupId, courseId);
|
|
|
|
- jdbcTemplate.update(
|
|
|
|
- "insert into ecs_exam_course_group_course(group_id,course_id,exam_id) values(?,?,?)", groupId,
|
|
|
|
- courseId, examId);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "删除课程组", notes = "添加课程组")
|
|
|
|
- @DeleteMapping("/exam/courseGroup/{id}")
|
|
|
|
- public ResponseEntity<?> CourseGroup(@PathVariable Long id, HttpServletRequest request) {
|
|
|
|
- courseGroupRepo.delete(id);
|
|
|
|
- jdbcTemplate.update("delete from ecs_exam_course_group_course where group_id=?", id);
|
|
|
|
- return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+package cn.com.qmth.examcloud.service.examwork.api;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.common.support.ControllerSupport;
|
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.CourseGroupRepo;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.ExamStudentRepo;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.CourseGroup;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.Exam;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.enums.ExamType;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.service.ExamService;
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.service.ExamStudentService;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 考试服务API Created by songyue on 17/1/13.
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("${app.api.root}")
|
|
|
|
+public class ExamApi extends ControllerSupport {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamRepo examRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamService examService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamStudentService examStudentService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ CourseGroupRepo courseGroupRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "查询所有考试批次", notes = "分页带查询")
|
|
|
|
+ @GetMapping("/exam/all/{curPage}/{pageSize}")
|
|
|
|
+ public ResponseEntity getAllExam(HttpServletRequest request, @ModelAttribute Exam examCriteria,
|
|
|
|
+ @PathVariable Integer curPage, @PathVariable Integer pageSize) {
|
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
+ if (accessUser != null) {
|
|
|
|
+ examCriteria.setOrgId(accessUser.getRootOrgId());
|
|
|
|
+ } else {
|
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(examService.getAllExam(examCriteria,
|
|
|
|
+ new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "id"))), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "查询所有考试批次(包含有效)", notes = "不分页带查询")
|
|
|
|
+ @GetMapping("/exam/all")
|
|
|
|
+ public ResponseEntity getEnableExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
|
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
+ if (accessUser != null) {
|
|
|
|
+ examCriteria.setOrgId(accessUser.getRootOrgId());
|
|
|
|
+ }
|
|
|
|
+ examCriteria.setEnable(true);
|
|
|
|
+ return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "根据机构ID和考试类型查询所有有效考试批次", notes = "根据机构ID和考试类型查询所有有效考试批次")
|
|
|
|
+ @GetMapping("/exam/rootOrgId/{orgId}/{examType}")
|
|
|
|
+ public ResponseEntity getEnableExamByRootOrgId(@PathVariable Long orgId, @PathVariable String examType) {
|
|
|
|
+ if (orgId == null) {
|
|
|
|
+ return new ResponseEntity(new ErrorMsg("机构ID不能为空"), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+ Exam examCriteria = new Exam();
|
|
|
|
+ examCriteria.setOrgId(orgId);
|
|
|
|
+ if (StringUtils.isNotBlank(examType)) {
|
|
|
|
+ examCriteria.setExamType(ExamType.valueOf(examType));
|
|
|
|
+ }
|
|
|
|
+ examCriteria.setEnable(true);
|
|
|
|
+ return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "查询所有考试批次(包含有效无效)", notes = "不分页带查询")
|
|
|
|
+ @GetMapping("/exam/all/both")
|
|
|
|
+ public ResponseEntity getAllExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
|
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
+ if (accessUser != null) {
|
|
|
|
+ examCriteria.setOrgId(accessUser.getRootOrgId());
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(examService.getAllExam(examCriteria), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
|
|
|
|
+ @GetMapping("/exam/{id}")
|
|
|
|
+ public ResponseEntity<Exam> getExamById(@PathVariable Long id) {
|
|
|
|
+ return new ResponseEntity<Exam>(examService.getExamById(id), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "新增考试批次", notes = "新增")
|
|
|
|
+ @PostMapping("/exam")
|
|
|
|
+ public ResponseEntity addExam(HttpServletRequest request, @RequestBody Exam exam) {
|
|
|
|
+ Map<String, String> errorMap = new HashMap<String, String>();
|
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
|
+ if (accessUser != null) {
|
|
|
|
+ exam.setOrgId(accessUser.getOrgId());
|
|
|
|
+ exam.setRootOrgId(accessUser.getRootOrgId());
|
|
|
|
+ exam.setCreateTime(new Date());
|
|
|
|
+ exam.setCanStuDel(true);
|
|
|
|
+ if (!examService.checkExamName(exam)) {
|
|
|
|
+ errorMap.put("errorMsg", "考试名称已存在,请重新填写");
|
|
|
|
+ return new ResponseEntity(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(examService.insertExam(exam, accessUser), HttpStatus.OK);
|
|
|
|
+ } else {
|
|
|
|
+ errorMap.put("errorMsg", "accessUser为空");
|
|
|
|
+ return new ResponseEntity(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "更新考试批次", notes = "更新")
|
|
|
|
+ @PutMapping("/exam")
|
|
|
|
+ public ResponseEntity updateExam(@RequestBody Exam exam) {
|
|
|
|
+ Map<String, String> errorMap = new HashMap<String, String>();
|
|
|
|
+ if (!examService.checkExamName(exam)) {
|
|
|
|
+ errorMap.put("errorMsg", "考试名称已存在,请重新填写");
|
|
|
|
+ return new ResponseEntity(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(examService.saveExam(exam), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "按ID删除考试批次", notes = "删除")
|
|
|
|
+ @DeleteMapping("/exam/{id}")
|
|
|
|
+ public ResponseEntity deleteExam(@PathVariable String id) {
|
|
|
|
+ try {
|
|
|
|
+ List<Long> examIds = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ examService.deleteExam(examIds);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("删除失败:", e);
|
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "启用考试", notes = "启用考试")
|
|
|
|
+ @PutMapping("/exam/enable/{ids}")
|
|
|
|
+ public ResponseEntity enableUser(@PathVariable String ids) {
|
|
|
|
+ List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
|
+ for (Long examId : examIds) {
|
|
|
|
+ Exam exam = examRepo.findOne(examId);
|
|
|
|
+ exam.setEnable(true);
|
|
|
|
+ examRepo.save(exam);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "禁用考试", notes = "禁用考试")
|
|
|
|
+ @PutMapping("/exam/disable/{ids}")
|
|
|
|
+ public ResponseEntity disableUser(@PathVariable String ids) {
|
|
|
|
+ List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
|
+ for (Long examId : examIds) {
|
|
|
|
+ Exam exam = examRepo.findOne(examId);
|
|
|
|
+ exam.setEnable(false);
|
|
|
|
+ examRepo.save(exam);
|
|
|
|
+ }
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "回填考生不可删除标志", notes = "回填考生不可删除标志")
|
|
|
|
+ @PutMapping("/exam/canNotDel/{id}")
|
|
|
|
+ public ResponseEntity disableUser(@PathVariable Long id) {
|
|
|
|
+ examRepo.canNotDel(id);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "网考初始化更新考务信息", notes = "网考初始化更新考务信息")
|
|
|
|
+ @PutMapping("/exam/updateExamInfo")
|
|
|
|
+ public ResponseEntity updateExamInfo(@RequestParam Long examId, @RequestParam Long examStuId) {
|
|
|
|
+ examRepo.canNotDel(examId);
|
|
|
|
+ examStudentService.updateExamStudentInfo(examStuId);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "网考更新考务信息", notes = "网考更新考务信息")
|
|
|
|
+ @PutMapping("/exam/updateExamStudent")
|
|
|
|
+ public ResponseEntity updateExamStudent(@RequestParam Long examId, @RequestParam Long examStuId) {
|
|
|
|
+ examRepo.canNotDel(examId);
|
|
|
|
+ ExamStudent examStudent = examStudentRepo.findOne(examStuId);
|
|
|
|
+ examStudent.setFinished(true);
|
|
|
|
+ examStudentRepo.save(examStudent);
|
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "查询课程组", notes = "查询课程组")
|
|
|
|
+ @GetMapping("/exam/allCourseGroups/{examId}/{curPage}/{pageSize}")
|
|
|
|
+ public ResponseEntity<?> queryAllCourseGroups(@PathVariable Long examId, @PathVariable Integer curPage,
|
|
|
|
+ @PathVariable Integer pageSize) {
|
|
|
|
+
|
|
|
|
+ List<CourseGroup> groupList = courseGroupRepo.findByExamId(examId, (curPage - 1) * pageSize, pageSize);
|
|
|
|
+
|
|
|
|
+ for (CourseGroup courseGroup : groupList) {
|
|
|
|
+ List<Long> courseIdList = Lists.newArrayList();
|
|
|
|
+ courseGroup.setCourseIdList(courseIdList);
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> queryList = jdbcTemplate.queryForList(
|
|
|
|
+ "select t.course_id from ecs_exam_course_group_course t where t.group_id=?", courseGroup.getId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(queryList)) {
|
|
|
|
+ for (Map<String, Object> map : queryList) {
|
|
|
|
+ Long courseId = Long.valueOf(map.get("COURSE_ID").toString());
|
|
|
|
+ courseIdList.add(courseId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new ResponseEntity<List<CourseGroup>>(groupList, HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "查询课程组", notes = "查询课程组")
|
|
|
|
+ @GetMapping("/exam/queryCourseGroupsByCourseId/{courseId}")
|
|
|
|
+ public ResponseEntity<?> queryCourseGroupsByCourseId(@PathVariable Long courseId) {
|
|
|
|
+ List<CourseGroup> groupList = courseGroupRepo.queryCourseGroupsByCourseId(courseId);
|
|
|
|
+
|
|
|
|
+ for (CourseGroup courseGroup : groupList) {
|
|
|
|
+ List<Long> courseIdList = Lists.newArrayList();
|
|
|
|
+ courseGroup.setCourseIdList(courseIdList);
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> queryList = jdbcTemplate.queryForList(
|
|
|
|
+ "select t.course_id from ecs_exam_course_group_course t where t.group_id=?", courseGroup.getId());
|
|
|
|
+ if (CollectionUtils.isNotEmpty(queryList)) {
|
|
|
|
+ for (Map<String, Object> map : queryList) {
|
|
|
|
+ Long curCourseId = Long.valueOf(map.get("COURSE_ID").toString());
|
|
|
|
+ courseIdList.add(curCourseId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new ResponseEntity<Object>(groupList, HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "更新课程组", notes = "更新课程组")
|
|
|
|
+ @PutMapping("/exam/courseGroup")
|
|
|
|
+ public ResponseEntity<?> updateCourseGroup(@RequestBody CourseGroup courseGroup, HttpServletRequest request) {
|
|
|
|
+
|
|
|
|
+ courseGroupRepo.save(courseGroup);
|
|
|
|
+ Long groupId = courseGroup.getId();
|
|
|
|
+ Long examId = courseGroup.getExamId();
|
|
|
|
+
|
|
|
|
+ List<Long> courseIdList = courseGroup.getCourseIdList();
|
|
|
|
+ jdbcTemplate.update("delete from ecs_exam_course_group_course where group_id=?", groupId);
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(courseIdList)) {
|
|
|
|
+ for (Long courseId : courseIdList) {
|
|
|
|
+ jdbcTemplate.update("delete from ecs_exam_course_group_course where exam_id=? and course_id=?",
|
|
|
|
+ groupId, courseId);
|
|
|
|
+ jdbcTemplate.update(
|
|
|
|
+ "insert into ecs_exam_course_group_course(group_id,course_id,exam_id) values(?,?,?)", groupId,
|
|
|
|
+ courseId, examId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "删除课程组", notes = "添加课程组")
|
|
|
|
+ @DeleteMapping("/exam/courseGroup/{id}")
|
|
|
|
+ public ResponseEntity<?> CourseGroup(@PathVariable Long id, HttpServletRequest request) {
|
|
|
|
+ courseGroupRepo.delete(id);
|
|
|
|
+ jdbcTemplate.update("delete from ecs_exam_course_group_course where group_id=?", id);
|
|
|
|
+ return new ResponseEntity<Object>(HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+}
|