📄 msgdb.java
字号:
String ubbtype = "";
if (ret == FileUpload.RET_SUCCESS) {
boolean isDdxc = false;
String sisDdxc = StrUtil.getNullString(mfu.getFieldValue("isDdxc"));
// 断点续传
if (sisDdxc.equals("true"))
isDdxc = true;
String filepath = StrUtil.getNullString(mfu.getFieldValue(
"filepath"));
picturename = "";
FileInfo fInfo = mfu.getUpFileInfo();
String virtualpath = "";
if (fInfo!=null) {
// 考虑到webedit控件的断点续传功能,这里上传后的路径还是应该使用附件的路径较好
// 但是附件如果以后用网络硬盘管理以后,可能会带来问题
// 因为表单中filename文件的大小不应被计入用户的磁盘空间,而断点续传后,会被计入么?
// 解决如下:单线程时计算磁盘空间的问题可以通过FileInfo中的size得以解决
// 多线程断点上传时计算空间可以通过控件发送文件大小数组来加以解决
// 另外,在MultiFileUpload中分离时要考到两种情况
// -------------------------------------------------------------
// 考虑到控件上传的附件以后要放在专门的路径中,以便于过滤,保护用户的网络硬盘文件
// 为提高并发性,如果每次存取filename中的文件都要被过滤,则不利于文件的快速存取
// 而断点上传时附件的路径是在控件中就指定了名称的,而且是滞后于其它域的信息保存的
// 无法另外给定其名称,所以一定是存放于附件指定的路径,因而此处放弃对其的处理
// 这里要注意的是需要对用到filename的应用加以处理,使其不能使用WEBEDIT_REDMOON方式发布
// 比如:拍卖。
// -------------------------------------------------------------
// 再三考虑后还是决定高级发贴方式支持filename,否则在博客中使用高级发贴方式时,因为不支持filename而使得一些加挂插件的版块不允许,这样会使得整个应用管理起来比较复杂
extName = fInfo.getExt();
if (!isDdxc) {
picturename = FileUpload.getRandName() + "." + extName;
virtualpath = FilePath;
}
else {
picturename = fInfo.getDiskName();
virtualpath = FilePath;
}
if (extName.equalsIgnoreCase("gif") ||
extName.equalsIgnoreCase("jpg") || extName.equalsIgnoreCase("bmp") || extName.equalsIgnoreCase("png"))
ubbtype = "img";
else if (extName.equalsIgnoreCase("swf"))
ubbtype = "flash";
else
ubbtype = "URL";
if (ubbtype.equals("img"))
content = "<BR><img src='" + rootpath + "/forum/" +
virtualpath + "/" +
picturename + "'><BR>" + content;
else if (ubbtype.equals("flash"))
content = "\n[" + ubbtype + "]" + rootpath + "/forum/" +
virtualpath + "/" +
picturename + "[/" +
ubbtype + "]\n" + content;
}
// 2006.1.31 application.getRealPath("/")取得的d:\zjrj在插入mysql后,\不见了,变成了d:zjrj
// 解决方法:改用Global.getRealPath
// String tempAttachFilePath = application.getRealPath("/") + filepath +
// "/";
String tempAttachFilePath = Global.getRealPath() + "forum/" + filepath +
"/";
mfu.setSavePath(tempAttachFilePath); // 取得目录
File f = new File(tempAttachFilePath);
if (!f.isDirectory()) {
f.mkdirs();
}
boolean issuccess = true;
Conn conn = new Conn(connname);
boolean re = false;
try {
conn.beginTrans();
// 插入thread,thread仅用来排序、索引、列表,所以无需缓存
String insertThreadSql = "insert into sq_thread (id,boardcode,msg_level,iselite,lydate,redate,name,blogUserDir,isBlog,check_status,thread_type) values (?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = conn.prepareStatement(insertThreadSql);
ps.setLong(1, id);
ps.setString(2, boardcode);
ps.setInt(3, level);
ps.setInt(4, isElite);
ps.setString(5, "" + System.currentTimeMillis());
ps.setString(6, "" + System.currentTimeMillis());
ps.setString(7, name);
ps.setString(8, blogUserDir);
ps.setInt(9, blog?1:0);
ps.setInt(10, checkStatus);
ps.setInt(11, threadType);
conn.executePreUpdate();
if (ps!=null) {
ps.close();
ps = null;
}
sql = "insert into sq_message (id,rootid,boardcode,name,title,content,length,expression,lydate,ip,filename,extname,MSG_TYPE,show_ubbcode,show_smile,iswebedit,redate,colorExpire,boldExpire,isBlog,blogUserDir,plugin2Code,email_notify,thread_type,pluginCode,check_status,replyid) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,-1)";
ps = conn.prepareStatement(sql);
ps.setLong(1, id);
ps.setLong(2, id);
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, virtualpath + "/" + picturename);
ps.setString(12, extName);
ps.setInt(13, msgType);
ps.setInt(14, show_ubbcode);
ps.setInt(15, show_smile);
ps.setInt(16, isWebedit);
ps.setString(17, "" + System.currentTimeMillis());
ps.setString(18, "" + System.currentTimeMillis());
ps.setString(19, "" + System.currentTimeMillis());
ps.setInt(20, intIsBlog);
ps.setString(21, blogUserDir);
ps.setString(22, plugin2Code);
ps.setInt(23, email_notify);
ps.setInt(24, threadType);
ps.setString(25, pluginCode);
ps.setInt(26, checkStatus);
re = conn.executePreUpdate()==1?true:false;
conn.commit();
if (voptions != null) {
MsgPollDb mpd = new MsgPollDb();
String epdate = StrUtil.getNullString(mfu.getFieldValue(
"expire_date"));
java.util.Date expireDate = DateUtil.parse(epdate, "yyyy-MM-dd");
String strMaxChoices = StrUtil.getNullString(mfu.
getFieldValue("max_choice"));
int maxChoices = StrUtil.toInt(strMaxChoices, 1);
// 创建投票项
mpd.create(new JdbcTemplate(), new Object[] {
new Long(id), expireDate, new Integer(maxChoices)
});
int vlen = voptions.length;
// 创建投票选项
MsgPollOptionDb mpod = new MsgPollOptionDb();
for (int i = 0; i < vlen; i++) {
mpod.create(new JdbcTemplate(), new Object[] {
new Long(id), new Integer(i), voptions[i]
});
}
}
if (re) {
// 保存frmAnnounce中filename上传的文件
if (fInfo != null)
if (!isDdxc) {
fInfo.write(Global.getRealPath() + "forum/" +
virtualpath + "/", picturename);
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(mfu.getSavePath() + fInfo.getDiskName()) +
"," + id + "," +
StrUtil.sqlstr(fInfo.getName()) + "," +
StrUtil.sqlstr(fInfo.getDiskName()) + "," +
StrUtil.sqlstr(FilePath) + ",1," +
StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + fInfo.getSize() + "," + StrUtil.sqlstr(name) + ")";
conn.executeUpdate(sql);
UserPrivDb upd = new UserPrivDb();
upd = upd.getUserPrivDb(name);
upd.addAttachTodayUploadCount(1);
// 加分
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, 1);
}
}
}
// 更改用户发贴数 经验值 信用值
UserDb user = new UserDb();
user = user.getUser(name);
user.setAddCount(user.getAddCount() + 1);
user.save();
// 更改用户博客的文章统计信息
if (blog) {
UserConfigDb ucd = new UserConfigDb();
ucd = ucd.getUserConfigDb(name);
ucd.setMsgCount(ucd.getMsgCount() + 1);
ucd.save();
}
// 更改版面最新发贴信息
if (checkStatus==CHECK_STATUS_PASS) {
setBoardNewAddId(id);
// 更改版面统计信息
setBoardStatistic(true);
}
} catch (SQLException e) {
conn.rollback();
Logger.getLogger(MsgDb.class.getName()).error("AddNewWE: " + e.getMessage());
issuccess = false;
throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.ERR_DB));
}
catch (ResKeyException e) {
issuccess = false;
Logger.getLogger(MsgDb.class.getName()).error("AddNewWE: " + e.getMessage(request));
throw new ErrMsgException(e.getMessage(request));
}
finally {
if (re) {
// 更新缓存
MsgCache mc = new MsgCache();
mc.refreshAdd(boardcode, name, blog, blogUserDir);
}
if (!issuccess && conn != null) {
conn.close();
conn = null;
}
}
sql = "";
int orders = 1;
try {
mfu.writeFile(false); // 用文件本来的名称命名文件
// 将HTMLCODE中的文件保存至数据库
Vector files = mfu.getFiles();
java.util.Enumeration e = files.elements();
while (e.hasMoreElements()) {
FileInfo fi = (FileInfo) e.nextElement();
filepath = FilePath + "/" + fi.getName();
long imgId = SequenceMgr.nextID(SequenceMgr.SQ_IMAGES);
// System.out.println("filepath=" + filepath);
conn.executeUpdate(
"insert into sq_images (id,path,otherid,kind) values (" +
imgId + "," +
StrUtil.sqlstr(filepath) + "," + id +
",'sq_message')");
}
// 断点续传
if (isDdxc) {
String[] attachFileNames = mfu.getFieldValues(
"attachFileName");
String[] clientFilePaths = mfu.getFieldValues(
"clientFilePath");
int len = 0;
if (attachFileNames != null)
len = attachFileNames.length;
int filenameIndex = -1;
String attachFileName = StrUtil.getNullString(mfu.getFieldValue("filename"));
if (!attachFileName.equals("")) {
String strIndex = attachFileName.substring("attachment".
length(), attachFileName.length());
if (StrUtil.isNumeric(strIndex))
filenameIndex = Integer.parseInt(strIndex);
}
// 将断点续传文件的相关信息保存至数据库
for (int i = 0; i < len; i++) {
// 跳过filename文件
if (filenameIndex==i)
continue;
String fpath = mfu.getSavePath() + attachFileNames[i];
String fname = mfu.getUploadFileName(clientFilePaths[i]);
long attachId = SequenceMgr.nextID(SequenceMgr.SQ_MESSAGE_ATTACH);
sql =
"insert into sq_message_attach (id,fullpath,msgId,name,diskname,visualpath,orders,UPLOAD_DATE,USER_NAME) values (" +
attachId + "," +
StrUtil.sqlstr(fpath) + "," + id + "," +
StrUtil.sqlstr(fname) + "," +
StrUtil.sqlstr(attachFileNames[i]) + "," +
StrUtil.sqlstr(FilePath) + "," + orders + "," + StrUtil.sqlstr("" + System.currentTimeMillis()) + "," + StrUtil.sqlstr(name) + ")";
conn.executeUpdate(sql);
orders++;
}
if (len > 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, len);
}
}
UserPrivDb upd = new UserPrivDb();
upd = upd.getUserPrivDb(name);
upd.addAttachTodayUploadCount(len);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -