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

    <resultMap type="TbForm" id="TbFormResult">
        <result property="id" column="id"/>
        <result property="formId" column="form_id"/>
        <result property="action" column="action"/>
        <result property="method" column="method"/>
        <result property="formTitle" column="form_title"/>
        <result property="orderBy" column="order_by"/>
        <result property="flowid" column="flowid"/>
        <result property="vueJsonText" column="vue_json_text"/>
        <result property="vueJsonField" column="vue_json_field"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="rolePermissions" column="role_permissions"/>
    </resultMap>

    <sql id="selectTbFormVo">
        select id, form_id, action, method, form_title, order_by, flowid, vue_json_text,vue_json_field, remark, create_by, create_time, role_permissions from yinet_act_form
    </sql>

    <select id="selectTbFormList" parameterType="TbForm" resultMap="TbFormResult">
        <include refid="selectTbFormVo"/>
        <where>
            <if test="formId != null  and formId != ''">and form_id = #{formId}</if>
            <if test="action != null  and action != ''">and action = #{action}</if>
            <if test="method != null  and method != ''">and method = #{method}</if>
            <if test="formTitle != null  and formTitle != ''">and form_title = #{formTitle}</if>
            <if test="orderBy != null ">and order_by = #{orderBy}</if>
            <if test="flowid != null ">and flowid = #{flowid}</if>
            <if test="vueJsonText != null  and vueJsonText != ''">and vue_json_text = #{vueJsonText}</if>
            <if test="rolePermissions != null  and rolePermissions != ''">and role_permissions = #{rolePermissions}</if>
        </where>
    </select>

    <select id="selectTbFormById" parameterType="Long" resultMap="TbFormResult">
        <include refid="selectTbFormVo"/>
        where id = #{id}
    </select>
    <select id="selectTbFormByAct" parameterType="String" resultMap="TbFormResult">
        <include refid="selectTbFormVo"/>
        where action = #{action}
    </select>

    <select id="selecltTable" parameterType="String" resultType="string">
        select *
        from information_schema.TABLES
        where TABLE_NAME = #{tableName};
    </select>

  <select id="selecltTableBytabName" parameterType="String" resultType="string">
        select vue_json_field
        from yinet_act_form
        where action = #{tableName};
    </select>


    <insert id="insertTbForm" parameterType="TbForm">
        insert into yinet_act_form
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="formId != null and formId != ''">form_id,</if>
            <if test="action != null and action != ''">action,</if>
            <if test="method != null and method != ''">method,</if>
            <if test="formTitle != null and formTitle != ''">form_title,</if>
            <if test="orderBy != null">order_by,</if>
            <if test="flowid != null">flowid,</if>
            <if test="vueJsonText != null">vue_json_text,</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>
            <if test="rolePermissions != null">role_permissions,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="formId != null and formId != ''">#{formId},</if>
            <if test="action != null and action != ''">#{action},</if>
            <if test="method != null and method != ''">#{method},</if>
            <if test="formTitle != null and formTitle != ''">#{formTitle},</if>
            <if test="orderBy != null">#{orderBy},</if>
            <if test="flowid != null">#{flowid},</if>
            <if test="vueJsonText != null">#{vueJsonText},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="rolePermissions != null">#{rolePermissions},</if>
        </trim>
    </insert>

    <update id="updateTbForm" parameterType="TbForm">
        update yinet_act_form
        <trim prefix="SET" suffixOverrides=",">
            <if test="formId != null and formId != ''">form_id = #{formId},</if>
            <if test="action != null and action != ''">action = #{action},</if>
            <if test="method != null and method != ''">method = #{method},</if>
            <if test="formTitle != null and formTitle != ''">form_title = #{formTitle},</if>
            <if test="orderBy != null">order_by = #{orderBy},</if>
            <if test="flowid != null">flowid = #{flowid},</if>
            <if test="vueJsonText != null">vue_json_text = #{vueJsonText},</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>
            <if test="rolePermissions != null">role_permissions = #{rolePermissions},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateTbFormJson" parameterType="String">
        update yinet_act_form
        set  vue_json_text=#{vueJsonText},vue_json_field=#{vueJsonField}
        where action = #{action}
    </update>


    <delete id="deleteTbFormById" parameterType="Long">
        delete from yinet_act_form where id = #{id}
    </delete>

    <delete id="deleteTbFormByIds" parameterType="String">
        delete from yinet_act_form where action in
        <foreach item="action" collection="array" open="(" separator="," close=")">
            #{action}
        </foreach>
    </delete>
    <delete id="deleteTable">
        drop table if exists
        <foreach item="action" collection="array" separator=",">
            `${action}`
        </foreach>

    </delete>

    <update id="altTalbe" parameterType="list">
        alter table `${tableName}`
        <foreach collection="tbFromModule" item="item" separator=",">
            add ${item.inputName} ${item.inputType}
        </foreach>
    </update>

    <update id="createTable" parameterType="string">
        create table `${_parameter}` (id int(2) PRIMARY KEY NOT NULL auto_increment  COMMENT '主键ID')
                                    ENGINE=InnoDB DEFAULT CHARSET=utf8
    </update>
    <update id="alterTableName" parameterType="String">
        alter table ${oldtableName} rename ${newtalbeName}
    </update>
    <update id="altDeleteZD" parameterType="list">
        alter table `${tableName}`
        <foreach collection="tbFromModule" item="item" separator=",">
            drop ${item.inputName}
        </foreach>

    </update>


    <select id="selAutoTable" parameterType="String" resultType="java.util.Map">
        select * from `${_parameter}`
    </select>
    <select id="selAutoTableById" resultType="java.util.Map">
        select *,(select vue_json_field from yinet_act_form where action= #{tableName}) as vueJson from ${tableName} where id = #{id}
    </select>



    <select id="selectByOne" resultType="java.lang.Object">
       select vue_json_field from yinet_act_form where action= #{tableName}
    </select>

</mapper>
