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


    <insert id="insertCphStuScoreMiddleDto" parameterType="list">

    </insert>
    <update id="updateBatchByIdList" parameterType="java.util.List">
        update cph_stu_score_middle
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="cj=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.xqid != null ">
                        when id=#{i.id} then #{i.xqid}
                    </if>
                </foreach>
            </trim>
            <trim prefix="xndm=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.xndm != null">
                        when id=#{i.id} then #{i.xndm}
                    </if>
                </foreach>
            </trim>
            <trim prefix="xqdm=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.xqdm != null">
                        when id=#{i.id} then #{i.xqdm}
                    </if>
                </foreach>
            </trim>
            <trim prefix="xf=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.xf != null">
                        when id=#{i.id} then #{i.xf}
                    </if>
                </foreach>
            </trim>
            <trim prefix="jd=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.jd != null">
                        when id=#{i.id} then #{i.jd}
                    </if>
                </foreach>
            </trim>
            <trim prefix="cj=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.cj != null">
                        when id=#{i.id} then #{i.cj}
                    </if>
                </foreach>
            </trim>
            <trim prefix="fzlx=case" suffix="end,">
                <foreach collection="cphStuScoreMiddleDto" item="i" index="index">
                    <if test="i.fzlx != null">
                        when id=#{i.id} then #{i.fzlx}
                    </if>
                </foreach>
            </trim>
        </trim>
        where
        <foreach collection="cphStuScoreMiddleDto" separator="or" item="i" index="index" >
            id=#{i.id}
        </foreach>
    </update>

    <update id="updateStuScoreMiddleList" parameterType="java.util.List">
        <foreach collection="CphStuScoreMiddleDto" item="item" index="index" open="" close="" separator=";">
            update cph_stu_score_middle
            <set>
                xqid=#{item.xqid},
                xndm=#{item.xndm},
                xqdm=#{item.xqdm},
                stu_no=#{item.stuNo},
                kcdm=#{item.kcdm},
                xf=#{item.xf},
                jd=#{item.jd},
                cj=#{item.cj},
                fzlx=#{item.fzlx}
            </set>
            where id = ${item.id}
        </foreach>
    </update>

    <select id="getCphStuScoreMiddleCjList" resultType="java.lang.String">
        SELECT cph_stu_score_middle.cj FROM cph_stu_score_middle
            left JOIN srs_course_info ON cph_stu_score_middle.kcdm=srs_course_info.course_no
            left join cph_term as c on cph_stu_score_middle.xqdm = c.term_code
            left join srs_stu_year as d on c.stu_year_id = d.id
                 WHERE cph_stu_score_middle.fzlx='2' AND stu_no=#{stuNo}
    </select>

    <select id="getCphStuScoreMiddleCjLists" resultType="java.lang.String">
        SELECT cph_stu_score_middle.cj FROM cph_stu_score_middle
                                                left JOIN srs_course_info ON cph_stu_score_middle.kcdm=srs_course_info.course_no
                                                left join cph_term as c on cph_stu_score_middle.xqdm = c.term_code
                                                left join srs_stu_year as d on c.stu_year_id = d.id
        WHERE cph_stu_score_middle.fzlx='2' AND stu_no=#{stuNo} AND cph_stu_score_middle.xndm=#{xndm}
    </select>

    <select id="getCphStuScoreMiddleCjListMap" resultType="java.util.Map">
        SELECT cph_stu_score_middle.cj ,srs_course_info.course_name  FROM cph_stu_score_middle
                                                left JOIN srs_course_info ON cph_stu_score_middle.kcdm=srs_course_info.course_no
                                                left join cph_term as c on cph_stu_score_middle.xqdm = c.term_code
                                                left join srs_stu_year as d on c.stu_year_id = d.id
        WHERE cph_stu_score_middle.fzlx='2' AND stu_no=#{stuNo} AND cph_stu_score_middle.xndm=#{xndm}
    </select>

    <select id="getCphStuScoreMiddleAll" resultType="CphStuScoreMiddleDtoVo">
        select cph_stu_score_middle.*,srs_course_info.course_name from cph_stu_score_middle
        left JOIN srs_course_info ON cph_stu_score_middle.kcdm=srs_course_info.course_no
        <where>
            <if test="stuNo!=null and stuNo!='' ">stu_no=#{stuNo}</if>
        </where>
    </select>

    <select id="updateTabeDate">
        TRUNCATE TABLE cph_stu_score_middle
    </select>
</mapper>
