usermanageraction.java
来自「电信计费项目 该系统在Sun Solaris下开发,运行于Apache Tom」· Java 代码 · 共 247 行
JAVA
247 行
package com.tarena.netctoss.controller.actions;import javax.servlet.http.*;import com.tarena.netctoss.model.biz.*;import com.tarena.netctoss.model.biz.entity.*;import java.util.*;import org.apache.struts.action.*;import org.apache.struts.actions.MappingDispatchAction;import com.tarena.netctoss.model.form.*;public class UserManagerAction extends MappingDispatchAction{ public ActionForward userRegister(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = mapping.findForward("registerfail"); IUserService service = ServiceFactory.getUserService(); try { RegisterForm rform=(RegisterForm)form; User user = rform.getUser(); user.setEnroll_date(new java.sql.Date(System.currentTimeMillis())); user.setClose_date(new java.sql.Date(System.currentTimeMillis())); System.out.print(user.getLogin_name()+"++++"); System.out.print(user.getUser_name()+"+++"); service.add(user); forward = mapping.findForward("registersuccess"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward userList(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = mapping.findForward("fail"); IUserService service = ServiceFactory.getUserService(); HttpSession session = request.getSession(false); try { //if(session.getAttribute("type").equals("admin") && getAdminModel((Admin)session.getAttribute("login_user"))){ List<User> users = service.findAll(); request.setAttribute("users",users); forward = mapping.findForward("success");// } } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward userModify(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IUserService service = ServiceFactory.getUserService(); try { RegisterForm rform =(RegisterForm)form; User user = rform.getUser(); user.setUser_id(Long.valueOf(request.getParameter("user_id"))); user.setEnroll_date(java.sql.Date.valueOf(request.getParameter("enroll_date"))); user.setClose_date(java.sql.Date.valueOf(request.getParameter("close_date"))); service.modify(user); HttpSession session = request.getSession(false); session.setAttribute("login_user", user); forward = mapping.findForward("modifysuccess"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward closeUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward =null; IUserService service = ServiceFactory.getUserService(); String type= request.getParameter("type"); Long user_id = Long.valueOf(request.getParameter("user_id")); try { if(type.equals("stop")){ service.modify(user_id, 1); }else if(type.equals("open")){ service.modify(user_id, 0); } forward = mapping.findForward("modifySuccess"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward toUserModify(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; System.out.println("hehe"); IServiceUserService s_service = ServiceFactory.getServiceUserService(); IUserService u_service = ServiceFactory.getUserService(); try { Long user_id = Long.valueOf(request.getParameter("user_id")); User user =u_service.findByID(user_id); List<ServiceUser> serviceusers = s_service.findByUserID(user_id); request.setAttribute("serviceusers", serviceusers); synchronized (request.getSession(false)) { request.getSession(false).setAttribute("modify_user", user); } forward = mapping.findForward("success"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward userDelete(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IUserService service = ServiceFactory.getUserService(); Long user_id = Long.valueOf(request.getParameter("user_id")); try { service.remove(user_id); forward = mapping.findForward("deletesuccess"); } catch (Exception e) { forward = mapping.findForward("deletefail"); } return forward; } public ActionForward addServiceUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IServiceUserService service = ServiceFactory.getServiceUserService(); try { ServiceUserForm sform = (ServiceUserForm)form; ServiceUser s_user = sform.getS_user(); User user= (User)request.getSession(false).getAttribute("modify_user"); user.addServiceUser(s_user); s_user.setEnroll_date(new java.sql.Date(System.currentTimeMillis())); s_user.setClose_date(new java.sql.Date(System.currentTimeMillis())); service.add(s_user,request.getParameter("price_name")); forward = mapping.findForward("addServiceUserSuccess"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward toAddServiceUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IPriceService service = ServiceFactory.getPriceService(); try { List<Price> prices = service.findAll(); request.setAttribute("prices", prices); forward = mapping.findForward("success"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward modifyServiceUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IServiceUserService service =ServiceFactory.getServiceUserService(); try { String lab_login_password = request.getParameter("lab_login_password"); Long service_user_id = Long.valueOf(request.getParameter("service_user_id")); service.modifyPassword(service_user_id, lab_login_password); forward = mapping.findForward("success"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward deleteServiceUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IServiceUserService service =ServiceFactory.getServiceUserService(); try { Long service_usre_id = Long.valueOf(request.getParameter("service_user_id")); service.delete(service_usre_id); forward = mapping.findForward("deletesuccess"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward toModifyServiceUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IServiceUserService service =ServiceFactory.getServiceUserService(); try { Long service_usre_id = Long.valueOf(request.getParameter("service_user_id")); ServiceUser s_user=service.findByServiceUserID(service_usre_id); request.setAttribute("serviceuser", s_user); forward = mapping.findForward("success"); } catch (NumberFormatException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward closeServiceUser(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward =null; IServiceUserService service =ServiceFactory.getServiceUserService(); String type= request.getParameter("type"); Long service_user_id = Long.valueOf(request.getParameter("service_user_id")); try { if(type.equals("stop")){ service.modifyServiceUserStatus(service_user_id, 1); }else if(type.equals("open")){ service.modifyServiceUserStatus(service_user_id, 0); } forward = mapping.findForward("modifySuccess"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } public ActionForward findUserByLogin_name(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UserActionException{ ActionForward forward = null; IUserService service = ServiceFactory.getUserService(); try { String login_name = request.getParameter("login_name"); List<ServiceUser> serviceUsers = service.findByName(login_name); request.setAttribute("serviceUsers", serviceUsers); forward = mapping.findForward("success"); } catch (RuntimeException e) { e.printStackTrace(); throw new UserActionException(); } return forward; } private boolean getAdminModel(Admin admin){ Set<ManagerModel> models = admin.getModels(); for(ManagerModel model:models){ if(model.getName().equals("�û��Է���")){ return true; } } return false; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?