package com.sinosoft.em.operation.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; 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.sinosoft.am.org.jdbcUtil.ORGTemplate; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; public class OperationDao { private Logger log = Logger.getLogger(this.getClass()); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); public Msg getPublish(String fd_id) throws ClassNotFoundException{ Msg m=new Msg(); String []arr=fd_id.split(","); String sql="UPDATE ECM_EM_GW_PHTOT SET STATE='2' WHERE FD_OBJECTID=?"; Connection conn = null; PreparedStatement st = null; int num=0; DbConnection db = new DbConnection(); try { conn = db.getConnection(); conn.setAutoCommit(false); st = conn.prepareStatement(sql); for(int i=0;i loadSysOrgInfo){ // String Unit = Utils.getParameter("Unit", params)==null?"":Utils.getParameter("Unit", params); String deptid = loadSysOrgInfo.get("deptId"); String id =loadSysOrgInfo.get("id"); boolean isFirstLoad = (id==null||"".equals(id))?true:false;//是否是第一次加载 String loadId = isFirstLoad?deptid:id; ORGTemplate org = new ORGTemplate(); StringBuffer sql2 = new StringBuffer(); StringBuffer sql3 = new StringBuffer(); StringBuffer json = new StringBuffer(); StringBuffer sql_man = new StringBuffer(); String isOpen = "'true' \"isParent\", "; List> list2 = new ArrayList>(); List> list3 = new ArrayList>(); List> list_man = new ArrayList>(); json.append("{\"treeNodes\":["); if(isFirstLoad){ //下级以外 sql2.append("select DEPT_ID \"id\" , PARENT_ID \"parentId\" , DEPT_NAME \"name\" , DEPT_LEVEL \"orgLevel\" , \n"); sql2.append("DECODE(DEPT_ID, '"+loadId+"', 'true', 'false') \"open\", \n"); sql2.append(isOpen); sql2.append("DECODE(IS_VIRTUAL, '1', '/nwyj/scripts/qui/libs/icons/selected.png', '/nwyj/scripts/qui/libs/icons/selected.png') \"icon\" \n"); sql2.append("from( select dept_id ,dept_name, parent_id,sort,dept_type,DEPT_LEVEL,IS_VIRTUAL from sys_department where dept_id='"+loadId+"' \n"); sql2.append("union select dept_id , dept_name, parent_id, sort, dept_type, DEPT_LEVEL, IS_VIRTUAL from sys_department where parent_id='"+loadId+"' ) where dept_type='2' order by dept_type, sort"); //根节点 sql3.append("select DEPT_ID \"id\" , PARENT_ID \"parentId\" , DEPT_NAME \"name\" , DEPT_LEVEL \"orgLevel\" , \n"); sql3.append("DECODE(DEPT_ID, '"+loadId+"', 'true', 'false') \"open\", 'false' \"isParent\" , \n"); sql3.append("DECODE(IS_VIRTUAL, '1', '/nwyj/scripts/qui/libs/icons/selected.png', '/nwyj/scripts/qui/libs/icons/selected.png') \"icon\" \n"); sql3.append("from( select dept_id ,dept_name, parent_id,sort,dept_type,DEPT_LEVEL,IS_VIRTUAL from sys_department where dept_id='"+loadId+"' \n"); sql3.append("union select dept_id , dept_name, parent_id, sort, dept_type, DEPT_LEVEL, IS_VIRTUAL from sys_department where parent_id='"+loadId+"' ) where dept_id='"+loadId+"' order by dept_type, sort"); }else{ //下级以外 sql2.append("select DEPT_ID \"id\" , PARENT_ID \"parentId\" , DEPT_NAME \"name\" , DEPT_LEVEL \"orgLevel\" , \n"); sql2.append("DECODE(DEPT_ID, '"+loadId+"', 'true', 'false') \"open\", \n"); sql2.append(isOpen); sql2.append("DECODE(IS_VIRTUAL, '1', '/nwyj/scripts/qui/libs/icons/selected.png', '/nwyj/scripts/qui/libs/icons/selected.png') \"icon\" \n"); sql2.append("from( select dept_id ,dept_name, parent_id,sort,dept_type,DEPT_LEVEL,IS_VIRTUAL from sys_department where dept_id='"+loadId+"' \n"); sql2.append("union select dept_id , dept_name, parent_id, sort, dept_type, DEPT_LEVEL, IS_VIRTUAL from sys_department where parent_id='"+loadId+"' ) where dept_type='2' and dept_id!='"+loadId+"' order by dept_type, sort"); //根节点 sql3.append("select DEPT_ID \"id\" , PARENT_ID \"parentId\" , DEPT_NAME \"name\" , DEPT_LEVEL \"orgLevel\" , \n"); sql3.append("DECODE(DEPT_ID, '"+loadId+"', 'true', 'false') \"open\", 'false' \"isParent\" , \n"); sql3.append("DECODE(IS_VIRTUAL, '1', '/nwyj/scripts/qui/libs/icons/selected.png', '/nwyj/scripts/qui/libs/icons/selected.png') \"icon\" \n"); sql3.append("from( select dept_id ,dept_name, parent_id,sort,dept_type,DEPT_LEVEL,IS_VIRTUAL from sys_department where dept_id='"+loadId+"' \n"); sql3.append("union select dept_id , dept_name, parent_id, sort, dept_type, DEPT_LEVEL, IS_VIRTUAL from sys_department where parent_id='"+loadId+"' ) where dept_id='"+loadId+"' order by dept_type, sort"); } sql_man.append("WITH D AS ( SELECT * FROM SYS_DEPARTMENT WHERE IS_DEL='0'),M AS((SELECT U.FD_OBJECTID \"userFdId\" ,U.REAL_NAME \"userRealName\",U.USER_ID \"userId\",D.DEPT_ID \"deptId\",D.DEPT_NAME \"deptName\",D.CORP_ID \"corpId\" ," + "D.CORP_NAME \"corpName\",U.EMAIL \"userEmail\",U.GENDER \"userGender\",U.MOBILE \"userPhone\" FROM SYS_DEPARTMENT D,SYS_USER_INFO U,SYS_DEPT_USER DU WHERE U.USER_ID = DU.USER_ID AND DU.DEPT_ID = D.DEPT_ID AND U.IS_DEL='0') " + "UNION (SELECT EI.FD_OBJECTID,EI.INLINK_NAME, EI.INLINK_INDEX,EI.VIRTUAL_ORG_ID,D.DEPT_NAME,D.CORP_ID,D.CORP_NAME,EI.EMAIL, '1', EI.PHONE FROM EMC_AM_ORG_INLINK EI,SYS_DEPARTMENT D, SYS_DEPT_USER DU WHERE " + "EI.INLINK_INDEX = DU.USER_ID AND DU.DEPT_ID= D.DEPT_ID AND EI.IS_DEL='0' ))"); sql_man.append("SELECT \"userFdId\" \"id\",\"userRealName\" \"name\",\"deptId\" \"parentId\", 'per' \"leafType\", '/nwyj/scripts/qui/libs/icons/user_group.gif\' \"icon\" FROM M WHERE \"deptId\"='"+loadId+"' \n"); try { //将sql语句查询出来的结果封装成集合 log.info("sql2========"+sql2.toString()); log.info("sql3========"+sql3.toString()); list3 = org.query(sql3.toString()); list2 = org.query(sql2.toString()); list_man.addAll(org.query(sql_man.toString())); } catch (SQLException e) { e.printStackTrace(); } if(isFirstLoad){ json.append(org.listToString(list3)); json.append(","); } json.append(org.listToString(list2)); json.append(","); if(json.substring(json.length()-2,json.length()-1).equals("[")){ json.deleteCharAt(json.lastIndexOf(",")); } json.append(org.listToString(list_man)); if(json.substring(json.length()-1).equals(",")){ json.deleteCharAt(json.lastIndexOf(",")); } json.append("]}"); log.info("json.toString======="+json.toString()); return json.toString(); } }