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

📄 messagebiz.java

📁 一个不错的bbs论坛系统.对初学者很有帮助
💻 JAVA
字号:
package com.yhbbs.message.biz;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;

import com.yhbbs.article.biz.ArticleBiz;
import com.yhbbs.article.itface.ArticleDto;
import com.yhbbs.bbs.biz.BbsPropBiz;
import com.yhbbs.bbs.itface.BbsProp;
import com.yhbbs.forum.biz.ForumBiz;
import com.yhbbs.message.bean.MessageIm;
import com.yhbbs.message.bean.MsgCountIm;
import com.yhbbs.message.bean.TempletIm;
import com.yhbbs.message.dao.MsgDaoIm;
import com.yhbbs.message.itface.Message;
import com.yhbbs.message.itface.MsgCount;
import com.yhbbs.message.itface.MsgDao;
import com.yhbbs.message.itface.Templet;
import com.yhbbs.user.biz.UserBiz;
import com.yhbbs.utils.Constants;

/**
 * <p>Title:论坛短消息相关信息操作</p>
 * <li>	论坛短消息数据存取模块 <br>
 * <li>	论坛注册,帖子删除移动短消息数据存取模块 <br>
 * <br><b>WebSite: www.yyhweb.com</b>
 * <br><b>CopyRight: yhbbs[永恒论坛]</b>
 * @author stephen
 * @version YH-1.0
 */
public class MessageBiz {
	
	private static Logger bbslog = Logger.getLogger(MessageBiz.class);
	
	private static MsgDao msgdao = MsgDaoIm.getInstance();

	/**
	 * @param userId 用户Id
	 * @return 用户短消息数目统计
	 */
	public static MsgCount getMsgCount(int userId){
		
		try {
            return msgdao.getMsgCount(userId);
        }
        catch(SQLException e) {
            bbslog.error("Throws a SqlException when invoke getMsgCount(userId):\n" + e.toString());
        }
        return new MsgCountIm();
	}
	/** 取得注册用户消息模版
	 * @return 注册用户消息模版
	 */
	public static Templet getRegTemplet(){
		
		try {
			return msgdao.getRegTemplet();
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getRegTemplet():\n" + e.toString());
		}
		return new TempletIm();
		
	}
	
	/** 取得注册用户后系统发送的消息模版
	 * @return 注册用户后系统发送的消息模版
	 */
	public static Templet getRegMessage(){
		
		try {
			return msgdao.getRegMessage();
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getRegMessage():\n" + e.toString());
		}
		return new TempletIm();
		
	}
	
	/** 取得移动帖子的消息模版
	 * @return 移动帖子消息模版
	 */
	public static Templet getMoveMessage(){
		
		try {
			return msgdao.getMoveMessage();
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getMoveMessage():\n" + e.toString());
		}
		return new TempletIm();
		
	}
	
	/** 取得删除帖子的消息模版
	 * @return 删除帖子消息模版
	 */
	public static Templet getDelMessage(){
		
		try {
			return msgdao.getDeleteMessage();
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getDelMessage():\n" + e.toString());
		}
		return new TempletIm();
	}
	
	/** 取得用户短消息数
	 * @param userId 用户Id
	 * @param i 0:发送 1:接受 2:最新 3:所有
	 * @return 短消息数
	 * @throws SQLException
	 */
	public static int getMsgCount(int userId,int i){
		
		try {
			return msgdao.getMsgCounts(userId, i);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getMsgCount(int userId,int i):\n" + e.toString());
		}
		return 0;
		
	}
	
