⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doccontent.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.oa.flow;import org.apache.log4j.Logger;import cn.js.fan.db.Conn;import java.sql.SQLException;import java.sql.PreparedStatement;import java.sql.ResultSet;import cn.js.fan.web.Global;import com.redmoon.kit.util.FileInfo;import cn.js.fan.util.ErrMsgException;import cn.js.fan.util.StrUtil;import java.io.File;import java.util.Iterator;import java.util.Vector;import javax.servlet.ServletContext;public class DocContent implements java.io.Serializable {    String content;    int docId;    int pageNum = 1;    String connname = "";    transient Logger logger = Logger.getLogger(DocContent.class.getName());    private static final String INSERT =            "INSERT into flow_doc_content (doc_id, content, page_num) VALUES (?,?,?)";    private static final String LOAD =            "SELECT content from flow_doc_content WHERE doc_id=? and page_num=?";    private static final String DEL =            "DELETE FROM flow_doc_content WHERE doc_id=? and page_num=?";    private static final String SAVE =            "UPDATE flow_doc_content SET content=? WHERE doc_id=? and page_num=?";    private static final String LOAD_DOCUMENT_ATTACHMENTS =            "SELECT id FROM flow_document_attach WHERE doc_id=? and page_num=? order by orders";    public DocContent() {        connname = Global.defaultDB;        if (connname.equals(""))            logger.info("DocContent:默认数据库名为空!");    }    public DocContent(int doc_id, int page_num) {        this.docId = doc_id;        this.pageNum = page_num;        connname = Global.defaultDB;        if (connname.equals(""))            logger.info("DocContent:默认数据库名为空!");        loadFromDb(doc_id, page_num);    }    public void renew() {        if (logger==null)            logger = Logger.getLogger(DocContent.class.getName());    }    public boolean createWithoutFile(ServletContext application,                                     CMSMultiFileUploadBean mfu, int doc_id,                                     String content, int pageNum) throws            ErrMsgException {        String FilePath = StrUtil.getNullString(mfu.getFieldValue("filepath"));                                String tempAttachFilePath = Global.getRealPath() + FilePath +                                    "/";        mfu.setSavePath(tempAttachFilePath);         File f = new File(tempAttachFilePath);        if (!f.isDirectory()) {            f.mkdirs();        }        this.docId = doc_id;        this.content = content;        this.pageNum = pageNum;        Conn conn = new Conn(connname);        boolean re = true;        try {                        int ret = mfu.getRet();            String sisDdxc = StrUtil.getNullString(mfu.getFieldValue("isDdxc"));                        if (sisDdxc.equals("true")) {                String[] attachFileNames = mfu.getFieldValues("attachFileName");                String[] clientFilePaths = mfu.getFieldValues("clientFilePath");                int len = 0;                if (attachFileNames != null)                    len = attachFileNames.length;                String sql = "";                int orders = 1;                for (int i = 0; i < len; i++) {                    String filepath = mfu.getSavePath() + attachFileNames[i];                    String name = mfu.getUploadFileName(clientFilePaths[i]);                    sql =                            "insert into flow_document_attach (fullpath,doc_id,name,diskname,visualpath,page_num,orders) values (" +                            StrUtil.sqlstr(filepath) + "," + docId + "," +                            StrUtil.sqlstr(name) + "," +                            StrUtil.sqlstr(attachFileNames[i]) + "," +                            StrUtil.sqlstr(FilePath) + "," + pageNum + "," + orders + ")";                    conn.executeUpdate(sql);                    orders ++;                }            } else {                if (ret == mfu.RET_SUCCESS) {                    String filepath = "";                    String sql = "";                                        mfu.writeAttachment(true);                     Vector attachs = mfu.getAttachments();                    Iterator ir = attachs.iterator();                    sql = "";                    while (ir.hasNext()) {                        FileInfo fi = (FileInfo) ir.next();                        filepath = mfu.getSavePath() + fi.getDiskName();                        sql =                                "insert into flow_document_attach (fullpath,doc_id,name,diskname,visualpath,page_num) values (" +                                StrUtil.sqlstr(filepath) + "," + docId + "," +                                StrUtil.sqlstr(fi.getName()) + "," +                                StrUtil.sqlstr(fi.getDiskName()) + "," +                                StrUtil.sqlstr(FilePath) + "," + pageNum + ")";                        conn.executeUpdate(sql);                    }                } else                    throw new ErrMsgException("上传失败!ret=" + ret);            }                        Document doc = new Document();            doc = doc.getDocument(docId);            PreparedStatement pstmt = null;                        if (pageNum <= doc.getPageCount() && pageNum != 1) {                                                String sql =                        "update flow_doc_content set page_num=page_num+1 where doc_id=? and page_num>=?";                pstmt = conn.prepareStatement(sql);                pstmt.setInt(1, docId);                pstmt.setInt(2, pageNum);                conn.executePreUpdate();                pstmt.close();                pstmt = null;                sql = "update flow_cms_images set subkey=subkey+1 where mainkey=? and subkey>=? and kind='document'";                pstmt = conn.prepareStatement(sql);                pstmt.setInt(1, docId);                pstmt.setInt(2, pageNum);                conn.executePreUpdate();                pstmt.close();                pstmt = null;                sql =                        "update flow_document_attach set page_num=page_num+1 where doc_id=? and page_num>=?";                pstmt = conn.prepareStatement(sql);                pstmt.setInt(1, docId);                pstmt.setInt(2, pageNum);                conn.executePreUpdate();                pstmt.close();                pstmt = null;            }                        DocContentCacheMgr dcm = new DocContentCacheMgr();            for (int i = pageNum; i < doc.getPageCount(); i++)                dcm.refreshUpdate(docId, pageNum);            pstmt = conn.prepareStatement(INSERT);            pstmt.setInt(1, doc_id);            pstmt.setString(2, content);            pstmt.setInt(3, pageNum);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                                dcm.refreshCreate(docId);            }                        if (pageNum != 1)                doc.UpdatePageCount(doc.getPageCount() + 1);        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public boolean create(int doc_id,                          String content) {        this.docId = doc_id;        this.content = content;        this.pageNum = 1;        Conn conn = new Conn(connname);        boolean re = false;        try {            PreparedStatement pstmt = conn.prepareStatement(INSERT);            pstmt.setInt(1, doc_id);            pstmt.setString(2, content);            pstmt.setInt(3, pageNum);            re = conn.executePreUpdate() == 1 ? true : false;            if (re) {                                DocContentCacheMgr dcm = new DocContentCacheMgr();                dcm.refreshCreate(docId);            }        } catch (SQLException e) {            logger.error(e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public String getContent() {        return content;    }    public void setContent(String content) {        this.content = content;    }    public DocContent getDocContent(int doc_id, int page_num) {        DocContentCacheMgr dccm = new DocContentCacheMgr();        return dccm.getDocContent(doc_id, page_num);    }    public void loadFromDb(int doc_id, int page_num) {        Conn conn = new Conn(connname);        ResultSet rs = null;        PreparedStatement pstmt = null;        try {            pstmt = conn.prepareStatement(LOAD);            this.docId = doc_id;            this.pageNum = page_num;            pstmt.setInt(1, doc_id);            pstmt.setInt(2, page_num);            rs = conn.executePreQuery();            if (rs != null) {                if (rs.next()) {                    content = rs.getString(1);                }            }            if (pstmt != null) {                pstmt.close();                pstmt = null;            }                        attachments = new Vector();            pstmt = conn.prepareStatement(LOAD_DOCUMENT_ATTACHMENTS);                        pstmt.setInt(1, docId);            pstmt.setInt(2, pageNum);            rs = conn.executePreQuery();            if (rs != null) {                while (rs.next()) {                    int aid = rs.getInt(1);                                        Attachment am = new Attachment(aid);                    attachments.addElement(am);                                    }            }        } catch (Exception e) {            logger.error("loadFromDb: " + e.getMessage());        } finally {                        if (conn != null) {                conn.close();                conn = null;            }        }    }    public boolean del() throws ErrMsgException {        Conn conn = new Conn(connname);        boolean re = false;        ResultSet rs = null;        try {                        String sql = "select path from flow_cms_images where mainkey=" + docId +                         " and kind='document' and subkey=" + pageNum;            rs = conn.executeQuery(sql);            if (rs != null) {                String fpath = "";                while (rs.next()) {                    fpath = rs.getString(1);                    if (fpath != null) {                        File virtualFile = new File(fpath);                        virtualFile.delete();                    }                }            }            if (rs != null) {                rs.close();                rs = null;            }                        sql = "delete from flow_cms_images where mainkey=" + docId +                  " and kind='document' and subkey=" + pageNum;            conn.executeUpdate(sql);                        sql = "select fullpath from flow_document_attach where doc_id=" + docId +                  " and page_num=" + pageNum;            rs = conn.executeQuery(sql);            if (rs != null) {                String fpath = "";                while (rs.next()) {                    fpath = rs.getString(1);                    if (fpath != null) {                        File virtualFile = new File(fpath);                        virtualFile.delete();                    }                }            }            if (rs != null) {                rs.close();                rs = null;            }                        sql = "delete from flow_document_attach where doc_id=" + docId +                  " and page_num=" + pageNum;            conn.executeUpdate(sql);                        PreparedStatement pstmt = conn.prepareStatement(DEL);            pstmt.setInt(1, docId);            pstmt.setInt(2, pageNum);            re = conn.executePreUpdate() == 1 ? true : false;            pstmt.close();            pstmt = null;                        Document doc = new Document();            doc = doc.getDocument(docId);            if (pageNum != doc.getPageCount()) {                                sql =                        "update flow_doc_content set page_num=page_num-1 where doc_id=? and page_num>?";                pstmt = conn.prepareStatement(sql);                pstmt.setInt(1, docId);                pstmt.setInt(2, pageNum);                conn.executePreUpdate();                pstmt.close();                pstmt = null;                sql = "update flow_cms_images set subkey=subkey-1 where mainkey=? and subkey>? and kind='document'";                pstmt = conn.prepareStatement(sql);                pstmt.setInt(1, docId);                pstmt.setInt(2, pageNum);                conn.executePreUpdate();                pstmt.close();                pstmt = null;                sql =                        "update flow_document_attach set page_num=page_num-1 where doc_id=? and page_num>?";                pstmt = conn.prepareStatement(sql);                pstmt.setInt(1, docId);                pstmt.setInt(2, pageNum);                conn.executePreUpdate();                pstmt.close();                pstmt = null;            }                        if (doc.getPageCount() > 1)                doc.UpdatePageCount(doc.getPageCount() - 1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -