Procházet zdrojové kódy

增加数据同步功能

宋悦 před 8 roky
rodič
revize
70a6efa5c6

+ 6 - 0
exam-work-api/pom.xml

@@ -70,6 +70,12 @@
             <artifactId>commons-fileupload</artifactId>
             <version>1.3.2</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.qmth.commons</groupId>
+            <artifactId>data-sync-rabbit</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
     
 	<build>

+ 7 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamApi.java

@@ -148,4 +148,11 @@ public class ExamApi {
         }
         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);
+    }
 }

+ 7 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/api/ExamStudentApi.java

@@ -22,6 +22,7 @@ import javax.persistence.criteria.Root;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.jpa.domain.Specification;
@@ -139,6 +140,9 @@ public class ExamStudentApi {
             }
             Exam exam = examRepo.findOne(examStudent.getExam().getId());
             examStudent.setExam(exam);
+            if(StringUtils.isEmpty(examStudent.getPaperType())){
+                examStudent.setPaperType("O");
+            }
             ExamStudent saveExamStu = examStudentService.saveExamStudent(examStudent);
             return new ResponseEntity(saveExamStu, HttpStatus.OK);
         } catch (Exception e) {
@@ -153,6 +157,9 @@ public class ExamStudentApi {
         try {
             Exam exam = examRepo.findOne(examStudent.getExam().getId());
             examStudent.setExam(exam);
+            if(StringUtils.isEmpty(examStudent.getPaperType())){
+                examStudent.setPaperType("O");
+            }
             ExamStudent saveExamStu = examStudentService.saveExamStudent(examStudent);
             return new ResponseEntity(saveExamStu, HttpStatus.OK);
         } catch (Exception e) {

+ 2 - 4
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/ExamStudentService.java

@@ -7,7 +7,6 @@ import java.util.List;
 import javax.persistence.criteria.Predicate;
 
 import cn.com.qmth.examcloud.common.util.BeanCopierUtil;
-import cn.com.qmth.examcloud.service.examwork.service.rpc.OeService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -384,11 +383,10 @@ public class ExamStudentService {
 		List<ExamStudent> targetExamStudents = new ArrayList<ExamStudent>();
 		Exam targetExam = examRepo.findOne(targetExamId);
 		sourceExamStudents.stream().forEach(examStudent -> {
-			if(examStudentRepo.checkExamStuById(examStudent.getExam().getId(),
+			if(examStudentRepo.checkExamStu(targetExam.getId(),
 					examStudent.getRootOrgId(),
 					examStudent.getIdentityNumber(),
-					examStudent.getCourseCode(),
-					examStudent.getId()) == 0){
+					examStudent.getCourseCode()) == 0){
 				ExamStudent tempStudent = BeanCopierUtil.copyProperties(examStudent,ExamStudent.class);
 				tempStudent.setId(null);
 				tempStudent.setExam(targetExam);

+ 81 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/sync/DataReceiveService.java

@@ -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---------");
+    }
+}

+ 10 - 0
exam-work-api/src/main/java/cn/com/qmth/examcloud/service/examwork/service/sync/DataSendService.java

@@ -0,0 +1,10 @@
+package cn.com.qmth.examcloud.service.examwork.service.sync;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * Created by songyue on 17/8/3.
+ */
+@Service
+public class DataSendService {
+}

+ 8 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/ExamRepo.java

@@ -3,9 +3,12 @@ package cn.com.qmth.examcloud.service.examwork.dao;
 import java.util.List;
 
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.service.examwork.entity.Exam;
+import org.springframework.transaction.annotation.Transactional;
 
 public interface ExamRepo extends JpaRepository<Exam, Long>,QueryByExampleExecutor<Exam>{
 
@@ -22,4 +25,9 @@ public interface ExamRepo extends JpaRepository<Exam, Long>,QueryByExampleExecut
 	Long countByNameAndIdNot(String name,Long id);
 
 	Long countByNameAndRootOrgIdAndIdNot(String name,Long rootOrgId,Long id);
+
+	@Transactional
+	@Modifying
+	@Query("update Exam e set e.canStuDel = false where e.id = ?1")
+	void canNotDel(Long id);
 }

+ 5 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/dao/ExamStudentRepo.java

@@ -46,4 +46,9 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, Query
     @Modifying
     @Query("update ExamStudent s set s.name = ?2,s.specialtyName  = ?3,s.examSite = ?4  where s.identityNumber = ?1")
     void updateById(String identityNumber,String name,String specialtyName,String examSite);
+
+    @Query("select s from ExamStudent s where s.rootOrgId=?1 and s.courseCode=?2")
+    List<ExamStudent> findByCourseCode(Long rootOrgId,String courseCode);
+
+    List<ExamStudent> findByOrgId(Long orgId);
 }

+ 1 - 0
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/Exam.java

@@ -199,6 +199,7 @@ public class Exam implements Serializable {
 	/**
 	 * 学生是否可以删除
      */
+	@NotNull
 	private Boolean canStuDel;
 
 

+ 1 - 1
exam-work-domain/src/main/java/cn/com/qmth/examcloud/service/examwork/entity/ExamStudent.java

@@ -21,7 +21,7 @@ public class ExamStudent implements Serializable {
 	@NotNull
 	private String name;
 
-	@ManyToOne(cascade = { CascadeType.REFRESH })
+	@ManyToOne
 	@JoinColumn(name = "examId")
 	private Exam exam;
 	/**

+ 5 - 0
exam-work-main/pom.xml

@@ -22,6 +22,11 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 7 - 0
exam-work-main/src/main/java/cn/com/qmth/examcloud/service/examwork/Application.java

@@ -1,15 +1,22 @@
 package cn.com.qmth.examcloud.service.examwork;
 
+import com.qmth.commons.query.dao.impl.BaseQueryDaoImpl;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
 import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
 import org.springframework.cloud.netflix.feign.EnableFeignClients;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 import org.springframework.web.multipart.MultipartResolver;
 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
+@ComponentScan(basePackages = {"com.qmth.commons","cn.com.qmth"})
+@EntityScan(basePackages = {"com.qmth.commons","cn.com.qmth"})
+@EnableJpaRepositories(basePackages = {"com.qmth.commons","cn.com.qmth"},repositoryBaseClass = BaseQueryDaoImpl.class)
 @SpringBootApplication
 @EnableEurekaClient
 @EnableFeignClients

+ 7 - 1
exam-work-main/src/main/resources/application-dev.properties

@@ -7,4 +7,10 @@ spring.redis.host=127.0.0.1
 spring.redis.port=6379
 
 
-eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
+eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
+
+spring.rabbitmq.host=192.168.1.99
+spring.rabbitmq.port=5672
+spring.rabbitmq.username=examcloud
+spring.rabbitmq.password=examcloud
+spring.rabbitmq.listener.acknowledgeMode=MANUAL

+ 2 - 1
exam-work-main/src/main/resources/application.properties

@@ -14,7 +14,7 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 logging.level.org.springframework=ERROR
 logging.level.org.hibernate=ERROR
 
-spring.jpa.show-sql=true
+spring.jpa.show-sql=false
 spring.jpa.hibernate.ddl-auto=update
 
 
@@ -27,6 +27,7 @@ hystrix.command.default.execution.timeout.enabled=false
 
 app.api.root=/api/ecs_exam_work
 app.api.core=/api/ecs_core
+app.api.oe=/api/ecs_oe
 #\u5b66\u751f\u7167\u7247\u4e0a\u4f20\u5730\u5740
 app.em.photo.path=/Users/ting.yin/Downloads
 app.em.facepp.key=e94d4a6a1ea8749144328be96a40e388

+ 1 - 4
pom.xml

@@ -19,12 +19,9 @@
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
-        <version>1.4.3.RELEASE</version>
+        <version>1.5.2.RELEASE</version>
     </parent>
 
-
-
-
     <properties>
         <!-- non-dependencies -->
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>