<?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.younike.system.mapper.DimensionMapper">
    
    <resultMap type="Dimension" id="DimensionResult">
        <id property="dimensionId"    column="dimension_id"    />
        <result property="name"    column="name"    />
        <result property="delFlag"    column="del_flag"    />
        <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="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <sql id="selectDimensionVo">
        select dimension_id, name, del_flag, create_by, create_time, update_by, update_time, column1, column2, column3 from dimension
    </sql>

    <select id="selectDimensionList" parameterType="Dimension" resultMap="DimensionResult">
        <include refid="selectDimensionVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
        </where>
    </select>
    
    <select id="selectDimensionByDimensionId" parameterType="Long" resultMap="DimensionResult">
        <include refid="selectDimensionVo"/>
        where dimension_id = #{dimensionId}
    </select>
        
    <insert id="insertDimension" parameterType="Dimension">
        insert into dimension
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dimensionId != null">dimension_id,</if>
            <if test="name != null">name,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</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="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dimensionId != null">#{dimensionId},</if>
            <if test="name != null">#{name},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</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="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <insert id="insertBatch" parameterType="Dimension" useGeneratedKeys="true" keyProperty="dimensionId">
        insert into dimension
        (name, create_time, create_by)
        values
        <foreach collection="dimensionList" separator="," item="item">
            (#{item.name}, #{item.createTime}, #{item.createBy})
        </foreach>
    </insert>

    <update id="updateBatch">
        <foreach collection="dimensionList" item="item" index="index" open="" close="" separator=";">
            update dimension
            <trim prefix="SET" suffixOverrides=",">
                <if test="item.name != null">name = #{item.name},</if>
                <if test="item.delFlag != null and item.delFlag != ''">del_flag = #{item.delFlag},</if>
                <if test="item.updateTime != null">update_time = #{item.updateTime},</if>
                <if test="item.updateBy != null and item.updateBy != ''">update_by = #{item.updateBy},</if>
            </trim>
            where dimension_id = ${item.dimensionId}
        </foreach>

    </update>

    <update id="updateDimension" parameterType="Dimension">
        update dimension
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</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="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where dimension_id = #{dimensionId}
    </update>

    <delete id="deleteDimensionByDimensionId" parameterType="Long">
        delete from dimension where dimension_id = #{dimensionId}
    </delete>

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