Quellcode durchsuchen

[add rpc api] existExamRecordData

deason vor 3 Jahren
Ursprung
Commit
d346adf8f8

+ 29 - 4
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/api/provider/ExamRecordDataCloudServiceProvider.java

@@ -19,11 +19,13 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.persistence.criteria.Predicate;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -32,10 +34,6 @@ import java.util.List;
 @RequestMapping("${$rmp.cloud.oe.student}/examRecordData")
 public class ExamRecordDataCloudServiceProvider extends ControllerSupport implements ExamRecordDataCloudService {
 
-
-    /**
-     *
-     */
     private static final long serialVersionUID = 6142107111834463854L;
 
     @Autowired
@@ -65,6 +63,33 @@ public class ExamRecordDataCloudServiceProvider extends ControllerSupport implem
     @Autowired
     private ExamControlService examControlService;
 
+    @Override
+    @ApiOperation(value = "查询是否存在考试记录")
+    @PostMapping("/existExamRecordData")
+    public ExistExamRecordDataResp existExamRecordData(ExistExamRecordDataReq req) {
+        if (req.getExamId() == null) {
+            throw new StatusException("400400", "考试ID不允许为空");
+        }
+
+        Specification<ExamRecordDataEntity> specification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+            predicates.add(cb.equal(root.get("examId"), req.getExamId()));
+
+            if (req.getCourseId() != null) {
+                predicates.add(cb.equal(root.get("courseId"), req.getCourseId()));
+            }
+
+            if (req.getStudentId() != null) {
+                predicates.add(cb.equal(root.get("studentId"), req.getStudentId()));
+            }
+
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+
+        long count = examRecordDataRepo.count(specification);
+        return new ExistExamRecordDataResp(count > 0);
+    }
+
     @Override
     @ApiOperation(value = "批量获取未同步的考试记录ID")
     @PostMapping("/getExamRecordDataIds")