<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__evvajYdBpgtx36wkvHm">
  <name>确认添加</name>
  <parentId>__pLqUgEuQ9xbehc5ESIH</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <type>13</type>
  <onActionFlow></onActionFlow>
  <onActionPrint></onActionPrint>
  <colorType>default</colorType>
  <beforeActionScript><![CDATA[//判断表单某字段不能为空
(function(){
  var uuid = getItemValueAsString("uuid")
  var sqlone="insert into tlk_Constrain (id,CREATED) values('"+uuid+"','"+format(getToday(),"yyyy-MM-dd HH:mm:ss")+"')";
  println(sqlone);
  try{
    insertByDSName("tms",sqlone);
  }catch(e){
    return "请勿重复提交"

  }
  var zw2 = 1;
  var examId= getItemValueAsString("examId"); 
  var examPersonName = getItemValueAsString("examPersonName"); 
  var personNumber = getItemValueAsString("personNumber"); 
  var msg="";
  var msg2 = "";
  var msgid = "";
  var msgid2 = "";

  if("".equals(examPersonName)) {
    return "请选择人员！";
  }
  var examPersonId = getItemValueAsString("examPersonId");
  var arrto = splitText(examPersonId,";");
  var length = arrto.length
  if(length>100){
    return "最多一次性添加100人！"
  }
  var sql="select COUNT(id) as num from tlk_system_exam_person where ITEM_examid='"+examId+"'";
  println(sql);
  var datas = queryByDSName("tms",sql);
  if(datas.size()>0){
    for(var iterator = datas.iterator();iterator.hasNext();){
      var map1 = iterator.next();//取值
      var num= map1.get("num");          
    } 
  }
  if(isNotNull(personNumber)&&(arrto.length)+parseInt(num)>parseInt(personNumber)){
    return "人数超过考场限制！"
  }else{
    for(var i=0;i<arrto.length;i++){
      var applyId = arrto[i];
      var applyInfoDoc = findDocument(applyId);
      var sqlExam="select * from tlk_system_exam_person where item_applyId='"+applyId+"'"
      var datas = queryByDSName("tms",sqlExam);
      if(datas.size()>0){
        var examNum = applyInfoDoc.findItem("examNum").getValue();
        var name = applyInfoDoc.findItem("name").getValue()
        var value=parseDouble(examNum)+1;
        if(value>1){
          msg+=name+"；"
          msgid += applyId+";"
        }
      }
      var sqlgg = "select item_name from tlk_apply_person_refund where item_applyid='"+applyId+"' and item_refundState = '0'";
      var datas = queryByDSName("tms",sqlgg);
      if(!"[]".equals(datas)){
        for(var iterator = datas.iterator();iterator.hasNext();){
          var map1 = iterator.next();//取值
          var name= map1.get("item_name");
          msg2+=name;
          msg2+=";";
          if(msgid.indexOf(applyId)!='-1'){
          }else{
            msgid += applyId+";"
          }
        }
      }
    }
  }

  var doc=getCurrentDocument();
  var examPersonId = doc.getItemValueAsString("examPersonId");
  var zw = 1;
  var examId= getItemValueAsString("examId"); 
  var idarr = splitText(msgid,";"); 
  for(var i=0;i<idarr.length;i++){
    examPersonId = examPersonId.replace(idarr[i],"");
  }
  var arrto = splitText(examPersonId,";"); 
  var process = getDocumentProcess();            
  var formProcess = getFormProcess();   
  var appId=getApplication();
  var appName = "考试管理";
  var subform = formProcess.doView("__2i8jAJxf4DjUsB0szBf");//表单id   

  if(examPersonId != ''){
    for(var i=0;i<arrto.length;i++){
      zw = zw2
      var applyId = arrto[i];
      println("当前applyId--》"+applyId)
      var applyInfoDoc = findDocument(applyId);
      var sqlExam="select * from tlk_system_exam_person where item_applyId='"+applyId+"'"
      var datas = queryByDSName("tms",sqlExam);
      while(true){
        var sql1="select id from tlk_system_exam_person where ITEM_examid='"+examId+"' and item_zw = '"+zw+"'";
        var datas1 = queryByDSName("tms",sql1);
        if(datas1 == null || datas1.size() == 0){     
          zw2 = zw+1
          break;
        }
        zw += 1;
      }
      if(datas.size()>0){//应该是补考
        println("进入补考，报名id"+applyId)
        var sqlUp="update tlk_system_exam_person set item_isDelete='1' where item_applyId='"+applyId+"'";
        updateByDSName("tms",sqlUp);
        var examNum = applyInfoDoc.findItem("examNum").getValue();
        var value=parseDouble(examNum)+1;
        applyInfoDoc.findItem("examNum").setValue(value);
        var doc = process.doNew(subform,getWebUser(),createParamsTable());   
        doc.addStringItem("securityId",applyInfoDoc.findItem("securityId").getValue());  
        doc.addStringItem("examId",examId);     
        doc.addStringItem("idCardNo",applyInfoDoc.findItem("idCardNo").getValue());     
        doc.addStringItem("name",applyInfoDoc.findItem("name").getValue()); 
        doc.addStringItem("company",applyInfoDoc.findItem("learnName").getValue()); 
        doc.addStringItem("mobile",applyInfoDoc.findItem("phone").getValue()); 
        doc.addStringItem("zw",zw); 
        applyInfoDoc.findItem("examId").setValue(examId);
        if(isNotNull(applyInfoDoc.findItem("writtenScore").getValue())){
          applyInfoDoc.findItem("writtenScore").setValue("0");
        }
        applyInfoDoc.findItem("operateScore").setValue("0");
        doc.addIntItem("writtenScore",0); 
        doc.addIntItem("operateScore",0); 
        doc.addIntItem("sumScore",0); 
        doc.addStringItem("testState","-"); 
        doc.addStringItem("noticeState","0"); 
        doc.addStringItem("scoreState","0"); 
        doc.addStringItem("cardState","0"); 
        doc.addStringItem("applyId",applyInfoDoc.getId()); 
        doc.addStringItem("writtenRecord","");  
        doc.addStringItem("writtenState","0");     
        doc.addStringItem("isMakeUp","2");     
        doc.addStringItem("signIn","0");     
        doc.addStringItem("confirmDate","");   
        process.doCreate(doc); 
      }else{
        println("进入正常安排，报名id"+applyId)
        var doc = process.doNew(subform,getWebUser(),createParamsTable()); 
        doc.addStringItem("securityId",applyInfoDoc.findItem("securityId").getValue());  
        doc.addStringItem("examId",examId);     
        doc.addStringItem("idCardNo",applyInfoDoc.findItem("idCardNo").getValue());     
        doc.addStringItem("name",applyInfoDoc.findItem("name").getValue()); 
        doc.addStringItem("company",applyInfoDoc.findItem("learnName").getValue()); 
        doc.addStringItem("mobile",applyInfoDoc.findItem("phone").getValue()); 
        applyInfoDoc.findItem("examId").setValue(examId);
        if(isNotNull(applyInfoDoc.findItem("writtenScore").getValue())){
          applyInfoDoc.findItem("writtenScore").setValue("0");
        }
        applyInfoDoc.findItem("operateScore").setValue("0");
        doc.addStringItem("zw",zw); 
        doc.addIntItem("writtenScore",0); 
        doc.addIntItem("operateScore",0); 
        doc.addIntItem("sumScore",0); 
        doc.addStringItem("testState","-"); 
        doc.addStringItem("noticeState","0"); 
        doc.addStringItem("scoreState","0"); 
        doc.addStringItem("cardState","0"); 
        doc.addStringItem("applyId",applyInfoDoc.getId()); 
        doc.addStringItem("writtenRecord","");  
        doc.addStringItem("writtenState","0");     
        doc.addStringItem("isMakeUp","0");     
        doc.addStringItem("signIn","0");     
        doc.addStringItem("confirmDate","");    
        //处理体检逻辑
        var examDoc=findDocument(examId);
        var taskId=""
        if("0".equals(applyInfoDoc.findItem("checkup_type").getValue())&&"0".equals(examDoc.findItem("examKind").getValue())){
          var orderId= applyInfoDoc.findItem("orderId").getValue()
          var orderDoc=findDocument(orderId);
          var checkupId= orderDoc.findItem("checkupId").getValue()
          var checkupProcess = getDocProcess('__1MmCqsHNrmMtmsitMcW');
          var checkup_time=examDoc.findItem("staminaStartDate").getValue()
          var checkup_address=examDoc.findItem("staminaAddress").getValue()
          var checkupformService = getFormProcess();
          var checkupsubform = checkupformService.doView("__2hdjwmNJyWcPn4RoxfL");
          var taskdoc = checkupProcess.doNew(checkupsubform,getWebUser(),createParamsTable());
          taskdoc.findItem("task_type").setValue('1');
          taskdoc.findItem("is_over").setValue('0');
          taskdoc.findItem("checkup_person_id").setValue(checkupId);
          taskdoc.findItem("checkup_time").setValue(checkup_time);
          taskdoc.findItem("checkup_address").setValue(checkup_address);
          taskdoc.findItem("checkup_seat").setValue(format(checkup_time,"yyyyMMddHHmm")+zw);
          checkupProcess.doCreate(taskdoc); 
          taskId=taskdoc.getId()
        }
        doc.addStringItem("taskId",taskId);  
        process.doCreate(doc); 
      }
      process.doUpdate(applyInfoDoc);
    }
  }else{
  }
  if(isNotNull(msg2)){
    msg2 = msg2.substring(0,msg2.length-1);
    return msg2+"以上人员已申请退款，请到退款审核，审核该记录！！"
  }
  if(isNotNull(msg)){
    return msg+"人员已经参加过补考了！！！";
  }
})()
]]></beforeActionScript>
  <afterActionScript><![CDATA[]]></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>1</orderno>
  <stateToShow></stateToShow>
  <parentForm>__pLqUgEuQ9xbehc5ESIH</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>__WHuwaHyEaMGmNS2ut1P|</targetList>
  <label><![CDATA[]]></label>
</activity>