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

📄 msgdb.java~171~

📁 云网论坛CWBBS 源码,内容丰富,学习,参考,教学的好资料,具体见内说明,
💻 JAVA~171~
📖 第 1 页 / 共 5 页
字号:
        if (rootid == -1) { // 当被回复贴为根帖时
            rootid = replyid;
            isroot = true;
        } else
            recount = 0;

        replyRootName = msgDd.getName();
        blog = msgDd.isBlog();

        parentorders = msgDd.getOrders();
        parentreplyid = msgDd.getReplyid();
        islocked = msgDd.getIsLocked();
        if (islocked == 1)
            throw new ErrMsgException(LoadString(request, "err_locked")); // "该贴已被锁定!");

        ResultSet rs = null;
        String sql = "";

        boolean isvalid = true;
        if (!isroot) { // 如果被回贴不是根贴则从根贴中取出回复数
            MsgDb rootmsg = getMsgDb(rootid);
            recount = rootmsg.getRecount();
            islocked = rootmsg.getIsLocked();
            replyRootName = rootmsg.getName();
            blog = rootmsg.isBlog();
        }

        int intIsBlog = blog?1:0;

        Conn conn = new Conn(connname);

        boolean updateorders = true;
        if (isroot && recount == 0)
            orders = parentorders + 1; // 如果是根贴且尚未有回贴,则orders=parentorders=1;
        else {
            if (parentreplyid == -1) { // 父结点为根贴
                orders = recount + 2;
                updateorders = false;
            } else {
                // 取出被回贴的下一个兄弟结点或当无兄弟结点时取最靠近的layer较小的结点的orders
                sql = "select min(orders) from sq_message where orders>" +
                      parentorders +
                      " and msg_layer<=" + parentlayer;
                try {
                    rs = conn.executeQuery(sql);
                    if (rs != null && rs.next())
                        orders = rs.getInt(1); // 如果orders=0,则表示未搜索到符合条件的贴子,回贴是位于最后的一个节点
                } catch (SQLException e) {
                    isvalid = false;
                    Logger.getLogger(MsgDb.class.getName()).error("AddReply SQLexception: " + e.getMessage());
                    throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.ERR_DB));
                } finally {
                    try {
                        if (rs != null)
                            rs.close();
                    } catch (Exception e) {}
                    if (!isvalid && conn != null) {
                        conn.close();
                        conn = null;
                    }
                }
                if (orders == 0) {
                    updateorders = false;
                    orders = recount + 2;
                }
            }
        }

        recount++;

        id = SequenceMgr.nextID();

        String virtualpath = "";

        FileInfo fi = null;
        Vector v = fu.getFiles();
        int size = v.size();
        String[] fileNameAry = null;
        if (size > 0) {
            fi = (FileInfo) v.get(0);
            // 为每个附件生成文件名
            fileNameAry = new String[size];
            for (int i=0; i<size; i++) {
                fileNameAry[i] = FileUpload.getRandName() + "." + ((FileInfo)v.get(i)).getExt();
            }
        }

        int msgType = TYPE_MSG;

        if (ret == FileUpload.RET_SUCCESS && fi!=null) {
            extName = fi.getExt();
            Calendar cal = Calendar.getInstance();
            String year = "" + (cal.get(cal.YEAR));
            String month = "" + (cal.get(cal.MONTH) + 1);
            String filepath = Global.getRealPath() + "forum/upfile/" +
                              year + "/" + month + "/";
            File f = new File(filepath);
            if (!f.isDirectory()) {
                f.mkdirs();
            }
            virtualpath = "upfile/" + year + "/" + month;
            fu.setSavePath(filepath); // 设置保存的目录

            picturename = fileNameAry[0];
            picturename = virtualpath + "/" + picturename;

            Iterator ir = v.iterator();
            int k = 0;
            while (ir.hasNext()) {
                fi = (FileInfo) ir.next();
                extName = fi.getExt();
                String ubbtype = "";
                if (extName.equalsIgnoreCase("gif") ||
                    extName.equalsIgnoreCase("jpg") ||
                    extName.equalsIgnoreCase("png") || extName.equalsIgnoreCase("bmp"))
                    ubbtype = "img";
                else if (extName.equalsIgnoreCase("swf"))
                    ubbtype = "flash";
                else
                    ubbtype = "URL";

                if (isWebedit >= WEBEDIT_REDMOON) {
                    if (ubbtype.equals("img"))
                        content = "<BR><a onfocus=this.blur() href=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" target=_blank><IMG SRC=\"" + rootpath + "/forum/" + virtualpath + "/" + fileNameAry[k] + "\" border=0 alt=" + SkinUtil.LoadString(request, "res.cn.js.fan.util.StrUtil", "click_open_win") + " onmousewheel='return zoomimg(this)' onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></a><BR>" + content;

                    else if (ubbtype.equals("flash"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" +
                                  ubbtype + "]\n" + content;
                } else {
                    if (ubbtype.equals("img"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" + ubbtype + "]\n" +
                                  content;
                    else if (ubbtype.equals("flash"))
                        content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
                                  virtualpath + "/" +
                                  fileNameAry[k] + "[/" +
                                  ubbtype + "]\n" + content;
                }
                k++;
            }
        }

        boolean re = false;
        try {
            conn.beginTrans();
            sql = "Update sq_message set replier=?,redate=?,recount=? where id=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, name);
            ps.setString(2, "" + System.currentTimeMillis());
            ps.setInt(3, recount);
            ps.setLong(4, rootid);
            conn.executePreUpdate();
            if (ps!=null) {
                ps.close();
                ps = null;
            }
            sql = "Update sq_thread set redate=? where id=?";
            ps = conn.prepareStatement(sql);
            ps.setString(1, "" + System.currentTimeMillis());
            ps.setLong(2, rootid);
            conn.executePreUpdate();
            if (ps!=null) {
                ps.close();
                ps = null;
            }

            if (updateorders) {
                sql = "select id from sq_message where rootid=" + rootid + " and orders>=" + orders;
                rs = conn.executeQuery(sql);
                if (rs!=null) {
                    while (rs.next()) {
                        MsgDb md = getMsgDb(rs.getInt(1));
                        try {
                            md.setOrders(md.getOrders() + 1);
                        }
                        catch (ResKeyException e) {
                            throw new ErrMsgException(e.getMessage(request));
                        }
                    }
                    rs.close();
                    rs = null;
                }
            }

            sql = "insert into sq_message (id,rootid,boardcode,name,title,content,length,expression,lydate,ip,filename,extname,MSG_TYPE,voteoption,voteresult,show_ubbcode,show_smile,iswebedit,orders,msg_layer,isBlog,blogUserDir,email_notify,replyid,replyRootName,pluginCode) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            ps = conn.prepareStatement(sql);
            ps.setLong(1, id);
            ps.setLong(2, rootid);
            ps.setString(3, boardcode);
            ps.setString(4, name);
            ps.setString(5, title);
            ps.setString(6, content);
            ps.setInt(7, length);
            ps.setInt(8, expression);
            ps.setString(9, "" + System.currentTimeMillis());
            ps.setString(10, ip);
            ps.setString(11, picturename);
            ps.setString(12, extName);
            ps.setInt(13, msgType);
            ps.setString(14, "");
            ps.setString(15, "");
            ps.setInt(16, show_ubbcode);
            ps.setInt(17, show_smile);
            ps.setInt(18, isWebedit);
            ps.setInt(19, orders);
            ps.setInt(20, layer);
            ps.setInt(21, intIsBlog);
            ps.setString(22, blogUserDir);
            ps.setInt(23, email_notify);
            ps.setLong(24, replyid);
            ps.setString(25, replyRootName);
            ps.setString(26, pluginCode);

            conn.executePreUpdate();

            // 保存上传的附件
            if (ret == FileUpload.RET_SUCCESS) {
                // fi.write(TheBean.getSavePath(), picturename);
                Iterator ir = v.iterator();
                // 将附件保存至数据库
                orders = 1;
                int i = 0;
                while (ir.hasNext()) {
                    fi = (FileInfo) ir.next();
                    fi.write(fu.getSavePath(), fileNameAry[i]);
                    String fpath = fu.getSavePath() + fi.getDiskName();
                    long attachId = SequenceMgr.nextID(SequenceMgr.SQ_MESSAGE_ATTACH);

                    sql =
                            "insert into sq_message_attach (id, fullpath,msgId,name,diskname,visualpath,orders,UPLOAD_DATE,FILE_SIZE,USER_NAME) values (" +
                            attachId + "," +
                            StrUtil.sqlstr(fpath) + "," + id + "," +
                            StrUtil.sqlstr(fi.getName()) + "," +
                            StrUtil.sqlstr(fi.getDiskName()) + "," +
                            StrUtil.sqlstr(virtualpath) +
                            "," +
                            orders +
                            "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + fi.getSize() + "," + StrUtil.sqlstr(name) + ")";
                    conn.executeUpdate(sql);
                    orders++;
                    i++;
                }

                // 加分
                if (i>0) {
                    ScoreMgr sm = new ScoreMgr();
                    Vector vatt = sm.getAllScore();
                    Iterator iratt = vatt.iterator();
                    while (iratt.hasNext()) {
                        ScoreUnit su = (ScoreUnit) iratt.next();
                        IPluginScore ips = su.getScore();
                        if (ips != null)
                            ips.onAddAttachment(name, i);
                    }
                }

                UserPrivDb upd = new UserPrivDb();
                upd = upd.getUserPrivDb(name);
                upd.addAttachTodayUploadCount(i);
            }

            conn.commit();

            re = true;

            // 将msgId与上传的临时图片文件相关联
            String[] tmpAttachIds = fu.getFieldValues("tmpAttachId");
            if (tmpAttachIds!=null) {
                int len = tmpAttachIds.length;
                for (int k=0; k<len; k++) {
                    Attachment att = new Attachment(Long.parseLong(tmpAttachIds[k]));
                    att.setMsgId(id);
                    att.save();
                }
            }

            // 更改根贴所对应用户博客的文章统计信息
            if (blog) {
                try {
                    UserConfigDb ucd = new UserConfigDb();
                    ucd = ucd.getUserConfigDb(getMsgDb(rootid).getName());
                    ucd.setReplyCount(ucd.getReplyCount() + 1);
                    ucd.save();
                } catch (ResKeyException e) {
                    Logger.getLogger(MsgDb.class.getName()).info("AddReply: ResKeyException " +
                                e.getMessage());
                }
            }
            // 更改版面最新发贴信息
            setBoardNewAddId(id);
            // 更改版面统计信息
            setBoardStatistic(false);

        } catch (SQLException e) {
            conn.rollback();
            Logger.getLogger(MsgDb.class.getName()).error("AddReply:" + e.getMessage());
        } finally {
       

⌨️ 快捷键说明

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