package nc.net.uapbd.activity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;

import org.restlet.engine.util.StringUtils;

import com.alibaba.fastjson.JSONObject;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IVOPersistence;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.net.uapbd.pojo.CODEVALUE;
import nc.net.uapbd.pojo.DATA;
import nc.net.uapbd.pojo.DATAINFO;
import nc.net.uapbd.pojo.DATAINFOS;
import nc.net.uapbd.pojo.ESB;
import nc.net.uapbd.pojo.PROPERTY;
import nc.net.uapbd.pojo.SPECIALITY;
import nc.vo.bd.bankaccount.BankAccbasVO;
import nc.vo.bd.bankdoc.BankdocVO;
import nc.vo.org.DeptVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFLiteralDate;

public  class PostUtils {
	


	public static BaseDAO baseDao = new BaseDAO();
	
	
	public static final List<String[]> accountingBookRequest = new ArrayList() {{
			add(new String[] {
					"NCC_FIN_ORG_PK","财务组织主键","pk_org"
			});
			add(new String[] {
					"NCC_FIN_ORG_CODE","财务组织编码","code"
			});
			add(new String[] {
					"NCC_FIN_ORG_NAME","财务组织名称","name"
			});
			add(new String[] {
					"NCC_FIN_PARENT_ORG_PK","上级财务组织主键","pk_fatherorg"
			});
			add(new String[] {
					"NCC_FIN_PARENT_ORG_CODE","上级财务组织编码","select code from org_orgs where pk_org =pk_fatherorg"
			});
			add(new String[] {
					"NCC_FIN_PARENT_ORG_NAME","上级财务组织名称","select name from org_orgs where pk_org =pk_fatherorg"
			});
			add(new String[] {
					"ACCOUNT_SET_PERIOD","账套建账时间","def43"
			});
			add(new String[] {
					"ACCOUNT_SEAL_PERIOD","账套封存时间","def44"
			});
			add(new String[] {
					"IS_COMMNAME_NULL","项目档案是否必填","def8"
			});
			//add
			add(new String[] {
					"IS_PROPERTY_OUTSIDE_CODE","物业是否外拓编码","select code from bd_defdoc where pk_defdoc =def15"
			});
			add(new String[] {
					"IS_PROPERTY_OUTSIDE_NAME","物业是否外拓名称","select name from bd_defdoc where pk_defdoc =def15"
			});
			add(new String[] {
					"PROPERTY_CHARGES_TYPE_CODE","物业接管方式编码","select code from bd_defdoc where pk_defdoc =def16"
			});
			add(new String[] {
					"PROPERTY_CHARGES_TYPE_NAME","物业接管方式名称","select name from bd_defdoc where pk_defdoc =def16"
			});
			add(new String[] {
					"IS_CONSOLIDATED_LISTING_STATEMENT_CODE","公司是否合并上市报表编码","select code from bd_defdoc where pk_defdoc =def20"
			});
			add(new String[] {
					"IS_CONSOLIDATED_LISTING_STATEMENT_NAME","公司是否合并上市报表名称","select name from bd_defdoc where pk_defdoc =def20"
			});
			add(new String[] {
					"ACTUAL_ACCOUNTING_SYSTEM_CODE","实际核算系统编码","select code from bd_defdoc where pk_defdoc =def37"
			});
			add(new String[] {
					"ACTUAL_ACCOUNTING_SYSTEM_NAME","实际核算系统名称","select name from bd_defdoc where pk_defdoc =def37"
			});
			add(new String[] {
					"EQUITY_SITUATION_CODE","股权情况编码","select code from bd_defdoc where pk_defdoc =def41"
			});
			add(new String[] {
					"EQUITY_SITUATION_NAME","股权情况名称","select name from bd_defdoc where pk_defdoc =def41"
			});
			add(new String[] {
					"ENABLE_STATUS","账套使用状态","enablestate"
			});
			add(new String[] {
					"AREA_CODE","所属区域编码","select code from bd_defdoc where pk_defdoc =def11"
			});
			add(new String[] {
					"AREA_NAME","所属区域名称","select name from bd_defdoc where pk_defdoc =def11"
			});
			add(new String[] {
					"PLATE_CODE","所属板块编码","select code from bd_defdoc where pk_defdoc =def6"
			});
			add(new String[] {
					"PLATE_NAME","所属板块名称","select name from bd_defdoc where pk_defdoc =def6"
			});
			add(new String[] {
					"IS_VIRTUAL_UNIT","是否虚拟单位","def30"
			});
			add(new String[] {
					"IS_POST_TO_MDM","是否已传递MDM主数据","def46"
			});
			add(new String[] {
					"CREATE_USER_CODE","创建人编码","select user_code from sm_user where cuserid =creator"
			});
			add(new String[] {
					"CREATE_USER_NAME","创建人名称","select user_name from sm_user where cuserid =creator"
			});
			add(new String[] {
					"CREATE_TIME","创建时间","creationtime"
			});
			add(new String[] {
					"LAST_UPDATE_USER_CODE","更新人编码","select user_code from sm_user where cuserid =modifier"
			});
			add(new String[] {
					"LAST_UPDATE_USER_NAME","更新人名称","select user_name from sm_user where cuserid =modifier"
			});
			add(new String[] {
					"LAST_UPDATE_TIME","更新时间","modifiedtime"
			});
			add(new String[] {
					"IS_DELETE","删除状态","dr"
			});
			
	}};
	
	
	public static final List<String[]> deptRequest = new ArrayList() {{
		add(new String[] {
				"NCC_FIN_DEPT_PK","财务部门主键","pk_dept"
		});
		add(new String[] {
				"NCC_FIN_DEPT_CODE","财务部门编码","code"
		});
		add(new String[] {
				"NCC_FIN_DEPT_NAME","财务部门名称","name"
		});
		add(new String[] {
				"NCC_FIN_ORG_PK","所属财务组织主键","pk_org"
		});
		add(new String[] {
				"NCC_FIN_ORG_CODE","所属财务组织编码","select code from org_orgs where pk_org =pk_org"
		});
		add(new String[] {
				"NCC_FIN_ORG_NAME","所属财务组织名称","select name from org_orgs where pk_org =pk_org"
		});
		add(new String[] {
				"NCC_PARENT_DEPT_PK","上级财务部门主键","pk_fatherorg"
		});
		add(new String[] {
				"NCC_PARENT_DEPT_CODE","上级财务部门编码","select code from org_orgs where pk_org =pk_fatherorg"
		});
		add(new String[] {
				"NCC_PARENT_DEPT_NAME","上级财务部门名称","select name from org_orgs where pk_org =pk_fatherorg"
		});
		add(new String[] {
				"DEPT_TYPE","部门类型","depttype"
		});
		add(new String[] {
				"ESTABLISH_DATE","部门成立时间","createdate"
		});
		add(new String[] {
				"IS_BUDGET_UTIL","是否预算单位","orgtype17"
		});
		add(new String[] {
				"ENABLE_STATUS","部门使用状态","enablestate"
		});
		add(new String[] {
				"IS_POST_TO_MDM","是否已传递MDM主数据","def15"
		});
		add(new String[] {
				"CREATE_USER_CODE","创建人编码","select user_code from sm_user where cuserid =creator"
		});
		add(new String[] {
				"CREATE_USER_NAME","创建人名称","select user_name from sm_user where cuserid =creator"
		});
		add(new String[] {
				"CREATE_TIME","创建时间","creationtime"
		});
		add(new String[] {
				"LAST_UPDATE_USER_CODE","更新人编码","select user_code from sm_user where cuserid =modifier"
		});
		add(new String[] {
				"LAST_UPDATE_USER_NAME","更新人名称","select user_name from sm_user where cuserid =modifier"
		});
		add(new String[] {
				"LAST_UPDATE_TIME","更新时间","modifiedtime"
		});
		add(new String[] {
				"IS_DELETE","删除状态","select dr from org_dept where pk_dept=pk_dept"
		});
}};



public static final List<String[]> bankdocRequest = new ArrayList() {{
	add(new String[] {
			"NCC_BANK_DOC_PK","银行档案主键","pk_bankdoc"
	});
	add(new String[] {
			"BANK_CODE","银行编码","code"
	});
	add(new String[] {
			"BANK_NAME","银行名称","name"
	});
	add(new String[] {
			"SHORT_NAME","银行简称","shortname"
	});
	add(new String[] {
			"NCC_BANK_TYPE_PK","银行类型主键","pk_banktype"
	});
	add(new String[] {
			"BANK_TYPE_CODE","银行类型编码","select code from bd_banktype where pk_banktype =pk_banktype"
	});
	add(new String[] {
			"BANK_TYPE_NAME","银行类型名称","select name from bd_banktype where pk_banktype =pk_banktype"
	});
	add(new String[] {
			"NCC_PARENT_DEPT_CODE","上级财务部门编码","select code from org_orgs where pk_org =pk_fatherorg"
	});
	add(new String[] {
			"COUNTRY","国家地区","select name from bd_countryzone where pk_country =pk_country"
	});
	add(new String[] {
			"AREA_CODE","地区代码编码","select code from bd_defdoc where pk_defdoc =areacode"
	});
	add(new String[] {
			"AREA_NAME","地区代码名称","select name from bd_defdoc where pk_defdoc=areacode"
	});
	add(new String[] {
			"BANK_AREA","开户地区","bankarea"
	});
	add(new String[] {
			"ORG_NUMBER","机构号分行号","orgnumber"
	});
	//123
	add(new String[] {
			"PROVINCE","省份","province"
	});
	add(new String[] {
			"CITY","城市","city"
	});
	add(new String[] {
			"COMBINE_NUM","联行号","pcombinenum"
	});
	add(new String[] {
			"IS_POST_TO_MDM","是否已传递MDM主数据","def1"
	});
	add(new String[] {
			"CREATE_USER_CODE","创建人编码","select user_code from sm_user where cuserid =creator"
	});
	add(new String[] {
			"CREATE_USER_NAME","创建人名称","select user_name from sm_user where cuserid =creator"
	});
	add(new String[] {
			"CREATE_TIME","创建时间","creationtime"
	});
	add(new String[] {
			"LAST_UPDATE_USER_CODE","修改人编码","select user_code from sm_user where cuserid =modifier"
	});
	add(new String[] {
			"LAST_UPDATE_USER_NAME","修改人名称","select user_name from sm_user where cuserid =modifier"
	});
	add(new String[] {
			"LAST_UPDATE_TIME","更新时间","modifiedtime"
	});
	add(new String[] {
			"IS_DELETE","删除状态","dr"
	});
}};

public static final List<String[]> bankaccbasRequest = new ArrayList() {{
	add(new String[] {
			"NCC_BANK_ACCBAS_PK","银行账户主键","pk_bankaccbas"
	});
	add(new String[] {
			"ACC_NUM","账号","accnum"
	});
	add(new String[] {
			"ACC_NAME","户名","accname"
	});
	add(new String[] {
			"OPENING_BANK","开户银行","pk_bankdoc"
	});
	add(new String[] {
			"OPENING_BANK_CODE","开户银行编码","select code from bd_bankdoc where pk_bankdoc=pk_bankdoc"
	});
	add(new String[] {
			"OPENING_BANK_NAME","开户银行名称","select name from bd_bankdoc where pk_bankdoc=pk_bankdoc"
	});
	add(new String[] {
			"BANK_TYPE","银行类别","pk_banktype"
	});
	add(new String[] {
			"BANK_TYPE_CODE","银行类别编码","select code from bd_banktype where pk_banktype =pk_banktype"
	});
	add(new String[] {
			"BANK_TYPE_NAME","银行类别名称","select name from bd_banktype where pk_banktype =pk_banktype"
	});
	add(new String[] {
			"OPENING_FIN_ORG","开户单位","financeorg"
	});
	add(new String[] {
			"OPENING_FIN_ORG_CODE","开户单位编码","select code from org_financeorg  where pk_financeorg =financeorg"
	});
	add(new String[] {
			"OPENING_FIN_ORG_NAME","开户单位名称","select name from org_financeorg  where pk_financeorg =financeorg"
	});
	add(new String[] {
			"CONTROL_ORG","核算归属组织","controlorg"
	});
	//123
	add(new String[] {
			"CONTROL_ORG_CODE","核算归属组织编码","select code from org_financeorg where pk_financeorg =controlorg"
	});
	add(new String[] {
			"CONTROL_ORG_NAME","核算归属组织名称","select name from org_financeorg where pk_financeorg =controlorg"
	});
	add(new String[] {
			"ACC_OPEN_DATE","开户日期","accopendate"
	});
	add(new String[] {
			"ENABLE_STATE","启用状态","enablestate"
	});
	add(new String[] {
			"ENABLE_TIME","启用日期","enabletime"
	});
	add(new String[] {
			"ENABLE_USER","启用人","enableuser"
	});
	add(new String[] {
			"ENABLE_USER_CODE","启用人编码","select user_code from sm_user  where cuserid =enableuser"
	});
	add(new String[] {
			"ENABLE_USER_NAME","启用人名称","select user_name from sm_user  where cuserid =enableuser"
	});
	add(new String[] {
			"DISABLE_TIME","停用日期","disabletime"
	});
	add(new String[] {
			"DISABLE_USER","停用人","disableuser"
	});
	add(new String[] {
			"DISABLE_USER_CODE","停用人编码","select user_code from sm_user  where cuserid =disableuser"
	});
	add(new String[] {
			"DISABLE_USER_NAME","停用人名称","select user_name from sm_user  where cuserid =disableuser"
	});
	add(new String[] {
			"ACC_XH_DATE","销户日期","accxhdate"
	});
	add(new String[] {
			"ARAP_PROP","收付属性","arapprop"
	});
	add(new String[] {
			"ACC_ATTRIBUTE","账户属性","accattribute"
	});
	add(new String[] {
			"ACC_STATE","账户状态","accstate"
	});
	add(new String[] {
			"NET_QUERY_FLAG","银企直联开通状态","netqueryflag"
	});
	add(new String[] {
			"IS_POST_TO_MDM","是否已传递MDM主数据","def26"
	});
	add(new String[] {
			"CREATE_USER_CODE","创建人编码","select user_code from sm_user  where cuserid =creator"
	});
	add(new String[] {
			"CREATE_USER_NAME","创建人名称","select user_name from sm_user  where cuserid =creator"
	});
	add(new String[] {
			"CREATE_TIME","创建时间","creationtime"
	});
	add(new String[] {
			"LAST_UPDATE_USER_CODE","更新人编码","select user_code from sm_user  where cuserid =modifier"
	});
	add(new String[] {
			"LAST_UPDATE_USER_NAME","更新人名称","select user_name from sm_user  where cuserid =modifier"
	});
	add(new String[] {
			"LAST_UPDATE_TIME","更新时间","modifiedtime"
	});
	add(new String[] {
			"CURR_TYPE","币种","select pk_currtype from bd_bankaccsub where pk_bankaccbas =pk_bankaccbas"
	});
	add(new String[] {
			"CURR_TYPE_CODE","币种编码","select code from bd_currtype where pk_currtype =select pk_currtype from bd_bankaccsub where pk_bankaccbas =pk_bankaccbas"
	});
	add(new String[] {
			"CURR_TYPE_NAME","币种名称","select name from bd_currtype where pk_currtype =select pk_currtype from bd_bankaccsub where pk_bankaccbas =pk_bankaccbas"
	});
	add(new String[] {
			"IS_DEFAULT","默认","select isdefault from bd_bankaccsub where pk_bankaccbas =pk_bankaccbas"
	});
	add(new String[] {
			"IS_TRADE","交易账户","select istrade from bd_bankaccsub where pk_bankaccbas =pk_bankaccbas"
	});
	add(new String[] {
			"IS_DELETE","删除状态","dr"
	});
}};

	
	public SPECIALITY speciality = new SPECIALITY();
	
//	public static JSONObject newRequestObj(String PUUID) {
//		JSONObject obj = new JSONObject() {{
//			put("ESB",new JSONObject() {{
//				put("DATAINFOS", new JSONObject() {{
//					put("DATAINFO",new JSONArray());
//					put("PUUID",PUUID);
//				}});
//			}} );
//		}};
//		return obj;
//	}
//	
//	public static JSONObject newDataInfo(JSONObject data,JSONObject meta) {
//		meta.getJSONObject("ESB").getJSONObject("DATAINFOS").getJSONArray("DATAINFO").add(data);
//		return meta;
//	}
//	
//	public static JSONObject newColValue(JSONArray property,String code) {
//		JSONObject codevalue = new JSONObject() {{
//			put("SPECIALITY",new JSONObject() {{
//				put("PROPERTY",property);
//			}});
//			put("SPECIALITYCODE",code);
//		}};
//		return codevalue;
//	}
	
//	public static JSONArray newProperty(JSONArray property,String code,String name,String value) {
//		JSONObject obj = new JSONObject() {
//			{
//				put("PROPERTYCODE",code);
//				put("PROPERTYNAME",name);
//				put("PROPERTYVALUE",value);
//			}
//		};
//		property.add(obj);
//		return property;
//	}
	
