<?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.dgtly.system.mapper.SysModelLayoutMapper">
    
    <resultMap type="SysModelLayout" id="SysModelLayoutResult">
        <result property="userId"    column="user_id"    />
        <result property="menuId"    column="menu_id"    />
        <result property="row"    column="row"    />
        <result property="col"    column="col"    />
        <result property="rowSpan"    column="rowSpan"    />
        <result property="colSpan"    column="colSpan"    />
        <result property="bgColor"    column="bgColor"    />
        <result property="titleColor"    column="titleColor"    />
        <result property="titlePosition"    column="titlePosition"    />
        <result property="titleFontSize"    column="titleFontSize"    />
        <result property="titleAlign"    column="titleAlign"    />
    </resultMap>

    <sql id="selectSysModelLayoutVo">
        select user_id, menu_id, row, col, rowSpan, colSpan, bgColor,titleColor,
         titlePosition, titleFontSize, titleAlign from sys_model_layout
    </sql>

    <select id="selectModelMenu" parameterType="Long" resultType="Map">
        select
        sml.user_id userId,
        sml.menu_id menuId,
        sml.row,
        sml.col,
        sml.rowSpan,
        sml.colSpan,
        sml.bgColor,
        sml.titleColor,
        sml.titlePosition,
        sml.titleFontSize,
        sml.titleAlign,
        sm.menu_name menuName,
        sm.menu_type menuType,
        sm.target,
        sm.url,
        sm.icon,
        sm.isrefresh,
        sm.app_type appType
        from sys_model_layout sml
        left join sys_menu sm on sm.menu_id = sml.menu_id
        <where>
            sml.user_id=#{userId}
        </where>
    </select>

    
    <select id="selectSMLByUserIdMenuId" parameterType="Long" resultMap="SysModelLayoutResult">
        <include refid="selectSysModelLayoutVo"/>
        where user_id = #{userId} and menu_id = #{menuId}
    </select>
        
    <insert id="insertSysModelLayout" parameterType="SysModelLayout" useGeneratedKeys="true" keyProperty="id">
        insert into sys_model_layout
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null ">user_id,</if>
            <if test="menuId != null ">menu_id,</if>
            <if test="row != null ">row,</if>
            <if test="col != null ">col,</if>
            <if test="rowSpan != null ">rowSpan,</if>
            <if test="colSpan != null ">colSpan,</if>
            <if test="bgColor != null and bgColor != '' ">bgColor,</if>
            <if test="titleColor != null  and titleColor != ''">titleColor,</if>
            <if test="titlePosition != null  and titlePosition != ''">titlePosition,</if>
            <if test="titleFontSize != null  and titleFontSize != ''">titleFontSize,</if>
            <if test="titleAlign != null  and titleAlign != ''">titleAlign,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null ">#{userId},</if>
            <if test="menuId != null ">#{menuId},</if>
            <if test="row != null ">#{row},</if>
            <if test="col != null ">#{col},</if>
            <if test="rowSpan != null ">#{rowSpan},</if>
            <if test="colSpan != null ">#{colSpan},</if>
            <if test="bgColor != null and bgColor != '' ">#{bgColor},</if>
            <if test="titleColor != null  and titleColor != ''">#{titleColor},</if>
            <if test="titlePosition != null  and titlePosition != ''">#{titlePosition},</if>
            <if test="titleFontSize != null  and titleFontSize != ''">#{titleFontSize},</if>
            <if test="titleAlign != null  and titleAlign != ''">#{titleAlign},</if>
         </trim>
    </insert>

    <update id="updateSysModelLayout" parameterType="SysModelLayout">
        update sys_model_layout
        <trim prefix="SET" suffixOverrides=",">
            <if test="row != null ">row=#{row},</if>
            <if test="col != null ">col=#{col},</if>
            <if test="rowSpan != null ">rowSpan=#{rowSpan},</if>
            <if test="colSpan != null ">colSpan=#{colSpan},</if>
            <if test="bgColor != null and bgColor != '' ">bgColor=#{bgColor},</if>
            <if test="titleColor != null  and titleColor != ''">titleColor=#{titleColor},</if>
            <if test="titlePosition != null  and titlePosition != ''">titlePosition=#{titlePosition},</if>
            <if test="titleFontSize != null  and titleFontSize != ''">titleFontSize=#{titleFontSize},</if>
            <if test="titleAlign != null  and titleAlign != ''">titleAlign=#{titleAlign},</if>

        </trim>
        where user_id = #{userId}
        and menu_id= #{menuId}
    </update>

    <delete id="deleteSMLByUserIdMenuId" parameterType="Long">
        delete from sys_model_layout where user_id = #{userId} and menu_id =#{menuId}
    </delete>

    <delete id="deleteSMLs" >
        delete from sys_model_layout
        <where>
            user_id = #{userId} and menu_id in
            <foreach item="menuId" collection="menuIds" open="("  close=" )" separator=",">
                #{menuId}
            </foreach>
        </where>

    </delete>
    
</mapper>