8b4e4c8d615fb7b23fad0edc5dc6b7094baa8beb.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. package com.sinosoft.am.resource.expert.dao;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.apache.log4j.Logger;
  5. import com.persistence.service.PersistenceFactory;
  6. import com.persistence.service.SysPersistence;
  7. import com.persistence.service.exception.PersistenceException;
  8. import com.sinosoft.am.resource.expert.vo.ExpertNum;
  9. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  10. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  11. public class ExpertDao {
  12. private Logger log = Logger.getLogger(this.getClass());
  13. SysModel sysmodel = ModelFactory.getSysmodel();
  14. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  15. StringBuffer json = new StringBuffer();
  16. private List<ExpertNum>numList=new ArrayList<ExpertNum>();
  17. //
  18. // var gridData={"rows":[
  19. // {"value":1,"key":"南京分公司","isParent":true,"open":false},
  20. // {"value":7,"key":"杭州办事处","isParent":true,"open":false}
  21. // ]}
  22. /**
  23. * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
  24. * @param id
  25. * @return
  26. */
  27. public String expertNumInit(String id,String isNwyj,String zhuanye,String deptId){
  28. String sql="select DEPT_ID from sys_department where (parent_id='"+id+"' or DEPT_ID='"+id+"')";
  29. try{
  30. if(deptId!=null && !"null".equals(deptId)){
  31. sql+=" and DEPT_ID in("+deptId+")";
  32. }
  33. sql+="order by sort";
  34. if(checkId(id)){
  35. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  36. log.info("carNum.tempList.size===="+tempList.size());
  37. List<String>list=new ArrayList<String>();
  38. for(int i=0;i<tempList.size();i++){
  39. list.add(tempList.get(i)[0]);
  40. }
  41. getExpertNum(list, list.get(0),isNwyj,zhuanye);
  42. }
  43. else{
  44. List<String>list=new ArrayList<String>();
  45. list.add(id);
  46. getNoChildExpertNum(list, id,isNwyj,zhuanye);
  47. }
  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. ExpertNum numBean = new ExpertNum();
  56. for(int i=0;i<numList.size();i++){
  57. numBean.setTran(numBean.getTran()+numList.get(i).getTran());
  58. numBean.setSub_one(numBean.getSub_one()+numList.get(i).getSub_one());
  59. numBean.setSub_two(numBean.getSub_two()+numList.get(i).getSub_two());
  60. numBean.setVoltage_low(numBean.getVoltage_low()+numList.get(i).getVoltage_low());
  61. numBean.setVoltage_mv(numBean.getVoltage_mv()+numList.get(i).getVoltage_mv());
  62. numBean.setSignal(numBean.getSignal()+numList.get(i).getSignal());
  63. numBean.setCivil(numBean.getCivil()+numList.get(i).getCivil());
  64. numBean.setMechanics(numBean.getMechanics()+numList.get(i).getMechanics());
  65. numBean.setHydraulic(numBean.getHydraulic()+numList.get(i).getHydraulic());
  66. numBean.setLogistics(numBean.getLogistics()+numList.get(i).getLogistics());
  67. numBean.setMedical(numBean.getMedical()+numList.get(i).getMedical());
  68. numBean.setOther(numBean.getOther()+numList.get(i).getOther());
  69. numBean.setNum(numBean.getNum()+numList.get(i).getNum());
  70. }
  71. json.append("{ ");
  72. json.append(" \"tran\":\"" + numBean.getTran() + "\",");
  73. json.append(" \"sub_one\":\"" + numBean.getSub_one() + "\",");
  74. json.append(" \"sub_two\":\"" + numBean.getSub_two() + "\",");
  75. json.append(" \"voltage_low\":\"" + numBean.getVoltage_low() + "\",");
  76. json.append(" \"voltage_mv\":\"" + numBean.getVoltage_mv() + "\",");
  77. json.append(" \"signal\":\"" + numBean.getSignal() + "\",");
  78. json.append(" \"civil\":\"" + numBean.getCivil() + "\",");
  79. json.append(" \"mechanics\":\"" + numBean.getMechanics() + "\",");
  80. json.append(" \"hydraulic\":\"" + numBean.getHydraulic() + "\",");
  81. json.append(" \"logistics\":\"" + numBean.getLogistics() + "\",");
  82. json.append(" \"medical\":\"" + numBean.getMedical() + "\",");
  83. json.append(" \"other\":\"" + numBean.getOther() + "\",");
  84. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  85. json.append(" \"name\":\"" +"总计" + "\",");
  86. json.append(" \"dept_id\":\"" + "11111" + "\",");
  87. json.append(" \"isParent\":false,");
  88. json.append(" \"open\":false");
  89. json.append("} ");
  90. String result="{\"rows\":["+json.toString()+"]}";
  91. // List<String>list=getCmpList(id, new ArrayList<String>());
  92. log.info("result===="+result);
  93. return result;
  94. }
  95. public String expertNum(String id,String isNwyj,String zhuanye){
  96. try{
  97. if(checkId(id)){
  98. String sql="select DEPT_ID from sys_department where parent_id='"+id+"' and DEPT_NAME like '%供电局%'";
  99. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  100. log.info("carNum.tempList.size===="+tempList.size());
  101. for(int i=0;i<tempList.size();i++){
  102. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  103. getExpertNum(list, tempList.get(i)[0],isNwyj,zhuanye);
  104. }
  105. }else{
  106. List<String>list=new ArrayList<String>();
  107. list.add(id);
  108. getNoChildExpertNum(list, id,isNwyj,zhuanye);
  109. }}catch(Exception e){
  110. this.log.error(e.getMessage(), e);
  111. }
  112. // log.info("最终JSON==="+json.toString());
  113. if (json.lastIndexOf(",") > -1) {
  114. json.deleteCharAt(json.lastIndexOf(","));
  115. }
  116. String result="{\"rows\":["+json.toString()+"]}";
  117. // List<String>list=getCmpList(id, new ArrayList<String>());
  118. log.info("result===="+result);
  119. return result;
  120. }
  121. public List<String> getCmpList(String id,List<String>list) {
  122. try{
  123. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  124. list.add(id);
  125. String sql="select distinct(DEPT_ID) from sys_department where parent_id='"+id+"' and DEPT_NAME like '%供电局%' ";
  126. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  127. log.info("getCmpList.tempList.size===="+tempList.size());
  128. for(int i=0;i<tempList.size();i++){
  129. getCmpList(tempList.get(i)[0],list);
  130. }
  131. }
  132. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  133. list.add(id);
  134. }}catch(Exception e){
  135. this.log.error(e.getMessage(), e);
  136. }
  137. return list;
  138. }
  139. public boolean checkId(String id) {
  140. try{
  141. String sql="select * from EMC_AM_EMERGENCY_EXPERT WHERE EXPERT_UNIT IN(SELECT DEPT_ID FROM SYS_DEPARTMENT WHERE PARENT_ID='"+id+"' and DEPT_NAME like '%供电局%' )";
  142. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  143. if(tempList==null||tempList.size()==0){
  144. return false;
  145. }else{
  146. return true;
  147. }}catch(Exception e){
  148. this.log.error(e.getMessage(), e);
  149. return false;
  150. }
  151. }
  152. public void getExpertNum(List<String>list,String id,String isNwyj,String zhuanye) throws PersistenceException{
  153. try{
  154. for(int i=0;i<list.size();i++){
  155. ExpertNum numBean = new ExpertNum();
  156. String sql = "select expert_unit,sum(case EXPERT_SPECIALTY when '1' then 1 else 0 end ) tran,sum(case EXPERT_SPECIALTY when '2' then 1 else 0 end ) sub_one,"
  157. + "sum(case EXPERT_SPECIALTY when '3' then 1 else 0 end ) sub_two,sum(case EXPERT_SPECIALTY when '5' then 1 else 0 end ) voltage_low,"
  158. + "sum(case EXPERT_SPECIALTY when '6' then 1 else 0 end ) voltage_mv,sum(case EXPERT_SPECIALTY when '4' then 1 else 0 end ) signal,"
  159. + "sum(case EXPERT_SPECIALTY when '7' then 1 else 0 end ) civil,sum(case EXPERT_SPECIALTY when '8' then 1 else 0 end ) mechanics,"
  160. + "sum(case EXPERT_SPECIALTY when '9' then 1 else 0 end ) hydraulic,sum(case EXPERT_SPECIALTY when '10' then 1 else 0 end ) logistics,"
  161. + "sum(case EXPERT_SPECIALTY when '11' then 1 else 0 end ) medical,sum(case EXPERT_SPECIALTY when '12' then 1 else 0 end ) other,"
  162. + "count(FD_OBJECTID) num from EMC_AM_EMERGENCY_EXPERT where is_del='0' and expert_unit='"+list.get(i)+"'";
  163. //是否南网员工
  164. if(isNwyj!=null && !"null".equals(isNwyj)){
  165. sql+=" and IS_SNSTAFF ="+isNwyj+"";
  166. }
  167. //专业
  168. if(zhuanye!=null && !"null".equals(zhuanye)){
  169. sql+=" and EXPERT_SPECIALTY in ("+zhuanye+")";
  170. }
  171. sql+=" group by expert_unit ";
  172. log.info("getExpertNum.sql===="+sql);
  173. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  174. if(tempList.size()>0){
  175. // numBean.setTran(numBean.getTran()+Integer.parseInt(numList.get(0)[1]));
  176. // numBean.setSub_one(numBean.getSub_one()+Integer.parseInt(numList.get(0)[2]));
  177. // numBean.setSub_two(numBean.getSub_two()+Integer.parseInt(numList.get(0)[3]));
  178. // numBean.setVoltage_low(numBean.getVoltage_low()+Integer.parseInt(numList.get(0)[4]));
  179. // numBean.setVoltage_mv(numBean.getVoltage_mv()+Integer.parseInt(numList.get(0)[5]));
  180. // numBean.setSignal(numBean.getSignal()+Integer.parseInt(numList.get(0)[6]));
  181. // numBean.setCivil(numBean.getCivil()+Integer.parseInt(numList.get(0)[7]));
  182. // numBean.setMechanics(numBean.getMechanics()+Integer.parseInt(numList.get(0)[8]));
  183. // numBean.setHydraulic(numBean.getHydraulic()+Integer.parseInt(numList.get(0)[9]));
  184. // numBean.setLogistics(numBean.getLogistics()+Integer.parseInt(numList.get(0)[10]));
  185. // numBean.setMedical(numBean.getMedical()+Integer.parseInt(numList.get(0)[11]));
  186. // numBean.setOther(numBean.getOther()+Integer.parseInt(numList.get(0)[12]));
  187. // numBean.setNum(numBean.getNum()+Integer.parseInt(numList.get(0)[13]));
  188. numBean.setTran(Integer.parseInt(tempList.get(0)[1]));
  189. numBean.setSub_one(Integer.parseInt(tempList.get(0)[2]));
  190. numBean.setSub_two(Integer.parseInt(tempList.get(0)[3]));
  191. numBean.setVoltage_low(Integer.parseInt(tempList.get(0)[4]));
  192. numBean.setVoltage_mv(Integer.parseInt(tempList.get(0)[5]));
  193. numBean.setSignal(Integer.parseInt(tempList.get(0)[6]));
  194. numBean.setCivil(Integer.parseInt(tempList.get(0)[7]));
  195. numBean.setMechanics(Integer.parseInt(tempList.get(0)[8]));
  196. numBean.setHydraulic(Integer.parseInt(tempList.get(0)[9]));
  197. numBean.setLogistics(Integer.parseInt(tempList.get(0)[10]));
  198. numBean.setMedical(Integer.parseInt(tempList.get(0)[11]));
  199. numBean.setOther(Integer.parseInt(tempList.get(0)[12]));
  200. numBean.setNum(Integer.parseInt(tempList.get(0)[13]));
  201. numList.add(numBean);
  202. if(numBean.getNum()>0){
  203. if(checkId(id)){
  204. json.append("{ ");
  205. json.append(" \"tran\":\"" + numBean.getTran() + "\",");
  206. json.append(" \"sub_one\":\"" + numBean.getSub_one() + "\",");
  207. json.append(" \"sub_two\":\"" + numBean.getSub_two() + "\",");
  208. json.append(" \"voltage_low\":\"" + numBean.getVoltage_low() + "\",");
  209. json.append(" \"voltage_mv\":\"" + numBean.getVoltage_mv() + "\",");
  210. json.append(" \"signal\":\"" + numBean.getSignal() + "\",");
  211. json.append(" \"civil\":\"" + numBean.getCivil() + "\",");
  212. json.append(" \"mechanics\":\"" + numBean.getMechanics() + "\",");
  213. json.append(" \"hydraulic\":\"" + numBean.getHydraulic() + "\",");
  214. json.append(" \"logistics\":\"" + numBean.getLogistics() + "\",");
  215. json.append(" \"medical\":\"" + numBean.getMedical() + "\",");
  216. json.append(" \"other\":\"" + numBean.getOther() + "\",");
  217. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  218. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  219. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  220. json.append(" \"isParent\":true,");
  221. json.append(" \"open\":false");
  222. json.append("}, ");
  223. }else{
  224. json.append("{ ");
  225. json.append(" \"tran\":\"" + numBean.getTran() + "\",");
  226. json.append(" \"sub_one\":\"" + numBean.getSub_one() + "\",");
  227. json.append(" \"sub_two\":\"" + numBean.getSub_two() + "\",");
  228. json.append(" \"voltage_low\":\"" + numBean.getVoltage_low() + "\",");
  229. json.append(" \"voltage_mv\":\"" + numBean.getVoltage_mv() + "\",");
  230. json.append(" \"signal\":\"" + numBean.getSignal() + "\",");
  231. json.append(" \"civil\":\"" + numBean.getCivil() + "\",");
  232. json.append(" \"mechanics\":\"" + numBean.getMechanics() + "\",");
  233. json.append(" \"hydraulic\":\"" + numBean.getHydraulic() + "\",");
  234. json.append(" \"logistics\":\"" + numBean.getLogistics() + "\",");
  235. json.append(" \"medical\":\"" + numBean.getMedical() + "\",");
  236. json.append(" \"other\":\"" + numBean.getOther() + "\",");
  237. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  238. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  239. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  240. json.append(" \"isParent\":false,");
  241. json.append(" \"open\":false");
  242. json.append("}, ");
  243. }
  244. }
  245. }}}catch(Exception e){
  246. this.log.error(e.getMessage(), e);
  247. }
  248. }
  249. public void getNoChildExpertNum(List<String>list,String id,String isNwyj,String zhuanye) throws PersistenceException{
  250. ExpertNum numBean = new ExpertNum();
  251. try{
  252. for(int i=0;i<list.size();i++){
  253. String sql = "select expert_unit,sum(case EXPERT_SPECIALTY when '1' then 1 else 0 end ) tran,sum(case EXPERT_SPECIALTY when '2' then 1 else 0 end ) sub_one,"
  254. + "sum(case EXPERT_SPECIALTY when '3' then 1 else 0 end ) sub_two,sum(case EXPERT_SPECIALTY when '5' then 1 else 0 end ) voltage_low,"
  255. + "sum(case EXPERT_SPECIALTY when '6' then 1 else 0 end ) voltage_mv,sum(case EXPERT_SPECIALTY when '4' then 1 else 0 end ) signal,"
  256. + "sum(case EXPERT_SPECIALTY when '7' then 1 else 0 end ) civil,sum(case EXPERT_SPECIALTY when '8' then 1 else 0 end ) mechanics,"
  257. + "sum(case EXPERT_SPECIALTY when '9' then 1 else 0 end ) hydraulic,sum(case EXPERT_SPECIALTY when '10' then 1 else 0 end ) logistics,"
  258. + "sum(case EXPERT_SPECIALTY when '11' then 1 else 0 end ) medical,sum(case EXPERT_SPECIALTY when '12' then 1 else 0 end ) other,"
  259. + "count(FD_OBJECTID) num from EMC_AM_EMERGENCY_EXPERT where is_del='0' and expert_unit='"+list.get(i)+"'";
  260. //是否南网员工
  261. if(isNwyj!=null && !"null".equals(isNwyj)){
  262. sql+=" and IS_SNSTAFF ="+isNwyj+"";
  263. }
  264. //专业
  265. if(zhuanye!=null && !"null".equals(zhuanye)){
  266. sql+=" and EXPERT_SPECIALTY in ("+zhuanye+")";
  267. }
  268. sql+=" group by expert_unit ";
  269. log.info("getNoChildExpertNum.sql===="+sql);
  270. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  271. if(numList.size()>0){
  272. numBean.setTran(numBean.getTran()+Integer.parseInt(numList.get(0)[1]));
  273. numBean.setSub_one(numBean.getSub_one()+Integer.parseInt(numList.get(0)[2]));
  274. numBean.setSub_two(numBean.getSub_two()+Integer.parseInt(numList.get(0)[3]));
  275. numBean.setVoltage_low(numBean.getVoltage_low()+Integer.parseInt(numList.get(0)[4]));
  276. numBean.setVoltage_mv(numBean.getVoltage_mv()+Integer.parseInt(numList.get(0)[5]));
  277. numBean.setSignal(numBean.getSignal()+Integer.parseInt(numList.get(0)[6]));
  278. numBean.setCivil(numBean.getCivil()+Integer.parseInt(numList.get(0)[7]));
  279. numBean.setMechanics(numBean.getMechanics()+Integer.parseInt(numList.get(0)[8]));
  280. numBean.setHydraulic(numBean.getHydraulic()+Integer.parseInt(numList.get(0)[9]));
  281. numBean.setLogistics(numBean.getLogistics()+Integer.parseInt(numList.get(0)[10]));
  282. numBean.setMedical(numBean.getMedical()+Integer.parseInt(numList.get(0)[11]));
  283. numBean.setOther(numBean.getOther()+Integer.parseInt(numList.get(0)[12]));
  284. numBean.setNum(numBean.getNum()+Integer.parseInt(numList.get(0)[13]));
  285. }
  286. }}catch(Exception e){
  287. this.log.error(e.getMessage(), e);
  288. }
  289. // StringBuffer json=new StringBuffer();
  290. if(numBean.getNum()>0){
  291. json.append("{ ");
  292. json.append(" \"tran\":\"" + numBean.getTran() + "\",");
  293. json.append(" \"sub_one\":\"" + numBean.getSub_one() + "\",");
  294. json.append(" \"sub_two\":\"" + numBean.getSub_two() + "\",");
  295. json.append(" \"voltage_low\":\"" + numBean.getVoltage_low() + "\",");
  296. json.append(" \"voltage_mv\":\"" + numBean.getVoltage_mv() + "\",");
  297. json.append(" \"signal\":\"" + numBean.getSignal() + "\",");
  298. json.append(" \"civil\":\"" + numBean.getCivil() + "\",");
  299. json.append(" \"mechanics\":\"" + numBean.getMechanics() + "\",");
  300. json.append(" \"hydraulic\":\"" + numBean.getHydraulic() + "\",");
  301. json.append(" \"logistics\":\"" + numBean.getLogistics() + "\",");
  302. json.append(" \"medical\":\"" + numBean.getMedical() + "\",");
  303. json.append(" \"other\":\"" + numBean.getOther() + "\",");
  304. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  305. json.append(" \"name\":\"" + getNameById(id) + "\",");
  306. json.append(" \"dept_id\":\"" + id + "\",");
  307. json.append(" \"isParent\":false,");
  308. json.append(" \"open\":true");
  309. json.append("}, ");
  310. numList.add(numBean);
  311. }
  312. }
  313. public String getNameById(String id){
  314. String sql="select DEPT_NAME from sys_department where DEPT_ID='"+id+"'";
  315. try {
  316. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  317. if(tempList==null||tempList.size()==0){
  318. return "";
  319. }else{
  320. String name=tempList.get(0)[0].replace("供电局", "").replace("电网有限责任公司", "电网");
  321. log.info("name===="+name);
  322. return name;
  323. }
  324. } catch (PersistenceException e) {
  325. // TODO Auto-generated catch block
  326. e.printStackTrace();
  327. return "";
  328. }
  329. }
  330. }