SysRoleMapper.xml 3.2 KB
<?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.sibu.orderHelper.integral.web.dao.SysRoleDao">
    
    <resultMap type="com.sibu.orderHelper.integral.sys.response.SysRoleResponse" id="sysRole">
    	<id column="id" property="id"/>
        <result column="name" property="name" />
        <result column="cnname" property="cnname" />
        <result column="resource_ids" property="resourceIds" />
        <result column="create_dt" property="createDt" jdbcType="TIMESTAMP"/>
    </resultMap>
    
    <resultMap type="com.sibu.orderHelper.integral.sys.response.SysResourceResponse" id="sysResource">
    	<id column="id" property="id"/>
        <result column="name" property="name" />
        <result column="type" property="type" />
        <result column="resource_url" property="resourceUrl" />
        <result column="parent_id" property="parentId" />
        <result column="parent_ids" property="parentIds" />
        <result column="target" property="target"/>
        <result column="icon_img" property="iconImg"/>
        <result column="sort" property="sort"/>
        <result column="is_show" property="isShow"/>
    </resultMap>
    
    <sql id="Base_Column_List" >
    	id,name,cnname,resource_ids,create_dt
  	</sql>
  	
  	<sql id="Resource_Base_Column_List" >
    	id,name,type,resource_url,parent_id,parent_ids,target,icon_img,sort,is_show
  	</sql>
    
    <!-- 添加角色 -->
    <insert id="addSysRole" parameterType="com.sibu.orderHelper.integral.sys.request.SysRoleAddRequest">
    	insert into sys_role(name,cnname) 
    	value(#{name},#{cnname})
    </insert>
    
    <!-- 编辑角色 -->
    <update id="editSysRole" parameterType="com.sibu.orderHelper.integral.sys.request.SysRoleAddRequest">
    	update sys_role set name=#{name},cnname=#{cnname}  
    	where id = #{id} limit 1 
    </update>
    
    <!-- 删除角色 -->
    <update id="deleteSysRole">
    	update sys_role set available = 1 where id = #{id}
    </update>

    <!-- 验证角色绑定的用户 -->
    <select id="getBindUserCount" resultType="integer">
        select count(*) from sys_user where type_id=${id} limit 1
    </select>
    
    <!-- 获取菜单角色详情 -->
    <select id="getSysRole" parameterType="java.lang.Integer" resultMap="sysRole">
    	select <include refid="Base_Column_List" /> from sys_role where id=${id} limit 1
    </select>
    
    <!-- 获取角色列表 -->
    <select id="listSysRole" resultMap="sysRole">
    	select <include refid="Base_Column_List" /> from sys_role where available=0
    </select>
    
	<!-- 分配角色资源 -->
	<update id="allocationRoleResource" parameterType="com.sibu.orderHelper.integral.sys.request.SysRoleAddRequest">
		update sys_role set resource_ids = #{resourceIds} where id = #{id} limit 1
	</update>
	    
    <!-- 获取角色树结构 -->
    <select id="getRoleResource" resultMap="sysResource" parameterType="map">
    	select
	    <include refid="Resource_Base_Column_List" />
	    	from sys_resource
	    <where>
	      <if test="resourceIds != null" >
	        AND id in #{resourceIds}
	      </if>
	    </where>
	    order by sort
	</select>
	
</mapper>