	public static Map<String,List<SPECIALITY>> getSpeciality(List<Map<String,List<Map<String,Object>>>> values) {
		Map<String,List<SPECIALITY>> map1 = new HashMap();
		
		for(Map<String,List<Map<String,Object>>> value:values) {
			List<SPECIALITY> listspeciality = new ArrayList();
			SPECIALITY speciality = new SPECIALITY();
			List<PROPERTY> propertys = new ArrayList();
			value.forEach((k,v)->{
				for(Map<String,Object> map:value.get(k)) {
					PROPERTY property = new PROPERTY();
					if(map.get("PROPERTYVALUE") instanceof UFDateTime || map.get("PROPERTYVALUE") instanceof UFLiteralDate) {
						property.setPROPERTYCODE( map.get("PROPERTYCODE"));
						property.setPROPERTYNAME( map.get("PROPERTYNAME"));
						property.setPROPERTYVALUE(map.get("PROPERTYVALUE").toString());
						propertys.add(property);
					}else {
					property.setPROPERTYCODE( map.get("PROPERTYCODE"));
					property.setPROPERTYNAME( map.get("PROPERTYNAME"));
					property.setPROPERTYVALUE( map.get("PROPERTYVALUE").toString());
					propertys.add(property);
					}
				}
				speciality.setPROPERTY(propertys);
				//此处要改
				speciality.setSPECIALITYCODE(k);
				listspeciality.add(speciality);
			});
			
			
			
			//uuid
			String uuid = UUID.randomUUID().toString().replaceAll("-","");
			map1.put(uuid,listspeciality);
		}
		
		
//		
//		for(Map<String,List<Map<String,String>>> value:values) {
//			List<SPECIALITY> listspeciality = new ArrayList();
//			SPECIALITY speciality = new SPECIALITY();
//			List<PROPERTY> propertys = new ArrayList();
//			for(Map<String,String> map:value.get(var1)) {
//				PROPERTY property = new PROPERTY();
//				property.setPROPERTYCODE( map.get("PROPERTYCODE"));
//				property.setPROPERTYNAME( map.get("PROPERTYNAME"));
//				property.setPROPERTYVALUE( map.get("PROPERTYVALUE"));
//				propertys.add(property);
//			}
//			speciality.setPROPERTY(propertys);
//			//此处要改
//			speciality.setSPECIALITYCODE(value.get(0).get("code"));
//			listspeciality.add(speciality);
//			//uuid
//			String uuid = UUID.randomUUID().toString().replaceAll("-","");
//			map1.put(uuid,listspeciality);
//		}
		
		return map1;
	}
	
