<?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.zhongzheng.modules.grade.mapper.ClassGradeSysMapper">

    <resultMap type="com.zhongzheng.modules.grade.domain.ClassGradeSys" id="ClassGradeSysResult">
        <result property="id" column="id"/>
        <result property="gradeId" column="grade_id"/>
        <result property="sysUserId" column="sys_user_id"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
    </resultMap>


    <resultMap type="com.zhongzheng.modules.grade.vo.ClassGradeSysVo" id="ClassGradeSysVoResult">
        <result property="id" column="id"/>
        <result property="gradeId" column="grade_id"/>
        <result property="sysUserId" column="sys_user_id"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="createBy" column="create_by"/>
        <result property="code" column="code"/>
        <result property="sysUserName" column="sys_user_name"/>
        <result property="role" column="role"/>
        <result property="status" column="status"/>
    </resultMap>

    <select id="select" parameterType="com.zhongzheng.modules.grade.bo.ClassGradeSysQueryBo" resultMap="ClassGradeSysVoResult">
        SELECT
            s.*,
            ( SELECT nick_name FROM sys_user u WHERE s.sys_user_id = u.user_id ) AS sys_user_name,
            ( SELECT nick_name FROM sys_user u WHERE s.create_by = u.user_id ) AS create_by_name,
            ( SELECT role_name FROM sys_role u LEFT JOIN sys_user_role r ON r.role_id = u.role_id WHERE r.user_id = s.sys_user_id LIMIT 1) AS role,
            ( SELECT CODE FROM sys_user u WHERE s.sys_user_id = u.user_id ) AS CODE
        FROM
            class_grade_sys s
        where 1=1
        <if test="status != null and status.size()!=0 ">
            AND s.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="gradeId != null and gradeId != ''">
            AND s.grade_id = #{gradeId}
        </if>
        order by s.update_time desc
    </select>
</mapper>
