<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__TwA5PAZIf51ob8O4opB">
  <name>确认成绩</name>
  <parentId>__9hkv8xD76wz3NBM39ER</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <type>13</type>
  <onActionFlow></onActionFlow>
  <onActionPrint></onActionPrint>
  <colorType>default</colorType>
  <beforeActionScript><![CDATA[//判断表单某字段不能为空
(function(){
 // Packages.java.lang.System.err.println("================等级证确认成绩动作前=================");
var classPersonName = getItemValueAsString("classPersonName"); 
if("".equals(classPersonName)) {
    return "请选择人员！";
}
})()
]]></beforeActionScript>
  <afterActionScript><![CDATA[#include "sysfunction";
(function(){
  //Packages.java.lang.System.err.println("================等级证确认成绩动作后=================");
  var classId = getItemValueAsString("classId");//班级id
  var errorStr = "";
  var now = getToday();
  //var CurrentTime=format(now,"yyyy-MM-dd HH");//当前时间 格式化为月份
  var CurrentTime=format(now,"yyyy-MM");//当前时间 格式化为月份
  var NOW1 = format(now,"yyyy-MM-dd HH:mm:ss");
  println("NOW-----------------"+NOW1);
  var formservice = getFormProcess();
  var CID="";
  var PID="";
  var classPersonId = getItemValueAsString("classPersonId"); //学员id
  println("classPersonId"+classPersonId)
  var arrto = splitText(classPersonId,";"); 
  var process = getDocumentProcess();
  for(var i=0;i<arrto.length;i++){
    var boolean1 = true;
    //  Packages.java.lang.System.err.println("================arrto[i]================="+arrto[i]);
    var examPersonInfoDoc = findDocument(arrto[i]);
    var scoreState = examPersonInfoDoc.findItem("scoreState").getValue(); 
    println("ggggggggggggggggg-------------"+scoreState)
    if("1".equals(scoreState)){
      boolean1 = false;
    }
    if(boolean1){
      //Packages.java.lang.System.err.println("===============examPersonInfoDoc================="+examPersonInfoDoc);
      var graduationTestResults = examPersonInfoDoc.findItem("graduationTestResults").getValue();
      println("graduationTestResults------------------------->"+graduationTestResults)
      var identificationTestResults = examPersonInfoDoc.findItem("identificationTestResults").getValue();
      var idCardNo = examPersonInfoDoc.findItem("idCardNo").getValue();
      var applyId = examPersonInfoDoc.findItem("applyId").getValue(); 
      var applyInfoDoc = findDocument(applyId);
      var learnid = applyInfoDoc.findItem("learnid").getValue(); 
      var trainid = applyInfoDoc.findItem("trainid").getValue(); 
      var orderId = applyInfoDoc.findItem("orderId").getValue(); 
      var learnName = applyInfoDoc.findItem("learnname").getValue(); 
      var trainName = applyInfoDoc.findItem("trainName").getValue(); 
      if(isNotNull(orderId)){
        var orderInfoDoc = findDocument(orderId);
        var biaoshi1 = orderInfoDoc.findItem("biaoshi1").getValue();
        var biaoshi2 = orderInfoDoc.findItem("biaoshi2").getValue();
        var trainSelectId = trainid;
        var conName = learnName	;
        var domainid = learnid;
        var peixunName = trainName;
        var Form_settlement = orderInfoDoc.findItem("Form_settlement").getValue();
        var form_p_settlement = orderInfoDoc.findItem("form_p_settlement").getValue();
        var f1 = orderInfoDoc.findItem("Form_settlement").getValue();
        var f2 = orderInfoDoc.findItem("form_p_settlement").getValue();
        println("f1--------------"+f1);
        println("f2--------------"+f2);
        //需要创建两张表的数据已创建培训公司的id作为业务id ,要考虑自然人情况（同一家公司）(item_my_domainID存储的是当前缴费的公司，item_peixunID存储的缴费的培训公司)
        var slq=" select ID from tlk_training_table where item_peixunID='"+trainSelectId+"'and date_format(created,'%Y-%m')='"+CurrentTime+"' "  ;//or (item_my_domainID='"+domainid+"' and   item_companyID='__iZjB3As6MOfttXkZTXo' and date_format(created,'%Y-%m')='"+CurrentTime+"')
        //var slq=" select ID from tlk_training_table where item_peixunID='"+trainSelectId+"'and date_format(created,'%Y-%m-%d %H')='"+CurrentTime+"' "  ;
        println("slq--------------------------->"+slq);
        var datas6 = queryByDSName("tms",slq);
        println("datas6--------------------------->"+datas6);
        if(datas6=="[]"){//无数据的时候 新建 
          println("进到创建数据了？？？？？？？")
          println("公司是同一个不会创建保安和培训数据 这边直接走创建平台数据"); 
          //创建培训公司和平台之间的数据
          //意味着收票方是自己 即使保安公司也是培训机构 开票方是平台  
          var bcxInfo = formservice.doView("__sveeIxudIagr9knJk12");//
          println("bcxInfo"+bcxInfo);
          println("formservice"+formservice);
          var bcxInfoDoc = process.doNew(bcxInfo, getWebUser(), createParamsTable());
          println("2");
          bcxInfoDoc.addStringItem("my_domainID", domainid);//当前组织域id
          bcxInfoDoc.addStringItem("my_domainName", conName);//当前企业域名称
          bcxInfoDoc.addStringItem("K_trueStatus", "1");//开票方确认状态
          bcxInfoDoc.addStringItem("S_Status", "1");//收票方确认状态
          bcxInfoDoc.addStringItem("Kai_type", "1");//开票状态 
          bcxInfoDoc.addStringItem("type", "1");// 我方应收？？（只能去sql 判断）
          bcxInfoDoc.addStringItem("platformid", "__iZjB3As6MOfttXkZTXo");// 平台id
          bcxInfoDoc.addStringItem("platform", "1"); //平台类型
          bcxInfoDoc.addStringItem("companyID","__iZjB3As6MOfttXkZTXo" );//开票方当前平台
          bcxInfoDoc.addStringItem("companyName","百川信（北京）信息服务有限公司");//开票方当前平台
          bcxInfoDoc.addStringItem("peixunName", peixunName);////收票方是培训机构
          bcxInfoDoc.addStringItem("peixunID",trainSelectId );//收票方是培训机构
          //bcxInfoDoc.addStringItem("companytype", companytype);//保安公司类型
          //bcxInfoDoc.addStringItem("traintype", traintype);// 培训公司类型
          bcxInfoDoc.addStringItem("isTrue", "1");//开起平台收费
          bcxInfoDoc.addStringItem("money", "10");//平台收取费用
          println("form_p_settlement------------------不是2吗？？？"+form_p_settlement);
          if("2".equals(form_p_settlement)){ 
            bcxInfoDoc.addStringItem("biaoshi", "1");//平台收取费用
          }
          println(bcxInfoDoc);

          //  Packages.java.lang.System.err.println("===============到这里了吗111=================");
          //这条数据的id 将来用做业务id
          if(("1".equals(Form_settlement)&&"2".equals(form_p_settlement)) || ("2".equals(Form_settlement)&&"1".equals(form_p_settlement))){
            var slqp=" select ID from tlk_training_table where item_peixunID='"+trainSelectId+"'"  ;
            println("slqp--------------------------->"+slqp);
            var datas99 = queryByDSName("tms",slqp);
            println("datas99--------------------------->"+datas99);
            if(datas99!="[]"){
              process.doCreate(bcxInfoDoc);
              var PID1 = orderInfoDoc.findItem("PID").getValue();
              var PID2=bcxInfoDoc.getId();
              PID = PID1+";"+PID2;
            }else{
              process.doCreate(bcxInfoDoc);
              PID=bcxInfoDoc.getId();
            }

          }/*else if("2".equals(Form_settlement)&&"1".equals(form_p_settlement)){
          var slqp=" select ID from tlk_training_table where item_peixunID='"+trainSelectId+"'"  ;
          println("slqp--------------------------->"+slqp);
          var datas99 = queryByDSName("tms",slqp);
          println("datas99--------------------------->"+datas99);
          if(datas99!="[]"){
            process.doCreate(bcxInfoDoc);
            var PID1 = orderInfoDoc.findItem("PID").getValue();
            var PID2=bcxInfoDoc.getId();
            PID = PID2+";"+PID1;
          }else{
            process.doCreate(bcxInfoDoc);
            PID=bcxInfoDoc.getId();
          }

        }*/else{
          process.doCreate(bcxInfoDoc);
          PID=bcxInfoDoc.getId();
        }
        }else{//表示查到了数据,业务id,是肯定存在的也就是PID,学员那边cid可能会没有就是null,
          //var sql6 = "update tlk_training_table set item_biaoshi = '1' where item_peixunid = '"+trainid+"'  "
          //var sql6 = "update tlk_training_table set item_biaoshi = '1' where item_peixunid = '"+trainid+"' and date_format(created,'%Y-%m-%d %H')='"+CurrentTime+"' "
          var sql6 = "update tlk_training_table set item_biaoshi = '1' where item_peixunid = '"+trainid+"' and date_format(created,'%Y-%m')='"+CurrentTime+"' "
          updateByDSName("tms",sql6);
          /*if("1".equals(form_p_settlement)){
          var slqq=" update tlk_training_table set item_biaoshi = '1' where item_peixunID='"+trainSelectId+"'and date_format(created,'%Y-%m-%d %H')='"+CurrentTime+"' "
          println("slqq-------------------"+slqq)
          updateByDSName("tms",slqq);
        }*/
          println("表示查到了数据")
          var iterator = datas6.iterator();
          if(iterator.hasNext()){
            var map3 = iterator.next();
            PID= map3.get("ID");
          }
        }
        //   Packages.java.lang.System.err.println("===============到这里了吗111=================");
        var sql2="select ID from tlk_Reconciliation_table where item_my_domainID='"+domainid+"' and item_companyID='"+trainSelectId+"' and date_format(created,'%Y-%m')='"+CurrentTime+"' "
        //var sql2="select ID from tlk_Reconciliation_table where item_my_domainID='"+domainid+"' and item_companyID='"+trainSelectId+"' and date_format(created,'%Y-%m-%d %H')='"+CurrentTime+"' "
        var datas7 = queryByDSName("tms",sql2);
        println("datas7--------------------------->"+datas7);
        if(datas7=="[]"){
          if(!domainid.equals(trainSelectId)){
            println("公司不是同一个");
            //创建保安公司和培训公司的数据
            var comInfo = formservice.doView("__id1XYDTMK5gXL4wCigC");
            var comInfoDoc = process.doNew(comInfo, getWebUser(), createParamsTable());
            comInfoDoc.addStringItem("my_domainID", domainid);//当前组织域id
            comInfoDoc.addStringItem("my_domainName", conName);//当前企业域名称
            comInfoDoc.addStringItem("K_trueStatus", "1");//开票方确认状态
            comInfoDoc.addStringItem("S_Status", "1");//收票方确认状态
            comInfoDoc.addStringItem("Kai_type", "1");//开票状态 
            comInfoDoc.addStringItem("type", "1");// 我方应收？？（只能去sql 判断）
            comInfoDoc.addStringItem("platformid", "__iZjB3As6MOfttXkZTXo");// 平台id
            comInfoDoc.addStringItem("platform", "1"); //平台类型
            comInfoDoc.addStringItem("companyID", trainSelectId);//开票方当前培训机构的企业域id
            comInfoDoc.addStringItem("companyName", peixunName);//开票方当前培训机构的企业域名称
            comInfoDoc.addStringItem("peixunName",conName );//收票方当前企业域名称
            comInfoDoc.addStringItem("peixunID", domainid);//收票方当前企业域id
            //comInfoDoc.addStringItem("companytype", companytype);//保安公司类型
            //comInfoDoc.addStringItem("traintype", traintype);// 培训公司类型
            comInfoDoc.addStringItem("isTrue", "0");//关闭平台收费
            comInfoDoc.addStringItem("b_Business_id",PID);//加一个培训表与平台的id
            println("Form_settlement------------------不是2吗？？？"+Form_settlement);
            if("2".equals(Form_settlement)){ 
              comInfoDoc.addStringItem("biaoshi", "1");
            }
            //      Packages.java.lang.System.err.println("===============到这里了吗222=================");
            println(comInfoDoc);
            if(("1".equals(Form_settlement)&&"2".equals(form_p_settlement)) || ("2".equals(Form_settlement)&&"1".equals(form_p_settlement))){
              var sqlp="select ID from tlk_Reconciliation_table where item_my_domainID='"+domainid+"' and item_companyID='"+trainSelectId+"'  "
              println("sqlp--------------------------->"+sqlp);
              var datas99 = queryByDSName("tms",sqlp);
              println("datas99--------------------------->"+datas99);
              if(datas99!="[]"){
                var CID1 = orderInfoDoc.findItem("com_id").getValue();
                process.doCreate(comInfoDoc);
                var CID2=comInfoDoc.getId()
                CID = CID1+";"+CID2;
              }else{
                process.doCreate(comInfoDoc);
                CID=comInfoDoc.getId()
              }

            }/*else if("2".equals(Form_settlement)&&"1".equals(form_p_settlement)){
            var sqlp="select ID from tlk_Reconciliation_table where item_my_domainID='"+domainid+"' and item_companyID='"+trainSelectId+"'  "
            println("sqlp--------------------------->"+sqlp);
            var datas99 = queryByDSName("tms",sqlp);
            println("datas99--------------------------->"+datas99);
            if(datas99!="[]"){
              var CID1 = orderInfoDoc.findItem("com_id").getValue();
              process.doCreate(comInfoDoc);
              var CID2=comInfoDoc.getId()
              CID = CID2+";"+CID1;
            }else{
              process.doCreate(comInfoDoc);
              CID=comInfoDoc.getId()
            }

          }*/else{
            process.doCreate(comInfoDoc);
            CID=comInfoDoc.getId()
          }
          }
        }else{
          //var sql5 = "update tlk_reconciliation_table set item_biaoshi = '1' where item_peixunid = '"+learnid+"' and item_companyid = '"+trainid+"' "
          //var sql5 = "update tlk_reconciliation_table set item_biaoshi = '1' where item_peixunid = '"+learnid+"' and item_companyid = '"+trainid+"' and date_format(created,'%Y-%m-%d %H')='"+CurrentTime+"'"
          var sql5 = "update tlk_reconciliation_table set item_biaoshi = '1' where item_peixunid = '"+learnid+"' and item_companyid = '"+trainid+"' and date_format(created,'%Y-%m')='"+CurrentTime+"'"
          updateByDSName("tms",sql5);

          /* if("1".equals(Form_settlement)){ 
          var slqq=" update tlk_Reconciliation_table set item_biaoshi = '1'  where item_my_domainID='"+domainid+"' and item_companyID='"+trainSelectId+"' and date_format(created,'%Y-%m-%d %H')='"+CurrentTime+"' "
          updateByDSName("tms",slqq);
        }*/
          //    Packages.java.lang.System.err.println("===============到这里了吗333=================");
          println("表示查到了数据")
          var iterator4 = datas7.iterator();
          if(iterator4.hasNext()){
            var map4 = iterator4.next();
            CID= map4.get("ID");
          }
        }
        //     Packages.java.lang.System.err.println("===============到这里了吗444=================");
        orderInfoDoc.findItem("confirmdate").setValue(NOW1);
        orderInfoDoc.findItem("com_ID").setValue(CID);
        orderInfoDoc.findItem("PID").setValue(PID);
        if("1".equals(f1) && "2".equals(f2)){
          println("进1~~~~~~~~~~~~~~~~~~~~")
          orderInfoDoc.findItem("PAYMENT_MARK").setValue("新购1");
        }else if("2".equals(f1) && "1".equals(f2)){
          println("进2~~~~~~~~~~~~~~~~~~~~")
          orderInfoDoc.findItem("PAYMENT_MARK").setValue("新购2");
        }else if("2".equals(f1) && "2".equals(f2)){
          println("进3~~~~~~~~~~~~~~~~~~~~")
          orderInfoDoc.findItem("PAYMENT_MARK").setValue("新购3");
        }
        if(!"1".equals(biaoshi1)){
          orderInfoDoc.findItem("biaoshi1").setValue("1");
        }
        if(!"1".equals(biaoshi2)){
          orderInfoDoc.findItem("biaoshi2").setValue("1");
        }
        process.doUpdate(orderInfoDoc);
      }
      //    Packages.java.lang.System.err.println("===============到这里了吗555=================");

      println("------------------------->"+applyId)
      println("------------------------->"+graduationTestResults)
      println("------------------------->"+identificationTestResults)
      var sqll = "select item_authlessonid from tlk_lesson_auth_base_info where item_authRecordId = '"+applyId+"'";
      var authlessonid = '';
      var datas = queryByDSName("tms",sqll);
      if(datas!=null){
        for(var iterator = datas.iterator();iterator.hasNext();){
          var map1 = iterator.next();//取值
          authlessonid = map1.get("item_authlessonid");
        }
      }

      if("1".equals(graduationTestResults)){
        examPersonInfoDoc.findItem("cardState").setValue("2"); 
      }//否则还是初始化的制证状态
      var day = format(getToday(),"yyyy-MM-dd HH:mm:ss"); 
      var now22 = getToday();
      var NOW22 = format(now22,"yyyy-MM-dd HH:mm:ss");
      println("NOW22222222222222222222222"+NOW22)
      examPersonInfoDoc.findItem("scoreState").setValue("1");//表示成绩已确认 
      examPersonInfoDoc.findItem("confirmdate").setValue(NOW22)

      var sql = "select "+
          "'"+getDomainid()+"' as DOMAINID,"+
          "ID,"+ //用户ID
          "ID as item_ID,"+
          "NAME as item_name," + 
          "FIELD11 as item_ID_TYPE," + //证件类型
          "FIELD12 as item_ID_NUMBER," + //证件号码
          "LOGINNO as item_telephone," + //手机号
          "FIELD13 as item_CERTIFICATIONSTATUS" + //实名状态
          " from " +sysfunction.DS_OBPM+".t_user"+
          " where ID='"+getWebUser().getId()+"'";
      var datart = findBySQL(sql);
      var operatorname = datart.getItemValueAsString("name")
      examPersonInfoDoc.findItem("confirmoperator").setValue(operatorname);
      process.doUpdate(examPersonInfoDoc);  
      //    Packages.java.lang.System.err.println("===============到这里了吗666=================");
      if("1".equals(graduationTestResults) && "1".equals(identificationTestResults)){
        /*var deleteSql = "delete from tlk_lesson_auth_base_info where item_authRecordId='"+applyId+"'";
          deleteByDSName("tms",deleteSql);*/
        //var updateSql = "update tlk_lesson_auth_base_info set item_isdelete='1' ,item_isProgress='1' where item_authRecordId='"+applyId+"'"
        //updateByDSName("tms",updateSql);	
        applyInfoDoc.findItem("applystatus").setValue("1");
        process.doUpdate(applyInfoDoc);
        println("更新为申报通过")
      }else if(("2".equals(identificationTestResults) && "1".equals(graduationTestResults)) || "2".equals(graduationTestResults)){
        /*var deleteSql = "delete from tlk_lesson_auth_base_info where item_authRecordId='"+applyId+"'";
          deleteByDSName("tms",deleteSql);*/
        //var updateSql = "update tlk_lesson_auth_base_info set item_isdelete='1' ,item_isProgress='0' where item_authRecordId='"+applyId+"'"
        //updateByDSName("tms",updateSql);	
        var updateSql = "update tlk_lesson_auth_base_info set item_isdelete='1',item_isProgress='0' where item_authuserid='"+idCardNo+"' and item_authlessonid = '"+authlessonid+"'"
        updateByDSName("tms",updateSql);
        var updateSql2 = "update tlk_sectioninfo set item_isStudy = '1' where ITEM_NEW_IDCARD = '"+idCardNo+"'"
        updateByDSName("tms",updateSql2);	
        var updateSql3 = "update tlk_grade_internship set item_isdelete = '1' where item_idcardno = '"+idCardNo+"'"
        updateByDSName("tms",updateSql3);	
        applyInfoDoc.findItem("applystatus").setValue("2");
        process.doUpdate(applyInfoDoc);
        println("更新为申报不通过")
      }
    }
  }
  //  Packages.java.lang.System.err.println("===============确认成绩结束=================");

})()]]></afterActionScript>
  <retractBeforeActionScript><![CDATA[]]></retractBeforeActionScript>
  <retractAfterActionScript><![CDATA[]]></retractAfterActionScript>
  <hiddenScript><![CDATA[]]></hiddenScript>
  <readonlyScript><![CDATA[]]></readonlyScript>
  <startFlowScript><![CDATA[]]></startFlowScript>
  <editMode>0</editMode>
  <fileNameScript><![CDATA[]]></fileNameScript>
  <iconurl></iconurl>
  <orderno>0</orderno>
  <stateToShow></stateToShow>
  <parentForm>__9hkv8xD76wz3NBM39ER</parentForm>
  <jumpType>0</jumpType>
  <expSub>false</expSub>
  <icon></icon>
  <disableFlowNode>false</disableFlowNode>
  <changeFlowOperator>false</changeFlowOperator>
  <changeFlowCc>false</changeFlowCc>
  <multiLanguageLabel></multiLanguageLabel>
  <dispatcherMode>0</dispatcherMode>
  <dispatcherUrl><![CDATA[]]></dispatcherUrl>
  <dispatcherParams><![CDATA[[{"paramKey":"","paramValue":""}]]]></dispatcherParams>
  <jumpMode>0</jumpMode>
  <jumpActOpenType>0</jumpActOpenType>
  <withOld>false</withOld>
  <actionType>2</actionType>
  <actionDispatcherUrlScript><![CDATA[]]></actionDispatcherUrlScript>
  <actionSelection>0</actionSelection>
  <relatedFormId></relatedFormId>
  <actionScript><![CDATA[]]></actionScript>
  <workFlowType>0</workFlowType>
  <contextMenu>false</contextMenu>
  <showInToolbar>true</showInToolbar>
  <transpond></transpond>
  <targetList>|</targetList>
  <label><![CDATA[]]></label>
</activity>