|
@@ -6,16 +6,6 @@ import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.core.Org;
|
|
|
-import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgTimeRepo;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgTime;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.mq.DataSendService;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.rpc.OrgService;
|
|
|
-
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Example;
|
|
|
import org.springframework.data.domain.ExampleMatcher;
|
|
@@ -26,157 +16,171 @@ import org.springframework.data.domain.Sort.Direction;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.core.Org;
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgTimeRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgTime;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.mq.DataSendService;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.rpc.OrgService;
|
|
|
+
|
|
|
/**
|
|
|
- * 考试批次服务类
|
|
|
- * Created by songyue on 17/1/13.
|
|
|
+ * 考试批次服务类 Created by songyue on 17/1/13.
|
|
|
*/
|
|
|
@Service
|
|
|
public class ExamService {
|
|
|
- @Autowired
|
|
|
- ExamRepo examRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentService examStudentService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamOrgTimeRepo examOrgTimeRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- OrgService orgService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- DataSendService dataSendService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有考试批次(分页)
|
|
|
- * @param examCriteria
|
|
|
- * @param pageable
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<Exam> getAllExam(Exam examCriteria, Pageable pageable){
|
|
|
- ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("name",contains());
|
|
|
- Example<Exam> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
- return examRepo.findAll(examExample,pageable);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有考试批次
|
|
|
- * @param examCriteria
|
|
|
- * @return
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<Exam> getAllExam(Exam examCriteria){
|
|
|
- ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("name",contains());
|
|
|
- Example<Exam> examExample = Example.of(examCriteria,exampleMatcher);
|
|
|
- return examRepo.findAll(examExample, new Sort(Direction.DESC,"id"));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 按ID获取考试批次
|
|
|
- * @param examId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Exam getExamById(Long examId){
|
|
|
- return examRepo.findOne(examId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存考试批次
|
|
|
- * @param exam
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Exam saveExam(Exam exam){
|
|
|
- Exam newExam = examRepo.save(exam);
|
|
|
- /*if(newExam.getId() != null){
|
|
|
- dataSendService.sendExam(newExam);
|
|
|
- }*/
|
|
|
- return newExam;
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- public Exam insertExam(Exam exam, cn.com.qmth.examcloud.commons.web.security.bean.User accessUser){
|
|
|
- ExamType examType = exam.getExamType();
|
|
|
- if(examType == ExamType.OFFLINE){
|
|
|
- Exam newExam = examRepo.save(exam);
|
|
|
- insertExamOrgTime(newExam,accessUser);
|
|
|
- return newExam;
|
|
|
- }
|
|
|
- return examRepo.save(exam);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增学习中心考试时间
|
|
|
- * @param exam
|
|
|
- * @param accessUser
|
|
|
- */
|
|
|
- private void insertExamOrgTime(Exam exam,cn.com.qmth.examcloud.commons.web.security.bean.User accessUser){
|
|
|
- Long examId = exam.getId();
|
|
|
- Long rootOrgId = accessUser.getRootOrgId();
|
|
|
- String token = accessUser.getUserToken();
|
|
|
- Date beginTime = exam.getBeginTime();
|
|
|
- Date endTime = exam.getEndTime();
|
|
|
- List<Org> orgList = orgService.findByParentId(token,rootOrgId);
|
|
|
- List<ExamOrgTime> examOrgTimes = new ArrayList<>();
|
|
|
- for(Org org:orgList){
|
|
|
- Long orgId = org.getId();
|
|
|
- String orgCode = org.getCode();
|
|
|
- String orgName = org.getName();
|
|
|
- ExamOrgTime examOrgTime = new ExamOrgTime(examId, orgId, orgCode,
|
|
|
- orgName, beginTime, endTime);
|
|
|
- examOrgTimes.add(examOrgTime);
|
|
|
- }
|
|
|
- examOrgTimeRepo.save(examOrgTimes);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除考试批次
|
|
|
- * @param ids
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Transactional
|
|
|
- public void deleteExam(List<Long> ids)throws Exception{
|
|
|
- List<Exam> exams = examRepo.findByIdIn(ids);
|
|
|
- for(Exam exam:exams){
|
|
|
- //删除考生
|
|
|
- if(exam.getCanStuDel()){
|
|
|
- //删除学习中心考试时间
|
|
|
- examOrgTimeRepo.deleteByExamId(exam.getId());
|
|
|
- examStudentService.deleteExamStudents(exam.getId());
|
|
|
- examRepo.delete(exam);
|
|
|
- }else{
|
|
|
- throw new RuntimeException(exam.getName()+"批次已经开始,不能删除");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public boolean checkExamName(Exam exam){
|
|
|
- if(exam.getId()!=null){
|
|
|
- if(examRepo.countByNameAndRootOrgIdAndIdNot(exam.getName(),
|
|
|
- exam.getRootOrgId(),
|
|
|
- exam.getId()) > 0){
|
|
|
- return false;
|
|
|
- }else{
|
|
|
- return true;
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(examRepo.countByNameAndRootOrgId(exam.getName(),exam.getRootOrgId()) > 0){
|
|
|
- return false;
|
|
|
- }else{
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Exam findExamByNameAndRootOrgId(String examName,Long rootOrgId){
|
|
|
- Exam exam = new Exam();
|
|
|
- exam.setName(examName);
|
|
|
- exam.setRootOrgId(rootOrgId);
|
|
|
- return examRepo.findOne(Example.of(exam));
|
|
|
- }
|
|
|
- public List<Exam> findByNameAndRootOrgId(String name,Long rootOrgId) {
|
|
|
- return examRepo.findByNameAndRootOrgId(name, rootOrgId);
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentService examStudentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamOrgTimeRepo examOrgTimeRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgService orgService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DataSendService dataSendService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有考试批次(分页)
|
|
|
+ *
|
|
|
+ * @param examCriteria
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Exam> getAllExam(Exam examCriteria, Pageable pageable) {
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains());
|
|
|
+ Example<Exam> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
+ return examRepo.findAll(examExample, pageable);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有考试批次
|
|
|
+ *
|
|
|
+ * @param examCriteria
|
|
|
+ * @return
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Exam> getAllExam(Exam examCriteria) {
|
|
|
+ ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains());
|
|
|
+ Example<Exam> examExample = Example.of(examCriteria, exampleMatcher);
|
|
|
+ return examRepo.findAll(examExample, new Sort(Direction.DESC, "id"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按ID获取考试批次
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Exam getExamById(Long examId) {
|
|
|
+ return examRepo.findOne(examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存考试批次
|
|
|
+ *
|
|
|
+ * @param exam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Exam saveExam(Exam exam) {
|
|
|
+ Exam newExam = examRepo.save(exam);
|
|
|
+ /*
|
|
|
+ * if(newExam.getId() != null){ dataSendService.sendExam(newExam); }
|
|
|
+ */
|
|
|
+ return newExam;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public Exam insertExam(Exam exam,
|
|
|
+ cn.com.qmth.examcloud.commons.web.security.bean.User accessUser) {
|
|
|
+ ExamType examType = exam.getExamType();
|
|
|
+ if (examType == ExamType.OFFLINE) {
|
|
|
+ Exam newExam = examRepo.save(exam);
|
|
|
+ insertExamOrgTime(newExam, accessUser);
|
|
|
+ return newExam;
|
|
|
+ }
|
|
|
+ return examRepo.save(exam);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增学习中心考试时间
|
|
|
+ *
|
|
|
+ * @param exam
|
|
|
+ * @param accessUser
|
|
|
+ */
|
|
|
+ private void insertExamOrgTime(Exam exam,
|
|
|
+ cn.com.qmth.examcloud.commons.web.security.bean.User accessUser) {
|
|
|
+ Long examId = exam.getId();
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
+ String token = accessUser.getUserToken();
|
|
|
+ Date beginTime = exam.getBeginTime();
|
|
|
+ Date endTime = exam.getEndTime();
|
|
|
+ List<Org> orgList = orgService.findByParentId(token, rootOrgId);
|
|
|
+ List<ExamOrgTime> examOrgTimes = new ArrayList<>();
|
|
|
+ for (Org org : orgList) {
|
|
|
+ Long orgId = org.getId();
|
|
|
+ String orgCode = org.getCode();
|
|
|
+ String orgName = org.getName();
|
|
|
+ ExamOrgTime examOrgTime = new ExamOrgTime(examId, orgId, orgCode, orgName, beginTime,
|
|
|
+ endTime);
|
|
|
+ examOrgTimes.add(examOrgTime);
|
|
|
+ }
|
|
|
+ examOrgTimeRepo.save(examOrgTimes);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除考试批次
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void deleteExam(List<Long> ids) {
|
|
|
+ List<Exam> exams = examRepo.findByIdIn(ids);
|
|
|
+ for (Exam exam : exams) {
|
|
|
+ // 删除考生
|
|
|
+ if (exam.getCanStuDel()) {
|
|
|
+ // 删除学习中心考试时间
|
|
|
+ examOrgTimeRepo.deleteByExamId(exam.getId());
|
|
|
+ examStudentService.deleteExamStudents(exam.getId());
|
|
|
+ examRepo.delete(exam);
|
|
|
+ } else {
|
|
|
+ throw new StatusException("", "[ " + exam.getName() + " ] 已经开始,不能删除");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean checkExamName(Exam exam) {
|
|
|
+ if (exam.getId() != null) {
|
|
|
+ if (examRepo.countByNameAndRootOrgIdAndIdNot(exam.getName(), exam.getRootOrgId(),
|
|
|
+ exam.getId()) > 0) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (examRepo.countByNameAndRootOrgId(exam.getName(), exam.getRootOrgId()) > 0) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Exam findExamByNameAndRootOrgId(String examName, Long rootOrgId) {
|
|
|
+ Exam exam = new Exam();
|
|
|
+ exam.setName(examName);
|
|
|
+ exam.setRootOrgId(rootOrgId);
|
|
|
+ return examRepo.findOne(Example.of(exam));
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Exam> findByNameAndRootOrgId(String name, Long rootOrgId) {
|
|
|
+ return examRepo.findByNameAndRootOrgId(name, rootOrgId);
|
|
|
}
|
|
|
}
|