<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Api id="__vRaEEarUiAhAHI4C9Wj">
  <name>行业考试管理-我的考试-人脸核验</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <status>published</status>
  <apiGroup></apiGroup>
  <encode>UTF-8</encode>
  <requestType>post</requestType>
  <requestUrl>/train/insert/exam/face</requestUrl>
  <tags></tags>
  <responseType>json</responseType>
  <responseScript><![CDATA[(function () {
  var result = new Packages.java.util.HashMap(); //创建指定类对象
  var jsonStr = getParameter("_content");
  var domainid = getDomainid();
  var domainprocess = getDomainProcess();//获取企业域对象 
  var domainDao=domainprocess.doView(domainid);
  var domainName = domainDao.getName();
  var userName= getWebUser().getName();
  var userid = getWebUser().getId();
  if(isNotNull(jsonStr)){
    var json = JSON.parse(jsonStr);
    var person_id = json["id"];
    var type = json["type"];//0是自动核验 1是教师核验 
    var exam_type = json["exam_type"];//0是开卷 1是交卷
    var resuilt = json["resuilt"];//0是不通过 1是通过
    var process = getDocumentProcess();
    var formProcess = getFormProcess();            
    var faceInfo = formProcess.doView("__qy9N5kVJ3RbsBOOlDj1");
    var faceInfoDoc = process.doNew(faceInfo,getWebUser(),createParamsTable());
    if("0".equals(type)){
      var oneImg = json["oneImg"];
      var twoImg = json["twoImg"];
      var bizFaceMode = "HIGHLIVENESS";
      var vtp = 70;
      var needface = "0"
      var appointChannel = "UNIAPP";
      faceInfoDoc.addStringItem("comparison_photo",oneImg);
      faceInfoDoc.addStringItem("photo",twoImg);
      faceInfoDoc.addStringItem("person_id",person_id);
      faceInfoDoc.addStringItem("person_id",person_id);
      faceInfoDoc.addStringItem("person_id",person_id);
      faceInfoDoc.addStringItem("person_name",getWebUser().getName());
      faceInfoDoc.addStringItem("person_employee_id",getWebUser().getId());
      faceInfoDoc.addStringItem("type",type);
      var personDoc=findDocument(person_id);
      faceInfoDoc.addStringItem("exam_id",personDoc.findItem("exam_id").getValue());
      faceInfoDoc.addStringItem("idcard_no",personDoc.findItem("idcard_no").getValue());
      faceInfoDoc.addStringItem("telephone",personDoc.findItem("telephone").getValue());
      var url = "https://identify.qiye.baibaodun.com.cn:14433/identify/api/baidu/match-face";
      var URLConnector = Packages.cn.hutool.http.HttpUtil;
      var strS ="bizFaceMode="+bizFaceMode+"&vtp="+vtp+"&appointChannel="+appointChannel+"&oneImg="+oneImg+"&twoImg="+twoImg+"";
      try{
        var rtJsonStr = URLConnector.post(url,strS);
        faceInfoDoc.addStringItem("comparison_info",rtJsonStr);
        var rtJsonStrData = eval('('+rtJsonStr+')');

        if('0'.equals(rtJsonStrData.retType)){
          if('1'.equals(rtJsonStrData.data.result)){
            faceInfoDoc.addStringItem("msg","人脸识别成功");
            result.put("msg","人脸识别成功")
            result.put("code","1");
            faceInfoDoc.addStringItem("check_resuilt","1");
            if("1".equals(exam_type)){
              personDoc.findItem("over_face_status").setValue("1")
            }else{
              personDoc.findItem("face_status").setValue("1")
            }

          }else{
            faceInfoDoc.addStringItem("msg","人脸识别失败");
            result.put("msg","人脸识别失败")
            result.put("code","0");
            faceInfoDoc.addStringItem("check_resuilt","0");
            if("1".equals(exam_type)){
              personDoc.findItem("over_face_status").setValue("0")
            }else{
              personDoc.findItem("face_status").setValue("0")
            }
          }
        }else{
          faceInfoDoc.addStringItem("msg","人脸识别出错");
          result.put("msg","人脸识别出错")
          result.put("code","0");
          faceInfoDoc.addStringItem("check_resuilt","0");
          if("1".equals(exam_type)){
            personDoc.findItem("over_face_status").setValue("0")
          }else{
            personDoc.findItem("face_status").setValue("0")
          }
        }

      }catch(e){
        faceInfoDoc.addStringItem("msg","人脸识别出错");
        result.put("msg","人脸识别出错")
        result.put("code","0");
        faceInfoDoc.addStringItem("check_resuilt","0");
        if("1".equals(exam_type)){
          personDoc.findItem("over_face_status").setValue("0")
        }else{
          personDoc.findItem("face_status").setValue("0")
        }
        faceInfoDoc.addStringItem("comparison_info",e);
      }
      process.doUpdate(personDoc);
      process.doCreate(faceInfoDoc); 
      return result
    }else{
      faceInfoDoc.addStringItem("person_id",person_id);
      faceInfoDoc.addStringItem("teacher_name",getWebUser().getName());
      faceInfoDoc.addStringItem("teacher_id",getWebUser().getId());
      faceInfoDoc.addStringItem("type",type);
      var personDoc=findDocument(person_id);
      faceInfoDoc.addStringItem("exam_id",personDoc.findItem("exam_id").getValue());
      faceInfoDoc.addStringItem("idcard_no",personDoc.findItem("idcard_no").getValue());
      faceInfoDoc.addStringItem("telephone",personDoc.findItem("telephone").getValue());
      faceInfoDoc.addStringItem("person_name",personDoc.findItem("person_name").getValue());
      faceInfoDoc.addStringItem("person_employee_id",personDoc.findItem("employee_id").getValue());
      if("1".equals(resuilt)){
        result.put("code","1");
        faceInfoDoc.addStringItem("msg","教师核验通过");
        faceInfoDoc.addStringItem("check_resuilt","1");
        result.put("msg","教师核验通过")
        if("1".equals(exam_type)){
          personDoc.findItem("over_face_status").setValue("1")
        }else{
          personDoc.findItem("face_status").setValue("1")
        }
      }else{
        result.put("code","0");
        faceInfoDoc.addStringItem("check_resuilt","0");
        faceInfoDoc.addStringItem("msg","教师核验不通过");
        if("1".equals(exam_type)){
          personDoc.findItem("over_face_status").setValue("0")
        }else{
          personDoc.findItem("face_status").setValue("0")
        }
        result.put("msg","教师核验不通过")

      }
      process.doUpdate(personDoc);
      process.doCreate(faceInfoDoc); 
      return result
    }
  }else{
    result.put("code","0");
    result.put("msg","请求体不能为空")
  }
})()]]></responseScript>
</Api>