|
@@ -22,8 +22,6 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -45,28 +43,40 @@ import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.core.examwork.api.controller.bean.CourseGroupBean;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamDomain;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.CourseGroupRelationRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.CourseGroupRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.CourseGroupEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.CourseGroupRelation;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.impl.ExamService;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.impl.ExamServiceImpl;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
|
- * 考试服务API Created by songyue on 17/1/13.
|
|
|
+ * 重构
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年8月17日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
*/
|
|
|
@Transactional
|
|
|
@RestController
|
|
|
@RequestMapping("${$rmp.ctr.examwork}/exam")
|
|
|
public class ExamController extends ControllerSupport {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ExamPropertyRepo examPropertyRepo;
|
|
|
+
|
|
|
@Autowired
|
|
|
RedisClient redisClient;
|
|
|
|
|
@@ -74,7 +84,7 @@ public class ExamController extends ControllerSupport {
|
|
|
ExamRepo examRepo;
|
|
|
|
|
|
@Autowired
|
|
|
- ExamService examService;
|
|
|
+ ExamServiceImpl examService;
|
|
|
|
|
|
@Autowired
|
|
|
ExamStudentRepo examStudentRepo;
|
|
@@ -91,26 +101,44 @@ public class ExamController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
CourseGroupRelationRepo courseGroupRelationRepo;
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examCriteria
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "查询所有考试批次", notes = "分页带查询")
|
|
|
@GetMapping("all/{curPage}/{pageSize}")
|
|
|
- public Page<Exam> getAllExam(HttpServletRequest request, @ModelAttribute Exam examCriteria,
|
|
|
+ public Page<ExamEntity> getAllExam(@ModelAttribute ExamEntity examCriteria,
|
|
|
@PathVariable Integer curPage, @PathVariable Integer pageSize) {
|
|
|
User accessUser = getAccessUser();
|
|
|
examCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- Page<Exam> page = examService.getAllExam(examCriteria,
|
|
|
+
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains());
|
|
|
+ Example<ExamEntity> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
+ return examRepo.findAll(examExample,
|
|
|
new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "updateTime")));
|
|
|
- return page;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examCriteria
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "查询所有考试批次(包含有效)", notes = "不分页带查询")
|
|
|
@GetMapping("all")
|
|
|
- public List<Exam> getEnableExam(HttpServletRequest request, @ModelAttribute Exam examCriteria) {
|
|
|
+ public List<ExamEntity> getEnableExam(@ModelAttribute ExamEntity examCriteria) {
|
|
|
User accessUser = getAccessUser();
|
|
|
-
|
|
|
examCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
examCriteria.setEnable(true);
|
|
|
- List<Exam> list = examService.getAllExam(examCriteria);
|
|
|
- return list;
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains());
|
|
|
+ Example<ExamEntity> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
+ return examRepo.findAll(examExample, new Sort(Direction.DESC, "id"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -122,14 +150,14 @@ public class ExamController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "查询考试批次(包含有效、无效)")
|
|
|
@GetMapping("queryByName")
|
|
|
- public List<Exam> queryByName(@RequestParam(required = false) String name) {
|
|
|
+ public List<ExamEntity> queryByName(@RequestParam(required = false) String name) {
|
|
|
|
|
|
if (StringUtils.isBlank(name)) {
|
|
|
- List<Exam> list = Lists.newArrayList();
|
|
|
+ List<ExamEntity> list = Lists.newArrayList();
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- Specification<Exam> specification = (root, query, cb) -> {
|
|
|
+ Specification<ExamEntity> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
predicates.add(cb.equal(root.get("rootOrgId"), getRootOrgId()));
|
|
|
predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
@@ -137,109 +165,153 @@ public class ExamController extends ControllerSupport {
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
Sort sort = new Sort(Direction.DESC, "updateTime");
|
|
|
- List<Exam> page = examRepo.findAll(specification, sort);
|
|
|
+ List<ExamEntity> page = examRepo.findAll(specification, sort);
|
|
|
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param examType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "根据机构ID和考试类型查询所有有效考试批次", notes = "根据机构ID和考试类型查询所有有效考试批次")
|
|
|
@GetMapping("rootOrgId/{rootOrgId}/{examType}")
|
|
|
- public List<Exam> getEnableExamByRootOrgId(@PathVariable Long rootOrgId,
|
|
|
+ public List<ExamEntity> getEnableExamByRootOrgId(@PathVariable Long rootOrgId,
|
|
|
@PathVariable String examType) {
|
|
|
- Exam examCriteria = new Exam();
|
|
|
+ ExamEntity examCriteria = new ExamEntity();
|
|
|
examCriteria.setRootOrgId(rootOrgId);
|
|
|
if (StringUtils.isNotBlank(examType)) {
|
|
|
examCriteria.setExamType(ExamType.valueOf(examType));
|
|
|
}
|
|
|
examCriteria.setEnable(true);
|
|
|
- List<Exam> list = examService.getAllExam(examCriteria);
|
|
|
- return list;
|
|
|
+
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains());
|
|
|
+ Example<ExamEntity> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
+ return examRepo.findAll(examExample, new Sort(Direction.DESC, "id"));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examCriteria
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "查询所有考试批次(包含有效无效)", notes = "不分页带查询")
|
|
|
@GetMapping("all/both")
|
|
|
- public List<Exam> getAllExam(@ModelAttribute Exam examCriteria) {
|
|
|
+ public List<ExamEntity> getAllExam(@ModelAttribute ExamEntity examCriteria) {
|
|
|
examCriteria.setRootOrgId(getRootOrgId());
|
|
|
ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains());
|
|
|
- Example<Exam> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
+ Example<ExamEntity> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
return examRepo.findAll(examExample, new Sort(Direction.DESC, "id"));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "根据名称查询考试批次(包含有效)", notes = "不分页带查询")
|
|
|
- @GetMapping("name")
|
|
|
- public List<Exam> getEnableExamByName(HttpServletRequest request,
|
|
|
- @ModelAttribute Exam examCriteria) {
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "根据名称查询考试批次(包含有效)")
|
|
|
+ @GetMapping("{name}")
|
|
|
+ public ExamEntity getEnableExamByName(@PathVariable String name) {
|
|
|
User accessUser = getAccessUser();
|
|
|
- if (accessUser != null) {
|
|
|
- examCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ ExamEntity one = examRepo.findByNameAndRootOrgId(name, accessUser.getRootOrgId());
|
|
|
+ if (null == one) {
|
|
|
+ throw new StatusException("E-001004", "考试不存在");
|
|
|
}
|
|
|
- examCriteria.setEnable(true);
|
|
|
- List<Exam> list = examService.findByNameAndRootOrgId(examCriteria.getName(),
|
|
|
- examCriteria.getRootOrgId());
|
|
|
- return list;
|
|
|
+ if (!one.getEnable()) {
|
|
|
+ throw new StatusException("E-001004", "考试被禁用");
|
|
|
+ }
|
|
|
+ return one;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
|
|
|
- @GetMapping("{id}")
|
|
|
- public ResponseEntity<Exam> getExamById(@PathVariable Long id) {
|
|
|
- return new ResponseEntity<Exam>(examService.getExamById(id), HttpStatus.OK);
|
|
|
+ @GetMapping("{examId}")
|
|
|
+ public ExamEntity getExamById(@PathVariable Long examId) {
|
|
|
+ ExamEntity one = examRepo.findOne(examId);
|
|
|
+ return one;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "新增考试批次", notes = "新增")
|
|
|
@PostMapping()
|
|
|
- public Exam addExam(@RequestBody Exam exam) {
|
|
|
- trim(exam);
|
|
|
+ public ExamEntity addExam(@RequestBody ExamDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
|
|
|
- if (null == exam.getExamType()) {
|
|
|
- throw new StatusException("E-001005", "考试类型为空");
|
|
|
- }
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
|
|
- if (null != exam.getBeforeExamRemark() && exam.getBeforeExamRemark().length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "考前说明内容过大");
|
|
|
- }
|
|
|
- if (null != exam.getAfterExamRemark() && exam.getAfterExamRemark().length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "考后说明内容过大");
|
|
|
- }
|
|
|
- if (null != exam.getCheatingRemark() && exam.getCheatingRemark().length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "作弊说明内容过大");
|
|
|
- }
|
|
|
+ ExamInfo examInfo = new ExamInfo();
|
|
|
|
|
|
- User accessUser = getAccessUser();
|
|
|
+ examInfo.setBeginTime(domain.getBeginTime());
|
|
|
+ examInfo.setDuration(domain.getDuration());
|
|
|
+ examInfo.setEnable(true);
|
|
|
+ examInfo.setEndTime(domain.getEndTime());
|
|
|
+ examInfo.setExamTimes(domain.getExamTimes());
|
|
|
+ examInfo.setExamType(domain.getExamType());
|
|
|
+ examInfo.setId(domain.getId());
|
|
|
+ examInfo.setName(domain.getName());
|
|
|
+ examInfo.setRemark(domain.getRemark());
|
|
|
+ examInfo.setRootOrgId(accessUser.getRootOrgId());
|
|
|
|
|
|
- exam.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- exam.setCanStuDel(true);
|
|
|
- if (!examService.checkExamName(exam)) {
|
|
|
- throw new StatusException("E-001001", "考试名称已存在,请重新填写");
|
|
|
- }
|
|
|
- Exam ret = examService.insertExam(exam);
|
|
|
- return ret;
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+ examInfo.setProperties(properties);
|
|
|
+
|
|
|
+ ExamEntity saved = examService.saveExam(examInfo);
|
|
|
+
|
|
|
+ return saved;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "更新考试批次", notes = "更新")
|
|
|
@PutMapping()
|
|
|
- public Exam updateExam(@RequestBody Exam exam) {
|
|
|
- trim(exam);
|
|
|
+ public ExamEntity updateExam(@RequestBody ExamDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
|
|
|
- if (null == exam.getExamType()) {
|
|
|
- throw new StatusException("E-001005", "考试类型为空");
|
|
|
- }
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
|
|
- if (!examService.checkExamName(exam)) {
|
|
|
- throw new StatusException("E-001001", "考试名称已存在,请重新填写");
|
|
|
- }
|
|
|
+ ExamInfo examInfo = new ExamInfo();
|
|
|
+ examInfo.setBeginTime(domain.getBeginTime());
|
|
|
+ examInfo.setDuration(domain.getDuration());
|
|
|
+ examInfo.setEnable(true);
|
|
|
+ examInfo.setEndTime(domain.getEndTime());
|
|
|
+ examInfo.setExamTimes(domain.getExamTimes());
|
|
|
+ examInfo.setExamType(domain.getExamType());
|
|
|
+ examInfo.setId(domain.getId());
|
|
|
+ examInfo.setName(domain.getName());
|
|
|
+ examInfo.setRemark(domain.getRemark());
|
|
|
+ examInfo.setRootOrgId(accessUser.getRootOrgId());
|
|
|
|
|
|
- if (null != exam.getBeforeExamRemark() && exam.getBeforeExamRemark().length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "考前说明内容过大");
|
|
|
- }
|
|
|
- if (null != exam.getAfterExamRemark() && exam.getAfterExamRemark().length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "考后说明内容过大");
|
|
|
- }
|
|
|
- if (null != exam.getCheatingRemark() && exam.getCheatingRemark().length() > 250000) {
|
|
|
- throw new StatusException("E-001002", "作弊说明内容过大");
|
|
|
- }
|
|
|
+ Map<String, String> properties = domain.getProperties();
|
|
|
+ examInfo.setProperties(properties);
|
|
|
|
|
|
- Exam ret = examService.saveExam(exam);
|
|
|
- return ret;
|
|
|
+ ExamEntity saved = examService.saveExam(examInfo);
|
|
|
+
|
|
|
+ return saved;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -264,7 +336,7 @@ public class ExamController extends ControllerSupport {
|
|
|
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);
|
|
|
+ ExamEntity exam = examRepo.findOne(examId);
|
|
|
exam.setEnable(true);
|
|
|
examRepo.save(exam);
|
|
|
}
|
|
@@ -276,7 +348,7 @@ public class ExamController extends ControllerSupport {
|
|
|
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);
|
|
|
+ ExamEntity exam = examRepo.findOne(examId);
|
|
|
exam.setEnable(false);
|
|
|
examRepo.save(exam);
|
|
|
}
|
|
@@ -439,13 +511,21 @@ public class ExamController extends ControllerSupport {
|
|
|
@ApiOperation(value = "考试IP限制", notes = "")
|
|
|
@GetMapping("ipLimit/{examId}")
|
|
|
public Map<String, Object> ipLimit(HttpServletRequest request, @PathVariable Long examId) {
|
|
|
- Exam exam = examRepo.findOne(examId);
|
|
|
+ ExamEntity exam = examRepo.findOne(examId);
|
|
|
if (null == exam) {
|
|
|
throw new StatusException("E-001010", "考试不存在");
|
|
|
}
|
|
|
|
|
|
Map<String, Object> map = Maps.newHashMap();
|
|
|
- Boolean ipLimit = exam.getIpLimit();
|
|
|
+
|
|
|
+ ExamPropertyEntity ipLimitProperty = examPropertyRepo.findByexamIdAndKeyId(exam.getId(),
|
|
|
+ ExamProperty.IP_LIMIT.getKeyId());
|
|
|
+
|
|
|
+ Boolean ipLimit = null;
|
|
|
+ if (null != ipLimitProperty) {
|
|
|
+ ipLimit = "true".equalsIgnoreCase(ipLimitProperty.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
if (null == ipLimit || !ipLimit) {
|
|
|
map.put("limited", false);
|
|
|
map.put("desc", "未配置IP限制");
|
|
@@ -463,7 +543,13 @@ public class ExamController extends ControllerSupport {
|
|
|
}
|
|
|
realIp = realIp.trim();
|
|
|
|
|
|
- String ipAddresses = exam.getIpAddresses();
|
|
|
+ ExamPropertyEntity ipAddressesProperty = examPropertyRepo.findByexamIdAndKeyId(exam.getId(),
|
|
|
+ ExamProperty.IP_ADDRESSES.getKeyId());
|
|
|
+
|
|
|
+ String ipAddresses = null;
|
|
|
+ if (null != ipAddressesProperty) {
|
|
|
+ ipAddresses = ipAddressesProperty.getValue();
|
|
|
+ }
|
|
|
|
|
|
boolean limited = true;
|
|
|
if (StringUtils.isNotBlank(ipAddresses)) {
|