<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__lyndWBA7KTe75QxV2sM">
  <name>取消班级</name>
  <parentId>__Xq3r3eKoddb3a49Mrrg</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <type>1</type>
  <onActionForm></onActionForm>
  <onActionView>__Xq3r3eKoddb3a49Mrrg</onActionView>
  <colorType>danger</colorType>
  <beforeActionScript><![CDATA[#include "sysfunction";
(function(){
  //取消班级
  var classStatus = ""; //班级状态
  var className = ""; //班级名称
  var sumScore=""     //总成绩
  var appName = "考试管理";
  var subject="您参与的保安员等级（五级）实操培训已取消！";
  var senderId=getWebUser().getId()//当前用户id(作为发送者)
  var appId=getApplication();
  var domainid = getDomainid();
  var process2 = getDomainProcess();//获取企业域对象 
  var system_name = process2.doView(domainid);
  var companyname = system_name.getName();//培训机构名称

  try{
    var selectId = getParameterAsText("_selects");//获取所选中数据的id结果集
    var rtn = "";
    var arrto = splitText(selectId, ";");
    if(isNotNull(selectId)){
      for (var i = 0; i < arrto.length; i++) { 
        var sql1 = "select ITEM_CLASSNAME,ITEM_CLASSSTATUS,ID from tlk_grade_card_class where ID ='" + arrto[i] + "'";
        var datas = queryByDSName("tms", sql1);
        println("sql1=========="+sql1);
        if (datas != null) {
          var iterator = datas.iterator();
          if(iterator.hasNext()){
            var map1 = iterator.next();//取值
            classStatus = map1.get("ITEM_CLASSSTATUS");//班级状态
            className = map1.get("ITEM_CLASSNAME");//班级名称
            println("成绩确认状态："+classStatus);
          }
        }
        if(!"1".equals(classStatus) && !"0".equals(classStatus)){
          return createAlert(className+"已经进入审核流程，无法取消！（只有待提交与审核通过才能取消）");
        }
        //如果班级成员有成绩则无法取消  
        var sql2 = "select ITEM_sumScore,ITEM_classId from tlk_level_class_student where ITEM_classId ='" + arrto[i] + "'";
        var datas2 = queryByDSName("tms", sql2);
        println("sql2=========="+sql2);
        if (datas2 != null) {
          for (var iterator = datas2.iterator(); iterator.hasNext();){
            var map1 = iterator.next();//取值
            sumScore = map1.get("ITEM_sumScore");//取到第一个直接结束了
            println("总成绩："+sumScore);
            if(sumScore>0 && "1".equals(classStatus)){//审核通过但是学生中有成绩
              return createAlert(className+"班级成员已有成绩无法取消！")
            }
          }  
        }
        //这里开始取消操作-------------------------------------------------------------------------
        
        /*
          //取消完在去通知班级里面的学生
           */
        var sql3 = "select ITEM_sumScore,ITEM_classId,item_name,item_SECURITYID from tlk_level_class_student where ITEM_classId ='" + arrto[i] + "'";
        var datas3 = queryByDSName("tms", sql3);
        println("sql3=========="+sql3);
        if (datas3 != null) {
          for (var iterator3 = datas3.iterator(); iterator3.hasNext();){
            var map3 = iterator3.next();//取值
            var name=map3.get("item_name");//名字
            var SECURITYID=map3.get("item_SECURITYID") //保安员id

            println("senderId------------------------------------------------------------------>"+senderId)
            println("SECURITYID------------------------------------------------------------------>"+SECURITYID)
            println("companyname------------------------------------------------------------------>"+companyname)

            var content = "";
            var texts = "";
            texts += "【"+name+"】，您好，" ;
            texts += "["+companyname+"]举办的等级实操培训已取消，班级名称："
            texts += "["+className+"]，请等待培训学校重新安排，有任何问题可直接咨询所属保安公司或培训学校。";
            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 + "";
            sendMessage(senderId,SECURITYID,subject,content)
            println("取消成功！")
          }//for循环结束 班级学员不为空 再把里头的所有学生删除（这里只能是先通知后进行删除）
          println("2--");
          var deletesql ="delete from tlk_level_class_student where ITEM_CLASSID='"+arrto[i]+"'";
          println("deletesql==========="+deletesql);
          deleteByDSName(sysfunction.DS_TMS,deletesql);
        }
        //再去更新班级状态
        var updatesql1="update tlk_grade_card_class set ITEM_CLASSSTATUS='5' where ID='"+arrto[i]+"'";
        println("updatesql==========="+updatesql1);
        updateByDSName(sysfunction.DS_TMS,updatesql1);
      }//for循环结束 
      
      //return "取消考试完成" 不能结束方法
      
    }else{
      return createAlert("请选择数据");
    }
  }catch(e){
    println(e);
  }
})()]]></beforeActionScript>
  <afterActionScript><![CDATA[]]></afterActionScript>
  <hiddenScript><![CDATA[]]></hiddenScript>
  <readonlyScript><![CDATA[]]></readonlyScript>
  <editMode>0</editMode>
  <fileNameScript><![CDATA[]]></fileNameScript>
  <orderno>3</orderno>
  <parentView>__Xq3r3eKoddb3a49Mrrg</parentView>
  <impmappingconfigid></impmappingconfigid>
  <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>0</actionType>
  <actionSelection>0</actionSelection>
  <workFlowType>0</workFlowType>
  <contextMenu>true</contextMenu>
  <showInToolbar>true</showInToolbar>
  <label><![CDATA[]]></label>
</activity>