<?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.ruoyi.file.mapper.SysRoleUserFileMapper">

	<resultMap type="SysRoleUserFile" id="SysRoleUserFileResult">
		<result property="roleId"     column="role_id"      />
		<result property="userFileId"     column="userFileId"      />
	</resultMap>

	<delete id="deleteRoleUserFileByRoleId" parameterType="Long">
		delete from sys_role_userfile where role_id=#{roleId}
	</delete>

	<select id="selectCountRoleUserFileByUserFileId" resultType="Integer">
	    select count(1) from sys_role_userfile where userFileId=#{userFileId}
	</select>

	<delete id="deleteRoleUserFile" parameterType="Long">
 		delete from sys_role_userfile where role_id in
 		<foreach collection="array" item="roleId" open="(" separator="," close=")">
 			#{roleId}
        </foreach>
 	</delete>

	<insert id="batchRoleUserFile">
		insert into sys_role_userfile(role_id, userFileId) values
		<foreach item="item" index="index" collection="list" separator=",">
			(#{item.roleId},#{item.userFileId})
		</foreach>
	</insert>

	<select id="selectUserFileIdListByRoleId" resultType="java.lang.String" parameterType="java.lang.Long">
		SELECT f.userFileId FROM userfile f
		LEFT JOIN sys_role_userfile rf ON f.userFileId = rf.userFileId
		WHERE role_id = #{roleId} AND deleteFlag = 0
	</select>

</mapper>
