5ccf39a03616af79d0255af116ca32e3cf408fd7.svn-base 15 KB

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