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

    <resultMap type="SysScreenModuleVo" id="SysScreenModuleResult">
        <result property="id"    column="id"    />
        <result property="description"    column="description"    />
        <result property="name"    column="name"    />
        <result property="icon"    column="icon"    />
        <result property="sequence"    column="sequence"    />
        <result property="status"    column="status"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectSysScreenModuleVo">
        select ssm.id, ssm.description, ssm.name, ssm.icon, ssm.sequence,ssm.status, ssm.type from sys_screen_module ssm
    </sql>

    <select id="selectSysScreenModuleList" resultType="com.ruoyi.system.domain.vo.SysScreenModuleVo">
        <include refid="selectSysScreenModuleVo"/>
    </select>

    <resultMap type="SysScreenLocationVo" id="SysScreenLocationResult">
        <result property="id" column="id"/>
        <result property="locationNum" column="location_num"/>
        <result property="moduleId" column="module_id"/>
        <result property="userId" column="user_id"/>
        <result property="name" column="name"/>
        <result property="description" column="description"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectSysScreenLocationVo">
        select ssl.id, ssl.location_num, ssl.module_id, ssl.user_id, ssl.create_by, ssl.create_time,
               ssl.update_by, ssl.update_time, ssm.description, ssm.name
        from sys_screen_location ssl
        left join sys_screen_module ssm on ssl.module_id = ssm.id
    </sql>

    <select id="selectSysScreenLocationList" parameterType="SysScreenLocationDto" resultMap="SysScreenLocationResult">
        <include refid="selectSysScreenLocationVo"/>
        <where>
            <if test="locationNum != null "> and ssl.location_num = #{locationNum}</if>
            <if test="moduleId != null "> and ssl.module_id = #{moduleId}</if>
            <if test="userId != null "> and ssl.user_id = #{userId}</if>
        </where>
        order by ssl.create_time desc
    </select>

    <select id="selectSysScreenLocationById" parameterType="Long" resultMap="SysScreenLocationResult">
        <include refid="selectSysScreenLocationVo"/>
        where ssl.id = #{id}
    </select>

    <insert id="insertSysScreenLocation" parameterType="SysScreenLocation">
        insert into sys_screen_location
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="locationNum != null">location_num,</if>
            <if test="moduleId != null">module_id,</if>
            <if test="userId != null">user_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="locationNum != null">#{locationNum},</if>
            <if test="moduleId != null">#{moduleId},</if>
            <if test="userId != null">#{userId},</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>
         </trim>
    </insert>

    <update id="updateSysScreenLocation" parameterType="SysScreenLocation">
        update sys_screen_location
        <trim prefix="SET" suffixOverrides=",">
            <if test="locationNum != null">location_num = #{locationNum},</if>
            <if test="moduleId != null">module_id = #{moduleId},</if>
            <if test="userId != null">user_id = #{userId},</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>
        </trim>
        where user_id = #{userId} and location_num = #{locationNum}
    </update>

    <delete id="deleteSysScreenLocationById" parameterType="Long">
        delete from sys_screen_location where id = #{id}
    </delete>

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

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

    <update id="removeSysScreenLocationById" parameterType="Long">
         update sys_screen_location set del_flag='1' where id = #{id}
    </update>

    <update id="removeSysScreenLocationByIds" parameterType="String">
        update sys_screen_location set del_flag='1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <insert id="batchInsertSysScreenLocation">
        insert into sys_screen_location(id,location_num,module_id,user_id,create_by,create_time,update_by, update_time) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.id},#{item.locationNum},#{item.moduleId},#{item.userId},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime})
        </foreach>
    </insert>
</mapper>
