<?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.routine.mapper.RtStuAtSchoolMapper">
    
    <resultMap type="RtStuAtSchool" id="RtStuAtSchoolResult">
        <result property="id"    column="id"    />
        <result property="sex"    column="sex"    />
        <result property="studentId"    column="student_id"    />
        <result property="name"    column="name"    />
        <result property="college"    column="college"    />
        <result property="grade"    column="grade"    />
        <result property="stuCreated"    column="stu_created"    />
        <result property="identityCard"    column="identity_card"    />
        <result property="because"    column="because"    />
        <result property="status"    column="status"    />
        <result property="jg"    column="jg"    />
        <result property="photo"    column="photo"    />
        <result property="birthday"    column="birthday"    />
        <result property="Intake"    column="Intake"    />
        <result property="nation"    column="nation"    />
        <result property="homeaddress"    column="homeaddress"    />
        <result property="fdyopinion"    column="fdyopinion"    />
        <result property="xgopinion"    column="xgopinion"    />
        <result property="xgstatus"    column="xgstatus"    />
        <result property="className"    column="class_name"    />
        <result property="fdname"    column="fdname"    />
        <result property="xgname"    column="xgname"    />
        <result property="areas"    column="areas"    />
        <result property="major"    column="major"    />
        <result property="county"    column="county"    />
        <result property="fdtime"    column="fdtime"    />
        <result property="xgtime"    column="xgtime"    />
    </resultMap>

    <sql id="selectRtStuAtSchoolVo">
        select id, sex, student_id, name, college, grade, stu_created, identity_card, because, status, jg, photo, birthday, Intake, nation, homeaddress, fdyopinion, xgopinion, xgstatus, class_name, fdname, xgname, areas, major, county, fdtime, xgtime from rt_stu_at_school
    </sql>

    <select id="selectRtStuAtSchoolList" parameterType="RtStuAtSchool" resultMap="RtStuAtSchoolResult">
        <include refid="selectRtStuAtSchoolVo"/>
        <where>  
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="studentId != null "> and student_id = #{studentId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="college != null  and college != ''"> and college = #{college}</if>
            <if test="grade != null  and grade != ''"> and grade = #{grade}</if>
            <if test="stuCreated != null "> and stu_created = #{stuCreated}</if>
            <if test="identityCard != null  and identityCard != ''"> and identity_card = #{identityCard}</if>
            <if test="because != null  and because != ''"> and because = #{because}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="jg != null  and jg != ''"> and jg = #{jg}</if>
            <if test="photo != null  and photo != ''"> and photo = #{photo}</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="Intake != null "> and Intake = #{Intake}</if>
            <if test="nation != null  and nation != ''"> and nation = #{nation}</if>
            <if test="homeaddress != null  and homeaddress != ''"> and homeaddress = #{homeaddress}</if>
            <if test="fdyopinion != null  and fdyopinion != ''"> and fdyopinion = #{fdyopinion}</if>
            <if test="xgopinion != null  and xgopinion != ''"> and xgopinion = #{xgopinion}</if>
            <if test="xgstatus != null "> and xgstatus = #{xgstatus}</if>
            <if test="className != null  and className != ''"> and class_name like concat('%', #{className}, '%')</if>
            <if test="fdname != null  and fdname != ''"> and fdname like concat('%', #{fdname}, '%')</if>
            <if test="xgname != null  and xgname != ''"> and xgname like concat('%', #{xgname}, '%')</if>
            <if test="areas != null  and areas != ''"> and areas = #{areas}</if>
            <if test="major != null  and major != ''"> and major like concat('%', #{major}, '%')</if>
            <if test="county != null  and county != ''"> and county like concat('%', #{county}, '%')</if>
            <if test="fdtime != null "> and fdtime = #{fdtime}</if>
            <if test="xgtime != null "> and xgtime = #{xgtime}</if>
        </where>
    </select>
    
    <select id="selectRtStuAtSchoolById" parameterType="Integer" resultMap="RtStuAtSchoolResult">
        <include refid="selectRtStuAtSchoolVo"/>
        where id = #{id}
    </select>

<!--    在校证明判断学号是否已经存在-->
    <select id="selectRtStuAtSchoolByStudentId" parameterType="String" resultMap="RtStuAtSchoolResult">
        <include refid="selectRtStuAtSchoolVo"/>
        where student_id = #{studentId}
    </select>
        
    <insert id="insertRtStuAtSchool" parameterType="RtStuAtSchool" useGeneratedKeys="true" keyProperty="id">
        insert into rt_stu_at_school
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sex != null">sex,</if>
            <if test="studentId != null">student_id,</if>
            <if test="name != null">name,</if>
            <if test="college != null">college,</if>
            <if test="grade != null">grade,</if>
            <if test="stuCreated != null">stu_created,</if>
            <if test="identityCard != null">identity_card,</if>
            <if test="because != null">because,</if>
            <if test="status != null">status,</if>
            <if test="jg != null">jg,</if>
            <if test="photo != null">photo,</if>
            <if test="birthday != null">birthday,</if>
            <if test="Intake != null">Intake,</if>
            <if test="nation != null">nation,</if>
            <if test="homeaddress != null">homeaddress,</if>
            <if test="fdyopinion != null">fdyopinion,</if>
            <if test="xgopinion != null">xgopinion,</if>
            <if test="xgstatus != null">xgstatus,</if>
            <if test="className != null">class_name,</if>
            <if test="fdname != null">fdname,</if>
            <if test="xgname != null">xgname,</if>
            <if test="areas != null">areas,</if>
            <if test="major != null">major,</if>
            <if test="county != null">county,</if>
            <if test="fdtime != null">fdtime,</if>
            <if test="xgtime != null">xgtime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sex != null">#{sex},</if>
            <if test="studentId != null">#{studentId},</if>
            <if test="name != null">#{name},</if>
            <if test="college != null">#{college},</if>
            <if test="grade != null">#{grade},</if>
            <if test="stuCreated != null">#{stuCreated},</if>
            <if test="identityCard != null">#{identityCard},</if>
            <if test="because != null">#{because},</if>
            <if test="status != null">#{status},</if>
            <if test="jg != null">#{jg},</if>
            <if test="photo != null">#{photo},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="Intake != null">#{Intake},</if>
            <if test="nation != null">#{nation},</if>
            <if test="homeaddress != null">#{homeaddress},</if>
            <if test="fdyopinion != null">#{fdyopinion},</if>
            <if test="xgopinion != null">#{xgopinion},</if>
            <if test="xgstatus != null">#{xgstatus},</if>
            <if test="className != null">#{className},</if>
            <if test="fdname != null">#{fdname},</if>
            <if test="xgname != null">#{xgname},</if>
            <if test="areas != null">#{areas},</if>
            <if test="major != null">#{major},</if>
            <if test="county != null">#{county},</if>
            <if test="fdtime != null">#{fdtime},</if>
            <if test="xgtime != null">#{xgtime},</if>
         </trim>
    </insert>

    <update id="updateRtStuAtSchool" parameterType="RtStuAtSchool">
        update rt_stu_at_school
        <trim prefix="SET" suffixOverrides=",">
            <if test="sex != null">sex = #{sex},</if>
            <if test="studentId != null">student_id = #{studentId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="college != null">college = #{college},</if>
            <if test="grade != null">grade = #{grade},</if>
            <if test="stuCreated != null">stu_created = #{stuCreated},</if>
            <if test="identityCard != null">identity_card = #{identityCard},</if>
            <if test="because != null">because = #{because},</if>
            <if test="status != null">status = #{status},</if>
            <if test="jg != null">jg = #{jg},</if>
            <if test="photo != null">photo = #{photo},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="Intake != null">Intake = #{Intake},</if>
            <if test="nation != null">nation = #{nation},</if>
            <if test="homeaddress != null">homeaddress = #{homeaddress},</if>
            <if test="fdyopinion != null">fdyopinion = #{fdyopinion},</if>
            <if test="xgopinion != null">xgopinion = #{xgopinion},</if>
            <if test="xgstatus != null">xgstatus = #{xgstatus},</if>
            <if test="className != null">class_name = #{className},</if>
            <if test="fdname != null">fdname = #{fdname},</if>
            <if test="xgname != null">xgname = #{xgname},</if>
            <if test="areas != null">areas = #{areas},</if>
            <if test="major != null">major = #{major},</if>
            <if test="county != null">county = #{county},</if>
            <if test="fdtime != null">fdtime = #{fdtime},</if>
            <if test="xgtime != null">xgtime = #{xgtime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRtStuAtSchoolById" parameterType="Integer">
        delete from rt_stu_at_school where id = #{id}
    </delete>

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