|
@@ -0,0 +1,81 @@
|
|
|
+package cn.com.qmth.examcloud.service.examwork.service.sync;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.ExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
|
|
|
+import com.qmth.commons.dataSync.core.annotations.DataReceive;
|
|
|
+import com.qmth.commons.dataSync.core.entity.BaseSyncData;
|
|
|
+import com.qmth.commons.dataSync.core.service.DataSyncService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by songyue on 17/8/3.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DataReceiveService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(DataReceiveService.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DataSyncService dataSyncService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
+
|
|
|
+ @DataReceive(domain = "cn.com.qmth.examcloud.common.dto.core.CourseSync")
|
|
|
+ public synchronized void readCourse(BaseSyncData baseSyncData) {
|
|
|
+ if (dataSyncService.expired(baseSyncData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("-----------coursesync start---------");
|
|
|
+ log.info(baseSyncData.toString());
|
|
|
+ String courseCode = baseSyncData.getEntity().get("code");
|
|
|
+ String orgId = baseSyncData.getEntity().get("orgId");
|
|
|
+ String courseName = baseSyncData.getEntity().get("name");
|
|
|
+ String courseLevel = baseSyncData.getEntity().get("level");
|
|
|
+ if(StringUtils.isEmpty(courseCode)
|
|
|
+ || StringUtils.isEmpty(orgId)
|
|
|
+ || StringUtils.isEmpty(courseName)
|
|
|
+ || StringUtils.isEmpty(courseLevel)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ExamStudent> examStudents = examStudentRepo.findByCourseCode(Long.valueOf(orgId),courseCode);
|
|
|
+ for(ExamStudent examStudent:examStudents){
|
|
|
+ if(!examStudent.getCourseLevel().equals(courseLevel)){
|
|
|
+ examStudent.setCourseLevel(courseLevel);
|
|
|
+ }
|
|
|
+ if(!examStudent.getCourseName().equals(courseName)){
|
|
|
+ examStudent.setCourseName(courseName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ examStudentRepo.save(examStudents);
|
|
|
+ log.info("-----------coursesync end---------");
|
|
|
+ }
|
|
|
+
|
|
|
+ @DataReceive(domain = "cn.com.qmth.examcloud.common.dto.core.OrgSync")
|
|
|
+ public synchronized void readOrg(BaseSyncData baseSyncData) {
|
|
|
+ if (dataSyncService.expired(baseSyncData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("-----------orgsync start---------");
|
|
|
+ log.info(baseSyncData.toString());
|
|
|
+ String orgId = baseSyncData.getPk();
|
|
|
+ String name = baseSyncData.getEntity().get("name");
|
|
|
+ if(StringUtils.isEmpty(orgId)
|
|
|
+ || StringUtils.isEmpty(name)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ExamStudent> examStudents = examStudentRepo.findByOrgId(Long.valueOf(orgId));
|
|
|
+ for(ExamStudent examStudent:examStudents){
|
|
|
+ if(!examStudent.getOrgName().equals(name)){
|
|
|
+ examStudent.setOrgName(name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ examStudentRepo.save(examStudents);
|
|
|
+ log.info("-----------orgsync end---------");
|
|
|
+ }
|
|
|
+}
|