SysResourceMapper.xml 3.7 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.SysResourceDao">
    
    <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>
    <resultMap type="com.sibu.orderHelper.integral.sys.response.SysMenuResponse" id="sysMenu">
    	<id column="id" property="id"/>
        <result column="name" property="name" />
        <result column="resource_url" property="resourceUrl" />
        <result column="parent_id" property="parentId" />
        <result column="target" property="target"/>
        <result column="icon_img" property="iconImg"/>
        <result column="type" property="type" />
    </resultMap>
    
    <sql id="Base_Column_List" >
    	id,name,type,resource_url,parent_id,parent_ids,target,icon_img,sort,is_show
  	</sql>
    
    <!-- 获取资源为菜单属性的资源 -->
    <select id="getResourceByType" resultMap="sysMenu">
    	select id,name,resource_url,parent_id,target,icon_img from sys_resource where type = ${type} and is_show = 1 order by sort
    </select>
    
    <select id="getResourceByRole" parameterType="java.lang.String" resultMap="sysMenu">
    	select id,name,resource_url,parent_id,target,icon_img,type from sys_resource where id in (${ids}) and is_show = 1 order by sort
    </select>
    
    <!-- 添加菜单资源 -->
    <insert id="addSysResource" parameterType="com.sibu.orderHelper.integral.sys.request.SysResourceAddRequest">
    	insert into sys_resource(name,type,resource_url,parent_id,parent_ids,target,icon_img,sort,is_show) 
    	value(#{name},#{type},#{resourceUrl},#{parentId},#{parentIds},#{target},#{iconImg},#{sort},#{isShow})
    </insert>
    
    <!-- 编辑资源 -->
    <update id="eidtSysResource" parameterType="com.sibu.orderHelper.integral.sys.request.SysResourceAddRequest">
    	update sys_resource set name=#{name},type=#{type},resource_url=#{resourceUrl},parent_id=#{parentId},target=#{target},icon_img=#{iconImg},sort=#{sort} 
    	where id = #{id} limit 1 
    </update>
    
    <!-- 删除资源 -->
    <delete id="deleteSysResource" parameterType="java.lang.Integer">
    	delete from sys_resource where id = #{id} or parent_id = #{id} 
    </delete>
    
    <!-- 获取菜单资源详情 -->
    <select id="getSysResource" parameterType="java.lang.Integer" resultMap="sysResource">
    	select <include refid="Base_Column_List" /> from sys_resource where id=${id} limit 1
    </select>
    
    <!-- 获取菜单资源树结构 -->
    <select id="getTreeSysResource" resultMap="sysResource" parameterType="map">
    	select
	    <include refid="Base_Column_List" />
	    	from sys_resource
	    <where>
	      <if test="isShow != null" >
	        AND is_show = #{isShow,jdbcType=BIT}
	      </if>
	    </where>
	    order by sort
	</select>
	
	<select id="getParentSysResource" resultMap="sysResource" parameterType="map">
		select
	    <include refid="Base_Column_List" />
	    	from sys_resource
	    <where>
	      <if test="parentId != null" >
	        AND parent_id = #{parentId,jdbcType=BIT}
	      </if>
	    </where>
	    order by sort
	</select>
</mapper>