package com.sinosoft.am.filemanger.document.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; 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.persistence.service.exception.PersistenceException; import com.sinosoft.am.filemanger.document.vo.DocBean; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; public class DocDao{ private Logger log = Logger.getLogger(this.getClass()); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); private ListnumList=new ArrayList(); /** * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据 * @param id * @return */ public String NumInit(String id,String StartTime,String EndTime,String mimiLevel,String tempLevel,String valueType,String deptId){ String sql="select dept_id from sys_department where (parent_id='"+id+"' or dept_id='"+id+"')"; try{ if(deptId != null && !"null".equals(deptId)&&!"".equals(deptId) ){ sql+=" and dept_id in("+deptId+") "; } if(checkId(id)){ ListtempList= persistence.getSearchResult(99, sql.toString()); log.info("carNum.tempList.size===="+tempList.size()); Listlist=new ArrayList(); for(int i=0;ilist=new ArrayList(); list.add(id); getNoChildFileNum(list, id,StartTime,EndTime,mimiLevel,tempLevel,valueType); }}catch(Exception e){ this.log.error(e.getMessage(), e); } // log.info("最终JSON==="+json.toString()); /* if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); }*/ DocBean numBean = new DocBean(); for(int i=0;ilist=getCmpList(id, new ArrayList()); log.info("result===="+result); return result; } public String teamNum(String id,String StartTime,String EndTime,String mimiLevel,String tempLevel,String valueType){ try{ if(checkId(id)){ String sql="select dept_id from sys_department where parent_id='"+id+"'"; ListtempList= persistence.getSearchResult(99, sql.toString()); log.info("teamNum.tempList.size===="+tempList.size()); for(int i=0;ilist=getCmpList(tempList.get(i)[0], new ArrayList()); getFileNum(list, tempList.get(i)[0],StartTime,EndTime,mimiLevel,tempLevel,valueType); } }else{ Listlist=new ArrayList(); list.add(id); getNoChildFileNum(list, id,StartTime,EndTime,mimiLevel,tempLevel,valueType); }}catch(Exception e){ this.log.error(e.getMessage(), e); } // log.info("最终JSON==="+json.toString()); if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); } String result="{\"rows\":["+json.toString()+"]}"; // Listlist=getCmpList(id, new ArrayList()); log.info("result===="+result); return result; } public List getCmpList(String id,Listlist) { try{ if(checkId(id)){//存在子节点且子节点在明细表中有记录 list.add(id); String sql="select dept_id from sys_department where parent_id='"+id+"'"; ListtempList= persistence.getSearchResult(99, sql.toString()); log.info("getCmpList.tempList.size===="+tempList.size()); 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 void getFileNum(Listlist,String id,String StartTime,String EndTime,String mimiLevel,String tempLevel,String valueType) throws PersistenceException{ try{ for(int i=0;itempList= persistence.getSearchResult(99, sql.toString()); if(tempList.size()>0){ fa.setEnpDoc(Integer.parseInt(tempList.get(0)[1])); fa.setEnpSys(Integer.parseInt(tempList.get(0)[2])); fa.setEnpArd(Integer.parseInt(tempList.get(0)[3])); fa.setNum(Integer.parseInt(tempList.get(0)[4])); numList.add(fa); if(fa.getNum()>0){ if(checkId(id)){ json.append("{ "); json.append(" \"enpdoc\":\"" + fa.getEnpDoc() + "\","); json.append(" \"enpsys\":\"" + fa.getEnpSys() + "\","); json.append(" \"enpard\":\"" + fa.getEnpArd() + "\","); json.append(" \"num\":\"" + fa.getNum() + "\","); json.append(" \"name\":\"" + getNameById(list.get(i)) + "\","); json.append(" \"dept_id\":\"" + list.get(i) + "\","); json.append(" \"isParent\":true,"); json.append(" \"open\":false"); json.append("}, "); }else{ json.append("{ "); json.append(" \"enpdoc\":\"" + fa.getEnpDoc() + "\","); json.append(" \"enpsys\":\"" + fa.getEnpSys() + "\","); json.append(" \"enpard\":\"" + fa.getEnpArd() + "\","); json.append(" \"num\":\"" + fa.getNum() + "\","); json.append(" \"name\":\"" + getNameById(list.get(i)) + "\","); json.append(" \"dept_id\":\"" + list.get(i) + "\","); json.append(" \"isParent\":false,"); json.append(" \"open\":false"); json.append("}, "); } } } }}catch(Exception e){ this.log.error(e.getMessage(), e); } } public void getNoChildFileNum(Listlist,String id,String StartTime,String EndTime,String mimiLevel,String tempLevel,String valueType) throws PersistenceException{ DocBean fa = new DocBean(); try{ for(int i=0;inumList= persistence.getSearchResult(99, sql.toString()); if(numList.size()>0){ fa.setEnpDoc(fa.getEnpDoc()+Integer.parseInt(numList.get(0)[1])); fa.setEnpSys(fa.getEnpSys()+Integer.parseInt(numList.get(0)[2])); fa.setEnpArd(fa.getEnpArd()+Integer.parseInt(numList.get(0)[3])); fa.setNum(fa.getNum()+Integer.parseInt(numList.get(0)[4])); } }}catch(Exception e){ this.log.error(e.getMessage(), e); } // StringBuffer json=new StringBuffer(); if(fa.getNum()>0){ json.append("{ "); json.append(" \"enpdoc\":\"" + fa.getEnpDoc() + "\","); json.append(" \"enpsys\":\"" + fa.getEnpSys() + "\","); json.append(" \"enpard\":\"" + fa.getEnpArd() + "\","); json.append(" \"num\":\"" + fa.getNum() + "\","); json.append(" \"name\":\"" + getNameById(id) + "\","); json.append(" \"dept_id\":\"" + id + "\","); json.append(" \"isParent\":false,"); json.append(" \"open\":true"); json.append("}, "); numList.add(fa); } } public String getNameById(String id){ String sql="select dept_name from sys_department where dept_id='"+id+"'"; try { ListtempList= persistence.getSearchResult(99, sql.toString()); if(tempList==null||tempList.size()==0){ return ""; }else{ String name=tempList.get(0)[0].replace("供电局", "").replace("电网有限责任公司", "电网"); log.info("name===="+name); return name; } } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } } /********************************发布、共享********************************************/ /** * 发布文件 除本级外都可以看到 * @throws ClassNotFoundException */ public Msg getDocuFabu(String fd_id) throws ClassNotFoundException{ Msg m=new Msg(); String []arr=fd_id.split(","); String sql="UPDATE EMC_AM_BUSINESS_DOCUMENT SET COLUMN_3='1' 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