e56c9800beee60069b6fe9866036814c6ce55393.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. package com.sinosoft.am.team.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.team.vo.TeamNum;
  9. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  10. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  11. public class OutTeamDao{
  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<TeamNum>numList=new ArrayList<TeamNum>();
  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 teamNumInit(String id){
  28. try{
  29. if(checkId(id)){
  30. String sql="select id from sys_department where parent_id='"+id+"' or id='"+id+"'";
  31. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  32. log.info("carNum.tempList.size===="+tempList.size());
  33. List<String>list=new ArrayList<String>();
  34. for(int i=0;i<tempList.size();i++){
  35. list.add(tempList.get(i)[0]);
  36. }
  37. getTeamNum(list, list.get(0));
  38. }else{
  39. List<String>list=new ArrayList<String>();
  40. list.add(id);
  41. getNoChildTeamNum(list, id);
  42. }}catch(Exception e){
  43. this.log.error(e.getMessage(), e);
  44. }
  45. // log.info("最终JSON==="+json.toString());
  46. /*if (json.lastIndexOf(",") > -1) {
  47. json.deleteCharAt(json.lastIndexOf(","));
  48. }*/
  49. TeamNum numBean = new TeamNum();
  50. for(int i=0;i<numList.size();i++){
  51. numBean.setTeamCount(numBean.getTeamCount()+numList.get(i).getTeamCount());
  52. numBean.setTeamMember(numBean.getTeamMember()+numList.get(i).getTeamMember());
  53. numBean.setSdXianLu(numBean.getSdXianLu()+numList.get(i).getSdXianLu());
  54. numBean.setSdXianLang(numBean.getSdXianLang()+numList.get(i).getSdXianLang());
  55. numBean.setSdSum(numBean.getSdSum()+numList.get(i).getSdSum());
  56. numBean.setBdYiCi(numBean.getBdYiCi()+numList.get(i).getBdYiCi());
  57. numBean.setBdErCi(numBean.getBdErCi()+numList.get(i).getBdErCi());
  58. numBean.setBdSum(numBean.getBdSum()+numList.get(i).getBdSum());
  59. numBean.setPdXianLu(numBean.getPdXianLu()+numList.get(i).getPdXianLu());
  60. numBean.setPdXianLang(numBean.getPdXianLang()+numList.get(i).getPdXianLang());
  61. numBean.setPdDianFang(numBean.getPdDianFang()+numList.get(i).getPdDianFang());
  62. numBean.setPdBaoDian(numBean.getPdBaoDian()+numList.get(i).getPdBaoDian());
  63. numBean.setPdSum(numBean.getPdSum()+numList.get(i).getPdSum());
  64. numBean.setTongxing(numBean.getTongxing()+numList.get(i).getTongxing());
  65. numBean.setWangluo(numBean.getWangluo()+numList.get(i).getWangluo());
  66. numBean.setShiyan(numBean.getShiyan()+numList.get(i).getShiyan());
  67. numBean.setKused(numBean.getKused()+numList.get(i).getKused());
  68. numBean.setBused(numBean.getBused()+numList.get(i).getBused());
  69. }
  70. json.append("{ ");
  71. json.append(" \"team_count\":\"" + numBean.getTeamCount() + "\",");
  72. json.append(" \"team_member\":\"" + numBean.getTeamMember() + "\",");
  73. json.append(" \"sd_xianlu\":\"" + numBean.getSdXianLu() + "\",");
  74. json.append(" \"sd_xianlang\":\"" + numBean.getSdXianLang() + "\",");
  75. json.append(" \"sd_sum\":\"" + numBean.getSdSum() + "\",");
  76. json.append(" \"bd_yici\":\"" + numBean.getBdYiCi() + "\",");
  77. json.append(" \"bd_erci\":\"" + numBean.getBdErCi() + "\",");
  78. json.append(" \"bd_sum\":\"" + numBean.getBdSum() + "\",");
  79. json.append(" \"pd_xianlu\":\"" + numBean.getPdXianLu() + "\",");
  80. json.append(" \"pd_xianlang\":\"" + numBean.getPdXianLang() + "\",");
  81. json.append(" \"pd_dianfang\":\"" + numBean.getPdDianFang() + "\",");
  82. json.append(" \"pd_baodian\":\"" + numBean.getPdBaoDian() + "\",");
  83. json.append(" \"pd_sum\":\"" + numBean.getPdSum() + "\",");
  84. json.append(" \"tongxing\":\"" + numBean.getTongxing() + "\",");
  85. json.append(" \"wangluo\":\"" + numBean.getWangluo() + "\",");
  86. json.append(" \"shiyan\":\"" + numBean.getShiyan() + "\",");
  87. json.append(" \"kused\":\"" + numBean.getKused() + "\",");
  88. json.append(" \"bused\":\"" + numBean.getBused() + "\",");
  89. json.append(" \"name\":\"" +"总计" + "\",");
  90. json.append(" \"dept_id\":\"" + "11111" + "\",");
  91. json.append(" \"isParent\":false,");
  92. json.append(" \"open\":false");
  93. json.append("} ");
  94. String result="{\"rows\":["+json.toString()+"]}";
  95. // List<String>list=getCmpList(id, new ArrayList<String>());
  96. log.info("result===="+result);
  97. return result;
  98. }
  99. public String teamNum(String id){
  100. try{
  101. if(checkId(id)){
  102. String sql="select id from sys_department_0827 where parent_id='"+id+"'";
  103. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  104. log.info("teamNum.tempList.size===="+tempList.size());
  105. for(int i=0;i<tempList.size();i++){
  106. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  107. getTeamNum(list, tempList.get(i)[0]);
  108. }
  109. }else{
  110. List<String>list=new ArrayList<String>();
  111. list.add(id);
  112. getNoChildTeamNum(list, id);
  113. }}catch(Exception e){
  114. this.log.error(e.getMessage(), e);
  115. }
  116. // log.info("最终JSON==="+json.toString());
  117. if (json.lastIndexOf(",") > -1) {
  118. json.deleteCharAt(json.lastIndexOf(","));
  119. }
  120. String result="{\"rows\":["+json.toString()+"]}";
  121. // List<String>list=getCmpList(id, new ArrayList<String>());
  122. log.info("result===="+result);
  123. return result;
  124. }
  125. public List<String> getCmpList(String id,List<String>list) {
  126. try{
  127. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  128. list.add(id);
  129. String sql="select id from sys_department_0827 where parent_id='"+id+"'";
  130. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  131. log.info("getCmpList.tempList.size===="+tempList.size());
  132. for(int i=0;i<tempList.size();i++){
  133. getCmpList(tempList.get(i)[0],list);
  134. }
  135. }
  136. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  137. list.add(id);
  138. }}catch(Exception e){
  139. this.log.error(e.getMessage(), e);
  140. }
  141. return list;
  142. }
  143. public boolean checkId(String id) {
  144. try{
  145. String sql="select * from ECM_AM_EMERGENCY_TEAM WHERE TEAM_COMP_ID IN(SELECT ID FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"')";
  146. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  147. if(tempList==null||tempList.size()==0){
  148. return false;
  149. }else{
  150. return true;
  151. }}catch(Exception e){
  152. this.log.error(e.getMessage(), e);
  153. return false;
  154. }
  155. }
  156. public void getTeamNum(List<String>list,String id) throws PersistenceException{
  157. try{
  158. for(int i=0;i<list.size();i++){
  159. TeamNum tn = new TeamNum();
  160. String sql="select TEAM_COMP_ID,count(team_name) as team_count,sum(TEAM_MEMBER_NUMBER) as team_member, sum(SD_XIANLU) as sd_xianlu,sum(SD_XIANLANG) as sd_xianlang ,"
  161. + "sum(SD_XIANLANG+SD_XIANLU) as sd_sum, sum(BD_YICI) as bd_yici,sum(BD_ERCI) as bd_erci,sum(BD_YICI+BD_ERCI) as bd_sum,sum(PD_XIANLU) as pd_xianlu,sum(PD_XIANLANG) as pd_xianlang, "
  162. + "sum(PD_DIANFANG) as pd_dianfang,sum(PD_BAODIAN) as pd_baodian,sum(PD_BAODIAN+PD_DIANFANG+PD_XIANLU+PD_XIANLANG) as pd_sum ,sum(TONGXING) as tongxing,sum(WANGLUO) as wangluo ,"
  163. + "sum(SHIYAN) as shiyan,sum(case when TEAM_STAT='1' or TEAM_STAT='3' then 1 else 0 end)as kdy,sum(case when TEAM_STAT='2' or TEAM_STAT='4' then 1 else 0 end)as bkdy from ecm_am_emergency_team where is_del='0' and TEAM_SYSTEM='123' and TEAM_COMP_ID='"+list.get(i)+"' group by TEAM_COMP_ID";
  164. log.info("getTeamNum.sql===="+sql);
  165. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  166. if(tempList.size()>0){
  167. tn.setTeamCount(Integer.parseInt(tempList.get(0)[1]));
  168. tn.setTeamMember(Integer.parseInt(tempList.get(0)[2]));
  169. tn.setSdXianLu(Integer.parseInt(tempList.get(0)[3]));
  170. tn.setSdXianLang(Integer.parseInt(tempList.get(0)[4]));
  171. tn.setSdSum(Integer.parseInt(tempList.get(0)[5]));
  172. tn.setBdYiCi(Integer.parseInt(tempList.get(0)[6]));
  173. tn.setBdErCi(Integer.parseInt(tempList.get(0)[7]));
  174. tn.setBdSum(Integer.parseInt(tempList.get(0)[8]));
  175. tn.setPdXianLu(Integer.parseInt(tempList.get(0)[9]));
  176. tn.setPdXianLang(Integer.parseInt(tempList.get(0)[10]));
  177. tn.setPdDianFang(Integer.parseInt(tempList.get(0)[11]));
  178. tn.setPdBaoDian(Integer.parseInt(tempList.get(0)[12]));
  179. tn.setPdSum(Integer.parseInt(tempList.get(0)[13]));
  180. tn.setTongxing(Integer.parseInt(tempList.get(0)[14]));
  181. tn.setWangluo(Integer.parseInt(tempList.get(0)[15]));
  182. tn.setShiyan(Integer.parseInt(tempList.get(0)[16]));
  183. tn.setKused(Integer.parseInt(tempList.get(0)[17]));
  184. tn.setBused(Integer.parseInt(tempList.get(0)[18]));
  185. numList.add(tn);
  186. if(tn.getTeamCount()>0){
  187. if(checkId(id)){
  188. json.append("{ ");
  189. json.append(" \"team_count\":\"" + tn.getTeamCount() + "\",");
  190. json.append(" \"team_member\":\"" + tn.getTeamMember() + "\",");
  191. json.append(" \"sd_xianlu\":\"" + tn.getSdXianLu() + "\",");
  192. json.append(" \"sd_xianlang\":\"" + tn.getSdXianLang() + "\",");
  193. json.append(" \"sd_sum\":\"" + tn.getSdSum() + "\",");
  194. json.append(" \"bd_yici\":\"" + tn.getBdYiCi() + "\",");
  195. json.append(" \"bd_erci\":\"" + tn.getBdErCi() + "\",");
  196. json.append(" \"bd_sum\":\"" + tn.getBdSum() + "\",");
  197. json.append(" \"pd_xianlu\":\"" + tn.getPdXianLu() + "\",");
  198. json.append(" \"pd_xianlang\":\"" + tn.getPdXianLang() + "\",");
  199. json.append(" \"pd_dianfang\":\"" + tn.getPdDianFang() + "\",");
  200. json.append(" \"pd_baodian\":\"" + tn.getPdBaoDian() + "\",");
  201. json.append(" \"pd_sum\":\"" + tn.getPdSum() + "\",");
  202. json.append(" \"tongxing\":\"" + tn.getTongxing() + "\",");
  203. json.append(" \"wangluo\":\"" + tn.getWangluo() + "\",");
  204. json.append(" \"shiyan\":\"" + tn.getShiyan() + "\",");
  205. json.append(" \"kused\":\"" + tn.getKused() + "\",");
  206. json.append(" \"bused\":\"" + tn.getBused() + "\",");
  207. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  208. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  209. json.append(" \"isParent\":true,");
  210. json.append(" \"open\":false");
  211. json.append("}, ");
  212. }else{
  213. json.append("{ ");
  214. json.append(" \"team_count\":\"" + tn.getTeamCount() + "\",");
  215. json.append(" \"team_member\":\"" + tn.getTeamMember() + "\",");
  216. json.append(" \"sd_xianlu\":\"" + tn.getSdXianLu() + "\",");
  217. json.append(" \"sd_xianlang\":\"" + tn.getSdXianLang() + "\",");
  218. json.append(" \"sd_sum\":\"" + tn.getSdSum() + "\",");
  219. json.append(" \"bd_yici\":\"" + tn.getBdYiCi() + "\",");
  220. json.append(" \"bd_erci\":\"" + tn.getBdErCi() + "\",");
  221. json.append(" \"bd_sum\":\"" + tn.getBdSum() + "\",");
  222. json.append(" \"pd_xianlu\":\"" + tn.getPdXianLu() + "\",");
  223. json.append(" \"pd_xianlang\":\"" + tn.getPdXianLang() + "\",");
  224. json.append(" \"pd_dianfang\":\"" + tn.getPdDianFang() + "\",");
  225. json.append(" \"pd_baodian\":\"" + tn.getPdBaoDian() + "\",");
  226. json.append(" \"pd_sum\":\"" + tn.getPdSum() + "\",");
  227. json.append(" \"tongxing\":\"" + tn.getTongxing() + "\",");
  228. json.append(" \"wangluo\":\"" + tn.getWangluo() + "\",");
  229. json.append(" \"shiyan\":\"" + tn.getShiyan() + "\",");
  230. json.append(" \"kused\":\"" + tn.getKused() + "\",");
  231. json.append(" \"bused\":\"" + tn.getBused() + "\",");
  232. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  233. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  234. json.append(" \"isParent\":false,");
  235. json.append(" \"open\":false");
  236. json.append("}, ");
  237. }
  238. }
  239. }
  240. }}catch(Exception e){
  241. this.log.error(e.getMessage(), e);
  242. }
  243. }
  244. public void getNoChildTeamNum(List<String>list,String id) throws PersistenceException{
  245. TeamNum tn = new TeamNum();
  246. try{
  247. for(int i=0;i<list.size();i++){
  248. String sql="select TEAM_COMP_ID,count(team_name) as team_count,sum(TEAM_MEMBER_NUMBER) as team_member, sum(SD_XIANLU) as sd_xianlu,sum(SD_XIANLANG) as sd_xianlang ,"
  249. + "sum(SD_XIANLANG+SD_XIANLU) as sd_sum, sum(BD_YICI) as bd_yici,sum(BD_ERCI) as bd_erci,sum(BD_YICI+BD_ERCI) as bd_sum,sum(PD_XIANLU) as pd_xianlu,sum(PD_XIANLANG) as pd_xianlang, "
  250. + "sum(PD_DIANFANG) as pd_dianfang,sum(PD_BAODIAN) as pd_baodian,sum(PD_BAODIAN+PD_DIANFANG+PD_XIANLU+PD_XIANLANG) as pd_sum ,sum(TONGXING) as tongxing,sum(WANGLUO) as wangluo ,"
  251. + "sum(SHIYAN) as shiyan,sum(case when TEAM_STAT='1' or TEAM_STAT='3' then 1 else 0 end)as kdy,sum(case when TEAM_STAT='2' or TEAM_STAT='4' then 1 else 0 end)as bkdy from ecm_am_emergency_team where is_del='0' and TEAM_SYSTEM='123' and TEAM_COMP_ID='"+list.get(i)+"' group by TEAM_COMP_ID";
  252. log.info("getNoChildTeamNum.sql===="+sql);
  253. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  254. if(numList.size()>0){
  255. tn.setTeamCount(tn.getTeamCount()+Integer.parseInt(numList.get(0)[1]));
  256. tn.setTeamMember(tn.getTeamMember()+Integer.parseInt(numList.get(0)[2]));
  257. tn.setSdXianLu(tn.getSdXianLu()+Integer.parseInt(numList.get(0)[3]));
  258. tn.setSdXianLang(tn.getSdXianLang()+Integer.parseInt(numList.get(0)[4]));
  259. tn.setSdSum(tn.getSdSum()+Integer.parseInt(numList.get(0)[5]));
  260. tn.setBdYiCi(tn.getBdYiCi()+Integer.parseInt(numList.get(0)[6]));
  261. tn.setBdErCi(tn.getBdErCi()+Integer.parseInt(numList.get(0)[7]));
  262. tn.setBdSum(tn.getBdSum()+Integer.parseInt(numList.get(0)[8]));
  263. tn.setPdXianLu(tn.getPdXianLu()+Integer.parseInt(numList.get(0)[9]));
  264. tn.setPdXianLang(tn.getPdXianLang()+Integer.parseInt(numList.get(0)[10]));
  265. tn.setPdDianFang(tn.getPdDianFang()+Integer.parseInt(numList.get(0)[11]));
  266. tn.setPdBaoDian(tn.getPdBaoDian()+Integer.parseInt(numList.get(0)[12]));
  267. tn.setPdSum(tn.getPdSum()+Integer.parseInt(numList.get(0)[13]));
  268. tn.setTongxing(tn.getTongxing()+Integer.parseInt(numList.get(0)[14]));
  269. tn.setWangluo(tn.getWangluo()+Integer.parseInt(numList.get(0)[15]));
  270. tn.setShiyan(tn.getShiyan()+Integer.parseInt(numList.get(0)[16]));
  271. tn.setKused(tn.getKused()+Integer.parseInt(numList.get(0)[17]));
  272. tn.setBused(tn.getBused()+Integer.parseInt(numList.get(0)[18]));
  273. }
  274. }}catch(Exception e){
  275. this.log.error(e.getMessage(), e);
  276. }
  277. // StringBuffer json=new StringBuffer();
  278. if(tn.getTeamCount()>0){
  279. json.append("{ ");
  280. json.append(" \"team_count\":\"" + tn.getTeamCount() + "\",");
  281. json.append(" \"team_member\":\"" + tn.getTeamMember() + "\",");
  282. json.append(" \"sd_xianlu\":\"" + tn.getSdXianLu() + "\",");
  283. json.append(" \"sd_xianlang\":\"" + tn.getSdXianLang() + "\",");
  284. json.append(" \"sd_sum\":\"" + tn.getSdSum() + "\",");
  285. json.append(" \"bd_yici\":\"" + tn.getBdYiCi() + "\",");
  286. json.append(" \"bd_erci\":\"" + tn.getBdErCi() + "\",");
  287. json.append(" \"bd_sum\":\"" + tn.getBdSum() + "\",");
  288. json.append(" \"pd_xianlu\":\"" + tn.getPdXianLu() + "\",");
  289. json.append(" \"pd_xianlang\":\"" + tn.getPdXianLang() + "\",");
  290. json.append(" \"pd_dianfang\":\"" + tn.getPdDianFang() + "\",");
  291. json.append(" \"pd_baodian\":\"" + tn.getPdBaoDian() + "\",");
  292. json.append(" \"pd_sum\":\"" + tn.getPdSum() + "\",");
  293. json.append(" \"tongxing\":\"" + tn.getTongxing() + "\",");
  294. json.append(" \"wangluo\":\"" + tn.getWangluo() + "\",");
  295. json.append(" \"shiyan\":\"" + tn.getShiyan() + "\",");
  296. json.append(" \"kused\":\"" + tn.getKused() + "\",");
  297. json.append(" \"bused\":\"" + tn.getBused() + "\",");
  298. json.append(" \"name\":\"" + getNameById(id) + "\",");
  299. json.append(" \"dept_id\":\"" + id + "\",");
  300. json.append(" \"isParent\":false,");
  301. json.append(" \"open\":true");
  302. json.append("}, ");
  303. numList.add(tn);
  304. }
  305. }
  306. public String getNameById(String id){
  307. String sql="select name from sys_department_0827 where id='"+id+"'";
  308. try {
  309. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  310. if(tempList==null||tempList.size()==0){
  311. return "";
  312. }else{
  313. String name=tempList.get(0)[0];
  314. log.info("name===="+name);
  315. return name;
  316. }
  317. } catch (PersistenceException e) {
  318. // TODO Auto-generated catch block
  319. e.printStackTrace();
  320. return "";
  321. }
  322. }
  323. }