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

📄 userindexedserviceimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-9-22
 * Last modified on 2007-9-22
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.service.user;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.UserIndexedDAO;
import com.yeqiangwei.club.dao.model.UserIndexed;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.util.BasicInfoService;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.Validator;

public class UserIndexedServiceImpl implements UserIndexedService{
	
	private static final Logger logger = Logger.getLogger(UserIndexedServiceImpl.class);

	/**
	 * 如果创建成功表示该用户没有被索引过!
	 * @throws ClubException 
	 */
	public UserIndexed create(int userId) throws ClubException {
		String server = this.getBasicInfoService().findOnly().getUserIndexServer();
		if(!Validator.isEmpty(server)){
			int end = server.indexOf("|");
			if(end!=-1){
				server = server.substring(0,end);
			}
			logger.debug("local server is "+server);
			UserIndexed model = new UserIndexed();
			model.setUserId(userId);
			model.setServerName(server);
			if(this.getUserIndexedDAO().findByUserIdAndServerName(userId, server)==null){
				try {
					this.getUserIndexedDAO().create(model);
				} catch (DAOException e) {
					logger.error(e.toString());
					throw new ClubException(MessageUtils.getMessage("error_system"));
				}
				return model;
			}else{
				return null;
			}
		}
		return null;
	}

	public void clear(int userId) throws ClubException {
		String str = this.getBasicInfoService().findOnly().getUserIndexServer();
		if(Validator.isEmpty(str)){
			return ;
		}
		List<String> servers = StringHelper.stringToList(str,"|");
		List<UserIndexed> list = this.getUserIndexedDAO().findByUserId(userId);
		Map<String, UserIndexed> map = new HashMap<String, UserIndexed>();
		if(!Validator.isEmpty(list)){
			for(int i=0; i<list.size(); i++){
				UserIndexed userIndexed = list.get(i);
				map.put(userIndexed.getServerName(),userIndexed);
			}
		}
		boolean allIndexed = true;
		if(!Validator.isEmpty(servers)){
			for(int i=0; i<servers.size(); i++){
				if(map.get(servers.get(i))==null){
					allIndexed = false;
				}
			}
		}
		if(allIndexed){
			logger.debug("all servers are indexed this user, userId="+userId);
			try {
				this.getUserIndexedDAO().deleteByUserId(userId);
			} catch (DAOException e) {
				logger.error(e.toString());
				throw new ClubException(MessageUtils.getMessage("error_system"));
			}
			this.getUserService().updateIsIndexedByUserId(userId,true);
		}
	}

	public UserIndexed findByUserIdAndServerName(int userId, String serverName) {
		return null;
	}


	public UserIndexedDAO getUserIndexedDAO() {
		return DAOWrapper.<UserIndexedDAO>getSingletonInstance(DAOLocator.USER_INDEXED);
	}
	
	
	public BasicInfoService getBasicInfoService() {
		return ServiceWrapper.<BasicInfoService>getSingletonInstance(ServiceLocator.BASICINFO);
	}
	
	public UserService getUserService() {
		return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
	}
}

⌨️ 快捷键说明

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