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

📄 userboimpl.java

📁 一个bbs论坛系统
💻 JAVA
字号:
package com.lovo.bo;

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

import com.lovo.factory.BOFactory;
import com.lovo.factory.DAOFactory;
import com.lovo.po.AreaPO;
import com.lovo.po.BlockPO;
import com.lovo.po.MessagePO;
import com.lovo.po.PublishPO;
import com.lovo.po.ReplyPO;
import com.lovo.po.UserPO;
import com.lovo.util.Page;

public class UserBOImpl implements UserBO {
	
	/**
	 * 用户登陆
	 * @param name 用户名
	 * @param password 用户密码
	 * @return
	 */
	public boolean login(String name, String password) {
		try {
			UserPO po = DAOFactory.getUserDAOInstance().queryUserByName(name);
			if (po != null) {
				if (password.equals(po.getPassword())) {
					return true;
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 用户注册
	 * @param vo 存储用户信息对象
	 * @return
	 */
	public boolean register(UserPO po) {
		try {
			UserPO poExist = DAOFactory.getUserDAOInstance().queryUserByName(po.getName());
			if(poExist == null) {
				DAOFactory.getUserDAOInstance().insert(po);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("格式输入不正确");
			return false;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	
	/**
	 * 用户找回密码
	 * @param vo 存储用户信息对象
	 * @return
	 * @throws SQLException 
	 * @throws SQLException 
	 */
	public String findPassword(UserPO po) throws SQLException {
		try {
			UserPO poExist = DAOFactory.getUserDAOInstance().queryUserByName(po.getName());
			if(poExist != null) {
				if(poExist.getProblem() != null && poExist.getResult() != null) {
					if(po.getProblem().equals(poExist.getProblem()) && po.getResult().equals(poExist.getResult())) {
						return poExist.getPassword();
					}	
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw e;
		}
		return null;
		
		
	}

	/**
	 * 用户修改信息
	 * @param vo 存储用户信息对象
	 * @return
	 */
	public boolean modifyInfo(UserPO po) {
		try {
			DAOFactory.getUserDAOInstance().update(po);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	/**
	 * 退出登陆
	 * @return
	 */
	public boolean exitLogin() {
		return false;
	}
	
	/**
	 * 添加区主
	 * @param name 用户名
	 * @return
	 */
	public boolean addAreaAdmin(UserPO po) {
		try {
			UserPO poExist = DAOFactory.getUserDAOInstance().queryUserByName(po.getName());
			if(poExist != null) {
				poExist.setAreaFlag(1);
				poExist.setArea(po.getArea());
				DAOFactory.getUserDAOInstance().update(poExist);
				DAOFactory.getUser_AreaDAOInstance().insert(poExist.getId(), poExist.getArea().getId());
			} else {
				return false;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	
	/**
	 * 添加版主
	 * @param name 用户名
	 * @return
	 */
	public boolean addBlockAdmin(UserPO po) {
		
		try {
			UserPO poExist = DAOFactory.getUserDAOInstance().queryUserByName(po.getName());
			if(poExist != null) {
				poExist.setBlockFlag(1);
				poExist.setBlock(po.getBlock());
				DAOFactory.getUser_BlockDAOInstance().insert(poExist.getId(), poExist.getBlock().getId());
				DAOFactory.getUserDAOInstance().update(poExist);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	
	

	/**
	 * 根据名字具体查询某个用户信息
	 * @param name 用户名
	 * @return
	 */
	public UserPO queryByName(String name) {
		UserPO po = null;
		try {
			po = DAOFactory.getUserDAOInstance().queryUserByName(name);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return po;
	}
	
	/**
	 * 根据名字模糊查询某些用户信息
	 * @param name 用户名
	 * @return
	 */
	public List<UserPO> queryByLike(String name) {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryUserByLike(name);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**
	 * 查询某个区的所有区主
	 * @return
	 */
	public List<UserPO> queryAreaAdmin(int areaId) {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryByAreaId(areaId);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 查询某个版块的所有版主
	 * @param aresId
	 * @return
	 */
	public List<UserPO> queryBlockAdmin(int blockId) {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryByBlockId(blockId);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**
	 * 查询所有用户信息
	 * @param blockId
	 * @return
	 */
	public List<UserPO> queryUsers(Page page) {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryUser(page);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 新人排名
	 */
	public List<UserPO> queryUserByRegisterTime() {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryUserByRegisterTime();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 财富排名
	 */
	public List<UserPO> queryUserByWealth(Page page) {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryUserByWealth(page);
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public List<UserPO> queryUserByWealth() {
		List<UserPO> list = null;
		try {
			list = DAOFactory.getUserDAOInstance().queryUserByWealth();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public void setMsgList(UserPO po) {
		List<MessagePO> msgList = null;
		try {
			msgList = DAOFactory.getMessageDAOInstance().queryMsgByReceiverId(po.getId());
			po.setMsgList(msgList);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void setReplyList(UserPO po) {
		List<ReplyPO> replyList;
		try {
			replyList = DAOFactory.getReplyDAOInstance().queryByUserId(po.getId());
			po.setReplyList(replyList);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void setPublishList(UserPO po) {
		List<PublishPO> publishList;
		try {
			publishList = DAOFactory.getPublishDAOInstance().queryByUserId(po.getId());
			po.setPublishList(publishList);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	public boolean initArea(UserPO po) {
		try {
			AreaPO area = DAOFactory.getAreaDAOInstance().queryById(po.getArea().getId());
			po.setArea(area);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	public boolean initBlock(UserPO po) {
		try {
			BlockPO block = DAOFactory.getBlockDAOInstance().queryBlockById(po.getBlock().getId());
			po.setBlock(block);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean deleteUser(int id) {
		try {
			DAOFactory.getUserDAOInstance().delete(id);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean deleteByName(String name) {
		try {
			DAOFactory.getUserDAOInstance().delete(name);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean deleteBlockAdmin(int userId, int areaId) {
		try {
			DAOFactory.getUser_AreaDAOInstance().delete(userId, areaId);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean deleteadAreaAdmin(int userId, int blockId) {
		try {
			DAOFactory.getUser_BlockDAOInstance().delete(userId, blockId);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public UserPO queryById(int id) {
		UserPO user = null;
		try {
			user = DAOFactory.getUserDAOInstance().queryUserById(id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

	public int queryRegUserNum() {
		int maxRows = 0;
		try {
			maxRows = DAOFactory.getUserDAOInstance().queryRegUserNum();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return maxRows;
	}

	public boolean lockUser(UserPO po) {
		po.setLockFlag(1);
		try {
			DAOFactory.getUserDAOInstance().update(po);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	public boolean delLockUser(UserPO po) {
		po.setLockFlag(0);
		try {
			DAOFactory.getUserDAOInstance().update(po);
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}

⌨️ 快捷键说明

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