|
@@ -0,0 +1,105 @@
|
|
|
+package cn.com.qmth.examcloud.exchange.outer.service.impl;
|
|
|
+
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.support.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.client.CourseCloudServiceClient;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.client.OrgCloudServiceClient;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.client.StudentCloudServiceClient;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.CourseReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.OrgReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.StudentReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.OrgResp;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.client.ExamCloudClient;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.client.ExamStudentCloudClient;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.ExamReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.ExamResp;
|
|
|
+import cn.com.qmth.examcloud.exchange.outer.api.request.ExamStudentAllInfoReq;
|
|
|
+import cn.com.qmth.examcloud.exchange.outer.service.ExamStudentService;
|
|
|
+
|
|
|
+public class ExamStudentServiceImpl implements ExamStudentService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamCloudClient examCloudClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamStudentCloudClient examStudentCloudClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrgCloudServiceClient orgCloudServiceClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CourseCloudServiceClient courseCloudServiceClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentCloudServiceClient studentCloudServiceClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveExamStudents(List<ExamStudentAllInfoReq> examStudentReqList) {
|
|
|
+ chechExamStudents(examStudentReqList);
|
|
|
+ Long rootOrgId = 109L;
|
|
|
+ ExamResp examResp = getExamResp(examStudentReqList,rootOrgId);
|
|
|
+ for(ExamStudentAllInfoReq examStudentAllInfoReq:examStudentReqList){
|
|
|
+ OrgResp orgResp = saveOrg(examStudentAllInfoReq,rootOrgId);
|
|
|
+ saveCourse(examStudentAllInfoReq,rootOrgId);
|
|
|
+ saveStudent(examStudentAllInfoReq,orgResp,rootOrgId);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveStudent(ExamStudentAllInfoReq examStudentAllInfoReq,OrgResp orgResp,Long rootOrgId) {
|
|
|
+ StudentReq studentReq = new StudentReq();
|
|
|
+ studentReq.setName(examStudentAllInfoReq.getStudentName());
|
|
|
+ studentReq.setStudentCode(examStudentAllInfoReq.getStudentCode());
|
|
|
+ studentReq.setOrgId(orgResp.getId());
|
|
|
+ studentReq.setRootOrgId(rootOrgId);
|
|
|
+ studentCloudServiceClient.saveStudent(studentReq);
|
|
|
+ }
|
|
|
+
|
|
|
+ private OrgResp saveOrg(ExamStudentAllInfoReq examStudentAllInfoReq,Long rootOrgId) {
|
|
|
+ OrgReq orgReq = new OrgReq();
|
|
|
+ orgReq.setRootOrgId(rootOrgId);
|
|
|
+ orgReq.setOrgCode(examStudentAllInfoReq.getOrgCode());
|
|
|
+ orgReq.setOrgName(examStudentAllInfoReq.getOrgName());
|
|
|
+ return orgCloudServiceClient.saveOrg(orgReq);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveCourse(ExamStudentAllInfoReq examStudentAllInfoReq,Long rootOrgId) {
|
|
|
+ CourseReq courseReq = new CourseReq();
|
|
|
+ courseReq.setOrgId(rootOrgId);
|
|
|
+ courseReq.setCourseName(examStudentAllInfoReq.getCourseName());
|
|
|
+ courseReq.setCourseCode(examStudentAllInfoReq.getCourseCode());
|
|
|
+ courseReq.setCourseLevel(examStudentAllInfoReq.getCourseLevel());
|
|
|
+ courseCloudServiceClient.saveCourse(courseReq);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void chechExamStudents(List<ExamStudentAllInfoReq> examStudentReqList){
|
|
|
+ if(examStudentReqList==null||examStudentReqList.size()==0){
|
|
|
+ throw new StatusException("exchange-errorMsg","集合不能为空");
|
|
|
+ }
|
|
|
+ if(examStudentReqList.size()>1000){
|
|
|
+ throw new StatusException("exchange-errorMsg","单次集合长度不能大于1000");
|
|
|
+ }
|
|
|
+ HashSet<String> examNameSet = new HashSet<String>();
|
|
|
+ for(ExamStudentAllInfoReq examStudentAllInfoReq:examStudentReqList){
|
|
|
+ examNameSet.add(examStudentAllInfoReq.getExamName());
|
|
|
+ }
|
|
|
+ if(examNameSet.size()>1){
|
|
|
+ throw new StatusException("exchange-errorMsg","集合中不允许存在多个考试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ExamResp getExamResp(List<ExamStudentAllInfoReq> examStudentReqList,Long rootOrgId){
|
|
|
+ ExamStudentAllInfoReq firstExamStudent = examStudentReqList.get(0);
|
|
|
+
|
|
|
+ ExamReq examReq = new ExamReq();
|
|
|
+ examReq.setName(firstExamStudent.getExamName());
|
|
|
+ examReq.setRootOrgId(rootOrgId);
|
|
|
+ return examCloudClient.findExamByExamReq(examReq);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|