Browse Source

更新stuFace的save逻辑

ting.yin 8 years ago
parent
commit
799c86e3ce

+ 5 - 3
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/StudentFaceInfoApi.java

@@ -21,6 +21,7 @@ import cn.com.qmth.examcloud.service.core.entity.Student;
 import cn.com.qmth.examcloud.service.core.entity.StudentFaceInfo;
 import cn.com.qmth.examcloud.service.core.repo.StudentFaceInfoRepo;
 import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
+import cn.com.qmth.examcloud.service.core.service.StudentFaceInfoService;
 
 /**
  * 学生照片API
@@ -32,11 +33,13 @@ public class StudentFaceInfoApi {
     @Autowired
     StudentFaceInfoRepo studentFaceInfoRepo;
     @Autowired
+    StudentFaceInfoService studentFaceInfoService;
+    @Autowired
     StudentRepo studentRepo;
 
     @ApiOperation(value="按身份证查询",notes="查询")
     @GetMapping("/identityNumber")
-    public ResponseEntity findByIdentityNumber(@RequestParam String identityNumber){
+    public ResponseEntity findByIdentityNumber(@RequestParam Long orgId,@RequestParam String identityNumber){
     	Student student  = studentRepo.findByIdentityNumber(identityNumber);
     	if(student == null){
     		return new ResponseEntity(new ErrorMsg("该学生不存在"),HttpStatus.OK);
@@ -73,8 +76,7 @@ public class StudentFaceInfoApi {
     @ApiOperation(value="新增学生照片信息",notes="新增")
     @PostMapping
     public ResponseEntity add(@RequestBody StudentFaceInfo studentFaceInfo){
-    	studentFaceInfo.setCreateTime(new Date());
-        return new ResponseEntity(studentFaceInfoRepo.save(studentFaceInfo),HttpStatus.CREATED);
+        return new ResponseEntity(studentFaceInfoService.save(studentFaceInfo),HttpStatus.CREATED);
     }
 
     @ApiOperation(value="更新学生照片信息",notes="更新")

+ 3 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java

@@ -6,6 +6,8 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.transaction.Transactional;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
 import org.springframework.data.domain.ExampleMatcher;
@@ -27,6 +29,7 @@ public class CourseService {
     @Autowired
     CourseRepo courseRepo;
 
+    @Transactional
 	public List<ExcelError> importCourse(Long orgId,InputStream inputStream) {
 		List<Course> list = new ArrayList<Course>();
 		ExcelReader excelReader = new ExcelReader(CourseDTO.class);

+ 34 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentFaceInfoService.java

@@ -0,0 +1,34 @@
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.Date;
+
+import javax.transaction.Transactional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.service.core.entity.StudentFaceInfo;
+import cn.com.qmth.examcloud.service.core.repo.StudentFaceInfoRepo;
+
+
+@Service
+public class StudentFaceInfoService {
+
+    @Autowired
+    StudentFaceInfoRepo studentFaceInfoRepo;
+
+    @Transactional
+    public StudentFaceInfo save(StudentFaceInfo studentFaceInfo) {
+    	StudentFaceInfo old = studentFaceInfoRepo.findByStudentId(studentFaceInfo.getStudent().getId());
+    	if(old == null){
+			studentFaceInfo.setCreateTime(new Date());
+			return studentFaceInfoRepo.save(studentFaceInfo);
+    	}
+    	old.setUpdateTime(new Date());
+    	old.setFaceSetToken(studentFaceInfo.getFaceSetToken());
+    	old.setFaceToken(studentFaceInfo.getFaceToken());
+    	old.setPhotoMD5(studentFaceInfo.getPhotoMD5());
+        return studentFaceInfoRepo.save(old);
+    }
+
+}

+ 3 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java

@@ -7,6 +7,8 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import javax.transaction.Transactional;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
 import org.springframework.data.domain.ExampleMatcher;
@@ -103,6 +105,7 @@ public class StudentService {
         return list;
     }
 
+    @Transactional
     public Student save(Student student) {
         if (student.getUser() == null || null == student.getUser().getId()) {//判断是否有用户
             //判断是否有该学生,