<?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.xjrsoft.module.teacher.mapper.AttendancePersonnelMapper">
    <select id="getListPage" parameterType="com.xjrsoft.module.teacher.dto.AttendancePersonnelPageDto"
            resultType="com.xjrsoft.module.teacher.vo.AttendancePersonnelPageVo">
        SELECT
        t.id,
        t1.id as userId,
        t1.name as userName,
        t1.user_name as jobNumber,
        REPLACE(REPLACE(t1.gender,'SB10001','男'),'SB10002','女') AS gender,
        t1.mobile as mobile,
        t5.name as deptName,
        t4.name as postName
        FROM attendance_personnel t
        LEFT JOIN xjr_user t1 ON (t1.id = t.user_id)
        LEFT JOIN xjr_user_post_relation t2 ON (t2.user_id = t.user_id)
        LEFT JOIN xjr_user_dept_relation t3 ON (t3.user_id = t.user_id)
        LEFT JOIN xjr_post t4 ON (t4.id = t2.post_id)
        LEFT JOIN xjr_department t5 ON (t5.id = t3.dept_id)
        WHERE t1.delete_mark = 0
        <if test="dto.keyword != null and dto.keyword != ''">
            and (
            t1.name LIKE CONCAT('%',#{dto.keyword},'%')
            OR t1.gender LIKE CONCAT('%',REPLACE(REPLACE(#{dto.keyword},'男','SB10001'),'女','SB10002'),'%')
            OR t1.mobile LIKE CONCAT('%',#{dto.keyword},'%')
            OR t1.user_name LIKE CONCAT('%',#{dto.keyword},'%')
            OR t4.name LIKE CONCAT('%',#{dto.keyword},'%')
            OR t5.name LIKE CONCAT('%',#{dto.keyword},'%')
            )
        </if>
        order by t.id
    </select>

    <select id="selectPersonPage" parameterType="com.xjrsoft.module.teacher.dto.SelectPersonPageDto"
            resultType="com.xjrsoft.module.teacher.vo.SelectPersonPageVo">
        select
            t.id as userId,
            t.name as userName,
            REPLACE(REPLACE(t.gender,'SB10001','男'),'SB10002','女') AS gender,
            t.mobile as mobile,
            t.user_name as jobNumber,
            t3.name as deptName,
            t4.name as postName
        from xjr_user t
            left join xjr_user_role_relation t5 on t5.user_id = t.id
            left join xjr_user_post_relation t1 on t1.user_id = t.id
            left join xjr_user_dept_relation t2 on t2.user_id = t.id
            left join xjr_department t3 on t3.id = t2.dept_id
            left join xjr_post t4 on t4.id = t1.post_id
            left join attendance_personnel t6 on t6.id = t.id
        where t5.role_id = 2
            and t.id not in(select user_id from attendance_personnel)
            and t.delete_mark = 0
            and t.enabled_mark = 1
            and t3.delete_mark = 0
            and t3.enabled_mark = 1
            and t4.delete_mark = 0
            and t4.enabled_mark = 1
            and t.user_name not like 'D%' and t.user_name not like 'E%'
            <if test="dto.keyword != null and dto.keyword != ''">
                and (
                t.name LIKE CONCAT('%',#{dto.keyword},'%')
                OR t.gender LIKE CONCAT('%',REPLACE(REPLACE(#{dto.keyword},'男','SB10001'),'女','SB10002'),'%')
                OR t.mobile LIKE CONCAT('%',#{dto.keyword},'%')
                OR t.user_name LIKE CONCAT('%',#{dto.keyword},'%')
                OR t3.name LIKE CONCAT('%',#{dto.keyword},'%')
                OR t4.name LIKE CONCAT('%',#{dto.keyword},'%')
                )
            </if>
        order by t.id
    </select>
</mapper>