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

    <resultMap type="DzSubject" id="DzSubjectResult">
        <result property="subjectId"    column="subject_id"    />
        <result property="subjectName"    column="subject_name"    />
        <result property="pinyin"    column="pinyin"    />
        <result property="sort"    column="sort"    />
        <result property="locations"    column="locations"    />
        <result property="examTypes"    column="exam_types"    />
    </resultMap>

    <sql id="selectDzSubjectVo">
        select subject_id, subject_name, pinyin, sort, locations, exam_types from dz_subject
    </sql>

    <select id="selectDzSubjectList" parameterType="DzSubject" resultMap="DzSubjectResult">
        <include refid="selectDzSubjectVo"/>
        <where>
            <if test="subjectName != null  and subjectName != ''"> and subject_name like concat('%', #{subjectName}, '%')</if>
            <if test="pinyin != null  and pinyin != ''"> and pinyin = #{pinyin}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="locations != null  and locations != ''"> and locations = #{locations}</if>
            <if test="examTypes != null  and examTypes != ''"> and exam_types  like concat('%', #{examTypes}, '%') </if>
        </where>
    </select>

    <select id="selectDzSubjectBySubjectId" parameterType="Long" resultMap="DzSubjectResult">
        <include refid="selectDzSubjectVo"/>
        where subject_id = #{subjectId}
    </select>

    <insert id="insertDzSubject" parameterType="DzSubject">
        insert into dz_subject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="subjectId != null">subject_id,</if>
            <if test="subjectName != null">subject_name,</if>
            <if test="pinyin != null">pinyin,</if>
            <if test="sort != null">sort,</if>
            <if test="locations != null">locations,</if>
            <if test="examTypes != null">exam_types,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="subjectId != null">#{subjectId},</if>
            <if test="subjectName != null">#{subjectName},</if>
            <if test="pinyin != null">#{pinyin},</if>
            <if test="sort != null">#{sort},</if>
            <if test="locations != null">#{locations},</if>
            <if test="examTypes != null">#{examTypes},</if>
         </trim>
    </insert>

    <update id="updateDzSubject" parameterType="DzSubject">
        update dz_subject
        <trim prefix="SET" suffixOverrides=",">
            <if test="subjectName != null">subject_name = #{subjectName},</if>
            <if test="pinyin != null">pinyin = #{pinyin},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="locations != null">locations = #{locations},</if>
            <if test="examTypes != null">exam_types = #{examTypes},</if>
        </trim>
        where subject_id = #{subjectId}
    </update>

    <delete id="deleteDzSubjectBySubjectId" parameterType="Long">
        delete from dz_subject where subject_id = #{subjectId}
    </delete>

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