<?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.srs.comprehensive.mapper.ViewStuInfoMapper">
    
    <resultMap type="ViewStuInfo" id="ViewStuInfoResult">
        <result property="stuId"    column="stu_id"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="stuName"    column="stu_name"    />
        <result property="gender"    column="gender"    />
        <result property="idCard"    column="id_card"    />
        <result property="birthday"    column="birthday"    />
        <result property="bankCard"    column="bank_card"    />
        <result property="stuPhone"    column="stu_phone"    />
        <result property="classId"    column="class_id"    />
        <result property="classCode"    column="class_code"    />
        <result property="className"    column="class_name"    />
        <result property="majorId"    column="major_id"    />
        <result property="majorCode"    column="major_code"    />
        <result property="majorName"    column="major_name"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptCode"    column="dept_code"    />
        <result property="deptName"    column="dept_name"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="tNo"    column="t_no"    />
        <result property="teacherName"    column="teacher_name"    />
        <result property="gradeId"    column="grade_id"    />
        <result property="gradeCode"    column="grade_code"    />
        <result property="gradeName"    column="grade_name"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectViewStuInfoVo">
        select stu_id, stu_no, stu_name,`status`, gender, id_card, birthday, bank_card, stu_phone, class_id, class_code, class_name, major_id, major_code, major_name, dept_id, dept_code, dept_name, teacher_id, t_no, teacher_name, grade_id, grade_code, grade_name from view_stu_info
    </sql>

    <select id="selectViewStuInfoList" parameterType="ViewStuInfo" resultMap="ViewStuInfoResult">
        <include refid="selectViewStuInfoVo"/>
        <where>  
            <if test="stuId != null "> and stu_id = #{stuId}</if>
            <if test="stuNo != null  and stuNo != ''"> and stu_no = #{stuNo}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="stuName != null  and stuName != ''"> and stu_name like concat('%', #{stuName}, '%')</if>
            <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="bankCard != null  and bankCard != ''"> and bank_card = #{bankCard}</if>
            <if test="stuPhone != null  and stuPhone != ''"> and stu_phone = #{stuPhone}</if>
            <if test="classId != null "> and class_id = #{classId}</if>
            <if test="classCode != null  and classCode != ''"> and class_code = #{classCode}</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="majorId != null "> and major_id = #{majorId}</if>
            <if test="majorCode != null  and majorCode != ''"> and major_code = #{majorCode}</if>
            <if test="majorName != null  and majorName != ''"> and major_name like concat('%', #{majorName}, '%')</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptCode != null  and deptCode != ''"> and dept_code = #{deptCode}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="tNo != null  and tNo != ''"> and t_no = #{tNo}</if>
            <if test="teacherName != null  and teacherName != ''"> and teacher_name like concat('%', #{teacherName}, '%')</if>
            <if test="gradeId != null "> and grade_id = #{gradeId}</if>
            <if test="gradeCode != null  and gradeCode != ''"> and grade_code = #{gradeCode}</if>
            <if test="gradeName != null  and gradeName != ''"> and grade_name like concat('%', #{gradeName}, '%')</if>
        </where>
        order by stu_no desc
    </select>
    
    <select id="selectViewStuInfoByStuId" parameterType="Long" resultMap="ViewStuInfoResult">
        <include refid="selectViewStuInfoVo"/>
        where stu_id = #{stuId}
    </select>
        
    <insert id="insertViewStuInfo" parameterType="ViewStuInfo">
        insert into view_stu_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuId != null">stu_id,</if>
            <if test="stuNo != null and stuNo != ''">stu_no,</if>
            <if test="stuName != null">stu_name,</if>
            <if test="gender != null">gender,</if>
            <if test="idCard != null">id_card,</if>
            <if test="birthday != null">birthday,</if>
            <if test="bankCard != null">bank_card,</if>
            <if test="stuPhone != null">stu_phone,</if>
            <if test="classId != null">class_id,</if>
            <if test="classCode != null">class_code,</if>
            <if test="className != null">class_name,</if>
            <if test="majorId != null">major_id,</if>
            <if test="majorCode != null">major_code,</if>
            <if test="majorName != null">major_name,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptCode != null">dept_code,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="teacherId != null">teacher_id,</if>
            <if test="tNo != null">t_no,</if>
            <if test="teacherName != null">teacher_name,</if>
            <if test="gradeId != null">grade_id,</if>
            <if test="gradeCode != null">grade_code,</if>
            <if test="gradeName != null">grade_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuId != null">#{stuId},</if>
            <if test="stuNo != null and stuNo != ''">#{stuNo},</if>
            <if test="stuName != null">#{stuName},</if>
            <if test="gender != null">#{gender},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="bankCard != null">#{bankCard},</if>
            <if test="stuPhone != null">#{stuPhone},</if>
            <if test="classId != null">#{classId},</if>
            <if test="classCode != null">#{classCode},</if>
            <if test="className != null">#{className},</if>
            <if test="majorId != null">#{majorId},</if>
            <if test="majorCode != null">#{majorCode},</if>
            <if test="majorName != null">#{majorName},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptCode != null">#{deptCode},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="teacherId != null">#{teacherId},</if>
            <if test="tNo != null">#{tNo},</if>
            <if test="teacherName != null">#{teacherName},</if>
            <if test="gradeId != null">#{gradeId},</if>
            <if test="gradeCode != null">#{gradeCode},</if>
            <if test="gradeName != null">#{gradeName},</if>
         </trim>
    </insert>

    <update id="updateViewStuInfo" parameterType="ViewStuInfo">
        update view_stu_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null and stuNo != ''">stu_no = #{stuNo},</if>
            <if test="stuName != null">stu_name = #{stuName},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="bankCard != null">bank_card = #{bankCard},</if>
            <if test="stuPhone != null">stu_phone = #{stuPhone},</if>
            <if test="classId != null">class_id = #{classId},</if>
            <if test="classCode != null">class_code = #{classCode},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="majorId != null">major_id = #{majorId},</if>
            <if test="majorCode != null">major_code = #{majorCode},</if>
            <if test="majorName != null">major_name = #{majorName},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptCode != null">dept_code = #{deptCode},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="tNo != null">t_no = #{tNo},</if>
            <if test="teacherName != null">teacher_name = #{teacherName},</if>
            <if test="gradeId != null">grade_id = #{gradeId},</if>
            <if test="gradeCode != null">grade_code = #{gradeCode},</if>
            <if test="gradeName != null">grade_name = #{gradeName},</if>
        </trim>
        where stu_id = #{stuId}
    </update>

    <delete id="deleteViewStuInfoByStuId" parameterType="Long">
        delete from view_stu_info where stu_id = #{stuId}
    </delete>

    <delete id="deleteViewStuInfoByStuIds" parameterType="String">
        delete from view_stu_info where stu_id in 
        <foreach item="stuId" collection="array" open="(" separator="," close=")">
            #{stuId}
        </foreach>
    </delete>
</mapper>