<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__TnnsgLQFUILcoOWII8d">
  <name>通知班级人员</name>
  <parentId>__Xq3r3eKoddb3a49Mrrg</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <type>1</type>
  <onActionForm></onActionForm>
  <onActionView>__Xq3r3eKoddb3a49Mrrg</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 rqs = Packages.java.util.ArrayList();

  println("SMS----------------->"+sms)//短信
  println("Telephone----------------->"+Telephone)//接收者手机号

  /*var sql="select place_of_register_address from baibaodunflow.vw_organization where id='"+domainid+"'";
  println("sql---------------->"+sql);
  var datas = queryByDSName("tms",sql);
  if(datas!=null){//一家公司只有一条数据
    for(var iterator = datas.iterator();iterator.hasNext();){
      var map1 = iterator.next();//取值
      var registerprovinces= map1.get("place_of_register_address");
      var registerprovince=splitText(registerprovinces, ",");
      var registerprovince1=registerprovince[0];
      var registerprovince2=registerprovince[1];
      println("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"+registerprovinces)
      println("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"+registerprovince)
      if("北京市".equals(registerprovince1)){
        println("北京欢迎你")*/

  //获取勾选的对象 还得判断一下条件满不满足
  var selectId = getParameterAsText("_selects");//获取所选中数据的id结果集
  var msg = ""
  var arrto = splitText(selectId, ";"); //对这个结果集进行处理，以;进行切割，放到数组arrto
  if(arrto.length>0&&arrto.length<2){
    var docid=arrto[0];
    var sql2="select item_classStatus,item_trainingStartTime,item_examPerson,item_trainingLocation from tlk_grade_card_class where id='"+docid+"' "
    var datas = queryByDSName("tms",sql2);//item_examine
    if(datas!=null){
      for(var iterator = datas.iterator();iterator.hasNext();){
        var map1 = iterator.next();//取值
        var examState= map1.get("item_classStatus");
        // var examine = map1.get("item_examine");
        var computerStartDate = map1.get("item_trainingStartTime");
        var theoreticalAddress = map1.get("item_trainingLocation");
        var person2 = map1.get("item_examPerson");//监考老师
        var arrto55 = splitText(person2, ";");
        if(arrto55.length>0){
          println("------------------------------------------------------------->"+ arrto55[0])
          //根据用户ID获取名称
          var userVO = getUserById(arrto55[0]);
          var person=userVO.getName()
          }
      }
      if("1".equals(examState))//&&("1".equals(examine)
      {
        println(examState+" 这个状态是可以进行确认操作的")
        //此处进行站内信通知
        var process = getDocumentProcess();
        var aid="";
        var ID="";
        var usid = getWebUser().getId();
        var subject="您的保安员等级（五级）实操培训已安排，请及时参加！";
        println("docid==>" + docid);
        println("computerStartDate==>" + computerStartDate);
        println("theoreticalAddress==>" + theoreticalAddress);
        var appId=getApplication();
        var appName = "考试管理";
        //取出在这场考试中未通知的人的身份证去做消息通知
        var sql = "select ID,ITEM_IDCARDNO,ITEM_NAME from tlk_level_class_student where ITEM_classID='"+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");
            //ID+= map2.get("ID")+","; //拿到数据ID进行拼接等待所有通知完成后再一个个去更新状态
            ID=map2.get("ID");
            var name= map2.get("ITEM_NAME"); 
            println("idCardNo==>" + idCardNo);
            println("ID==>----------------------------------》12.18" + ID);

            var sqls = "select ITEM_LEARNID,ITEM_LEARNNAME,item_trainName from tlk_grade_registration where ITEM_IDCARDNO='"+idCardNo+"'";//一条数据
            var datass = queryByDSName("tms",sqls);
            println("sqls==>----------------------------------》1.4"+sqls)
            println("datass==>----------------------------------》1.4"+datass)
            if(datass!=null){
              var iterator = datass.iterator();
              if(iterator.hasNext()){
                println("进来？？？")
                var map3 = iterator.next();//取值
                var learnName= map3.get("ITEM_LEARNNAME"); //本企业名称
                var learnId= map3.get("ITEM_LEARNID");//本企业id
                var trainName= map3.get("item_trainName");//培训公司
                var sql1 = "select ITEM_userID,ITEM_phone from baibaodunflow.vw_employee where ITEM_documentID='"+idCardNo+"'and DOMAINID='"+learnId+"'";
                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();//取值
                    //aid += map1.get("ITEM_userID")+",";  
                    aid=map1.get("ITEM_userID")
                    var phone=map1.get("ITEM_phone")
                    var content = "";
                    var texts = "";
                    texts += "" + name + "，" ;
                    texts += "" + trainName + "安排您于" ;
                    texts += "" + computerStartDate + "开始保安员五级实操培训，请在实操培训开始前一天下午五点前到" ;
                    texts += "" + theoreticalAddress + "报到。请提前准备及时到场参训。" ;
                    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);


                    sendMessage(usid,aid,subject,content);//------------------------------------站内信发送
                    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)//站内信推送完成后更新此人的考试通知状态！
                  } 
                }
              }
            }
          } //里面for循环结束
          println("rqs---------------------------"+rqs)
          dispatchMessages(rqs);
          println("短信封装完发送---------------------------")  
        }
        return "站内信发送结束 " //站内信发送结束，且不允许载入视图
      }else{
        return "该场考试状态未通过，不可进行通知！";
      }
    }
  }else{
    return "请选择一条数据！";
  }


})()]]></beforeActionScript>
  <afterActionScript><![CDATA[]]></afterActionScript>
  <hiddenScript><![CDATA[]]></hiddenScript>
  <readonlyScript><![CDATA[]]></readonlyScript>
  <editMode>0</editMode>
  <fileNameScript><![CDATA[]]></fileNameScript>
  <orderno>4</orderno>
  <parentView>__Xq3r3eKoddb3a49Mrrg</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>