	public static ESB getESB(Map<String,List<SPECIALITY>> map) {
		DATA data = new DATA();
		ESB esb = new ESB();
		DATAINFOS datainfos = new DATAINFOS();
		List<DATAINFO> listdatainfo = new ArrayList();
		
		map.forEach((key,value)->{
			DATAINFO datainfo = new DATAINFO();
			CODEVALUE codevalue = new CODEVALUE();
			codevalue.setSPECIALITY(value);
			datainfo.setCODEVALUE(codevalue);
			datainfo.setUUID(key);
			listdatainfo.add(datainfo);
		});
		datainfos.setDATAINFO(listdatainfo);
		String puuid = UUID.randomUUID().toString().replaceAll("-","");
		datainfos.setPUUID(puuid);
		data.setDATAINFOS(datainfos);
		esb.setDATA(data);
		return esb;
		
	}
	
	
	

	public static List<Map<String,List<Map<String,Object>>>> VOHandler(SuperVO[] vos) {
		List<Map<String,List<Map<String,Object>>>> listMap = new ArrayList(); 
		for(SuperVO vo:vos) {
			Map<String,List<Map<String,Object>>> every = new HashMap();
			List<Map<String,Object>> key = inputProperty(vo);
			//key的值是SPECIALITYCODE
			every.put("JBXX", key);
			listMap.add(every);
//			if(vo instanceof AccountingBookVO) {
//				Map<String,List<Map<String,String>>> every = new HashMap();
//				List<Map<String,String>> key = inputProperty(vo);
//				//key的值是SPECIALITYCODE
//				every.put("JBXX", key);
//				listMap.add(every);
//			}else if(vo instanceof DeptVO) {
//				Map<String,List<Map<String,String>>> every = new HashMap();
//				List<Map<String,String>> key = inputProperty(vo);
//				//key的值是SPECIALITYCODE
//				every.put("JBXX", key);
//				listMap.add(every);
//			}
		}
		return listMap;
		
		
		
	}
	
	
	//主数据发送报文
	public static JSONObject sendHttpJsonPost(String url,String param,String syncode,String puuid) throws Exception{  
	       HttpURLConnection httpURLConnection = null;  
	       OutputStream out = null; //写  
	       BufferedReader br = null;   //读  
	       int responseCode = 0;    //远程主机响应的HTTP状态码  
	       StringBuffer result=new StringBuffer();  
	       try{  
	           URL sendUrl = new URL(url);  
	           httpURLConnection = (HttpURLConnection)sendUrl.openConnection();  
	           //post方式请求  
	           httpURLConnection.setRequestMethod("POST");  
	           //一定要设置 Content-Type 要不然服务端接收不到参数  
	           httpURLConnection.setRequestProperty("Content-Type", "application/Json; charset=UTF-8");  
	           httpURLConnection.setRequestProperty("usercode", "ncc");  
	           httpURLConnection.setRequestProperty("password", "ncc");  
	           httpURLConnection.setRequestProperty("sysid", "NCC");  
	           httpURLConnection.setRequestProperty("syncode", syncode);  
	           httpURLConnection.setRequestProperty("puuid", puuid);  
	           //指示应用程序要将数据写入URL连接,其值默认为false（是否传参）  
	           httpURLConnection.setDoOutput(true);  
	           httpURLConnection.setDoInput(true);   
	             
	           httpURLConnection.setUseCaches(false);//不使用缓存
	           httpURLConnection.setConnectTimeout(120000); //120秒连接超时  
	           httpURLConnection.setReadTimeout(120000);    //120秒读取超时  
	           //传入参数  
	           out = httpURLConnection.getOutputStream();  
	           out.write(param.getBytes());  
	           out.flush(); //清空缓冲区,发送数据  
	           responseCode = httpURLConnection.getResponseCode();  
	           //获取请求的资源  
	           br = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(),"UTF-8"));  
	           String line="";
	           while ((line = br.readLine()) != null) {
	               result.append(line);
	           }
	       }catch(Exception e) {
	    	   throw e;
	       }finally{
				try {
					if(out!=null)
						out.close();
					if(br!=null)
						br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}  
	       }
	       if(result!=null && result.length()>0)//转换为Json对象输出
	    	   return com.alibaba.fastjson.JSONObject.parseObject(result.toString());
	       else
	    	   return null; 
	   }
	
	
	public static  List<Map<String,Object>> inputProperty(SuperVO vo) {
		List<Map<String,Object>> key = new ArrayList();
		Map<String,String> map = new HashMap<String,String>();
		List<String[]> list = null;
		
		decideList(vo).forEach((k)->{
			Map<String,Object> every = new HashMap();
			every.put("PROPERTYCODE",k[0] );
			every.put("PROPERTYNAME", k[1]);
			if(k[2]==null||k[2]=="") {				
			}else {
			if(Pattern.matches(".*select.*", k[2])) {
				String result = query(k[2],vo);
				every.put("PROPERTYVALUE", result);	
			}else {
			every.put("PROPERTYVALUE", vo.getAttributeValue(k[2]));
			}
			if(every.get("PROPERTYVALUE")!=null) {
				key.add(every);
			}
			
			}
		});
		return key;
	}
	
	
	public static String query(String expression,SuperVO vo) {
			String result = null;		
			String[] strs = expression.split("=",2);
			if(Pattern.matches(".*select.*", strs[1])) {
				String[] strs1 = strs[1].split("=");
				strs1[0] = strs1[0] + "= ?";
				SQLParameter param = new SQLParameter();
				param.addParam(vo.getAttributeValue(strs1[1]));
				try {
					strs[1] = baseDao.executeQuery(strs1[0], param, new ColumnProcessor())==null ?null:baseDao.executeQuery(strs1[0], param, new ColumnProcessor()).toString();
				} catch (DAOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				if(!StringUtils.isNullOrEmpty(strs[1])) {
					strs[0] = strs[0] + "= ?";
					SQLParameter param1 = new SQLParameter();
					param1.addParam(strs[1]);	
					try {
						result = baseDao.executeQuery(strs[0], param1, new ColumnProcessor())==null ?null:baseDao.executeQuery(strs[0], param1, new ColumnProcessor()).toString();
					} catch (DAOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					return result;
					}
			}
			if(!StringUtils.isNullOrEmpty(strs[1])&&vo.getAttributeValue(strs[1])!=null) {
			strs[0] = strs[0] + "= ?";
			SQLParameter param = new SQLParameter();
			
			param.addParam(vo.getAttributeValue(strs[1]));	
			try {
				result = baseDao.executeQuery(strs[0], param, new ColumnProcessor())==null ?null:baseDao.executeQuery(strs[0], param, new ColumnProcessor()).toString();
			} catch (DAOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			}
		return result;
	}
	
	public static List<String[]> decideList(SuperVO vo){
		
		if(vo instanceof OrgVO) {
			return accountingBookRequest;
		}else if(vo instanceof DeptVO) {
			return deptRequest;
		}else if(vo instanceof BankAccbasVO) {
			return bankaccbasRequest;
		}else if(vo instanceof BankdocVO) {
			return bankdocRequest;
		}
		return null;
	}
	
	public static void updateAfterSuccess(SuperVO vo,boolean ifSuccess) throws BusinessException {
		IVOPersistence service = NCLocator.getInstance().lookup(IVOPersistence.class);
		String insertV = "是";
		if(ifSuccess!=true) {
			insertV = "否";
		}
		if(vo instanceof OrgVO) {
			vo.setAttributeValue("def46", insertV);
		}else if(vo instanceof DeptVO) {
			vo.setAttributeValue("def15", insertV);
		}else if(vo instanceof BankAccbasVO) {
			vo.setAttributeValue("def26", insertV);
		}else if(vo instanceof BankdocVO) {
			vo.setAttributeValue("def1", insertV);
		}
		if(vo.getPrimaryKey()!=null) {
			service.updateVO(vo);
		}else {
			service.insertVO(vo);
		}
		
	}
	
}
