123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- /**
- *
- */
- 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 List<CommandCarNum>numList=new ArrayList<CommandCarNum>();
-
- //
- // 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+"'";
- 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>());
- getCarNum(list, tempList.get(i)[0]);
- }
- }else{
- List<String>list=new ArrayList<String>();
- 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;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.setLevel_max(numBean.getLevel_max()+numList.get(i).getLevel_max());
- numBean.setLevel_min(numBean.getLevel_min()+numList.get(i).getLevel_min());
- numBean.setGenerator(numBean.getGenerator()+numList.get(i).getGenerator());
- numBean.setUps(numBean.getUps()+numList.get(i).getUps());
- numBean.setFly_circle(numBean.getFly_circle()+numList.get(i).getFly_circle());
- 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(" \"level_min\":\"" + numBean.getLevel_min() + "\",");
- json.append(" \"level_max\":\"" + numBean.getLevel_max() + "\",");
- json.append(" \"generator\":\"" + numBean.getGenerator() + "\",");
- json.append(" \"ups\":\"" + numBean.getUps() + "\",");
- json.append(" \"fly_circle\":\"" + numBean.getFly_circle() + "\",");
- 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 carNum(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>());
- getCarNum(list, tempList.get(i)[0]);
- }
- }else{
- List<String>list=new ArrayList<String>();
- 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()+"]}";
- // 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_EMERGENCY_COMMAND_CAR 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 getCarNum(List<String>list,String id) throws PersistenceException{
- CommandCarNum cn=new CommandCarNum();
- 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_emergency_command_car group by car_comp,comp_id ,is_del having is_del='0' and comp_id='"+list.get(i)+"'";
- log.info("getCarNum.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.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(List<String>list,String id) throws PersistenceException{
- CommandCarNum cn=new CommandCarNum();
- 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_emergency_command_car group by car_comp,comp_id ,is_del having is_del='0' and comp_id='"+list.get(i)+"'";
- log.info("getCarNum.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.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 {
- 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 "";
- }
- }
- }
|