document.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 1,120 行 · 第 1/3 页
JAVA
1,120 行
if (conn != null) { conn.close(); conn = null; } } return true; } public synchronized boolean UpdateIsHome(boolean isHome) throws ErrMsgException { String sql = "update netdisk_document set isHome=? where id=?"; Conn conn = new Conn(connname); PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(sql); pstmt.setInt(1, isHome ? 1 : 0); pstmt.setInt(2, id); conn.executePreUpdate(); DocCacheMgr dcm = new DocCacheMgr(); dcm.refreshUpdate(id); } catch (SQLException e) { logger.error(e.getMessage()); throw new ErrMsgException("服务器内部错!"); } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public synchronized boolean increaseHit() throws ErrMsgException { hit ++; Conn conn = new Conn(connname); PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(SAVE_HIT); pstmt.setInt(1, hit); pstmt.setInt(2, id); conn.executePreUpdate(); DocCacheMgr dcm = new DocCacheMgr(); dcm.refreshUpdate(id); } catch (SQLException e) { logger.error(e.getMessage()); throw new ErrMsgException("服务器内部错!"); } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public synchronized boolean UpdateSummaryWithoutFile(ServletContext application, CMSMultiFileUploadBean mfu) throws ErrMsgException { Conn conn = new Conn(connname); boolean re = true; try { String idstr = StrUtil.getNullString(mfu.getFieldValue("id")); if (!StrUtil.isNumeric(idstr)) throw new ErrMsgException("标识id=" + idstr + "非法,必须为数字!"); id = Integer.parseInt(idstr); summary = StrUtil.getNullString(mfu.getFieldValue("htmlcode")); PreparedStatement pstmt = null; pstmt = conn.prepareStatement(SAVE_SUMMARY); pstmt.setString(1, summary); pstmt.setInt(2, id); re = conn.executePreUpdate()==1?true:false; DocCacheMgr dcm = new DocCacheMgr(); dcm.refreshUpdate(id); } catch (SQLException e) { re = false; logger.error(e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public synchronized boolean UpdateSummary(ServletContext application, CMSMultiFileUploadBean mfu) throws ErrMsgException { String isuploadfile = StrUtil.getNullString(mfu.getFieldValue( "isuploadfile")); if (isuploadfile.equals("false")) return UpdateSummaryWithoutFile(application, mfu); String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath")); String tempAttachFilePath = application.getRealPath("/") + FilePath + "/"; mfu.setSavePath(tempAttachFilePath); File f = new File(tempAttachFilePath); if (!f.isDirectory()) { f.mkdirs(); } boolean re = false; ResultSet rs = null; Conn conn = new Conn(connname); try { String sql = "select path from cms_images where mainkey=" + id + " and kind='netdisk_document' and subkey=" + 0 + ""; rs = conn.executeQuery(sql); if (rs != null) { String fpath = ""; while (rs.next()) { fpath = rs.getString(1); if (fpath != null) { File virtualFile = new File(Global.getRealPath() + fpath); virtualFile.delete(); } } } if (rs != null) { rs.close(); rs = null; } sql = "delete from cms_images where mainkey=" + id + " and kind='netdisk_document' and subkey=" + 0 + ""; conn.executeUpdate(sql); int ret = mfu.getRet(); if (ret == 1) { mfu.writeFile(false); Vector files = mfu.getFiles(); java.util.Enumeration e = files.elements(); String filepath = ""; sql = ""; while (e.hasMoreElements()) { FileInfo fi = (FileInfo) e.nextElement(); filepath = FilePath + "/" + fi.getName(); sql = "insert into cms_images (path,mainkey,kind,subkey) values (" + StrUtil.sqlstr(filepath) + "," + id + ",'netdisk_document'," + 0 + ")"; conn.executeUpdate(sql); } } else throw new ErrMsgException("上传失败!ret=" + ret); if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } re = UpdateSummaryWithoutFile(application, mfu); } catch (Exception e) { logger.error("UpdateSummary:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public synchronized boolean updateTemplateId() { String sql = "update netdisk_document set template_id=? where id=?"; Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setInt(1, templateId); pstmt.setInt(2, id); re = conn.executePreUpdate()==1?true:false; if (re) { DocCacheMgr dcm = new DocCacheMgr(); dcm.refreshUpdate(id); } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (conn!=null) { conn.close(); conn = null; } } return re; } public synchronized boolean Update(ServletContext application, CMSMultiFileUploadBean mfu) throws ErrMsgException { String isuploadfile = StrUtil.getNullString(mfu.getFieldValue( "isuploadfile")); if (isuploadfile.equals("false")) return UpdateWithoutFile(application, mfu); String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code")); author = StrUtil.getNullString(mfu.getFieldValue("author")); title = StrUtil.getNullString(mfu.getFieldValue("title")); String strIsHome = StrUtil.getNullString(mfu.getFieldValue("isHome")); if (strIsHome.equals("")) isHome = false; else if (strIsHome.equals("false")) isHome = false; else if (strIsHome.equals("true")) isHome = true; else isHome = false; String strexamine = mfu.getFieldValue("examine"); int oldexamine = examine; examine = Integer.parseInt(strexamine); keywords = StrUtil.getNullStr(mfu.getFieldValue("keywords")); String strisRelateShow = StrUtil.getNullStr(mfu.getFieldValue("isRelateShow")); int intisRelateShow = 0; if (StrUtil.isNumeric(strisRelateShow)) { intisRelateShow = Integer.parseInt(strisRelateShow); if (intisRelateShow==1) isRelateShow = true; } String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew")); if (StrUtil.isNumeric(strisnew)) isNew = Integer.parseInt(strisnew); else isNew = 0; String strCanComment = StrUtil.getNullStr(mfu.getFieldValue( "canComment")); if (strCanComment.equals("")) canComment = false; else if (strCanComment.equals("1")) canComment = true; flowTypeCode = StrUtil.getNullStr(mfu.getFieldValue("flowTypeCode")); Conn conn = new Conn(connname); ResultSet rs = null; PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(SAVE_DOCUMENT); pstmt.setString(1, title); pstmt.setInt(2, canComment ? 1 : 0); pstmt.setBoolean(3, isHome); pstmt.setInt(4, examine); pstmt.setString(5, keywords); pstmt.setInt(6, intisRelateShow); pstmt.setInt(7, templateId); pstmt.setString(8, dir_code); pstmt.setInt(9, isNew); pstmt.setString(10, author); pstmt.setString(11, flowTypeCode); pstmt.setInt(12, id); conn.executePreUpdate(); DocCacheMgr dcm = new DocCacheMgr(); if (oldexamine==examine) { dcm.refreshUpdate(id); } else { dcm.refreshUpdate(id, class1, parentCode); } if (!dir_code.equals(class1)) { dcm.refreshChangeDirCode(class1, dir_code); } DocContent dc = new DocContent(); dc = dc.getDocContent(id, 1); dc.save(application, mfu); } catch (SQLException e) { logger.error(e.getMessage()); throw new ErrMsgException("服务器内部错!"); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } return true; } public boolean create(String code_class1, String title, String content, int type, String voteoption, String voteresult, String nick, int templateId, String author) { Leaf lf = new Leaf(); lf = lf.getLeaf(code_class1); parentCode = lf.getParentCode(); Conn conn = new Conn(connname); this.id = (int) SequenceManager.nextID(SequenceManager.OA_DOCUMENT_NETDISK); try { PreparedStatement pstmt = conn.prepareStatement(INSERT_DOCUMENT); pstmt.setInt(1, id); pstmt.setString(2, title); pstmt.setString(3, code_class1); pstmt.setInt(4, type); pstmt.setString(5, voteoption); pstmt.setString(6, voteresult); pstmt.setString(7, nick); pstmt.setString(8, ""); pstmt.setInt(9, 1); pstmt.setInt(10, canComment?1:0); pstmt.setInt(11, templateId); pstmt.setString(12, parentCode); pstmt.setInt(13, examine); pstmt.setInt(14, isNew); pstmt.setString(15, author); pstmt.setString(16, flowTypeCode); conn.executePreUpdate(); DocContent dc = new DocContent(); dc.create(id, content); } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return true; } public String get(String field) { if (field.equals("title")) return getTitle(); else if (field.equals("content")) return getContent(1); else if (field.equals("summary")) return getSummary(); else if (field.equals("id")) return "" + getID(); else return ""; } public boolean del() throws ErrMsgException { DocContent dc = new DocContent(); dc.delDocContentOfDocument(id); Conn conn = new Conn(connname); try { PreparedStatement pstmt = conn.prepareStatement(DEL_DOCUMENT); pstmt.setInt(1, id); conn.executePreUpdate();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?