Commit 3b568b1f authored by 霍传世's avatar 霍传世

HaiNa---接口

parent f17e0f2c
...@@ -10,6 +10,8 @@ import org.springframework.jdbc.core.JdbcTemplate; ...@@ -10,6 +10,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
@RestController @RestController
@RequestMapping("/faceMatchApi") @RequestMapping("/faceMatchApi")
...@@ -45,42 +47,58 @@ public class FaceMatchController { ...@@ -45,42 +47,58 @@ public class FaceMatchController {
JSONObject object = new JSONObject(picName); JSONObject object = new JSONObject(picName);
picName = object.getString("picName"); picName = object.getString("picName");
log.info("faceMatch正在校验-》身份证号:"+idCard+"参加面试编号:"+examConnectionCode+"_人脸照片"); log.info("faceMatch正在校验-》身份证号:"+idCard+"参加面试编号:"+examConnectionCode+"_人脸照片");
String message = ""; if(check(examConnectionCode,idCard).get("result").equals("fail")){
if(check(examConnectionCode,idCard,message)){
JSONObject responseBody = new JSONObject(); JSONObject responseBody = new JSONObject();
responseBody.put("code",500); responseBody.put("code",500);
responseBody.put("message",message); responseBody.put("message",check(examConnectionCode,idCard).get("message").toString());
return ResponseEntity.badRequest().body(responseBody.toString()); return ResponseEntity.badRequest().body(responseBody.toString());
} }
String[] result = faceMatch.faceMatchBaidu(idCard,picName); try{
if(result[0].equals("1")){ String[] result = faceMatch.faceMatchBaidu(idCard,picName);
stringRedisTemplate.opsForValue().increment("face_success:" + examConnectionCode + "_" + idCard); JSONObject responseBody = new JSONObject();
DBOperator.update("update candidate_exam set status_face = 1 where exam_connection_code = ? and zkz_num = ?",new Object[]{examConnectionCode,zkzNum}); responseBody.put("code",200);
log.info("身份证:"+idCard+"参加面试编号:"+examConnectionCode+"人脸验证成功"); if(result[0].equals("1")){
}else{ stringRedisTemplate.opsForValue().increment("face_success:" + examConnectionCode + "_" + idCard);
stringRedisTemplate.opsForValue().increment("face_error:" + examConnectionCode + "_" + idCard); DBOperator.update("update candidate_exam set status_face = 1 where exam_connection_code = ? and zkz_num = ?",new Object[]{examConnectionCode,zkzNum});
log.info("身份证:"+idCard+"参加面试编号:"+examConnectionCode+"人脸验证失败"); log.info("身份证:"+idCard+"参加面试编号:"+examConnectionCode+"人脸验证成功");
responseBody.put("message","检测成功");
responseBody.put("result",true);
}else{
stringRedisTemplate.opsForValue().increment("face_error:" + examConnectionCode + "_" + idCard);
log.info("身份证:"+idCard+"参加面试编号:"+examConnectionCode+"人脸验证失败");
responseBody.put("message","检测成功");
responseBody.put("result",false);
}
return ResponseEntity.ok(responseBody.toString());
}catch (Exception e){
e.printStackTrace();
JSONObject data = new JSONObject();
data.put("code",500);
data.put("message","检测失败");
return ResponseEntity.ok(data.toString());
} }
JSONObject responseBody = new JSONObject();
responseBody.put("code",200);
responseBody.put("message","校验成功");
return ResponseEntity.ok(responseBody.toString());
} }
private boolean check(String examConnectionCode, String idCard,String message) { private HashMap<String,Object> check(String examConnectionCode, String idCard) {
String success = stringRedisTemplate.opsForValue().get("face_success:" + examConnectionCode + "_" + idCard); String success = stringRedisTemplate.opsForValue().get("face_success:" + examConnectionCode + "_" + idCard);
if (!StringUtils.isEmpty(success)) { if (!StringUtils.isEmpty(success)) {
if (Integer.parseInt(success) >= 1) { if (Integer.parseInt(success) >= 1) {
message = "请勿重复提交"; return new HashMap<String,Object>(){{
return true; put("result","fail");
put("message","请勿重复上传");
}};
} }
} }
String s = stringRedisTemplate.opsForValue().get("face_error:" + examConnectionCode + "_" + idCard); String s = stringRedisTemplate.opsForValue().get("face_error:" + examConnectionCode + "_" + idCard);
if (!StringUtils.isEmpty(s)) { if (!StringUtils.isEmpty(s)) {
if (Integer.parseInt(s) >=3) { if (Integer.parseInt(s) >=3) {
message = "失败次数超3次"; return new HashMap<String,Object>(){{
return true; put("result","fail");
put("message","失败次数超过三次");
}};
} }
} }
return false; return new HashMap<String,Object>(){{
put("result","success");
}};
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment