1.首先链接到lodp
package nc.impl.erm.informerplugin;import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.UUID;import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;import uap.iweb.log.Logger;
import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.pub.pa.PreAlertObject;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.erm.ladpdata.LadpDataVO;
import nc.vo.pub.BusinessException;import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.ldap.LdapContext;import ch.qos.logback.core.pattern.Converter;import com.itextpdf.text.List;/*** @author tjr* @date 2016-08-11* @miaos 后台任务,定时将到账通知单(收款情况)发送到中间表* */
public class InformerToCrmPlugin implements IBackgroundWorkPlugin {ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();BaseDAO dao = new BaseDAO();public PreAlertObject executeTask(BgWorkingContext arg0)throws BusinessException {Hashtable<String, String> env = new Hashtable<String, String>();env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");env.put(Context.SECURITY_PRINCIPAL, "test2");env.put(Context.SECURITY_CREDENTIALS, "abc@123");env.put(Context.SECURITY_AUTHENTICATION, "simple");env.put(Context.PROVIDER_URL, "ldap://192.168.0.5:389");
//      env.put("java.naming.ldap.attributes.binary","objectGUID");
//       try {InitialDirContext ctx = new InitialDirContext(env);// Add by jm ArrayList<String> arr = new ArrayList<String>();
//          arr.add("淮安映客互娱网络信息有限公司");  arr.add("inke");
//          arr.add("Dark werewolf");
//          arr.add("inmyworld");
//          arr.add("cs_inke");Iterator<String> sListIterator = arr.iterator(); while(sListIterator.hasNext()){  String e = sListIterator.next();  //  Add by jm String searchBase = "ou="+e+",dc=inke,dc=intra";
//          String searchBase = "ou=cs_inke,dc=inke,dc=intra";
//          String searchBase = "dc=inke,dc=intra";ctx.lookup(searchBase);//
//          SearchControls searchCtls = new SearchControls();
//          searchCtls.setSearchScope(SearchControls.OBJECT_SCOPE);     //NamingEnumeration<?> answer = ctx.search(searchBase, "objectClass=*", null);int d = 0;while (answer.hasMoreElements()) {// 遍历结果集   Logger.error("aaaa============="+d++);SearchResult sr = (SearchResult) answer.next();// 得到符合搜索条件的DNString dn = (String) sr.getNameInNamespace();String name = sr.getName();
//              String guid =getGUID(sr.getAttributes().get("objectGUID").get().toString().getBytes());   String objectClass = sr.getAttributes().get("objectClass").get().toString();
//              String street = sr.getAttributes().get("StreetAddress").get().toString();//String street = "";String codeco = "";//部门编码if(sr.getAttributes().get("street")!= null){street = sr.getAttributes().get("street").get().toString();}byte[] GUID = (byte[])sr.getAttributes().get("objectGUID").get();  String guid =getGUID(GUID);
//               String street = sr.getAttributes().get("street").get().toString(); //公司编码if(sr.getAttributes().get("co")!= null){codeco = sr.getAttributes().get("co").get().toString();}HashMap<String, String> insert = new HashMap<String, String>();             insert.put("guid", guid);insert.put("name", name);//
//              insert.put("def1","inke");insert.put("def1",e);insert.put("def2",street);insert.put("def4",codeco);//insert.put("objectClass", objectClass);insert.put("fatherguid", null);list.add(insert);  ArrayList<HashMap<String, String>> list1 = getDeptPsn(ctx,dn,"objectClass=*",guid);for(int i=0;i<list1.size();i++){HashMap<?, ?> map1 = (HashMap<?, ?>) list1.get(i);ArrayList<HashMap<String, String>> list2 = getDeptPsn(ctx,map1.get("dn").toString(),"objectClass=*",map1.get("guid").toString());if(list2.size()>0){//getDeptPsn(ctx,map1.get("dn").toString(),"objectClass=*",map1.get("guid").toString());//}else{for(int ii=0;ii<list2.size();ii++){ HashMap<?, ?> map2 = (HashMap<?, ?>) list2.get(ii);ArrayList<HashMap<String, String>> list3 = getDeptPsn(ctx,map2.get("dn").toString(),"objectClass=*",map2.get("guid").toString());if(list3.size()>0){//getDeptPsn(ctx,map2.get("dn").toString(),"objectClass=*",map2.get("guid").toString());//}else{for(int iii=0;iii<list3.size();iii++){HashMap<?, ?> map3 = (HashMap<?, ?>) list3.get(iii);ArrayList<HashMap<String, String>> list4 = getDeptPsn(ctx,map3.get("dn").toString(),"objectClass=*",map3.get("guid").toString());if(list4.size()>=0){//getDeptPsn(ctx,map3.get("dn").toString(),"objectClass=*",map3.get("guid").toString());//}else{for(int iiii=0;iiii<list4.size();iiii++){HashMap<?, ?> map4 = (HashMap<?, ?>) list4.get(iiii);ArrayList<HashMap<String, String>> list5 = getDeptPsn(ctx,map4.get("dn").toString(),"objectClass=*",map4.get("guid").toString());if(list5.size()>=0){//getDeptPsn(ctx,map4.get("dn").toString(),"objectClass=*",map4.get("guid").toString());//}else{for(int iiiii=0;iiiii<list5.size();iiiii++){HashMap<?, ?> map5 = (HashMap<?, ?>) list5.get(iii);ArrayList<HashMap<String, String>> list6 = getDeptPsn(ctx,map5.get("dn").toString(),"objectClass=*",map5.get("guid").toString());if(list6.size()>=0){getDeptPsn(ctx,map5.get("dn").toString(),"objectClass=*",map5.get("guid").toString());}}}}}}}}}}}            }  ctx.close();setLadpData(list);} catch (Exception e) {e.printStackTrace();}return null;}@SuppressWarnings({ "rawtypes", "unchecked" })private ArrayList<HashMap<String, String>> getDeptPsn(InitialDirContext ctx,String dname,String searchFilter,String fid){ArrayList<HashMap<String, String>> list1 = new ArrayList<HashMap<String, String>>();try {NamingEnumeration<?> iter = ctx.search(dname,searchFilter,null);while (iter.hasMoreElements()) {// 遍历结果集HashMap<String, String> map = new HashMap<String, String>();SearchResult sr = (SearchResult) iter.next();// 得到符合搜索条件的DNString dn = (String) sr.getNameInNamespace();              Attributes attrs = sr.getAttributes();String name = sr.getName();//byte[] GUID = (byte[])sr.getAttributes().get("objectGUID").get();  String guid =getGUID(GUID); //if(fid.equals(guid)){continue;}map.put("dn", dn);map.put("guid", guid);String objectClass = attrs.get("objectClass").toString();HashMap<String, String> insert = new HashMap<String, String>();//获取部门if(objectClass.contains("organizationalUnit")){//部门下的公司编码if(attrs.get("Co")!= null){insert.put("def4", attrs.get("Co").get().toString());}//部门编码if(attrs.get("street")!= null){insert.put("def2", attrs.get("street").get().toString());}//标示if(attrs.get("description")!= null){insert.put("def5", attrs.get("description").get().toString());}insert.put("guid", guid);insert.put("name", name.replace("OU=", ""));insert.put("objectClass", "organizationalUnit");insert.put("fatherguid", fid);list.add(insert);list1.add(map);}if(objectClass.contains("user")){//人员编码     if(attrs.get("EmployeeID")!=null){insert.put("def3", attrs.get("EmployeeID").get().toString());}//公司编码if(attrs.get("Company")!= null){insert.put("def4", attrs.get("Company").get().toString());}//人员下的部门编码if(attrs.get("Department")!= null){insert.put("def2", attrs.get("Department").get().toString());}if (attrs.get("samaccountName")!=null){insert.put("samaccountName", attrs.get("samaccountName").get().toString());}if (sr.getAttributes().get("sn")!=null){insert.put("sn", attrs.get("sn").get().toString().replace("CN=", "")); }if (sr.getAttributes().get("mail")!=null){insert.put("mail", attrs.get("mail").get().toString());}insert.put("guid", guid);insert.put("name", name);insert.put("objectClass", "user");insert.put("fatherguid", fid);list.add(insert);}                   }} catch (NamingException e) {e.printStackTrace();} return list1;}private void setLadpData(ArrayList<HashMap<String, String>> ladplist){ArrayList nclist = getAdGUID();for (int i = 0; i < ladplist.size(); i++) {HashMap<?, ?> map = (HashMap<?, ?>) ladplist.get(i);LadpDataVO vo = new LadpDataVO();if(map.get("guid")!=null){vo.setGuid(map.get("guid").toString());}if(map.get("dn")!=null){vo.setDn(map.get("dn").toString());}if(map.get("objectClass")!=null){vo.setObjectClass(map.get("objectClass").toString());}if(map.get("fatherguid")!=null){vo.setFatherguid(map.get("fatherguid").toString());}if(map.get("samaccountName")!=null){vo.setSamaccountName(map.get("samaccountName").toString());}if(map.get("name")!=null){vo.setSn(map.get("name").toString().replace("CN=", "").replace("OU=", ""));}if(map.get("mail")!=null){vo.setMail(map.get("mail").toString());}if(map.get("orgcode")!=null){vo.setOrgcode(map.get("orgcode").toString());}if(map.get("deptcode")!=null){vo.setDeptcode(map.get("deptcode").toString());}if(map.get("psncode")!=null){vo.setPsncode(map.get("psncode").toString());}if(map.get("def1")!=null){vo.setDef1(map.get("def1").toString());}if(map.get("def2")!=null){vo.setDef2(map.get("def2").toString());}if(map.get("def3")!=null){vo.setDef3(map.get("def3").toString());}if(map.get("def4")!=null){vo.setDef4(map.get("def4").toString());}if(map.get("def5")!=null){vo.setDef5(map.get("def5").toString());}    if(map.get("def6")!=null){vo.setDef6(map.get("def6").toString());}if(map.get("def7")!=null){vo.setDef7(map.get("def7").toString());}if(map.get("def8")!=null){vo.setDef8(map.get("def8").toString());}if(map.get("def9")!=null){vo.setDef9(map.get("def9").toString());}if(map.get("def10")!=null){vo.setDef10(map.get("def10").toString());}  String sf = "N";String pk_ladp = "";//判断逻辑是如果guid一样,且上级父节点一样且不为空的话,就更新数据if(nclist.size()>0){  for(int j=0;j<nclist.size(); j++){HashMap ncmap = (HashMap) nclist.get(j);if(ncmap.get("guid")!=null){if(vo.getGuid().equals(ncmap.get("guid").toString()) ){      //&& !ncmap.get("objectClass").toString().equals("top")         sf = "NN";if(map.get("fatherguid") != null && ncmap.get("fatherguid") != null){if(ncmap.get("fatherguid").toString().equals(map.get("fatherguid").toString()) ){  //ncmap.get("SN").toString().equals(map.get("name").toString())pk_ladp = ncmap.get("pk_ladp").toString();sf = "Y";}}}}}}try {if(sf.equals("Y")){vo.setPk_ladp(pk_ladp);dao.updateVO(vo);}if(sf.equals("N")){dao.insertVO(vo);}} catch (DAOException e) {e.printStackTrace();}}}private static String getGUID(byte[] GUID) {  String strGUID = "";  String byteGUID = ""; for (int c=0;c<GUID.length;c++) {  byteGUID = byteGUID + "\\" + AddLeadingZero((int)GUID[c] & 0xFF);  }strGUID = strGUID + AddLeadingZero((int)GUID[0] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[1] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[2] & 0xFF);strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[3] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[4] & 0xFF);  strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[5] & 0xFF);  strGUID = strGUID + "-";  strGUID = strGUID + AddLeadingZero((int)GUID[6] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[7] & 0xFF);    strGUID = strGUID + "-";  strGUID = strGUID + AddLeadingZero((int)GUID[8] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[9] & 0xFF);  strGUID = strGUID + "-";  strGUID = strGUID + AddLeadingZero((int)GUID[10] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[11] & 0xFF);  strGUID = strGUID + "-";  strGUID = strGUID + AddLeadingZero((int)GUID[12] & 0xFF); strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[13] & 0xFF);  strGUID = strGUID + "-";  strGUID = strGUID + AddLeadingZero((int)GUID[14] & 0xFF);strGUID = strGUID + "-"; strGUID = strGUID + AddLeadingZero((int)GUID[15] & 0xFF);  System.out.println("GUID (String format): " + strGUID.toUpperCase());  return strGUID.toUpperCase();}public static String AddLeadingZero(int k) {  return (k <= 0xF) ? "0" + Integer.toHexString(k) : Integer.toHexString(k);  }//jmprivate ArrayList getNCPerson() {// 查询是否是第一次导入String sql ="select org_orgs.name  orgname,org_dept.name deptname from bd_psndoc bd_psndoc "+"left join bd_psnjob bd_psnjob  on bd_psnjob.pk_psndoc = bd_psndoc.pk_psndoc"+ "left join org_orgs org_orgs on bd_psnjob.pk_org = org_orgs.pk_org  left join org_dept org_dept"+"on bd_psnjob.pk_dept = org_dept.pk_dept";ArrayList list = null;try {list = (ArrayList) dao.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}private ArrayList getAdGUID() {// 查询是否是第一次导入String sql ="select * from nc_ladpdata ";ArrayList list = null;try {list = (ArrayList) dao.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}
}

2.把lodp中的数据放在NC系统中人员表(你们一般用不到,看上边就可以了,我放在这里只是做个记录)

package nc.impl.bd.ncpsndoc;import java.io.IOException;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.pub.pa.PreAlertObject;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.itf.bd.ncpsndoc.INCpsndocService;
import nc.itf.bd.psn.psndoc.IPsndocService;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.md.data.access.NCObject;
import nc.md.model.MetaDataException;
import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.vo.bd.psn.PsndocVO;
import nc.vo.bd.psn.PsnjobVO;
import nc.vo.erm.ladpdata.LadpDataVO;
import nc.vo.org.GroupVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFLiteralDate;
import nc.vo.sm.UserVO;
import net.sf.saxon.functions.Last;import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;import de.javawi.jstun.attribute.Username;public class NCPsndocmpl implements IBackgroundWorkPlugin {private IMDPersistenceQueryService queryService = null;private IPsndocService service = null;BaseDAO ncbd = new BaseDAO();@Overridepublic PreAlertObject executeTask(BgWorkingContext bgwc)throws BusinessException {NcResponseXml();return null;}/** 解析xml*/private String NcResponseXml() {ArrayList ladplist = getLADPPerson();ArrayList NClist = getNCPerson();HashMap orgmap = querypkOrg();
//      HashMap<String,String> pkoorg = this.querypkOrg();if (ladplist.size() > 0) {for (int i = 0; i < ladplist.size(); i++) {HashMap map = (HashMap) ladplist.get(i);String ladpusercode = null;String ladpdeptcode = null;String ladpcmpn = null;String ladpfadeptname= null;String ladpusername= null;
//              String ncpkdept = "";String deptobc = "";String deptobd = "";String grp = null;String dept = null;//中间表人员编码if (map.get("def3") != null) {ladpusercode = map.get("def3").toString();}//中间表部门 编码if (map.get("def2") != null) {ladpdeptcode = map.get("def2").toString();//根据部门编码查询部门主键dept = querypkdept(ladpdeptcode);}//中间表所属公司if (map.get("def4") != null) {ladpcmpn = map.get("def4").toString();//查询组织主键grp = (String) orgmap.get(ladpcmpn);}if (map.get("deptname") != null) {ladpfadeptname = map.get("deptname").toString();//查上级节点
//                  ncpkdept = getncpkdept(ladpfadeptname);}if (map.get("username") != null) {ladpusername = map.get("username").toString();}//根据人员上级部门guid找到人员同步在那个部门下if (map.get("fatherguid") != null) {deptobc = map.get("fatherguid").toString();//查到标识符deptobd = getdeptobc(deptobc);}if(ladpusercode == null || ladpusercode.length()<=0){String guid = getguid(ladpusername);ladpusercode = guid;}//有时候根据编码查不到部门,就换用名字来查if(dept == null || dept.length()<=0){dept = getncpkdept(ladpfadeptname);;}String str = "XZ";String pk_psndoc = "";String pk_psnjob = "";if (NClist.size() > 0) {for (int j = 0; j < NClist.size(); j++) {HashMap NCmap = (HashMap) NClist.get(j);        String NCusername = null;String NCdeptname = null;String cmpncode= null;String psnname = null;String pkf = null;//NC人员编码if (NCmap.get("code") != null) {NCusername = NCmap.get("code").toString();}//NC部门编码if (NCmap.get("deptcode") != null) {NCdeptname = NCmap.get("deptcode").toString();}//NC公司编码if (NCmap.get("cmpncode") != null) {cmpncode = NCmap.get("cmpncode").toString();}//获取姓名if (NCmap.get("psnname") != null) {psnname = NCmap.get("psnname").toString();}//获取上级编码if (NCmap.get("pk_fatherorg") != null) {pkf = NCmap.get("pk_fatherorg").toString();}if (ladpusercode.equals(NCusername)) {  //人员编码一样 str = "NN";if ( !ladpcmpn.equals(cmpncode) || !ladpusername.equals(psnname)) {//部门编码,公司编码,人员姓名str = "TG";pk_psndoc = NCmap.get("pk_psndoc").toString();pk_psnjob = NCmap.get("pk_psnjob").toString();}//如果人员所在部门的编码跟中介表的不一样就更新
//                          if(!deptobc.equals(pkf) && pkf.length()>0 && deptobc.length()>0){
//                              pk_psndoc = NCmap.get("pk_psndoc").toString();
//                              String uppsndocsql = "update bd_psnjob set pk_dept='"+dept+"' where pk_psndoc = '"+pk_psndoc+"' ";
//                          }}}}PsndocVO hvo = new PsndocVO();PsnjobVO bvo = new PsnjobVO();// 走调刚逻辑if (str.equals("TG")) {Date date = new Date();date = getNextDay(date);String s = new SimpleDateFormat("yyyy-MM-dd").format(date);UFLiteralDate edate = new UFLiteralDate(s);String uppsndocsql = "update bd_psndoc set pk_org='"+grp+"' where pk_psndoc = '"+pk_psndoc+"' "; String uppsnjobsql = "update bd_psnjob set enddutydate='"+edate+"' where pk_psnjob = '"+pk_psnjob+ "' ";String uppsnpsnsql = "update bd_psndoc set name='"+ladpusername+"' where pk_psndoc = '"+pk_psndoc+ "' ";try {ncbd.executeUpdate(uppsndocsql);ncbd.executeUpdate(uppsnjobsql);ncbd.executeUpdate(uppsnpsnsql);ncbd.executeUpdate("commit;");} catch (DAOException e) {e.printStackTrace();}bvo.setPk_psndoc(pk_psndoc);bvo.setPk_group("0001A11000000000040G");bvo.setPk_org(grp);bvo.setIndutydate(new UFLiteralDate());bvo.setIsmainjob(new UFBoolean(true));bvo.setPk_psncl("1001A11000000000047A");bvo.setPk_dept(dept);bvo.setPsncode(ladpusercode);bvo.setStatus(VOStatus.NEW);try {ncbd.insertVO(bvo);ncbd.executeUpdate("commit;");} catch (DAOException e) {e.printStackTrace();}}if(str.equals("XZ")){                         hvo.setPk_group("0001A11000000000040G");hvo.setCreator("1001ZZ10000000034F2K");UFDate dd = new UFDate();hvo.setCreationtime(new UFDateTime(dd.toString()));hvo.setCode(ladpusercode);hvo.setName(ladpusername);hvo.setEnablestate(2);hvo.setPk_org(grp);hvo.setStatus(VOStatus.NEW);bvo.setPk_group("0001A11000000000040G");bvo.setPk_org(grp);
//                              bvo.setPk_dept(ncpkdept);bvo.setPk_dept(dept);bvo.setPk_psncl("1001A110000000000473");  //人员类别bvo.setPsncode(ladpusercode);Date date = new Date();date = getNextDay(date);String s = new SimpleDateFormat("yyyy-MM-dd").format(date);UFLiteralDate edate = new UFLiteralDate(s);bvo.setIndutydate(edate);bvo.setIsmainjob(new UFBoolean("Y"));bvo.setStatus(VOStatus.NEW);PsnjobVO[] jobvo = new PsnjobVO[1];jobvo[0] = bvo;hvo.setPsnjobs(jobvo);try {getPsndocService().insertPsndoc(hvo, false);ncbd.executeUpdate("commit;");} catch (BusinessException e) {e.printStackTrace();}}}}return null;}private String getguid(String sn) {String sql = "select guid from nc_ladpdata where sn  = '"+sn+"'";String guid = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);guid = (String) map.get("guid");}} catch (DAOException e) {e.printStackTrace();}return guid;}private ArrayList getLADPPerson() {// 查询费控任职有变更的记录人员String sql = "select a.sn username,b.sn deptname ,a.guid userguid,b.guid deptguid,a.def2,a.def3,a.def4,a.fatherguid  from nc_ladpdata a "+ "inner join nc_ladpdata b on a.fatherguid = b.guid "+ "where a.objectclass = 'user'  and  a.def2 is not null and a.def3 is not null ";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}@SuppressWarnings("rawtypes")private ArrayList getNCPerson() {// 查询费控任职有变更的记录人员String sql = "select bd_psndoc.code,bd_psndoc.name psnname, bd_psndoc.pk_psndoc,bd_psnjob.indutydate,bd_psnjob.enddutydate,bd_psnjob.ismainjob, org_orgs.name cmpnname,org_orgs.code cmpncode,org_dept.code deptcode,org_dept.name,bd_psndoc.code,bd_psnjob.pk_psnjob,org_dept.pk_fatherorg from bd_psndoc bd_psndoc"+ " left join bd_psnjob bd_psnjob on  bd_psnjob.pk_psndoc = bd_psndoc.pk_psndoc"+ " left join org_orgs org_orgs on bd_psnjob.pk_org = org_orgs.pk_org"+ " left join org_dept org_dept on bd_psnjob.pk_dept = org_dept.pk_dept"+ " where nvl(bd_psndoc.dr,0)=0 and nvl(bd_psnjob.dr,0)=0 and nvl(org_orgs.dr,0)=0  and nvl(org_dept.dr,0)=0";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}// 查询创建人public String querycpsn(String pcd) {String sql = "select * from sm_user where nvl(dr,0)=0  and user_code='"+ pcd + "'";String pk = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if (list.size() > 0) {HashMap map2 = (HashMap) list.get(0);pk = (String) map2.get("cuserid");}} catch (DAOException e) {e.printStackTrace();}return pk;}// 查询人员部门public String querypkdept(String dept) {String sql = "select pk_dept from org_dept where code = '" + dept + "'";String pkdept = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkdept = (String) map.get("pk_dept");}} catch (DAOException e) {e.printStackTrace();}return pkdept;}// 查询人员部门public String querypkorg(String code) {String sql = "select pk_org from org_orgs where nvl(dr,0)=0 and code = '"+ code +"'";String pkorg = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkorg = (String) map.get("pk_org");}} catch (DAOException e) {e.printStackTrace();}return pkorg;}// 查询人员类别public String querypkpsncl() {HashMap<String, String> map = new HashMap<String, String>();String sql = "select * from bd_psncl where nvl(dr,0)=0";String pk = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if (list.size() > 0) {HashMap map1 = (HashMap) list.get(0);pk = (String) map1.get("pk_psncl");}} catch (DAOException e) {e.printStackTrace();}return pk;}// 查询人员public HashMap<String, String> querypsndoc() {HashMap<String, String> map = new HashMap<String, String>();String sql = "select * from bd_psndoc where nvl(dr,0)=0";try {ArrayList result = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(PsndocVO.class));for (int i = 0; i < result.size(); i++) {PsndocVO vo = new PsndocVO();vo = (PsndocVO) result.get(i);map.put(vo.getCode(), vo.getPk_psndoc());}} catch (DAOException e) {e.printStackTrace();}return map;}// 查询集团public HashMap<String, String> queryOrg() {HashMap<String, String> map = new HashMap<String, String>();String sql = "select * from org_group where nvl(dr,0)=0";try {ArrayList result = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(GroupVO.class));for (int i = 0; i < result.size(); i++) {GroupVO vo = new GroupVO();vo = (GroupVO) result.get(i);map.put(vo.getCode(), vo.getPk_group());}} catch (DAOException e) {e.printStackTrace();}return map;}private IPsndocService getPsndocService() {if (service == null)service = NCLocator.getInstance().lookup(IPsndocService.class);return service;}private PsndocVO queryOldPSndovCO(String vopk) throws MetaDataException,BusinessException {NCObject obj = getIPsndocQueryService().queryBillOfNCObjectByPK(PsndocVO.class, vopk);if (obj == null) {throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("10140psn", "110140psn0026"));// 该数据已被删除}PsndocVO oldvo = (PsndocVO) obj.getContainmentObject();return oldvo;}private IMDPersistenceQueryService getIPsndocQueryService() {if (queryService == null)queryService = NCLocator.getInstance().lookup(IMDPersistenceQueryService.class);return queryService;}public static Date getNextDay(Date date) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.DAY_OF_MONTH, -1);date = calendar.getTime();return date;}private HashMap getOrgPK(String code){//根据编码读取集团、公司 String sql = "select pk_org,pk_group from org_orgs where code = '"+code+"' ";HashMap map = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if(list.size()>0){map = (HashMap) list.get(0);              }} catch (DAOException e) {e.printStackTrace();}        return map;}private ArrayList getAdGUID() {String sql ="select * from nc_ladpdata ";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}private ArrayList getGUID(String guid) {String sql ="select pk_psndoc from bd_psndoc where nvl(dr,0)=0  and "+ "name in (select sn from nc_ladpdata where  objectclass = 'user'and "+ "guid ='"+ guid+"')";ArrayList list = null;try {list =  (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}// 查询组织public HashMap<String, String> querypkOrg() {HashMap<String, String> map = new HashMap<String, String>();String sql = "select pk_org,code from org_orgs where nvl(dr,0)=0 and orgtype29 = 'Y' order by code ";try {ArrayList result = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(OrgVO.class));for (int i = 0; i < result.size(); i++) {OrgVO vo = (OrgVO) result.get(i);map.put(vo.getCode(), vo.getPk_org());}} catch (DAOException e) {e.printStackTrace();}return map;}private String getncpkdept(String ladpname) {String sql = "select pk_dept from org_dept where name = '"+ladpname+"' ";String pkdept = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkdept = (String) map.get("pk_dept");}} catch (DAOException e) {e.printStackTrace();}return pkdept;}//查上级部门标识符private String getdeptobc(String obc) {String sql = "select def5 from nc_ladpdata  where guid = '"+obc+"' ";String pkobc = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkobc = (String) map.get("def5");}} catch (DAOException e) {e.printStackTrace();}return pkobc;}}

3.把数据放在部门表里

package nc.impl.bd.ncpsndoc;import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.itf.bd.ncpsndoc.INCdeptService;
import nc.itf.bd.psn.psndoc.IPsndocService;
import nc.itf.org.IDeptManageService;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.vo.org.DeptSaveVO;
import nc.vo.org.DeptVO;
import nc.vo.org.GroupVO;
import nc.vo.org.OrgVO;
import nc.vo.pfxx.util.PfxxPluginUtils;
import nc.vo.pm.util.app.BizContext;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFLiteralDate;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;import nc.bs.pfxx.ISwapContext;
import nc.bs.pub.pa.PreAlertObject;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;public class NCDeptmpl implements IBackgroundWorkPlugin {BaseDAO ncbd = new BaseDAO();@Overridepublic PreAlertObject executeTask(BgWorkingContext bgwc) throws BusinessException {String returnxml = NcResponseXml();return null;}private String NcResponseXml() {HashMap orgmap = querypkOrg();IDeptManageService deptManageService = (IDeptManageService) NCLocator.getInstance().lookup(nc.itf.org.IDeptManageService.class);//ArrayList ladplist = getLADPPerson();ArrayList NClist = getNCPerson();ArrayList deptid = getdeptid();//UFDate validateTime = new UFDate();validateTime = new UFDate(validateTime.getMillis()-5*60*1000);UFDate alter_Time = BizContext.getInstance().getBizDate();if (validateTime.after(alter_Time)) {ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("subcontract_0","04820003-0161")/*@res "此合同的变更日期早于实际生效日期 "*/);}//UFDate dd = new UFDate();HashMap<String, String> pkoorg = this.querypkOrg();//if (ladplist.size() > 0) {if (deptid.size() > 0) {for (int i = 0; i < deptid.size(); i++) {DeptVO vo = new DeptVO();HashMap map = (HashMap) deptid.get(i);String ladpcode = "";String ladpname = "";String ladporgcode = "";String ladpfacode = "";String ladpfaname = "";String ladpfaorgcode = "";String ladpObjectclass = "";String ncpkdept = "";String compn = "";String deptxz= "";String pk_org = "";String pk_fatherdept = "";if (map.get("code") != null) {ladpcode = map.get("code").toString();}if (map.get("name") != null) {ladpname = map.get("name").toString();}if (map.get("orgcode") != null) {ladporgcode = map.get("orgcode").toString();pk_org = (String) orgmap.get(ladporgcode);}if (map.get("facode") != null) {ladpfacode = map.get("facode").toString();//查上级节点ncpkdept = getncpkdept(ladpfacode);}if (map.get("faname") != null) {ladpfaname = map.get("faname").toString();//查上级节点
//                  ncpkdept = getncpkdept(ladpfaname);}//中间表自定义项4if (map.get("faorgcode") != null) {ladpfaorgcode = map.get("faorgcode").toString();}if (map.get("objectclass") != null) {ladpObjectclass = map.get("objectclass").toString();}if (map.get("def1") != null) {compn = map.get("def1").toString();}//一个是否传递组织架构的一个标识if (map.get("def5") != null) {deptxz = map.get("def5").toString();}//为顶级部门时设置上级部门为空if(ladpfaname == null || ladpfaname.length()<=0 ){ncpkdept = null;}//判断编码是否存在,不存在就用guid来存当编码if(ladpcode == null || ladpcode.length()<=0){String guid = getguid(ladpname);ladpcode = guid;}//最上级部门获取                        后期的修改if(pk_org == null || pk_org.length()<=0){if(compn.equals("inke")){ladporgcode = "01";pk_org = (String) orgmap.get(ladporgcode);}}//           if(deptxz.equals("1") || deptxz.equals("") ){   //  标志为1时正常传递String pk_dept = "";String str = "XZ";if (NClist.size() > 0) {for (int jj = 0; jj < NClist.size(); jj++) {HashMap ncmap = (HashMap) NClist.get(jj);String nccode = "";String ncname = "";                    String ncfacode = "";String ncfaname = "";String ncorgcode = "";String ncorgname = "";//                        if (ncmap.get("pk_dept") != null) {
//                          pk_dept = ncmap.get("pk_dept").toString();
//                      }if (ncmap.get("code") != null) {nccode = ncmap.get("code").toString();}if (ncmap.get("name") != null) {ncname = ncmap.get("name").toString();}if (ncmap.get("fcode") != null) {ncfacode = ncmap.get("fcode").toString();}if (ncmap.get("fname") != null) {ncfaname = ncmap.get("fname").toString();}if (ncmap.get("orgcode") != null) {ncorgcode = ncmap.get("orgcode").toString();}if (ncmap.get("orgname") != null) {ncorgname = ncmap.get("orgname").toString();}if(ncorgcode.equals(ladpfaorgcode) || ladpObjectclass.equals("top")){  //如果是这同一个公司下边if(nccode.equals(ladpcode)){str = "NN";if(!ncname.equals(ladpname) || !ladpfacode.equals(ncfacode)){if (ncmap.get("pk_dept") != null) {pk_dept = ncmap.get("pk_dept").toString();}str = "GX";}}}                     }}if(str.equals("GX")){String pk_father = getncpkfther(ladpfaname,ladporgcode);String upsql = "update org_dept set name='"+ladpname+"',pk_fatherorg='"+pk_father+"' where pk_dept = '"+pk_dept+"' ";try {ncbd.executeUpdate(upsql);ncbd.executeUpdate("commit;");} catch (DAOException e) {e.printStackTrace();}}                      if (str.equals("XZ")) {vo.setCode(ladpcode);vo.setCreationtime(new UFDateTime(dd.toString()));vo.setCreator("1001ZZ10000000034F2K");vo.setIslastversion(new UFBoolean("Y"));vo.setModifiedtime(new UFDateTime(dd.toString()));vo.setModifier("1001ZZ10000000034F2K");vo.setName(ladpname);vo.setPk_group("0001A11000000000040G");vo.setPk_org(pk_org);//中间表自定义项斯没值影响
//                  vo.setPk_org("0001A110000000000U5K");vo.setOrgtype13(new UFBoolean("Y"));vo.setOrgtype17(new UFBoolean("N"));vo.setDisplayorder( new Integer(999999));
//                  vo.setPk_vid("0001A110000000000VAN");  //必须赋值vo.setEnablestate(2);vo.setHrcanceled(new UFBoolean("N"));vo.setIsretail(new UFBoolean("N"));vo.setVenddate(new UFDate("9999-12-31 23:59:59"));vo.setPk_fatherorg(ncpkdept);   //当是一级部门的时候这个为空//vo.setVname("初始版本");
//                  vo.setVno("2017");vo.setVstartdate(new UFDate(dd.toString()));vo.setCreatedate(new UFLiteralDate(dd.toString()));vo.setStatus(VOStatus.NEW);try {deptManageService.insertVO(vo);ncbd.executeUpdate("commit;");} catch (BusinessException e) {e.printStackTrace();}}
//            }//更新所有标示为0的部门下的人员
//          if(deptxz.equals("0")){
//              String ladpdeptguid = getladpdeptguid();                      //查询标示为零的部门guid
//              String ladptoptopguid = getladptoptopguid(ladpdeptguid);      //根据为零的guid找到父类guid
//              String ladptopguid = getladptopguid(ladptoptopguid);          //查询标示为零的部门的上级guidArrayList psnlist = getpsnnmo(ladpdeptguid);                  //查询出标示为零的部门所有信息
//              ArrayList psnlist = getpsnnmoa(ladptoptopguid);
//              if(psnlist.size()>0 && ladptopguid.length()>0){
//                  for(int ii = 0; ii<psnlist.size(); ii++){
//                      HashMap map1 = (HashMap------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//                      String c = queryDept(cod);String upsql = "update nc_ladpdata set fatherguid= '"+ladptopguid+"' where fatherguid = '"+ladpdeptguid+"' ";
//                      String upsql = "update bd_psnjob set pk_dept= '"+c+"' where pk_psndoc = '"+ladpdeptguid+"' ";
//                      try {
//                          ncbd.executeUpdate(upsql);
//                          ncbd.executeUpdate("commit;");
//                      } catch (DAOException e) {
//                          e.printStackTrace();
//                      }
//                  }
//              }
//          }}}return null;}private ArrayList getpsnnmoa(String ladpdeptguid) {String sql = "select * from nc_ladpdata where fatherguid = '"+ladpdeptguid+"'";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}//根据guid找到父类guidprivate String getladptoptopguid(String ladpdeptguid) {String sql = "select fatherguid from nc_ladpdata where guid  = '"+ladpdeptguid+"' ";String guid = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);guid = (String) map.get("fatherguid");}} catch (DAOException e) {e.printStackTrace();}return guid;}//查询标示为零的部门guidprivate String getladptopguid(String ladpdeptguid) {String sql = "select guid from nc_ladpdata where guid  = '"+ladpdeptguid+"' ";String guid = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);guid = (String) map.get("guid");}} catch (DAOException e) {e.printStackTrace();}return guid;}//查询部门下为零的人员private ArrayList getpsnnmo(String ladpdeptguid) {String sql = "select * from nc_ladpdata where fatherguid = '"+ladpdeptguid+"'";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}//查询标示为零的部门guidprivate String getladpdeptguid() {String sql = "select guid from nc_ladpdata where def5  = '0' ";String guid = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);guid = (String) map.get("guid");}} catch (DAOException e) {e.printStackTrace();}return guid;}private String getguid(String sn) {String sql = "select guid from nc_ladpdata where sn  = '"+sn+"'";String guid = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);guid = (String) map.get("guid");}} catch (DAOException e) {e.printStackTrace();}return guid;}private String getncpkdept(String ladpname) {String sql = "select pk_dept from org_dept where code = '"+ladpname+"' ";String pkdept = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkdept = (String) map.get("pk_dept");}} catch (DAOException e) {e.printStackTrace();}return pkdept;}private String getfath(String pk_fatherorg) {String sql = "select code from org_dept where pk_dept = '"+pk_fatherorg+"' ";String code = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);code = (String) map.get("code");}} catch (DAOException e) {e.printStackTrace();}return code;}private String getladpfath(String fathergudi) {String sql = "select def3 from nc_ladpdata  where guid = '"+ fathergudi +"' ";String pkdept = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkdept = (String) map.get("def3");}} catch (DAOException e) {e.printStackTrace();}return pkdept;}private ArrayList getdeptid() {String sql = "select zj.def2 code,zj.sn name,zj.def4 orgcode,fa.def2 facode,fa.sn faname,fa.def4 faorgcode,fa.objectclass,zj.def1,zj.def5 "+" from nc_ladpdata zj "+"left join nc_ladpdata fa on zj.fatherguid = fa.guid "+"where zj.def2 is not null and zj.def4 is not null and (zj.objectclass = 'organizationalUnit' or zj.objectclass = 'top')  order by zj.def2 ";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}private ArrayList getAdGUID() {String sql = "select * from nc_ladpdata ";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}private ArrayList getLADPPerson() {// 查询费控任职有变更的记录人员String sql = "select a.sn username,b.sn deptname ,a.guid userguid,b.guid deptguid,a.def2,a.def3,a.def4 from nc_ladpdata a "+ "inner join nc_ladpdata b on a.fatherguid = b.guid ";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}@SuppressWarnings("rawtypes")private ArrayList getNCPerson() {// 查询费控任职有变更的记录人员String sql = "select dept.pk_dept,dept.code, "+"dept.name, "+"fdept.code fcode, "+ "fdept.name fname, "+ "org.code orgcode, "+"org.name orgname "+"from org_dept dept "+"left join org_dept fdept on dept.pk_fatherorg = fdept.pk_dept "+ "left join org_orgs org on dept.pk_org = org.pk_org "+"where nvl(dept.dr, 0) = 0 and nvl(org.dr, 0) = 0 "+"and nvl(fdept.dr, 0) = 0 and org.code is not null "+"order by org.code,dept.code";ArrayList list = null;try {list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());} catch (DAOException e) {e.printStackTrace();}return list;}// 查询是否已经存在编码@SuppressWarnings("unchecked")private String queryDept(String cod) {String sql = "select  * from org_dept where code='" + cod+ "' and nvl(dr,0)=0";String pkd = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if (list.size() > 0) {HashMap ma = (HashMap) list.get(0);pkd = (String) ma.get("pk_dept");}} catch (DAOException e) {e.printStackTrace();}return pkd;}// 查询上级public String querydept(String pkfer, String grp) {String sql = "select * from org_dept where nvl(dr,0)=0 and code='"+ pkfer + "' and pk_org = '" + grp + "'";String pk = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new MapListProcessor());if (list.size() > 0) {HashMap map2 = (HashMap) list.get(0);pk = (String) map2.get("pk_dept");}} catch (DAOException e) {e.printStackTrace();}return pk;}// 查询集团public HashMap<String, String> queryOrg() {HashMap<String, String> map = new HashMap<String, String>();String sql = "select * from org_group where nvl(dr,0)=0";try {ArrayList result = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(GroupVO.class));for (int i = 0; i < result.size(); i++) {GroupVO vo = new GroupVO();vo = (GroupVO) result.get(i);map.put(vo.getCode(), vo.getPk_group());}} catch (DAOException e) {e.printStackTrace();}return map;}// 查询组织public HashMap<String, String> querypkOrg() {HashMap<String, String> map = new HashMap<String, String>();String sql = "select pk_org,code from org_orgs where nvl(dr,0)=0 and orgtype29 = 'Y' order by code ";try {ArrayList result = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(OrgVO.class));for (int i = 0; i < result.size(); i++) {OrgVO vo = (OrgVO) result.get(i);map.put(vo.getCode(), vo.getPk_org());}} catch (DAOException e) {e.printStackTrace();}return map;}// 查询组织public HashMap<String, String> querypkDept(String orgcode) {HashMap<String, String> map = new HashMap<String, String>();String sql = "select * from org_dept where ";try {ArrayList result = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(OrgVO.class));for (int i = 0; i < result.size(); i++) {OrgVO vo = (OrgVO) result.get(i);map.put(vo.getCode(), vo.getPk_org());}} catch (DAOException e) {e.printStackTrace();}return map;}// 查询内编码跟vid@SuppressWarnings("unchecked")private DeptVO querymm(String pkdept) {DeptVO vo = new DeptVO();String sql = "select  * from org_dept where pk_dept='" + pkdept+ "' and nvl(dr,0)=0 ";try {ArrayList list = (ArrayList) ncbd.executeQuery(sql,new BeanListProcessor(DeptVO.class));for (int i = 0; i < list.size(); i++) {vo = (DeptVO) list.get(i);}} catch (DAOException e) {e.printStackTrace();}return vo;}private String getncpkfther(String ladpname,String code) {String sql = "select org_dept.pk_dept from org_dept "+  "left join org_orgs  on org_dept.pk_org = org_orgs.pk_org "+"where org_dept.name = '"+ladpname+"' and org_orgs.code='"+code+"' ";String pkdept = null;try {ArrayList list = (ArrayList) ncbd.executeQuery(sql, new MapListProcessor());if (list.size() > 0) {HashMap map = (HashMap) list.get(0);pkdept = (String) map.get("pk_dept");}} catch (DAOException e) {e.printStackTrace();}return pkdept;}}

用java链接lodp取数据相关推荐

  1. java set中取数据_Java中取数据库用的ResultSet问题

    这段时间做java项目,在操作数据库的时候,犯了一个错误,请看下面的程序 .......                        //前面连接数据库方面的省略 ResultSet  result ...

  2. java分页抓取数据_网页分页数据抓取的几种方式

    相信所有个人网站的站长都有抓取别人数据的经历吧,目前抓取别人网站数据的方式无非两种方式: 一.使用第三方工具,其中最著名的是火车头采集器,在此不做介绍. 二.自己写程序抓取,这种方式要求站长自己写程序 ...

  3. java爬虫异步取数据_教您使用java爬虫gecco抓取JD全部商品信息(三)

    ##详情页抓取 商品的基本信息抓取完成后,就要针对每个商品的详情页进行抓取,可以看到详情页的地址格式一般如下:http://item.jd.com/1861098.html.我们建立商品详情页的Bea ...

  4. 学校铃声Java_java_java多线程抓取铃声多多官网的铃声数据,一直想练习下java多线程抓取数 - phpStudy...

    java多线程抓取铃声多多官网的铃声数据 一直想练习下java多线程抓取数据. 有天被我发现,铃声多多的官网(http://www.shoujiduoduo.com/main/)有大量的数据. 通过观 ...

  5. python java 爬数据_如何用java爬虫爬取网页上的数据

    当我们使用浏览器处理网页的时候,有时候是不需要浏览的,例如使用PhantomJS适用于无头浏览器,进行爬取网页数据操作.最近在进行java爬虫学习的小伙伴们有没有想过如何爬取js生成的网络页面吗?别急 ...

  6. iOS—网络实用技术OC篇网络爬虫-使用java语言抓取网络数据

    网络爬虫-使用java语言抓取网络数据 前提:熟悉java语法(能看懂就行) 准备阶段:从网页中获取html代码 实战阶段:将对应的html代码使用java语言解析出来,最后保存到plist文件 上一 ...

  7. java读取文件按照空格_java实现读取txt文件并以在每行以空格取数据

    java实现读取txt文件并以在每行以空格取数据 发布于 2020-7-7| 复制链接 分享一篇关于java实现读取txt文件并以在每行以空格取数据,具有很好的参考价值,希望对大家有所帮助.一起跟随小 ...

  8. 基于Java的阿里妈妈数据抓取技术

    基于Java的阿里妈妈数据抓取技术 前言: 对于需要登录的网站爬虫最大的困难就是需要登录,然后才能获取到数据,如微博,阿里妈妈,webqq等.之前也有看过使用浏览器登录到网站后直接从浏览器中获取coo ...

  9. 使用java爬取数据的三种思路

    目录 一.使用HttpClient 二.使用HtmlUnit ->使用htmlUnit捕获百度搜索页面 三.捕获接口获取数据 一.使用HttpClient HttpClient是一种简单的捕获h ...

最新文章

  1. linux 存储映射lun 给_如何在 Linux 上扫描/检测新的 LUN 和 SCSI 磁盘 | Linux 中国
  2. forward declaration of class 错误
  3. 1289 大鱼吃小鱼
  4. 阿里云安装Quantaxis
  5. linux内核那些事之buddy
  6. onsyscommand
  7. echarts地图插入图片
  8. java学生选课系统_JAVA | 学生选课系统
  9. 【量化金融】利用DCF估值模型实现股票价值监测
  10. 一些优秀的源码开源网站
  11. 推荐比较好的广告联盟之BloggerAds-部落格行销,来自台湾的CPM博客赚钱联盟
  12. windows server 2016云主机如何挂载云硬盘
  13. 多智能体强化学习【Windows\Ubuntu 安装星际争霸Ⅱ】
  14. “黑吃黑”webshell箱子
  15. Python实现小说下载器,可以打包exe
  16. 帮转|腾讯云市场新版上线:大不同
  17. String+CytoScape构建PPI网络
  18. 索骥馆-编程语言之《Android内核剖析》扫描版[PDF]
  19. PTA 7-10 黑白三子棋局
  20. 应用最新的AD和TXK补丁

热门文章

  1. Hadoop精华问答 | Hadoop框架中最核心的设计是什么?
  2. python py启动闪退_运行ride.py报错,闪退
  3. CSS3 transform动画 3D旋转立体正方形
  4. 二维码生成细节和原理
  5. 转:领导变革,要减少“学习焦虑”而非增加“生存威胁”
  6. php result json,详解JsonResult的使用方法
  7. Vue项目接入海康威视智能应用平台监控摄像头全过程分享
  8. 苹果键盘对应PC键盘-苹果键 option command control
  9. WPF DataGrid控件的使用
  10. MySQL讲义第17讲——索引(INDEX)的删除