	/** 发送短消息
	 * @param msg 短消息
	 * @throws SQLException
	 */
	public static void sendMessage(Message msg){
		
		try {
			msgdao.addMessage(msg);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke sendMessage(Message msg):\n" + e.toString());
		}
		return ;
		
	}
	/** 发送一个注册成功短消息给新注册用户
	 * @param regId 目标用户Id
	 * @param regName 目标用户名称
	 * @throws SQLException
	 */
	public static void sendRegMessage(int regId,String regName){
		Message msg = new MessageIm();
		BbsProp bbsprop = BbsPropBiz.getBbsProp();
		try {
			String bbsname = bbsprop.getName();
			Templet regTemp = getRegMessage();
			String msgTitle = regTemp.getRegmsgtitle();
			msg.setTitle(msgTitle.replaceAll("\\$\\{"+Constants.forum_name+"\\}", bbsname));
			msg.setContent(regTemp.getRegmsg());
			msg.setFromId(1);
			msg.setFromUser("admin");
			msg.setToId(regId);
			msg.setToUser(regName);
			msg.setSave("0");
			msgdao.addMessage(msg);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke sendRegMessage(int regId,String regName):\n" + e.toString());
		}
		return ;
		
	}
	/** 删除短消息,0:表示从发送邮箱里删除,1:从接受邮箱里删除 2:彻底删除
	 * @param msgId 短消息Id
	 * @param i 0:发送 1:接受 2:删除
	 * @throws SQLException
	 */
	public static void delMessage(int msgId,int i){
		
		try {
			msgdao.deleteMessage(msgId,i);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke delMessage(int msgId):\n" + e.toString());
		}
		return ;
		
	}
	/** 取得用户消息列表
	 * @param userId 用户Id
	 * @param start 开始位置
	 * @param end 长度
	 * @param i 0:发件箱 1:收件箱
	 * @return 用户收件箱消息
	 */
	public static List getMessages(int userId,int start,int end,int i){
		HashMap<String, Integer> msgpage = new HashMap<String, Integer>();
		msgpage.put("userid",userId);
		msgpage.put("start",start);
		msgpage.put("end",end);
		try {
			return msgdao.getMsgs(msgpage,i);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getRevMsgs(int userId,int start,int end,int i):\n" + e.toString());
		}
		return null;
	}
	/** 由ID取得短消息
	 * @param msgId 短消息Id
	 * @return 短消息
	 */
	public static Message getMessage(int msgId){
		
		try {
			return msgdao.getMessage(msgId);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke getMessage(int msgId):\n" + e.toString());
		}
		return new MessageIm();
	}
	/** 更新短消息为已读
	 * @param msgId 消息Id
	 * @throws SQLException
	 */
	public static void ReadMsg(int msgId){
		
		try {
			msgdao.ReadMessage(msgId);
		}
		catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke ReadMsg(int msgId):\n" + e.toString());
		}
		return;
	}
	
	/** 移动帖子后发送短消息给帖子发表者
	 * @param artId 被移动的帖子Id
	 * @param moveCId 目标区论坛Id
	 * @param moveFId 目标论坛Id
	 * @param forumId 原论坛Id
	 * @param adminId 移动帖子的管理员Id
	 * @throws SQLException
	 */
	public static void moveArticle(int artId,int moveCId,int moveFId,int forumId,int adminId){
		Message msg = new MessageIm();
		try {
			Templet moveTemp = getMoveMessage();
			String isMove = moveTemp.getIsmove();
			if(isMove.equals("0")) // 移动用户帖子是否发送短消息告知
			   return;
			
			ArticleDto moveArt = ArticleBiz.getArticle(artId);
			String moveFName = ForumBiz.getForumName(moveFId);
			String forumName = ForumBiz.getForumName(forumId);
			String adminName = UserBiz.getUserName(adminId);
			
			String msgTitle = moveTemp.getMovetitle();
			String msgContent = moveTemp.getMoveart();
			msgTitle = msgTitle.replaceAll("\\$\\{"+Constants.forum_moveToName+"\\}", moveFName);
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.user_userName+"\\}",moveArt.getUser());
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.article_title+"\\}",moveArt.getTitle());
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.admin_userName+"\\}",adminName);
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.forum_moveFromName+"\\}",forumName);
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.forum_moveToName+"\\}",moveFName);
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.forum_moveToCId+"\\}",String.valueOf(moveCId));
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.forum_moveToId+"\\}",String.valueOf(moveFId));
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.article_id+"\\}",String.valueOf(artId));
			msg.setFromId(adminId);
			msg.setFromUser(adminName);
			msg.setToId(moveArt.getUserid());
			msg.setToUser(moveArt.getUser());
			msg.setTitle(msgTitle);
			msg.setContent(msgContent);
			msg.setSave("0");
			msgdao.addMessage(msg);
			
		}catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke MoveArticle(artId,moveCId,moveFId,forumId,adminId):\n" + e.toString());
		}
		return;
	}
	/** 删除(主题)帖子后发送短消息给帖子发表者
	 * @param delArt 被删除的帖子
	 * @param adminId 删除帖子的管理员ID
	 * @param reason 删除帖子原因
	 * @throws SQLException
	 */
	public static void deleteArticle(ArticleDto delArt,int adminId,String reason){
		Message msg = new MessageIm();
		try {
			Templet delTemp = getDelMessage();
			String isDel = delTemp.getIsdelete();
			if(delArt==null || isDel.equals("0")) // 删除用户帖子是否发送短消息告知
				return;
			if(delArt.getUserid()==adminId)		// 如果是管理员删除了自己的帖子就可以不用发送短消息了
				return;
			String forumName = ForumBiz.getForumName(delArt.getForum());
			String adminName = UserBiz.getUserName(adminId);
			
			String msgTitle = delTemp.getDeletetitle();
			String msgContent = delTemp.getDeleteart();
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.user_userName+"\\}",delArt.getUser());
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.article_title+"\\}",delArt.getTitle());
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.admin_userName+"\\}",adminName);
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.forum_deleteName+"\\}",forumName);
			msgContent = msgContent.replaceAll("\\$\\{"+Constants.admin_comment+"\\}",reason);
			
			msg.setFromId(adminId);
			msg.setFromUser(adminName);
			msg.setToId(delArt.getUserid());
			msg.setToUser(delArt.getUser());
			msg.setTitle(msgTitle);
			msg.setContent(msgContent);
			msg.setSave("0");
			msgdao.addMessage(msg);
			
		}catch(SQLException e) {
			bbslog.error("Throws a SqlException when invoke MoveArticle(artId,moveCId,moveFId,forumId,adminId):\n" + e.toString());
		}
		return;
	}
	
	// 后台管理使用
	
	/**
	 * @param i 更新模版类型
	 * 0:注册协议、1:注册消息、2:移动消息、3:删除消息模版
	 * @param templet 模版
	 * @return true:成功 false:失败
	 */
	public static boolean updateTemplet(int i,Templet templet){
		boolean flag = true;
		try{
			flag = msgdao.updateTemplet(i, templet);
		}catch(SQLException e){
			bbslog.error("Throws a SqlException when invoke updateTemplet(int i,Templet templet):\n" + e.toString());
			flag = false;
		}
		return flag;
	}
}

⌨️ 快捷键说明

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