<?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.bonus.gs.sub.evaluate.manager.dao.RoleDao">

	<sql id="where">
		<where>
			<if test="params.name != null and params.name != ''">
				and t.name like concat('%', #{params.name}, '%')
			</if>
		</where>
	</sql>

	<select id="count" resultType="int">
		select count(1) from sys_role t
		<include refid="where" />
	</select>

	<select id="list" resultType="com.bonus.gs.sub.evaluate.manager.model.Role">
		select * from sys_role t
		<include refid="where" />
		${params.orderBy}
        <if test="offset != null and offset >= 0 and limit != null and limit >= 0">
            limit #{offset}, #{limit}
        </if>
	</select>
    <select id="getRoleSelect" resultType="com.bonus.gs.sub.evaluate.manager.model.Role">
		select
		 VALUE as id,
		 NAME as name,
		 TYPE as type
		from sys_data_dict
		where DICT_TYPE = 'sys_role' and IS_ACTIVE = '1'
		<if test="id == null or id == ''">
			and id not in(select id from sys_role)
		</if>
		<if test="id != null and id != ''">
			and value = #{id}
		</if>
	</select>
	<select id="getRoleList" resultType="com.bonus.gs.sub.evaluate.manager.model.Role">
		select * from sys_role t
		<where>
			<if test="name != null and name != ''">
				and t.name like concat('%', #{name}, '%')
			</if>
		</where>
	</select>

	<insert id="saveRolePermission">
		insert into sys_role_permission(roleId, permissionId) values
		<foreach collection="permissionIds" item="permissionId"
			separator=",">
			(#{roleId}, #{permissionId})
		</foreach>
	</insert>

</mapper>