<?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">
<!-- UIWS system 이식: 권한-메뉴 매핑(tb_uiws_role_menu). -->
<mapper namespace="com.zioinfo.signage.uiws.system.mapper.RoleMenuMapper">

    <select id="findByRoleId" resultType="com.zioinfo.signage.uiws.system.model.SysRoleMenu">
        SELECT * FROM tb_uiws_role_menu WHERE role_id = #{roleId}
    </select>

    <select id="existsByMenuId" resultType="boolean">
        SELECT EXISTS(SELECT 1 FROM tb_uiws_role_menu WHERE menu_id = #{menuId})
    </select>

    <insert id="insert" parameterType="com.zioinfo.signage.uiws.system.model.SysRoleMenu">
        INSERT INTO tb_uiws_role_menu (role_id, menu_id, read_yn, write_yn, created_by, created_at)
        VALUES (#{roleId}, #{menuId}, #{readYn}, #{writeYn}, #{createdBy}, now())
        ON CONFLICT (role_id, menu_id) DO UPDATE SET
            read_yn = EXCLUDED.read_yn, write_yn = EXCLUDED.write_yn
    </insert>

    <delete id="deleteByRoleId">
        DELETE FROM tb_uiws_role_menu WHERE role_id = #{roleId}
    </delete>
</mapper>
