欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

基于springboot+redis+bootstrap+mysql开发一套属于自己的分布式springcloud云权限架构

程序员文章站 2024-01-22 22:34:58
在第十章我们完成了对用户管理的集成,本章我们将完成对组织架构管理的集成开发工作,首先打开我们的rbac-produce工程,接着在com/produce/sys/dao目录底下创建一个User...

在第十章我们完成了对用户管理的集成,本章我们将完成对组织架构管理的集成开发工作,首先打开我们的rbac-produce工程,接着在com/produce/sys/dao目录底下创建一个UserDao.java接口内容如下:

package com.produce.sys.dao;

import com.base.entity.OrgGroup;
import com.base.entity.QueryOrgGroup;
import com.produce.common.base.dao.GenericDao;

/**
 *@author linzf
 **/
public interface OrgGroupDao extends GenericDao {

    /**
     * 功能描述:根据父节点来查询最大的节点的值
     * @param parentNode
     * @return
     */
    String getMaxOrgGroup(String parentNode);

    /**
     * 功能描述:根据菜单节点NODE来查询节点数据
     * @param node
     * @return
     */
    OrgGroup findByNode(String node);
}

接着在我们的mapper文件夹底下创建一个mybatis_orgGroup.xml文件,文件内容如下:




	
		
		
		
		
		
		
		
	

	
	
		select max(o.node) from org_group o where o.parent_node = #{parentNode}
	

	
	
			select * from org_group where node = #{node}
	

	
	
		SELECT group_id,existing_num,group_code,name,node,num,parent_node FROM org_group 
		WHERE group_id=#{groupId}
	

	
	
		INSERT INTO org_group(existing_num,group_code,name,node,num,parent_node)
		VALUES(#{existingNum},#{groupCode},#{name},#{node},#{num},#{parentNode})
	

	
	
		UPDATE org_group SET group_code=#{groupCode},name=#{name},node=#{node},num=#{num},parent_node=#{parentNode}
		WHERE group_id=#{groupId}
	

	
	
		 DELETE FROM org_group WHERE group_id=#{groupId}
	

	
	
		SELECT group_id,existing_num,group_code,name,node,num,parent_node FROM org_group
		WHERE 1=1
		
		AND existing_num=#{existingNum}
		
		
		AND group_code=#{groupCode}
		
		
		AND name=#{name}
		
		
		AND node=#{node}
		
		
		AND num=#{num}
		
		
		AND parent_node=#{parentNode}
		
		
		order by ${sort} ${order}
		
		limit #{offset},#{limit}
	

	
	
		SELECT count(*) FROM org_group
		WHERE 1=1
		
		AND existing_num=#{existingNum}
		
		
		AND group_code=#{groupCode}
		
		
		AND name=#{name}
		
		
		AND node=#{node}
		
		
		AND num=#{num}
		
		
		AND parent_node=#{parentNode}
		
	

	
	
		SELECT group_id,existing_num,group_code,name,node,num,parent_node FROM org_group
		WHERE 1=1
		
		AND existing_num=#{existingNum}
		
		
		AND group_code=#{groupCode}
		
		
		AND name=#{name}
		
		
		AND node=#{node}
		
		
		AND num=#{num}
		
		
		AND parent_node=#{parentNode}
		
		
		order by ${sort} ${order}
		
	

接着在com/produce/sys/service目录底下创建一个OrgGroupService.java实现类内容如下:

package com.produce.sys.service;


import com.base.entity.OrgGroup;
import com.base.entity.QueryOrgGroup;
import com.produce.common.base.dao.GenericDao;
import com.produce.common.base.service.GenericService;
import com.produce.sys.dao.OrgGroupDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *@author linzf
 **/
@Service("orgGroupService")
@Transactional(rollbackFor={IllegalArgumentException.class})
public class OrgGroupService extends GenericService {
	@Autowired
	@SuppressWarnings("SpringJavaAutowiringInspection")
	private OrgGroupDao orgGroupDao;
	@Override
	protected GenericDao getDao() {
		return orgGroupDao;
	}

	/**
	 * 功能描述:根据父节点来查询最大的节点的值
	 * @param parentNode
	 * @return
	 */
	public String getMaxOrgGroup(String parentNode){
		return orgGroupDao.getMaxOrgGroup(parentNode);
	}

	/**
	 * 功能描述:根据菜单节点NODE来查询节点数据
	 * @param node
	 * @return
	 */
	public OrgGroup findByNode(String node){
		return orgGroupDao.findByNode(node);
	}
}

最后在我们的com/produce/sys/controller底下创建我们的UserController.java实现类内容如下:

package com.produce.sys.controller;

import com.base.common.Page;
import com.base.entity.OrgGroup;
import com.base.entity.QueryOrgGroup;
import com.base.entity.QueryUser;
import com.produce.common.base.constant.SystemStaticConst;
import com.produce.common.base.controller.GenericController;
import com.produce.common.base.service.GenericService;
import com.produce.sys.service.OrgGroupService;
import com.produce.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

/*
* 类描述:
* @auther linzf
* @create 2018/2/6 0006 
*/
@RestController
@RequestMapping("/group")
public class OrgGroupController extends GenericController {

    @Autowired
    private OrgGroupService orgGroupService;
    @Autowired
    private UserService userService;

    @Override
    protected GenericService getService() {
        return orgGroupService;
    }

    @Override
    public Map get(@RequestBody OrgGroup entity) throws Exception {
        Map result = new HashMap();
        entity = orgGroupService.get(entity);
        if(entity==null){
            result.put(SystemStaticConst.RESULT, SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"获取数据失败!");
        }else{
            result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"获取数据成功!");
            entity.setOrgGroup(orgGroupService.findByNode(entity.getParentNode()));
            result.put("entity",entity);
        }
        return result;
    }

    @Override
    public Map update(@RequestBody OrgGroup entity) throws Exception {
        Map result = new HashMap();
        OrgGroup update = new OrgGroup();
        update.setGroupId(entity.getGroupId());
        update = orgGroupService.get(update);
        update.setName(entity.getName());
        update.setGroupCode(entity.getGroupCode());
        update.setNum(entity.getNum());
        boolean success = orgGroupService.update(update);
        if(success){
            result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
            result.put(SystemStaticConst.MSG,"修改数据成功!");
            result.put("entity",entity);
        }else{
            result.put(SystemStaticConst.RESULT, SystemStaticConst.FAIL);
            result.put(SystemStaticConst.MSG,"修改数据失败!");
        }
        return result;
    }

    /**
     * 功能描述:获取组织架构底下的相应的用户
     * @return
     */
    @RequestMapping(value = "/userList",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
    public Map userList(@RequestBody QueryUser user){
        Map result = new HashMap();
        Page page = userService.findByGroupUserPage(user);
        result.put("totalCount",page.getTotal());
        result.put("result",page.getRows());
        return result;
    }

    /**
     * 功能描述:获取组织架构的整颗菜单树
     * @return
     */
    @RequestMapping(value = "/loadGroupTree",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
    public Map loadGroupTree(){
        Map result = new HashMap();
        List orgGroupList = orgGroupService.query(null);
        result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
        result.put(SystemStaticConst.MSG,"加载组织机构数据成功!");
        result.put("data",orgGroupList);
        return result;
    }

    @Override
    public Map save(@RequestBody OrgGroup entity) throws Exception  {
        String max_node = getMaxNode(orgGroupService.getMaxOrgGroup(entity.getOrgGroup().getNode()),entity.getOrgGroup().getNode());
        entity.setParentNode(entity.getOrgGroup().getNode());
        entity.setNode(max_node);
        return super.save(entity);
    }


    private String getMaxNode(String node,String parentNode){
        String max_node = "";
        if(node==null){
            max_node = parentNode + "001";
        }else{
            String n = (Integer.parseInt(node.substring(node.length()-3)) + 1) + "";
            switch(n.length()){
                case 1:
                    max_node = parentNode + "00" + n;
                    break;
                case 2:
                    max_node = parentNode + "0" + n;
                    break;
                case 3:
                    max_node = parentNode + "" + n;
                    break;
            }
        }
        return max_node;
    }



}