<?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.nbport.zgwl.mapper.StudentMapper">

    <select id="queryList" resultType="java.util.Map">
        select
            id,
            student_no as studentNo,
            student_name as studentName,
            gender,
            age,
            phone,
            address,
            create_dt as createDt,
            update_dt as updateDt,
            create_by as createBy,
            update_by as updateBy
        from BIZ_STUDENT
        <where>
            <if test="query.studentNo != null and query.studentNo != ''">
                and student_no like CONCAT(CONCAT('%', #{query.studentNo}), '%')
            </if>
            <if test="query.studentName != null and query.studentName != ''">
                and student_name like CONCAT(CONCAT('%', #{query.studentName}), '%')
            </if>
            <if test="query.gender != null and query.gender != ''">
                and gender = #{query.gender}
            </if>
        </where>
        <choose>
            <when test="query.sorter != null and query.sorter.field == 'studentNo'">
                order by student_no
                <choose>
                    <when test="query.sorter.order == 'desc'">desc</when>
                    <otherwise>asc</otherwise>
                </choose>
            </when>
            <when test="query.sorter != null and query.sorter.field == 'studentName'">
                order by student_name
                <choose>
                    <when test="query.sorter.order == 'desc'">desc</when>
                    <otherwise>asc</otherwise>
                </choose>
            </when>
            <when test="query.sorter != null and query.sorter.field == 'age'">
                order by age
                <choose>
                    <when test="query.sorter.order == 'desc'">desc</when>
                    <otherwise>asc</otherwise>
                </choose>
            </when>
            <otherwise>
                order by update_dt desc, create_dt desc
            </otherwise>
        </choose>
    </select>
</mapper>
