package com.sinosoft.am.resource.generator_car.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.resource.generator_car.vo.CarNum; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; public class GeneratorCarDao{ 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 carNumInit(String id,String content1,String content2,String valueType,String valueType2,String valueType3,String deptId){ try{ // String sql="select dept_id from sys_department where (parent_id='"+id+"' or dept_id='"+id+"')"; // if(deptId!=null&&!"".equals(deptId)&&!"null".equals(deptId)){ // sql+=" and DEPT_ID in("+deptId+") "; // } // sql+="order by sort"; String sql=""; if("1".equals(levelId(id))){ }else if("2".equals(levelId(id))){ sql="select dept_id from sys_department where dept_type='1' and (parent_id='"+id+"' )";//or dept_id='"+id+"' if(deptId!=null && !"".equals(deptId)){ sql+=" and dept_id in("+deptId+")"; } sql+=" order by sort"; }else if("3".equals(levelId(id))||"4".equals(levelId(id))||"5".equals(levelId(id))){ sql="select dept_id from sys_department where dept_type='1' and (parent_id='"+id+"' or dept_id='"+id+"' )"; if(deptId!=null && !"".equals(deptId)){ sql+=" and dept_id in("+deptId+")"; } sql+=" order by dept_level,sort"; } 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); getNoChildCarNum(list, id,content1,content2,valueType,valueType2,valueType3); }}catch(Exception e){ this.log.error(e.getMessage(), e); } // log.info("最终JSON==="+json.toString()); /*if (json.lastIndexOf(",") > -1) { json.deleteCharAt(json.lastIndexOf(",")); }*/ CarNum numBean=new CarNum(); for(int i=0;ilist=getCmpList(id, new ArrayList()); log.info("result===="+result); return result; } public String carNum(String id,String content1,String content2,String valueType,String valueType2,String valueType3){ try{ if(checkId(id)){ String sql="SELECT dept_id FROM SYS_DEPARTMENT 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],content1,content2,valueType,valueType2,valueType3,id); } }else{ Listlist=new ArrayList(); list.add(id); getNoChildCarNum(list, id,content1,content2,valueType,valueType2,valueType3); }}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 String levelId(String id) { try{ String sql="select dept_level from SYS_DEPARTMENT WHERE dept_id = '"+id+"' "; ListtempList= persistence.getSearchResult(99, sql.toString()); if(tempList==null||tempList.size()==0){ return "0"; }else{ return tempList.get(0)[0]; }}catch(Exception e){ this.log.error(e.getMessage(), e); return "0"; } } public void getCarNum(Listlist,String id,String content1,String content2,String valueType,String valueType2,String valueType3,String zsId) throws PersistenceException{ try{ String team_comp = ""; for(int i=0;i=251 and car_content<=500 then car_num else 0 end) as content_mid," + "sum(case when car_content>=501 then car_num else 0 end) as content_max," + "sum(case car_level when '139' then car_num else 0 end)as level_max," + "sum(case car_level when '138' then car_num else 0 end)as level_min," + "sum(case STORED_ENERGY_TYPE when '1' then car_num else 0 end)as generator," + "sum(case STORED_ENERGY_TYPE when '2' then car_num else 0 end)as ups," + "sum(case STORED_ENERGY_TYPE when '3' then car_num else 0 end)as fly_circle ," + "sum(car_num)as num, sum(car_content*car_num) as sm," + "sum(case IS_USED when '1' then car_num else 0 end)as kdy," + "sum(case IS_USED when '2' then car_num else 0 end)as bkdy " + "from emc_am_generator_car where is_del='0' and comp_id in ("+team_comp+") "; /*//容量 if(content1!=null&&!"".equals(content1)&&!"null".equals(content1)){ sql+=" and CAR_CONTENT between '"+content1+"' and '"+content2+"'"; } //电压等级valueType if(valueType!=null&&!"".equals(valueType)&&!"null".equals(valueType)){ sql+=" and CAR_LEVEL in( "+valueType+")"; } //储能方式 if(valueType2!=null&&!"".equals(valueType2)&&!"null".equals(valueType2)){ sql+=" and STORED_ENERGY_TYPE in ("+valueType2+") "; }*/ //可否调用 if(valueType3!=null&&!"".equals(valueType3)&&!"null".equals(valueType3)){ sql+=" and IS_USED in( "+valueType3+" )"; } //comp_id sql+=" group by is_del "; log.info("getCarNum.sql===="+sql); ListtempList= persistence.getSearchResult(99, sql.toString()); if(tempList.size()>0){ cn.setContent_min(Integer.parseInt(tempList.get(0)[1])); cn.setContent_mid(Integer.parseInt(tempList.get(0)[2])); cn.setContent_max(Integer.parseInt(tempList.get(0)[3])); cn.setLevel_max(Integer.parseInt(tempList.get(0)[4])); cn.setLevel_min(Integer.parseInt(tempList.get(0)[5])); cn.setGenerator(Integer.parseInt(tempList.get(0)[6])); cn.setUps(Integer.parseInt(tempList.get(0)[7])); cn.setFly_circle(Integer.parseInt(tempList.get(0)[8])); cn.setNum(Integer.parseInt(tempList.get(0)[9])); cn.setSum(Double.parseDouble(tempList.get(0)[10])); cn.setKused(Integer.parseInt(tempList.get(0)[11])); cn.setBused(Integer.parseInt(tempList.get(0)[12])); numList.add(cn); 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(" \"sum\":\"" + cn.getSum() + "\","); json.append(" \"kused\":\"" + cn.getKused() + "\","); json.append(" \"bused\":\"" + cn.getBused() + "\","); 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(" \"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(" \"sum\":\"" + cn.getSum() + "\","); json.append(" \"kused\":\"" + cn.getKused() + "\","); json.append(" \"bused\":\"" + cn.getBused() + "\","); 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); } // StringBuffer json=new StringBuffer(); // 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("}, "); } public void getNoChildCarNum(Listlist,String id,String content1,String content2,String valueType,String valueType2,String valueType3) throws PersistenceException{ CarNum cn=new CarNum(); try{ for(int i=0;i=251 and car_content<=500 then car_num else 0 end) as content_mid," + "sum(case when car_content>=501 then car_num else 0 end) as content_max," + "sum(case car_level when '139' then car_num else 0 end)as level_max," + "sum(case car_level when '138' then car_num else 0 end)as level_min," + "sum(case STORED_ENERGY_TYPE when '1' then car_num else 0 end)as generator," + "sum(case STORED_ENERGY_TYPE when '2' then car_num else 0 end)as ups," + "sum(case STORED_ENERGY_TYPE when '3' then car_num else 0 end)as fly_circle ," + "sum(car_num)as num, sum(car_content*car_num) as sm," + "sum(case IS_USED when '1' then car_num else 0 end)as kdy," + "sum(case IS_USED when '2' then car_num else 0 end)as bkdy " + "from emc_am_generator_car where is_del='0' and comp_id='"+list.get(i)+"'"; /*//容量 if(content1!=null&&!"".equals(content1)&&!"null".equals(content1)){ sql+=" and CAR_CONTENT between '"+content1+"' and '"+content2+"'"; } //电压等级valueType if(valueType!=null&&!"".equals(valueType)&&!"null".equals(valueType)){ sql+=" and CAR_LEVEL in( "+valueType+")"; } //储能方式 if(valueType2!=null&&!"".equals(valueType2)&&!"null".equals(valueType2)){ sql+=" and STORED_ENERGY_TYPE in ("+valueType2+") "; }*/ //可否调用 if(valueType3!=null&&!"".equals(valueType3)&&!"null".equals(valueType3)){ sql+=" and IS_USED in( "+valueType3+" )"; } //comp_id sql+=" group by comp_id"; log.info("getCarNum.sql===="+sql); ListnumList= 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)[4])); cn.setLevel_min(cn.getLevel_min()+Integer.parseInt(numList.get(0)[5])); cn.setGenerator(cn.getGenerator()+Integer.parseInt(numList.get(0)[6])); cn.setUps(cn.getUps()+Integer.parseInt(numList.get(0)[7])); cn.setFly_circle(cn.getFly_circle()+Integer.parseInt(numList.get(0)[8])); cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[9])); cn.setSum(cn.getSum()+Double.parseDouble(numList.get(0)[10])); cn.setKused(cn.getKused()+Integer.parseInt(numList.get(0)[11])); cn.setBused(cn.getBused()+Integer.parseInt(numList.get(0)[12])); } }}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(" \"sum\":\"" + cn.getSum() + "\","); json.append(" \"kused\":\"" + cn.getKused() + "\","); json.append(" \"bused\":\"" + cn.getBused() + "\","); 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 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("供电局", ""); log.info("name===="+name); return name; } } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } } /**************************************调拨*************************************/ /** * 调拨 * @throws ClassNotFoundException */ public Msg getCardiaobo(String fd_id,String number) throws ClassNotFoundException{ Msg m=new Msg(); String []arr=fd_id.split(","); log.info(number); String sql=""; if(number.equals("1")){ sql="UPDATE emc_am_generator_car SET USED_STAT='1',IS_USED='1' where fd_objectid=?"; }else if(number.equals("2")){ sql="UPDATE emc_am_generator_car SET USED_STAT='2',IS_USED='2' where fd_objectid=?"; }else if(number.equals("3")){ sql="UPDATE emc_am_generator_car SET USED_STAT='3',IS_USED='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