/** * */ package com.sinosoft.am.resource.command_car.dao; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.exception.PersistenceException; import com.sinosoft.am.resource.command_car.vo.CommandCarNum; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; /** * @author 蒋云涛 * */ public class CommandCarDao{ private Logger log = Logger.getLogger(this.getClass()); SysModel sysmodel = ModelFactory.getSysmodel(); SysPersistence persistence = PersistenceFactory.getInstance(sysmodel); StringBuffer json = new StringBuffer(); private ListnumList=new ArrayList(); // // var gridData={"rows":[ // {"value":1,"key":"南京分公司","isParent":true,"open":false}, // {"value":7,"key":"杭州办事处","isParent":true,"open":false} // ]} /** * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据 * @param id * @return */ public String carNumInit(String id){ try{ if(checkId(id)){ String sql="select id from sys_department_0827 where parent_id='"+id+"'"; ListtempList= persistence.getSearchResult(99, sql.toString()); log.info("carNum.tempList.size===="+tempList.size()); for(int i=0;ilist=getCmpList(tempList.get(i)[0], new ArrayList()); getCarNum(list, tempList.get(i)[0]); } }else{ Listlist=new ArrayList(); list.add(id); getNoChildCarNum(list, id); }}catch(Exception e){ this.log.error(e.getMessage(), e); } // log.info("最终JSON==="+json.toString()); /* if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); }*/ CommandCarNum numBean=new CommandCarNum(); for(int i=0;ilist=getCmpList(id, new ArrayList()); log.info("result===="+result); return result; } public String carNum(String id){ try{ if(checkId(id)){ String sql="select id from sys_department_0827 where parent_id='"+id+"'"; ListtempList= persistence.getSearchResult(99, sql.toString()); log.info("carNum.tempList.size===="+tempList.size()); for(int i=0;ilist=getCmpList(tempList.get(i)[0], new ArrayList()); getCarNum(list, tempList.get(i)[0]); } }else{ Listlist=new ArrayList(); list.add(id); getNoChildCarNum(list, id); }}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 id from sys_department_0827 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 getCarNum(Listlist,String id) throws PersistenceException{ CommandCarNum cn=new CommandCarNum(); try{ for(int i=0;inumList= persistence.getSearchResult(99, sql.toString()); if(numList.size()>0){ cn.setContent_min(cn.getContent_min()+Integer.parseInt(numList.get(0)[1])); cn.setContent_mid(cn.getContent_mid()+Integer.parseInt(numList.get(0)[2])); cn.setContent_max(cn.getContent_max()+Integer.parseInt(numList.get(0)[3])); cn.setLevel_max(cn.getLevel_max()+Integer.parseInt(numList.get(0)[5])); cn.setLevel_min(cn.getLevel_min()+Integer.parseInt(numList.get(0)[6])); cn.setGenerator(cn.getGenerator()+Integer.parseInt(numList.get(0)[7])); cn.setUps(cn.getUps()+Integer.parseInt(numList.get(0)[8])); cn.setFly_circle(cn.getFly_circle()+Integer.parseInt(numList.get(0)[9])); cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[10])); } }}catch(Exception e){ this.log.error(e.getMessage(), e); } // StringBuffer json=new StringBuffer(); if(cn.getNum()>0){ if(checkId(id)){ json.append("{ "); json.append(" \"content_min\":\"" + cn.getContent_min() + "\","); json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\","); json.append(" \"content_max\":\"" + cn.getContent_max() + "\","); json.append(" \"level_min\":\"" + cn.getLevel_min() + "\","); json.append(" \"level_max\":\"" + cn.getLevel_max() + "\","); json.append(" \"generator\":\"" + cn.getGenerator() + "\","); json.append(" \"ups\":\"" + cn.getUps() + "\","); json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\","); json.append(" \"num\":\"" + cn.getNum() + "\","); json.append(" \"name\":\"" + getNameById(id) + "\","); json.append(" \"dept_id\":\"" + id + "\","); json.append(" \"isParent\":true,"); json.append(" \"open\":false"); json.append("}, "); }else{ json.append("{ "); json.append(" \"content_min\":\"" + cn.getContent_min() + "\","); json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\","); json.append(" \"content_max\":\"" + cn.getContent_max() + "\","); json.append(" \"level_min\":\"" + cn.getLevel_min() + "\","); json.append(" \"level_max\":\"" + cn.getLevel_max() + "\","); json.append(" \"generator\":\"" + cn.getGenerator() + "\","); json.append(" \"ups\":\"" + cn.getUps() + "\","); json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\","); json.append(" \"num\":\"" + cn.getNum() + "\","); json.append(" \"name\":\"" + getNameById(id) + "\","); json.append(" \"dept_id\":\"" + id + "\","); json.append(" \"isParent\":false,"); json.append(" \"open\":false"); json.append("}, "); } // json.append("{ "); // json.append(" \"content_min\":\"" + cn.getContent_min() + "\","); // json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\","); // json.append(" \"content_max\":\"" + cn.getContent_max() + "\","); // json.append(" \"level_min\":\"" + cn.getLevel_min() + "\","); // json.append(" \"level_max\":\"" + cn.getLevel_max() + "\","); // json.append(" \"generator\":\"" + cn.getGenerator() + "\","); // json.append(" \"ups\":\"" + cn.getUps() + "\","); // json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\","); // json.append(" \"num\":\"" + cn.getNum() + "\","); // json.append(" \"name\":\"" + getNameById(id) + "\","); // json.append(" \"dept_id\":\"" + id + "\","); // json.append(" \"isParent\":true,"); // json.append(" \"open\":false"); // json.append("}, "); } numList.add(cn); } public void getNoChildCarNum(Listlist,String id) throws PersistenceException{ CommandCarNum cn=new CommandCarNum(); try{ for(int i=0;inumList= persistence.getSearchResult(99, sql.toString()); if(numList.size()>0){ cn.setContent_min(cn.getContent_min()+Integer.parseInt(numList.get(0)[1])); cn.setContent_mid(cn.getContent_mid()+Integer.parseInt(numList.get(0)[2])); cn.setContent_max(cn.getContent_max()+Integer.parseInt(numList.get(0)[3])); cn.setLevel_max(cn.getLevel_max()+Integer.parseInt(numList.get(0)[5])); cn.setLevel_min(cn.getLevel_min()+Integer.parseInt(numList.get(0)[6])); cn.setGenerator(cn.getGenerator()+Integer.parseInt(numList.get(0)[7])); cn.setUps(cn.getUps()+Integer.parseInt(numList.get(0)[8])); cn.setFly_circle(cn.getFly_circle()+Integer.parseInt(numList.get(0)[9])); cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[10])); } }}catch(Exception e){ this.log.error(e.getMessage(), e); } // StringBuffer json=new StringBuffer(); if(cn.getNum()>0){ json.append("{ "); json.append(" \"content_min\":\"" + cn.getContent_min() + "\","); json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\","); json.append(" \"content_max\":\"" + cn.getContent_max() + "\","); json.append(" \"level_min\":\"" + cn.getLevel_min() + "\","); json.append(" \"level_max\":\"" + cn.getLevel_max() + "\","); json.append(" \"generator\":\"" + cn.getGenerator() + "\","); json.append(" \"ups\":\"" + cn.getUps() + "\","); json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\","); json.append(" \"num\":\"" + cn.getNum() + "\","); json.append(" \"name\":\"" + getNameById(id) + "\","); json.append(" \"dept_id\":\"" + id + "\","); json.append(" \"isParent\":false,"); json.append(" \"open\":true"); json.append("}, "); numList.add(cn); } } public String getNameById(String id){ String sql="select name from sys_department_0827 where id='"+id+"'"; try { ListtempList= persistence.getSearchResult(99, sql.toString()); if(tempList==null||tempList.size()==0){ return ""; }else{ String name=tempList.get(0)[0]; log.info("name===="+name); return name; } } catch (PersistenceException e) { e.printStackTrace(); return ""; } } }