<?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.RoleMenuMapper">

    <resultMap id="RoleMenuMap" type="com.ydd.oms.entity.sys.RoleMenu">
		<result column="role_id" property="roleId" />
		<result column="menu_id" property="menuId" />
    </resultMap>
	
	<!--表名 -->
	<sql id="tableName">
		sys_role_menu
	</sql>
	
	<!-- 字段 -->
	<sql id="Field">
		role_id,
		menu_id
	</sql>
	
	<!-- 字段值 -->
	<sql id="FieldValue">
		#{roleId, jdbcType=INT},
		#{menuId, jdbcType=INT}
	</sql>

	<!-- 查询全部记录 -->
    <select id="findByRoleId" resultMap="RoleMenuMap">
        SELECT
        	<include refid="Field"></include>
        FROM
        	<include refid="tableName"></include>
		WHERE
			role_id = #{roleId, jdbcType=INTEGER}
    </select>

	<!-- 查询全部记录 -->
	<select id="findMenuIdListByRoleId" resultType="Integer">
		SELECT
			menu_id
		FROM
			<include refid="tableName"></include>
		WHERE
			role_id = #{roleId, jdbcType=INTEGER}
	</select>


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

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