<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<repositoryVO id="__3iodlty7JqbtTDZdw0N">
  <name>sysfunctionNew</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <content><![CDATA[//系统函数库(公共函数库)       
var sysfunctionNew = {       
        
        SAAS_URL : "http://saasweb.test.baibaodun.cn/",
        	        
    	/**        
    	* applicationid        
    	*/        
    	APPLICATIONID : "__DXZvc8mnEmDqMARhK7G",      
            
      	/**      
      	*本平台的系统库      
      	*/      
      	DS_OBPM : "obpm2",      
    	    
    	/**      
      	*本平台的系统库数据源 要确保应用-数据源有此配置    
      	*/      
      	DS_OBPM_NAME : "baibaodunObpm",      
             
             
        /**      
      	*本平台的业务库对应数据源     
      	*/      
      	DS_FLOW : "baibaodunFlow",   		
     	     
       	/**      
      	*组织权益数据源和数据库名称要同名      
      	*/      
      	DS_ORGANIZATIONAUTH : "organizationAuth",      
       	     
		/**

		*推送到监管端的业务库对应的数据源，内外的数据源需要一致
		**/	
		TO_DSDATASOURCE : "SecurityFlow",
      	/**      
      	*监管端系统ID      
      	*/      
      	JIANGUAN_SYSTEMID : "__wGomeHJBz6CpLFCCl4y",      
            
      	/**      
      	*监管端 保安从业系统ID      
      	*/      
      	JIANGUAN_CONGYE_SYSTEMID : "__DXZvc8mnEmDqMARhK7G",      
      	      
      	/**      
      	*我的ip地址      
      	*/      
		MY_IP : "http://117.78.35.63:8080/obpm",      
      	      
      	/**      
      	*回调地址      
      	*/      
      	MY_CALLBACKURL : "http://117.78.35.63:8080/obpm/bcxin/callBackData",      
      	      
      	      
      	/**      
      	*对接监管端数据需要的用户登录      
      	*/           
      	JIANGUAN_USER_ID	: "__et20Vwbg4LTP0FUYcVf",	
		/**
		保安员角色，在保安员列表中入职新用户，自动创建后台账号需要，不要删除角色 保安员
		**/		
      	SECURITY_ROLE_ID : "__99ckEhqH2ZflI0ibFWa",   
		
      	sendDateToJgSystemNEW : function (){  
 			var URLConnector = new Packages.cn.myapps.util.http.HttpRequestUtil();       
			var toDomainID = "__0iYJYU3PyE97bRzpBpe";
			var toApplicationID = getApplication(); 
			var toDataSoure = sysfunction.TO_DSDATASOURCE;
  			var domainid = getDomainid();       
  			var doc = getCurrentDocument();     			
  			var docid = doc.getId(); 
			var toFormID = doc.getFormid();			
			var syncUtil = new Packages.com.teemlink.sync.util.SyncUtil(); 
			var JSONObject = new Packages.net.sf.json.JSONObject();
			var DataServiceUrl = "/runtime/sync/data";
			var FileServiceUrl = "/runtime/sync/file";
			var FileDownURLOUT = "/data/obpm-demoSecurity";
			var FileDownURLINT = "/data/obpm-demo-security-pg";		
  			//先发送t_ducument，再发送tlk表，最后再发送文件     
    
			var sql = "select '"+getDomainid()+"' AS DOMAINID, rs.item_regionId,rs.item_systemAdmin,rs.item_systemURL,rs.item_systemURLNw,rs.item_callbackUrl,rs.item_targetServiceUrl,rs.item_toDominid from  "+sysfunction.DS_ORGANIZATIONAUTH+".tlk_RegionSystem rs  inner JOIN  "+sysfunction.DS_ORGANIZATIONAUTH+".tlk_DepartmentLevel dl on rs.ITEM_REGIONId=dl.ITEM_REGIONId and  dl.id in (select item_officePoliceAddressID from tlk_SetSupervise WHERE domainid='"+domainid+"') GROUP BY DOMAINID, ITEM_REGIONId,item_systemAdmin,item_systemURL "; 
			var datas = queryBySQL(sql);   
			if(datas.size()>0){    
	  
				for(var iterator = datas.iterator();iterator.hasNext();){     
					var data = iterator.next(); 
					var userId = data.getItemValueAsString("systemAdmin");     
					//监管外网地址
					var srcApp = data.getItemValueAsString("systemURL");         
					//监管内网地址
					var targetApp = data.getItemValueAsString("systemURLNw");   
					//监管内网接收接口地址
					//var targetServiceUrl = data.getItemValueAsString("targetServiceUrl");
					var targetServiceUrl = "/bcxin/receiveOperation";
					//监管外网回调地址
					var callbackUrl = data.getItemValueAsString("callbackUrl");
					var regionId = data.getItemValueAsString("regionId"); 
					var toDomainID =  data.getItemValueAsString("toDominid"); 
					//业务id
					var businessId = "1001000000001";
					var businessType = "1001";
					var fileOperation = syncUtil.genFileDataOperationFromDocument(doc,userId,sysfunction.MY_IP,FileDownURLOUT);
					var fileOperation2 = syncUtil.genFileDataOperationFromDocument(doc,userId,sysfunction.MY_IP,FileDownURLINT);
					//替换需要推送的字段
					doc.setDomainid(toDomainID);
					doc.setApplicationid(toApplicationID);
					doc.setFormid(toFormID);
					doc.setAuthorDeptIndex("{}");
					doc.setAuthorId(userId);		
					var documentOperation = syncUtil.buildDocumentHeadOperation(doc,toApplicationID, toDataSoure, "save");
					var documentOperationStr = JSONObject.fromObject(documentOperation).toString();

					var TLKOperation = syncUtil.buildDocumentOperation(doc,toApplicationID, toDataSoure, "save");
					var TLKOperationStr = JSONObject.fromObject(TLKOperation).toString();					
					// 发送 监管外网 t_document							
					URLConnector.post(srcApp+DataServiceUrl,documentOperationStr); 
					// 发送  监管外网 tlk					
					URLConnector.post(srcApp+DataServiceUrl,TLKOperationStr); 
					// 监管外网  推送文件					
					if(fileOperation.size()>0){
						for(var iter = fileOperation.iterator();iter.hasNext();){
							var fileOperationVO = iter.next();
							var fileOperationStr = JSONObject.fromObject(fileOperationVO).toString();

							URLConnector.post(srcApp+FileServiceUrl,fileOperationStr); 
						}
					}
					//通知监管外网推送数据内网  documentOperationStr
					//println("targetApp==="+targetApp);
					var contentMap  = new Packages.com.alibaba.fastjson.JSONObject();
					contentMap.put("docId",docid);
					contentMap.put("formId",toFormID);
					contentMap.put("userId",userId);
					contentMap.put("srcApp",srcApp);
					contentMap.put("targetApp",targetApp);
					contentMap.put("regionId",regionId);
					contentMap.put("targetServiceUrl",targetServiceUrl);
					contentMap.put("businessId",businessId);
					contentMap.put("businessType",businessType);
					contentMap.put("callbackUrl",callbackUrl);
					contentMap.put("operation",documentOperationStr);
					contentMap.put("mode","normal");
					var outputStr = contentMap.toJSONString();//转换为字符串
					var FlowUrl = srcApp +"/bcxin/sendOperation";
					var JSONString = URLConnector.post(FlowUrl,outputStr);  					
					//监管端外网摆渡内网 TLK
					var contentMap2  = new Packages.com.alibaba.fastjson.JSONObject();
					contentMap2.put("docId",docid);
					contentMap2.put("formId",toFormID);
					contentMap2.put("userId",userId);
					contentMap2.put("srcApp",srcApp);
					contentMap2.put("targetApp",targetApp);
					contentMap2.put("regionId",regionId);
					contentMap2.put("targetServiceUrl",targetServiceUrl);
					contentMap2.put("businessId",businessId);
					contentMap2.put("businessType",businessType);
					contentMap2.put("callbackUrl",callbackUrl);
					contentMap2.put("operation",TLKOperationStr);
					contentMap2.put("mode","normal");
					var outputStr2 = contentMap2.toJSONString();//转换为字符串
					var FlowUrl = srcApp +"/bcxin/sendOperation";
					var JSONString = URLConnector.post(FlowUrl,outputStr2);  
					// 监管外网推送文件  推送文件					
					if(fileOperation2.size()>0){
						for(var iter2 = fileOperation2.iterator();iter2.hasNext();){
							var fileOperationVO = iter2.next();
							var fileOperationStr = JSONObject.fromObject(fileOperationVO).toString();
							var contentMap3  = new Packages.com.alibaba.fastjson.JSONObject();
							contentMap3.put("docId",docid);
							contentMap3.put("formId",toFormID);
							contentMap3.put("userId",userId);
							contentMap3.put("srcApp",srcApp);
							contentMap3.put("targetApp",targetApp);
							contentMap3.put("regionId",regionId);
							contentMap3.put("targetServiceUrl",targetServiceUrl);
							contentMap3.put("businessId",businessId);
							contentMap3.put("businessType",businessType);
							contentMap3.put("callbackUrl",callbackUrl);
							contentMap3.put("operation",fileOperationStr);
							contentMap3.put("mode","annex");
							var outputStr3 = contentMap3.toJSONString();//转换为字符串
							var FlowUrl = srcApp +"/bcxin/sendOperation";
							var JSONString = URLConnector.post(FlowUrl,outputStr3);  
							
						}
					}					
				
						}       
				  
			}else{       
				return "提交失败，请先完善【从业单位信息】-【单位信息维护】中的数据监管配置后再上报数据。若您无此模块权限，请联系组织管理员操作或授权权限。";       
			}       

      	},      
  		  
  		sendDateToJgSystemByDocNEW : function (doc,form_id,applicationId,officeAddressID){         
 			var URLConnector = new Packages.cn.myapps.util.http.HttpRequestUtil();       
			var toDomainID = "__0iYJYU3PyE97bRzpBpe";
			var toApplicationID =applicationId;
			var toDataSoure = sysfunction.TO_DSDATASOURCE;
  			var domainid = getDomainid();       
  			var doc = doc;     			
  			var docid = doc.getId(); 
			var toFormID = form_id;			
			var syncUtil = new Packages.com.teemlink.sync.util.SyncUtil(); 
			var JSONObject = new Packages.net.sf.json.JSONObject();
			var DataServiceUrl = "/runtime/sync/data";
			var FileServiceUrl = "/runtime/sync/file";
			var FileDownURLOUT = "/data/obpm-demoSecurity";
			var FileDownURLINT = "/data/obpm-demo-security-pg";			
  			//先发送t_ducument，再发送tlk表，最后再发送文件     
    
			var sql = "select '"+getDomainid()+"' As domainid, rs.ITEM_regionId,rs.item_systemAdmin,rs.item_systemURL,rs.item_systemURLNw,rs.item_callbackUrl,rs.item_targetServiceUrl,rs.item_toDominid from  "+sysfunction.DS_ORGANIZATIONAUTH+".tlk_RegionSystem rs  inner JOIN  "+sysfunction.DS_ORGANIZATIONAUTH+".tlk_DepartmentLevel dl on rs.ITEM_regionId=dl.ITEM_regionId and  dl.id ='"+officeAddressID+"' ";
			//println("sql=="+sql);
			var datas = queryBySQL(sql);   
			if(datas.size()>0){    
	  
				for(var iterator = datas.iterator();iterator.hasNext();){     
					var data = iterator.next(); 
					var userId = data.getItemValueAsString("systemAdmin");     
					//监管外网地址
					var srcApp = data.getItemValueAsString("systemURL");         
					//监管内网地址
					var targetApp = data.getItemValueAsString("systemURLNw");   
					//监管内网接收接口地址
					//var targetServiceUrl = data.getItemValueAsString("targetServiceUrl");
					var targetServiceUrl = "/bcxin/receiveOperation";
					//监管外网回调地址
					var callbackUrl = data.getItemValueAsString("callbackUrl");
					var regionId = data.getItemValueAsString("regionId"); 
					var toDomainID =  data.getItemValueAsString("toDominid"); 
					//业务id
					var businessId = "1001000000001";
					var businessType = "1001";
					var fileOperation = syncUtil.genFileDataOperationFromDocument(doc,userId,sysfunction.MY_IP,FileDownURLOUT);
					var fileOperation2 = syncUtil.genFileDataOperationFromDocument(doc,userId,sysfunction.MY_IP,FileDownURLINT);
					//替换需要推送的字段
					doc.setDomainid(toDomainID);
					doc.setApplicationid(toApplicationID);
					doc.setFormid(toFormID);
					doc.setAuthorDeptIndex("{}");
					doc.setAuthorId(userId);		
					var documentOperation = syncUtil.buildDocumentHeadOperation(doc,toApplicationID, toDataSoure, "save");
					var documentOperationStr = JSONObject.fromObject(documentOperation).toString();

					var TLKOperation = syncUtil.buildDocumentOperation(doc,toApplicationID, toDataSoure, "save");
					var TLKOperationStr = JSONObject.fromObject(TLKOperation).toString();					
					// 发送 监管外网 t_document							
					URLConnector.post(srcApp+DataServiceUrl,documentOperationStr); 
					// 发送  监管外网 tlk					
					URLConnector.post(srcApp+DataServiceUrl,TLKOperationStr); 
					// 监管外网  推送文件					
					if(fileOperation.size()>0){
						for(var iter = fileOperation.iterator();iter.hasNext();){
							var fileOperationVO = iter.next();
							var fileOperationStr = JSONObject.fromObject(fileOperationVO).toString();

							URLConnector.post(srcApp+FileServiceUrl,fileOperationStr); 
						}
					}
					//通知监管外网推送数据内网  documentOperationStr
					var contentMap  = new Packages.com.alibaba.fastjson.JSONObject();
					println("targetApp=="+targetApp);
					println("callbackUrl=="+callbackUrl);
					contentMap.put("docId",docid);
					contentMap.put("formId",toFormID);
					contentMap.put("userId",userId);
					contentMap.put("srcApp",srcApp);
					contentMap.put("targetApp",targetApp);
					contentMap.put("regionId",regionId);
					contentMap.put("targetServiceUrl",targetServiceUrl);
					contentMap.put("businessId",businessId);
					contentMap.put("businessType",businessType);
					contentMap.put("callbackUrl",callbackUrl);
					contentMap.put("operation",documentOperationStr);
					contentMap.put("mode","normal");
					var outputStr = contentMap.toJSONString();//转换为字符串
					var FlowUrl = srcApp +"/bcxin/sendOperation";
					var JSONString = URLConnector.post(FlowUrl,outputStr);  					
					//监管端外网摆渡内网 TLK
					var contentMap2  = new Packages.com.alibaba.fastjson.JSONObject();
					contentMap2.put("docId",docid);
					contentMap2.put("formId",toFormID);
					contentMap2.put("userId",userId);
					contentMap2.put("srcApp",srcApp);
					contentMap2.put("targetApp",targetApp);
					contentMap2.put("regionId",regionId);
					contentMap2.put("targetServiceUrl",targetServiceUrl);
					contentMap2.put("businessId",businessId);
					contentMap2.put("businessType",businessType);
					contentMap2.put("callbackUrl",callbackUrl);
					contentMap2.put("operation",TLKOperationStr);
					contentMap2.put("mode","normal");
					var outputStr2 = contentMap2.toJSONString();//转换为字符串
					var FlowUrl = srcApp +"/bcxin/sendOperation";
					var JSONString = URLConnector.post(FlowUrl,outputStr2);  
					// 监管外网推送文件  推送文件					
					if(fileOperation2.size()>0){
						for(var iter2 = fileOperation2.iterator();iter2.hasNext();){
							var fileOperationVO = iter2.next();
							var fileOperationStr = JSONObject.fromObject(fileOperationVO).toString();
							var contentMap3  = new Packages.com.alibaba.fastjson.JSONObject();
							contentMap3.put("docId",docid);
							contentMap3.put("formId",toFormID);
							contentMap3.put("userId",userId);
							contentMap3.put("srcApp",srcApp);
							contentMap3.put("targetApp",targetApp);
							contentMap3.put("regionId",regionId);
							contentMap3.put("targetServiceUrl",targetServiceUrl);
							contentMap3.put("businessId",businessId);
							contentMap3.put("businessType",businessType);
							contentMap3.put("callbackUrl",callbackUrl);
							contentMap3.put("operation",fileOperationStr);
							contentMap3.put("mode","annex");
							var outputStr3 = contentMap3.toJSONString();//转换为字符串
							var FlowUrl = srcApp +"/bcxin/sendOperation";
							var JSONString = URLConnector.post(FlowUrl,outputStr3);  
							
						}
					}					
				
						}       
				  
			}else{       
				return "提交失败，请先完善【从业单位信息】-【单位信息维护】中的数据监管配置后再上报数据。若您无此模块权限，请联系组织管理员操作或授权权限。";       
			}  
      	},
 		deleteDataToJgSystemByDoc : function (attId,applicationId){ 
			var arrto = splitText(attId,";");
			
			if(arrto.length>1){
			return "请选择一条记录操作！";
			}
			var toApplicationID = applicationId;
			var srcApp = sysfunction.MY_IP;
			var DataServiceUrl = "/runtime/sync/data";
			//println("attIdlength=="+(arrto.length));

			var doc = findDocument(attId);
			var docid = doc.getId();
 			var URLConnector = new Packages.cn.myapps.util.http.HttpRequestUtil();       
			var toDataSoure = sysfunction.TO_DSDATASOURCE;			
			var syncUtil = new Packages.com.teemlink.sync.util.SyncUtil(); 
			var JSONObject = new Packages.net.sf.json.JSONObject();
			//替换需要推送的字段

			var documentOperation = syncUtil.buildDocumentHeadOperation(doc,toApplicationID, toDataSoure, "delete");
			var documentOperationStr = JSONObject.fromObject(documentOperation).toString();

			var TLKOperation = syncUtil.buildDocumentOperation(doc,toApplicationID, toDataSoure, "delete");
			var TLKOperationStr = JSONObject.fromObject(TLKOperation).toString();

			
			//调用删除接口     
			var sql = "select '"+getDomainid()+"' AS DOMAINID, rs.item_regionId,rs.item_systemAdmin,rs.item_systemURL,rs.item_systemURLNw,rs.item_callbackUrl,rs.item_targetServiceUrl from  "+sysfunction.DS_ORGANIZATIONAUTH+".tlk_RegionSystem rs  inner JOIN  "+sysfunction.DS_ORGANIZATIONAUTH+".tlk_DepartmentLevel dl on rs.ITEM_REGIONId=dl.item_regionId and  dl.id in (select item_officePoliceAddressID from tlk_SetSupervise WHERE domainid='"+getDomainid()+"') GROUP BY DOMAINID, item_regionId,item_systemAdmin,item_systemURL "; 
			
			var datas = queryBySQL(sql);
	
			if(datas.size()>0){	
				for(var iterator = datas.iterator();iterator.hasNext();){    
					var data = iterator.next();  						
					
					var userId = data.getItemValueAsString("systemAdmin");     
					//监管外网地址
					var srcApp = data.getItemValueAsString("systemURL");         
					//监管内网地址
					var targetApp = data.getItemValueAsString("systemURLNw");   
					//监管内网接收接口地址
					//var targetServiceUrl = data.getItemValueAsString("targetServiceUrl");
					var targetServiceUrl = "/bcxin/receiveOperation";
					//监管外网回调地址
					var callbackUrl = data.getItemValueAsString("callbackUrl");
					//业务id
					var businessId = "1001000000001";
					var businessType = "1002";
					var regionId = data.getItemValueAsString("regionId");     

				
					//先发送t_ducument，再发送tlk表，最后再发送文件     
					URLConnector.post(srcApp+DataServiceUrl,documentOperationStr); 
					// 发送tlk
					URLConnector.post(srcApp+DataServiceUrl,TLKOperationStr); 
					//通知监管外网推送数据内网
					var contentMap  = new Packages.com.alibaba.fastjson.JSONObject();
					contentMap.put("docId",docid);
					contentMap.put("formId",doc.getFormid());
					contentMap.put("userId",userId);
					contentMap.put("srcApp",srcApp);
					contentMap.put("targetApp",targetApp);
					contentMap.put("regionId",regionId);
					contentMap.put("targetServiceUrl",targetServiceUrl);
					contentMap.put("businessId",businessId);
					contentMap.put("businessType",businessType);
					contentMap.put("callbackUrl",callbackUrl);
					contentMap.put("operation",documentOperationStr);
					contentMap.put("mode","normal");
					var outputStr = contentMap.toJSONString();//转换为字符串

					//监管端外网摆渡  
					var FlowUrl = srcApp +"/bcxin/sendOperation";
					var JSONString = URLConnector.post(FlowUrl,outputStr);    
				
				} 
			 
			}else{      
				return "删除失败，请先完善【从业单位信息】-【单位信息维护】中的数据监管配置后再上报数据。若您无此模块权限，请联系组织管理员操作或授权权限。";      
			}          
		},
}]]></content>
  <version>0</version>
</repositoryVO>