<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task id="__yoVzMDMtqHb9Cy1cLqa">
  <name>证书同步到智能人事</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <description></description>
  <type>1</type>
  <runningTime>2023-08-01T09:44:09.000+08:00</runningTime>
  <interval>1</interval>
  <period>34</period>
  <runtimes>0</runtimes>
  <terminateScript><![CDATA[]]></terminateScript>
  <taskScript><![CDATA[(function(){
    Packages.java.lang.System.err.println("================证书同步至智能人事=================");
    var sqlO = "select id from tlk_certification where item_synchronize IS NULL OR item_synchronize='' OR item_synchronize='0' is null limit 20";
    var datasO = queryByDSName("tms", sqlO);
    var certificationId = "";
    if (datasO.size() > 0) {
      for (var iterator = datasO.iterator(); iterator.hasNext();) {
        var map1 = iterator.next();//取值
        certificationId += map1.get("id");
        println("certificationId1------------"+certificationId);
        certificationId += ";"
        println("certificationId2------------"+certificationId);
      }
    }
    if (isNotNull(certificationId)) {
      certificationId = certificationId.substring(0,certificationId.length-1);
      println("certificationId3------------"+certificationId);
      var arrto = splitText(certificationId, ";");
      var process = getDocumentProcess();
      for (var i = 0; i < arrto.length; i++) {
        println("id是"+arrto[i]);
        Packages.java.lang.System.err.println("================arrto[i]================="+arrto[i]);
        if(arrto[i].indexOf("__JPHvq5gsbT0nuFotaqq") != -1){
          var certificationDoc = findDocument(arrto[i]);
          var sqljudge = "select id from obpm2.tenant_user_credential_details where id = REPLACE( '"+arrto[i]+"','__JPHvq5gsbT0nuFotaqq','__jlNfVcjppSliMYH6FkJ')";
          var datasjudge = queryByDSName("tms",sqljudge);
          println("sqljudge--------------"+sqljudge);
          if(datasjudge!="[]"){
            var sqlup = "update tlk_certification set item_synchronize = '1' where id = '"+arrto[i]+"' order by created desc limit 1";
            println("sqlup---------"+sqlup);
            updateByDSName("tms",sqlup); 
            continue;
          }
          var docid=certificationDoc.getId();
          var securityId = certificationDoc.findItem("securityId").getValue();
          var personid = certificationDoc.findItem("personid").getValue();
          var areacode = "";
          if(personid != ''){
            var sqlqq = "select item_areacode from tlk_qualify_person_apply where id = '"+personid+"'";
            var datasqq = queryByDSName("tms",sqlqq);
            if(datasqq!=null){
              for(var iterator = datasqq.iterator();iterator.hasNext();){
                var map1 = iterator.next();//取值
                areacode= map1.get("item_areacode");
                println("areacode----------------"+areacode)
              }
            }
          }
          var confirmDate = certificationDoc.findItem("certificateDate").getValue();
          var validdateto = "9999-12-31";
          println("confirmDate---------------->"+confirmDate)
          var boolean1 = true;
          if(confirmDate==""||!isNotNull(confirmDate)){
            boolean1 = false;
            println("confirmDate---------------->2"+confirmDate)
          }
          var cultivateCompany = certificationDoc.findItem("cultivateCompany").getValue();//培训公司名称
          var CompanyNameToGet = certificationDoc.findItem("CompanyNameToGet").getValue();//保安公司名称
          var cultivateCompanyCode = certificationDoc.findItem("cultivateCompanyCode").getValue();//培训公司id
          var CompanyNameToGetCode = certificationDoc.findItem("CompanyNameToGetCode").getValue();//保安公司id
          var sqlp = "SELECT tk.domainid,dl.ITEM_REGIONId FROM organizationauth.tlk_DepartmentLevel dl JOIN baibaodunflow.tlk_SetSupervise tk ON dl.id = tk.item_registerPoliceAddressID WHERE tk.domainid IN ('"+CompanyNameToGetCode+"')"
          println("sqlp---------------"+sqlp)
          if("".equals(areacode) || !isNotNull(areacode)){
            var datasp = queryByDSName("tms",sqlp);
            if(datasp!=null){
              for(var iterator = datasp.iterator();iterator.hasNext();){
                var map1 = iterator.next();//取值
                areacode= map1.get("ITEM_REGIONId");
                println("areacode----------------"+areacode)
              }
            }
          }
          if(isNotNull(areacode)){
            var areacode2 = areacode.substr(0,2);
            println("areacode2------------------"+areacode)
            if("64".equals(areacode2)){
  
            }
          }
          var certificateFrom = certificationDoc.findItem("certificateFrom").getValue();
          var name = certificationDoc.findItem("name").getValue();
          var certificateType = certificationDoc.findItem("certificateType").getValue();
          var certificateNO = certificationDoc.findItem("certificateNO").getValue();
          var idCardNo = certificationDoc.findItem("idCardNo").getValue();
          var oneInchPhoto = certificationDoc.findItem("oneInchPhoto").getValue();
          var TRAININGENDTIME = ""
          var idg = ""
          var userSql = "select tenant_user_id from obpm2.tenant_employees where id = '"+securityId+"'";
          var datasuser = queryByDSName("obpm2", userSql);
          if (datasuser.size() > 0) {
            for (var iteratoruser = datasuser.iterator(); iteratoruser.hasNext();) {
              var map1 = iteratoruser.next();//取值
              var tenant_user_id = map1.get("tenant_user_id");
            }
          }
          var types="";
          var types2 = "";
          Packages.java.lang.System.err.println("================tenant_user_id================="+tenant_user_id);
          if(isNotNull(tenant_user_id)){
            var insertsql=''
            var insertsql2=''
            if('1'.equals(certificateType) || '11'.equals(certificateType)){
              if('1'.equals(certificateType)){
                types="7";
              }else{
                types="11";
              }
              if('1'.equals(certificateType)){
                types2="1";
              }else{
                types2="11";
              }
              if(boolean1){
                //insertsql="insert into tenant_user_credentials (created_time,name,selected,id,tenant_user_id,credential_type,number,valid_date_from,valid_date_to,address) values('"+confirmDate+"','"+name+"','0', REPLACE ( '"+docid+"', '__JPHvq5gsbT0nuFotaqq', '__jlNfVcjppSliMYH6FkJ' ),'"+tenant_user_id+"','"+types+"','"+certificateNO+"','"+confirmDate+"','"+validdateto+"','"+certificateFrom+"')"
                insertsql2="INSERT INTO tenant_user_credential_details (areacode,create_time,certificateType,id, xm, active, idnum, zsbh, fzrq, fzjgmc, state,appraisalGrade,tenant_user_id,trainId,trainName,companyId,companyName) VALUES ('"+areacode+"', '"+confirmDate+"','"+types2+"', REPLACE ( '"+docid+"', '__JPHvq5gsbT0nuFotaqq', '__jlNfVcjppSliMYH6FkJ' ), '"+name+"', '1' , '"+idCardNo+"','"+certificateNO+"','"+confirmDate+"', '"+certificateFrom+"', '1','','"+tenant_user_id+"','"+cultivateCompanyCode+"','"+cultivateCompany+"','"+CompanyNameToGetCode+"','"+CompanyNameToGet+"' )"
              }else{
                //insertsql="insert into tenant_user_credentials (created_time,name,selected,id,tenant_user_id,credential_type,number,valid_date_to,address) values(now(),'"+name+"','0', REPLACE ( '"+docid+"', '__JPHvq5gsbT0nuFotaqq', '__jlNfVcjppSliMYH6FkJ' ),'"+tenant_user_id+"','"+types+"','"+certificateNO+"','"+validdateto+"','"+certificateFrom+"')"
                insertsql2="INSERT INTO tenant_user_credential_details (areacode,create_time,certificateType,id, xm, active, idnum, zsbh, fzjgmc, state,appraisalGrade,tenant_user_id,trainId,trainName,companyId,companyName) VALUES ('"+areacode+"',now(),'"+types2+"', REPLACE ( '"+docid+"', '__JPHvq5gsbT0nuFotaqq', '__jlNfVcjppSliMYH6FkJ' ), '"+name+"', '1' , '"+idCardNo+"','"+certificateNO+"', '"+certificateFrom+"', '1','','"+tenant_user_id+"','"+cultivateCompanyCode+"','"+cultivateCompany+"','"+CompanyNameToGetCode+"','"+CompanyNameToGet+"' )"
              }            
            }else{
              var sqlv="select id from tlk_level_class_student  where item_idcardno = '"+idCardNo+"'  "
              println("sqlv----------->"+sqlv);
              var datasv = queryByDSName("tms", sqlv);
              if (datasv.size() > 0) {
                for (var iterator = datasv.iterator(); iterator.hasNext();) {
                  var map1 = iterator.next();//取值
                  var idg = map1.get("id");
                  println("idg----------->"+idg);
                }
              }
              if(isNotNull(idg)){
                var sqlg = "select a.ITEM_TRAININGENDTIME from tlk_grade_card_class a left join tlk_level_class_student b on a.id = b.item_classid where b.id = '"+idg+"'"
                var datasg = queryByDSName("tms", sqlg);
                if (datasg.size() > 0) {
                  for (var iterator = datasg.iterator(); iterator.hasNext();) {
                    var map1 = iterator.next();//取值
                    var item_trainningendtime = map1.get("ITEM_TRAININGENDTIME");
                    println("item_trainningendtime----------->"+item_trainningendtime);
                  }
                }
              }
              types="9";
              types2 = "3"
              //insertsql="insert into tenant_user_credentials (created_time,name,selected,id,tenant_user_id,credential_type,number,valid_date_to,valid_date_from,address) values('"+confirmDate+"','"+name+"','0',REPLACE ( '"+docid+"', '__JPHvq5gsbT0nuFotaqq', '__jlNfVcjppSliMYH6FkJ' ),'"+tenant_user_id+"','"+types+"','"+certificateNO+"','9999-12-31','"+item_trainningendtime+"','"+certificateFrom+"')"
              insertsql2="INSERT INTO tenant_user_credential_details (areacode,create_time, certificateType,id, xm, active, idnum, zsbh, fzrq, fzjgmc, state,appraisalGrade,tenant_user_id,trainId,trainName,companyId,companyName) VALUES ('110000', '"+confirmDate+"','"+types2+"', REPLACE ( '"+docid+"', '__JPHvq5gsbT0nuFotaqq', '__jlNfVcjppSliMYH6FkJ' ), '"+name+"', '1' , '"+idCardNo+"','"+certificateNO+"','"+confirmDate+"', '"+certificateFrom+"', '1','5','"+tenant_user_id+"','"+cultivateCompanyCode+"','"+cultivateCompany+"','"+CompanyNameToGetCode+"','"+CompanyNameToGet+"' )"
              println("----------------------------------------------------------------------------"+insertsql)
            }
            println("insertsql--------------------"+insertsql);
            println("insertsql2---------------------"+insertsql2);
            //insertByDSName("obpm2",insertsql);
            insertByDSName("obpm2",insertsql2);
            println("进来插入语句----------->"+insertsql);
            Packages.java.lang.System.err.println("================进来插入语句================="+insertsql);
            var certificationDoc = findDocument(arrto[i]);
            var sqlu = "update tms.tlk_certification set item_synchronize = '1' where id = '"+arrto[i]+"'";
            updateByDSName("tms",sqlu);
            println("----------->"+certificationDoc);
            Packages.java.lang.System.err.println("================certificationDoc================="+certificationDoc);
          }else{
            var sqlu = "update tms.tlk_certification set item_synchronize = '1' where id = '"+arrto[i]+"'";
            updateByDSName("tms",sqlu);
            Packages.java.lang.System.err.println("==================进else==============="+certificationDoc);
          }
        }
      } 
    }
    Packages.java.lang.System.err.println("================证书同步至智能人事结束=================");
  })()]]></taskScript>
  <modifyTime>2023-08-01T09:44:09.000+08:00</modifyTime>
  <creator>Admin</creator>
  <creatorid>Ai6hllhNjS2ull9TKGb</creatorid>
  <totalRuntimes>0</totalRuntimes>
  <state>0</state>
  <startupType>1</startupType>
  <dayOfMonth>1</dayOfMonth>
  <repeatTimes>0</repeatTimes>
  <frequency>0</frequency>
  <executedCount>0</executedCount>
  <rDate></rDate>
  <rTime>00:00:00</rTime>
</task>