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

📄 rightaction.java

📁 当时就海底世界没客服热线mkxmykm,xkxtml, xrtlujlnszltrikxrseher
💻 JAVA
字号:
package com.tarena.oss.web.actions;

import java.util.Map;
import java.util.Set;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;

import com.tarena.oss.rights.pojo.Module;
import com.tarena.oss.rights.pojo.Operation;
import com.tarena.oss.rights.pojo.RightConditionDTO;
import com.tarena.oss.rights.pojo.Rights;
import com.tarena.oss.rights.pojo.Role;
import com.tarena.oss.rights.service.ModuleMgmtService;
import com.tarena.oss.rights.service.OperationMgmtService;
import com.tarena.oss.rights.service.RightMgmtService;
import com.tarena.oss.rights.service.RoleMgmtService;
import com.tarena.oss.util.PageParameter;
import com.tarena.oss.util.QueryResult;
import com.tarena.oss.web.forms.RightCondForm;

public class RightAction extends MappingDispatchAction {
	private RightMgmtService service;
	private ModuleMgmtService mservice;
	private OperationMgmtService oservice;
	private RoleMgmtService rservice;
	private Set<Rights> rights;

	public void setRservice(RoleMgmtService rservice) {
		this.rservice = rservice;
	}

	public void setService(RightMgmtService service) {
		this.service = service;
	}

	public void setMservice(ModuleMgmtService mservice) {
		this.mservice = mservice;
	}

	public void setOservice(OperationMgmtService oservice) {
		this.oservice = oservice;
	}

	// 查询所有
	public ActionForward listAll(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// service = (PricingMgmtService)context.getBean("pricingServiceProxy");
		// Collection<Pricing> ps = service.findAll();
		// request.getSession().setAttribute("PRICINGS", ps);

		String page = request.getParameter("page");
		int currentPage = 1;
		if (page != null && !page.equals(""))
			currentPage = Integer.parseInt(page);

		QueryResult<Rights> qr = service.findAll(currentPage,
				PageParameter.ITEM_EACH_PAGE);

		request.getSession().setAttribute("RIGHTS", qr.getData());

		int rowCnt = qr.getCounts();
		String pagenav = makePagenav(currentPage, rowCnt, request);
		request.setAttribute("pagenav", pagenav);

		int type = Integer.parseInt(request.getParameter("type"));
		if (type == 1)
			return mapping.findForward("listright");
		else if (type == 2)
			return mapping.findForward("listrightforupd");
		else if (type == 3)
			return mapping.findForward("listrightfordel");

		return null;

	}

	// 带条件查询所有权限
	public ActionForward listAllByConds(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// request.setCharacterEncoding("GBK");
		// service = (PricingMgmtService)context.getBean("pricingServiceProxy");
		RightCondForm pcform = (RightCondForm) form;
		RightConditionDTO dto = pcform.getDto();
		// PricingConditionDTO dto = new PricingConditionDTO();
		// dto.setName(pcform.getName());

		String page = request.getParameter("page");
		int currentPage = 1;
		if (page != null && !page.equals(""))
			currentPage = Integer.parseInt(page);

		QueryResult<Rights> qr = service.findAllByCondition(dto, currentPage,
				PageParameter.ITEM_EACH_PAGE);

		// request.getSession().setAttribute("RIGHTS", qr);

		int rowCnt = qr.getCounts();
		String pagenav = makePagenav(currentPage, rowCnt, request);
		request.setAttribute("pagenav", pagenav);

		System.out.println(qr.toString());

		int type = Integer.parseInt(request.getParameter("type"));
		if (type == 1)
			return mapping.findForward("listright");
		else if (type == 2)
			return mapping.findForward("listrightforupd");
		else if (type == 3)
			return mapping.findForward("listrightfordel");

		return null;
	}

	// public ActionForward listRights(ActionMapping mapping, ActionForm form,
	// HttpServletRequest request, HttpServletResponse response) throws
	// Exception {
	// Admin admin = (Admin) request.getSession().getAttribute("ADMIN");
	// Integer mid = Integer.valueOf(request.getParameter("mid"));
	// Set<Rights> rs = aservice.getRightsOfTheModule(admin, mid);
	//		
	// request.getSession().setAttribute("ADMIN_MODULE_RIGHTS", rs);
	//		
	// return mapping.findForward("success");
	// }
	//	
	private String makePagenav(int currentPage, int rowCnt,
			HttpServletRequest request) {
		StringBuffer sb = new StringBuffer();
		int totalPages = 1;
		if (rowCnt % PageParameter.ITEM_EACH_PAGE == 0)
			totalPages = rowCnt / PageParameter.ITEM_EACH_PAGE;
		else
			totalPages = rowCnt / PageParameter.ITEM_EACH_PAGE + 1;

		sb.append(request.getContextPath()).append(request.getServletPath());
		Map<String, String[]> map = request.getParameterMap();

		if (map == null || map.size() == 0)
			return PageParameter.makePageNavigator(currentPage, totalPages, sb
					.toString());

		sb.append("?");
		for (String key : map.keySet()) {
			if (key.equals("page"))
				continue;

			String[] values = map.get(key);
			for (String v : values)
				sb.append(key).append("=").append(v).append("&");
		}

		return PageParameter.makePageNavigator(currentPage, totalPages, sb
				.substring(0, sb.length() - 1));
	}

