123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- /**
- *
- */
- package com.sinosoft.am.resource.ups_generator.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.ups_generator.vo.UPSGeneratorNum;
- import com.sysmodel.datamodel.xmlmodel.ModelFactory;
- import com.sysmodel.datamodel.xmlmodel.able.SysModel;
- /**
- * @author 蒋云涛
- *
- */
- public class UPSGeneratorDao{
- private Logger log = Logger.getLogger(this.getClass());
- SysModel sysmodel = ModelFactory.getSysmodel();
- SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
- StringBuffer json = new StringBuffer();
- private List<UPSGeneratorNum>numList=new ArrayList<UPSGeneratorNum>();
-
-
- /**
- * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
- * @param id
- * @return
- */
- public String UPSGeneratorNumInit(String id){
- try{
- if(checkId(id)){
- String sql="select id from sys_department_0827 where parent_id='"+id+"'";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- log.info("carNum.tempList.size===="+tempList.size());
- for(int i=0;i<tempList.size();i++){
- List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
- getUPSGeneratorNum(list, tempList.get(i)[0]);
- }
- }else{
- List<String>list=new ArrayList<String>();
- list.add(id);
- getNoChildUPSGeneratorNum(list, id);
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- // log.info("最终JSON==="+json.toString()); 统计栏
- /*if (json.lastIndexOf(",") > -1) {
- json.deleteCharAt(json.lastIndexOf(","));
- }*/
- UPSGeneratorNum numBean=new UPSGeneratorNum();
- for(int i=0;i<numList.size();i++){
- numBean.setContent_min(numBean.getContent_min()+numList.get(i).getContent_min());
- numBean.setContent_mid(numBean.getContent_mid()+numList.get(i).getContent_mid());
- numBean.setContent_max(numBean.getContent_max()+numList.get(i).getContent_max());
- numBean.setNum(numBean.getNum()+numList.get(i).getNum());
- }
- json.append("{ ");
- json.append(" \"content_min\":\"" + numBean.getContent_min() + "\",");
- json.append(" \"content_mid\":\"" + numBean.getContent_mid() + "\",");
- json.append(" \"content_max\":\"" + numBean.getContent_max() + "\",");
- json.append(" \"num\":\"" + numBean.getNum() + "\",");
- json.append(" \"name\":\"" +"总计" + "\",");
- json.append(" \"dept_id\":\"" + "11111" + "\",");
- json.append(" \"isParent\":false,");
- json.append(" \"open\":false");
- json.append("} ");
- String result="{\"rows\":["+json.toString()+"]}";
- // List<String>list=getCmpList(id, new ArrayList<String>());
- log.info("result===="+result);
- return result;
- }
-
- public String UPSGeneratorNum(String id){
- try{
- if(checkId(id)){
- String sql="select id from sys_department_0827 where parent_id='"+id+"'";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- log.info("generatorNum.tempList.size===="+tempList.size());
- for(int i=0;i<tempList.size();i++){
- List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
- getUPSGeneratorNum(list, tempList.get(i)[0]);
- }
- }else{
- List<String>list=new ArrayList<String>();
- list.add(id);
- getNoChildUPSGeneratorNum(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()+"]}";
- // List<String>list=getCmpList(id, new ArrayList<String>());
- log.info("result===="+result);
- return result;
- }
-
- public List<String> getCmpList(String id,List<String>list) {
- try{
- if(checkId(id)){//存在子节点且子节点在明细表中有记录
- list.add(id);
- String sql="select id from sys_department_0827 where parent_id='"+id+"'";
- List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
- log.info("getCmpList.tempList.size===="+tempList.size());
- for(int i=0;i<tempList.size();i++){
- getCmpList(tempList.get(i)[0],list);
- }
- }
- else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
- list.add(id);
- }}catch(Exception e){
- this.log.error(e.getMessage(), e);
- }
- return list;
- }
-
- public boolean checkId(String id) {
- try{
- String sql="SELECT * FROM EMC_AM_UPS_GENERATOR WHERE COMP_ID IN(SELECT ID FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"')";
- List<String[]>tempList= 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 getUPSGeneratorNum(List<String>list,String id) throws PersistenceException{
- UPSGeneratorNum cn=new UPSGeneratorNum();
- try{
- for(int i=0;i<list.size();i++){
- // String sql="select comp_id,sum(case when car_content<250 then car_num else 0 end) "
- // + "as content_min,sum(case when car_content>250 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,car_comp,sum(case car_level when '380V' then car_num else 0 end)as"
- // + " level_max,sum(case car_level when '10kV' then car_num else 0 end)as level_min,sum(case "
- // + "STORED_ENERGY_TYPE when '发电机' then car_num else 0 end)as generator,sum(case STORED_ENERGY_TYPE "
- // + "when 'UPS' then car_num else 0 end)as ups,sum(case STORED_ENERGY_TYPE when '磁飞轮' then car_num"
- // + " else 0 end)as fly_circle ,sum(car_num)as num ,is_del from emc_am_generator_car group by car_comp,comp_id "
- // + ",is_del having is_del='0' and comp_id='"+list.get(i)+"'";
- String sql ="select comp_id , sum(case when content<10 then num else 0 end) as content_min, sum(case when content>11 and content<50 then num else 0 end) as content_mid,"
- + "sum(case when content>51 then num else 0 end) as content_max,comp,sum(num) as num,is_del from emc_am_ups_generator group by comp,comp_id,is_del having is_del='0' and "
- + "comp_id='"+list.get(i)+"'";
- log.info("getUPSGeneratorNum.sql===="+sql);
- List<String[]>numList= 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.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[5]));
- }
- }}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(" \"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(" \"num\":\"" + cn.getNum() + "\",");
- json.append(" \"name\":\"" + getNameById(id) + "\",");
- json.append(" \"dept_id\":\"" + id + "\",");
- json.append(" \"isParent\":false,");
- json.append(" \"open\":false");
- json.append("}, ");
- }
- }
- numList.add(cn);
- }
-
-
- public void getNoChildUPSGeneratorNum(List<String>list,String id) throws PersistenceException{
- UPSGeneratorNum cn=new UPSGeneratorNum();
- try{
- for(int i=0;i<list.size();i++){
- String sql ="select comp_id , sum(case when content<10 then num else 0 end) as content_min, sum(case when content>11 and content<50 then num else 0 end) as content_mid,"
- + "sum(case when content>51 then num else 0 end) as content_max,comp,sum(num) as num,is_del from emc_am_ups_generator group by comp,comp_id,is_del having is_del='0' and "
- + "comp_id='"+list.get(i)+"'";
- log.info("getNoChildUPSGeneratorNum.sql===="+sql);
- List<String[]>numList= 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.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[5]));
- }
- }}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(" \"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 {
- List<String[]>tempList= 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 "";
- }
- }
- }
|