<?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.system.mapper.UserTableColumnConfigMapper">
    
    <resultMap type="UserTableColumnConfig" id="UserTableColumnConfigResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="pageRoute"    column="page_route"    />
        <result property="columnConfig"    column="column_config"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectUserTableColumnConfigVo">
        select id, user_id, page_route, column_config, create_by, create_time, update_by, update_time, remark from user_table_column_config
    </sql>

    <select id="selectUserTableColumnConfigList" parameterType="UserTableColumnConfig" resultMap="UserTableColumnConfigResult">
        <include refid="selectUserTableColumnConfigVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="pageRoute != null  and pageRoute != ''"> and page_route = #{pageRoute}</if>
            <if test="columnConfig != null  and columnConfig != ''"> and column_config = #{columnConfig}</if>
        </where>
    </select>
    
    <select id="selectUserTableColumnConfigById" parameterType="Long" resultMap="UserTableColumnConfigResult">
        <include refid="selectUserTableColumnConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertUserTableColumnConfig" parameterType="UserTableColumnConfig" useGeneratedKeys="true" keyProperty="id">
        insert into user_table_column_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="pageRoute != null and pageRoute != ''">page_route,</if>
            <if test="columnConfig != null and columnConfig != ''">column_config,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="pageRoute != null and pageRoute != ''">#{pageRoute},</if>
            <if test="columnConfig != null and columnConfig != ''">#{columnConfig},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateUserTableColumnConfig" parameterType="UserTableColumnConfig">
        update user_table_column_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="columnConfig != null and columnConfig != ''">column_config = #{columnConfig},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        <where>
            <choose>
                <when test="id != null">
                    and id = #{id}
                </when>
                <when test="userId != null and pageRoute != null">
                    and user_id = #{userId} and page_route = #{pageRoute}
                </when>
                <otherwise>
                    and 1=0 <!-- 如果两个条件都不满足，则不更新任何记录 -->
                </otherwise>
            </choose>
        </where>
    </update>

    <delete id="deleteUserTableColumnConfigById" parameterType="Long">
        delete from user_table_column_config where id = #{id}
    </delete>

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