Преглед на файлове

Merge remote-tracking branch 'remotes/origin/hotfixes_v3.0_20200604'

deason преди 5 години
родител
ревизия
e773b22ae4

+ 115 - 99
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/ExamCaptureServiceImpl.java

@@ -8,6 +8,8 @@
 package cn.com.qmth.examcloud.core.oe.admin.service.impl;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
 import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamCaptureRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
@@ -56,13 +58,14 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
     private ExamRecordDataRepo examRecordDataRepo;
     @Autowired
     private ExamSyncCaptureRepo examSyncCaptureRepo;
-
+    private static final ExamCloudLog LOG = ExamCloudLogFactory
+            .getLog(ExamCaptureServiceImpl.class);
     @Override
     public ExamCaptureAuditInfo getExamCaptureAuditDetail(Long examRecordDataId) {
         if (examRecordDataId == null) {
             return null;
         }
-        ExamRecordDataEntity recordData = GlobalHelper.getEntity(examRecordDataRepo,examRecordDataId,ExamRecordDataEntity.class);
+        ExamRecordDataEntity recordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
         if (recordData == null) {
             return null;
         }
@@ -70,28 +73,28 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
         ExamAuditEntity audit = examAuditService.getExamAuditByExamRecordDataId(examRecordDataId);
         ExamCaptureAuditInfo detail = new ExamCaptureAuditInfo();
         if (audit != null) {
-             if (audit.getStatus() != null) {
-                 detail.setStatus(audit.getStatus().getName());
-             } else {
-                 detail.setStatus(AuditStatus.UN_PASS.getName());
-             }
-             detail.setDisciplineDetail(audit.getDisciplineDetail());
-             if(audit.getDisciplineType() != null){
-             	detail.setDisciplineType(audit.getDisciplineType().getName());
-             }
+            if (audit.getStatus() != null) {
+                detail.setStatus(audit.getStatus().getName());
+            } else {
+                detail.setStatus(AuditStatus.UN_PASS.getName());
+            }
+            detail.setDisciplineDetail(audit.getDisciplineDetail());
+            if (audit.getDisciplineType() != null) {
+                detail.setDisciplineType(audit.getDisciplineType().getName());
+            }
         }
-        
+
         detail.setExamRecordDataId(examRecordDataId);
         detail.setStudentId(recordData.getStudentId());
         detail.setStudentCode(recordData.getStudentCode());
         detail.setStudentName(recordData.getStudentName());
         detail.setIdentityNumber(recordData.getIdentityNumber());
-        
+
         CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(recordData.getCourseId());
 
         detail.setCourseCode(courseBean.getCode());
         detail.setCourseName(courseBean.getName());
-        
+
         detail.setIsWarn(recordData.getIsWarn());
         detail.setIsAudit(recordData.getIsAudit());
         detail.setIsIllegality(recordData.getIsIllegality());
@@ -102,8 +105,8 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
         detail.setFaceSuccessPercent(recordData.getFaceSuccessPercent());
         detail.setFaceLandmarkVal(recordData.getFaceLandmarkVal());
         detail.setBaiduFaceLivenessSuccessPercent(recordData.getBaiduFaceLivenessSuccessPercent());
-        if(recordData.getFaceVerifyResult()!=null){
-        	detail.setFaceVerifyResult(recordData.getFaceVerifyResult().name());
+        if (recordData.getFaceVerifyResult() != null) {
+            detail.setFaceVerifyResult(recordData.getFaceVerifyResult().name());
         }
         detail.setVirtualCameraNames(getVirtualCameraNames(examRecordDataId));
 //同步人脸比较时抓拍照片的url
@@ -120,41 +123,48 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
 
         return syncCapture.getFileUrl();
     }
-    
+
     /**
      * 获取虚拟摄像头名称
+     *
      * @param examRecordDataId
      * @return
      */
-    private String getVirtualCameraNames(Long examRecordDataId){
-    	 Set<String> virtualCameraNames = new HashSet<String>();
-         List<ExamCaptureEntity> examCaptureList = examCaptureRepo.findByExamRecordDataId(examRecordDataId);
-         if(examCaptureList != null && examCaptureList.size() >0){
-         	for(ExamCaptureEntity examCapture:examCaptureList){
-         		String cameraInfos = examCapture.getCameraInfos();
-         		if(StringUtils.isNotBlank(cameraInfos)){
-         			JSONArray jsonArray;
-					try {
-						jsonArray = new JSONArray(cameraInfos);						
-						for(int i = 0;i<jsonArray.length();i++){
-	         				JSONObject jsonObject = (JSONObject) jsonArray.get(i);
-	         				if(StringUtils.isBlank(jsonObject.getString("pid"))){
-	         					virtualCameraNames.add(jsonObject.getString("name"));
-	         				}
-	         			}
-					} catch (JSONException e) {
-						e.printStackTrace();
-						throw new StatusException("ExamCaptureService-001", "获取虚拟摄像头名称失败");
-					}
-         			
-         		}
-         	}
-         }
-         StringBuffer sb = new StringBuffer();
-         for(String cameraName:virtualCameraNames){
-        	 sb.append(cameraName).append(";");
-         }
-         return sb.toString();
+    private String getVirtualCameraNames(Long examRecordDataId) {
+        Set<String> virtualCameraNames = new HashSet<String>();
+        List<ExamCaptureEntity> examCaptureList = examCaptureRepo.findByExamRecordDataId(examRecordDataId);
+        if (examCaptureList != null && examCaptureList.size() > 0) {
+            for (ExamCaptureEntity examCapture : examCaptureList) {
+                String cameraInfos = examCapture.getCameraInfos();
+                if (StringUtils.isNotBlank(cameraInfos)) {
+                    JSONArray jsonArray;
+                    try {
+                        jsonArray = new JSONArray(cameraInfos);
+                        for (int i = 0; i < jsonArray.length(); i++) {
+                            try {
+                                JSONObject jsonObject = (JSONObject) jsonArray.get(i);
+                                if (StringUtils.isBlank(jsonObject.getString("pid"))) {
+                                    virtualCameraNames.add(jsonObject.getString("name"));
+                                }
+                            } catch (JSONException e) {
+                                //主要针对json数组最后的空对象处理,不影响业务
+                                LOG.error("抓拍照片格式不正确", e);
+                                continue;
+                            }
+                        }
+                    } catch (JSONException e) {
+                        LOG.error("获取虚拟摄像头名称失败",e);
+                        throw new StatusException("ExamCaptureService-001", "获取虚拟摄像头名称失败");
+                    }
+
+                }
+            }
+        }
+        StringBuffer sb = new StringBuffer();
+        for (String cameraName : virtualCameraNames) {
+            sb.append(cameraName).append(";");
+        }
+        return sb.toString();
     }
 
     @Override
@@ -164,13 +174,13 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
         }
         List<ExamCaptureEntity> examCaptureEntityList = examCaptureRepo.findByExamRecordDataId(examRecordDataId);
         List<ExamCaptureInfo> examCaptureInfoList = new ArrayList<ExamCaptureInfo>();
-        for(ExamCaptureEntity examCapture:examCaptureEntityList){
-        	examCaptureInfoList.add(buildExamCaptureInfo(examCapture));
+        for (ExamCaptureEntity examCapture : examCaptureEntityList) {
+            examCaptureInfoList.add(buildExamCaptureInfo(examCapture));
         }
         return examCaptureInfoList;
     }
 
-    
+
     public ExamCaptureInfo buildExamCaptureInfo(ExamCaptureEntity entity) {
         ExamCaptureInfo info = new ExamCaptureInfo();
         info.setId(entity.getId());
@@ -179,48 +189,54 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
         info.setReturnMessage(entity.getFaceCompareResult());
         info.setPass(entity.getIsPass());
         info.setStranger(entity.getIsStranger());
-        
+
         String faceLivenessResult = entity.getFacelivenessResult();
         info.setIsFacelivenessPass(isFaceLivenessPass(faceLivenessResult));
-        
+
         String cameraInfos = entity.getCameraInfos();
         info.setVirtualCameraNames(getVirtualCameraNames(cameraInfos));
         return info;
     }
-    
-    private String getVirtualCameraNames(String cameraInfos){
-    	StringBuffer sb = new StringBuffer();
-    	if(StringUtils.isNotBlank(cameraInfos)){
- 			JSONArray jsonArray;
-			try {
-				jsonArray = new JSONArray(cameraInfos);
-				for(int i = 0;i<jsonArray.length();i++){
-	 				JSONObject jsonObject = (JSONObject) jsonArray.get(i);
-	 				if(StringUtils.isBlank(jsonObject.getString("pid"))){
-	 					sb.append(jsonObject.getString("name")+",");
-	 				}
-	 			}
-			} catch (JSONException e) {
-				e.printStackTrace();
-				throw new StatusException("ExamCaptureService-002", "获取虚拟摄像头名称失败");
-			}
- 			
- 			if(sb.lastIndexOf(",")>-1){
- 				return sb.substring(0, sb.lastIndexOf(","));
- 			}
- 		}
-    	return sb.toString();
+
+    private String getVirtualCameraNames(String cameraInfos) {
+        StringBuffer sb = new StringBuffer();
+        if (StringUtils.isNotBlank(cameraInfos)) {
+            JSONArray jsonArray;
+            try {
+                jsonArray = new JSONArray(cameraInfos);
+                for (int i = 0; i < jsonArray.length(); i++) {
+                    try {
+                        JSONObject jsonObject = (JSONObject) jsonArray.get(i);
+                        if (StringUtils.isBlank(jsonObject.getString("pid"))) {
+                            sb.append(jsonObject.getString("name") + ",");
+                        }
+                    } catch (JSONException e) {
+                        //主要针对json数组最后的空对象处理,不影响业务eg:"[   {      \"name\" : \"Camera\",      \"pid\" : \"\",      \"vid\" : \"\"   },]";
+                        LOG.error("抓拍照片格式不正确", e);
+                        continue;
+                    }
+                }
+            } catch (JSONException e) {
+                LOG.error("获取虚拟摄像头名称失败",e);
+                throw new StatusException("ExamCaptureService-002", "获取虚拟摄像头名称失败");
+            }
+
+            if (sb.lastIndexOf(",") > -1) {
+                return sb.substring(0, sb.lastIndexOf(","));
+            }
+        }
+        return sb.toString();
     }
-    
-    private boolean isFaceLivenessPass(String faceLivenessResult){
-    	if(StringUtils.isNotBlank(faceLivenessResult)){
-			JSONObject jsonObject;
-			try {
-				jsonObject = new JSONObject(faceLivenessResult);
-				if(jsonObject.has("error_code")&&jsonObject.getInt("error_code") == 0&&jsonObject.has("result")){
-					JSONObject resultJson = jsonObject.getJSONObject("result");
-					if(resultJson.has("face_liveness")){
-						double faceLivenessVal = resultJson.getDouble("face_liveness");
+
+    private boolean isFaceLivenessPass(String faceLivenessResult) {
+        if (StringUtils.isNotBlank(faceLivenessResult)) {
+            JSONObject jsonObject;
+            try {
+                jsonObject = new JSONObject(faceLivenessResult);
+                if (jsonObject.has("error_code") && jsonObject.getInt("error_code") == 0 && jsonObject.has("result")) {
+                    JSONObject resultJson = jsonObject.getJSONObject("result");
+                    if (resultJson.has("face_liveness")) {
+                        double faceLivenessVal = resultJson.getDouble("face_liveness");
 
                         Double baiduFacelivenessThreshold;
                         SysPropertyCacheBean baiduFacelivenessThresholdProperty = CacheHelper.getSysProperty("$baidu.faceliveness.threshold");
@@ -230,18 +246,18 @@ public class ExamCaptureServiceImpl implements ExamCaptureService {
                             baiduFacelivenessThreshold = Double.valueOf(baiduFacelivenessThresholdProperty.getValue().toString());
                         }
 
-						if(faceLivenessVal > baiduFacelivenessThreshold){
-							return true;
-						}
-					}
-				}
-			} catch (JSONException e) {
-				e.printStackTrace();
-				return false;
-			}
-			
-    	}
-		return false;
-	}
-    
-}
+                        if (faceLivenessVal > baiduFacelivenessThreshold) {
+                            return true;
+                        }
+                    }
+                }
+            } catch (JSONException e) {
+                LOG.error("json格式转换失败",e);
+                return false;
+            }
+
+        }
+        return false;
+    }
+
+}