<?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.SrsGraduateStudentMapper">

    <resultMap type="SrsGraduateStudent" id="SrsGraduateStudentResult">
        <result property="id"    column="id"    />
<!--        <result property="counselorComments"    column="counselor_comments"    />-->
<!--        <result property="counselorName"    column="counselor_name"    />-->
<!--        <result property="fillData"    column="fill_data"    />-->
<!--        <result property="collegeOpinion"    column="college_opinion"    />-->
        <result property="stuYear"    column="stu_year"    />
        <result property="graduateId"    column="graduate_id"    />
        <result property="employeeId" column="employee_id"  />
    </resultMap>
<!--    SrsIdentifytable-->

    <resultMap type="com.srs.comprehensive.domain.SrsIdentifytable" id="SrsIdentifytableResult">
        <result property="id"    column="id"    />
        <result property="studentName"    column="student_name"    />
        <result property="studentCode"    column="student_code"    />
        <result property="studentCollege"    column="student_college"    />
        <result property="studentGrade"    column="student_grade"    />
        <result property="studentClass"    column="student_class"    />
        <result property="sex"    column="sex"    />
        <result property="nation"    column="nation"    />
        <result property="birthData"    column="birth_data"    />
    </resultMap>

    <sql id="selectSrsGraduateStudentVo">
        select id, politics, moral_character, observe_discipline, attitude, attendance_situation, position_held, working_attitude, working_ability, ldeological_political, scientific_quality, physical_quality, total_points, counselor_comments, counselor_name, fill_data, college_opinion, stu_year, graduate_id, biao_jit from srs_graduate_student
    </sql>

    <select id="selectSrsGraduateStudentList" parameterType="SrsGraduateStudent" resultMap="SrsGraduateStudentResult">
        select id, counselor_comments, counselor_name, fill_data, college_opinion, stu_year from srs_graduate_student
        <where>
            <if test="politics != null  and politics != ''"> and politics = #{politics}</if>
            <if test="moralCharacter != null  and moralCharacter != ''"> and moral_character = #{moralCharacter}</if>
        </where>
    </select>

    <select id="selectSrsGraduateStudentLists" parameterType="SrsGraduateStudent" resultMap="SrsIdentifytableResult">
        select a.id, a.student_name, a.student_code, a.student_college, a.student_class from srs_graduate_studentinfo a
        left join srs_class b on a.student_class=b.class_name
        left join cph_teacher c on c.teacher_id=b.teacher_id
        <where>
            <if test="studentCode != null  and studentCode != ''"> and a.student_code = #{studentCode}</if>
            <if test="studentClass != null  and studentClass != ''"> and a.student_class = #{studentClass}</if>
            <if test="employeeId != null  and employeeId != ''"> and a.employee_id = #{employeeId}</if>
        </where>
    </select>

    <select id="selectSrsGraduateStudentById" parameterType="Long" resultMap="SrsGraduateStudentResult">
        <include refid="selectSrsGraduateStudentVo"/>
        where id = #{id}
    </select>

    <insert id="inserts" parameterType="SrsGraduateStudent" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO srs_graduate_studentinfo (
            student_name,
            student_code)
        VALUES (
            #{studentName},
            #{studentCode})
    </insert>

    <insert id="insertSrsGraduateStudentYearOne" parameterType="SrsGraduateStudent">
        insert into srs_graduate_student
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <!-- yearOne 学年字段 -->
            <if test="yearOne != null">
                <if test="yearOne.counselorComments != null">counselor_comments,</if>
                <if test="yearOne.counselorName != null">counselor_name,</if>
                <if test="yearOne.fillData != null">fill_data,</if>
                <if test="yearOne.collegeOpinion != null">college_opinion,</if>
                <if test="yearOne.stuYear != null">stu_year,</if>
                <if test="yearOne.biaoJit != null ">biao_jit,</if>
            </if>
            <if test="graduateId != null">graduate_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="yearOne != null">
                <if test="yearOne.counselorComments != null">#{yearOne.counselorComments},</if>
                <if test="yearOne.counselorName != null">#{yearOne.counselorName},</if>
                <if test="yearOne.fillData != null">#{yearOne.fillData},</if>
                <if test="yearOne.collegeOpinion != null">#{yearOne.collegeOpinion},</if>
                <if test="yearOne.stuYear != null">#{yearOne.stuYear},</if>
                <if test="yearOne.biaoJit != null">#{yearOne.biaoJit},</if>
            </if>
            <if test="graduateId != null">#{graduateId}</if>
         </trim>
    </insert>

    <insert id="insertSrsGraduateStudentYearTwo" parameterType="SrsGraduateStudent">
        insert into srs_graduate_student
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="yearTwo != null">
                <if test="yearTwo.counselorComments != null">counselor_comments,</if>
                <if test="yearTwo.counselorName != null">counselor_name,</if>
                <if test="yearTwo.fillData != null">fill_data,</if>
                <if test="yearTwo.collegeOpinion != null">college_opinion,</if>
                <if test="yearTwo.stuYear != null">stu_year,</if>
                <if test="yearTwo.biaoJit != null ">biao_jit,</if>
            </if>
            <if test="graduateId != null">graduate_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="yearTwo != null">
                <if test="yearTwo.counselorComments != null">#{yearTwo.counselorComments},</if>
                <if test="yearTwo.counselorName != null">#{yearTwo.counselorName},</if>
                <if test="yearTwo.fillData != null">#{yearTwo.fillData},</if>
                <if test="yearTwo.collegeOpinion != null">#{yearTwo.collegeOpinion},</if>
                <if test="yearTwo.stuYear != null">#{yearTwo.stuYear},</if>
                <if test="yearTwo.biaoJit != null">#{yearTwo.biaoJit},</if>
            </if>
            <if test="graduateId != null">#{graduateId},</if>
        </trim>
    </insert>

    <insert id="insertSrsGraduateStudentYearThree" parameterType="SrsGraduateStudent">
        insert into srs_graduate_student
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <!-- yearThree 学年字段 -->
            <if test="yearThree != null">
                <if test="yearThree.counselorComments != null">counselor_comments,</if>
                <if test="yearThree.counselorName != null">counselor_name,</if>
                <if test="yearThree.fillData != null">fill_data,</if>
                <if test="yearThree.collegeOpinion != null">college_opinion,</if>
                <if test="yearThree.stuYear != null">stu_year,</if>
                <if test="yearThree.biaoJit != null">biao_jit,</if>
            </if>
            <if test="graduateId != null">graduate_id</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="yearThree != null">
                <if test="yearThree.counselorComments != null">#{yearThree.counselorComments},</if>
                <if test="yearThree.counselorName != null">#{yearThree.counselorName},</if>
                <if test="yearThree.fillData != null">#{yearThree.fillData},</if>
                <if test="yearThree.collegeOpinion != null">#{yearThree.collegeOpinion},</if>
                <if test="yearThree.stuYear != null">#{yearThree.stuYear},</if>
                <if test="yearThree.biaoJit != null">#{yearThree.biaoJit},</if>
            </if>
            <if test="graduateId != null">#{graduateId},</if>
        </trim>
    </insert>

    <update id="updateSrsGraduateStudentYearOne" parameterType="SrsGraduateStudent">
        update srs_graduate_student
            <set>
                <!-- yearOne 字段 -->
                <if test="yearOne != null">
                    <if test="yearOne.counselorComments != null">counselor_comments = #{yearOne.counselorComments},</if>
                    <if test="yearOne.counselorName != null">counselor_name = #{yearOne.counselorName},</if>
                    <if test="yearOne.fillData != null">fill_data = #{yearOne.fillData},</if>
                    <if test="yearOne.collegeOpinion != null">college_opinion = #{yearOne.collegeOpinion},</if>
                    <if test="yearOne.stuYear != null">stu_year = #{yearOne.stuYear},</if>
                    <if test="yearOne.biaoJit != null">biao_jit = #{yearOne.biaoJit},</if>
                </if>
                <if test="graduateId != null">graduate_id = #{graduateId},</if>
            </set>
            <where>
                graduate_id = #{graduateId}
                <if test="yearOne.biaoJit != null"> and biao_jit = #{yearOne.biaoJit}</if>
            </where>
    </update>

    <update id="updateSrsGraduateStudentYearTwo" parameterType="SrsGraduateStudent">
        update srs_graduate_student
        <set>
            <!-- yearOne 字段 -->
            <if test="yearTwo != null">
                <if test="yearTwo.counselorComments != null">counselor_comments = #{yearTwo.counselorComments},</if>
                <if test="yearTwo.counselorName != null">counselor_name = #{yearTwo.counselorName},</if>
                <if test="yearTwo.fillData != null">fill_data = #{yearTwo.fillData},</if>
                <if test="yearTwo.collegeOpinion != null">college_opinion = #{yearTwo.collegeOpinion},</if>
                <if test="yearTwo.stuYear != null">stu_year = #{yearTwo.stuYear},</if>
                <if test="yearTwo.biaoJit != null">biao_jit = #{yearTwo.biaoJit},</if>
            </if>
            <if test="graduateId != null">graduate_id = #{graduateId},</if>
        </set>
        <where>
            graduate_id = #{graduateId}
            <if test="yearTwo.biaoJit != null"> and biao_jit = #{yearTwo.biaoJit}</if>
        </where>
    </update>

    <update id="updateSrsGraduateStudentYearThree" parameterType="SrsGraduateStudent">
        update srs_graduate_student
        <set>
            <!-- yearOne 字段 -->
            <if test="yearThree != null">
                <if test="yearThree.counselorComments != null">counselor_comments = #{yearThree.counselorComments},</if>
                <if test="yearThree.counselorName != null">counselor_name = #{yearThree.counselorName},</if>
                <if test="yearThree.fillData != null">fill_data = #{yearThree.fillData},</if>
                <if test="yearThree.collegeOpinion != null">college_opinion = #{yearThree.collegeOpinion},</if>
                <if test="yearThree.stuYear != null">stu_year = #{yearThree.stuYear},</if>
                <if test="yearThree.biaoJit != null">biao_jit = #{yearThree.biaoJit},</if>
            </if>
            <if test="graduateId != null">graduate_id = #{graduateId},</if>
        </set>
        <where>
            graduate_id = #{graduateId}
            <if test="yearThree.biaoJit != null"> and biao_jit = #{yearThree.biaoJit}</if>
        </where>
    </update>

    <delete id="deleteSrsGraduateStudentById" parameterType="Long">
        delete from srs_graduate_student where id = #{id}
    </delete>

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

</mapper>
