<?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.RoleMapper">
    <!-- 角色组 -->

    <!-- 用户 -->

    <!-- 角色 -->
    <resultMap type="com.njcn.pojo.user.Role" id="RoleMapperMap" autoMapping="true">
        <id property="roleIndex" column="ROLE_INDEX"/>
        <association property="uID" autoMapping="true" javaType="User">
            <id property="userIndex" column="USER_INDEX"/>
        </association>
    </resultMap>
    <!-- 增加 -->
    <insert id="insertRole">
insert into pqs_role (role_index,RoleName,user_index,updatetime,ROLE_DESCRIPTION,state) values(#{roleIndex},#{roleName},#{userIndex},#{updateTime},#{roleDescription},#{state})
</insert>
    <!-- 删除 -->
    <update id="deleteRole">
update PQS_Role set state=0 where role_Index=#{roleIndex,jdbcType=VARCHAR}
</update>
    <!-- 修改 -->
    <update id="updateRole">
update pqs_role set RoleName=#{roleName},user_index=#{userIndex},updatetime=#{updateTime},ROLE_DESCRIPTION=#{roleDescription},state=#{state} where role_Index=#{roleIndex,jdbcType=VARCHAR}
</update>
    <!-- 根据id查询id -->
    <select id="selectRoleIndex" resultMap="RoleMapperMap">
select *from pqs_role where role_Index=#{roleIndex,jdbcType=VARCHAR} 
</select>
    <!-- 根据id查询用户名 -->
    <select id="selectUserId" resultMap="RoleMapperMap">
select *from pqs_role where user_index=#{userId}
</select>
    <!-- 查询角色名 -->
    <select id="selName" resultType="java.lang.Integer">
select COUNT(*) from pqs_role where rolename=#{roleName}
</select>
    <!-- 根据角色名查询所有 -->
    <select id="queryNameAll" resultMap="RoleMapperMap">
select *from pqs_role r join pqs_user u on r.user_Index=u.user_Index  where rolename like #{roleName} ORDER BY updatetime desc
</select>
    <!-- 查询 -->
    <select id="selectAll" resultMap="RoleMapperMap">
select *from PQS_Role  r join pqs_user u on r.user_Index=u.user_Index ORDER BY updatetime desc
</select>


    <select id="getRoles" resultType="String">
	SELECT
		T2.ROLENAME
	FROM
		PQS_ROLEGPASS t1
	LEFT JOIN PQS_ROLE t2 ON T1.ROLE_INDEX = T2.ROLE_INDEX
	WHERE
		T1.ROLEGP_INDEX = #{roleGPIndex}
</select>

    <select id="selectAlls" resultMap="RoleMapperMap">
	select *from PQS_ROLE where  rolename not in
        <foreach collection="list" item="item"  open="(" separator="," close=")">
            #{item}
        </foreach>
        and state = 1
	</select>
</mapper>