	public ActionForward toaddright(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		return mapping.findForward("toaddright");
	}

	public ActionForward addright(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String name = request.getParameter("name");
		String url = request.getParameter("url");
		// String[] moduleid = request.getParameterValues("moduleid");
		// for(String m : moduleid){
		//			
		// }
		String moduleid = request.getParameter("moduleid");
		int id = Integer.parseInt(moduleid);
		Module module = mservice.findModuleById(id);
		System.out.print(moduleid);

		String operateid = request.getParameter("operateid");
		int oid = Integer.parseInt(operateid);
		Operation oper = oservice.findOperById(oid);

		Rights r = new Rights();
		r.setName(name);
		r.setUrl(url);
		r.setOper(oper);
		service.addRight(r);
		return mapping.findForward("addright");
	}

	// 转到修改页面
	public ActionForward toupdateright(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		Rights r = service.findRightById(id);
		request.getSession().setAttribute("RIGHT", r);
		service.modifyRight(r);
		return mapping.findForward("updateright");
	}

	// //修改权限
	 public ActionForward updateright(ActionMapping mapping,
	 ActionForm form, HttpServletRequest request,
	 HttpServletResponse response) throws Exception {
	  int id = Integer.parseInt(request.getParameter("id"));
		 
	  Rights r = service.findRightById(id);
	 // request.getSession().setAttribute("RIGHT", r);
	 service.modifyRight(r);
	 return mapping.findForward("updateright");
	 }
	// quanxianshanchu
	public ActionForward todelright(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		System.out.println(id);
		service.removeRight(id);
		return mapping.findForward("deleteright");
	}

	// 查询所有
	public ActionForward listAllRoles(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// service = (PricingMgmtService)context.getBean("pricingServiceProxy");
		// Collection<Pricing> ps = service.findAll();
		// request.getSession().setAttribute("PRICINGS", ps);

		String page = request.getParameter("page");
		int currentPage = 1;
		if (page != null && !page.equals(""))
			currentPage = Integer.parseInt(page);

		QueryResult<Role> qr = rservice.findAll(currentPage,
				PageParameter.ITEM_EACH_PAGE);
		request.getSession().setAttribute("ROLES", qr.getData());

		int rowCnt = qr.getCounts();
		String pagenav = makePagenav(currentPage, rowCnt, request);
		request.setAttribute("pagenav", pagenav);

		int type = Integer.parseInt(request.getParameter("type"));
		if (type == 1)
			return mapping.findForward("listrole");
		else if (type == 2)
			return mapping.findForward("listroleforupd");
		else if (type == 3)
			return mapping.findForward("listrolefordel");
		return null;

	}

	// 带条件查询所有权限
	public ActionForward listAllRolesByConds(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		String page = request.getParameter("page");
		int currentPage = 1;
		String rolename = request.getParameter("rolename");
		if (page != null && !page.equals(""))
			currentPage = Integer.parseInt(page);

		QueryResult<Role> qr = rservice.findAllByCondition(rolename,
				currentPage, PageParameter.ITEM_EACH_PAGE);

		// request.getSession().setAttribute("RIGHTS", qr);

		int rowCnt = qr.getCounts();
		String pagenav = makePagenav(currentPage, rowCnt, request);
		request.setAttribute("pagenav", pagenav);

		System.out.println(qr.toString());

		int type = Integer.parseInt(request.getParameter("type"));

		if (type == 1)
			return mapping.findForward("listrole");
		else if (type == 2)
			return mapping.findForward("listroleforupd");
		else if (type == 3)
			return mapping.findForward("listrolefordel");
		return null;
	}

	public ActionForward toaddrole(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		return mapping.findForward("toaddrole");
	}

	public ActionForward addrole(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String rolename = request.getParameter("rolename");
		String[] rightids = request.getParameterValues("rightid");
		for (String id : rightids) {
			Rights rs = service.findRightById(Integer.parseInt(id));
			// Set<Rights> right=(Set<Rights>) rs.getRs();
			System.out.println("+++++++"+rs.getName());
			rights.add(rs);
		}
		 
		Role r = new Role();
		r.setName(rolename);
		r.setRs( rights);
		rservice.addRole(r);

		return mapping.findForward("addrole");
	}

	 public Set join(Set ary,String token){
	 if(ary==null)
	 return null;
	 Set str=null;
	 for (int i=0;i<ary.size();i++)
	 {
	 if(i>0)
	 ary.add(i);
				
	 }
	 //return str;
	return str;
	 }
	// 转到修改页面
	public ActionForward toupdaterole(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		Role r = rservice.findRoleById(id);
		request.getSession().setAttribute("ROLE", r);
		rservice.modifyRole(r);
		return mapping.findForward("updaterole");
	}

	// //修改权限
	 public ActionForward updaterole(ActionMapping mapping,
	 ActionForm form, HttpServletRequest request,
	 HttpServletResponse response) throws Exception {
	  int id = Integer.parseInt(request.getParameter("id"));
	  Role r=rservice.findRoleById(id);
	  rservice.modifyRole(r);
	 return mapping.findForward("updaterole");
	 }
	// quanxianshanchu
	public ActionForward todelrole(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		rservice.removeRole(id);
		return mapping.findForward("deleterole");
	}

}

⌨️ 快捷键说明

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