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

📄 messagedb.java

📁 oa 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.oa.message;import java.sql.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.kit.util.*;import com.redmoon.kit.util.FileInfo;import com.redmoon.oa.db.*;import com.redmoon.oa.person.*;import com.redmoon.oa.ui.IDesktopUnit;import com.redmoon.oa.ui.DesktopMgr;import com.redmoon.oa.ui.DesktopUnit;import cn.js.fan.util.file.FileUtil;import cn.js.fan.web.Global;public class MessageDb extends ObjectDb implements IMessage, IDesktopUnit {    int id;    private FileUpload fileUpload;    public String title, content, receiver, sender, ip, rq;    public int type = 0;    boolean readed = false;    public static final String SENDER_SYSTEM = "系统";    public static final int TYPE_SYSTEM = 10;    public MessageDb() {        init();    }    public MessageDb(int id) {        this.id = id;        init();        load();    }    public int getNewMsgCount(String receiver) {        MessageCache mc = new MessageCache(this);        return mc.getNewMsgCount(receiver);    }    public String getPageList(HttpServletRequest request, UserDesktopSetupDb uds) {        DesktopMgr dm = new DesktopMgr();        DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode());        String url = du.getPageList();        return url;    }    public String display(HttpServletRequest request, UserDesktopSetupDb uds) {        com.redmoon.oa.pvg.Privilege privilege = new com.redmoon.oa.pvg.                                                 Privilege();                DesktopMgr dm = new DesktopMgr();        DesktopUnit du = dm.getDesktopUnit(uds.getModuleCode());        String url = du.getPageShow();        String str = "";        int count = uds.getCount();        String sql = "select id from oa_message where receiver=" +                     StrUtil.sqlstr(privilege.getUser(request)) +                     " and isDraft=0 order by isreaded asc,rq desc";        str += "<ul>";        String sender = "", rq = "";        boolean isreaded = true;        Iterator msgir = list(sql, 0, count-1).iterator();        while (msgir.hasNext()) {            MessageDb md = (MessageDb) msgir.next();            id = md.getId();            title = md.getTitle();            receiver = md.getReceiver();            rq = md.getRq();            type = md.getType();            isreaded = md.isReaded();            str += "<li><a href='" + url + "?id=" + md.getId() + "'>";            if (isreaded) {                str += title;            } else {                str += "<b>" + title + "</b>";            }                        str += "  [" + rq + "]";            str += "</a></li>";        }        str += "</ul>";        return str;    }        public void clearMsgOfUser(String userName) {        String sql = "select id from oa_message where receiver=" +                     StrUtil.sqlstr(userName) +                     " and isDraft=0 order by isreaded asc,rq desc";        int total = getObjectCount(sql);        UserSetupDb usd = new UserSetupDb();        usd = usd.getUserSetupDb(userName);        if (total>usd.getMessageUserMaxCount()) {            int count = total - usd.getMessageUserMaxCount();            sql = "select id from oa_message where receiver=" +                     StrUtil.sqlstr(userName) +                     " and isDraft=0 order by rq asc";            Iterator ir = list(sql, 0, count-1).iterator();            while (ir.hasNext()) {                MessageDb md = (MessageDb)ir.next();                md.del();            }        }    }    public boolean AddMsg(ServletContext application, HttpServletRequest request,                          String sender) throws            ErrMsgException {        MessageForm mf = new MessageForm(application, request, this);        mf.checkCreate();        this.fileUpload = mf.getFileUpload();        this.sender = sender;        String[] ary = receiver.split(",");        logger.info("create:toUser=" + receiver);        int len = ary.length;        for (int i=0; i<len; i++) {            create(ary[i], mf.fileUpload);        }        return true;    }    public String getSenderRealName() {        String realName = sender;        if (!sender.equals(MessageDb.SENDER_SYSTEM)) {            com.redmoon.oa.person.UserDb ud = new com.redmoon.oa.person.                                              UserDb();            ud = ud.getUserDb(sender);            if (ud != null && ud.isLoaded()) {                realName = ud.getRealName();            }        }        return realName;    }    public boolean delMsg(String[] ids) throws ErrMsgException {        int len = ids.length;        String str = "";        for (int i = 0; i < len; i++)            if (str.equals(""))                str += ids[i];            else                str += "," + ids[i];        str = "(" + str + ")";        String sql = "select id from oa_message where id in " + str;        Conn conn = null;        try {            conn = new Conn(connname);            ResultSet rs = conn.executeQuery(sql);            if (rs!=null) {                while (rs.next()) {                    getMessageDb(rs.getInt(1)).del();                }            }        } catch (Exception e) {            logger.error("delMsg:" + e.getMessage());            throw new ErrMsgException("删除消息失败!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return true;    }    public boolean isReaded() {        return readed;    }    public IMessage getMessageDb(int id) {        return (IMessage)getObjectDb(new Integer(id));    }    public String getTitle() {        return title;    }    public String getContent() {        return content;    }    public String getRq() {        return rq;    }    public String getSender() {        return sender;    }    public String getReceiver() {        return receiver;    }    public String getIp() {        return ip;    }    public int getType() {        return type;    }    public int getId() {        return id;    }    public Vector getAttachments() {        return attachments;    }    public boolean isDraft() {        return draft;    }    public FileUpload getFileUpload() {        return fileUpload;    }    public boolean create(String toUser, FileUpload fu) throws ErrMsgException {        Conn conn = null;        boolean re = false;        logger.info("create:toUser=" + toUser);        try {            conn = new Conn(connname);            PreparedStatement ps = conn.prepareStatement(QUERY_CREATE);            id = (int) SequenceManager.nextID(SequenceManager.OA_MESSAGE);            ps.setInt(1, id);            ps.setString(2, title);            ps.setString(3, content);            ps.setString(4, sender);            ps.setString(5, toUser);            ps.setInt(6, type);            ps.setString(7, ip);            java.util.Date curDate = new java.util.Date();            ps.setTimestamp(8, new Timestamp(curDate.getTime()));            ps.setInt(9, draft?1:0);            re = conn.executePreUpdate() == 1 ? true : false;            MessageCache mc = new MessageCache(this);            mc.refreshNewCountOfReceiver(receiver);            mc.refreshCreate();            if (re) {                if (fu.getRet() == fu.RET_SUCCESS) {                                        Calendar cal = Calendar.getInstance();                    String year = "" + (cal.get(cal.YEAR));                    String month = "" + (cal.get(cal.MONTH) + 1);                    com.redmoon.oa.Config cfg = new com.redmoon.oa.Config();                    String vpath = cfg.get("file_message") + "/" + year + "/" + month + "/";                    String filepath = fu.getRealPath() + vpath;                    fu.setSavePath(filepath);                                        fu.writeFile(true);                    Vector v = fu.getFiles();                    FileInfo fi = null;                    Iterator ir = v.iterator();                    while (ir.hasNext()) {                        fi = (FileInfo) ir.next();                        Attachment att = new Attachment();                        att.setFullPath(filepath + fi.getDiskName());                        att.setMsgId(id);                        att.setName(fi.getName());                        att.setDiskName(fi.getDiskName());                        att.setVisualPath(vpath);                        re = att.create();                    }                }            }        } catch (Exception e) {            logger.error("create: " + e.getMessage());            throw new ErrMsgException("数据库操作错误!");        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }        return re;    }    public boolean sendSysMsg(String receiver, String title, String content) throws ErrMsgException {        Conn conn = null;        boolean re = false;        try {            conn = new Conn(connname);            PreparedStatement ps = conn.prepareStatement(QUERY_CREATE);            id = (int) SequenceManager.nextID(SequenceManager.OA_MESSAGE);            ps.setInt(1, id);            ps.setString(2, title);            ps.setString(3, content);            ps.setString(4, SENDER_SYSTEM);            ps.setString(5, receiver);            ps.setInt(6, TYPE_SYSTEM);            ps.setString(7, "");            java.util.Date curDate = new java.util.Date();            ps.setTimestamp(8, new Timestamp(curDate.getTime()));            ps.setInt(9, 0);            re = conn.executePreUpdate() == 1 ? true : false;            MessageCache mc = new MessageCache(this);

⌨️ 快捷键说明

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