<?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.project.system.mapper.TbFormModuleMapper">

    <resultMap type="TbFormModule" id="TbFormModuleResult">
        <result property="id" column="Id"/>
        <result property="formid" column="formid"/>
        <result property="inputType" column="input_type"/>
        <result property="inputId" column="input_id"/>
        <result property="inputName" column="input_name"/>
        <result property="notNull" column="not_null"/>
        <result property="inputTitle" column="input_title"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <sql id="selectTbFormModuleVo">
        select Id, formid, input_type, input_id, input_name, not_null, input_title, remark, create_by, create_time from tb_form_module
    </sql>

    <select id="selectTbFormModuleList" parameterType="TbFormModule" resultMap="TbFormModuleResult">
        <include refid="selectTbFormModuleVo"/>
        <where>
            <if test="formid != null ">and formid = #{formid}</if>
            <if test="inputType != null  and inputType != ''">and input_type = #{inputType}</if>
            <if test="inputId != null  and inputId != ''">and input_id = #{inputId}</if>
            <if test="inputName != null  and inputName != ''">and input_name like concat('%', #{inputName}, '%')</if>
            <if test="notNull != null ">and not_null = #{notNull}</if>
            <if test="inputTitle != null  and inputTitle != ''">and input_title = #{inputTitle}</if>
        </where>
    </select>

    <select id="selectTbFormModuleById" parameterType="Long" resultMap="TbFormModuleResult">
        <include refid="selectTbFormModuleVo"/>
        where Id = #{id}
    </select>
    <select id="selectTableData" resultType="java.util.Map">
        select * from ${_parameter}
    </select>
    <select id="selTbDataByName" resultMap="TbFormModuleResult">
        select * from  tb_form_module where formid = #{tableName}
    </select>

    <insert id="insertTbFormModule" parameterType="TbFormModule" useGeneratedKeys="true" keyProperty="id">
        insert into tb_form_module
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="formid != null">formid,</if>
            <if test="inputType != null and inputType != ''">input_type,</if>
            <if test="inputId != null and inputId != ''">input_id,</if>
            <if test="inputName != null and inputName != ''">input_name,</if>
            <if test="notNull != null">not_null,</if>
            <if test="inputTitle != null and inputTitle != ''">input_title,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="formid != null">#{formid},</if>
            <if test="inputType != null and inputType != ''">#{inputType},</if>
            <if test="inputId != null and inputId != ''">#{inputId},</if>
            <if test="inputName != null and inputName != ''">#{inputName},</if>
            <if test="notNull != null">#{notNull},</if>
            <if test="inputTitle != null and inputTitle != ''">#{inputTitle},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <insert id="insertTableData">
        insert into ${tableName}
        <foreach collection="tableMap.keys" item="key" open="(" separator="," close=")">
            ${key}
        </foreach>
        values
        <foreach collection="tableMap.keys"  item="key" open="(" separator="," close=")">
            #{tableMap[${key}]}
        </foreach>

    </insert>

    <insert id="insertTable">
        insert into ${tableName} (${vModel})
         values (${defaultValue})
    </insert>

    <update id="updateTbFormModule" parameterType="TbFormModule">
        update tb_form_module
        <trim prefix="SET" suffixOverrides=",">
            <if test="formid != null">formid = #{formid},</if>
            <if test="inputType != null and inputType != ''">input_type = #{inputType},</if>
            <if test="inputId != null and inputId != ''">input_id = #{inputId},</if>
            <if test="inputName != null and inputName != ''">input_name = #{inputName},</if>
            <if test="notNull != null">not_null = #{notNull},</if>
            <if test="inputTitle != null and inputTitle != ''">input_title = #{inputTitle},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where Id = #{id}
    </update>


    <update id="updateTableData">
        update ${tableName} set
        <foreach collection="tableMap.keys"  item="key" separator=",">
           ${key} =  #{tableMap[${key}]}
        </foreach>
        where id=${id}
    </update>

    <delete id="deleteTbFormModuleById" parameterType="Long">
        delete from tb_form_module where Id = #{id}
    </delete>

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

    <delete id="deleteTableZJ" parameterType="String">
        delete from tb_form_module where formid = #{formId}
    </delete>

    <delete id="deleteTableData">
        delete from ${tableName} where id = #{id}
    </delete>

</mapper>
