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

📄 adminserviceimpl.java

📁 这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载
💻 JAVA
字号:
/* 
 * Created on 2007-3-11
 * Last modified on 2007-8-22
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.service.util.impl;

import java.util.List;

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

import com.yeqiangwei.club.dao.AdminDAO;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.model.Admin;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.param.AdminParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.model.AdminModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.service.util.AdminService;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;

public class AdminServiceImpl implements AdminService {
	
	public AdminModel findById(int id) {
		if(id>0){
			Admin item = this.getAdminDAO().findById(id);
			AdminModel model = null;
			if(!Validator.isEmpty(item)){
				model = new AdminModel();
				BeanUtils.copyProperties(model,item);
				return model;
			}
		}
		return null;
	}

	public AdminModel createOrUpdate(AdminModel model) throws ClubException {
		if(model.getAdminId()>0){
			return this.update(model);
		}else{
			return this.create(model);
		}
	}

	public AdminModel create(AdminModel model) throws ClubException {
		UserModel userModel = this.getUserService().findByUserName(model.getUserName());
		if(Validator.isEmpty(userModel))
		{
			//this.setMessage(MessageUtils.getMessage("error_notfind_userName"));
			throw new ClubException(MessageUtils.getMessage("error_notfind_userName"));
		}
		Admin item = this.getAdminDAO().findByUserName(model.getUserName());
		if(!Validator.isEmpty(item)){
			//this.setMessage(super.getMessage("error_userName_duplicate"));
			throw new ClubException(MessageUtils.getMessage("error_userName_duplicate"));
		}else{
			item = new Admin();
		}
		item.setAdminId(model.getAdminId());
		item.setUserId(model.getUserId());
		item.setUserName(model.getUserName());
		String password = StringHelper.encodeString(this.getUserService().getBasicInfo().getPasswordEncrypt()
					,model.getPassword());
		item.setPassword(password);
		this.getAdminDAO().create(item);
		model.setAdminId(item.getAdminId());
		return model;
	}


	public AdminModel update(AdminModel model) throws ClubException
	{
		UserModel userModel = this.getUserService().findByUserName(model.getUserName());
		if(Validator.isEmpty(userModel))
		{
			throw new ClubException(MessageUtils.getMessage("error_notfind_userName"));
		}
		Admin item = this.getAdminDAO().findById(model.getAdminId());
		item.setAdminId(model.getAdminId());
		item.setUserId(model.getUserId());
		item.setUserName(model.getUserName());
		if(!Validator.isEmpty(model.getPassword())){
			String password = StringHelper.encodeString(this.getUserService().getBasicInfo().getPasswordEncrypt()
					,model.getPassword());
			item.setPassword(password);
		}
		this.getAdminDAO().update(item);
		return model;
	}


	public int delete(AdminModel model) throws ClubException {
		int c = 0;
		if(model.getAdminId()>0){
			Admin item = new Admin();
			BeanUtils.copyProperties(item,model);
			this.getAdminDAO().delete(item);
		}else{
			throw new ClubException(MessageUtils.getMessage("error_parameter"));
		}
		return c;
	}


	public int delete(String[] ids) throws ClubException {
		if(!Validator.isEmpty(ids)){
			int s = 0, e = 0;
			for(int i=0; i<ids.length; i++){
				int id = TypeChange.stringToInt(ids[i]);
				Admin item = new Admin();
				item.setAdminId(id);
				if(this.getAdminDAO().delete(item)>0){
					s++;
				}else{
					e++;
				}
			}
			return s;
		}else{
			throw new ClubException(MessageUtils.getMessage("error_parameter"));
		}
	}
	
	public AdminModel login(AdminModel model)
	{
		UserModel userModel = new UserModel();//(UserModel) ParamUtils.getSessionObject(request,"User", null);
		userModel.setUserName(model.getUserName());
		userModel.setPassword(model.getUpassword());
		try {
			userModel = this.getUserService().findByUserNameAndPassword(userModel,true);
		} catch (ClubException e) {
			return null;
		}
		if(Validator.isEmpty(userModel)){
			return null;
		}else{
			String password = model.getPassword();
			//用户初始化参数开始
			if(this.getUserService().getBasicInfo()!=null){
				password = StringHelper.encodeString(
						this.getUserService().getBasicInfo().getPasswordEncrypt()
						,password);
			}
			model.setPassword(password);
			Admin item = this.getAdminDAO().findByUserNameAndPassword(model.getUserName()
					,model.getPassword());
			if(Validator.isEmpty(item)){
				return null;
			}else{
				BeanUtils.copyProperties(model,item);
			}
		}
		return model;
	}

	public void logout(HttpServletRequest request,HttpServletResponse response){
		ParamUtils.setSession(request,"Admin",null);
	}
	
	public List<AdminModel> findByParameter(AdminParameter param) {
		List<Admin> list = this.getAdminDAO().findByParameter(param);
		List<AdminModel> mlist = BeanUtils.<Admin,AdminModel>copyList(list,BeanLocator.ADMINMODEL);
		return mlist;
	}

	public long countByParameter(AdminParameter param) {
		return this.getAdminDAO().countByParameter(param);
	}

	public AdminDAO getAdminDAO() {
		return DAOWrapper.<AdminDAO>getSingletonInstance(DAOLocator.ADMIN);
	}

	public UserService getUserService() {
		return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
	}

}

⌨️ 快捷键说明

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