<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Api id="__lLwHx6c93oUoOsj8s67">
  <name>行业考试管理-我的培训-人脸核验</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <status>published</status>
  <apiGroup></apiGroup>
  <encode>UTF-8</encode>
  <requestType>post</requestType>
  <requestUrl>/train/insert/train/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 resuilt = json["resuilt"];//0是不通过 1是通过
    var process = getDocumentProcess();
    var formProcess = getFormProcess();            
    var faceInfo = formProcess.doView("__Xl7jLxrPn56kn0XuMua");
    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_name",getWebUser().getName());
      faceInfoDoc.addStringItem("person_employee_id",getWebUser().getId());
      faceInfoDoc.addStringItem("type",type);
      var personDoc=findDocument(person_id);
      faceInfoDoc.addStringItem("idcard_no",personDoc.findItem("idcard_no").getValue());
      faceInfoDoc.addStringItem("telephone",personDoc.findItem("telephone").getValue());
      faceInfoDoc.addStringItem("class_id",personDoc.findItem("class_id").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");
          }else{
            faceInfoDoc.addStringItem("msg","人脸识别失败");
            result.put("msg","人脸识别失败")
            result.put("code","0");
            faceInfoDoc.addStringItem("check_resuilt","0");
          }
        }else{
          faceInfoDoc.addStringItem("msg","人脸识别出错");
          result.put("msg","人脸识别出错")
          result.put("code","0");
          faceInfoDoc.addStringItem("check_resuilt","0");
        }

      }catch(e){
        faceInfoDoc.addStringItem("msg","人脸识别出错");
        result.put("msg","人脸识别出错")
        result.put("code","0");
        faceInfoDoc.addStringItem("comparison_info",e);
        faceInfoDoc.addStringItem("check_resuilt","0");
      }

      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("telephone",personDoc.findItem("telephone").getValue());
      faceInfoDoc.addStringItem("idcard_no",personDoc.findItem("idcard_no").getValue());
      faceInfoDoc.addStringItem("class_id",personDoc.findItem("class_id").getValue());
      faceInfoDoc.addStringItem("person_name",personDoc.findItem("person_name").getValue());
      faceInfoDoc.addStringItem("person_employee_id",personDoc.findItem("employee_id").getValue());
      if("1".equals(resuilt)){//同时进行签到
        var teacher_class_id = json["class_id"]
        var person_class_id=personDoc.findItem("class_id").getValue();
        if(!teacher_class_id.equals(person_class_id)){
          result.put("code","500");
          result.put("msg","当前班级与学员签到的班级不一致，请核对！");
          result.put("state", false);
          return result;
        }
        var process = getDocumentProcess();
        var formProcess = getFormProcess();
        var personSignInfo = formProcess.doView("__76KsQBpAITtCResDauk");
        var personSignInfoDoc = process.doNew(personSignInfo,getWebUser(),createParamsTable());
        var class_id = personDoc.findItem("class_id").getValue()//班级id
        personSignInfoDoc.addStringItem("class_id",class_id);
        var classDoc=findDocument(class_id);//获取班级信息
        var classroom_name=classDoc.findItem("classroom_name").getValue()//教室名称
        var classroom_id=classDoc.findItem("classroom_id").getValue()//教室id
        personSignInfoDoc.addStringItem("classroom_name",classroom_name);
        personSignInfoDoc.addStringItem("classroom_id",classroom_id);
        var point_type_id = personDoc.findItem("point_type").getValue()//培训类型id
        var pointTypeDoc=findDocument(point_type_id);//获取培训类型文档
        var point_type=pointTypeDoc.findItem("point_type").getValue()//培训类型名称
        personSignInfoDoc.addStringItem("point_type",point_type);
        personSignInfoDoc.addStringItem("point_type_id",point_type_id);
        var classroom_type = personDoc.findItem("classroom_type").getValue()//教室类型
        personSignInfoDoc.addStringItem("classroom_type",classroom_type);
        var person_name = personDoc.findItem("person_name").getValue()//人员姓名
        var employee_id = personDoc.findItem("employee_id").getValue()//人员职员id
        var idcard_no = personDoc.findItem("idcard_no").getValue()//人员身份证
        var telephone = personDoc.findItem("telephone").getValue()//人员手机号
        personSignInfoDoc.addStringItem("person_name",person_name);
        personSignInfoDoc.addStringItem("employee_id",employee_id);
        personSignInfoDoc.addStringItem("idcard_no",idcard_no);
        personSignInfoDoc.addStringItem("telephone",telephone);
        personSignInfoDoc.addStringItem("resuilt",resuilt);
        personSignInfoDoc.addDateItem("sign_date",getToday());
        personSignInfoDoc.addStringItem("sign_teacher",userName);
        personSignInfoDoc.addStringItem("sign_teacher_id",userid);
        personSignInfoDoc.addStringItem("domain_name",domainName);
        personSignInfoDoc.addStringItem("domain_id",domainid);
        var person_sign_status=personDoc.findItem("sign_status").getValue()
        if("0".equals(person_sign_status)&&"1".equals(resuilt)){
          personDoc.findItem("sign_status").setValue('1')//签到状态
          process.doUpdate(personDoc); 
        }
        process.doCreate(personSignInfoDoc); 

        result.put("code","1");
        faceInfoDoc.addStringItem("msg","教师核验通过");
        faceInfoDoc.addStringItem("check_resuilt","1");
        result.put("msg","教师核验通过")
      }else{
        result.put("code","0");
        faceInfoDoc.addStringItem("msg","教师核验不通过");
        faceInfoDoc.addStringItem("check_resuilt","0");
        result.put("msg","教师核验不通过")

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