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

📄 friendaction.java

📁 简易java框架开源论坛系统,简 易java框架开源论坛系统
💻 JAVA
字号:
package com.easyjf.bbs.action;

import java.util.Iterator;

import com.easyjf.bbs.business.ActiveUser;
import com.easyjf.bbs.business.BBSRights;
import com.easyjf.bbs.business.Friend;
import com.easyjf.bbs.business.UserInfo;
import com.easyjf.bbs.business.WebMessage;
import com.easyjf.bbs.business.util.FriendUtil;
import com.easyjf.bbs.business.util.MessageUtil;
import com.easyjf.util.CommUtil;
import com.easyjf.web.ActionContext;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.AbstractCmdAction;
import com.easyjf.web.tools.IPageList;
import com.easyjf.bbs.business.util.*;

public class FriendAction extends AbstractCmdAction {

	public FriendAction() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Page doInit(WebForm form, Module module) {
		// TODO Auto-generated method stub
		return null;
	}

	private ActiveUser getCurrentUser() {
		ActiveUser user = (ActiveUser) ActionContext.getContext().getSession()
				.getAttribute("bbsuser");
		return user;
	}

	public Page doList(WebForm form, Module module) {
		if (!BBSRights.checkRights(new Friend(), "list", getCurrentUser()))
			return new Page("popedomError", "/bbs/norights.htm", "page");
		return doQuery(form, module);
	}

	public Page doQuery(WebForm form, Module module) {
		int currentPage = CommUtil.null2Int(form.get("page"));
		int pageSize = CommUtil.null2Int(form.get("pageSize"));
		if (currentPage < 1)
			currentPage = 1;
		if (pageSize < 1)
			pageSize = 15;
		IPageList pList = FriendUtil.queryFriends("1=1 and owner='"
				+ UserInfo.readByUserName(getCurrentUser().getUserName())
						.getCid() + "'", pageSize, currentPage);
		if (pList.getResult() != null) {
			for (Iterator it = pList.getResult().iterator(); it.hasNext();) {
				Friend f = (Friend) it.next();
				ActiveUser user = new ActiveUser();
				user.setUserName(f.getName());
				System.out.println(ActiveUserUtil.contain(user));
				f
						.setState(new Integer(
								ActiveUserUtil.contain(user) ? "1" : "0"));

			}
		}
		if (pList != null) {
			form.addResult("list", pList.getResult());
			form.addResult("pages", new Integer(pList.getPages()));
			form.addResult("rows", new Integer(pList.getRowCount()));
			form.addResult("page", new Integer(pList.getCurrentPage()));
			form.addResult("gotoPageHTML", CommUtil.showPageHtml(pList
					.getCurrentPage(), pList.getPages()));
		}
		return module.findPage("list");
	}

	public Page doDel(WebForm form, Module module) {
		if (!BBSRights.checkRights(new Friend(), "list", getCurrentUser()))
			return new Page("popedomError", "/bbs/norights.htm", "page");
		String cid = CommUtil.null2String(form.get("cid"));
		if (cid != null) {
			Friend f = Friend.read(cid);
			f.del();
		}
		return new Page("FriendsList", "/bbsfriends.ejf?easyJWebCommand=list",
				"page");
	}

	public Page doAdd(WebForm form, Module module) {
		if (!BBSRights.checkRights(new Friend(), "add", getCurrentUser()))
			return new Page("popedomError", "/bbs/norights.htm", "page");
		String friend = CommUtil.null2String(form.get("friend"));
		String owner = UserInfo.readByUserName(getCurrentUser().getUserName())
				.getCid();
		
		if (friend != null && owner != null) {
			Friend f = new Friend();
			f.setFriend(friend);
			f.setOwner(owner);
			f.setName(UserInfo.read(friend).getUserName());
			if(f.save()){
				MessageUtil.sendSystemMessage(WebMessage.FRIENDREQMSG, getCurrentUser().getUserName());
			}
			
		
		}
		return new Page("FriendsList", "/bbsfriends.ejf?easyJWebCommand=list",
				"page");
	}

	public Page doAddByName(WebForm form, Module module) {
		if (!BBSRights.checkRights(new Friend(), "add", getCurrentUser()))
			return new Page("popedomError", "/bbs/norights.htm", "page");
		String friendname = CommUtil.null2String(form.get("friendname"));

		System.out.println(friendname);

		String friend = "";
		if (friendname != null) {
			friend = UserInfo.readByUserName(friendname).getCid();
		}
		String owner = UserInfo.readByUserName(getCurrentUser().getUserName())
				.getCid();
		if (friend != null && owner != null) {
			Friend f = new Friend();
			f.setFriend(friend);
			f.setOwner(owner);
			f.setName(friendname);
			if(f.save()){
				MessageUtil.sendSystemMessage(WebMessage.FRIENDREQMSG, getCurrentUser().getUserName());
			}
		}
		return new Page("FriendsList", "/bbsfriends.ejf?easyJWebCommand=list",
				"page");
	}

	public Page doPreAdd(WebForm form, Module module) {
		return module.findPage("add");
	}

}

⌨️ 快捷键说明

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