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

    <resultMap type="SrsKnrdType" id="SrsKnrdTypeResult">
        <result property="id" column="id"/>
        <result property="stuNo" column="stu_no"/>
        <result property="stuName" column="stu_name"/>
        <result property="knrdType" column="knrd_type"/>
        <result property="stuYearId" column="stu_year_id"/>
        <result property="stuYearName" column="stu_year_name"/>
    </resultMap>

    <sql id="selectSrsKnrdTypeVo">
        select a.id, a.stu_no, a.knrd_type, b.stu_name, a.stu_year_id, c.stu_year_name
        from srs_knrd_type as a
                 left join view_stu_info as b on a.stu_no = b.stu_no
                 left join srs_stu_year as c on a.stu_year_id = c.id
    </sql>

    <select id="selectSrsKnrdTypeList" parameterType="SrsKnrdType" resultMap="SrsKnrdTypeResult">
        <include refid="selectSrsKnrdTypeVo"/>
        <where>
            <if test="stuNo != null  and stuNo != ''">and a.stu_no = #{stuNo}</if>
            <if test="knrdType != null  and knrdType != ''">and a.knrd_type = #{knrdType}</if>
            <if test="stuYearId != null ">and a.stu_year_id = #{stuYearId}</if>
        </where>
        order by a.id desc
    </select>

    <select id="selectSrsKnrdTypeById" parameterType="Long" resultMap="SrsKnrdTypeResult">
        <include refid="selectSrsKnrdTypeVo"/>
        where a.id = #{id}
    </select>

    <insert id="insertSrsKnrdType" parameterType="SrsKnrdType" useGeneratedKeys="true" keyProperty="id">
        insert into srs_knrd_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">stu_no,</if>
            <if test="knrdType != null">knrd_type,</if>
            <if test="stuYearId != null">stu_year_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stuNo != null">#{stuNo},</if>
            <if test="knrdType != null">#{knrdType},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
        </trim>
    </insert>

    <update id="updateSrsKnrdType" parameterType="SrsKnrdType">
        update srs_knrd_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="knrdType != null">knrd_type = #{knrdType},</if>
            <if test="stuYearId != null">stu_year_id = #{stuYearId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSrsKnrdTypeById" parameterType="Long">
        delete
        from srs_knrd_type
        where id = #{id}
    </delete>

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