📄 forumbiz.java
字号:
package com.yhbbs.forum.biz;
import java.sql.SQLException;
import java.util.List;
import org.apache.log4j.Logger;
import com.yhbbs.article.biz.ArticleBiz;
import com.yhbbs.forum.bean.ForumIm;
import com.yhbbs.forum.bean.ForumJumpIm;
import com.yhbbs.forum.dao.ForumDaoIm;
import com.yhbbs.forum.itface.Forum;
import com.yhbbs.forum.itface.ForumArtPost;
import com.yhbbs.forum.itface.ForumDao;
import com.yhbbs.forum.itface.ForumJump;
import com.yhbbs.user.biz.UserBiz;
/**
* <p>Title:论坛列表相关操作</p>
* <li> 论坛列表的相关操作
* <p>Company: www.yyhweb.com</p>
* <br><b>CopyRight: yyhweb[由由华网]</b>
* @author stephen
* @version YHBBS-2.0
*/
public class ForumBiz {
private static Logger bbslog = Logger.getLogger(ForumBiz.class);
private static ForumDao forumdao = ForumDaoIm.getInstance();
/** 取得论坛管理员
* @param forumId 论坛Id
* @return 论坛管理员
*/
public static String getForumAdmin(int forumId){
try {
return forumdao.getForumadmin(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke getForumadmin(forumId):\n" + e.toString());
}
return "";
}
/** 取得论坛管理员
* @param forumId 论坛Id
* @param userName 用户名称
* @return 论坛管理员
*/
public static boolean isForumAdmin(int forumId,String userName){
String admin = "";
try {
admin = getForumAdmin(forumId);
return admin.indexOf(userName)!=-1;
}catch(Exception e) {
bbslog.error("Throws a SqlException when invoke isForumAdmin(int forumId,String userName):\n" + e.toString());
}
return false;
}
/** 取得论坛名称
* @param forumId 论坛Id
* @return 论坛名称
*/
public static String getForumName(int forumId){
try {
return forumdao.getForumName(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke getForumName(forumId):\n" + e.toString());
}
return "";
}
/** 根据论坛Id区论坛Id
* @param forumId 论坛Id
* @return 区论坛Id
*/
public static int getForumClassId(int forumId){
try {
return forumdao.getForumClassId(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke getForumClassId(int forumId):\n" + e.toString());
}
return 0;
}
/** 取得论坛最新帖子Id
* @param forumId 论坛Id
* @return 论坛名称
*/
public static int getForumLArtId(int forumId){
try {
return forumdao.getForumLArtId(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke getForumName(forumId):\n" + e.toString());
}
return 0;
}
/** 更新论坛最新帖子标题
* <li>当更新帖子时如该帖为论坛最新帖子,则需要更新其标题
* @param forumId 论坛Id
* @param title 最新帖子的新标题
*/
public static void upForumLArtTitle(int forumId,String title){
ForumJump forum = new ForumJumpIm();
forum.setId(forumId);
forum.setFname(title);
try {
forumdao.upForumLArtTitle(forum);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke upForumLArtTitle(forum):\n" + e.toString());
}
return ;
}
/** 更新论坛今天和昨天的发贴统计
* @param forumId 论坛Id
*/
private static void upYesdayCount(int forumId){
try {
forumdao.upYesdayCount(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke upYesdayCount(forumId):\n" + e.toString());
}
return ;
}
/** 更新论坛今天和昨天的发贴统计
* @return 论坛Id列表
*/
private static List getAllForumId(){
try {
return forumdao.getAllForumId();
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke getAllForumId():\n" + e.toString());
}
return null;
}
/** 更新所有论坛今天和昨天的发贴统计
*/
public static void upAllFYesdayC(){
List curList = getAllForumId();
int fId = 0;
int i = 0;
for(i=0;i<curList.size();i++){
fId = Integer.parseInt(curList.get(i).toString());
upYesdayCount(fId);
}
}
/** 发表帖子后更新论坛最新统计信息
* @param fArtPost 待更新的论坛信息(最新帖子信息)
* @param flag true:主题贴 false:回复贴
*/
public static void forumPostArt(ForumArtPost fArtPost,boolean flag){
try {
forumdao.forumPostArt(fArtPost,flag);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke forumPostArt(fArtPost):\n" + e.toString());
}
return ;
}
/** 移动帖子后更新论坛最新统计信息
* @param fArtPost 待更新的论坛信息(最新帖子信息)
* @param istoday 判断移动过来的帖子是否是今日帖子 true:今日帖 false:非今日贴
*/
public static void forumMoveArt(ForumArtPost fArtPost,boolean istoday){
try {
forumdao.forumMoveArt(fArtPost,istoday);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke forumPostArt(fArtPost):\n" + e.toString());
}
return ;
}
/** 删除帖子后更新论坛最新统计信息
* @param fArtDel 待更新的论坛信息
* @param flag true:主题贴 false:回复贴
* @param istoday true:今日帖 false:非今日贴
*/
public static void forumDelArt(ForumArtPost fArtDel,boolean flag,boolean istoday){
try {
forumdao.forumDelArt(fArtDel,flag,istoday);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke forumDelArt(fArtDel,flag):\n" + e.toString());
}
return ;
}
/** 删除帖子后更新论坛最新统计信息(主要是数目统计)
* @param forumId 待更新的论坛Id
* @param flag true:主题贴 false:回复贴
* @param istoday true:今日帖 false:非今日贴
*/
public static void delArticle(int forumId,boolean flag,boolean istoday){
try {
forumdao.delArticle(forumId,flag,istoday);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke delArticle(forumId,flag):\n" + e.toString());
}
return ;
}
// 后台管理使用
/** 取得论坛
* @param forumId 论坛Id
* @return Forum 论坛
*/
public static Forum getForum(int forumId){
try {
return forumdao.getForumById(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke getForum(int forumId):\n" + e.toString());
}
return new ForumIm();
}
/** 增加论坛
* @param forum 新论坛
* @return true:成功 false:失败
*/
public static boolean addForum(Forum forum){
boolean flag = true;
try {
forum.setId(forumdao.getForumMaxId()+1);
forum.setFsort(forumdao.getForumMaxSort(forum.getClassid())+1);
forumdao.addForum(forum);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke addForum(Forum forum):\n" + e.toString());
flag = false;
}
return flag;
}
/** 修改论坛
* @param forum 已修改论坛
* @return true:成功 false:失败
*/
public static boolean editForum(Forum forum){
boolean flag = true;
try {
flag = forumdao.editForum(forum);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke addForum(Forum forum):\n" + e.toString());
flag = false;
}
return flag;
}
/** 删除论坛
* @param forumId 删除论坛Id
* @return true:成功 false:失败
*/
public static boolean deleteForum(int forumId){
boolean flag = true;
try {
flag = forumdao.deleteForum(forumId);
}
catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke deleteForum(int forumId):\n" + e.toString());
flag = false;
}
return flag;
}
/** 移动论坛,如果该论坛有帖子则移动其所属帖子
* @param forumId 论坛Id
* @param classId 目标区论坛Id
* @return true:成功 false:失败
*/
public static boolean moveForum(int forumId,int classId){
boolean flag = true;
try {
flag = forumdao.moveForum(forumId, classId);
if(flag){
int lastArtId = getForumLArtId(forumId);
if(lastArtId>0) // 有帖子
flag = ArticleBiz.moveForum(forumId, classId);
}else
flag = false;
}catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke moveForum(int forumId,int classId):\n" + e.toString());
flag = false;
}
return flag;
}
/** 增加一个论坛版主,同时更新该用户类型(版主:4)
* @param forumId 论坛Id
* @param forumAdmin 论坛版主
* @return true:成功 false:失败
* @throws SQLException
*/
public static boolean addForumAdmin(int forumId,String forumAdmin){
boolean flag = true;
try {
flag = forumdao.addForumadmin(forumId, forumAdmin);
if(flag)
flag = UserBiz.updateUserType(forumAdmin, 4);
}catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke addForumAdmin(int forumId,String forumAdmin):\n" + e.toString());
flag = false;
}
return flag;
}
/** 论坛排序
* @param forumId 论坛Id
* @param forumSort 论坛顺序
* @return true:成功 false:失败
* @throws SQLException
*/
public static boolean forumSort(int forumId,int forumSort){
boolean flag = true;
try {
flag = forumdao.forumSort(forumId, forumSort);
}catch(SQLException e) {
bbslog.error("Throws a SqlException when invoke forumSort(int forumId,String forumSort):\n" + e.toString());
flag = false;
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -