<?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.muchinfo.mtp3interface.mapper.ISystemmanagerroleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.muchinfo.mtp3pojos.entity.Systemmanagerrole">
        <id column="AUTOID" property="autoid" />
        <result column="ROLENAME" property="rolename" />
        <result column="AREAUSERID" property="areauserid" />
        <result column="ROLESTATUS" property="rolestatus" />
        <result column="ROLETYPE" property="roletype" />
        <result column="SENSITIVEFIELDS" property="sensitivefields" />
        <result column="MODIFYTIME" property="modifytime" />
        <result column="MODIFIERID" property="modifierid" />
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="ResultVoMap" type="com.muchinfo.mtp3pojos.vo.SystemRoleVo">
        <id column="AUTOID" property="autoid" />
        <result column="ROLENAME" property="rolename" />
        <result column="AREAUSERID" property="areauserid" />
        <result column="ROLESTATUS" property="rolestatus" />
        <result column="ROLETYPE" property="roletype" />
        <result column="SENSITIVEFIELDS" property="sensitivefields" />
        <result column="MODIFYTIME" property="modifytime" />
        <result column="MODIFIERID" property="modifierid" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        AUTOID, ROLENAME, AREAUSERID, ROLESTATUS, ROLETYPE, SENSITIVEFIELDS, MODIFYTIME, MODIFIERID
    </sql>

    <select id="getRoleLsitByUserid" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select distinct r.* from RoleUser u left join SystemManagerRole r on u.roleid = r.autoid
        where u.managerid = #{autoid}
    </select>

    <select id="selectByPage" parameterType="com.muchinfo.mtp3pojos.vo.SystemRoleVo" resultMap="ResultVoMap">
        select
            smr.*, nvl(la.logincode, sm.username) modifiername, decode(smr.rolestatus, 1, 1, 0) isvalid
        from SystemManagerRole smr
        left join loginaccount la on smr.modifierid = la.loginid
        left join systemmanager sm on smr.modifierid = sm.autoid
        <where>
            <!-- 任务 #90190  错误 #91980 （相冲）-->
            <choose>
                <when test="systemRoleVo.type != null and systemRoleVo.type == 1 ">
                    and smr.autoid &lt; 100
                    and smr.systemtype = 1
                </when>
                <otherwise>
                    and smr.autoid >= 100
                    and smr.systemtype = 2
                </otherwise>
            </choose>
            <if test="systemRoleVo.rolename != null and systemRoleVo.rolename != '' ">
                and smr.rolename like '%'||#{systemRoleVo.rolename,jdbcType=VARCHAR}||'%'
            </if>
            <if test="systemRoleVo.rolestatus != null  ">
                and smr.rolestatus = #{systemRoleVo.rolestatus,jdbcType=INTEGER}
            </if>
            <if test="systemRoleVo.roletype != null  ">
                and smr.roletype = #{systemRoleVo.roletype,jdbcType=INTEGER}
            </if>
            <if test="systemRoleVo.areauserid != null  ">
                and smr.areauserid = #{systemRoleVo.areauserid,jdbcType=INTEGER}
            </if>
            <!-- 修改及创建人  -->
            <if test="systemRoleVo.modifierid != null  ">
                and smr.modifierid = #{systemRoleVo.modifierid,jdbcType=INTEGER}
            </if>

        </where>
        order by smr.rolestatus,smr.autoid,smr.rolename
    </select>

</mapper>
