fc84b35db60c75ab75c8e57ddbcd7e8137c41022.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /**
  2. *
  3. */
  4. package com.sinosoft.am.resource.command_car.dao;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import org.apache.log4j.Logger;
  8. import com.persistence.service.PersistenceFactory;
  9. import com.persistence.service.SysPersistence;
  10. import com.persistence.service.exception.PersistenceException;
  11. import com.sinosoft.am.resource.command_car.vo.CommandCarNum;
  12. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  13. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  14. /**
  15. * @author 蒋云涛
  16. *
  17. */
  18. public class CommandCarDao{
  19. private Logger log = Logger.getLogger(this.getClass());
  20. SysModel sysmodel = ModelFactory.getSysmodel();
  21. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  22. StringBuffer json = new StringBuffer();
  23. private List<CommandCarNum>numList=new ArrayList<CommandCarNum>();
  24. //
  25. // var gridData={"rows":[
  26. // {"value":1,"key":"南京分公司","isParent":true,"open":false},
  27. // {"value":7,"key":"杭州办事处","isParent":true,"open":false}
  28. // ]}
  29. /**
  30. * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
  31. * @param id
  32. * @return
  33. */
  34. public String carNumInit(String id){
  35. try{
  36. if(checkId(id)){
  37. String sql="select id from sys_department_0827 where parent_id='"+id+"'";
  38. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  39. log.info("carNum.tempList.size===="+tempList.size());
  40. for(int i=0;i<tempList.size();i++){
  41. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  42. getCarNum(list, tempList.get(i)[0]);
  43. }
  44. }else{
  45. List<String>list=new ArrayList<String>();
  46. list.add(id);
  47. getNoChildCarNum(list, id);
  48. }}catch(Exception e){
  49. this.log.error(e.getMessage(), e);
  50. }
  51. // log.info("最终JSON==="+json.toString());
  52. /* if (json.lastIndexOf(",") > -1) {
  53. json.deleteCharAt(json.lastIndexOf(","));
  54. }*/
  55. CommandCarNum numBean=new CommandCarNum();
  56. for(int i=0;i<numList.size();i++){
  57. numBean.setContent_min(numBean.getContent_min()+numList.get(i).getContent_min());
  58. numBean.setContent_mid(numBean.getContent_mid()+numList.get(i).getContent_mid());
  59. numBean.setContent_max(numBean.getContent_max()+numList.get(i).getContent_max());
  60. numBean.setLevel_max(numBean.getLevel_max()+numList.get(i).getLevel_max());
  61. numBean.setLevel_min(numBean.getLevel_min()+numList.get(i).getLevel_min());
  62. numBean.setGenerator(numBean.getGenerator()+numList.get(i).getGenerator());
  63. numBean.setUps(numBean.getUps()+numList.get(i).getUps());
  64. numBean.setFly_circle(numBean.getFly_circle()+numList.get(i).getFly_circle());
  65. numBean.setNum(numBean.getNum()+numList.get(i).getNum());
  66. }
  67. json.append("{ ");
  68. json.append(" \"content_min\":\"" + numBean.getContent_min() + "\",");
  69. json.append(" \"content_mid\":\"" + numBean.getContent_mid() + "\",");
  70. json.append(" \"content_max\":\"" + numBean.getContent_max() + "\",");
  71. json.append(" \"level_min\":\"" + numBean.getLevel_min() + "\",");
  72. json.append(" \"level_max\":\"" + numBean.getLevel_max() + "\",");
  73. json.append(" \"generator\":\"" + numBean.getGenerator() + "\",");
  74. json.append(" \"ups\":\"" + numBean.getUps() + "\",");
  75. json.append(" \"fly_circle\":\"" + numBean.getFly_circle() + "\",");
  76. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  77. json.append(" \"name\":\"" +"总计" + "\",");
  78. json.append(" \"dept_id\":\"" + "11111" + "\",");
  79. json.append(" \"isParent\":false,");
  80. json.append(" \"open\":false");
  81. json.append("} ");
  82. String result="{\"rows\":["+json.toString()+"]}";
  83. // List<String>list=getCmpList(id, new ArrayList<String>());
  84. log.info("result===="+result);
  85. return result;
  86. }
  87. public String carNum(String id){
  88. try{
  89. if(checkId(id)){
  90. String sql="select id from sys_department_0827 where parent_id='"+id+"'";
  91. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  92. log.info("carNum.tempList.size===="+tempList.size());
  93. for(int i=0;i<tempList.size();i++){
  94. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  95. getCarNum(list, tempList.get(i)[0]);
  96. }
  97. }else{
  98. List<String>list=new ArrayList<String>();
  99. list.add(id);
  100. getNoChildCarNum(list, id);
  101. }}catch(Exception e){
  102. this.log.error(e.getMessage(), e);
  103. }
  104. // log.info("最终JSON==="+json.toString());
  105. if (json.lastIndexOf(",") > -1) {
  106. json.deleteCharAt(json.lastIndexOf(","));
  107. }
  108. String result="{\"rows\":["+json.toString()+"]}";
  109. // List<String>list=getCmpList(id, new ArrayList<String>());
  110. log.info("result===="+result);
  111. return result;
  112. }
  113. public List<String> getCmpList(String id,List<String>list) {
  114. try{
  115. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  116. list.add(id);
  117. String sql="select id from sys_department_0827 where parent_id='"+id+"'";
  118. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  119. log.info("getCmpList.tempList.size===="+tempList.size());
  120. for(int i=0;i<tempList.size();i++){
  121. getCmpList(tempList.get(i)[0],list);
  122. }
  123. }
  124. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  125. list.add(id);
  126. }}catch(Exception e){
  127. this.log.error(e.getMessage(), e);
  128. }
  129. return list;
  130. }
  131. public boolean checkId(String id) {
  132. try{
  133. String sql="select * from EMC_AM_EMERGENCY_COMMAND_CAR WHERE COMP_ID IN(SELECT ID FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"')";
  134. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  135. if(tempList==null||tempList.size()==0){
  136. return false;
  137. }else{
  138. return true;
  139. }}catch(Exception e){
  140. this.log.error(e.getMessage(), e);
  141. return false;
  142. }
  143. }
  144. public void getCarNum(List<String>list,String id) throws PersistenceException{
  145. CommandCarNum cn=new CommandCarNum();
  146. try{
  147. for(int i=0;i<list.size();i++){
  148. 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)+"'";
  149. log.info("getCarNum.sql===="+sql);
  150. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  151. if(numList.size()>0){
  152. cn.setContent_min(cn.getContent_min()+Integer.parseInt(numList.get(0)[1]));
  153. cn.setContent_mid(cn.getContent_mid()+Integer.parseInt(numList.get(0)[2]));
  154. cn.setContent_max(cn.getContent_max()+Integer.parseInt(numList.get(0)[3]));
  155. cn.setLevel_max(cn.getLevel_max()+Integer.parseInt(numList.get(0)[5]));
  156. cn.setLevel_min(cn.getLevel_min()+Integer.parseInt(numList.get(0)[6]));
  157. cn.setGenerator(cn.getGenerator()+Integer.parseInt(numList.get(0)[7]));
  158. cn.setUps(cn.getUps()+Integer.parseInt(numList.get(0)[8]));
  159. cn.setFly_circle(cn.getFly_circle()+Integer.parseInt(numList.get(0)[9]));
  160. cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[10]));
  161. }
  162. }}catch(Exception e){
  163. this.log.error(e.getMessage(), e);
  164. }
  165. // StringBuffer json=new StringBuffer();
  166. if(cn.getNum()>0){
  167. if(checkId(id)){
  168. json.append("{ ");
  169. json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  170. json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  171. json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  172. json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  173. json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  174. json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  175. json.append(" \"ups\":\"" + cn.getUps() + "\",");
  176. json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  177. json.append(" \"num\":\"" + cn.getNum() + "\",");
  178. json.append(" \"name\":\"" + getNameById(id) + "\",");
  179. json.append(" \"dept_id\":\"" + id + "\",");
  180. json.append(" \"isParent\":true,");
  181. json.append(" \"open\":false");
  182. json.append("}, ");
  183. }else{
  184. json.append("{ ");
  185. json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  186. json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  187. json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  188. json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  189. json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  190. json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  191. json.append(" \"ups\":\"" + cn.getUps() + "\",");
  192. json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  193. json.append(" \"num\":\"" + cn.getNum() + "\",");
  194. json.append(" \"name\":\"" + getNameById(id) + "\",");
  195. json.append(" \"dept_id\":\"" + id + "\",");
  196. json.append(" \"isParent\":false,");
  197. json.append(" \"open\":false");
  198. json.append("}, ");
  199. }
  200. // json.append("{ ");
  201. // json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  202. // json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  203. // json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  204. // json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  205. // json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  206. // json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  207. // json.append(" \"ups\":\"" + cn.getUps() + "\",");
  208. // json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  209. // json.append(" \"num\":\"" + cn.getNum() + "\",");
  210. // json.append(" \"name\":\"" + getNameById(id) + "\",");
  211. // json.append(" \"dept_id\":\"" + id + "\",");
  212. // json.append(" \"isParent\":true,");
  213. // json.append(" \"open\":false");
  214. // json.append("}, ");
  215. }
  216. numList.add(cn);
  217. }
  218. public void getNoChildCarNum(List<String>list,String id) throws PersistenceException{
  219. CommandCarNum cn=new CommandCarNum();
  220. try{
  221. for(int i=0;i<list.size();i++){
  222. 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)+"'";
  223. log.info("getCarNum.sql===="+sql);
  224. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  225. if(numList.size()>0){
  226. cn.setContent_min(cn.getContent_min()+Integer.parseInt(numList.get(0)[1]));
  227. cn.setContent_mid(cn.getContent_mid()+Integer.parseInt(numList.get(0)[2]));
  228. cn.setContent_max(cn.getContent_max()+Integer.parseInt(numList.get(0)[3]));
  229. cn.setLevel_max(cn.getLevel_max()+Integer.parseInt(numList.get(0)[5]));
  230. cn.setLevel_min(cn.getLevel_min()+Integer.parseInt(numList.get(0)[6]));
  231. cn.setGenerator(cn.getGenerator()+Integer.parseInt(numList.get(0)[7]));
  232. cn.setUps(cn.getUps()+Integer.parseInt(numList.get(0)[8]));
  233. cn.setFly_circle(cn.getFly_circle()+Integer.parseInt(numList.get(0)[9]));
  234. cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[10]));
  235. }
  236. }}catch(Exception e){
  237. this.log.error(e.getMessage(), e);
  238. }
  239. // StringBuffer json=new StringBuffer();
  240. if(cn.getNum()>0){
  241. json.append("{ ");
  242. json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  243. json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  244. json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  245. json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  246. json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  247. json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  248. json.append(" \"ups\":\"" + cn.getUps() + "\",");
  249. json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  250. json.append(" \"num\":\"" + cn.getNum() + "\",");
  251. json.append(" \"name\":\"" + getNameById(id) + "\",");
  252. json.append(" \"dept_id\":\"" + id + "\",");
  253. json.append(" \"isParent\":false,");
  254. json.append(" \"open\":true");
  255. json.append("}, ");
  256. numList.add(cn);
  257. }
  258. }
  259. public String getNameById(String id){
  260. String sql="select name from sys_department_0827 where id='"+id+"'";
  261. try {
  262. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  263. if(tempList==null||tempList.size()==0){
  264. return "";
  265. }else{
  266. String name=tempList.get(0)[0];
  267. log.info("name===="+name);
  268. return name;
  269. }
  270. } catch (PersistenceException e) {
  271. e.printStackTrace();
  272. return "";
  273. }
  274. }
  275. }