<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__jcUkbCWjjh6I01YuDcW">
  <name>通知考试人员</name>
  <parentId>__AZNfvD3U2wD6bQ0FHbh</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <type>1</type>
  <onActionForm></onActionForm>
  <onActionView>__AZNfvD3U2wD6bQ0FHbh</onActionView>
  <colorType>info</colorType>
  <beforeActionScript><![CDATA[(function(){  
  var domainid = getDomainid();
  var sms = Packages.com.bcxin.saas.core.enums.MessageType.Sms;
  var Telephone= Packages.com.bcxin.saas.core.enums.ReceiverType.Telephone;
  var URLConnector = Packages.com.bcxin.saas.core.utils.HttpUtils;
  var rqs = Packages.java.util.ArrayList();
  var usid  =getWebUser().getId();
  var process = getDocumentProcess();
  var aid="";
  var ID="";
  var cid="";
  var appId=getApplication();
  var appName = "考试管理";
  var subject="您的参加的培训考试已安排，请及时参加！";
  println("SMS----------------->"+sms)//短信
  println("Telephone----------------->"+Telephone)//接收者手机号
  var accessToken =""//Security.getToken(getWebUser().getId());

  //获取勾选的对象 还得判断一下条件满不满足
  var selectId = getParameterAsText("_selects");//获取所选中数据的id结果集
  var msg = ""
  var arrto = splitText(selectId, ";"); //对这个结果集进行处理，以;进行切割，放到数组arrto
  if(arrto.length>0&&arrto.length<2){
    var docid=arrto[0];
    var sysinfo = findDocument(docid);
    var examState= sysinfo.findItem("examState").getValue();
    var examine = sysinfo.findItem("examine").getValue();
    var computerStartDate =sysinfo.findItem("computerStartDate").getValue();
    var month = computerStartDate.split(" ")[0].split("-")[1] + "月";
    var day = computerStartDate.split(" ")[0].split("-")[2] + "日";
    var hour = computerStartDate.split(" ")[1].split(":")[0] + ":";
    var minute = computerStartDate.split(" ")[1].split(":")[1];
    computerStartDate = month+day+hour+minute;
    var theoreticalAddress = sysinfo.findItem("theoreticalAddress").getValue();
    var person1 = sysinfo.findItem("person").getValue() ;//监考老师
    var person_phone=sysinfo.findItem("person_phone").getValue();//老师手机号
    var arrto55 = splitText(person1, ";");
    println("arrto55---------------------------------------------->"+ arrto55[0])
    if(arrto55.length>0){
      println("根据用户ID获取名称---------------------------------------------->"+ arrto55[0])
      //根据用户ID获取名称
      var userVO = getUserById(arrto55[0]);
      var person=userVO.getName()
      println("person---------------------------------------------->"+ person)
    }
    if("0".equals(examState)&&("1".equals(examine))) {
      Packages.java.lang.System.err.println("================站内信开始=================")
      println(examine+" 这个状态是可以进行确认操作的")
      println("docid==>" + docid);
      println("computerStartDate==>" + computerStartDate);
      println("theoreticalAddress==>" + theoreticalAddress);
      //取出在这场考试中未通知的人的身份证去做消息通知
      var sql = "select ID,ITEM_IDCARDNO,ITEM_APPLYID,ITEM_SECURITYID,ITEM_NAME from tlk_system_exam_person where ITEM_EXAMID='"+docid+"'and item_noticeState='0' ";
      println("sql==>" + sql);
      var datasss = queryByDSName("tms",sql);
      if(datasss!=null){ 
        for(var iterators = datasss.iterator();iterators.hasNext();) {
          var map2 = iterators.next();//取值
          var idCardNo= map2.get("ITEM_IDCARDNO");//身份证
          var APPLYID= map2.get("ITEM_APPLYID");//报名id
          var aid= map2.get("ITEM_SECURITYID");//保安员id
          ID=map2.get("ID");
          var name= map2.get("ITEM_NAME"); 
          println("idCardNo==>" + idCardNo);
          println("ID==>----------------------------------》12.18" + ID);
          var appinfo = findDocument(APPLYID);
          if(APPLYID!=null){
            println("进来？？？")
            var learnName= appinfo.findItem("LEARNNAME").getValue();
            var learnId= appinfo.findItem("LEARNID").getValue();//本企业id
            var trainId = appinfo.findItem("trainId").getValue();// 培训公司id
            var trainName = "";//培训公司
            var trainCompanyAbbSql = "select company_abbreviation abbName from tms.company_abbreviation where id = '" + trainId +"'";
            var iter = queryByDSName("tms",trainCompanyAbbSql).iterator();
            if(iter.hasNext()){
              trainName = iter.next().get("abbName");
            }else{
              trainName = appinfo.findItem("trainName").getValue();
            }
            var sql1 = "select ITEM_phone,item_cid from baibaodunflow.vw_employee where  ITEM_userID='"+aid+"'  ";
            var datas = queryByDSName("obpm2",sql1);
            println("sql1==>----------------------------------》1.4"+sql1)
            println("datas==>----------------------------------》1.4"+datas)
            if(datas!="[]"){
              println("进来？？？1.4")
              var iteratora = datas.iterator();
              if(iteratora.hasNext()){
                var map1 = iteratora.next();//取值
                var phone=map1.get("ITEM_phone")
                cid=map1.get("item_cid")+";"+aid//个推cid
                println("cid==>----------------------------------》1.4"+cid)
                var content = "";
                var texts = "";
                texts += "" + name + "，" ;
                texts += "" + trainName + "安排您" ;
                texts += "" + computerStartDate + "进行保安员证考试，请携带身份证提前30分钟到达学校签到。" ;
                //texts += "" + theoreticalAddress + "扫码签到。届时请联系监考老师【"+person+"】，手机号："+person_phone ;
                var appAvatar = "  https://bcxin-saas-prod.obs.cn-north-1.myhuaweicloud.com:443/upload%2F2021-11-01%2F1635755240828768236.png";
                var title = "";
                var titleImg = "";
                var actionName = "";
                var actionUrl = "";
                content += "appName=" + appName + "&&;" ; //应用名称
                content += "appId=" + appId + "&&;" ;  //应用id
                content += "appAvatar=" + appAvatar + "&&;" ;  //应用图标
                content += "title=" + title + "&&;" ; //标题
                content += "titleImg=" + titleImg + "&&;" ;  //标题图标
                content += "actionName=" + actionName + "&&;" ;   //操作名称
                content += "actionUrl=" + actionUrl + "&&;" ;   //操作链接
                content += "content=" + texts + "";
                println("usid==>" + usid);
                println("aid==>" + aid);
                println("subject==>" + subject);
                println("phone==>" + phone);
                println("content==>" + content);
                Packages.java.lang.System.err.println("================快要进入sendMessage方法=================");
                sendMessage(usid,aid,subject,content);//------------------------------------站内信发送
                Packages.java.lang.System.err.println("================sendMessage方法结束=================");
                println("站内信发送结束")   
                var request =createDispatchMessageRequestWithSpecialUser(usid,sms,subject,texts,Telephone,phone,"通知班级的ID:"+docid+"用于后续业务查询",aid)
                rqs.add(request);
                println("短信发送结束")
                var examPersonInfoDoc = findDocument(ID);
                examPersonInfoDoc.findItem("noticeState").setValue("1")
                println("examPersonInfoDoc" + examPersonInfoDoc);
                process.doUpdate(examPersonInfoDoc)//站内信推送完成后更新此人的考试通知状态！
                println("更新结束")
                Packages.java.lang.System.err.println("================更新结束=================");
              }
            }
          }
        } //里面for循环结束
        println("rqs---------------------------"+rqs)
        dispatchMessages(rqs);
        println("短信封装完发送---------------------------") 
        Packages.java.lang.System.err.println("================短信封装完发送=================")
        if(isNotNull(cid)){/*个推发送*/
          println("cid进来了")
           Packages.java.lang.System.err.println("================cid进来了=================")
          var payUrl="http://identify.test.bcxin.com.cn/identify/api/common/gt-send-msg"
          var strS ="body="+texts+"&content="+texts+"&cuList="+cid+"&orgId=aSuXCEfz&param=notice,aa,/pages/Tab-Conversation/WorkNotice/WorkNotice&payload=/pages/Tab-Conversation/WorkNotice/WorkNotice&title=百保盾"
          var rtJsonStr = URLConnector.post(payUrl,strS,accessToken);
          println("strS"+strS)
        }
         println("为什么会没到这里1")
      }
      println("为什么会没到这里2")
      Packages.java.lang.System.err.println("================站内信发送成功=================")
      return "站内信发送成功" //站内信发送结束，且不允许载入视图
      
      println("为什么会没到这里3")
    }else{
      return "该场考试状态未通过，不可进行通知！";
    }

  }else{
    return "请选择一条数据！";
  }


})()]]></beforeActionScript>
  <afterActionScript><![CDATA[
/*(function(){  
  var domainid = getDomainid();
  //获取cid每个学员的cid需要判空然后接口调用推送消息） 
  //数据库查询cid
  //var Security = new Packages.cn.myapps.common.util.Security();
  var accessToken =""//Security.getToken(getWebUser().getId());
  var URLConnector = Packages.com.bcxin.saas.core.utils.HttpUtils;
  var cid=""
  //var Security = new Packages.cn.myapps.common.util.Security();
  var accessToken = "" //Security.getToken(getWebUser().getId());
  var URLConnector = Packages.com.bcxin.saas.core.utils.HttpUtils;
  var cid=""
  var aid="";
  var selectId = getParameterAsText("_selects");//获取所选中数据的id结果集
  var msg = ""
  var arrto = splitText(selectId, ";"); //对这个结果集进行处理，以;进行切割，放到数组arrto
  var docid=arrto[0];
  var sql = "select ITEM_SECURITYID from tlk_system_exam_person where ITEM_EXAMID='"+docid+"'and item_noticeState='0' ";
  println("sql==>" + sql);
  var datasss = queryByDSName("tms",sql);
  if(datasss!=null){ 
    for(var iterators = datasss.iterator();iterators.hasNext();) {
      var map2 = iterators.next();//取值
      var aid= map2.get("ITEM_SECURITYID");//保安员id
      var sql1 = "select item_cid from baibaodunflow.vw_employee where  ITEM_userID='"+aid+"'  ";
      var datas = queryByDSName("obpm2",sql1);
      println("sql1==>----------------------------------》1.4"+sql1)
      println("datas==>----------------------------------》1.4"+datas)
      if(datas!="[]"){
        println("进来？？？1.4")
        var iteratora = datas.iterator();
        if(iteratora.hasNext()){
          var map1 = iteratora.next();//取值
          cid=map1.get("item_cid")+";"+aid//个推cid
          println("cid==>----------------------------------》1.4"+cid)
          //个推将cid进行拼接
        }
      }
    }
  }
  //个推发送
  //判空cid
  if(isNotNull(cid)){
    println("cid进来了")
    var payUrl="http://identify.test.bcxin.com.cn/identify/api/common/gt-send-msg"
    var strS ="body=wahmn&content=wahmn&cuList=f8fec983aac3e6d2f3cc71e087724941;ZlC9I2k0&orgId=aSuXCEfz&param=notice,aa,/pages/Tab-Conversation/WorkNotice/WorkNotice&payload=/pages/Tab-Conversation/WorkNotice/WorkNotice&title=百保盾"
    var rtJsonStr = URLConnector.post(payUrl,strS,accessToken);
    println("strS"+strS)
  }
  return "站内信发送成功" //站内信发送结束，且不允许载入视图
  println("没到这里？？")

})()*/]]></afterActionScript>
  <hiddenScript><![CDATA[(function(){
  var domainid = getDomainid();
  var areacode = "";
  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 ('"+domainid+"')"
  println("sqlp---------------"+sqlp)
  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)){
    areacode = areacode.substr(0,2);
    println("areacode2------------------"+areacode)
  }
  if("64".equals(areacode)){
    if(!"505303218683641856--__AOkTvsah9VLicJhQ1FO".equals(domainid)){
      return true
    }
  }



  return false


})()]]></hiddenScript>
  <readonlyScript><![CDATA[]]></readonlyScript>
  <editMode>0</editMode>
  <fileNameScript><![CDATA[]]></fileNameScript>
  <orderno>2</orderno>
  <parentView>__AZNfvD3U2wD6bQ0FHbh</parentView>
  <impmappingconfigid></impmappingconfigid>
  <jumpType>0</jumpType>
  <expSub>false</expSub>
  <icon>{"icon":"/p129_combination.png","type":"img"}</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>0</actionType>
  <actionSelection>0</actionSelection>
  <workFlowType>0</workFlowType>
  <contextMenu>true</contextMenu>
  <showInToolbar>true</showInToolbar>
  <label><![CDATA[]]></label>
</activity>