<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<activity id="__R6LbS4WlUAXiSiijKGz">
  <name>确认授权</name>
  <parentId>__LFCzL9oexy8fk340Aky</parentId>
  <type>11</type>
  <onActionForm></onActionForm>
  <onActionView></onActionView>
  <onActionFlow></onActionFlow>
  <onActionPrint></onActionPrint>
  <colorType>default</colorType>
  <beforeActionScript><![CDATA[#include "sysfunction";
(function(){                      
 var doc=getCurrentDocument();    
var authLessonName=getItemValueAsString("authLessonName");               
  var id=doc.getId()+"";                 
var authLessonId=getItemValueAsString("authLessonId");                   
var authPeoples=getItemValueAsString("authPeoples"); //视图选择框

var lessonAuthStartDate = format(doc.getItemValueAsDate("lessonAuthStartDate"),"yyyy-MM-dd");
var lessonAuthEndDate = format(doc.getItemValueAsDate("lessonAuthEndDate"),"yyyy-MM-dd");
var arrto = splitText(authPeoples,";"); 

var errorStr = "";  
var userIdSql = "";       
var dominId = getDomainid();                
it =arrto.length;  

if(!isNotNull(authPeoples)){                  
  return createAlert("请先选择需要授权的人员");                  
}                  
for(var i=0;i<arrto.length;i++){                  
  var userId = arrto[i]; 
  var userVO = getUserById(userId);                     
   var userName = userVO.getName();  
  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='"+userId+"'";
            println("sql2---->"+sql);
          var datart = findBySQL(sql);

  userId=datart.getItemValueAsString("ID_NUMBER");
  println("userId---->"+userId);
  userIdSql += "'"+userId + "',";
  var sql="select '"+ dominId +"' as domainid,count(ID) count, ITEM_AUTHLESSONNAME, "+    
      "ITEM_AUTHLESSONID, ITEM_AUTHUSERID, ITEM_AUTHUSERNAME, ITEM_AUTHRECORDID "+                 
      "from tlk_lesson_auth_base_info where ITEM_AUTHUSERID = '"+userId+"' and ITEM_AUTHLESSONID = '"+authLessonId+"' GROUP BY ID";
  println("sql1---->"+sql);
  var datas = queryByDSName(sysfunction.DS_TMS,sql); 
  println("adtas------------>"+datas);
  if(datas!="[]"){  
     var iter  =datas.iterator();
     if(iter != null && iter.hasNext()){
        println("111111111111111111111111111111111");
             for(var iterator = datas.iterator();iterator.hasNext();){
       var map1 = iterator.next();//取值
       var authRecordId = map1.get("ITEM_AUTHRECORDID");
      if(authRecordId != id){ 
        println("222222222222222222");
        if(map1.get("count") != "0"){                  
          errorStr += map1.get("ITEM_AUTHUSERNAME") + "已授权此课程，请勿再次授权</br>";                  
      
      }
    }
     }
  }}
        else{
        
          
          var countSql = "select count(ID) count from tlk_lesson_auth_base_info where ITEM_AUTHLESSONID = '"+authLessonId+"' and ITEM_AUTHUSERID = '"+userId+"'";                   
          println("countSql---->"+countSql);
          var datas = queryByDSName(sysfunction.DS_TMS,countSql);   
          var data = datas.iterator().next();                   
          if(data.get("count") == "0"){   
           var process = getDocumentProcess();               
           var formProcess = getFormProcess();               
           var subform = formProcess.doView("__t8b3WI9MCRgmpSycGIZ");               
           var doc = process.doNew(subform,getWebUser(),createParamsTable());      
           doc.addStringItem("AUTHLESSONNAME",authLessonName);               
           doc.addStringItem("AUTHLESSONID",authLessonId);               
           doc.addStringItem("AUTHUSERID",datart.getItemValueAsString("ID_NUMBER"));             
           doc.addStringItem("AUTHUSERNAME",userName);      
           doc.addStringItem("AUTHRECORDID",id);        
           doc.addStringItem("validityDate",lessonAuthStartDate + " ~ " + lessonAuthEndDate);   
           //doc.addIntItem("progress",0);   
           println("doc==>" + doc);
           process.doCreate(doc);               
         }   
        }  
}               
 if(errorStr != ""){                  
  return createAlert(errorStr);                   
}else{
  userIdSql = userIdSql.substring(0, userIdSql.length - 1); 
  var sql8="select * from tlk_lesson_auth_base_info where ITEM_AUTHRECORDID='"+id+"'";
 println("useridSQL-------->"+userIdSql);
  var deleteSql = "delete from tlk_lesson_auth_base_info where ITEM_AUTHRECORDID = '"+id+"'"+      
      " and ITEM_AUTHUSERID not in ("+userIdSql+")" ;  
       deleteByDSName(sysfunction.DS_TMS,deleteSql);  
 
}                          
})()]]></beforeActionScript>
  <afterActionScript><![CDATA[]]></afterActionScript>
  <retractBeforeActionScript><![CDATA[]]></retractBeforeActionScript>
  <retractAfterActionScript><![CDATA[]]></retractAfterActionScript>
  <hiddenScript><![CDATA[]]></hiddenScript>
  <readonlyScript><![CDATA[]]></readonlyScript>
  <startFlowScript><![CDATA[							]]></startFlowScript>
  <editMode>0</editMode>
  <flowShowType>表单中显示流程操作</flowShowType>
  <fileNameScript><![CDATA[]]></fileNameScript>
  <orderno>1</orderno>
  <stateToShow></stateToShow>
  <parentView></parentView>
  <parentForm>__LFCzL9oexy8fk340Aky</parentForm>
  <impmappingconfigid>__7tkXQ8UWGSqrTJkHtCB</impmappingconfigid>
  <jumpType>0</jumpType>
  <expSub>false</expSub>
  <icon></icon>
  <disableFlowNode>true</disableFlowNode>
  <changeFlowOperator>true</changeFlowOperator>
  <changeFlowCc>true</changeFlowCc>
  <multiLanguageLabel></multiLanguageLabel>
  <dispatcherMode>0</dispatcherMode>
  <dispatcherUrl><![CDATA[]]></dispatcherUrl>
  <dispatcherParams><![CDATA[]]></dispatcherParams>
  <jumpMode>0</jumpMode>
  <jumpActOpenType>0</jumpActOpenType>
  <withOld>false</withOld>
  <actionType>0</actionType>
  <actionDispatcherUrlScript><![CDATA[]]></actionDispatcherUrlScript>
  <actionSelection>0</actionSelection>
  <relatedFormId></relatedFormId>
  <actionScript><![CDATA[]]></actionScript>
  <workFlowType>0</workFlowType>
  <isneedcomment>0</isneedcomment>
  <contextMenu>true</contextMenu>
  <showInToolbar>true</showInToolbar>
  <transpond>选择</transpond>
  <targetList>ism1EiHqAkpLpSd2Zr7|</targetList>
  <label><![CDATA[]]></label>
</activity>