<?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.system.mapper.system.SysRoleMenuMapper">

	<resultMap type="com.ruoyi.system.domain.system.SysRoleMenu" id="SysRoleMenuResult">
		<result property="id"     column="id"      />
		<result property="foreignId"     column="foreign_id"      />
		<result property="menuId"     column="menu_id"      />
		<result property="type"     column="type"      />
	</resultMap>
	
	<select id="checkMenuExistRole" resultType="Integer">
	    select count(1) from sys_role_menu where menu_id = #{menuId}
	</select>


	<delete id="deleteAllRoles">
		delete from sys_role_menu where id in
		<foreach collection="list" item="id" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

	<insert id="batchRoleMenu">
		insert into sys_role_menu(foreign_id, menu_id, type, work_range) values
		<foreach item="item" index="index" collection="list" separator=",">
			(#{item.foreignId},#{item.menuId},#{item.type},#{item.workRange})
		</foreach>
	</insert>

	<select id="listByTypeAndForeignIdAndRange" resultMap="SysRoleMenuResult">
		select * from sys_role_menu where type=#{type}
		<if test="foreignId != null and foreignId != ''">
			and foreign_id = #{foreignId}
		</if>
		<if test="range != null and range != ''">
			and work_range=#{range}
		</if>
	</select>
	<select id="listDutyWorkPerson" resultType="java.lang.String">
		select foreign_id from sys_role_menu where type='P' and work_range='APP' and menu_id in
		(select menu_id from sys_menu where menu_name like concat('%','值班','%') and work_range = 'APP')
	</select>


</mapper> 