8fbf83bc0744d57f1d4ec0b744765e57810c618f.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. package com.sinosoft.am.resource.resources.external.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.resources.external.vo.ExternalNum;
  9. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  10. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  11. public class ExternalDao {
  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<ExternalNum>numList=new ArrayList<ExternalNum>();
  17. /**
  18. * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
  19. * @param id
  20. * @return
  21. */
  22. public String externalNumInit(String id,String typevalue,String deptId){
  23. String sql="select DEPT_ID from sys_department where (parent_id='"+id+"' or DEPT_ID='"+id+"')";
  24. try{
  25. if(deptId!=null && !"null".equals(deptId)){
  26. sql+=" and DEPT_ID in("+deptId+") ";
  27. }
  28. if(checkId(id)){
  29. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  30. log.info("Num.tempList.size===="+tempList.size());
  31. List<String>list=new ArrayList<String>();
  32. for(int i=0;i<tempList.size();i++){
  33. list.add(tempList.get(i)[0]);
  34. }
  35. getExternalNum(list, list.get(0),typevalue);
  36. }else{
  37. List<String>list=new ArrayList<String>();
  38. list.add(id);
  39. getNoChildExternalNum(list, id,typevalue);
  40. }}catch(Exception e){
  41. this.log.error(e.getMessage(), e);
  42. }
  43. // log.info("最终JSON==="+json.toString()); 统计栏
  44. /*if (json.lastIndexOf(",") > -1) {
  45. json.deleteCharAt(json.lastIndexOf(","));
  46. }*/
  47. ExternalNum numBean=new ExternalNum();
  48. for(int i=0;i<numList.size();i++){
  49. numBean.setGRFHZB(numBean.getGRFHZB()+numList.get(i).getGRFHZB());
  50. numBean.setSMJZZB(numBean.getSMJZZB()+numList.get(i).getSMJZZB());
  51. numBean.setLSSSZB(numBean.getLSSSZB()+numList.get(i).getLSSSZB());
  52. numBean.setFDZB(numBean.getFDZB()+numList.get(i).getFDZB());
  53. numBean.setZMZB(numBean.getZMZB()+numList.get(i).getZMZB());
  54. numBean.setTXZB(numBean.getTXZB()+numList.get(i).getTXZB());
  55. numBean.setJTYSZB(numBean.getJTYSZB()+numList.get(i).getJTYSZB());
  56. numBean.setGCZB(numBean.getGCZB()+numList.get(i).getGCZB());
  57. numBean.setWRQLZB(numBean.getWRQLZB()+numList.get(i).getWRQLZB());
  58. numBean.setGCCL(numBean.getGCCL()+numList.get(i).getGCCL());
  59. numBean.setDIAOCHE(numBean.getDIAOCHE()+numList.get(i).getDIAOCHE());
  60. numBean.setCHACHE(numBean.getCHACHE()+numList.get(i).getCHACHE());
  61. numBean.setWJJ(numBean.getWJJ()+numList.get(i).getWJJ());
  62. numBean.setHUOCHE(numBean.getHUOCHE()+numList.get(i).getHUOCHE());
  63. numBean.setTTJ(numBean.getTTJ()+numList.get(i).getTTJ());
  64. numBean.setNum(numBean.getNum()+numList.get(i).getNum());
  65. }
  66. json.append("{ ");
  67. json.append(" \"GRFHZB\":\"" + numBean.getGRFHZB() + "\",");
  68. json.append(" \"SMJZZB\":\"" + numBean.getSMJZZB() + "\",");
  69. json.append(" \"LSSSZB\":\"" + numBean.getLSSSZB() + "\",");
  70. json.append(" \"FDZB\":\"" + numBean.getFDZB() + "\",");
  71. json.append(" \"ZMZB\":\"" + numBean.getZMZB() + "\",");
  72. json.append(" \"TXZB\":\"" + numBean.getTXZB() + "\",");
  73. json.append(" \"JTYSZB\":\"" + numBean.getJTYSZB() + "\",");
  74. json.append(" \"GCZB\":\"" + numBean.getGCZB() + "\",");
  75. json.append(" \"WRQLZB\":\"" + numBean.getWRQLZB() + "\",");
  76. json.append(" \"GCCL\":\"" + numBean.getGCCL() + "\",");
  77. json.append(" \"DIAOCHE\":\"" + numBean.getDIAOCHE() + "\",");
  78. json.append(" \"CHACHE\":\"" + numBean.getCHACHE() + "\",");
  79. json.append(" \"WJJ\":\"" + numBean.getWJJ() + "\",");
  80. json.append(" \"HUOCHE\":\"" + numBean.getHUOCHE() + "\",");
  81. json.append(" \"TTJ\":\"" + numBean.getTTJ() + "\",");
  82. json.append(" \"NUM\":\"" + numBean.getNum() + "\",");
  83. json.append(" \"name\":\"" +"总计" + "\",");
  84. json.append(" \"dept_id\":\"" + "11111" + "\",");
  85. json.append(" \"isParent\":false,");
  86. json.append(" \"open\":false");
  87. json.append("} ");
  88. String result="{\"rows\":["+json.toString()+"]}";
  89. // List<String>list=getCmpList(id, new ArrayList<String>());
  90. log.info("result===="+result);
  91. return result;
  92. }
  93. public String externalNum(String id,String typevalue){
  94. try{
  95. if(checkId(id)){
  96. String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
  97. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  98. log.info("externalNum.tempList.size===="+tempList.size());
  99. for(int i=0;i<tempList.size();i++){
  100. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  101. getExternalNum(list, tempList.get(i)[0],typevalue);
  102. }
  103. }else{
  104. List<String>list=new ArrayList<String>();
  105. list.add(id);
  106. getNoChildExternalNum(list, id,typevalue);
  107. }}catch(Exception e){
  108. this.log.error(e.getMessage(), e);
  109. }
  110. // log.info("最终JSON==="+json.toString());
  111. if (json.lastIndexOf(",") > -1) {
  112. json.deleteCharAt(json.lastIndexOf(","));
  113. }
  114. String result="{\"rows\":["+json.toString()+"]}";
  115. // List<String>list=getCmpList(id, new ArrayList<String>());
  116. log.info("result===="+result);
  117. return result;
  118. }
  119. public List<String> getCmpList(String id,List<String>list) {
  120. try{
  121. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  122. list.add(id);
  123. String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
  124. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  125. log.info("getCmpList.tempList.size===="+tempList.size());
  126. for(int i=0;i<tempList.size();i++){
  127. getCmpList(tempList.get(i)[0],list);
  128. }
  129. }
  130. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  131. list.add(id);
  132. }}catch(Exception e){
  133. this.log.error(e.getMessage(), e);
  134. }
  135. return list;
  136. }
  137. public boolean checkId(String id) {
  138. try{
  139. String sql="select * from EMC_AM_EXTEMAL_RESOURCES WHERE SUB_UNIT IN(SELECT DEPT_ID FROM SYS_DEPARTMENT WHERE PARENT_ID='"+id+"')";
  140. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  141. if(tempList==null||tempList.size()==0){
  142. return false;
  143. }else{
  144. return true;
  145. }}catch(Exception e){
  146. this.log.error(e.getMessage(), e);
  147. return false;
  148. }
  149. }
  150. public void getExternalNum(List<String>list,String id ,String typevalue) throws PersistenceException{
  151. try{
  152. for(int i=0;i<list.size();i++){
  153. ExternalNum cn=new ExternalNum();
  154. String sql ="select sub_unit , sum(case resource_type when '1' then num else 0 end) as GRFHZB, sum(case resource_type when '2' then num else 0 end) as SMJZZB,"
  155. + "sum(case resource_type when '3' then num else 0 end) as LSSSZB,sum(case resource_type when '4' then num else 0 end) as FDZB,"
  156. + "sum(case resource_type when '5' then num else 0 end) as ZMZB,sum(case resource_type when '6' then num else 0 end) as TXZB,"
  157. + "sum(case resource_type when '7' then num else 0 end) as JTYSZB,sum(case resource_type when '8' then num else 0 end) as GCZB,"
  158. + "sum(case resource_type when '9' then num else 0 end) as WRQLZB,sum(case resource_type when '10' then num else 0 end) as GCCL,"
  159. + "sum(case resource_type when '11' then num else 0 end) as DIAOCHE,sum(case resource_type when '12' then num else 0 end) as CHACHE,"
  160. + "sum(case resource_type when '13' then num else 0 end) as WJJ,sum(case resource_type when '14' then num else 0 end) as HUOCHE,sum(case resource_type when '15' then num else 0 end) as TTJ,"
  161. + "sum(num) as num from EMC_AM_EXTEMAL_RESOURCES where is_del='0' and sub_unit='"+list.get(i)+"'";
  162. //专业
  163. if(typevalue!=null&&!"null".equals(typevalue)&&!"".equals(typevalue)){
  164. sql+=" and resource_type in ("+typevalue+")";
  165. }
  166. sql+=" group by sub_unit ";
  167. log.info("getExternalNum.sql===="+sql);
  168. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  169. if(tempList.size()>0){
  170. cn.setGRFHZB(Integer.parseInt(tempList.get(0)[1]));
  171. cn.setSMJZZB(Integer.parseInt(tempList.get(0)[2]));
  172. cn.setLSSSZB(Integer.parseInt(tempList.get(0)[3]));
  173. cn.setFDZB(Integer.parseInt(tempList.get(0)[4]));
  174. cn.setZMZB(Integer.parseInt(tempList.get(0)[5]));
  175. cn.setTXZB(Integer.parseInt(tempList.get(0)[6]));
  176. cn.setJTYSZB(Integer.parseInt(tempList.get(0)[7]));
  177. cn.setGCZB(Integer.parseInt(tempList.get(0)[8]));
  178. cn.setWRQLZB(Integer.parseInt(tempList.get(0)[9]));
  179. cn.setGCCL(Integer.parseInt(tempList.get(0)[10]));
  180. cn.setDIAOCHE(Integer.parseInt(tempList.get(0)[11]));
  181. cn.setCHACHE(Integer.parseInt(tempList.get(0)[12]));
  182. cn.setWJJ(Integer.parseInt(tempList.get(0)[13]));
  183. cn.setHUOCHE(Integer.parseInt(tempList.get(0)[14]));
  184. cn.setTTJ(Integer.parseInt(tempList.get(0)[15]));
  185. cn.setNum(Integer.parseInt(tempList.get(0)[16]));
  186. numList.add(cn);
  187. if(cn.getNum()>0){
  188. if(checkId(id)){
  189. json.append("{ ");
  190. json.append(" \"GRFHZB\":\"" + cn.getGRFHZB() + "\",");
  191. json.append(" \"SMJZZB\":\"" + cn.getSMJZZB() + "\",");
  192. json.append(" \"LSSSZB\":\"" + cn.getLSSSZB() + "\",");
  193. json.append(" \"FDZB\":\"" + cn.getFDZB() + "\",");
  194. json.append(" \"ZMZB\":\"" + cn.getZMZB() + "\",");
  195. json.append(" \"TXZB\":\"" + cn.getTXZB() + "\",");
  196. json.append(" \"JTYSZB\":\"" + cn.getJTYSZB() + "\",");
  197. json.append(" \"GCZB\":\"" + cn.getGCZB() + "\",");
  198. json.append(" \"WRQLZB\":\"" + cn.getWRQLZB() + "\",");
  199. json.append(" \"GCCL\":\"" + cn.getGCCL() + "\",");
  200. json.append(" \"DIAOCHE\":\"" + cn.getDIAOCHE() + "\",");
  201. json.append(" \"CHACHE\":\"" + cn.getCHACHE() + "\",");
  202. json.append(" \"WJJ\":\"" + cn.getWJJ() + "\",");
  203. json.append(" \"HUOCHE\":\"" + cn.getHUOCHE() + "\",");
  204. json.append(" \"TTJ\":\"" + cn.getTTJ() + "\",");
  205. json.append(" \"NUM\":\"" + cn.getNum() + "\",");
  206. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  207. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  208. json.append(" \"isParent\":true,");
  209. json.append(" \"open\":false");
  210. json.append("}, ");
  211. }else{
  212. json.append("{ ");
  213. json.append(" \"GRFHZB\":\"" + cn.getGRFHZB() + "\",");
  214. json.append(" \"SMJZZB\":\"" + cn.getSMJZZB() + "\",");
  215. json.append(" \"LSSSZB\":\"" + cn.getLSSSZB() + "\",");
  216. json.append(" \"FDZB\":\"" + cn.getFDZB() + "\",");
  217. json.append(" \"ZMZB\":\"" + cn.getZMZB() + "\",");
  218. json.append(" \"TXZB\":\"" + cn.getTXZB() + "\",");
  219. json.append(" \"JTYSZB\":\"" + cn.getJTYSZB() + "\",");
  220. json.append(" \"GCZB\":\"" + cn.getGCZB() + "\",");
  221. json.append(" \"WRQLZB\":\"" + cn.getWRQLZB() + "\",");
  222. json.append(" \"GCCL\":\"" + cn.getGCCL() + "\",");
  223. json.append(" \"DIAOCHE\":\"" + cn.getDIAOCHE() + "\",");
  224. json.append(" \"CHACHE\":\"" + cn.getCHACHE() + "\",");
  225. json.append(" \"WJJ\":\"" + cn.getWJJ() + "\",");
  226. json.append(" \"HUOCHE\":\"" + cn.getHUOCHE() + "\",");
  227. json.append(" \"TTJ\":\"" + cn.getTTJ() + "\",");
  228. json.append(" \"NUM\":\"" + cn.getNum() + "\",");
  229. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  230. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  231. json.append(" \"isParent\":false,");
  232. json.append(" \"open\":false");
  233. json.append("}, ");
  234. }
  235. }
  236. }
  237. }}catch(Exception e){
  238. this.log.error(e.getMessage(), e);
  239. }
  240. }
  241. public void getNoChildExternalNum(List<String>list,String id,String typevalue) throws PersistenceException{
  242. ExternalNum cn=new ExternalNum();
  243. try{
  244. for(int i=0;i<list.size();i++){
  245. String sql ="select sub_unit , sum(case resource_type when '1' then num else 0 end) as GRFHZB, sum(case resource_type when '2' then num else 0 end) as SMJZZB,"
  246. + "sum(case resource_type when '3' then num else 0 end) as LSSSZB,sum(case resource_type when '4' then num else 0 end) as FDZB,"
  247. + "sum(case resource_type when '5' then num else 0 end) as ZMZB,sum(case resource_type when '6' then num else 0 end) as TXZB,"
  248. + "sum(case resource_type when '7' then num else 0 end) as JTYSZB,sum(case resource_type when '8' then num else 0 end) as GCZB,"
  249. + "sum(case resource_type when '9' then num else 0 end) as WRQLZB,sum(case resource_type when '10' then num else 0 end) as GCCL,"
  250. + "sum(case resource_type when '11' then num else 0 end) as DIAOCHE,sum(case resource_type when '12' then num else 0 end) as CHACHE,"
  251. + "sum(case resource_type when '13' then num else 0 end) as WJJ,sum(case resource_type when '14' then num else 0 end) as HUOCHE,sum(case resource_type when '15' then num else 0 end) as TTJ,"
  252. + "sum(num) as num from EMC_AM_EXTEMAL_RESOURCES where is_del='0' and sub_unit='"+list.get(i)+"'";
  253. //专业
  254. if(typevalue!=null && !"null".equals(typevalue)&&!"".equals(typevalue)){
  255. sql+=" and resource_type in ("+typevalue+")";
  256. }
  257. sql+=" group by sub_unit ";
  258. log.info("getNoChildExternalNum.sql===="+sql);
  259. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  260. if(numList.size()>0){
  261. cn.setGRFHZB(cn.getGRFHZB()+Integer.parseInt(numList.get(0)[1]));
  262. cn.setSMJZZB(cn.getSMJZZB()+Integer.parseInt(numList.get(0)[2]));
  263. cn.setLSSSZB(cn.getLSSSZB()+Integer.parseInt(numList.get(0)[3]));
  264. cn.setFDZB(cn.getFDZB()+Integer.parseInt(numList.get(0)[4]));
  265. cn.setZMZB(cn.getZMZB()+Integer.parseInt(numList.get(0)[5]));
  266. cn.setTXZB(cn.getTXZB()+Integer.parseInt(numList.get(0)[6]));
  267. cn.setJTYSZB(cn.getJTYSZB()+Integer.parseInt(numList.get(0)[7]));
  268. cn.setGCZB(cn.getGCZB()+Integer.parseInt(numList.get(0)[8]));
  269. cn.setWRQLZB(cn.getWRQLZB()+Integer.parseInt(numList.get(0)[9]));
  270. cn.setGCCL(cn.getGCCL()+Integer.parseInt(numList.get(0)[10]));
  271. cn.setDIAOCHE(cn.getDIAOCHE()+Integer.parseInt(numList.get(0)[11]));
  272. cn.setCHACHE(cn.getCHACHE()+Integer.parseInt(numList.get(0)[12]));
  273. cn.setWJJ(cn.getWJJ()+Integer.parseInt(numList.get(0)[13]));
  274. cn.setHUOCHE(cn.getHUOCHE()+Integer.parseInt(numList.get(0)[14]));
  275. cn.setTTJ(cn.getTTJ()+Integer.parseInt(numList.get(0)[15]));
  276. cn.setNum(cn.getNum()+Integer.parseInt(numList.get(0)[16]));
  277. }
  278. }}catch(Exception e){
  279. this.log.error(e.getMessage(), e);
  280. }
  281. if(cn.getNum()>0){
  282. json.append("{ ");
  283. json.append(" \"GRFHZB\":\"" + cn.getGRFHZB() + "\",");
  284. json.append(" \"SMJZZB\":\"" + cn.getSMJZZB() + "\",");
  285. json.append(" \"LSSSZB\":\"" + cn.getLSSSZB() + "\",");
  286. json.append(" \"FDZB\":\"" + cn.getFDZB() + "\",");
  287. json.append(" \"ZMZB\":\"" + cn.getZMZB() + "\",");
  288. json.append(" \"TXZB\":\"" + cn.getTXZB() + "\",");
  289. json.append(" \"JTYSZB\":\"" + cn.getJTYSZB() + "\",");
  290. json.append(" \"GCZB\":\"" + cn.getGCZB() + "\",");
  291. json.append(" \"WRQLZB\":\"" + cn.getWRQLZB() + "\",");
  292. json.append(" \"GCCL\":\"" + cn.getGCCL() + "\",");
  293. json.append(" \"DIAOCHE\":\"" + cn.getDIAOCHE() + "\",");
  294. json.append(" \"CHACHE\":\"" + cn.getCHACHE() + "\",");
  295. json.append(" \"WJJ\":\"" + cn.getWJJ() + "\",");
  296. json.append(" \"HUOCHE\":\"" + cn.getHUOCHE() + "\",");
  297. json.append(" \"TTJ\":\"" + cn.getTTJ() + "\",");
  298. json.append(" \"NUM\":\"" + cn.getNum() + "\",");
  299. json.append(" \"name\":\"" + getNameById(id) + "\",");
  300. json.append(" \"dept_id\":\"" + id + "\",");
  301. json.append(" \"isParent\":false,");
  302. json.append(" \"open\":true");
  303. json.append("}, ");
  304. numList.add(cn);
  305. }
  306. }
  307. public String getNameById(String id){
  308. String sql="select DEPT_NAME from sys_department where DEPT_ID='"+id+"'";
  309. try {
  310. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  311. if(tempList==null||tempList.size()==0){
  312. return "";
  313. }else{
  314. String name=tempList.get(0)[0].replace("供电局", "").replace("电网有限责任公司", "电网");
  315. log.info("name===="+name);
  316. return name;
  317. }
  318. } catch (PersistenceException e) {
  319. // TODO Auto-generated catch block
  320. e.printStackTrace();
  321. return "";
  322. }
  323. }
  324. }