<?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="cn.fateverse.query.mapper.UniColumnMapper">

    <select id="selectByQueryId" resultType="cn.fateverse.query.entity.UniColumn">
        select id, query_id, prop, label, display_type, display_param, sort
        from uni_column
        where query_id = #{queryId}
    </select>

    <insert id="batchInsert">
        insert into uni_column (query_id, prop, label, display_type, display_param, sort) values
        <foreach collection="list" separator="," item="column">
            (#{column.queryId},#{column.prop},#{column.label},#{column.displayType},#{column.displayParam},#{column.sort})
        </foreach>
    </insert>

    <update id="batchUpdate">
        update uni_con
        <set>
            <trim prefix="prop = case" suffix="end,">
                <foreach collection="list" separator=" " item="item">
                    <if test="item.prop != null">
                        when column_id = #{item.columnId} then #{item.prop}
                    </if>
                </foreach>
            </trim>
            <trim prefix="label = case" suffix="end,">
                <foreach collection="list" separator=" " item="item">
                    <if test="item.label != null">
                        when column_id = #{item.columnId} then #{item.label}
                    </if>
                </foreach>
            </trim>
            <trim prefix="display_type = case" suffix="end,">
                <foreach collection="list" separator=" " item="item">
                    <if test="item.displayType != null">
                        when column_id = #{item.columnId} then #{item.displayType}
                    </if>
                </foreach>
            </trim>
            <trim prefix="display_param = case" suffix="end,">
                <foreach collection="list" separator=" " item="item">
                    <if test="item.displayParam != null">
                        when column_id = #{item.columnId} then #{item.displayParam}
                    </if>
                </foreach>
            </trim>
            <trim prefix="sort = case" suffix="end,">
                <foreach collection="list" separator=" " item="item">
                    <if test="item.dictType != null">
                        when column_id = #{item.columnId} then #{column.sort}
                    </if>
                </foreach>
            </trim>
        </set>
        where id in
        <foreach collection="list" item="item" index="index"
                 separator="," open="(" close=")">
            #{item.id}
        </foreach>
    </update>


    <delete id="batchDeleteByQueryId">
        delete from uni_column where query_id = #{queryId}
    </delete>

    <delete id="batchRemove">
        delete from uni_column where id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>