friendjsp.java

来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 159 行

JAVA
159
字号
/* 
 * Created on 2007-5-5
 * Last modified on 2007-5-5
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.view.jsp;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yeqiangwei.club.param.FriendParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.model.FriendLastPost;
import com.yeqiangwei.club.model.Friend;
import com.yeqiangwei.club.module.doing.controller.form.MessageForm;
import com.yeqiangwei.club.module.doing.model.Message;
import com.yeqiangwei.club.module.doing.param.MessageParameter;
import com.yeqiangwei.club.module.doing.service.MessageService;
import com.yeqiangwei.club.service.user.FriendService;
import com.yeqiangwei.club.service.user.UserLogin;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.view.model.FriendLastPostView;
import com.yeqiangwei.club.view.model.FriendView;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.Validator;

public class FriendJsp extends BaseJsp{
	
	public FriendJsp(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
	}

	private String pagination;

	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}
	
	public List<FriendLastPostView> findLastPost(int rows, boolean isTopic){
		List<FriendLastPost> mlist = this.getFriendService().findLastPost(
				UserLogin.getUserId(request),rows,isTopic);
		/*
		for(FriendLastPost fp: mlist){
			FriendLastPostView fv = new FriendLastPostView();
			Topic topic = fp.getTopic();
			TopicView topicView = new TopicView();
			BeanUtils.copyProperties(topicView, topic);
			Reply reply = fp.getReply();
			ReplyView replyView = new ReplyView();
			BeanUtils.copyProperties(replyView, reply);
			fv.setTopicView(topicView);
			fv.setReplyView(replyView);
		}
		*/
		List<FriendLastPostView> list = BeanUtils.copyList(mlist,BeanLocator.FRIENDLASTPOSTVIEW);
		return list;
	}
	
	public List<FriendView> findByFriendUserId(int rows){
		FriendParameter param = new FriendParameter();
		param.setPage(1);
		param.setRows(rows);
		param.setOrderBy(null); //按关系值倒序排列
		param.setFriendUserId(UserLogin.getUserId(request));
		param.setMyUserId(null);
		List<Friend> mlist = this.getFriendService().findByParameter(param);
		if(!Validator.isEmpty(mlist)){
			List<FriendView> list = BeanUtils.copyList(mlist,BeanLocator.FRIENDVIEW);
			return list;
		}else{
			return null;
		}
	}
	
	public List<FriendView> findBestFriendByMyUserId(int rows){
		FriendParameter param = new FriendParameter();
		param.setPage(1);
		param.setRows(rows);
		param.setOrderBy((byte)3); //按关系值倒序排列
		param.setMyUserId(UserLogin.getUserId(request));
		List<Friend> mlist = this.getFriendService().findByParameter(param);
		List<FriendView> list = BeanUtils.copyList(mlist,BeanLocator.FRIENDVIEW);
		return list;	
	}
	
	public List<FriendView> findByMyUserId(int rows){
		int userId = ParamUtils.getIntParameter(request,"userId",0);
		if(userId==0){
			userId = UserLogin.getUserId(request);
		}
		int page = ParamUtils.getIntParameter(request,"page",1);
		FriendParameter param = new FriendParameter();
		param.setPage(page);
		param.setRows(rows);
		param.setMyUserId(userId);
		List<Friend> mlist = this.getFriendService().findByParameter(param);
		List<FriendView> list = BeanUtils.copyList(mlist,BeanLocator.FRIENDVIEW);
		return list;
		/*
		 * 限制了上限为50位好友,因此分页暂不启用。
		 */
		//long total = this.getFriendService().countByParameter(param);
		//StringBuffer url = new StringBuffer();
		//url.append("friend.jsp?page=");
		//this.setPagination(com.yeqiangwei.html.OutPrint.pagination(page, rows, total, url.toString(),5));	 
		
	}
	
	public List<MessageForm> findFriendDoing(int rows){
		int userId = ParamUtils.getIntParameter(request,"userId",0);
		if(userId==0){
			userId = UserLogin.getUserId(request);
		}
		if(userId==0){
			return null;
		}
		FriendParameter param = new FriendParameter();
		param.setPage(1);
		param.setRows(100);
		param.setMyUserId(userId);
		List<Friend> friendlist = this.getFriendService().findByParameter(param);
		List<Integer> userIdList = new ArrayList<Integer>();
		for(Friend friend : friendlist){
			userIdList.add(friend.getFriendUserId());
		}
		List<MessageForm> list = new ArrayList<MessageForm>();
		MessageParameter msgparam = new MessageParameter();
		msgparam.setPage(1);
		msgparam.setRows(rows);
		msgparam.setUserIdList(userIdList);
		List<Message> mlist = this.getMessageService().findByParameter(msgparam);
		if(!Validator.isEmpty(mlist)){
			for(Message message : mlist){
				MessageForm form = new MessageForm();
				BeanUtils.copyProperties(form,message);
				list.add(form);
			}
		}
		return list;
	}
	
	private MessageService getMessageService(){
		return ServiceWrapper.<MessageService>getSingletonInstance(ServiceLocator.DOING_MESSAGE);
	}
	
	public FriendService getFriendService() {
		return ServiceWrapper.<FriendService>getSingletonInstance(ServiceLocator.FRIEND);
	}
}

⌨️ 快捷键说明

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