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

    <resultMap type="SrsCeScore" id="SrsCeScoreResult">
        <result property="id" column="id"/>
        <result property="stuId" column="stu_id"/>
        <result property="stuYearId" column="stu_year_id"/>
        <result property="ceScore" column="ce_score"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="stuNo" column="stu_no"/>
        <association property="student" javaType="SrsStudent" resultMap="studentJoin"/>
    </resultMap>

    <resultMap type="SrsCeScoreStudentStuYear" id="SrsCeScoreStudentStuYearS">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="stuNo" column="stu_no"/>
        <result property="stuYearName" column="stu_year_name"/>
        <result property="ceScore" column="ce_score"/>
        <result property="stuId" column="stu_id"/>
        <result property="stuYearId" column="stu_year_id"/>
    </resultMap>
    <resultMap type="SrsStudent" id="studentJoin">
        <result property="stuId" column="stu_id"/>
        <result property="name" column="name"/>
        <result property="stuNo" column="stu_no"/>
        <result property="gender" column="gender"/>
        <result property="birthday" column="birthday"/>
        <result property="idCard" column="id_card"/>
        <result property="deptId" column="dept_id"/>
        <result property="majorId" column="major_id"/>
        <result property="phone" column="phone"/>
        <result property="address" column="address"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectSrsCeScoreVo">
        select scs.id,
               scs.stu_id,
               scs.stu_year_id,
               scs.ce_score,
               scs.del_flag,
               scs.create_by,
               scs.create_time,
               scs.update_by,
               scs.update_time
        from srs_ce_score scs
                 left join srs_student stu on stu.stu_id = scs.stu_id
    </sql>

    <select id="selectSrsCeScoreList" parameterType="SrsCeScore" resultMap="SrsCeScoreResult">
        <include refid="selectSrsCeScoreVo"/>
        <where>
            <if test="stuId != null ">and stu_id = #{stuId}</if>
            <if test="stuYearId != null ">and stu_year_id = #{stuYearId}</if>
            <if test="ceScore != null ">and ce_score = #{ceScore}</if>
            <if test="student.classId != null ">and stu.class_id = #{student.classId}</if>
            <if test="student.stuNo != null and student.stuNo!=''">and stu.stu_no = #{student.stuNo}</if>
            <if test="student.name != null ">and stu.name like #{student.name}</if>
        </where>
    </select>

    <sql id="selectSrsCeScoreVoS">
        select id,
               stu_id,
               stu_year_id,
               ce_score,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from srs_ce_score
    </sql>
    <select id="selectSrsCeScoreListS" parameterType="SrsCeScore" resultMap="SrsCeScoreResult">
        <include refid="selectSrsCeScoreVoS"/>
        <where>
            <if test="stuId != null ">and stu_id = #{stuId}</if>
            <if test="stuYearId != null ">and stu_year_id = #{stuYearId}</if>
            <if test="ceScore != null ">and ce_score = #{ceScore}</if>
        </where>
    </select>

    <select id="selectSrsCeScoreById" parameterType="Long" resultMap="SrsCeScoreResult">
        <include refid="selectSrsCeScoreVo"/>
        where id = #{id}
    </select>

    <insert id="insertSrsCeScore" parameterType="SrsCeScore" useGeneratedKeys="true" keyProperty="id">
        insert into srs_ce_score
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuId != null">stu_id,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="ceScore != null">ce_score,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="stuNo != null">stu_no</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuId != null">#{stuId},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="ceScore != null">#{ceScore},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="stuNo != null">#{stuNo}</if>
        </trim>
    </insert>

    <update id="updateSrsCeScore" parameterType="SrsCeScore">
        update srs_ce_score
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuId != null">stu_id = #{stuId},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
            <if test="ceScore != null">ce_score = #{ceScore},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>




    <delete id="deleteSrsCeScoreById" parameterType="Long">
        delete
        from srs_ce_score
        where id = #{id}
    </delete>

    <delete id="deleteSrsCeScoreByIds" parameterType="String">
        delete from srs_ce_score where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <!--    综合评价连表查询-->
    <select id="SrsCeScoreStudentStuYear" parameterType="SrsCeScore" resultMap="SrsCeScoreStudentStuYearS">
        select a.id,b.`name`,b.stu_no,c.stu_year_name,a.ce_score,a.stu_id,a.stu_year_id from srs_ce_score as a
        left join srs_student as b on a.stu_id = b.stu_id
        left join srs_stu_year as c on a.stu_year_id = c.id
        <where>
            <if test="delFlag != null ">and a.del_flag = #{delFlag}</if>
            <if test="stuId != null ">and a.stu_id = #{stuId}</if>
            <if test="stuYearId != null ">and stu_year_id = #{stuYearId}</if>
            <if test="ceScore != null ">and ce_score = #{ceScore}</if>
            <if test="student.classId != null ">and b.class_id = #{student.classId}</if>
            <if test="student.stuNo != null and student.stuNo!=''">and b.stu_no = #{student.stuNo}</if>
            <if test="student.name != null ">and b.name like #{student.name}</if>
        </where>
    </select>
</mapper>
