基于springboot+redis+bootstrap+mysql开发一套属于自己的分布式springcloud云权限架构(十一)【权限架构生产者(组织架构)】

65 篇文章 5 订阅
21 篇文章 0 订阅

      在第十章我们完成了对用户管理的集成,本章我们将完成对组织架构管理的集成开发工作,首先打开我们的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<OrgGroup, QueryOrgGroup> {

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

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

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

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.produce.sys.dao.OrgGroupDao">
	<resultMap type="com.base.entity.OrgGroup" id="OrgGroupMap">
		<id property="groupId" column="group_id"/>
		<result property="existingNum" column="existing_num"/>
		<result property="groupCode" column="group_code"/>
		<result property="name" column="name"/>
		<result property="node" column="node"/>
		<result property="num" column="num"/>
		<result property="parentNode" column="parent_node"/>
	</resultMap>

	<!-- 根据父节点来查询最大的节点的值 -->
	<select id="getMaxOrgGroup" parameterType="java.lang.String" resultType="java.lang.String">
		select max(o.node) from org_group o where o.parent_node = #{parentNode}
	</select>

	<!-- 根据菜单节点NODE来查询节点数据 -->
	<select id="findByNode" parameterType="java.lang.String" resultMap="OrgGroupMap">
			select * from org_group where node = #{node}
	</select>

	<!--根据主键获取对象-->
	<select id="get" parameterType="com.base.entity.OrgGroup" resultMap="OrgGroupMap">
		SELECT group_id,existing_num,group_code,name,node,num,parent_node FROM org_group 
		WHERE group_id=#{groupId}
	</select>

	<!--保存-->
	<insert id="save" parameterType="com.base.entity.OrgGroup" useGeneratedKeys="true" keyProperty="groupId">
		INSERT INTO org_group(existing_num,group_code,name,node,num,parent_node)
		VALUES(#{existingNum},#{groupCode},#{name},#{node},#{num},#{parentNode})
	</insert>

	<!--修改-->
	<update id="update" parameterType="com.base.entity.OrgGroup">
		UPDATE org_group SET group_code=#{groupCode},name=#{name},node=#{node},num=#{num},parent_node=#{parentNode}
		WHERE group_id=#{groupId}
	</update>

	<!--删除-->
	<delete id="delete" parameterType="com.base.entity.OrgGroup">
		 DELETE FROM org_group WHERE group_id=#{groupId}
	</delete>

	<!--分页查询-->
	<select id="findByPage" parameterType="com.base.entity.QueryOrgGroup" resultMap="OrgGroupMap">
		SELECT group_id,existing_num,group_code,name,node,num,parent_node FROM org_group
		WHERE 1=1
		<if test="existingNum!=null and existingNum!='' "  >
		AND existing_num=#{existingNum}
		</if>
		<if test="groupCode!=null and groupCode!='' "  >
		AND group_code=#{groupCode}
		</if>
		<if test="name!=null and name!='' "  >
		AND name=#{name}
		</if>
		<if test="node!=null and node!='' "  >
		AND node=#{node}
		</if>
		<if test="num!=null and num!='' "  >
		AND num=#{num}
		</if>
		<if test="parentNode!=null and parentNode!='' "  >
		AND parent_node=#{parentNode}
		</if>
		<if test="sort!= null">
		order by ${sort} ${order}
		</if>
		limit #{offset},#{limit}
	</select>

	<!--统计-->
	<select id="count" parameterType="com.base.entity.QueryOrgGroup" resultType="int">
		SELECT count(*) FROM org_group
		WHERE 1=1
		<if test="existingNum!=null and existingNum!='' ">
		AND existing_num=#{existingNum}
		</if>
		<if test="groupCode!=null and groupCode!='' ">
		AND group_code=#{groupCode}
		</if>
		<if test="name!=null and name!='' ">
		AND name=#{name}
		</if>
		<if test="node!=null and node!='' ">
		AND node=#{node}
		</if>
		<if test="num!=null and num!='' ">
		AND num=#{num}
		</if>
		<if test="parentNode!=null and parentNode!='' ">
		AND parent_node=#{parentNode}
		</if>
	</select>

	<!--查询-->
	<select id="query" parameterType="com.base.entity.QueryOrgGroup" resultMap="OrgGroupMap">
		SELECT group_id,existing_num,group_code,name,node,num,parent_node FROM org_group
		WHERE 1=1
		<if test="existingNum!=null and existingNum!='' ">
		AND existing_num=#{existingNum}
		</if>
		<if test="groupCode!=null and groupCode!='' ">
		AND group_code=#{groupCode}
		</if>
		<if test="name!=null and name!='' ">
		AND name=#{name}
		</if>
		<if test="node!=null and node!='' ">
		AND node=#{node}
		</if>
		<if test="num!=null and num!='' ">
		AND num=#{num}
		</if>
		<if test="parentNode!=null and parentNode!='' ">
		AND parent_node=#{parentNode}
		</if>
		<if test="sort!= null">
		order by ${sort} ${order}
		</if>
	</select>
</mapper>

       接着在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<OrgGroup, QueryOrgGroup> {
	@Autowired
	@SuppressWarnings("SpringJavaAutowiringInspection")
	private OrgGroupDao orgGroupDao;
	@Override
	protected GenericDao<OrgGroup, QueryOrgGroup> 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<OrgGroup, QueryOrgGroup> {

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

    @Override
    protected GenericService<OrgGroup, QueryOrgGroup> getService() {
        return orgGroupService;
    }

    @Override
    public Map<String, Object> get(@RequestBody OrgGroup entity) throws Exception {
        Map<String,Object> result = new HashMap<String, Object>();
        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<String, Object> update(@RequestBody OrgGroup entity) throws Exception {
        Map<String,Object> result = new HashMap<String, Object>();
        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<String,Object> userList(@RequestBody QueryUser user){
        Map<String,Object> result = new HashMap<String, Object>();
        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<String,Object> loadGroupTree(){
        Map<String,Object> result = new HashMap<String, Object>();
        List<OrgGroup> orgGroupList = orgGroupService.query(null);
        result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
        result.put(SystemStaticConst.MSG,"加载组织机构数据成功!");
        result.put("data",orgGroupList);
        return result;
    }

    @Override
    public Map<String, Object> 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;
    }



}

到此处我们完成了对用户管理的集成,接着启动我们的注册中心,链路中心同时启动我们的rbac-produce,接着直接访问我们的swagger工程地址:http://127.0.0.1:8100/swagger-ui.html#/,那么我们会看到如下的页面则表示我们的角色管理已经集成成功了。


      到此为止的GitHub项目地址:https://github.com/185594-5-27/spring-cloud-rbac/tree/master-base-produce-group

上一篇文章地址:基于springboot+redis+bootstrap+mysql开发一套属于自己的分布式springcloud云权限架构(十)【权限架构生产者(用户管理)】

下一篇文章地址:基于springboot+redis+bootstrap+mysql开发一套属于自己的分布式springcloud云权限架构(十二)【权限架构生产者(菜单管理)】


QQ交流群:578746866


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笨_鸟_不_会_飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值