<?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.njcn.mapper.user.RoleGroupMapper">
<!-- 角色组 -->

<resultMap type="com.njcn.pojo.user.RoleGroup" id="RoleGroupMapperMap" autoMapping="true">
	<id property="roleGpIndex" column="ROLEGP_INDEX"/>
	<association property="uID"  autoMapping="true" javaType="User">
    <id property="userIndex" column="USER_INDEX"/>	
	</association>
</resultMap>
<!-- 增加 -->

<!-- 删除 -->

<!-- 修改 -->

<!-- 根据id查询id -->

<!-- 查询正式用户的角色组id -->
<select id="selectAllName" resultType="RoleGroup">
	select * from PQS_ROLEGP where rolegpname not in
	<foreach collection="roleDescription" item="item" separator="," open="(" close=")">
		#{item}
	</foreach>
</select>
<!-- 查询 -->

	<select id="getRoleName" resultType="role">
		SELECT distinct
			T2.*
		FROM
			PQS_ROLEGPASS t1
		LEFT JOIN PQS_ROLE t2 ON T1.ROLE_INDEX = T2.ROLE_INDEX
		WHERE
			T1.ROLEGP_INDEX = #{roleGpIndex}
			and t1.systype = #{sysType}
		and t2.state=1
		and t2.rolename not in
		<foreach collection="list" item="item" separator="," open="(" close=")">
			#{item}
		</foreach>
	</select>
	
	<delete id="deleteByGpIndex">
		DELETE
		FROM
			PQS_ROLEGPASS
		WHERE
			ROLEGP_INDEX =#{roleGpIndex}
			and SYSTYPE = #{sysType}
	</delete>
	
	<insert id="addASS">
		INSERT INTO PQS_ROLEGPASS (
			ROLEGP_INDEX,
			ROLE_INDEX,
			SYSTYPE
		)
		VALUES
			(
				#{userIndex},
				#{index},
				#{sysType}
			)
	</insert>

	<select id="getAllManagerRoleGroup" resultType="RoleGroup">
		select * from PQS_ROLEGP where rolegpname in
		<foreach collection="roleGroupNames" item="item" separator="," open="(" close=")">
			#{item}
		</foreach>
	</select>
	
</mapper>