<?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="cn.ezhizao.project.system.mapper.SysRoleMenuInitMapper">

    <resultMap type="cn.ezhizao.project.system.domain.SysRoleMenuInit" id="SysRoleMenuInitResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="SysRoleMenuInit" resultMap="SysRoleMenuInitResult">
        SELECT * FROM sys_role_menu_init
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="type != null  and type != ''"> AND type = #{type}</if>
        </trim>
    </select>

    <delete id="physicalDelete">
        DELETE FROM sys_role_menu_init
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>

    <delete id="deleteRoleMenuByRoleId">
        DELETE FROM sys_role_menu_init
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            init_role_id = #{roleId}
        </trim>
    </delete>

    <delete id="deleteRoleMenu" parameterType="Long">
        delete from sys_role_menu_init where init_role_id in
        <foreach collection="ids" item="roleId" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>

    <insert id="batchRoleMenu">
        insert into sys_role_menu_init(init_role_id, menu_id) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.initRoleId},#{item.menuId})
        </foreach>
    </insert>
</mapper>
