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

📄 userserviceimpl.java

📁 这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				model.setUserId(id);
				try {
					c = this.delete(model);
				} catch (ClubException e) {
					logger.error(e.toString());
				}
				if(c>0){
					success++;
				}else{
					error++;
				}
			}
			logger.info("delete(String[] ids) 成功:"+success+"  失败:"+error);
		}else{
			logger.warn("delete(String[] ids) 传入空的ID集合");
			throw new ClubException(MessageUtils.getMessage("error_delete_noid"));
		}		
		return success;
	}
	
	/**
	 * have not cache
	 */
	public UserModel findByUserName(String userName) {
		UserModel model = null;
		if(!Validator.isEmpty(userName)){
			User item = this.getUserDAO().findByUserName(userName);
			if(!Validator.isEmpty(item)){
				model = new UserModel();
				BeanUtils.copyProperties(model,item); //PO->BO
				userCache.put(CacheKeys.getKey(model),model);
			}
		}
		return model;
	}
	
	public UserModel findByUserNameAndPassword(UserModel model) throws ClubException{
		return this.findByUserNameAndPassword(model, true);
	}


	public UserModel findByUserIdAndPassword(int userId, String password) {
		return this.findByUserIdAndPassword(userId, password, true);
	}

	public UserModel findByUserNameAndPassword(UserModel model, boolean passwordEncrypt) throws ClubException
	{
		User item = null;
		if(!Validator.isEmpty(model.getUserName())&&!Validator.isEmpty(model.getPassword()))
		{
			
			String password = model.getPassword();
			//用户初始化参数开始
			if(this.getBasicInfo()!=null && passwordEncrypt){
				password = StringHelper.encodeString(this.getBasicInfo().getPasswordEncrypt(),model.getPassword());
			}
			item = this.getUserDAO().findByUserNameAndPassword(model.getUserName(),password);
			if(Validator.isEmpty(item)){
				logger.debug("login error: userName="+model.getUserName()+
						", password=" + password + 
						", passwordEncrypt=" + passwordEncrypt);
				return null;
			}else{
				item.setLastLoginDateTime(FormatDateTime.now());
				logger.debug("model.getLastLoginDateTime():"+item.getLastLoginDateTime());
				item.setLastLoginIp(model.getLastLoginIp());
				item.setLoginTimes(model.getLoginTimes()+1);
				this.ruleUtils(item,1); //按积分制度更新参数
				this.getUserDAO().update(item);
				BeanUtils.copyProperties(model,item); //PO->BO
				userCache.put(CacheKeys.getKey(model),model); // Cache
				//this.setMessage(MessageUtils.getMessage("success_login"));
				return model;
			}
		}else{
			//this.setMessage(MessageUtils.getMessage("error_login_empty"));
			//throw new ClubException(MessageUtils.getMessage("error_login_empty"));
			return null;
		}
	}

	public UserModel findByUserIdAndPassword(int userId, String password, boolean passwordEncrypt) {
		UserModel model = null;
		if(userId>0&&!Validator.isEmpty(password)){
			if(passwordEncrypt){
				password = StringHelper.encodeString(this.getBasicInfo().getPasswordEncrypt(),password);
			}
			model = (UserModel) userCache.get(CacheKeys.getUserKey(userId));
			if(!Validator.isEmpty(model)){ //如果缓存存在
				if(!model.getPassword().equals(password)){ //如果密码不符则置空对象
					return null;
				}
			}else{//如果缓存不存在则通过DAO读取数据库数据
				User item = this.getUserDAO().findByUserIdAndPassword(userId,password);
				if(!Validator.isEmpty(item)){
					model = new UserModel();
					BeanUtils.copyProperties(model,item); //PO->BO
					userCache.put(CacheKeys.getKey(model),model);
				}
			}
		}
		return model;
	}

	public UserModel findByEmailAddress(String emailAddress) {
		UserModel model = null;
		if(!Validator.isEmpty(emailAddress)){
			User item = this.getUserDAO().findByEmailAddress(emailAddress);
			if(!Validator.isEmpty(item)){
				model = new UserModel();
				BeanUtils.copyProperties(model,item); //PO->BO
				userCache.put(CacheKeys.getKey(model),model);
			}
		}
		return model;
	}


	public List<UserModel> findByParameter(UserParameter param) {
		if(!Validator.isEmpty(param)){
			List<User>  list =this.getUserDAO().findByParameter(param);
			List<UserModel> mlist = BeanUtils.<User,UserModel>copyList(list,BeanLocator.USERMODEL);
			return mlist;
		}
		return null;
	}

	public long countByParameter(UserParameter param) {
		if(!Validator.isEmpty(param)){
			return this.getUserDAO().countByParameter(param);
		}
		return 0;
	}
	
	/**
	 * 如果缓存存在则向数据库内读取数据
	 */
	public UserModel findById(int id) {
		UserModel model = (UserModel) userCache.get(CacheKeys.getUserKey(id));
		if(Validator.isEmpty(model)&&id>0){
			User item = this.getUserDAO().findById(id);
			if(!Validator.isEmpty(item)){
				model = new UserModel();
				BeanUtils.copyProperties(model,item);
				userCache.put(CacheKeys.getKey(model),model);
			}
		}
		/*
		if(Validator.isEmpty(model)){
			this.setMessage(MessageUtils.getMessage("error_notfind"));
		}
		*/
		return model;
	}
	
	public int updateGroupIdByUserIds(int groupId, String[] userIds) throws ClubException {
		int c = 0;
		if(Validator.isEmpty(userIds)){
			//this.setMessage(MessageUtils.getMessage("error_update_noid"));
			throw new ClubException(MessageUtils.getMessage("error_update_noid"));
		}else{
			for(int i=0; i<userIds.length; i++){
				int id = TypeChange.stringToInt(userIds[i]);
				UserModel model = this.findById(id);
				if(!Validator.isEmpty(model)){
					model.setGroupId(groupId);
					try {
						this.update(model);
					} catch (ClubException e1) {
						logger.error(e1.toString());
					}
				}
			}
			//this.setMessage(MessageUtils.getMessage(c,e));
		}
		return c;
	}
	
	private User ruleUtils(User item, int locator){
		return this.ruleUtils(item,0,locator);
	}
	
	public User ruleUtils(User item, int forumId, int locator){
		double score = this.getRuleService().getElement(forumId,RuleService.SCORE,locator);
		double money = this.getRuleService().getElement(forumId,RuleService.MONEY,locator);
		double credit = this.getRuleService().getElement(forumId,RuleService.CREDIT,locator);
		item.setScore(item.getScore()+score);
		item.setMoney(item.getMoney()+money);
		item.setCredit(item.getCredit()+credit);
		return item;
	}
	
	private UserModel ruleUtils(UserModel model, int locator){
		return this.ruleUtils(model,0,locator);
	}
	
	public ManageLogModel ruleUtils(ManageLogModel model, int forumId, int locator) {
		double score = this.getRuleService().getElement(forumId,RuleService.SCORE,locator);
		double money = this.getRuleService().getElement(forumId,RuleService.MONEY,locator);
		double credit = this.getRuleService().getElement(forumId,RuleService.CREDIT,locator);
		model.setScore(score);
		model.setMoney(money);
		model.setCredit(credit);
		return model;
	}
	
	public UserModel ruleUtils(UserModel model, int forumId, int locator){
		double score = this.getRuleService().getElement(forumId,RuleService.SCORE,locator);
		double money = this.getRuleService().getElement(forumId,RuleService.MONEY,locator);
		double credit = this.getRuleService().getElement(forumId,RuleService.CREDIT,locator);
		model.setScore(model.getScore()+score);
		model.setMoney(model.getMoney()+money);
		model.setCredit(model.getCredit()+credit);
		logger.debug("积分变更:"+score+" 金币变更:"+money+" 信誉变更:"+credit);
		return model;
	}
	
	/************************************************************/

	public BasicInfoService getBasicInfoService() {
		return ServiceWrapper.<BasicInfoService>getSingletonInstance(ServiceLocator.BASICINFO);
	}

	public UserDAO getUserDAO() {
		return DAOWrapper.<UserDAO>getSingletonInstance(DAOLocator.USER);
	}
	
	public GroupService getGroupService() {
		return ServiceWrapper.<GroupService>getSingletonInstance(ServiceLocator.GROUP);
	}

	public RuleService getRuleService() {
		return ServiceWrapper.<RuleService>getSingletonInstance(ServiceLocator.RULE);
	}

	public BasicInfoModel getBasicInfo() {
		return this.getBasicInfoService().findOnly();
	}

	public UserModel getUserModel() {
		return this.userModel;
	}

	public void setUserModel(UserModel model) {
		this.userModel = model;
	}

	public UserModel update_fileUpload(UserModel model) {
		return null;
	}

}

⌨️ 快捷键说明

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