document.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 1,120 行 · 第 1/3 页
JAVA
1,120 行
package com.redmoon.oa.netdisk;import java.io.File;import java.sql.*;import java.sql.Date;import java.util.Iterator;import java.util.Vector;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import cn.js.fan.base.ITagSupport;import cn.js.fan.db.Conn;import cn.js.fan.security.SecurityUtil;import cn.js.fan.util.ErrMsgException;import cn.js.fan.util.StrUtil;import cn.js.fan.web.Global;import com.redmoon.kit.util.FileInfo;import org.apache.log4j.Logger;import com.redmoon.oa.db.SequenceManager;public class Document implements java.io.Serializable, ITagSupport { public static final int NOTEMPLATE = -1; String connname = ""; int id = -1; String title; String content; String date; String class1; Date modifiedDate; String summary; boolean isHome = false; int examine = 0; public static final int EXAMINE_NOT = 0; public static final int EXAMINE_NOTPASS = 1; public static final int EXAMINE_PASS = 2; public static final int TYPE_DOC = 0; public static final int TYPE_VOTE = 1; transient Logger logger = Logger.getLogger(Document.class.getName()); private static final String INSERT_DOCUMENT = "INSERT into netdisk_document (id, title, class1, type, voteoption, voteresult, nick, keywords, isrelateshow, can_comment, hit, template_id, parent_code, examine, isNew, author, flowTypeCode, modifiedDate) VALUES (?,?,?,?,?,?,?,?,?,?,0,?,?,?,?,?,?,NOW())"; private static final String LOAD_DOCUMENT = "SELECT title, class1, modifiedDate, can_comment,summary,ishome,type,voteOption,voteResult,examine,nick,keywords,isrelateshow,hit,template_id,page_count,parent_code,isNew,author,flowTypeCode FROM netdisk_document WHERE id=?"; private static final String DEL_DOCUMENT = "delete FROM netdisk_document WHERE id=?"; private static final String SAVE_DOCUMENT = "UPDATE netdisk_document SET title=?, can_comment=?, ishome=?, modifiedDate=NOW(),examine=?,keywords=?,isrelateshow=?,template_id=?,class1=?,isNew=?,author=?,flowTypeCode=? WHERE id=?"; private static final String SAVE_SUMMARY = "UPDATE netdisk_document SET summary=? WHERE id=?"; private static final String SAVE_HIT = "UPDATE netdisk_document SET hit=? WHERE id=?"; public Document() { connname = Global.defaultDB; if (connname.equals("")) logger.info("Document:默认数据库名为空!"); } public Document(int id) { connname = Global.defaultDB; if (connname.equals("")) logger.info("Directory:默认数据库名为空!"); this.id = id; loadFromDB(); } public void renew() { if (logger==null) logger = Logger.getLogger(Document.class.getName()); } public int getIDOrCreateByCode(String code, String nick) { int myid = getFirstIDByCode(code); if (myid != -1) { this.id = myid; loadFromDB(); } else { title = ""; content = " "; Leaf leaf = new Leaf(); leaf = leaf.getLeaf(code); create(code, title, content, 0, "", "", nick, leaf.getTemplateId(), nick); this.id = getFirstIDByCode(code); leaf.setDocID(id); leaf.update(); } return id; } public void delDocumentByDirCode(String code) throws ErrMsgException { Vector v = getDocumentsByDirCode(code); Iterator ir = v.iterator(); while (ir.hasNext()) { Document doc = (Document) ir.next(); doc.del(); } } public Vector getDocumentsByDirCode(String code) { Vector v = new Vector(); String sql = "select id from netdisk_document where class1=" + StrUtil.sqlstr(code); logger.info("getDocumentsByDirCode:" + sql); Conn conn = new Conn(connname); ResultSet rs = null; try { rs = conn.executeQuery(sql); if (rs != null) { while (rs.next()) { v.addElement(getDocument(rs.getInt(1))); logger.info("getDocumentsByDirCode:" + getDocument(rs.getInt(1)).getID()); } } } catch (SQLException e) { logger.error("getDocumentsByDirCode:" + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} } if (conn != null) { conn.close(); conn = null; } } return v; } public Document getDocumentByDirCode(String dirCode) { Leaf leaf = new Leaf(); leaf = leaf.getLeaf(dirCode); if (leaf != null && leaf.isLoaded()) { int id = leaf.getDocID(); return getDocument(id); } else return null; } public boolean changeAttachmentToDir(Attachment att, String newDirCode) { Document doc = new Document(); doc = doc.getDocumentByDirCode(newDirCode); int newDocId = doc.getID(); att.setDocId(newDocId); boolean re = att.save(); DocContentCacheMgr dcm = new DocContentCacheMgr(); dcm.refreshUpdate(id, 1); dcm.refreshUpdate(newDocId, 1); return re; } public int getFirstIDByCode(String code) { String sql = "select id from netdisk_document where class1=" + StrUtil.sqlstr(code); Conn conn = new Conn(connname); ResultSet rs = null; try { rs = conn.executeQuery(sql); if (rs != null && rs.next()) { return rs.getInt(1); } } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} } if (conn != null) { conn.close(); conn = null; } } return -1; } public String getSummary() { return this.summary; } public int getID() { return id; } public void setID(int id) { this.id = id; } public String getTitle() { return title; } public boolean getIsHome() { return this.isHome; } public void setIsHome(boolean h) { this.isHome = h; } public void setType(int type) { this.type = type; } public void setVoteOption(String voteOption) { this.voteOption = voteOption; } public void setVoteResult(String voteResult) { this.voteResult = voteResult; } public String getContent(int pageNum) { DocContent dc = new DocContent(); dc = dc.getDocContent(id, pageNum); if (dc!=null) return dc.getContent(); else return null; } public Vector list(String sql, int count) { ResultSet rs = null; Vector result = new Vector(); Conn conn = new Conn(connname); try { rs = conn.executeQuery(sql); if (rs == null) { return result; } else { rs.setFetchSize(count); while (rs.next()) { int id = rs.getInt(1); Document doc = getDocument(id); result.addElement(doc); } } } catch (SQLException e) { logger.error("list: " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return result; } public String RenderContent(HttpServletRequest request, int pageNum) { DocContent dc = new DocContent(); dc = dc.getDocContent(id, pageNum); if (dc != null) { return dc.getContent(); } else return null; } public DocContent getDocContent(int pageNum) { DocContent dc = new DocContent(); return dc.getDocContent(id, pageNum); } public boolean isCanComment() { return canComment; } public String getDirCode() { return class1; } public synchronized boolean UpdateWithoutFile(ServletContext application,CMSMultiFileUploadBean mfu) throws ErrMsgException { String dir_code = StrUtil.getNullStr(mfu.getFieldValue("dir_code")); author = StrUtil.getNullString(mfu.getFieldValue("author")); title = StrUtil.getNullString(mfu.getFieldValue("title")); String strCanComment = StrUtil.getNullStr(mfu.getFieldValue( "canComment")); if (strCanComment.equals("")) canComment = false; else if (strCanComment.equals("1")) canComment = true; 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); String strisnew = StrUtil.getNullStr(mfu.getFieldValue("isNew")); if (StrUtil.isNumeric(strisnew)) isNew = Integer.parseInt(strisnew); else isNew = 0; 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; } flowTypeCode = StrUtil.getNullString(mfu.getFieldValue("flowTypeCode")); Conn conn = new Conn(connname); 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.saveWithoutFile(application, mfu); } catch (SQLException e) { logger.error(e.getMessage()); throw new ErrMsgException("服务器内部错!"); } finally {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?