2c68b042d26d4f18dcc6eafa294fb4dcd4ddf105.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. package com.sinosoft.am.filemanger.document.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.filemanger.document.vo.DocBean;
  15. import com.sinosoft.am.filemanger.document.vo.govDoc;
  16. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  17. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  18. public class govDocDao{
  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<govDoc>numList = new ArrayList<govDoc>();
  24. /**
  25. * 根据传过来的ID进行检测,有子节点且子节点在明细表中有数据的,继续查询该节点下面的数据
  26. * @param id
  27. * @return
  28. */
  29. public String NumInit(String id,String startTime,String endTime,String tempLevel,String deptId,String valueType1){
  30. String sql="select DEPT_ID from sys_department where (parent_id='"+id+"' or DEPT_ID='"+id+"')";
  31. try{
  32. if(deptId != null && !"null".equals(deptId) &&!"".equals(deptId)){
  33. sql+=" and DEPT_ID in("+deptId+") ";
  34. }
  35. if(checkId(id)){
  36. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  37. log.info("carNum.tempList.size===="+tempList.size());
  38. List<String>list=new ArrayList<String>();
  39. for(int i=0;i<tempList.size();i++){
  40. list.add(tempList.get(i)[0]);
  41. }
  42. getFileNum(list, list.get(0),startTime,endTime,tempLevel,valueType1);
  43. }else{
  44. List<String>list=new ArrayList<String>();
  45. list.add(id);
  46. getNoChildFileNum(list, id,startTime,endTime,tempLevel,valueType1);
  47. }}catch(Exception e){
  48. this.log.error(e.getMessage(), e);
  49. }
  50. // log.info("最终JSON==="+json.toString());
  51. /*if (json.lastIndexOf(",") > -1) {
  52. json.deleteCharAt(json.lastIndexOf(","));
  53. }
  54. */
  55. govDoc numBean = new govDoc();
  56. for(int i=0;i<numList.size();i++){
  57. // numBean.setGovDoc(numBean.getGovDoc()+numList.get(i).getGovDoc());
  58. numBean.setLevel1(numBean.getLevel1()+numList.get(i).getLevel1());
  59. numBean.setLevel2(numBean.getLevel2()+numList.get(i).getLevel2());
  60. numBean.setLevel3(numBean.getLevel3()+numList.get(i).getLevel3());
  61. numBean.setLevel4(numBean.getLevel4()+numList.get(i).getLevel4());
  62. // numBean.setEnpDoc(numBean.getEnpDoc()+numList.get(i).getEnpDoc());
  63. // numBean.setEnpSys(numBean.getEnpSys()+numList.get(i).getEnpSys());
  64. // numBean.setEnpArd(numBean.getEnpArd()+numList.get(i).getEnpArd());
  65. numBean.setNum(numBean.getNum()+numList.get(i).getNum());
  66. }
  67. json.append("{ ");
  68. json.append(" \"level1\":\"" + numBean.getLevel1() + "\",");
  69. json.append(" \"level2\":\"" + numBean.getLevel2() + "\",");
  70. json.append(" \"level3\":\"" + numBean.getLevel3() + "\",");
  71. json.append(" \"level4\":\"" + numBean.getLevel4() + "\",");
  72. // json.append(" \"enpDoc\":\"" + numBean.getEnpDoc() + "\",");
  73. // json.append(" \"enpSys\":\"" + numBean.getEnpSys() + "\",");
  74. // json.append(" \"enpArd\":\"" + numBean.getEnpArd() + "\",");
  75. json.append(" \"num\":\"" + numBean.getNum() + "\",");
  76. json.append(" \"name\":\"" +"总计" + "\",");
  77. json.append(" \"dept_id\":\"" + "11111" + "\",");
  78. json.append(" \"isParent\":false,");
  79. json.append(" \"open\":false");
  80. json.append("} ");
  81. String result="{\"rows\":["+json.toString()+"]}";
  82. // List<String>list=getCmpList(id, new ArrayList<String>());
  83. log.info("result===="+result);
  84. return result;
  85. }
  86. public String teamNum(String id,String startTime,String endTime,String tempLevel,String valueType1){
  87. try{
  88. if(checkId(id)){
  89. String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
  90. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  91. log.info("teamNum.tempList.size===="+tempList.size());
  92. for(int i=0;i<tempList.size();i++){
  93. List<String>list=getCmpList(tempList.get(i)[0], new ArrayList<String>());
  94. getFileNum(list, tempList.get(i)[0],startTime,endTime,tempLevel,valueType1);
  95. }
  96. }else{
  97. List<String>list=new ArrayList<String>();
  98. list.add(id);
  99. getNoChildFileNum(list, id,startTime,endTime,tempLevel,valueType1);
  100. }}catch(Exception e){
  101. this.log.error(e.getMessage(), e);
  102. }
  103. // log.info("最终JSON==="+json.toString());
  104. if (json.lastIndexOf(",") > -1) {
  105. json.deleteCharAt(json.lastIndexOf(","));
  106. }
  107. String result="{\"rows\":["+json.toString()+"]}";
  108. // List<String>list=getCmpList(id, new ArrayList<String>());
  109. log.info("result===="+result);
  110. return result;
  111. }
  112. public List<String> getCmpList(String id,List<String>list) {
  113. try{
  114. if(checkId(id)){//存在子节点且子节点在明细表中有记录
  115. list.add(id);
  116. String sql="select DEPT_ID from sys_department where parent_id='"+id+"'";
  117. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  118. log.info("getCmpList.tempList.size===="+tempList.size());
  119. for(int i=0;i<tempList.size();i++){
  120. getCmpList(tempList.get(i)[0],list);
  121. }
  122. }
  123. else{//如果不存在自己点或者子节点在明细表中无记录,则返回该ID
  124. list.add(id);
  125. }}catch(Exception e){
  126. this.log.error(e.getMessage(), e);
  127. }
  128. return list;
  129. }
  130. //判断是否有下级单位
  131. public boolean checkId(String id) {
  132. try{
  133. // String sql="select * from EMC_AM_BUSINESS_DOCUMENT WHERE UNITE IN(SELECT ID FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"')";
  134. String sql="select * from EMC_AM_GOVERNMENT_DOCUMENT WHERE UNITE IN(SELECT DEPT_ID FROM SYS_DEPARTMENT WHERE PARENT_ID='"+id+"')";
  135. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  136. if(tempList==null||tempList.size()==0){
  137. return false;
  138. }else{
  139. return true;
  140. }}catch(Exception e){
  141. this.log.error(e.getMessage(), e);
  142. return false;
  143. }
  144. }
  145. //统计
  146. public void getFileNum(List<String>list,String id,String startTime,String endTime,String tempLevel,String valueType1) throws PersistenceException{
  147. try{
  148. for(int i=0;i<list.size();i++){
  149. govDoc fa = new govDoc();
  150. String sql="select UNITE,sum(case SECRECY_LEVEL when '1' then 1 else 0 end)as 公开,"
  151. + "sum(case SECRECY_LEVEL when '2' then 1 else 0 end)as 秘密 ,"
  152. + "sum(case SECRECY_LEVEL when '3' then 1 else 0 end)as 机密,"
  153. + "sum(case SECRECY_LEVEL when '4' then 1 else 0 end)as 绝密,"
  154. + "count(SECRECY_LEVEL)as num from EMC_AM_GOVERNMENT_DOCUMENT where is_del='0' and IS_ISSUE = '1' and UNITE='"+list.get(i)+"'";
  155. if(startTime!=null&&!"null".equals(startTime)&&!"".equals(startTime)){
  156. sql+=" and PRINT_DATE between '"+startTime+"' and '"+endTime+"'";
  157. }
  158. //状态
  159. if(tempLevel!=null&&!"".equals(tempLevel)&&!"null".equals(tempLevel)){
  160. sql+=" and STATE in("+tempLevel+")";
  161. }
  162. //保密级别
  163. if(valueType1!=null&&!"null".equals(valueType1)&&!"".equals(valueType1)){
  164. sql+=" and SECRECY_LEVEL in ("+valueType1+")";
  165. }
  166. sql+=" group by UNITE ";
  167. log.info("getTeamNum.sql===="+sql);
  168. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  169. if(tempList.size()>0){
  170. fa.setLevel1(Integer.parseInt(tempList.get(0)[1]));
  171. fa.setLevel2(Integer.parseInt(tempList.get(0)[2]));
  172. fa.setLevel3(Integer.parseInt(tempList.get(0)[3]));
  173. fa.setLevel4(Integer.parseInt(tempList.get(0)[4]));
  174. /*fa.setEnpDoc(Integer.parseInt(tempList.get(0)[1]));
  175. fa.setEnpSys(Integer.parseInt(tempList.get(0)[2]));
  176. fa.setEnpArd(Integer.parseInt(tempList.get(0)[3]));*/
  177. fa.setNum(Integer.parseInt(tempList.get(0)[5]));
  178. numList.add(fa);
  179. int fff = fa.getNum();
  180. if(fa.getNum()>0){
  181. if(checkId(id)){
  182. json.append("{ ");
  183. json.append(" \"level1\":\"" + fa.getLevel1() + "\",");
  184. json.append(" \"level2\":\"" + fa.getLevel2() + "\",");
  185. json.append(" \"level3\":\"" + fa.getLevel3() + "\",");
  186. json.append(" \"level4\":\"" + fa.getLevel4() + "\",");
  187. json.append(" \"num\":\"" + fa.getNum() + "\",");
  188. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  189. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  190. json.append(" \"isParent\":true,");
  191. json.append(" \"open\":false");
  192. json.append("}, ");
  193. }else{
  194. json.append("{ ");
  195. json.append(" \"level1\":\"" + fa.getLevel1() + "\",");
  196. json.append(" \"level2\":\"" + fa.getLevel2() + "\",");
  197. json.append(" \"level3\":\"" + fa.getLevel3() + "\",");
  198. json.append(" \"level4\":\"" + fa.getLevel4() + "\",");
  199. json.append(" \"num\":\"" + fa.getNum() + "\",");
  200. json.append(" \"name\":\"" + getNameById(list.get(i)) + "\",");
  201. json.append(" \"dept_id\":\"" + list.get(i) + "\",");
  202. json.append(" \"isParent\":false,");
  203. json.append(" \"open\":false");
  204. json.append("}, ");
  205. }
  206. }
  207. }
  208. }}catch(Exception e){
  209. this.log.error(e.getMessage(), e);
  210. }
  211. }
  212. //统计
  213. public void getNoChildFileNum(List<String>list,String id,String startTime,String endTime,String tempLevel,String valueType1) throws PersistenceException{
  214. govDoc fa = new govDoc();
  215. try{
  216. for(int i=0;i<list.size();i++){
  217. String sql="select UNITE,sum(case SECRECY_LEVEL when '1' then 1 else 0 end)as 公开,"
  218. + "sum(case SECRECY_LEVEL when '2' then 1 else 0 end)as 秘密 ,"
  219. + "sum(case SECRECY_LEVEL when '3' then 1 else 0 end)as 机密,"
  220. + "sum(case SECRECY_LEVEL when '4' then 1 else 0 end)as 绝密,"
  221. + "count(SECRECY_LEVEL)as num from EMC_AM_GOVERNMENT_DOCUMENT where is_del='0' and IS_ISSUE = '1' and UNITE='"+list.get(i)+"'";
  222. if(startTime!=null&&!"null".equals(startTime)&&!"".equals(startTime)){
  223. sql+=" and PRINT_DATE between '"+startTime+"' and '"+endTime+"'";
  224. }
  225. //状态
  226. if(tempLevel!=null&&!"".equals(tempLevel)&&!"null".equals(tempLevel)){
  227. sql+=" and STATE in("+tempLevel+")";
  228. }
  229. //保密级别
  230. if(valueType1!=null&&!"null".equals(valueType1)&&!"".equals(valueType1)){
  231. sql+=" and SECRECY_LEVEL in ("+valueType1+")";
  232. }
  233. sql+=" group by UNITE ";
  234. log.info("getNoChildTeamNum.sql===="+sql);
  235. List<String[]>numList= persistence.getSearchResult(99, sql.toString());
  236. if(numList.size()>0){
  237. fa.setLevel1(fa.getLevel1()+Integer.parseInt(numList.get(0)[1]));
  238. fa.setLevel2(fa.getLevel2()+Integer.parseInt(numList.get(0)[2]));
  239. fa.setLevel3(fa.getLevel3()+Integer.parseInt(numList.get(0)[3]));
  240. fa.setLevel4(fa.getLevel4()+Integer.parseInt(numList.get(0)[4]));
  241. /*fa.setEnpDoc(fa.getEnpDoc()+Integer.parseInt(numList.get(0)[1]));
  242. fa.setEnpSys(fa.getEnpSys()+Integer.parseInt(numList.get(0)[2]));
  243. fa.setEnpArd(fa.getEnpArd()+Integer.parseInt(numList.get(0)[3]));*/
  244. fa.setNum(fa.getNum()+Integer.parseInt(numList.get(0)[5]));
  245. }
  246. }}catch(Exception e){
  247. this.log.error(e.getMessage(), e);
  248. }
  249. // StringBuffer json=new StringBuffer();
  250. if(fa.getNum()>0){
  251. json.append("{ ");
  252. json.append(" \"level1\":\"" + fa.getLevel1() + "\",");
  253. json.append(" \"level2\":\"" + fa.getLevel2() + "\",");
  254. json.append(" \"level3\":\"" + fa.getLevel3() + "\",");
  255. json.append(" \"level4\":\"" + fa.getLevel4() + "\",");
  256. json.append(" \"num\":\"" + fa.getNum() + "\",");
  257. json.append(" \"name\":\"" + getNameById(id) + "\",");
  258. json.append(" \"dept_id\":\"" + id + "\",");
  259. json.append(" \"isParent\":false,");
  260. json.append(" \"open\":true");
  261. json.append("}, ");
  262. numList.add(fa);
  263. }
  264. }
  265. public String getNameById(String id){
  266. String sql="select DEPT_NAME from sys_department where DEPT_ID='"+id+"'";
  267. try {
  268. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  269. if(tempList==null||tempList.size()==0){
  270. return "";
  271. }else{
  272. String name=tempList.get(0)[0].replace("供电局", "").replace("广东电网有限责任公司", "广东");
  273. log.info("name===="+name);
  274. return name;
  275. }
  276. } catch (PersistenceException e) {
  277. // TODO Auto-generated catch block
  278. e.printStackTrace();
  279. return "";
  280. }
  281. }
  282. /********************************发布、共享********************************************/
  283. /**
  284. *政府公文,,,,改变(更新)发布状态为1
  285. * @throws ClassNotFoundException
  286. */
  287. public Msg getIsIssue(String fd_id) throws ClassNotFoundException{
  288. Msg m=new Msg();
  289. String []arr=fd_id.split(",");
  290. String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_ISSUE='1' where fd_objectid=?";
  291. Connection conn = null;
  292. PreparedStatement st = null;
  293. int num=0;
  294. DbConnection db = new DbConnection();
  295. try {
  296. conn = db.getConnection();
  297. conn.setAutoCommit(false);
  298. st = conn.prepareStatement(sql);
  299. for(int i=0;i<arr.length;i++){
  300. st.setString(1, arr[i]);
  301. st.executeUpdate();
  302. num++;
  303. }
  304. if(num==arr.length){
  305. log.info("发布----num===="+num);
  306. m.setSucsess(new Boolean(true).toString());
  307. m.setInfo(Parameter.OPER_SUCSESS);
  308. conn.commit();
  309. return m;
  310. }else{
  311. m.setSucsess(new Boolean(false).toString());
  312. m.setInfo(Parameter.OPER_FAILURE);
  313. conn.rollback();
  314. return m;
  315. }
  316. }catch (SQLException e) {
  317. this.log.error(e.getMessage(), e);
  318. throw new ClassNotFoundException("DAO Layou: 发布消息" + sql, e);
  319. } finally {
  320. db.close(st);
  321. db.close(conn);
  322. }
  323. }
  324. /**
  325. *政府公文,,,,改变(更新)发布状态为1
  326. * @throws ClassNotFoundException
  327. */
  328. public Msg getnoIsIssue(String fd_id) throws ClassNotFoundException{
  329. Msg m=new Msg();
  330. String []arr=fd_id.split(",");
  331. String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_ISSUE='0',IS_SHARE='0' where fd_objectid=?";
  332. Connection conn = null;
  333. PreparedStatement st = null;
  334. int num=0;
  335. DbConnection db = new DbConnection();
  336. try {
  337. conn = db.getConnection();
  338. conn.setAutoCommit(false);
  339. st = conn.prepareStatement(sql);
  340. for(int i=0;i<arr.length;i++){
  341. st.setString(1, arr[i]);
  342. st.executeUpdate();
  343. num++;
  344. }
  345. if(num==arr.length){
  346. log.info("发布----num===="+num);
  347. m.setSucsess(new Boolean(true).toString());
  348. m.setInfo(Parameter.OPER_SUCSESS);
  349. conn.commit();
  350. return m;
  351. }else{
  352. m.setSucsess(new Boolean(false).toString());
  353. m.setInfo(Parameter.OPER_FAILURE);
  354. conn.rollback();
  355. return m;
  356. }
  357. }catch (SQLException e) {
  358. this.log.error(e.getMessage(), e);
  359. throw new ClassNotFoundException("DAO Layou: 发布消息" + sql, e);
  360. } finally {
  361. db.close(st);
  362. db.close(conn);
  363. }
  364. }
  365. /**
  366. * 共享文件 都可以看到
  367. * @throws ClassNotFoundException
  368. */
  369. //共享
  370. public Msg getDocuShare(String fd_id) throws ClassNotFoundException{
  371. Msg m=new Msg();
  372. String []arr=fd_id.split(",");
  373. String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_SHARE='1' where fd_objectid=?";
  374. Connection conn = null;
  375. PreparedStatement st = null;
  376. int num=0;
  377. DbConnection db = new DbConnection();
  378. try {
  379. conn = db.getConnection();
  380. conn.setAutoCommit(false);
  381. st = conn.prepareStatement(sql);
  382. for(int i=0;i<arr.length;i++){
  383. st.setString(1, arr[i]);
  384. st.executeUpdate();
  385. num++;
  386. }
  387. if(num==arr.length){
  388. log.info("发布----num===="+num);
  389. m.setSucsess(new Boolean(true).toString());
  390. m.setInfo(Parameter.OPER_SUCSESS);
  391. conn.commit();
  392. return m;
  393. }else{
  394. m.setSucsess(new Boolean(false).toString());
  395. m.setInfo(Parameter.OPER_FAILURE);
  396. conn.rollback();
  397. return m;
  398. }
  399. }catch (SQLException e) {
  400. this.log.error(e.getMessage(), e);
  401. throw new ClassNotFoundException("DAO Layou: 发布消息" + sql, e);
  402. } finally {
  403. db.close(st);
  404. db.close(conn);
  405. }
  406. }
  407. /**
  408. * 撤销共享
  409. * @throws ClassNotFoundException
  410. */
  411. //取消共享
  412. public Msg getnoDocuShare(String fd_id) throws ClassNotFoundException{
  413. Msg m=new Msg();
  414. String []arr=fd_id.split(",");
  415. String sql="UPDATE EMC_AM_GOVERNMENT_DOCUMENT SET IS_SHARE='0' where fd_objectid=?";
  416. Connection conn = null;
  417. PreparedStatement st = null;
  418. int num=0;
  419. DbConnection db = new DbConnection();
  420. try {
  421. conn = db.getConnection();
  422. conn.setAutoCommit(false);
  423. st = conn.prepareStatement(sql);
  424. for(int i=0;i<arr.length;i++){
  425. st.setString(1, arr[i]);
  426. st.executeUpdate();
  427. num++;
  428. }
  429. if(num==arr.length){
  430. log.info("发布----num===="+num);
  431. m.setSucsess(new Boolean(true).toString());
  432. m.setInfo(Parameter.OPER_SUCSESS);
  433. conn.commit();
  434. return m;
  435. }else{
  436. m.setSucsess(new Boolean(false).toString());
  437. m.setInfo(Parameter.OPER_FAILURE);
  438. conn.rollback();
  439. return m;
  440. }
  441. }catch (SQLException e) {
  442. this.log.error(e.getMessage(), e);
  443. throw new ClassNotFoundException("DAO Layou: 发布消息"
  444. + sql, e);
  445. } finally {
  446. db.close(st);
  447. db.close(conn);
  448. }
  449. }
  450. }