<?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.aiotagro.cattletrade.business.mapper.SysUserMenuMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.aiotagro.cattletrade.business.entity.SysUserMenu">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="menu_id" property="menuId" />
        <result column="create_time" property="createTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, menu_id, create_time
    </sql>

    <!-- 根据用户ID查询菜单列表（包含权限信息） -->
    <select id="selectMenusByUserId" resultType="com.aiotagro.cattletrade.business.entity.SysMenu">
        SELECT DISTINCT m.*
        FROM sys_menu m
        INNER JOIN sys_user_menu um ON m.id = um.menu_id
        WHERE um.user_id = #{userId}
          AND m.is_delete = 0
        ORDER BY m.sort ASC
    </select>

    <!-- 根据用户ID查询已分配的菜单ID列表 -->
    <select id="selectMenuIdsByUserId" resultType="java.lang.Integer">
        SELECT menu_id
        FROM sys_user_menu
        WHERE user_id = #{userId}
        ORDER BY create_time ASC
    </select>

</mapper>
