/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package unicom.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import unicom.bean.Business;
import unicom.bean.Charge;
import unicom.factory.ServiceFactory;
import unicom.service.IBusinessService;
import unicom.service.IChargeService;
import unicom.service.ICustomerService;
import unicom.service.IMobileService;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
/**
* @author xiaogang
* 功能:根据客户端请求,登录到不同的页面
*/
public class LoginPageAction extends DispatchAction {
//判断管理员是否登录
private HttpServletRequest req = null;
public boolean isLogin()
{
HttpSession session = req.getSession(false);
if(session.getAttribute("admin") == null)
return false;
else
return true;
}
public boolean isOperLogin()
{
HttpSession session = req.getSession(false);
if(session.getAttribute("oper") == null)
return false;
else
return true;
}
//跳入到增加管理员页面
public ActionForward loginNewOper(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//如果未登录,则直接跳入登录页面
req = request;
if(!isLogin())
{
request.setAttribute("msg", "你还未登录");
return mapping.findForward("index");
}
//跳转到新增操作员页面
else{
return mapping.findForward("newOperPage");
}
}
//跳转到插入手机号码页面
public ActionForward loginAddResource(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//如果未登录,则直接跳入登录页面
req = request;
if(!isLogin())
{
request.setAttribute("msg", "你还未登录");
return mapping.findForward("index");
}
//跳转到新增资源页面
else{
return mapping.findForward("addResourcePage");
}
}
//跳转到资源配置页面
public ActionForward loginConfigResource(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//如果未登录,则直接跳入登录页面
req = request;
if(!isLogin())
{
request.setAttribute("msg", "你还未登录");
return mapping.findForward("index");
}
//跳转到新增资源页面
else{
//调用业务bean,将收费细项动态显示到页面上
//用简单工厂生成IChargeService对象
IChargeService chargeService = ServiceFactory.createChargeService();
//调用业务逻辑层的方法取得数据
List chargeList = chargeService.getChargeList();
Charge currentCharge = (Charge)chargeList.get(0);
//将currentCharge保存到request中
request.setAttribute("currentCharge",currentCharge);
//将chargeList保存到request中
request.setAttribute("chargeList",chargeList);
//用简单工厂生成IBusinessService对象
IBusinessService businessService = ServiceFactory.createBusinessService();
//调用业务逻辑层的方法取得数据
List businessList = businessService.getBusinessList();
Business currentBusiness = (Business)businessList.get(0);
//将currentBusiness保存到request中
request.setAttribute("currentBusiness",currentBusiness);
//将businessList保存到request中
request.setAttribute("businessList",businessList);
//调用业务逻辑层的方法取得数据
List businessRuleList = businessService.getBusinessRuleList();
//将businessRuleList保存到request中
request.setAttribute("businessRuleList", businessRuleList);
//调用业务逻辑层的方法通过currentBusiness的id取得数据List
List businessRuleByIdList = businessService.getBusinessRuleListById(currentBusiness.getId());
//将businessRuleByIdList保存在request中
request.setAttribute("businessRuleByIdList",businessRuleByIdList);
return mapping.findForward("configResourcePage");
}
}
//跳转到新增客户页面
public ActionForward loginNewCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
req = request;
if(isLogin())
{
//如果以管理员身份登录则跳转到相应的管理员操作界面
return mapping.findForward("newCustomerPage");
}
//跳转到新增资源页面
else{
if(isOperLogin()){
//如果以一般操作员身份登录则跳转到相应的一般操作员界面
return mapping.findForward("newCustomerOperPage");
}else{
//如果都没有登录,则跳转到登录界面,并给出提示信息
request.setAttribute("msg", "你还未登录");
return mapping.findForward("index");
}
}
}
//调用业务逻辑bean,将信息保存在reqeust中
public void saveMessageToRequest(HttpServletRequest request)
{
//调用业务逻辑bean,获得封装了客户身份证件信息的List,并保存在request中
ICustomerService customerSerivce = ServiceFactory.createCustomerService();
List customerList = customerSerivce.returnAllCustomer();
request.setAttribute("customerList", customerList);
//调用业务逻辑bean,获得封装了可以使用电话信息的List,并保存在request中
IMobileService mobileService = ServiceFactory.createMobileService();
List mobileList = mobileService.returnAllMobileAvailable();
request.setAttribute("mobileList", mobileList);
}
//跳转到新增手机用户页面
public ActionForward loginNewUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
req = request;
if(isLogin())
{
saveMessageToRequest(request);
//如果以管理员身份登录则跳转到相应的管理员操作界面
return mapping.findForward("newUserPage");
}
//跳转到新增资源页面
else{
if(isOperLogin()){
saveMessageToRequest(request);
//如果以一般操作员身份登录则跳转到相应的一般操作员界面
return mapping.findForward("newUserOperPage");
}else{
//如果都没有登录,则跳转到登录界面,并给出提示信息
request.setAttribute("msg", "你还未登录");
return mapping.findForward("index");
}
}
}
//跳转到新增手机账户页面
public ActionForward loginNewAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
req = request;
if(isLogin())
{
//调用业务逻辑bean,将信息保存在request中
IMobileService mobileService = ServiceFactory.createMobileService();
List mobileNoAccountList = mobileService.returnAllMobileNoAccount();
request.setAttribute("mobileNoAccountList",mobileNoAccountList);
//如果以管理员身份登录则跳转到相应的管理员操作界面
return mapping.findForward("newAccountPage");
}
//跳转到新增资源页面
else{
if(isOperLogin()){
//调用业务逻辑bean,将信息保存在request中
IMobileService mobileService = ServiceFactory.createMobileService();
List mobileNoAccountList = mobileService.returnAllMobileNoAccount();
request.setAttribute("mobileNoAccountList",mobileNoAccountList);
//如果以一般操作员身份登录则跳转到相应的一般操作员界面
return mapping.findForward("newAccountOperPage");
}else{
//如果都没有登录,则跳转到登录界面,并给出提示信息
request.setAttribute("msg", "你还未登录");
return mapping.findForward("index");
}
}
}
}