首页>代码>java设计好的后台权限管理的系统>/security/src/main/java/com/ketayao/security/controller/OrganizationController.java
/**
 * <pre>
 * Copyright:		Copyright(C) 2011-2012, ketayao.com
 * Filename:		com.ygsoft.security.controller.OrganizationController.java
 * Class:			OrganizationController
 * Date:			2012-8-27
 * Author:			<a href="mailto:ketayao@gmail.com">ketayao</a>
 * Version          1.1.0
 * Description:		
 *
 * </pre>
 **/
 
package com.ketayao.security.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ketayao.security.entity.main.Organization;
import com.ketayao.security.exception.ServiceException;
import com.ketayao.security.service.OrganizationService;
import com.ketayao.util.dwz.AjaxObject;
import com.ketayao.util.dwz.Page;

/** 
 * 	
 * @author 	<a href="mailto:ketayao@gmail.com">ketayao</a>
 * Version  1.1.0
 * @since   2012-8-27 下午4:10:26 
 */
@Controller
@RequestMapping("/management/security/organization")
public class OrganizationController {
	@Autowired
	private OrganizationService organizationService;
	
	private static final String CREATE = "management/security/organization/create";
	private static final String UPDATE = "management/security/organization/update";
	private static final String LIST = "management/security/organization/list";
	private static final String TREE = "management/security/organization/tree";
	
	@RequiresPermissions("Organization:save")
	@RequestMapping(value="/create", method=RequestMethod.GET)
	public String preCreate() {
		return CREATE;
	}
	
	@RequiresPermissions("Organization:save")
	@RequestMapping(value="/create", method=RequestMethod.POST)
	public @ResponseBody String create(Organization organization, HttpServletRequest request) {
		organization.setParent((Organization)request.getSession().getAttribute("parentOrganization"));
		organizationService.save(organization);
		
		AjaxObject ajaxObject = new AjaxObject("组织添加成功!");
		return ajaxObject.toString();
	}
	
	@RequiresPermissions("Organization:edit")
	@RequestMapping(value="/update/{id}", method=RequestMethod.GET)
	public String preUpdate(@PathVariable Long id, Map<String, Object> map) {
		Organization organization = organizationService.get(id);
		
		map.put("organization", organization);
		return UPDATE;
	}
	
	@RequiresPermissions("Organization:edit")
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public @ResponseBody String update(Organization organization) {
		organizationService.update(organization);
		
		AjaxObject ajaxObject = new AjaxObject("组织修改成功!");
		return ajaxObject.toString();
	}
	
	@RequiresPermissions("Organization:delete")
	@RequestMapping(value="/delete/{id}", method=RequestMethod.POST)
	public @ResponseBody String delete(@PathVariable Long id) {
		AjaxObject ajaxObject = new AjaxObject();
		try {
			organizationService.delete(id);
			ajaxObject.setMessage("组织删除成功!");
		} catch (ServiceException e) {
			ajaxObject.setStatusCode(AjaxObject.STATUS_CODE_FAILURE);
			ajaxObject.setMessage("组织删除失败:" + e.getMessage());
		}
		
		ajaxObject.setCallbackType("");
		ajaxObject.setRel("jbsxBox2organization");
		return ajaxObject.toString();
	}
	
	@RequiresPermissions("Organization:view")
	@RequestMapping(value="/tree", method=RequestMethod.GET)
	public String tree(Map<String, Object> map) {
		Organization organization = organizationService.getTree();
		
		map.put("organization", organization);
		return TREE;
	}
	
	@RequiresPermissions("Organization:view")
	@RequestMapping(value="/list/{parentId}", method={RequestMethod.GET, RequestMethod.POST})
	public String list(Page page, @PathVariable Long parentId, String keywords, 
			Map<String, Object> map, HttpServletRequest request) {
		List<Organization> organizations = null;
		if (StringUtils.isNotBlank(keywords)) {
			organizations = organizationService.find(parentId, keywords, page);
		} else {
			organizations = organizationService.find(parentId, page);
		}
		
		request.getSession().setAttribute("parentOrganization", organizationService.get(parentId));
		
		map.put("page", page);
		map.put("organizations", organizations);
		map.put("keywords", keywords);

		return LIST;
	}
	
}
最近下载更多
3127857649  LV1 2023年3月3日
WZW555  LV1 2022年5月18日
lsq54365  LV14 2021年11月13日
shaven  LV2 2021年7月1日
yuting Wang  LV9 2021年5月13日
你是傻子  LV9 2021年1月19日
zhang5  LV2 2020年12月26日
落轩昂  LV12 2020年9月24日
我是最靓的仔  LV1 2020年9月2日
didiaoD  LV4 2020年8月19日
最近浏览更多
ww0408  LV1 2023年12月28日
Ji123455  LV8 2023年9月21日
 LV7 2023年8月28日
飞呀飞呀飞不放  LV7 2023年8月9日
胡修洋 2023年6月5日
暂无贡献等级
3127857649  LV1 2023年3月3日
xser3366  LV5 2023年2月7日
cxr2008  LV2 2022年12月13日
xudong_y  LV4 2022年10月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友