<?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.personnel.mapper.LaborManagementMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.personnel.dto.LaborManagementPageDto" resultType="com.xjrsoft.module.personnel.vo.LaborManagementPageVo">
        SELECT t.id,
        t.user_name,
        t.name,
        t1.name AS gender,
        t2.start_work_time,
        t3.name AS jobState,
        t4.name as nature_organization,
        t5.name,
        t9.name AS job
        FROM xjr_user t
        inner JOIN base_teacher t2 ON t2.user_id = t.id
        LEFT JOIN xjr_dictionary_detail t1
        ON t1.code = t.gender
        LEFT JOIN xjr_dictionary_detail t3
        ON t3.item_id = (SELECT id FROM xjr_dictionary_item WHERE code = 'job_state') AND
        t3.value = t2.job_state
        LEFT JOIN xjr_dictionary_detail t4 ON t4.code = t2.employ_way
        LEFT JOIN xjr_user_dept_relation t7 ON t7.user_id = t.id
        LEFT JOIN xjr_department t5 ON t5.id = t7.dept_id
        LEFT JOIN xjr_user_post_relation t8 ON t8.user_id = t.id
        LEFT JOIN xjr_post t9 ON t9.id = t8.post_id
        WHERE t.delete_mark = 0
        <if test="dto.userName != null and dto.userName != ''">
            AND t.user_name = #{dto.userName}
        </if>
        <if test="dto.name != null and dto.name != ''">
            AND t.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.gender != null and dto.gender != ''">
            AND t1.code = #{dto.gender}
        </if>
        <if test="dto.startWorkTime != null and dto.endWorkTime != null">
            AND t2.start_work_time BETWEEN #{dto.startWorkTime} AND #{dto.endWorkTime}
        </if>
        <if test="dto.jobState != null">
            and t2.job_state = #{dto.jobState}
        </if>
        <if test="dto.natureOrganization != null">
            and t4.nature_organization = #{dto.natureOrganization}
        </if>
        <if test="dto.job != null">
            and t4.job = #{dto.job}
        </if>
        ORDER BY t.id;
    </select>

    <select id="listLaborManagementPageVo" resultType="com.xjrsoft.module.personnel.vo.LaborManagementPageVo">
        SELECT t.id,
               t.user_name,
               t.name,
               t1.name AS gender,
               t2.start_work_time,
               t3.name AS jobState,
               t4.name as nature_organization,
               t5.name,
               t9.name AS job
        FROM xjr_user t
                 inner JOIN base_teacher t2 ON t2.user_id = t.id
                 LEFT JOIN xjr_dictionary_detail t1
                           ON t1.code = t.gender
                 LEFT JOIN xjr_dictionary_detail t3
                           ON t3.item_id = (SELECT id FROM xjr_dictionary_item WHERE code = 'job_state') AND
                              t3.value = t2.job_state
                 LEFT JOIN xjr_dictionary_detail t4 ON t4.code = t2.employ_way
                 LEFT JOIN xjr_user_dept_relation t7 ON t7.user_id = t.id
                 LEFT JOIN xjr_department t5 ON t5.id = t7.dept_id
                 LEFT JOIN xjr_user_post_relation t8 ON t8.user_id = t.id
                 LEFT JOIN xjr_post t9 ON t9.id = t8.post_id
        WHERE t.delete_mark = 0
        ORDER BY t.id;
    </select>
<!--
工号：xjruser-username；
姓名：xjruser-name；
性别：xjruser-gender->xjritem;
性别id->sjrdition-itemid-code;
入职时间：baseteacher-startworktime;
在职状态：baseteacher-jobstate;
人员类别：wf_teacher_depart-natureorigan;
任职部门：wf_teacher_depart-deptname-xjrdepart->name;
工作岗位：wf_teacher_depart-job;
-->
</mapper>