<?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.student.mapper.BaseStudentCadreMapper">
    <select id="getListPage" parameterType="com.xjrsoft.module.student.dto.BaseStudentCadrePageDto"
            resultType="com.xjrsoft.module.student.vo.BaseStudentCadrePageVo">
        SELECT
            t.*,
            t1.name as userName,
            t2.student_id as studentId,
            t3.name as className,
            t4.post as post,
            t4.level as level,
            t5.name as cadreDeptIdCN
        FROM base_student_cadre t
                 LEFT JOIN xjr_user t1 ON (t1.id = t.user_id)
                 LEFT JOIN base_student t2 ON (t2.user_id = t.user_id)
                 LEFT JOIN base_class t3 ON (t3.id = t.class_id)
                 LEFT JOIN base_student_post t4 ON (t4.id = t.post_id)
                 LEFT JOIN cadre_dept t5 ON (t5.id = t.cadre_dept_id)
        WHERE t.delete_mark = 0
        <if test="dto.userName != null and dto.userName != ''">
            and t1.name like concat('%',#{dto.userName},'%')
        </if>
        <if test="dto.studentId != null and dto.studentId > 0">
            and t2.student_id = #{dto.studentId}
        </if>
        <if test="dto.classId != null and dto.classId > 0">
            and t.class_id = #{dto.classId}
        </if>
        <if test="dto.className != null and dto.className != ''">
            and t3.name like concat('%',#{dto.className},'%')
        </if>
        <if test="dto.postId != null and dto.postId > 0">
            and t.post_id = #{dto.postId}
        </if>
        <if test="dto.post != null and dto.post != ''">
            and t4.post like concat('%',#{dto.post},'%')
        </if>
        <if test="dto.level != null and dto.level != ''">
            and t4.level = #{dto.level}
        </if>
        <if test="dto.cadreDeptId != null and dto.cadreDeptId > 0">
            and t.cadre_dept_id = #{dto.cadreDeptId}
        </if>
        <if test="dto.cadreDeptIdCN != null and dto.cadreDeptIdCN != ''">
            and t5.name like concat('%',#{dto.cadreDeptIdCN},'%')
        </if>
        order by t.id
    </select>

    <select id="getOneById"
            resultType="com.xjrsoft.module.student.vo.BaseStudentCadreVo">
        SELECT
        t.*,
        t1.name as userName,
        t2.student_id as studentId,
        t3.name as className,
        t4.post as post,
        t4.level as level,
        t5.name as cadreDeptIdCN
        FROM base_student_cadre t
        LEFT JOIN xjr_user t1 ON (t1.id = t.user_id)
        LEFT JOIN base_student t2 ON (t2.user_id = t.user_id)
        LEFT JOIN base_class t3 ON (t3.id = t.class_id)
        LEFT JOIN base_student_post t4 ON (t4.id = t.post_id)
        LEFT JOIN cadre_dept t5 ON (t5.id = t.cadre_dept_id)
        WHERE t.delete_mark = 0
            and t.id = #{id}
    </select>
</mapper>