2cb616bc410f5c6f1ea199cdf9a5c582371ab85a.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. package com.sinosoft.am.resource.generator_car.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import org.apache.log4j.Logger;
  8. import com.formaction.Parameter;
  9. import com.formaction.vo.Msg;
  10. import com.persistence.DbConnection;
  11. import com.persistence.service.PersistenceFactory;
  12. import com.persistence.service.SysPersistence;
  13. import com.persistence.service.exception.PersistenceException;
  14. import com.sinosoft.am.resource.generator_car.vo.CarNum;
  15. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  16. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  17. public class GeneratorCarDao{
  18. private Logger log = Logger.getLogger(this.getClass());
  19. SysModel sysmodel = ModelFactory.getSysmodel();
  20. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  21. StringBuffer json = new StringBuffer();
  22. private List<CarNum>numList=new ArrayList<CarNum>();
  23. /**
  24. * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
  25. * @param id
  26. * @return
  27. */
  28. public String carNumInit(String id,String content1,String content2,String valueType,String valueType2,String valueType3,String deptId){
  29. try{
  30. // String sql="select dept_id from sys_department where (parent_id='"+id+"' or dept_id='"+id+"')";
  31. // if(deptId!=null&&!"".equals(deptId)&&!"null".equals(deptId)){
  32. // sql+=" and DEPT_ID in("+deptId+") ";
  33. // }
  34. // sql+="order by sort";
  35. String sql="";
  36. if("1".equals(levelId(id))){
  37. }else if("2".equals(levelId(id))){
  38. sql="select dept_id from sys_department where dept_type='1' and (parent_id='"+id+"' )";//or dept_id='"+id+"'
  39. if(deptId!=null && !"".equals(deptId)){
  40. sql+=" and dept_id in("+deptId+")";
  41. }
  42. sql+=" order by sort";
  43. }else if("3".equals(levelId(id))||"4".equals(levelId(id))||"5".equals(levelId(id))){
  44. sql="select dept_id from sys_department where dept_type='1' and (parent_id='"+id+"' or dept_id='"+id+"' )";
  45. if(deptId!=null && !"".equals(deptId)){
  46. sql+=" and dept_id in("+deptId+")";
  47. }
  48. sql+=" order by dept_level,sort";
  49. }
  50. if(checkId(id)){
  51. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  52. log.info("carNum.tempList.size===="+tempList.size());
  53. List<String>list=new ArrayList<String>();
  54. for(int i=0;i<tempList.size();i++){
  55. list.add(tempList.get(i)[0]);
  56. }
  57. getCarNum(list, list.get(0),content1,content2,valueType,valueType2,valueType3,id);
  58. }else{
  59. List<String>list=new ArrayList<String>();
  60. list.add(id);
  61. getNoChildCarNum(list, id,content1,content2,valueType,valueType2,valueType3);
  62. }}catch(Exception e){
  63. this.log.error(e.getMessage(), e);
  64. }
  65. // log.info("最终JSON==="+json.toString());
  66. /*if (json.lastIndexOf(",") > -1) {
  67. json.deleteCharAt(json.lastIndexOf(","));
  68. }*/
  69. CarNum numBean=new CarNum();
  70. for(int i=0;i<numList.size();i++){
  71. numBean.setContent_min(numBean.getContent_min()+numList.get(i).getContent_min());
  72. numBean.setContent_mid(numBean.getContent_mid()+numList.get(i).getContent_mid());
  73. numBean.setContent_max(numBean.getContent_max()+numList.get(i).getContent_max());
  74. numBean.setLevel_max(numBean.getLevel_max()+numList.get(i).getLevel_max());
  75. numBean.setLevel_min(numBean.getLevel_min()+numList.get(i).getLevel_min());
  76. numBean.setGenerator(numBean.getGenerator()+numList.get(i).getGenerator());
  77. numBean.setUps(numBean.getUps()+numList.get(i).getUps());
  78. numBean.setFly_circle(numBean.getFly_circle()+numList.get(i).getFly_circle());
  79. numBean.setNum(numBean.getNum()+numList.get(i).getNum());
  80. numBean.setSum(numBean.getSum()+numList.get(i).getSum());
  81. numBean.setKused(numBean.getKused()+numList.get(i).getKused());
  82. numBean.setBused(numBean.getBused()+numList.get(i).getBused());
  83. }
  84. json.append("{ ");
  85. json.append(" \"content_min\":\"" + numBean.getContent_min() + "\",");
  86. json.append(" \"content_mid\":\"" + numBean.getContent_mid() + "\",");
  87. json.append(" \"content_max\":\"" + numBean.getContent_max() + "\",");
  88. json.append(" \"level_min\":\"" + numBean.getLevel_min() + "\",");
  89. json.append(" \"level_max\":\"" + numBean.getLevel_max() + "\",");
  90. json.append(" \"generator\":\"" + numBean.getGenerator() + "\",");
  91. json.append(" \"ups\":\"" + numBean.getUps() + "\",");
  92. json.append(" \"fly_circle\":\"" + numBean.getFly_circle() + "\",");
  93. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  94. json.append(" \"sum\":\"" + numBean.getSum() + "\",");
  95. json.append(" \"kused\":\"" + numBean.getKused() + "\",");
  96. json.append(" \"bused\":\"" + numBean.getBused() + "\",");
  97. json.append(" \"name\":\"" +"总计" + "\",");
  98. json.append(" \"dept_id\":\"" + "11111" + "\",");
  99. json.append(" \"isParent\":false,");
  100. json.append(" \"open\":false");
  101. json.append("} ");
  102. String result="{\"rows\":["+json.toString()+"]}";
  103. // List<String>list=getCmpList(id, new ArrayList<String>());
  104. log.info("result===="+result);
  105. return result;
  106. }
  107. public String carNum(String id,String content1,String content2,String valueType,String valueType2,String valueType3){
  108. try{
  109. if(checkId(id)){
  110. String sql="SELECT dept_id FROM SYS_DEPARTMENT WHERE PARENT_ID='"+id+"'";
  111. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  112. log.info("carNum.tempList.size===="+tempList.size());
  113. for(int i=0;i<tempList.size();i++){
  114. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  115. getCarNum(list, tempList.get(i)[0],content1,content2,valueType,valueType2,valueType3,id);
  116. }
  117. }else{
  118. List<String>list=new ArrayList<String>();
  119. list.add(id);
  120. getNoChildCarNum(list, id,content1,content2,valueType,valueType2,valueType3);
  121. }}catch(Exception e){
  122. this.log.error(e.getMessage(), e);
  123. }
  124. // log.info("最终JSON==="+json.toString());
  125. if (json.lastIndexOf(",") > -1) {
  126. json.deleteCharAt(json.lastIndexOf(","));
  127. }
  128. String result="{\"rows\":["+json.toString()+"]}";
  129. // List<String>list=getCmpList(id, new ArrayList<String>());
  130. log.info("result===="+result);
  131. return result;
  132. }
  133. public List<String> getCmpList(String id,List<String>list) {
  134. try{
  135. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  136. list.add(id);
  137. String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
  138. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  139. log.info("getCmpList.tempList.size===="+tempList.size());
  140. for(int i=0;i<tempList.size();i++){
  141. getCmpList(tempList.get(i)[0],list);
  142. }
  143. }
  144. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  145. list.add(id);
  146. }}catch(Exception e){
  147. this.log.error(e.getMessage(), e);
  148. }
  149. return list;
  150. }
  151. public boolean checkId(String id) {
  152. try{
  153. String sql="select * from emc_am_generator_car WHERE COMP_ID IN(SELECT dept_id FROM SYS_DEPARTMENT WHERE DEPT_TYPE='1' AND PARENT_ID='"+id+"') union all "
  154. + "select * from emc_am_generator_car WHERE COMP_ID IN(SELECT dept_id FROM SYS_DEPARTMENT WHERE DEPT_TYPE='1' AND PARENT_ID in (SELECT dept_id FROM SYS_DEPARTMENT WHERE DEPT_TYPE='1' AND PARENT_ID='"+id+"')) union all "
  155. + "select * from emc_am_generator_car WHERE COMP_ID IN(SELECT dept_id FROM SYS_DEPARTMENT WHERE DEPT_TYPE='1' AND PARENT_ID in (SELECT dept_id FROM SYS_DEPARTMENT WHERE DEPT_TYPE='1' AND PARENT_ID in (SELECT dept_id FROM SYS_DEPARTMENT WHERE DEPT_TYPE='1' AND PARENT_ID='"+id+"')))";
  156. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  157. if(tempList==null||tempList.size()==0){
  158. return false;
  159. }else{
  160. return true;
  161. }}catch(Exception e){
  162. this.log.error(e.getMessage(), e);
  163. return false;
  164. }
  165. }
  166. public String levelId(String id) {
  167. try{
  168. String sql="select dept_level from SYS_DEPARTMENT WHERE dept_id = '"+id+"' ";
  169. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  170. if(tempList==null||tempList.size()==0){
  171. return "0";
  172. }else{
  173. return tempList.get(0)[0];
  174. }}catch(Exception e){
  175. this.log.error(e.getMessage(), e);
  176. return "0";
  177. }
  178. }
  179. public void getCarNum(List<String>list,String id,String content1,String content2,String valueType,String valueType2,String valueType3,String zsId) throws PersistenceException{
  180. try{
  181. String team_comp = "";
  182. for(int i=0;i<list.size();i++){
  183. CarNum cn=new CarNum();
  184. String comp_id = list.get(i);
  185. log.info(comp_id);
  186. if("3".equals(levelId(comp_id))){
  187. if(comp_id.equals(zsId)){
  188. team_comp = "select dept_id from sys_department where dept_id = '"+comp_id+"'";
  189. }else{
  190. team_comp = "select dept_id from sys_department where (dept_type='1' and (parent_id = '"+comp_id+"' or dept_id = '"+comp_id+"')) union all "
  191. + "select dept_id from sys_department where (dept_type='1' and parent_id in (select dept_id from sys_department where dept_type='1' and parent_id = '"+comp_id+"'))";
  192. }
  193. }else if("4".equals(levelId(comp_id))){
  194. if(comp_id.equals(zsId)){
  195. team_comp = "select dept_id from sys_department where dept_id = '"+comp_id+"'";
  196. }else{
  197. team_comp = "select dept_id from sys_department where dept_type='1' and (parent_id = '"+comp_id+"' or dept_id = '"+comp_id+"')";
  198. }
  199. }else if("5".equals(levelId(comp_id))){
  200. team_comp = "select dept_id from sys_department where dept_id = '"+comp_id+"'";
  201. }
  202. String sql="select is_del,sum(case when car_content<=250 then car_num else 0 end) as content_min,"
  203. + "sum(case when car_content>=251 and car_content<=500 then car_num else 0 end) as content_mid,"
  204. + "sum(case when car_content>=501 then car_num else 0 end) as content_max,"
  205. + "sum(case car_level when '139' then car_num else 0 end)as level_max,"
  206. + "sum(case car_level when '138' then car_num else 0 end)as level_min,"
  207. + "sum(case STORED_ENERGY_TYPE when '1' then car_num else 0 end)as generator,"
  208. + "sum(case STORED_ENERGY_TYPE when '2' then car_num else 0 end)as ups,"
  209. + "sum(case STORED_ENERGY_TYPE when '3' then car_num else 0 end)as fly_circle ,"
  210. + "sum(car_num)as num, sum(car_content*car_num) as sm,"
  211. + "sum(case IS_USED when '1' then car_num else 0 end)as kdy,"
  212. + "sum(case IS_USED when '2' then car_num else 0 end)as bkdy "
  213. + "from emc_am_generator_car where is_del='0' and comp_id in ("+team_comp+") ";
  214. /*//容量
  215. if(content1!=null&&!"".equals(content1)&&!"null".equals(content1)){
  216. sql+=" and CAR_CONTENT between '"+content1+"' and '"+content2+"'";
  217. }
  218. //电压等级valueType
  219. if(valueType!=null&&!"".equals(valueType)&&!"null".equals(valueType)){
  220. sql+=" and CAR_LEVEL in( "+valueType+")";
  221. }
  222. //储能方式
  223. if(valueType2!=null&&!"".equals(valueType2)&&!"null".equals(valueType2)){
  224. sql+=" and STORED_ENERGY_TYPE in ("+valueType2+") ";
  225. }*/
  226. //可否调用
  227. if(valueType3!=null&&!"".equals(valueType3)&&!"null".equals(valueType3)){
  228. sql+=" and IS_USED in( "+valueType3+" )";
  229. }
  230. //comp_id
  231. sql+=" group by is_del ";
  232. log.info("getCarNum.sql===="+sql);
  233. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  234. if(tempList.size()>0){
  235. cn.setContent_min(Integer.parseInt(tempList.get(0)[1]));
  236. cn.setContent_mid(Integer.parseInt(tempList.get(0)[2]));
  237. cn.setContent_max(Integer.parseInt(tempList.get(0)[3]));
  238. cn.setLevel_max(Integer.parseInt(tempList.get(0)[4]));
  239. cn.setLevel_min(Integer.parseInt(tempList.get(0)[5]));
  240. cn.setGenerator(Integer.parseInt(tempList.get(0)[6]));
  241. cn.setUps(Integer.parseInt(tempList.get(0)[7]));
  242. cn.setFly_circle(Integer.parseInt(tempList.get(0)[8]));
  243. cn.setNum(Integer.parseInt(tempList.get(0)[9]));
  244. cn.setSum(Double.parseDouble(tempList.get(0)[10]));
  245. cn.setKused(Integer.parseInt(tempList.get(0)[11]));
  246. cn.setBused(Integer.parseInt(tempList.get(0)[12]));
  247. numList.add(cn);
  248. if(cn.getNum()>0){
  249. if(checkId(id)){
  250. json.append("{ ");
  251. json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  252. json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  253. json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  254. json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  255. json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  256. json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  257. json.append(" \"ups\":\"" + cn.getUps() + "\",");
  258. json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  259. json.append(" \"num\":\"" + cn.getNum() + "\",");
  260. json.append(" \"sum\":\"" + cn.getSum() + "\",");
  261. json.append(" \"kused\":\"" + cn.getKused() + "\",");
  262. json.append(" \"bused\":\"" + cn.getBused() + "\",");
  263. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  264. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  265. json.append(" \"isParent\":true,");
  266. json.append(" \"open\":false");
  267. json.append("}, ");
  268. }else{
  269. json.append("{ ");
  270. json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  271. json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  272. json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  273. json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  274. json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  275. json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  276. json.append(" \"ups\":\"" + cn.getUps() + "\",");
  277. json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  278. json.append(" \"num\":\"" + cn.getNum() + "\",");
  279. json.append(" \"sum\":\"" + cn.getSum() + "\",");
  280. json.append(" \"kused\":\"" + cn.getKused() + "\",");
  281. json.append(" \"bused\":\"" + cn.getBused() + "\",");
  282. json.append(" \"name\":\"" + getNameById(list.get(i))+ "\",");
  283. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  284. json.append(" \"isParent\":false,");
  285. json.append(" \"open\":false");
  286. json.append("}, ");
  287. }
  288. }
  289. }
  290. }}catch(Exception e){
  291. this.log.error(e.getMessage(), e);
  292. }
  293. // StringBuffer json=new StringBuffer();
  294. // json.append("{ ");
  295. // json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  296. // json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  297. // json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  298. // json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  299. // json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  300. // json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  301. // json.append(" \"ups\":\"" + cn.getUps() + "\",");
  302. // json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  303. // json.append(" \"num\":\"" + cn.getNum() + "\",");
  304. // json.append(" \"name\":\"" + getNameById(id) + "\",");
  305. // json.append(" \"dept_id\":\"" + id + "\",");
  306. // json.append(" \"isParent\":true,");
  307. // json.append(" \"open\":false");
  308. // json.append("}, ");
  309. }
  310. public void getNoChildCarNum(List<String>list,String id,String content1,String content2,String valueType,String valueType2,String valueType3) throws PersistenceException{
  311. CarNum cn=new CarNum();
  312. try{
  313. for(int i=0;i<list.size();i++){
  314. String sql="select comp_id,sum(case when car_content<=250 then car_num else 0 end) as content_min,"
  315. + "sum(case when car_content>=251 and car_content<=500 then car_num else 0 end) as content_mid,"
  316. + "sum(case when car_content>=501 then car_num else 0 end) as content_max,"
  317. + "sum(case car_level when '139' then car_num else 0 end)as level_max,"
  318. + "sum(case car_level when '138' then car_num else 0 end)as level_min,"
  319. + "sum(case STORED_ENERGY_TYPE when '1' then car_num else 0 end)as generator,"
  320. + "sum(case STORED_ENERGY_TYPE when '2' then car_num else 0 end)as ups,"
  321. + "sum(case STORED_ENERGY_TYPE when '3' then car_num else 0 end)as fly_circle ,"
  322. + "sum(car_num)as num, sum(car_content*car_num) as sm,"
  323. + "sum(case IS_USED when '1' then car_num else 0 end)as kdy,"
  324. + "sum(case IS_USED when '2' then car_num else 0 end)as bkdy "
  325. + "from emc_am_generator_car where is_del='0' and comp_id='"+list.get(i)+"'";
  326. /*//容量
  327. if(content1!=null&&!"".equals(content1)&&!"null".equals(content1)){
  328. sql+=" and CAR_CONTENT between '"+content1+"' and '"+content2+"'";
  329. }
  330. //电压等级valueType
  331. if(valueType!=null&&!"".equals(valueType)&&!"null".equals(valueType)){
  332. sql+=" and CAR_LEVEL in( "+valueType+")";
  333. }
  334. //储能方式
  335. if(valueType2!=null&&!"".equals(valueType2)&&!"null".equals(valueType2)){
  336. sql+=" and STORED_ENERGY_TYPE in ("+valueType2+") ";
  337. }*/
  338. //可否调用
  339. if(valueType3!=null&&!"".equals(valueType3)&&!"null".equals(valueType3)){
  340. sql+=" and IS_USED in( "+valueType3+" )";
  341. }
  342. //comp_id
  343. sql+=" group by comp_id";
  344. log.info("getCarNum.sql===="+sql);
  345. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  346. if(numList.size()>0){
  347. cn.setContent_min(cn.getContent_min()+Integer.parseInt(numList.get(0)[1]));
  348. cn.setContent_mid(cn.getContent_mid()+Integer.parseInt(numList.get(0)[2]));
  349. cn.setContent_max(cn.getContent_max()+Integer.parseInt(numList.get(0)[3]));
  350. cn.setLevel_max(cn.getLevel_max()+Integer.parseInt(numList.get(0)[4]));
  351. cn.setLevel_min(cn.getLevel_min()+Integer.parseInt(numList.get(0)[5]));
  352. cn.setGenerator(cn.getGenerator()+Integer.parseInt(numList.get(0)[6]));
  353. cn.setUps(cn.getUps()+Integer.parseInt(numList.get(0)[7]));
  354. cn.setFly_circle(cn.getFly_circle()+Integer.parseInt(numList.get(0)[8]));
  355. cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[9]));
  356. cn.setSum(cn.getSum()+Double.parseDouble(numList.get(0)[10]));
  357. cn.setKused(cn.getKused()+Integer.parseInt(numList.get(0)[11]));
  358. cn.setBused(cn.getBused()+Integer.parseInt(numList.get(0)[12]));
  359. }
  360. }}catch(Exception e){
  361. this.log.error(e.getMessage(), e);
  362. }
  363. // StringBuffer json=new StringBuffer();
  364. if(cn.getNum()>0){
  365. json.append("{ ");
  366. json.append(" \"content_min\":\"" + cn.getContent_min() + "\",");
  367. json.append(" \"content_mid\":\"" + cn.getContent_mid() + "\",");
  368. json.append(" \"content_max\":\"" + cn.getContent_max() + "\",");
  369. json.append(" \"level_min\":\"" + cn.getLevel_min() + "\",");
  370. json.append(" \"level_max\":\"" + cn.getLevel_max() + "\",");
  371. json.append(" \"generator\":\"" + cn.getGenerator() + "\",");
  372. json.append(" \"ups\":\"" + cn.getUps() + "\",");
  373. json.append(" \"fly_circle\":\"" + cn.getFly_circle() + "\",");
  374. json.append(" \"num\":\"" + cn.getNum() + "\",");
  375. json.append(" \"sum\":\"" + cn.getSum() + "\",");
  376. json.append(" \"kused\":\"" + cn.getKused() + "\",");
  377. json.append(" \"bused\":\"" + cn.getBused() + "\",");
  378. json.append(" \"name\":\"" + getNameById(id) + "\",");
  379. json.append(" \"dept_id\":\"" + id + "\",");
  380. json.append(" \"isParent\":false,");
  381. json.append(" \"open\":true");
  382. json.append("}, ");
  383. numList.add(cn);
  384. }
  385. }
  386. public String getNameById(String id){
  387. String sql="select dept_name from sys_department where dept_id='"+id+"'";
  388. try {
  389. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  390. if(tempList==null||tempList.size()==0){
  391. return "";
  392. }else{
  393. String name=tempList.get(0)[0].replace("供电局", "");
  394. log.info("name===="+name);
  395. return name;
  396. }
  397. } catch (PersistenceException e) {
  398. // TODO Auto-generated catch block
  399. e.printStackTrace();
  400. return "";
  401. }
  402. }
  403. /**************************************调拨*************************************/
  404. /**
  405. * 调拨
  406. * @throws ClassNotFoundException
  407. */
  408. public Msg getCardiaobo(String fd_id,String number) throws ClassNotFoundException{
  409. Msg m=new Msg();
  410. String []arr=fd_id.split(",");
  411. log.info(number);
  412. String sql="";
  413. if(number.equals("1")){
  414. sql="UPDATE emc_am_generator_car SET USED_STAT='1',IS_USED='1' where fd_objectid=?";
  415. }else if(number.equals("2")){
  416. sql="UPDATE emc_am_generator_car SET USED_STAT='2',IS_USED='2' where fd_objectid=?";
  417. }else if(number.equals("3")){
  418. sql="UPDATE emc_am_generator_car SET USED_STAT='3',IS_USED='2' where fd_objectid=?";
  419. }
  420. Connection conn = null;
  421. PreparedStatement st = null;
  422. int num=0;
  423. DbConnection db = new DbConnection();
  424. try {
  425. conn = db.getConnection();
  426. conn.setAutoCommit(false);
  427. st = conn.prepareStatement(sql);
  428. for(int i=0;i<arr.length;i++){
  429. st.setString(1, arr[i]);
  430. st.executeUpdate();
  431. num++;
  432. }
  433. if(num==arr.length){
  434. log.info("发布----num===="+num);
  435. m.setSucsess(new Boolean(true).toString());
  436. m.setInfo(Parameter.OPER_SUCSESS);
  437. conn.commit();
  438. return m;
  439. }else{
  440. m.setSucsess(new Boolean(false).toString());
  441. m.setInfo(Parameter.OPER_FAILURE);
  442. conn.rollback();
  443. return m;
  444. }
  445. }catch (SQLException e) {
  446. this.log.error(e.getMessage(), e);
  447. throw new ClassNotFoundException("DAO Layou: 发布消息"
  448. + sql, e);
  449. } finally {
  450. db.close(st);
  451. db.close(conn);
  452. }
  453. }
  454. /**
  455. * 调拨 通信车
  456. * @throws ClassNotFoundException
  457. */
  458. public Msg getComdiaobo(String fd_id,String number) throws ClassNotFoundException{
  459. Msg m=new Msg();
  460. String []arr=fd_id.split(",");
  461. log.info(number);
  462. String sql="";
  463. if(number.equals("1")){
  464. sql="UPDATE EMC_AM_EMERGENCY_COMMAND_CAR SET USED_STAT='1',IS_USED='1' where fd_objectid=?";
  465. }else if(number.equals("2")){
  466. sql="UPDATE EMC_AM_EMERGENCY_COMMAND_CAR SET USED_STAT='2',IS_USED='2' where fd_objectid=?";
  467. }else if(number.equals("3")){
  468. sql="UPDATE EMC_AM_EMERGENCY_COMMAND_CAR SET USED_STAT='3',IS_USED='2' where fd_objectid=?";
  469. }
  470. Connection conn = null;
  471. PreparedStatement st = null;
  472. int num=0;
  473. DbConnection db = new DbConnection();
  474. try {
  475. conn = db.getConnection();
  476. conn.setAutoCommit(false);
  477. st = conn.prepareStatement(sql);
  478. for(int i=0;i<arr.length;i++){
  479. st.setString(1, arr[i]);
  480. st.executeUpdate();
  481. num++;
  482. }
  483. if(num==arr.length){
  484. log.info("发布----num===="+num);
  485. m.setSucsess(new Boolean(true).toString());
  486. m.setInfo(Parameter.OPER_SUCSESS);
  487. conn.commit();
  488. return m;
  489. }else{
  490. m.setSucsess(new Boolean(false).toString());
  491. m.setInfo(Parameter.OPER_FAILURE);
  492. conn.rollback();
  493. return m;
  494. }
  495. }catch (SQLException e) {
  496. this.log.error(e.getMessage(), e);
  497. throw new ClassNotFoundException("DAO Layou: 发布消息"
  498. + sql, e);
  499. } finally {
  500. db.close(st);
  501. db.close(conn);
  502. }
  503. }
  504. }