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

    <resultMap type="DzControl" id="DzControlResult">
        <result property="id"    column="id"    />
        <result property="location"    column="location"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="isValid"    column="is_valid"    />
        <result property="planYear"    column="plan_year"    />
        <result property="submitYear"    column="submit_year"    />
        <result property="examTypes"    column="exam_types"    />
    </resultMap>

    <sql id="selectDzControlVo">
        select id, location, start_date, end_date, is_valid, plan_year, submit_year, exam_types from dz_control
    </sql>

    <select id="selectDzControlList" parameterType="DzControl" resultMap="DzControlResult">
        <include refid="selectDzControlVo"/>
        <where>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="startDate != null  and startDate != ''"> and start_date = #{startDate}</if>
            <if test="endDate != null  and endDate != ''"> and end_date = #{endDate}</if>
            <if test="isValid != null "> and is_valid = #{isValid}</if>
            <if test="planYear != null  and planYear != ''"> and plan_year = #{planYear}</if>
            <if test="submitYear != null  and submitYear != ''"> and submit_year = #{submitYear}</if>
            <if test="examTypes != null  and examTypes != ''"> and exam_types like concat ('%',#{examTypes},'%') </if>
        </where>
    </select>

    <select id="selectDzControlById" parameterType="Long" resultMap="DzControlResult">
        <include refid="selectDzControlVo"/>
        where id = #{id}
    </select>

    <insert id="insertDzControl" parameterType="DzControl" useGeneratedKeys="true" keyProperty="id">
        insert into dz_control
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="location != null">location,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="isValid != null">is_valid,</if>
            <if test="planYear != null">plan_year,</if>
            <if test="submitYear != null">submit_year,</if>
            <if test="examTypes != null">exam_types,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="location != null">#{location},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="isValid != null">#{isValid},</if>
            <if test="planYear != null">#{planYear},</if>
            <if test="submitYear != null">#{submitYear},</if>
            <if test="examTypes != null">#{examTypes},</if>
         </trim>
    </insert>

    <update id="updateDzControl" parameterType="DzControl">
        update dz_control
        <trim prefix="SET" suffixOverrides=",">
            <if test="location != null">location = #{location},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="isValid != null">is_valid = #{isValid},</if>
            <if test="planYear != null">plan_year = #{planYear},</if>
            <if test="submitYear != null">submit_year = #{submitYear},</if>
            <if test="examTypes != null">exam_types = #{examTypes},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDzControlById" parameterType="Long">
        delete from dz_control where id = #{id}
    </delete>

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