📄 userjsp.java
字号:
/*
* Created on 2007-2-25
* Last modified on 2007-05-11
* 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 org.apache.log4j.Logger;
import com.yeqiangwei.club.param.FavoriteParameter;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.param.UserParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.topic.ReplyService;
import com.yeqiangwei.club.service.topic.TopicService;
import com.yeqiangwei.club.service.user.UserLogin;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.service.forum.FavoriteForumService;
import com.yeqiangwei.club.service.message.MessageService;
import com.yeqiangwei.club.service.model.ForumModel;
import com.yeqiangwei.club.service.model.ReplyModel;
import com.yeqiangwei.club.service.model.TopicModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.FormatDateTime;
import com.yeqiangwei.util.HttpServletUtils;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;
import com.yeqiangwei.club.controller.form.AProfileForm;
import com.yeqiangwei.club.controller.form.EmailForm;
import com.yeqiangwei.club.controller.form.build.EmailBuild;
import com.yeqiangwei.club.view.model.ForumView;
import com.yeqiangwei.club.view.model.ReplyView;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.club.view.model.UserView;
import com.yeqiangwei.html.OutPrint;
import com.yeqiangwei.net.URL;
/**
*
* @author 一般人
*/
public class UserJsp extends BaseJsp{
private static final Logger logger = Logger.getLogger(UserJsp.class);
private UserView user;
private String pagination;
private int page = 1;
private byte orderBy = 0;
public UserJsp(HttpServletRequest request, HttpServletResponse response) {
super(request, response);
}
public AProfileForm getAProfileForm(){
AProfileForm form = (AProfileForm) request.getAttribute("AProfileForm");
if(Validator.isEmpty(form)){
form = new AProfileForm();
int userId = ParamUtils.getIntParameter(request,"userId",0);
UserModel model = this.getUserService().findById(userId);
BeanUtils.copyProperties(form,model);
}
return form;
}
public EmailForm getEmailForm(){
EmailForm form = (EmailForm) request.getAttribute("EmailForm");
if(Validator.isEmpty(form)){
EmailBuild b = new EmailBuild(request);
form = b.build();
}
if(form.getTakerUserId()>0){
UserModel user = this.getUserService().findById(form.getTakerUserId());
if(!Validator.isEmpty(user)){
form.setTaker(user.getUserName());
form.setTo(user.getEmailAddress());
}
}
return form;
}
public List<TopicView> findTopicsFromFavorite(int rows){
return this.findTopicsFromFavorite(UserLogin.getUserId(request),rows);
}
public List<TopicView> findTopicsFromFavorite(){
return this.findTopicsFromFavorite(UserLogin.getUserId(request),50);
}
public List<TopicView> findTopicsFromFavorite(int userId, int rows){
List<TopicView> list = null;
FavoriteParameter param = new FavoriteParameter();
param.setUserId(userId);
param.setRows(rows);
List<TopicModel> mlist = this.getFavoriteForumService().findTopic(param);
if(rows==0){
list = BeanUtils.<TopicModel,TopicView>copyList(mlist,BeanLocator.TOPICVIEW);
}else{
list = new ArrayList<TopicView>();
if(!Validator.isEmpty(mlist)){
F:for(int i=0; i<mlist.size(); i++){
TopicModel model = mlist.get(i);
TopicView view = new TopicView();
BeanUtils.copyProperties(view,model);
list.add(view);
if(list.size()==rows){
break F;
}
}
}
}
return list;
}
public List<TopicView> findMyTopicOfLastReplyed(int rows){
List<TopicView> list = null;
TopicParameter param = new TopicParameter();
param.setUserId(UserLogin.getUserId(request));
param.setPage(new Integer(1));
param.setRows(new Integer(rows));
param.setIsDeleted(new Boolean(false));
param.setOrderBy((byte)3); //按最后被回复排序
List<TopicModel> mlist = this.getTopicService().findByParameter(param);
list = BeanUtils.<TopicModel,TopicView>copyList(mlist,BeanLocator.TOPICVIEW);
return list;
}
public long countNewMessage(){
return this.getMessageService().countNewMessage(UserLogin.getUserId(request));
}
/**
*
* @param rows 显示的行数
* @return
*/
public List<TopicView> findTopicByUserId(int rows){
List<TopicView> list = null;
int userId = ParamUtils.getIntParameter(request,"userId",0);
if(userId==0){
userId = UserLogin.getUserId(request);
}
if(userId==0){
request.setAttribute("message",MessageUtils.getMessage("error_notlogin"));
HttpServletUtils.forward(request,response,"/club/msg.jsp");
logger.debug("错误的参数 userId=0");
return null;
}else{
UserModel userModel = this.getUserService().findById(userId);
user = new UserView();
BeanUtils.copyProperties(user,userModel);
TopicParameter param = new TopicParameter();
param.setPage(new Integer(1));
param.setRows(rows);
param.setUserId(userId);
param.setOrderBy((byte)2);
List<TopicModel> mlist = this.getTopicService().findByParameter(param);
list = BeanUtils.copyList(mlist,BeanLocator.TOPICVIEW);
}
return list;
}
public List<ReplyView> findReplyByUserId(int rows){
int userId = ParamUtils.getIntParameter(request,"userId",0);
if(userId==0){
userId = UserLogin.getUserId(request);
}
TopicParameter param = new TopicParameter();
param.setPage(new Integer(1));
param.setRows(rows);
param.setUserId(new Integer(userId));
param.setOrderBy(new Byte((byte)2)); //order by replyId desc
List<ReplyModel> mlist = this.getReplyService().findByParameter(param);
List<ReplyView> list = BeanUtils.copyList(mlist,BeanLocator.REPLYVIEW);
return list;
}
public List<UserView> findAll(int rows){
String userName = ParamUtils.getStringParameter(request, "userName", "");
userName = URL.urlDecoder(userName,"UTF-8");
userName = StringHelper.toUTF8(userName);
String ip = ParamUtils.getStringParameter(request, "ip", "");
int days = ParamUtils.getIntParameter(request,"days",-1);
page = ParamUtils.getIntParameter(request,"page",1);
orderBy = ParamUtils.getByteParameter(request,"orderBy",(byte)0);
UserParameter param = new UserParameter();
param.setOrderBy(new Byte((byte) 0));
param.setPage(page);
param.setRows(rows);
param.setOrderBy(new Byte(orderBy));
param.setUserName(userName);
param.setRegIp(ip);
if(days!=-1){
String time = FormatDateTime.dateAdd(FormatDateTime.DAY_OF_MONTH,-days,"yyyyMMddHHmmss");
long ltime = TypeChange.stringToLong(time);
param.setLastLoginTime(ltime);
}
List<UserModel> list = this.getUserService().findByParameter(param);
List<UserView> vlist = BeanUtils.copyList(list,BeanLocator.USERVIEW);
long total = this.getUserService().countByParameter(param);
StringBuffer url = new StringBuffer();
url.append("users.jsp?userName=");
url.append(URL.urlEncoder(userName,"UTF-8"));
url.append("&ip=");
url.append(ip);
url.append("&days=");
url.append(days);
url.append("&page=");
this.setPagination(OutPrint.pagination(page, rows, total, url.toString(),5));
return vlist;
}
public UserView findOnly(){
UserView v = new UserView();
UserModel m = null;
int userId = ParamUtils.getIntParameter(request,"userId",0);
if(userId==0&&!Validator.isEmpty(ParamUtils.getSessionObject(request,"User",null))){
m = ParamUtils.getSessionObject(request,"User",null);
userId = m.getUserId();
}
m = this.getUserService().findById(userId);
if(!Validator.isEmpty(m)){
BeanUtils.copyProperties(v,m);
}else{
HttpServletUtils.redirect(response,"404.html");
return null;
}
return v;
}
public List<ForumView> findFavoriteForums(){
int userId = ParamUtils.getIntParameter(request,"userId",0);
if(userId==0){
userId = UserLogin.getUserId(request);
}
List<ForumModel> mlist = this.getFavoriteForumService().findForumByUserId(userId);
List<ForumView> list = BeanUtils.<ForumModel,ForumView>copyList(mlist,BeanLocator.FORUMVIEW);
return list;
}
public UserView getUser() {
return user;
}
public void setUser(UserView user) {
this.user = user;
}
public String getPagination() {
return pagination;
}
public void setPagination(String pagination) {
this.pagination = pagination;
}
public UserService getUserService() {
return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
}
public ReplyService getReplyService() {
return ServiceWrapper.<ReplyService>getSingletonInstance(ServiceLocator.REPLY);
}
public TopicService getTopicService() {
return ServiceWrapper.<TopicService>getSingletonInstance(ServiceLocator.TOPIC);
}
public FavoriteForumService getFavoriteForumService() {
return ServiceWrapper.<FavoriteForumService>getSingletonInstance(ServiceLocator.FAVORITEFORUM);
}
public MessageService getMessageService() {
return ServiceWrapper.<MessageService>getSingletonInstance(ServiceLocator.MESSAGE);
}
public byte getOrderBy() {
return orderBy;
}
public void setOrderBy(byte orderBy) {
this.orderBy = orderBy;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -