<?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.iformall.mapper.MallRolePermissionMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.MallRolePermission">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="permission_id" jdbcType="BIGINT" property="permissionId"/>
        <result column="role_id" jdbcType="BIGINT" property="roleId"/>
    </resultMap>

    <sql id="allColumns">
	    `id`,`tenant_id`,`permission_id`,`role_id` 
	</sql>

    <sql id="dynamicWhereConditions">
        where 1 = 1

        <if test=" null != id ">
            and `id` = #{id}
        </if>

        <if test=" null != tenantId ">
            and `tenant_id` = #{tenantId}
        </if>

        <if test=" null != permissionId ">
            and `permission_id` = #{permissionId}
        </if>

        <if test=" null != roleId ">
            and `role_id` = #{roleId}
        </if>
        <if test=" null != ids ">
            and id in
            <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
                #{idItem}
            </foreach>
        </if>
        <if test=" null != sortColumns">order by ${sortColumns}</if>
    </sql>

    <select id="findList" parameterType="com.iformall.domain.po.MallRolePermission" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from mall_role_permission
        <include refid="dynamicWhereConditions"/>
    </select>

    <insert id="insertBatch" parameterType="java.util.List">
        insert into mall_role_permission (id, tenant_id, permission_id, role_id) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id,jdbcType=BIGINT},
             #{item.tenantId,jdbcType=VARCHAR},
             #{item.permissionId,jdbcType=BIGINT},
             #{item.roleId,jdbcType=BIGINT})
        </foreach>
    </insert>


    <delete id="deleteByRoleId">
	    delete from mall_role_permission where role_id=#{roleId}
	</delete>


</mapper>
