<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<repositoryVO id="__jnODA6FrzckvbAy5Y3y">
  <name>sysfunction</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <content><![CDATA[//系统函数库(公共函数库)       
var sysfunction = {       
        
        SAAS_URL : "http://saasweb.test.baibaodun.cn/",
        	        
    	/**        
    	* applicationid        
    	*/        
    	APPLICATIONID : "__DXZvc8mnEmDqMARhK7G",      
            
      	/**      
      	*本平台的系统库      
      	*/      
      	DS_OBPM : "obpm2",      
    	    
    	/**      
      	*本平台的系统库数据源     
      	*/      
      	DS_OBPM_NAME : "baibaodunObpm",    
  
      	/**      
      	*本平台的培训服务数据源     
      	*/      
      	DS_TMS : "tms",      
             
        /**      
      	*本平台的业务库对应数据源      
      	*/      
      	DS_FLOW : "baibaodunFlow",      
     	     
       	/**      
      	*组织权益数据源      
      	*/      
      	DS_ORGANIZATIONAUTH : "organizationAuth",      
       	      
      	/**      
      	*外部监控端系统库      
      	*/      
      	DS_SECURITYOBPM : "securityObpm",      
            
      	/**      
      	*监管端ip地址      
      	*/      
      	//JIANGUAN_IP : "http://192.168.88.125:8080",      
      	//JIANGUAN_IP : "http://obpm.test.bcxin.com.cn",      
      	JIANGUAN_IP :  "http://117.78.35.63:8060/obpm",     
      	/**      
      	*监管端系统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	: "__JiwB01OQQ42pAhtmFs0",      
      	JIANGUAN_USER_ID	: "__et20Vwbg4LTP0FUYcVf",
      	sendDateToJgSystemByDocHZH : function (doc,myFormId,syncFormId,applicationId,officeAddressID){         
 			var URLConnector = new Packages.cn.myapps.util.http.HttpRequestUtil();         
 			var domainid = getDomainid();       
 			var docid = doc.getId();   
			
			//需先校验表单校验无问题。无问题则保存并推送数据，有未填则不推送,不执行之后逻辑，等待表单校验
			var docprocessValidata = getDocumentProcess();
			var paramsValidata = createParamsTable();
			var webUserValidata = getWebUser();
			var validata = docprocessValidata.doValidate(doc,paramsValidata,webUserValidata);
			if(validata.size() != 0 ){
					return "";	
			}
			
 			var itemsMap  = new Packages.com.alibaba.fastjson.JSONObject();      
 			var userlist = createObject("java.util.ArrayList");   
 			for(var iter=doc.getItems().iterator();iter.hasNext();){      
				var item=iter.next();          
				itemsMap.put(item.getName(),item.getValue() != null ? item.getValue() : "");  
				var formService = getFormProcess();
				var form=formService.doView(myFormId); 
				var field = form.findFieldByName(item.getName());
				var simpleName ="";
				if(isNotNull(field)){
					simpleName =field.getClass().getSimpleName();
				}
				if(("AttachmentUploadField".equals(simpleName) || "ImageUploadField".equals(simpleName) ) && isNotNull(item.getValue())){
					
					var JSONArray=new Packages.net.sf.json.JSONArray();
					var JSONObject=new Packages.net.sf.json.JSONObject(); 
					var oldFileArr = JSONArray.fromObject(item.getValue()); 
					
					for(var  i=0 ;i<oldFileArr.size();i++){
						var itemsMapfile  = new Packages.com.alibaba.fastjson.JSONObject();       
						var mode=oldFileArr.get(i);
						var fileNetPath =  mode.get("path");
						var fileName =  fileNetPath.substring(fileNetPath.lastIndexOf("/")+1);
						var savePath =  fileNetPath.substring(0,fileNetPath.lastIndexOf("/"));
						
						//拼接附件地址
						var webUser = getWebUser();
						var myToken = new Packages.cn.myapps.common.util.Security().getToken(sysfunction.JIANGUAN_USER_ID); 	      
						itemsMapfile.put("fileNetPath",sysfunction.MY_IP+fileNetPath+"?accessToken=" + myToken);
						itemsMapfile.put("savePath",savePath);
						itemsMapfile.put("fileName",fileName);
						userlist.add(itemsMapfile);
					}
				}
 			}     
 				 
 			var contentMap  = new Packages.com.alibaba.fastjson.JSONObject();     
 			contentMap.put("items",itemsMap);     
 			contentMap.put("applicationId",applicationId != null?applicationId:sysfunction.JIANGUAN_SYSTEMID);     
 			contentMap.put("id",docid);     
 			contentMap.put("formId",syncFormId);     
 			var documentMap = new Packages.com.alibaba.fastjson.JSONObject();     
 			documentMap.put("document",contentMap);     
 			var outputStr = documentMap.toJSONString();//转换为字符串       
 			//调用保存并启动流程接口     
    		 
			var sql = "select '"+getDomainid()+"' As domainid, rs.ITEM_REGIONId,rs.item_systemAdmin,rs.item_systemURL 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 targetApp = data.getItemValueAsString("systemURL");        
					var regionId = data.getItemValueAsString("region");            
					var FlowUrl = targetApp+"/runtime/"+applicationId+"/documents/activities/saveStartWorkFlow";      
					var token = new Packages.cn.myapps.common.util.Security().getToken(userId); //通过用户id获取token，才能以前端账号调用接口	     
					FlowUrl = FlowUrl +  "?accessToken=" + token;  
					println("FlowUrl=="+FlowUrl);
					println("outputStr=="+outputStr);
					println("userId=="+userId);		
                  try{
					var JSONString = URLConnector.post(FlowUrl,outputStr);    
                    println("JSONString=="+JSONString);		
					var errmsg = JSONString.get("errmsg"); 
                     println("errmsg=="+errmsg);	
					if(!"ok".equals(errmsg)){  
                      var errStr = "";
                      var errors = JSONString.get("errors"); 
                      if(errors==null){
                     	return "同步数据失败，请联系管理员";
                      }else{
                      	for(var iterator = errors.iterator();iterator.hasNext();){
                          var map1 = iterator.next();//取值
                          var errmsg= map1.get("errmsg");
                          errStr += errmsg+"</br>";
                        }
                        
                        return errStr;
                      }
					} 
                  } catch(e) {   
                    println("异常信息==>" + e);
                    return "同步数据失败，请联系管理员";     
                  }   
                  	println("==================");
					//发送附件userlist
					for(var userlistIterator = userlist.iterator();userlistIterator.hasNext();){     
						var dataFile = userlistIterator.next();
						
						var FlowUrlFile = targetApp+"/runtime/file/transfer";      
						FlowUrlFile = FlowUrlFile +  "?accessToken=" + token;   		
						var outputStrFile=dataFile.toJSONString();//转换为字符串    
						println("outputStrFile=="+outputStrFile);	
						var JSONStringFile = URLConnector.post(FlowUrlFile,outputStrFile);   
						var errmsg = JSONStringFile.get("errmsg");
						println("JSONStringFileerrmsg=="+errmsg);				
					}					
				}       
			}else{      
				return "提交审批失败，请先完善【从业单位信息】-【单位信息维护】中的数据监管配置后再上报数据。若您无此模块权限，请联系组织管理员操作或授权权限。";      
			}     
      	},
          updataDateToJgSystemByDocHZH : function (doc,myFormId,docid,syncFormId,applicationId,officeAddressID){         
 			var URLConnector = new Packages.cn.myapps.util.http.HttpRequestUtil();         
 			var domainid = getDomainid();       
 			var docid = docid;   
			
			//需先校验表单校验无问题。无问题则保存并推送数据，有未填则不推送,不执行之后逻辑，等待表单校验
			var docprocessValidata = getDocumentProcess();
			var paramsValidata = createParamsTable();
			var webUserValidata = getWebUser();
			var validata = docprocessValidata.doValidate(doc,paramsValidata,webUserValidata);
			if(validata.size() != 0 ){
					return "";	
			}
			
 			var itemsMap  = new Packages.com.alibaba.fastjson.JSONObject();      
 			var userlist = createObject("java.util.ArrayList");   
 			for(var iter=doc.getItems().iterator();iter.hasNext();){      
				var item=iter.next();          
				itemsMap.put(item.getName(),item.getValue() != null ? item.getValue() : "");  
				var formService = getFormProcess();
				var form=formService.doView(myFormId); 
				var field = form.findFieldByName(item.getName());
				var simpleName ="";
				if(isNotNull(field)){
					simpleName =field.getClass().getSimpleName();
				}
				if(("AttachmentUploadField".equals(simpleName) || "ImageUploadField".equals(simpleName) ) && isNotNull(item.getValue())){
					
					var JSONArray=new Packages.net.sf.json.JSONArray();
					var JSONObject=new Packages.net.sf.json.JSONObject(); 
					var oldFileArr = JSONArray.fromObject(item.getValue()); 
					
					for(var  i=0 ;i<oldFileArr.size();i++){
						var itemsMapfile  = new Packages.com.alibaba.fastjson.JSONObject();       
						var mode=oldFileArr.get(i);
						var fileNetPath =  mode.get("path");
						var fileName =  fileNetPath.substring(fileNetPath.lastIndexOf("/")+1);
						var savePath =  fileNetPath.substring(0,fileNetPath.lastIndexOf("/"));
						
						//拼接附件地址
						var webUser = getWebUser();
						var myToken = new Packages.cn.myapps.common.util.Security().getToken(sysfunction.JIANGUAN_USER_ID); 	      
						itemsMapfile.put("fileNetPath",sysfunction.MY_IP+fileNetPath+"?accessToken=" + myToken);
						itemsMapfile.put("savePath",savePath);
						itemsMapfile.put("fileName",fileName);
						userlist.add(itemsMapfile);
					}
				}
 			}     
 				 
 			var contentMap  = new Packages.com.alibaba.fastjson.JSONObject();     
 			contentMap.put("items",itemsMap);     
 			contentMap.put("applicationId",applicationId != null?applicationId:sysfunction.JIANGUAN_SYSTEMID);     
 			contentMap.put("id",docid);     
 			contentMap.put("formId",syncFormId);     
 			var documentMap = new Packages.com.alibaba.fastjson.JSONObject();     
 			documentMap.put("document",contentMap);     
 			var outputStr = documentMap.toJSONString();//转换为字符串       
 			//调用保存并启动流程接口     
    		 
			var sql = "select '"+getDomainid()+"' As domainid, rs.ITEM_REGIONId,rs.item_systemAdmin,rs.item_systemURL 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 targetApp = data.getItemValueAsString("systemURL");        
					var regionId = data.getItemValueAsString("region");            
					var FlowUrl = targetApp+"/runtime/"+applicationId+"/documents/activities/saveStartWorkFlow";      
					var token = new Packages.cn.myapps.common.util.Security().getToken(userId); //通过用户id获取token，才能以前端账号调用接口	     
					FlowUrl = FlowUrl +  "?accessToken=" + token;  
					println("FlowUrl=="+FlowUrl);
					println("outputStr=="+outputStr);
					println("userId=="+userId);		
                  try{
					var JSONString = URLConnector.post(FlowUrl,outputStr);    
                    println("JSONString=="+JSONString);		
					var errmsg = JSONString.get("errmsg"); 
                     println("errmsg=="+errmsg);	
					if(!"ok".equals(errmsg)){  
                      var errStr = "";
                      var errors = JSONString.get("errors"); 
                      if(errors==null){
                     	return "同步数据失败，请联系管理员";
                      }else{
                      	for(var iterator = errors.iterator();iterator.hasNext();){
                          var map1 = iterator.next();//取值
                          var errmsg= map1.get("errmsg");
                          errStr += errmsg+"</br>";
                        }
                        
                        return errStr;
                      }
					} 
                  } catch(e) {   
                    println("异常信息==>" + e);
                    return "同步数据失败，请联系管理员";     
                  }   
                  	println("==================");
					//发送附件userlist
					for(var userlistIterator = userlist.iterator();userlistIterator.hasNext();){     
						var dataFile = userlistIterator.next();
						
						var FlowUrlFile = targetApp+"/runtime/file/transfer";      
						FlowUrlFile = FlowUrlFile +  "?accessToken=" + token;   		
						var outputStrFile=dataFile.toJSONString();//转换为字符串    
						println("outputStrFile=="+outputStrFile);	
						var JSONStringFile = URLConnector.post(FlowUrlFile,outputStrFile);   
						var errmsg = JSONStringFile.get("errmsg");
						println("JSONStringFileerrmsg=="+errmsg);				
					}					
				}       
			}else{      
				return "提交审批失败，请先完善【从业单位信息】-【单位信息维护】中的数据监管配置后再上报数据。若您无此模块权限，请联系组织管理员操作或授权权限。";      
			}     
      	},
          deleteDateToJgSystemByDocHZH : function (attId,applicationId,officeAddressID){   
            var userlist = new Packages.com.alibaba.fastjson.JSONArray();
            var arrto = splitText(attId,";");   
            for(var i=0;i<arrto.length;i++){   
              userlist.add(arrto[i]);
            }
            var outputStr = userlist.toJSONString();//转换为字符串    
            //调用删除接口     
            var sql = "select '"+getDomainid()+"' As domainid, rs.ITEM_REGIONId,rs.item_systemAdmin,rs.item_systemURL 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+"' ";
            var datas = queryBySQL(sql);  
            if(datas.size()>0){
              var URLConnector = Packages.cn.hutool.http.HttpRequest;     
              for(var iterator = datas.iterator();iterator.hasNext();){    
                var data = iterator.next();  						
                var userId = data.getItemValueAsString("systemAdmin");           
                var targetApp = data.getItemValueAsString("systemURL");        
                var regionId = data.getItemValueAsString("region");               
                var token = new Packages.cn.myapps.common.util.Security().getToken(userId); //通过用户id获取token，才能以前端账号调用接口	     
                var FlowUrl = targetApp+"/runtime/"+applicationId+"/documents?accessToken=" + token;  
					println("FlowUrl=="+FlowUrl);
               		println("outputStr=="+outputStr);
                try{
                  var JSONString = URLConnector['delete'](FlowUrl).body(outputStr).execute().body();
                 
                }catch(e){
                  //println("异常信息==》" +e);
                  return "同步失败！";  
                }
              }  
			}else{      
				return "提交审批失败，请先完善【从业单位信息】-【单位信息维护】中的数据监管配置后再上报数据。若您无此模块权限，请联系组织管理员操作或授权权限。";      
			}      
           
      	}

}]]></content>
  <version>0</version>
</repositoryVO>