/** * */ package com.sinosoft.am.org.dept.indept.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import com.formaction.Parameter; import com.formaction.vo.Msg; import com.persistence.DbConnection; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.assitant.generator.IdentityGenerator; import com.persistence.service.exception.PersistenceException; import com.sinosoft.am.filemanger.laws.vo.FileBean; import com.sinosoft.am.org.dept.indept.vo.OrgInDeptStatistics; import com.sinosoft.am.org.dept.indept.vo.OrgInDeptVo; import com.sinosoft.am.org.jdbcUtil.ORGTemplate; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; import org.apache.log4j.Logger; import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** * @author 蒋云涛 * */ public class OrgInDeptDao { private static SysModel sysmodel = ModelFactory.getSysmodel(); @SuppressWarnings("unused") private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); private Logger log = Logger.getLogger(OrgInDeptDao.class); /** * * @param sql * @return 返回带有InDeptVo的ArrayList集合 */ public ArrayList getDeptList(String sql) throws ClassNotFoundException{ Connection conn = null; Statement st = null; ResultSet rs = null; DbConnection db = new DbConnection(); try { conn = db.getConnection(); st = conn.createStatement(); rs = st.executeQuery(sql); ArrayList result = new ArrayList(); while(rs.next()){ result.add(getInDeptVo(rs)); } return result; } catch (SQLException e) { this.log.error(e.getMessage(),e); throw new ClassNotFoundException("DAO Layou: 取得InDeptVo集合" + sql, e); }finally{ db.close(conn); db.close(st); db.close(rs); } } public ArrayList getAllDeptList() throws ClassNotFoundException{ Connection conn = null; Statement st = null; ResultSet rs = null; String sql = "select * from SYS_DEPARTMENT"; DbConnection db = new DbConnection(); try { conn = db.getConnection(); st = conn.createStatement(); rs = st.executeQuery(sql); ArrayList result = new ArrayList(); while(rs.next()){ result.add(getInDeptVo(rs)); } return result; } catch (SQLException e) { this.log.error(e.getMessage(),e); throw new ClassNotFoundException("DAO Layou: 取得InDeptVo集合" + sql, e); }finally{ db.close(conn); db.close(st); db.close(rs); } } /** * * @param id * @return InDeptVo 类对象 * @throws ClassNotFoundException */ public OrgInDeptVo getInDeptVoById(String id) throws ClassNotFoundException{ OrgInDeptVo result = new OrgInDeptVo(); Connection conn = null; Statement st = null; ResultSet rs = null; DbConnection db = new DbConnection(); String sql = "select * from SYS_DEPARTMENT where DEPT_ID='"+id+"' and is_del='0'"; try { conn = db.getConnection(); st = conn.createStatement(); rs = st.executeQuery(sql); if(rs.next()){ result = getInDeptVo(rs); return result; }; } catch (SQLException e) { this.log.error(e.getMessage(),e); throw new ClassNotFoundException("DAO Layou: 取得InDeptVo" + sql, e); }finally{ db.close(conn); db.close(st); db.close(rs); } return result; } /** * 获取给定部门id的下一级部门 * @param id * @return * @throws ClassNotFoundException */ public ArrayList getNextLevelTreeById(String id) throws ClassNotFoundException{ Connection conn = null; Statement st = null; ResultSet rs = null; DbConnection db = new DbConnection(); String sql = "select * from SYS_DEPARTMENT where PARENT_ID='"+id+"' AND IS_DEL='0'"; try { conn = db.getConnection(); st = conn.createStatement(); rs = st.executeQuery(sql); ArrayList result = new ArrayList(); while(rs.next()){ result.add(getInDeptVo(rs)); } return result; } catch (SQLException e) { this.log.error(e.getMessage(),e); throw new ClassNotFoundException("DAO Layou: 取得InDeptVo" + sql, e); }finally{ db.close(conn); db.close(st); db.close(rs); } } /** * * @param id * @return * @throws ClassNotFoundException */ public ArrayList getDeptTreeNodesById(String id) throws ClassNotFoundException{ ArrayList list = new ArrayList(); list = getAllDeptList(); OrgInDeptVo dept = getInDeptVoById(id); ArrayList nodesTree = getTreeNodesByInDeptVo(dept,list); return nodesTree; } /** * 这个递归存在问题 * @param dept * @param list * @return */ @SuppressWarnings("unused") public ArrayList getTreeNodesByInDeptVo(OrgInDeptVo dept,ArrayList list){ ArrayList deptTree = new ArrayList(); if(!deptTree.contains(dept)){ deptTree.add(dept); }; for(int i = 0; i tlist = getTreeNodesByInDeptVo(tdept,list); deptTree.addAll(getTreeNodesByInDeptVo(tdept,list)); //System.out.println(tdept); } } return deptTree; } /** * @param rs * @return dv 将部门结果集放在InDeptVo类中 */ private OrgInDeptVo getInDeptVo(ResultSet rs) { OrgInDeptVo dv = new OrgInDeptVo(); try{ dv.setCODE(rs.getString("DEPT_CODE")); dv.setDEPT_DESC(rs.getString("DEPT_DESC")); dv.setID(rs.getString("DEPT_ID")); dv.setDEPT_LEVEL(rs.getString("DEPT_LEVEL")); dv.setNAME(rs.getString("DEPT_NAME")); dv.setDEPT_PATH(rs.getString("DEPT_PATH")); dv.setDEPT_TYPE(rs.getString("DEPT_TYPE")); dv.setFD_OBJECTID(rs.getString("FD_OBJECTID")); dv.setIS_DEL(rs.getString("IS_DEL")); dv.setIS_VIRTUAL(rs.getString("IS_VIRTUAL")); dv.setMOD_DATE(rs.getString("MOD_DATE")); dv.setPARENT_ID(rs.getString("PARENT_ID")); dv.setSHORT_NAME(rs.getString("SHORT_NAME")); dv.setSORT(rs.getString("SORT")); dv.setUNICODE(rs.getString("UNICODE")); }catch(SQLException e){ this.log.error(e.getMessage(),e); } return dv; } /** * 根据部门Id,上级部门Id 部门名称 * @param deptId * @param parentId * @param deptName * @return 是否新增内部虚拟机构成功 */ public boolean addOrgInDept(String deptId, String parentId, String deptName) { Connection conn = null; PreparedStatement ps = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); String objectId = deptId; sql.append("--新增内部虚拟组织机构 \n"); sql.append("INSERT INTO SYS_DEPARTMENT (FD_OBJECTID,DEPT_ID,PARENT_ID,NAME,IS_DEL,IS_VIRTUAL)VALUES(?,?,?,?,?,?) \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, objectId); ps.setString(2, deptId); ps.setString(3, parentId); ps.setString(4, deptName); ps.setString(5, "0"); ps.setString(6, "1"); log.info("新增内部机构sql="+sql); return ps.executeUpdate() == 1; } catch (Exception e) { log.error("新增内部组织机构根节点错误", e); } finally { db.close(conn); db.close(ps); } return false; } /** * * @param deptId * @param deptName * @return 是否成功修改内部虚拟机构的名称 */ public boolean updateOrgInDeptName(String deptId, String deptName) { Connection conn = null; PreparedStatement ps = null; PreparedStatement ps2 = null; PreparedStatement ps3 = null; DbConnection db = new DbConnection(); //修改机构名称sql语句 StringBuffer sql1 = new StringBuffer(); //修改外部人员表的 部门 和部门名称 StringBuffer sql2 = new StringBuffer(); StringBuffer sql3 = new StringBuffer(); sql1.append("--修改内部组织机构名称 \n"); sql1.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET NAME=? WHERE ID=? AND IS_DEL=? \n"); log.info(sql1 + "-------------------sql1"); sql2.append("--修改内部人员表的部门名称 \n"); sql2.append("UPDATE EMC_AM_ORG_INLINK SET PARENT_DEPT=? WHERE PARENT_DEPT_ID=? \n"); log.info("修改内部人员表的部门名称sql="+sql2 ); sql3.append("--修改内部人员表的单位名称 \n"); sql3.append("UPDATE EMC_AM_ORG_INLINK SET PARENT_ORG=? WHERE PARENT_ORG_ID=? \n"); log.info("修改内部人员表的单位名称 sql="+sql3); try { //原子性还没做 conn = db.getConnection(); // conn.setAutoCommit(false); ps = conn.prepareStatement(sql1.toString()); ps.setString(1, deptName); ps.setString(2, deptId); ps.setString(3,"0"); boolean updateOrgName = ps.executeUpdate()>=1; boolean updateInLinkDeptName=true; //boolean updateInLinkOrgName = true; if(hasStaff(deptId)){ ps2 = conn.prepareStatement(sql2.toString()); ps2.setString(1, deptName); ps2.setString(2, deptId); updateInLinkDeptName = ps2.executeUpdate()>=1; } if(hasParentOrg(deptId)){ ps3 = conn.prepareStatement(sql3.toString()); ps3.setString(1, deptName); ps3.setString(2, deptId); ps3.executeUpdate(); } boolean isUpdate = updateOrgName && updateInLinkDeptName; // conn.commit(); return isUpdate; } catch (Exception e) { log.error("修改内部组织机构的名称出错", e); } finally { db.close(conn); db.close(ps); db.close(ps2); db.close(ps3); } return false; } /** * * @param deptId * @return 是否成功删除(改变IS_DEL状态)内部虚拟组织机构 */ public boolean shamDeleteOrgInDept(String deptId){ //先进行判断能否删除(判断机构下是否还有子机构存在) if(hasChildNode(deptId)){ return false; } //判断机构下是否还有员工存在 if(hasStaff(deptId)){ return false; } Connection conn = null; PreparedStatement ps = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--删除内部组织机构名称 \n"); sql.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET IS_DEL=? WHERE ID=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, "1"); ps.setString(2, deptId); log.info("删除内部虚拟机构sql="+sql); return ps.executeUpdate() == 1; } catch (Exception e) { log.error("删除内部组织机构名称错误", e); } finally { db.close(conn); db.close(ps); } return false; } /** * 判断该机构下是否存在人员 * @param deptId * @return 返回当前机构是否还有未删除的员工 */ public boolean hasStaff(String deptId) { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--查询该机构是否有没有删除的员工 \n"); sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE PARENT_DEPT_ID=? AND IS_DEL=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, deptId); ps.setString(2, "0"); log.info("查询该内部机构是否有未删除的员工sql="+sql); rs =ps.executeQuery(); if(rs.next()){ //log.info("该内部机构是否有员工"+rs.getBoolean(1)); return rs.getBoolean(1); }; } catch (Exception e) { log.error("查询该内部机构是否存在员工", e); } finally { db.close(conn); db.close(ps); db.close(rs); } return false; } /** * 判断是否存在下一级的机构 * @param deptId * @return 返回当前虚拟机构是否还有子机构 */ public boolean hasChildNode(String deptId) { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--查询该机构是否有子机构 \n"); sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, deptId); ps.setString(2, "0"); log.info("查询是否有子机构 sql="+sql); rs =ps.executeQuery(); if(rs.next()){ log.info("是否有子机构"+rs.getBoolean(1)); return rs.getBoolean(1); }; } catch (Exception e) { log.error("修改内部组织机构根节点错误", e); } finally { db.close(conn); db.close(ps); db.close(rs); } return false; } /** * 判断是否存上级部门 * @param deptId * @return */ public boolean hasParentOrg(String deptId) { Connection conn = null; Statement st = null; ResultSet rs = null; DbConnection db = new DbConnection(); String sql = "SELECT COUNT(1) FROM EMC_AM_ORG_DEPARTMENT_TEST a,"+ "(SELECT * FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE ID='"+deptId+"' AND IS_DEL='0') b WHERE a.ID=b.PARENT_ID AND a.IS_DEL='0'"; try { conn = db.getConnection(); st = conn.createStatement(); log.info("是否上级单位sql="+sql); rs = st.executeQuery(sql); if(rs.next()){ return rs.getBoolean(1); }; } catch (Exception e) { log.error("查询是否存在上级单位出错", e); }finally { db.close(conn); db.close(st); db.close(rs); } return false; } /*******************生成内部机构双选树开始***************************************************/ public OrgInDeptVo getInOrgDoubleTreeRoot(String deptId){ OrgInDeptVo ov = new OrgInDeptVo(); Connection conn = null; Statement st = null; ResultSet rs = null; String sql = "SELECT * FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE ID='"+deptId+"' AND IS_DEL='0'"; DbConnection db = new DbConnection(); try { conn = db.getConnection(); st = conn.createStatement(); rs = st.executeQuery(sql); if(rs.next()){ ov = getInDeptVo(rs); return ov; }; } catch (Exception e) { log.error("查询双向选择树的根级单位出错", e); }finally{ db.close(conn); db.close(st); db.close(rs); } return ov; } public String getInOrgTree(String id,String type) { log.info("id-- " + id); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); sql.append("-- 查询内部组织机构根节点 \n"); // sql.append(" SELECT ID,NAME,PARENT_ID \n"); sql.append(" SELECT DEPT_ID,DEPT_NAME,PARENT_ID \n"); sql.append(" FROM SYS_DEPARTMENT where IS_DEL='0' \n"); // if (id.equals("")) { // sql.append(" and PARENT_ID='0'"); // } else { // sql.append(" and PARENT_ID='" + id + "'"); // } sql.append(" and DEPT_ID='" + id + "'"); // sql.append(" ORDER BY SORT asc \n"); log.info(sql.toString()); try { ArrayList listRoot = persistence.getSearchResult(99, sql.toString()); String[] temp = listRoot.get(0); String deptId = temp[0]; String deptName = temp[1]; String parentId = temp[2]; json.append("{fromList:["); // if (listRoot.size() > 1) { // /** // * 加载人员信息 if(this.hasPersonLeaf(id)&&"per".equals(type)){ // * json.append(this.getPersonJson(id)); } // */ // if(this.hasStaff(id)&&"per".equals(type)){ // json.append(this.getPersonJson(id)); // }; //// json.append(this.getDeptChlidrenJson(id, type)); // } else { json.append("{"); json.append(" id:'" + deptId + "',parentId:'0', "); json.append(" parentId:'" + parentId + "', "); json.append(" name:'" + deptName + "', "); json.append("oldParentId:'null',"); json.append(" type:'unit',menuType:'nonLeafMenu', drag:'false', "); json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'"); json.append("},"); /** 加载人员信息 */ // if (this.hasStaff(deptId) && "per".equals(type)) { json.append(this.getPersonJson(deptId)); // } // json.append(this.getDeptChlidrenJson(deptId, type)); // } if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("],toList:[]}"); } catch (PersistenceException e) { log.error("查询组织机构错误", e); } log.info("组织机构json========"+JSONObject.fromObject(json.toString()).toString()); return JSONObject.fromObject(json.toString()).toString(); } // /** // * 返回部门节点json字符串 // * // * @param unitCode // * @return // */ // private String getDeptChlidrenJson(String unitCode, String type) { // SysModel sysmodel = ModelFactory.getSysmodel(); // SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); // // StringBuffer json = new StringBuffer(); // StringBuffer sql = new StringBuffer(); // sql.append("-- 查询组织机构子节点 \n"); //// sql.append(" SELECT ID,NAME,FD_OBJECTID \n"); // sql.append(" SELECT DEPT_ID,DEPT_NAME,PARENT_ID \n"); // sql.append(" FROM SYS_DEPARTMENT WHERE PARENT_ID='" + unitCode + "' \n"); // sql.append(" ORDER BY SORT asc \n"); // try { // ArrayList listDept = persistence.getSearchResult(99, sql.toString()); // int num = listDept.size(); // // for (int i = 0; i < num; i++) { // String[] temp = listDept.get(i); // String deptId = temp[0]; // String deptName = temp[1]; // String objectId = temp[2]; // json.append("{ "); // json.append(" id:'" + deptId + "', parentId:'" + unitCode + "',"); // json.append(" classId:'800',objectId:'" + objectId + "',"); // json.append(" name:'" + deptName + "',"); // json.append("oldParentId:'null',"); // json.append(" type:'unit',menuType:'nonLeafMenu', drag:'false', "); // json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'"); // json.append("}, "); // // if (this.hasStaff(deptId)&&"per".equals(type)){ // json.append(this.getPersonJson(deptId)); // } // if (this.hasChildNode(deptId)) { // json.append(this.getDeptChlidrenJson(deptId, type)); // } // // } // // } catch (PersistenceException e) { // log.error("查询组织机构子节点错误", e); // } // // return json.toString(); // } private String getPersonJson(String deptId) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); String sql = "SELECT FD_OBJECTID,COMPANY_ID,REAL_NAME FROM SYS_USER_INFO WHERE IS_DEL='0' and COMPANY_ID='" + deptId + "' AND FD_OBJECTID NOT IN (SELECT FD_OBJECTID FROM EMC_AM_EMERGENCY_EXPERT WHERE IS_DEL='0') ORDER BY COMPANY_ID ASC "; // // log.info("=="+sql); try { ArrayList list = persistence.getSearchResult(99, sql.toString()); int num = list.size(); for (int i = 0; i < num; i++) { String[] temp = list.get(i); String objectId = temp[0]; String pCode = temp[1]; String name = temp[2]; json.append("{ "); json.append(" id:'" + objectId + "', parentId:'" + pCode + "',"); json.append(" classId:'880',objectId:'" + objectId + "',"); json.append(" type:'per', name:'" + name + "',"); json.append("oldParentId:'"+ deptId+"', "); json.append(" menuType:'leafMenu',"); json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'"); /* * if(sex.equals("0")){ json.append( * " icon:'../../../scripts/qui/libs/icons/user_female.gif'"); * }else{ * json.append(" icon:'../../../scripts/qui/libs/icons/user.gif'" * ); } */ json.append("}, "); } } catch (PersistenceException e) { log.error("查询内部人员数据错误-- ", e); } log.info("json=========="+json.toString()); return json.toString(); } /*******************内部机构双选树结束***************************************************/ /*******************人力资源双选树开始***************************************************/ /** * 获取人力资源树 * @param comp_id * @return * @throws Exception */ public String getDoubleTreeRoot(String comp_id,String toDeptId) throws Exception{ StringBuffer json=new StringBuffer(); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); String sql="SELECT DEPT_ID,PARENT_ID,DEPT_NAME FROM SYS_DEPARTMENT WHERE DEPT_ID='"+comp_id+"'"; log.info("getDoubleTreeRoot.sql==="+sql+"===comp_id==="+comp_id); ArrayList userTree = persistence.getSearchResult(99, sql.toString()); log.info(userTree.size()); String dept_id=userTree.get(0)[0]; String dept_name=userTree.get(0)[2]; json.append("{\"fromList\":["); json.append("{"); json.append(" id:'"+dept_id+"', parentId:'0', "); json.append(" objectId:'000', "); json.append(" name:'"+dept_name+"', "); json.append(" drag:'false', "); json.append(" open:true, "); json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'"); json.append("},"); json.append(getDoubleTreeDao(comp_id,toDeptId)); if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("],\"toList\":["); //json.append("{"); //json.append(" id:'"+toDeptId+"', "); //json.append(" parentId:'"+comp_id+"', "); //json.append(" name:'"+getInDeptVoById(toDeptId).getNAME()+"', "); //json.append(" oldParentId:'"+comp_id+"', "); //json.append(" drag:'false', "); //json.append(" open:true, "); //json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'"); //json.append("}"); json.append("]}"); log.info("json==="+json); return JSONObject.fromObject(json.toString()).toString(); } /** * 获得下级的机构节点 * @param comp_id * @return * @throws Exception */ public String getDoubleTreeDao(String comp_id,String toDeptId) throws Exception{ SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json=new StringBuffer(); String sql="SELECT DEPT_ID,PARENT_ID,DEPT_NAME FROM SYS_DEPARTMENT WHERE PARENT_ID='"+comp_id+"'"; ArrayList userTree = persistence.getSearchResult(99, sql.toString()); log.info("getDoubleTreeDao.userTree.size===="+userTree.size()); for(int i=0;i userTree = persistence.getSearchResult(99, sql.toString()); log.info("getDoubleTreeEle.sql===="+sql); log.info("getDoubleTreeEle.userTree.size===="+userTree.size()); if(userTree.size()>0){ for(int i=0;i0){ m.setSucsess(new Boolean(true).toString()); //m.setInfo(Parameter.CREATE_SUCSESS); m.setInfo("right"); return m; }else{ m.setSucsess(new Boolean(false).toString()); //m.setInfo(Parameter.CREATE_FAILURE); m.setInfo("error"); return m; } } catch (SQLException e) { e.printStackTrace(); } return m; } /** * 更具classid设置主键的方法 * @param string * @return */ private String setPrimaryId(int classid) { String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(classid); return fd_id; } /** * 根据id获取表中的数据信息 放到map集合中 * @param arr * @return * @throws ClassNotFoundException */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Map> getUserInfo(String[]arr) throws ClassNotFoundException{ Map> map=new HashMap>(); for(int i=0;i list = new ArrayList(); while (rs.next()) { list.add(rs.getString("REAL_NAME")); list.add(rs.getString("MOBILE")); list.add(rs.getString("USER_ID")); list.add(rs.getString("EMAIL")); map.put(rs.getString("USER_ID"), list); } } catch (SQLException e) { this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人" + sql, e); } finally { db.close(rs); db.close(stat); db.close(conn); } } log.info("map.size===="+map.size()); return map; } /** * 获得内部联系人的fd_objectId集合 * @return 内部联系人的fd_objectId集合 * @throws ClassNotFoundException */ @SuppressWarnings({ "unchecked", "rawtypes" }) public List getEmcInlinkId() throws ClassNotFoundException { String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK"; Connection conn = null; Statement stat = null; ResultSet rs = null; DbConnection db = new DbConnection(); try { conn = db.getConnection(); stat = conn.createStatement(); rs = stat.executeQuery(sql); List list = new ArrayList(); while (rs.next()) { list.add(rs.getString("FD_OBJECTID")); } return list; } catch (SQLException e) { this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合" + sql, e); } finally { db.close(rs); db.close(stat); db.close(conn); } } /** * 格式化日期 * @param d * @return */ public String formatDate(Date d) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = sd.format(d); return date; } public String formatDateExpert(Date d) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = sd.format(d); return date; } /** * 为新增的内部联系人创建一个fd_objectid * @param list * @return * @throws ClassNotFoundException */ public String createMsgId(List list) throws ClassNotFoundException{ long l=(long) ((Math.random()+1)*1000000000); String msgId=l+""; if(list.contains(msgId)){ return createMsgId(list); } else{ log.info("EMC_AM_ORG_INLINK_ID==="+msgId); return msgId; } } /*******************人力资源双选树结束***************************************************/ /*******************存储专家信息开始***************************************************/ public Msg saveExpert(String id,String compId,String userId) throws Exception{ Msg m=new Msg(); // String[]idArr=id.split("%")[0].split(","); String[]idArr=id.split(","); Map>userMap=new HashMap>(); userMap=getInlinkInfo(idArr); Connection conn = null; PreparedStatement st = null; DbConnection db = new DbConnection(); log.info("idArr.length================"+idArr.length); try { String sql = "INSERT INTO EMC_AM_EMERGENCY_EXPERT(FD_OBJECTID,EXPERT_ID,EXPERT_NAME,EXPERT_CAL,EXPERT_EMAIL,EXPERT_UNIT,IS_SNSTAFF,IS_DEL,UPDATEDATE,CHANGE_TYPE,COLUMN_1,COLUMN_2,COLUMN_3,EXPERT_TEL,EXPERT_SEX,EXPERT_RESUME)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; conn = db.getConnection(); int num=0; conn.setAutoCommit(false); st = conn.prepareStatement(sql); for(int i=0;i>userMap=new HashMap>(); userMap=getInlinkInfo2(idArr); Connection conn = null; PreparedStatement st = null; DbConnection db = new DbConnection(); log.info("idArr.length================"+idArr.length); try { String sql = "INSERT INTO emc_am_org_inlink(FD_OBJECTID,inlink_index,inlink_name,emc_type,phone,email,parent_org_id,parent_dept_id,job,virtual_org_id,is_del,sort_no,entry_man_id,UPDATEDATE,PARENT_DEPT)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; conn = db.getConnection(); int num=0; conn.setAutoCommit(false); st = conn.prepareStatement(sql); for(int i=0;itempList= persistence.getSearchResult(99, sql.toString()); if(tempList==null||tempList.size()==0){ return false; }else{ return true; }}catch(Exception e){ this.log.error(e.getMessage(), e); return false; } } public int houxuzhi(String id) throws ClassNotFoundException { try{ String sql="select sort_no from emc_am_org_inlink where virtual_org_id ='"+id+"' and is_del = '0' and sort_no is not null order by sort_no desc"; ListtempList= persistence.getSearchResult(99, sql.toString()); return Integer.parseInt(tempList.get(0)[0]); }catch(Exception e){ this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 消息保存", e); } } /** * 根据id获取表中的数据信息 放到map集合中 * @param arr * @return * @throws ClassNotFoundException */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Map> getInlinkInfo(String[]arr) throws ClassNotFoundException{ Map> map=new HashMap>(); for(int i=0;i list = new ArrayList(); while (rs.next()) { list.add(rs.getString("REAL_NAME")); list.add(rs.getString("OFFICE_PHONE")); list.add(rs.getString("MOBILE")); list.add(rs.getString("EMAIL")); list.add(rs.getString("COMPANY_ID")); list.add(rs.getString("EMPLOY_NO")); list.add(rs.getString("GENDER")); list.add(rs.getString("FD_OBJECTID")); map.put(rs.getString("FD_OBJECTID"), list); } } catch (SQLException e) { this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人" + sql, e); } finally { db.close(conn); db.close(stat); db.close(rs); } } log.info("map.size===="+map.size()); return map; } /** * * @param arr * @return * @throws ClassNotFoundException */ @SuppressWarnings({ "rawtypes", "unchecked" }) public Map> getInlinkInfo2(String[]arr) throws ClassNotFoundException{ Map> map=new HashMap>(); for(int i=0;i list = new ArrayList(); while (rs.next()) { list.add(rs.getString("USER_ID")); list.add(rs.getString("REAL_NAME")); list.add(rs.getString("CONTINGENCY_TYPE")); list.add(rs.getString("MOBILE")); list.add(rs.getString("LOGIN_NAME")); list.add(rs.getString("COMPANY_ID")); list.add(rs.getString("ORG_ID")); list.add(rs.getString("POSITION")); map.put(rs.getString("FD_OBJECTID"), list); } } catch (SQLException e) { this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人" + sql, e); } finally { db.close(conn); db.close(stat); db.close(rs); } } log.info("map.size===="+map.size()); return map; } @SuppressWarnings({ "unchecked", "rawtypes" }) public List getEmcExpertId() throws ClassNotFoundException { String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK"; Connection conn = null; Statement stat = null; ResultSet rs = null; DbConnection db = new DbConnection(); try { conn = db.getConnection(); stat = conn.createStatement(); rs = stat.executeQuery(sql); List list = new ArrayList(); while (rs.next()) { list.add(rs.getString("FD_OBJECTID")); } return list; } catch (SQLException e) { this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合" + sql, e); } finally { db.close(rs); db.close(stat); db.close(conn); } } /*******************存储专家信息结束***************************************************/ /*******************存储队伍人员信息开始***************************************************/ /** * @param id * @param teamId * @return */ public Msg saveTeamPerson(String id, String teamId)throws Exception { Msg m=new Msg(); String[]idArr=id.split("%")[0].split(","); Map>userMap=new HashMap>(); userMap=getInlinkInfo(idArr); Connection conn = null; PreparedStatement st = null; DbConnection db = new DbConnection(); log.info("idArr.length================"+idArr.length); try { String sql = "INSERT INTO EMC_AM_TEAM_PERSONNEL(FD_OBJECTID,TEAM_NAME,CODE,NAME,DEPT_ID,TELEPHONE,IS_DEL,UPDATEDATE,TEAM_SYSTEM)VALUES(?,?,?,?,?,?,?,?,?)"; conn = db.getConnection(); int num=0; conn.setAutoCommit(false); st = conn.prepareStatement(sql); for(int i=0;i getEmcTeamPersonId() throws Exception{ String sql = "SELECT FD_OBJECTID FROM EMC_AM_TEAM_PERSONNEL"; Connection conn = null; Statement stat = null; ResultSet rs = null; DbConnection db = new DbConnection(); try { conn = db.getConnection(); stat = conn.createStatement(); rs = stat.executeQuery(sql); List list = new ArrayList(); while (rs.next()) { list.add(rs.getString("FD_OBJECTID")); } return list; } catch (SQLException e) { this.log.error(e.getMessage(), e); throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合" + sql, e); } finally { db.close(rs); db.close(stat); db.close(conn); } } /**根据部门ID获得其下的所有人员-内部人员(外部机构添加时联动部门下的联系人) * * @param id * @return */ public String getInlinkById(String id,String type) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); String sql; if(type=="1"||"1".equals(type)){ sql = "SELECT FD_OBJECTID,INLINK_INDEX,INLINK_NAME FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' and VIRTUAL_ORG_ID='" + id + "' ORDER BY INLINK_INDEX ASC "; }else{ sql = "SELECT FD_OBJECTID,INLINK_INDEX,INLINK_NAME FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' and PARENT_DEPT_ID='" + id + "' ORDER BY INLINK_INDEX ASC "; } log.info("=="+sql); json.append("{\"treeNodes\":["); /*json.append("{ "); json.append(" \"id\":\"" + id + "\", \"parentId\":\"0\","); json.append(" \"name\":\"人员列表\","); json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\" "); json.append("}, ");*/ try { ArrayList list = persistence.getSearchResult(210, sql.toString()); int num = list.size(); for (int i = 0; i < num; i++) { String[] temp = list.get(i); String pCode = temp[0]; String name = temp[2]; json.append("{ "); json.append(" \"id\":\"" + pCode + "\", \"parentId\":\"" + id + "\","); json.append(" \"name\":\"" + name + "\","); json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user_group.gif\" "); json.append("}, "); } } catch (PersistenceException e) { log.error("查询内部人员数据错误-- ", e); } //清除最后一个‘,’ if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } json.append("]}"); return json.toString(); } /*******************************************************内部人员统计开始************************/ public String InlinkStatisticsInit(String id){ StringBuffer json = new StringBuffer(); json.insert(0, "{\"rows\":["); json.append(InlinkNumInit(id)); json.append("]}"); return json.toString(); } /** 初始化数据(数据格式 {rows:[{}} ) *1.先获取实体机构信息(根据传来的id)如果存在下级单位显示“+” 2.统计该机构下的所有虚拟机构的人员信息 * 2.1递归查询该实体机构下的所有虚拟机构获得机构id * 2.2查询人员表 获得该虚拟机构下的所有人员信息 * 2.3对人员信息进行分类统计(应急类别的人数和应急角色的人数)将统计信息填充到该机构对应的OrgInDeptStatistics中 * 2.4汇总每个虚拟机构的OrgInDeptStatistics信息得到实体机构的OrgInDeptStatistics信息 3.获得实体机构下所有虚拟机构的实际人数 *3.1递归获得该实体机构下的所有虚拟机构的id *3.2在人员表中统计出存在id下的所有人员个数,去重(根据inlink_index) * @param id * @return */ public String InlinkNumInit(String id) { SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); StringBuffer sql = new StringBuffer(); /*//是否存在虚拟子机构 boolean hasVirtualDept =hasVirtualDept(id);*/ //是否存在子机构 实体的 boolean hasChildDept = hasEntityChildDept(id); //存储统计信息的实体类 OrgInDeptStatistics OIDS = new OrgInDeptStatistics(); /*//获得该机构下的所有虚拟机构id ArrayList virtualDeptIds = new ArrayList(); if(hasVirtualDept){ virtualDeptIds = getVirtualDeptIds(id); }*/ //获得该实体机构下所有人员的统计信息 OIDS = getStatisticsByIds(id); //获得该实体机构下的所有人员的总数 int staffNum = getStaffNum(id); sql.append("--查询传来id的机构信息 \n"); sql.append("SELECT ID , NAME ,PARENT_ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE IS_DEL='0' \n "); if (id.equals("")) { sql.append(" AND ID='1'"); } else { sql.append(" AND ID='" + id + "'"); } sql.append(" ORDER BY SORT asc \n"); try { ArrayList listRoot = persistence.getSearchResult(99, sql.toString()); String[] temp = listRoot.get(0); String deptId = temp[0]; String deptName = temp[1]; String parentId = temp[2]; //json.append("{rows:["); json.append("{"); json.append(" \"dept_id\":\"" + deptId + "\", "); json.append(" \"parentId\":\"" + parentId + "\", "); json.append(" \"name\":\"" + deptName + "\", "); //统计信息的赋值 //json.append(" \"AccNum\":\"" + OIDS.getAccNum() + "\", "); //json.append(" \"EmergencyRoleNum\":\"" + OIDS.getEmergencyRoleNum() + "\", "); json.append(" \"AccNum\":\"" + staffNum + "\", "); json.append(" \"EmergencyRoleNum\":\"" + staffNum + "\", "); json.append(" \"LifeAcc\":\"" + OIDS.getLifeAcc() + "\", "); json.append(" \"PowerNetWorkAcc\":\"" + OIDS.getPowerNetWorkAcc() + "\", "); json.append(" \"WindFloodAcc\":\"" + OIDS.getWindFloodAcc() + "\", "); json.append(" \"EquipmentAcc\":\"" + OIDS.getEquipmentAcc() + "\", "); json.append(" \"ElseAcc\":\"" + OIDS.getElseAcc() + "\", "); json.append(" \"GeneralDirector\":\"" + OIDS.getGeneralDirector() + "\", "); json.append(" \"DetupyDirector\":\"" + OIDS.getDetupyDirector() + "\", "); json.append(" \"Chairman\":\"" + OIDS.getChairman() + "\", "); json.append(" \"DetupyChairman\":\"" + OIDS.getDetupyChairman() + "\", "); json.append(" \"Member\":\"" + OIDS.getMember() + "\", "); json.append(" \"Administrator\":\"" + OIDS.getAdministrator() + "\", "); if(hasChildDept){ json.append(" \"isParent\":true, "); json.append(" \"open\":false, "); }else{ json.append(" \"isParent\":false, "); json.append(" \"open\":true, "); } json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\""); json.append("}"); //json.append("]}"); } catch (PersistenceException e) { e.printStackTrace(); } return json.toString(); } /** * @param id * @return */ private boolean hasEntityChildDept(String deptId) { /* Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--查询该机构是否有子机构 \n"); sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, deptId); ps.setString(2, "0"); ps.setString(3, "0"); //log.info("查询是否有子机构 sql="+sql); rs =ps.executeQuery(); if(rs.next()){ //log.info("是否有子机构"+rs.getBoolean(1)); return rs.getBoolean(1); }; } catch (Exception e) { log.error("查询是否存在子机构", e); } finally { db.close(conn); db.close(ps); db.close(rs); } return false; */ Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--查询该机构是否有子机构 \n"); sql.append("SELECT COUNT(1) c FROM EMC_DEPARTMENT_IN WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, deptId); ps.setString(2, "0"); ps.setString(3, "0"); //log.info("查询是否有子机构 sql="+sql); rs =ps.executeQuery(); if(rs.next()){ //log.info("是否有子机构"+rs.getBoolean(1)); return rs.getBoolean(1); }; } catch (Exception e) { log.error("查询是否存在子机构", e); } finally { db.close(conn); db.close(ps); db.close(rs); } return false; } /** * @param id * @return */ private int getStaffNum(String id) { int staffNum=0; SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer sql = new StringBuffer(); sql.append("-- 统计给定id的机构下的人员总数 \n"); sql.append(" SELECT DISTINCT INLINK_INDEX FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' \n"); sql.append(" AND PARENT_ORG_ID ='"+id+"' \n"); try { ArrayList list = persistence.getSearchResult(99, sql.toString()); staffNum = list.size(); } catch (PersistenceException e) { e.printStackTrace(); } return staffNum; } /** * @param virtualDeptIds * @return */ private OrgInDeptStatistics getStatisticsByIds(String id) { OrgInDeptStatistics OIDS = new OrgInDeptStatistics(); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer sql = new StringBuffer(); sql.append("SELECT COUNT(1) AS 应急类别总数, COUNT(1) AS 应急角色总数, COUNT(DECODE(EMC_TYPE,'1',1,0)) AS 人身事故, COUNT(DECODE(EMC_TYPE,'2',1,0)) AS 电网事故, COUNT(DECODE(EMC_TYPE,'4',1,0)) AS 防风防汛, COUNT(DECODE(EMC_TYPE,'3',1,0)) AS 设备事故, COUNT(DECODE(EMC_TYPE,'5',1,0)) AS 其他, \n"); sql.append("COUNT(DECODE(EMC_ROLE,'1',1,0)) AS 总指挥, COUNT(DECODE(EMC_ROLE,'2',1,0)) AS 副总指挥, COUNT(DECODE(EMC_ROLE,'3',1,0)) AS 主任, COUNT(DECODE(EMC_ROLE,'4',1,0)) AS 副主任, COUNT(DECODE(EMC_ROLE,'5',1,0)) AS 成员,COUNT(DECODE(EMC_ROLE,'6 ',1,0)) AS 管理人员 \n"); sql.append("FROM EMC_AM_ORG_INLINK WHERE IS_DEL = '0' \n "); sql.append(" AND VIRTUAL_ORG_ID IN ("+" SELECT ORG_ID FROM EMC_DEPARTMENT_IN WHERE INSTR(PATH_ID,'_"+id+"_')>0 AND IS_VIRTUAL='1' AND IS_DEL='0'"+") \n"); log.info("sql=========="+sql); try { ArrayList list = persistence.getSearchResult(99, sql.toString()); for(int i = 0;i list = persistence.getSearchResult(99, sql.toString()); String[] temp = list.get(0); //将每条结果对应的数据合并到OIDS中 OIDS.setAccNum(OIDS.getAccNum()+Integer.parseInt(temp[0]));//应急类型总数 OIDS.setEmergencyRoleNum(OIDS.getEmergencyRoleNum()+Integer.parseInt(temp[1]));//应急角色--总数 OIDS.setLifeAcc(OIDS.getLifeAcc()+Integer.parseInt(temp[2]));//应急类型--人身事故 OIDS.setPowerNetWorkAcc(OIDS.getPowerNetWorkAcc()+Integer.parseInt(temp[3]));//应急类别--电网事故 OIDS.setWindFloodAcc(OIDS.getWindFloodAcc()+Integer.parseInt(temp[4]));//应急类别--防风防汛 OIDS.setEquipmentAcc(OIDS.getEquipmentAcc()+Integer.parseInt(temp[5]));//应急类别--设备事故 OIDS.setElseAcc(OIDS.getElseAcc()+Integer.parseInt(temp[6]));//应急类别--其他应急类别 OIDS.setGeneralDirector(OIDS.getGeneralDirector()+Integer.parseInt(temp[7]));//应急角色--总指挥 OIDS.setDetupyDirector(OIDS.getDetupyDirector()+Integer.parseInt(temp[8]));//应急角色--副总指挥 OIDS.setChairman(OIDS.getChairman()+Integer.parseInt(temp[9]));//应急角色--主任 OIDS.setDetupyChairman(OIDS.getDetupyChairman()+Integer.parseInt(temp[10]));//应急角色--副主任 OIDS.setMember(OIDS.getMember()+Integer.parseInt(temp[11]));//应急角色--成员 OIDS.setAdministrator(OIDS.getAdministrator()+Integer.parseInt(temp[12]));//应急角色--管理人员 } catch (PersistenceException e) { e.printStackTrace(); } } }*/ return OIDS; } /** 根据传来的id获得该机构下的所有虚拟机构id * @param id * @return */ private ArrayList getVirtualDeptIds(String id) { /* ArrayList listIds = new ArrayList(); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer sql = new StringBuffer(); sql.append(" --查询给定机构下的子虚拟机构ids \n"); sql.append(" SELECT ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0' \n"); sql.append(" ORDER BY SORT asc \n"); try { ArrayList list = persistence.getSearchResult(99, sql.toString()); String[] temp; for(int i = 0;i listIds = new ArrayList(); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer sql = new StringBuffer(); sql.append(" --查询给定机构下的子虚拟机构ids \n"); sql.append(" SELECT ORG_ID FROM EMC_DEPARTMENT_IN WHERE INSTR(PATH_ID,'_"+id+"_')>0 AND IS_VIRTUAL='1' AND IS_DEL='0' \n"); ArrayList list = new ArrayList(); try { list = persistence.getSearchResult(99, sql.toString()); } catch (PersistenceException e) { e.printStackTrace(); } String[] temp; for(int i = 0;i compIds = new ArrayList(); sql.append("--查询传来id的机构信息 \n"); sql.append("SELECT ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE IS_DEL='0' \n "); sql.append(" AND PARENT_ID='" + id + "' \n"); sql.append(" AND IS_VIRTUAL ='0' \n"); sql.append(" ORDER BY SORT asc \n"); try { ArrayList listCompIds = persistence.getSearchResult(99, sql.toString()); //获得传来id下的所有实体机构 for(int i = 0;i-1){ json.deleteCharAt(json.lastIndexOf(",")); } json.append("]}"); } catch (PersistenceException e) { e.printStackTrace(); } log.info("json==========s"+json); return json.toString(); } public boolean hasStaffs(String deptId) { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--查询该机构是否有没有删除的员工 \n"); sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE PARENT_ORG_ID=? AND IS_DEL=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, deptId); ps.setString(2, "0"); log.info("查询该内部机构是否有未删除的员工sql="+sql); rs =ps.executeQuery(); if(rs.next()){ //log.info("该内部机构是否有员工"+rs.getBoolean(1)); return rs.getBoolean(1); }; } catch (Exception e) { log.error("查询该内部机构是否存在员工", e); } finally { db.close(conn); db.close(ps); db.close(rs); } return false; } /*******************************************************内部人员统计结束************************/ /** * @param deptId * @return */ public boolean shamDeleteOrgInDept2(String deptId) { //先进行判断能否删除(判断机构下是否还有子机构存在) if(hasChildNode(deptId)){ return false; } //判断机构下是否还有员工存在 if(hasStaff2(deptId)){ return false; } Connection conn = null; PreparedStatement ps = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--删除内部组织机构名称 \n"); sql.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET IS_DEL=? WHERE ID=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, "1"); ps.setString(2, deptId); log.info("删除内部虚拟机构sql="+sql); return ps.executeUpdate() == 1; } catch (Exception e) { log.error("删除内部组织机构名称错误", e); } finally { db.close(conn); db.close(ps); } return false; } /** * @param deptId * @return */ private boolean hasStaff2(String deptId) { Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; DbConnection db = new DbConnection(); StringBuffer sql = new StringBuffer(); sql.append("--查询该机构是否有没有删除的员工 \n"); sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID=? AND IS_DEL=? \n"); try { conn = db.getConnection(); ps = conn.prepareStatement(sql.toString()); ps.setString(1, deptId); ps.setString(2, "0"); log.info("查询该内部机构是否有未删除的员工sql="+sql); rs =ps.executeQuery(); if(rs.next()){ //log.info("该内部机构是否有员工"+rs.getBoolean(1)); return rs.getBoolean(1); }; } catch (Exception e) { log.error("查询该内部机构是否存在员工", e); } finally { db.close(conn); db.close(ps); db.close(rs); } return false; } /*******************存储队伍人员信息结束***************************************************/ public Msg getMove(String fd_id, String up_id,String fd_sort,String up_sort)throws Exception { Msg m=new Msg(); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); int sqlExecute = 0; StringBuffer sqlmoveUp = new StringBuffer(); sqlmoveUp.append("update EMC_AM_ORG_INLINK set SORT_NO = '"+up_sort+"' where FD_OBJECTID='"+fd_id+"';"); sqlmoveUp.append("update EMC_AM_ORG_INLINK set SORT_NO = '"+fd_sort+"' where FD_OBJECTID='"+up_id+"';"); log.info(sqlmoveUp); try { sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString()); //判定是否删除数据成功 if(sqlExecute==1){ log.info("保存成功"); m.setSucsess(new Boolean(true).toString()); m.setInfo(Parameter.CREATE_SUCSESS); return m; }else{ log.info("保存失败"); m.setSucsess(new Boolean(false).toString()); m.setInfo(Parameter.CREATE_FAILURE); return m; } } catch (PersistenceException e) { e.printStackTrace(); } return m; } public Msg exeGetMove(String tableName,String fillName,String max,String id, String idFille,String fd_id)throws Exception { String no =sortNo(tableName, fillName, max, id, idFille); int fillerNo = Integer.valueOf(no).intValue(); int fillerNo1 = fillerNo-1; String no1 = fillerNo1 + ""; Msg m=new Msg(); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); int sqlExecute = 0; StringBuffer sqlmoveUp = new StringBuffer(); sqlmoveUp.append("update "+tableName+" set SORT_NO = '"+no1+"' where FD_OBJECTID='"+fd_id+"';"); log.info(sqlmoveUp); try { sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString()); //判定是否删除数据成功 if(sqlExecute==1){ log.info("保存成功"); m.setSucsess(new Boolean(true).toString()); m.setInfo(Parameter.CREATE_SUCSESS); return m; }else{ log.info("保存失败"); m.setSucsess(new Boolean(false).toString()); m.setInfo(Parameter.CREATE_FAILURE); return m; } } catch (PersistenceException e) { e.printStackTrace(); } return m; } //根据传过来的id号取本id下最小的排序序号 public String sortNo(String tableName,String fillName,String max,String id, String idFille){ String sql="select min(to_number("+fillName+")) from "+tableName+" where "+idFille+" ='"+id+"' and is_del='0';"; List list = null; try { list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResult(99, sql); } catch (PersistenceException e) { log.error(e.getMessage()); } String result = ""; if(list.size()>0){ result=list.get(0)[0]; } log.info("============================================="+result); return result; } }