<?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.yiqi.generator.mapper.GenFormMapper">

    <resultMap type="GenForm" id="GenFormResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="drawingData" column="drawing_data"/>
        <result property="createTime" column="create_time"/>
        <result property="createById" column="create_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="menuId" column="menu_id"/>
        <result property="typeName" column="type_name"/>
    </resultMap>

    <sql id="selectGenFormVo">
        select id, title, drawing_data, create_time, create_by_id, update_by, update_time, update_by_id, create_by, menu_id, type_name
        from gen_form
    </sql>

    <select id="selectGenFormList" parameterType="GenForm" resultMap="GenFormResult">
        <include refid="selectGenFormVo"/>
        <where>
            <if test="title != null  and title != ''">
                and title = #{title}
            </if>
            <if test="typeName != null  and typeName != ''">
                and type_name like concat('%', #{typeName}, '%')
            </if>
        </where>
    </select>

    <select id="selectGenFormById" parameterType="Long"
            resultMap="GenFormResult">
        <include refid="selectGenFormVo"/>
        where id = #{id}
    </select>

    <insert id="insertGenForm" parameterType="GenForm" useGeneratedKeys="true"
            keyProperty="id">
        insert into gen_form
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,
            </if>
            <if test="drawingData != null">drawing_data,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="menuId != null">menu_id,
            </if>
            <if test="typeName != null">type_name,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},
            </if>
            <if test="drawingData != null">#{drawingData},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="menuId != null">#{menuId},
            </if>
            <if test="typeName != null">#{typeName},
            </if>
        </trim>
    </insert>

    <update id="updateGenForm" parameterType="GenForm">
        update gen_form
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title =
                #{title},
            </if>
            <if test="drawingData != null">drawing_data =
                #{drawingData},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="menuId != null">menu_id =
                #{menuId},
            </if>
            <if test="typeName != null">type_name =
                #{typeName},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGenFormById" parameterType="Long">
        delete from gen_form where id = #{id}
    </delete>

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