0e1ae69006d28c6a294a34b866e9ee18c1554f8c.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. package com.sinosoft.am.systemFile.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.Map;
  12. import net.sf.json.JSONArray;
  13. import org.apache.log4j.Logger;
  14. import com.formaction.Parameter;
  15. import com.formaction.vo.Msg;
  16. import com.persistence.DbConnection;
  17. import com.persistence.service.PersistenceFactory;
  18. import com.persistence.service.exception.PersistenceException;
  19. import com.sinosoft.am.systemFile.vo.SystemFile;
  20. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  21. public class SystemFileDao{
  22. private Logger log = Logger.getLogger(this.getClass());
  23. /**
  24. * 上报文件 上级单位可看
  25. * @throws ClassNotFoundException
  26. */
  27. public Msg appear(String comp_id,String fd_id) throws ClassNotFoundException{
  28. Msg m=new Msg();
  29. String []arr=fd_id.split(",");
  30. String sql="UPDATE ECM_AM_FILE_MANAGEMENT SET FILE_STATUS='1',REPORT_COMP_ID=? where fd_objectid=?";
  31. Connection conn = null;
  32. PreparedStatement st = null;
  33. int num=0;
  34. DbConnection db = new DbConnection();
  35. try {
  36. conn = db.getConnection();
  37. conn.setAutoCommit(false);
  38. st = conn.prepareStatement(sql);
  39. for(int i=0;i<arr.length;i++){
  40. st.setString(1, comp_id);
  41. st.setString(2, arr[i]);
  42. st.executeUpdate();
  43. num++;
  44. }
  45. if(num==arr.length){
  46. log.info("删除----num===="+num);
  47. m.setSucsess(new Boolean(true).toString());
  48. m.setInfo(Parameter.DELETE_SUCSESS);
  49. conn.commit();
  50. return m;
  51. }else{
  52. m.setSucsess(new Boolean(false).toString());
  53. m.setInfo(Parameter.DELETE_FAILURE);
  54. conn.rollback();
  55. return m;
  56. }
  57. }catch (SQLException e) {
  58. this.log.error(e.getMessage(), e);
  59. throw new ClassNotFoundException("DAO Layou: 删除消息"
  60. + sql, e);
  61. } finally {
  62. db.close(st);
  63. db.close(conn);
  64. }
  65. }
  66. /**
  67. * 发布文件 使所有级别都可以看到
  68. * @throws ClassNotFoundException
  69. */
  70. public Msg issue(String comp_id,String fd_id) throws ClassNotFoundException{
  71. Msg m=new Msg();
  72. String []arr=fd_id.split(",");
  73. String sql="UPDATE ECM_AM_FILE_MANAGEMENT SET FILE_STATUS='2',PUBLISH_COMP_ID=? where fd_objectid=?";
  74. Connection conn = null;
  75. PreparedStatement st = null;
  76. int num=0;
  77. DbConnection db = new DbConnection();
  78. try {
  79. conn = db.getConnection();
  80. conn.setAutoCommit(false);
  81. st = conn.prepareStatement(sql);
  82. for(int i=0;i<arr.length;i++){
  83. st.setString(1, comp_id);
  84. st.setString(2, arr[i]);
  85. st.executeUpdate();
  86. num++;
  87. }
  88. if(num==arr.length){
  89. log.info("删除----num===="+num);
  90. m.setSucsess(new Boolean(true).toString());
  91. m.setInfo(Parameter.DELETE_SUCSESS);
  92. conn.commit();
  93. return m;
  94. }else{
  95. m.setSucsess(new Boolean(false).toString());
  96. m.setInfo(Parameter.DELETE_FAILURE);
  97. conn.rollback();
  98. return m;
  99. }
  100. }catch (SQLException e) {
  101. this.log.error(e.getMessage(), e);
  102. throw new ClassNotFoundException("DAO Layou: 删除消息"
  103. + sql, e);
  104. } finally {
  105. db.close(st);
  106. db.close(conn);
  107. }
  108. }
  109. /**
  110. * 撤回文件 更改文件状态,上级无法查看,只能本人查看
  111. * @throws ClassNotFoundException
  112. */
  113. public Msg callBack(String fd_id) throws ClassNotFoundException{
  114. Msg m=new Msg();
  115. String []arr=fd_id.split(",");
  116. String sql="UPDATE ECM_AM_FILE_MANAGEMENT SET FILE_STATUS='0' where fd_objectid=?";
  117. Connection conn = null;
  118. PreparedStatement st = null;
  119. int num=0;
  120. DbConnection db = new DbConnection();
  121. try {
  122. conn = db.getConnection();
  123. conn.setAutoCommit(false);
  124. st = conn.prepareStatement(sql);
  125. for(int i=0;i<arr.length;i++){
  126. st.setString(1, arr[i]);
  127. st.executeUpdate();
  128. num++;
  129. }
  130. if(num==arr.length){
  131. log.info("删除----num===="+num);
  132. m.setSucsess(new Boolean(true).toString());
  133. m.setInfo(Parameter.DELETE_SUCSESS);
  134. conn.commit();
  135. return m;
  136. }else{
  137. m.setSucsess(new Boolean(false).toString());
  138. m.setInfo(Parameter.DELETE_FAILURE);
  139. conn.rollback();
  140. return m;
  141. }
  142. }catch (SQLException e) {
  143. this.log.error(e.getMessage(), e);
  144. throw new ClassNotFoundException("DAO Layou: 删除消息"
  145. + sql, e);
  146. } finally {
  147. db.close(st);
  148. db.close(conn);
  149. }
  150. }
  151. /**
  152. * 上传文件
  153. */
  154. public void importFile(String fileName){
  155. }
  156. //查询上报的文件
  157. //上报公司为查询用户的子公司且状态为上报状态‘1’
  158. public List<Map<String, String>> queryAppearFileList(String userId,String conditon) throws ClassNotFoundException{
  159. String sql="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT WHERE REPORT_COMP_ID in(select id from sys_department_0827 where parent_id='"+userId+"') and FILE_STATUS='1' ";
  160. if(!"".equals(conditon)){
  161. sql+=conditon;
  162. }
  163. log.info("queryAppearFileList.sql==="+sql);
  164. List<Map<String, String>> list = null;
  165. try {
  166. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  167. } catch (PersistenceException e) {
  168. log.error(e.getMessage());
  169. }
  170. log.info("获取已接收消息条数===="+list.size());
  171. // String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  172. return list;
  173. }
  174. //查询发布的文件
  175. //状态为2 且发布部门为当前用户部门
  176. public List<Map<String, String>> queryIssueFileList(String userId,String conditon) throws ClassNotFoundException{
  177. String sql="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT WHERE FILE_STATUS='2' AND PUBLISH_COMP_ID='"+userId+"' ";
  178. if(!"".equals(conditon)){
  179. sql+=conditon;
  180. }
  181. log.info("queryIssueFileList.sql==="+sql);
  182. List<Map<String, String>> list = null;
  183. try {
  184. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  185. } catch (PersistenceException e) {
  186. log.error(e.getMessage());
  187. }
  188. log.info("获取已接收消息条数===="+list.size());
  189. // String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  190. return list;
  191. }
  192. //查询上传的文件
  193. //上传用户为登录用户且文件状态为上传状态‘0’
  194. public List<Map<String, String>> queryUploadFileList(String userId,String conditon) throws ClassNotFoundException{
  195. String sql="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT WHERE FILE_STATUS in('0','1') AND PIGEONHOLE_MAN_ID='"+userId+"' ";
  196. if(!"".equals(conditon)){
  197. sql+=conditon;
  198. }
  199. log.info("queryUploadFileList.sql==="+sql);
  200. List<Map<String, String>> list = null;
  201. try {
  202. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  203. } catch (PersistenceException e) {
  204. log.error(e.getMessage());
  205. }
  206. log.info("获取已接收消息条数===="+list.size());
  207. // String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  208. return list;
  209. }
  210. /**
  211. * 初始化和查询文件
  212. * @throws ClassNotFoundException
  213. */
  214. public String queryFileList(String userId,String comp_id,String condition,int pageNo,int pageSize) throws ClassNotFoundException{
  215. if(!"".equals(condition)){
  216. condition+=" ";
  217. }
  218. /*String sql1="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT WHERE REPORT_COMP_ID in(select id from sys_department_0827 where parent_id='"+userId+"') and FILE_STATUS='1' ";
  219. String sql2="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT WHERE FILE_STATUS='2' AND PUBLISH_COMP_ID='"+userId+"' ";
  220. String sql3="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT WHERE FILE_STATUS in('0','1') AND PIGEONHOLE_MAN_ID='"+userId+"' ";*/
  221. String sql="";
  222. String sqlR="";
  223. if(!"".equals(condition)){
  224. sql+="select FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT "
  225. + "WHERE (REPORT_COMP_ID in(select id from sys_department_0827 where parent_id='"+userId+"') and FILE_STATUS='1' "+condition+")or (FILE_STATUS='2' AND PUBLISH_COMP_ID='"+userId+"' "+condition+") or(FILE_STATUS in('0','1') AND PIGEONHOLE_MAN_ID='"+userId+"' "+condition+") ";
  226. sqlR+="select top "+(pageNo-1)*pageSize+","+pageSize+" FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID from ECM_AM_FILE_MANAGEMENT "
  227. + "WHERE (REPORT_COMP_ID in(select id from sys_department_0827 where parent_id='"+userId+"') and FILE_STATUS='1' "+condition+")or (FILE_STATUS='2' AND PUBLISH_COMP_ID='"+userId+"' "+condition+") or(FILE_STATUS in('0','1') AND PIGEONHOLE_MAN_ID='"+userId+"' "+condition+") ";
  228. /*sql+=condition;
  229. sqlR+=condition;*/
  230. }
  231. List<Map<String, String>> list = null;
  232. List<Map<String, String>> listR = null;
  233. try {
  234. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  235. listR = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sqlR);
  236. } catch (PersistenceException e) {
  237. log.error(e.getMessage());
  238. }
  239. log.info("sqlR===="+sqlR);
  240. log.info("sql===="+sql);
  241. log.info("获取已接收消息条数===="+list.size());
  242. /*List<Map<String, String>>list1=queryAppearFileList(comp_id,condition);
  243. List<Map<String, String>>list2=queryIssueFileList(comp_id,condition);
  244. List<Map<String, String>>list3=queryUploadFileList(userId,condition);*/
  245. /*for(int i=0;i<list1.size();i++){
  246. list.add(list1.get(i));
  247. // list.add(list1.get(i));
  248. // list.add(list1.get(i));
  249. // list.add(list1.get(i));
  250. // list.add(list1.get(i));
  251. // list.add(list1.get(i));
  252. // list.add(list1.get(i));
  253. // list.add(list1.get(i));
  254. }*/
  255. /*for(int i=0;i<list2.size();i++){
  256. list.add(list2.get(i));
  257. // list.add(list2.get(i));
  258. // list.add(list2.get(i));
  259. // list.add(list2.get(i));
  260. // list.add(list2.get(i));
  261. // list.add(list2.get(i));
  262. // list.add(list2.get(i));
  263. // list.add(list2.get(i));
  264. }*/
  265. /*for(int i=0;i<list3.size();i++){
  266. list.add(list3.get(i));
  267. // list.add(list3.get(i));
  268. // list.add(list3.get(i));
  269. // list.add(list3.get(i));
  270. // list.add(list3.get(i));
  271. // list.add(list3.get(i));
  272. // list.add(list3.get(i));
  273. // list.add(list3.get(i));
  274. }*/
  275. log.info("获取已接收消息条数===="+list.size());
  276. String result = "{\"pager.pageNo\":"+pageNo+",\"pager.totalRows\":"+list.size()+",\"rows\":" + JSONArray.fromObject(listR).toString() + "}";
  277. log.info("result==="+result);
  278. return result;
  279. }
  280. /**
  281. * 查看文件明细和修改文件查看
  282. */
  283. public String getFileInfo(String fd_id){
  284. String sql="select * from ECM_AM_FILE_MANAGEMENT where fd_objectid='"+fd_id+"'";
  285. List list = null;
  286. try {
  287. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  288. } catch (PersistenceException e) {
  289. log.error(e.getMessage());
  290. }
  291. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  292. log.info("获取制度文件信息==="+result);
  293. return result;
  294. }
  295. /**
  296. * 修改文件--纯修改文件基本信息
  297. * @throws ClassNotFoundException
  298. */
  299. public Msg updateFile(SystemFile sf) throws ClassNotFoundException{
  300. Msg m=new Msg();
  301. String sql="update ECM_AM_FILE_MANAGEMENT SET FILE_TITLE=?,FILE_CLASSIFY=?,FILE_CONTENT=?,CHANGE_DETAIL=?,CHANGE_TYPE=?,UPDATEDATE=?,FILE_ADD_DATE=? WHERE FD_OBJECTID=?";
  302. Connection conn = null;
  303. PreparedStatement st = null;
  304. int num=0;
  305. DbConnection db = new DbConnection();
  306. try {
  307. conn = db.getConnection();
  308. conn.setAutoCommit(false);
  309. st = conn.prepareStatement(sql);
  310. st.setString(1, sf.getFILE_TITLE());
  311. st.setString(2, sf.getFILE_CLASSIFY());
  312. st.setString(3, sf.getFILE_CONTENT());
  313. st.setString(4, sf.getCHANGE_DETAIL());
  314. st.setString(5, sf.getCHANGE_TYPE());
  315. st.setString(6,formatDate(new Date()));
  316. st.setString(7, sf.getFILE_ADD_DATE());
  317. st.setString(8, sf.getFD_OBJECTID());
  318. st.executeUpdate();
  319. num++;
  320. if(num==1){
  321. log.info("删除----num===="+num);
  322. m.setSucsess(new Boolean(true).toString());
  323. m.setInfo(Parameter.UPDATE_SUCSESS);
  324. conn.commit();
  325. return m;
  326. }else{
  327. m.setSucsess(new Boolean(false).toString());
  328. m.setInfo(Parameter.UPDATE_FAILURE);
  329. conn.rollback();
  330. return m;
  331. }
  332. }catch (SQLException e) {
  333. this.log.error(e.getMessage(), e);
  334. throw new ClassNotFoundException("DAO Layou: 删除消息"
  335. + sql, e);
  336. } finally {
  337. db.close(st);
  338. db.close(conn);
  339. }
  340. }
  341. /**
  342. * 归档--修改时如果附件栏有变动,则视为归档
  343. * @throws ClassNotFoundException
  344. */
  345. public Msg placeFile(SystemFile sf) throws ClassNotFoundException{
  346. Msg m=new Msg();
  347. // String version_id=getVersionId(sf.getFD_OBJECTID());
  348. sf.setVERSION_ID(sf.getVERSION_ID());
  349. m=createFile(sf);
  350. m=deleteFile(sf.getFD_OBJECTID());
  351. return m;
  352. }
  353. // public String getVersionId(String id) throws ClassNotFoundException{
  354. // String sql="SELECT version_id FROM WHERE fd_objectid='"+id+"'";
  355. // String fd_id="";
  356. // Connection conn = null;
  357. // Statement stat = null;
  358. // ResultSet rs = null;
  359. // DbConnection db = new DbConnection();
  360. // try {
  361. // conn = db.getConnection();
  362. // stat = conn.createStatement();
  363. // rs = stat.executeQuery(sql);
  364. // List<String> list = new ArrayList<String>();
  365. // while (rs.next()) {
  366. // list.add(rs.getString("FD_OBJECTID"));
  367. // }
  368. // if(list.size()==1){
  369. // fd_id=list.get(0);
  370. // }
  371. // } catch (SQLException e) {
  372. // this.log.error(e.getMessage(), e);
  373. // throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  374. // + sql, e);
  375. // } finally {
  376. // db.close(rs);
  377. // db.close(stat);
  378. // db.close(conn);
  379. // }
  380. // return fd_id;
  381. // }
  382. //查看历史版本,表格显示 版次-变更说明-状态
  383. public String showHis(String version_id){
  384. String sql="SELECT * FROM ECM_AM_FILE_MANAGEMENT WHERE version_id='"+version_id+"'";
  385. List list = null;
  386. try {
  387. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  388. } catch (PersistenceException e) {
  389. log.error(e.getMessage());
  390. }
  391. log.info("获取已接收消息条数===="+list.size());
  392. String result = JSONArray.fromObject(list).toString();
  393. return result;
  394. }
  395. /**
  396. * 删除文件
  397. * @throws ClassNotFoundException
  398. */
  399. public Msg deleteFile(String fd_id) throws ClassNotFoundException{
  400. Msg m=new Msg();
  401. String []arr=fd_id.split(";");
  402. String sql="UPDATE ECM_AM_FILE_MANAGEMENT SET IS_DEL='1' WHERE FD_OBJECTID=?" ;
  403. Connection conn = null;
  404. PreparedStatement st = null;
  405. int num=0;
  406. DbConnection db = new DbConnection();
  407. try {
  408. conn = db.getConnection();
  409. conn.setAutoCommit(false);
  410. st = conn.prepareStatement(sql);
  411. for(int i=0;i<arr.length;i++){
  412. st.setString(1, arr[i]);
  413. st.executeUpdate();
  414. num++;
  415. }
  416. if(num==arr.length){
  417. log.info("删除----num===="+num);
  418. m.setSucsess(new Boolean(true).toString());
  419. m.setInfo(Parameter.DELETE_SUCSESS);
  420. conn.commit();
  421. return m;
  422. }else{
  423. m.setSucsess(new Boolean(false).toString());
  424. m.setInfo(Parameter.DELETE_FAILURE);
  425. conn.rollback();
  426. return m;
  427. }
  428. }catch (SQLException e) {
  429. this.log.error(e.getMessage(), e);
  430. throw new ClassNotFoundException("DAO Layou: 删除消息"
  431. + sql, e);
  432. } finally {
  433. db.close(st);
  434. db.close(conn);
  435. }
  436. }
  437. /**
  438. * 增加文件
  439. * @throws ClassNotFoundException
  440. */
  441. public Msg createFile(SystemFile sf) throws ClassNotFoundException{
  442. Msg m=new Msg();
  443. // String fileName=sf.getELECTRONIC_FILE();
  444. // String newFileName=uploadFile(fileName);
  445. String sql="INSERT INTO ECM_AM_FILE_MANAGEMENT(FD_OBJECTID,FILE_TITLE,FILE_CLASSIFY,FILE_CONTENT,FILE_ADD_DATE,PIGEONHOLE_MAN_ID,PIGEONHOLE_DATE,CHANGE_DETAIL,CHANGE_TYPE,PUBLISH_COMP_ID,REPORT_COMP_ID,FILE_STATUS,IS_DEL,ELECTRONIC_FILE,UPDATEDATE,VERSION_ID) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  446. Connection conn = null;
  447. PreparedStatement st = null;
  448. int num=0;
  449. DbConnection db = new DbConnection();
  450. try {
  451. conn = db.getConnection();
  452. conn.setAutoCommit(false);
  453. st = conn.prepareStatement(sql);
  454. String fd_id=createMsgId(getMsgId());
  455. st.setString(1,fd_id );
  456. st.setString(2, sf.getFILE_TITLE());
  457. st.setString(3, sf.getFILE_CLASSIFY());
  458. st.setString(4, sf.getFILE_CONTENT());
  459. st.setString(5, sf.getFILE_ADD_DATE());
  460. st.setString(6, sf.getPIGEONHOLE_MAN_ID());
  461. st.setString(7, formatDate(new Date()));
  462. st.setString(8, sf.getCHANGE_DETAIL());
  463. st.setString(9, "新增");
  464. st.setString(10,"");//发布单位
  465. st.setString(11, "");//上报单位
  466. st.setString(12, "0");//发布、上传、上报状态
  467. st.setString(13,"0");
  468. st.setString(14, sf.getELECTRONIC_FILE());
  469. st.setString(15, formatDate(new Date()));
  470. st.setString(16, fd_id);
  471. st.executeUpdate();
  472. num++;
  473. if(num==1){
  474. log.info("删除----num===="+num);
  475. m.setSucsess(new Boolean(true).toString());
  476. m.setInfo(Parameter.DELETE_SUCSESS);
  477. conn.commit();
  478. }else{
  479. m.setSucsess(new Boolean(false).toString());
  480. m.setInfo(Parameter.DELETE_FAILURE);
  481. conn.rollback();
  482. }
  483. }catch (SQLException e) {
  484. m.setSucsess(new Boolean(false).toString());
  485. m.setInfo(Parameter.DELETE_FAILURE);
  486. this.log.error(e.getMessage(), e);
  487. throw new ClassNotFoundException("DAO Layou: 删除消息"
  488. + sql, e);
  489. } finally {
  490. db.close(st);
  491. db.close(conn);
  492. }
  493. return m;
  494. }
  495. public String formatDate(Date d) {
  496. SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  497. String date = sd.format(d);
  498. return date;
  499. }
  500. public List<String> getMsgId() throws ClassNotFoundException {
  501. String sql = "SELECT FD_OBJECTID FROM ECM_AM_FILE_MANAGEMENT";
  502. Connection conn = null;
  503. Statement stat = null;
  504. ResultSet rs = null;
  505. DbConnection db = new DbConnection();
  506. try {
  507. conn = db.getConnection();
  508. stat = conn.createStatement();
  509. rs = stat.executeQuery(sql);
  510. List<String> list = new ArrayList();
  511. while (rs.next()) {
  512. list.add(rs.getString("FD_OBJECTID"));
  513. }
  514. return list;
  515. } catch (SQLException e) {
  516. this.log.error(e.getMessage(), e);
  517. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  518. + sql, e);
  519. } finally {
  520. db.close(rs);
  521. db.close(stat);
  522. db.close(conn);
  523. }
  524. }
  525. public String createMsgId(List<String> list) throws ClassNotFoundException{
  526. long l=(long) ((Math.random()+1)*1000000000);
  527. String msgId=l+"";
  528. if(list.contains(msgId)){
  529. return createMsgId(list);
  530. }
  531. else{
  532. log.info("FD_OBJECTID==="+msgId);
  533. return msgId;
  534. }
  535. }
  536. //上传文件,参数为本地文件路径+文件名
  537. //返回文件上传后在服务器中的地址加文件名
  538. public String uploadFile(String fileName){
  539. return null;
  540. }
  541. public void downLoadFile(String fd_id){
  542. }
  543. }