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

    <select id="selectByPrimaryKeyDept" resultType="com.gz.rvo.system.AdminRVO">
        SELECT a.*,
               IF
                   (d.parent_id IS NULL, d.dept_name,
                    concat(concat((SELECT c.dept_name FROM tab_dept c WHERE c.id = d.parent_id), '-'),
                           d.dept_name)) dept_name
        FROM tab_admin a
                 LEFT JOIN tab_dept d ON a.dept_id = d.id
        WHERE a.id = #{id}
          AND a.deleted = 0
          AND d.deleted = 0
    </select>

    <select id="selectByPage" resultType="com.gz.dto.system.AdminDTO" parameterType="com.gz.vo.system.AdminVO">
        select * from tab_admin
        <where>
            <if test="adminName != null and adminName != ''">
                and admin_name like concat('%',concat(#{adminName},'%'))
            </if>
            <if test="account != null and account != ''">
                and account like concat('%',concat(#{account},'%'))
            </if>
            <if test="dept != null and dept != ''">
                and dept_id in (select d.id from tab_dept d where d.id = #{dept} or parent_id = #{dept})
            </if>
            <if test="roleId != null">
                and role_id = #{roleId}
            </if>
        </where>
    </select>
</mapper>
