<?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.ruoyi.dz.mapper.DzSelectSubjectMapper">
    
    <resultMap type="DzSelectSubject" id="DzSelectSubjectResult">
        <result property="groupId"    column="group_id"    />
        <result property="name"    column="name"    />
        <result property="rank"    column="rank"    />
        <result property="course0"    column="course0"    />
        <result property="course1"    column="course1"    />
        <result property="newgaokaoType"    column="newgaokao_type"    />
    </resultMap>

    <sql id="selectDzSelectSubjectVo">
        select group_id, name, rank, course0, course1, newgaokao_type from dz_select_subject
    </sql>

    <select id="selectDzSelectSubjectList" parameterType="DzSelectSubject" resultMap="DzSelectSubjectResult">
        <include refid="selectDzSelectSubjectVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="rank != null "> and rank = #{rank}</if>
            <if test="course0 != null  and course0 != ''"> and course0 = #{course0}</if>
            <if test="course1 != null  and course1 != ''"> and course1 = #{course1}</if>
            <if test="newgaokaoType != null  and newgaokaoType != ''"> and newgaokao_type = #{newgaokaoType}</if>
        </where>
    </select>
    
    <select id="selectDzSelectSubjectByGroupId" parameterType="String" resultMap="DzSelectSubjectResult">
        <include refid="selectDzSelectSubjectVo"/>
        where group_id = #{groupId}
    </select>

    <insert id="insertDzSelectSubject" parameterType="DzSelectSubject" useGeneratedKeys="true" keyProperty="groupId">
        insert into dz_select_subject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="rank != null">rank,</if>
            <if test="course0 != null">course0,</if>
            <if test="course1 != null">course1,</if>
            <if test="newgaokaoType != null">newgaokao_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="rank != null">#{rank},</if>
            <if test="course0 != null">#{course0},</if>
            <if test="course1 != null">#{course1},</if>
            <if test="newgaokaoType != null">#{newgaokaoType},</if>
         </trim>
    </insert>

    <update id="updateDzSelectSubject" parameterType="DzSelectSubject">
        update dz_select_subject
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="rank != null">rank = #{rank},</if>
            <if test="course0 != null">course0 = #{course0},</if>
            <if test="course1 != null">course1 = #{course1},</if>
            <if test="newgaokaoType != null">newgaokao_type = #{newgaokaoType},</if>
        </trim>
        where group_id = #{groupId}
    </update>

    <delete id="deleteDzSelectSubjectByGroupId" parameterType="String">
        delete from dz_select_subject where group_id = #{groupId}
    </delete>

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