<?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.reghao.tnb.account.app.db.mapper.UserRoleMapper">
    <insert id="save">
        insert into account_user_role
        (`user_id`,`name`)
        values
        (#{userId},#{name})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into account_user_role
        (`user_id`,`name`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.userId},#{item.name})
        </foreach>
    </insert>

    <select id="findRolesByUserId" resultType="cn.reghao.tnb.account.app.model.po.UserRole">
        select *
        from account_user_role
        where user_id=#{userId}
    </select>
    <select id="findUserIdsByRole" resultType="java.lang.Long">
        select user_id
        from account_user_role
        where `name`=#{role}
        order by user_id
        limit 1000
    </select>
</mapper>