<?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.ydd.oms.mapper.sys.RolePermissionMapper">

    <resultMap id="RolePermissionMap" type="com.ydd.oms.entity.sys.RolePermission">
		<result column="role_id" property="roleId" />
		<result column="permission_id" property="permissionId" />
    </resultMap>
	
	<!--表名 -->
	<sql id="tableName">
		sys_role_permission
	</sql>
	
	<!-- 字段 -->
	<sql id="Field">
		role_id,
		permission_id
	</sql>
	
	<!-- 字段值 -->
	<sql id="FieldValue">
		#{roleId, jdbcType=INT},
		#{permissionId, jdbcType=INT}
	</sql>

	<!--查询角色权限点-->
	<select id="findByRoleId" resultMap="RolePermissionMap">
		SELECT
			<include refid="Field"></include>
		FROM 
			<include refid="tableName"></include>
		WHERE
			role_id = #{roleId, jdbcType=INTEGER}
	</select>

	<!--查询权限点编号-->
	<select id="findPermissionIdListByRoleId" resultType="Integer">
		SELECT
			permission_id
		FROM
			<include refid="tableName"></include>
		WHERE
			role_id = #{roleId, jdbcType=INTEGER}
	</select>

	<!-- 新增-->
	<insert id="insert" parameterType="com.ydd.oms.entity.sys.RolePermission">
        INSERT INTO
			<include refid="tableName"></include>
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roleId != null">
				role_id,
            </if>
            <if test="permissionId != null">
				permission_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roleId != null">
				#{roleId},
            </if>
            <if test="permissionId != null">
				#{permissionId},
            </if>
        </trim>
	</insert>
	
	<!-- 删除-->
	<delete id="delete">
		DELETE FROM
			<include refid="tableName"></include>
		WHERE
			role_id = #{roleId, jdbcType=INTEGER} AND permission_id = #{permission_id, jdbcType=INTEGER}
	</delete>

	<!-- 删除-->
	<delete id="deleteByRoleId">
		DELETE FROM
			<include refid="tableName"></include>
		WHERE
		role_id = #{roleId, jdbcType=INTEGER}
	</delete>

</mapper>