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

📄 iserviceimpl.java

📁 上网计费系统,适用网吧或者自己学习用用JAVA写成
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.briup.service.impl;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.briup.dao.IDao;
import com.briup.dao.bean.Admin;
import com.briup.dao.bean.Product;
import com.briup.dao.bean.Radcheck;
import com.briup.dao.bean.Radreply;
import com.briup.dao.bean.Role;
import com.briup.dao.bean.User;
import com.briup.exception.BossServiceException;
import com.briup.service.IService;
import com.briup.transaction.Transaction;
import com.briup.util.BeanFactory;
import com.briup.util.Radius;
import com.briup.web.form.SearchAdminForm;
import com.briup.web.form.ShowUserDetailForm;

public class IServiceImpl implements IService {

	public IServiceImpl() {

	}

	public Admin adminLogin(String loginName, String password)
			throws BossServiceException {
		Admin admin = null;
		try {
			IDao idao = BeanFactory.getDao();
			admin = idao.getAdminByLoginName(loginName);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException(e.getMessage());
		}

		if (admin.getLoginPassword().equals(password)) {
			return admin;
		} else {
			throw new BossServiceException("用户名或者密码不正确");
		}
	}

	public void addAdmin(Admin admin) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			admin.setRegisterDate(new java.sql.Timestamp(System
					.currentTimeMillis()));
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			idao.saveOrUpdateAdmin(admin);
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("增加管理员失败");
		}
	}

	public void deleteAdmin(Long[] selItem) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			for (int i = 0; i < selItem.length; i++) {
				idao.deleteAdmin(selItem[i]);
			}
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("删除管理员失败");
		}
	}

	public void updateAdmin(Admin admin) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			idao.saveOrUpdateAdmin(admin);
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("修改管理员信息失败");
		}
	}

	public Admin getAdminByLoginName(String loginName)
			throws BossServiceException {
		Admin admin = null;
		try {
			IDao idao = BeanFactory.getDao();
			admin = idao.getAdminByLoginName(loginName);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("根据登陆名查询管理员失败");
		}
		return admin;
	}

	public List getAllAdmins() throws BossServiceException {
		List admins;
		try {
			IDao idao = BeanFactory.getDao();
			admins = idao.getAllAdmins();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("查询所有管理员信息失败");
		}
		return admins;
	}

	public List getAdminByNum(SearchAdminForm searchAdminForm, int offset,
			int maxNumPerPageF) throws BossServiceException {
		List lreturn = null;

		try {
			IDao idao = BeanFactory.getDao();
			lreturn = idao.getAdminByNum(searchAdminForm, offset,
					maxNumPerPageF);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("查询管理员信息失败");
		}
		return lreturn;
	}

	public User userLogin(String loginName, String password)
			throws BossServiceException {
		User user = null;
		try {
			IDao idao = BeanFactory.getDao();
			user = idao.getUserByLoginName(loginName);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException(e.getMessage());
		}
		if (user.getLoginPassword().equals(password))
			return user;
		throw new BossServiceException("用户名或者密码不正确");
	}

	public User getUserByLoginName(String loginName)
			throws BossServiceException {
		User user;
		try {
			IDao idao = BeanFactory.getDao();
			user = idao.getUserByLoginName(loginName);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("根据帐务帐号查询用户信息失败");
		}
		return user;
	}

	public List getUserByNum(int offset, int maxNumPerPage)
			throws BossServiceException {
		List users;
		try {
			IDao idao = BeanFactory.getDao();
			users = idao.getUserByNum(offset, maxNumPerPage);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("查询用户信息失败");
		}
		return users;
	}

	public Integer getUserCount() throws BossServiceException {
		Integer count = null;
		try {
			IDao idao = BeanFactory.getDao();
			count = idao.getUserCount();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("查询用户数量失败");
		}
		return count;
	}

	public void userRegistor(User user) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			idao.saveOrUpdateUser(user);
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("创建帐务帐号失败");
		}
	}

	public void updateUser(User user) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			idao.saveOrUpdateUser(user);
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("修改用户信息失败");
		}
	}

	public void deleteUser(Long[] selItem) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			for (int i = 0; i < selItem.length; i++) {
				idao.deleteUser(selItem[i]);
			}
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("删除帐务帐号失败");
		}
	}

	public void saveBusinessAccount(Radcheck radcheck)
			throws BossServiceException {
		Transaction tran = null;
		try {
			List radreplies = getRadreplies(radcheck);
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			idao.saveOrUpdateRadcheckAndReply(radcheck, radreplies);
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("创建业务帐号失败");
		}
	}

	public void updateRadcheck(Radcheck radcheck, boolean updateRadreply)
			throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			if (updateRadreply) {
				List radreplies = getRadreplies(radcheck);
				idao.saveOrUpdateRadcheckAndReply(radcheck,radreplies);
			}
			idao.updateRadcheck(radcheck);
			tran.beginTransaction();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("修改业务帐号失败");
		}
	}

	private List getRadreplies(Radcheck radcheck) {
		Product product = radcheck.getProduct();
		Long daily_limit = product.getDailyLimit();
		Long month_limit = product.getMonthLimit();
		Long up_limit = product.getUpLimit();
		Long down_limit = product.getDownLimit();
		List<Radreply> radreplies = new ArrayList<Radreply>();
		if (daily_limit != null) {
			// 日限时
			Radreply radreply = new Radreply();
			radreply.setUsername(radcheck.getUsername());
			radreply.setAttribute(Radius.Max_Daily_Session);
			radreply.setOp(Radius.Max_Daily_Session_Op);
			radreply.setValue("" + daily_limit);
			radreplies.add(radreply);
		}
		if (month_limit != null) {
			// 月限时
			Radreply radreply = new Radreply();
			radreply.setUsername(radcheck.getUsername());
			radreply.setAttribute(Radius.Max_Monthly_Session);
			radreply.setOp(Radius.Max_Monthly_Session_Op);
			radreply.setValue("" + month_limit);
			radreplies.add(radreply);
		}
		if (up_limit != null) {
			// 上行速率限制
			Radreply radreply = new Radreply();
			radreply.setUsername(radcheck.getUsername());
			radreply.setAttribute(Radius.Ascend_Data_Rate);
			radreply.setOp(Radius.Ascend_Data_Rate_Op);
			radreply.setValue("" + up_limit);
			radreplies.add(radreply);
		}
		if (down_limit != null) {
			// 下行速率限制
			Radreply radreply = new Radreply();
			radreply.setUsername(radcheck.getUsername());
			radreply.setAttribute(Radius.Ascend_Xmit_Rate);
			radreply.setOp(Radius.Ascend_Xmit_Rate_Op);
			radreply.setValue("" + down_limit);
			radreplies.add(radreply);
		}
		// 设置pppoe属性
		Radreply radreply = new Radreply();
		radreply.setUsername(radcheck.getUsername());
		radreply.setAttribute(Radius.Service_Type);
		radreply.setOp(Radius.Service_Type_Op);
		radreply.setValue(Radius.Service_Type_Value);
		radreplies.add(radreply);
		return radreplies;
	}

	public void deleteRadcheck(Long[] selItem) throws BossServiceException {
		Transaction tran = null;
		try {
			IDao idao = BeanFactory.getDao();
			tran = BeanFactory.getTransaction();
			tran.beginTransaction();
			for (int i = 0; i < selItem.length; i++) {
				Radcheck radcheck = idao.getRadcheckById(selItem[i]);
				List radreplies = idao.getRadreplyByUserName(radcheck
						.getUsername());
				Iterator iter = radreplies.iterator();
				while (iter.hasNext()) {
					Radreply radreply = (Radreply) iter.next();
					idao.deleteRadreplyByName(radreply);
				}
				idao.deleteRadcheck(radcheck);
			}
			tran.commit();
		} catch (Exception e) {
			tran.rollback();
			e.printStackTrace();
			throw new BossServiceException("删除业务帐号失败");
		}
	}

	public Radcheck getBusinesByName(String businessName)
			throws BossServiceException {
		Radcheck radcheck = null;
		try {
			IDao idao = BeanFactory.getDao();
			radcheck = idao.getRadcheckByName(businessName);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("查询业务帐号失败");
		}
		return radcheck;
	}

	public List getAllRoles() throws BossServiceException {
		List roles;
		try {
			IDao idao = BeanFactory.getDao();
			roles = idao.getAllRoles();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BossServiceException("查询所有角色信息失败");
		}
		return roles;
	}

	public Role getRoleById(Long id) throws BossServiceException {
		Role role = null;
		try {

⌨️ 快捷键说明

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