package com.fs.hospital.mapper;

import java.util.List;

import com.fs.company.domain.CompanyMenu;
import com.fs.hospital.domain.HospitalMenu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 菜单权限Mapper接口
 *
 * @author fs
 * @date 2024-02-26
 */
public interface HospitalMenuMapper
{




    /**
     * 查询菜单权限
     *
     * @param menuId 菜单权限主键
     * @return 菜单权限
     */
    public HospitalMenu selectHospitalMenuByMenuId(Long menuId);

    /**
     * 查询菜单权限列表
     *
     * @param hospitalMenu 菜单权限
     * @return 菜单权限集合
     */
    public List<HospitalMenu> selectHospitalMenuList(HospitalMenu hospitalMenu);

    /**
     * 新增菜单权限
     *
     * @param hospitalMenu 菜单权限
     * @return 结果
     */
    public int insertHospitalMenu(HospitalMenu hospitalMenu);

    /**
     * 修改菜单权限
     *
     * @param hospitalMenu 菜单权限
     * @return 结果
     */
    public int updateHospitalMenu(HospitalMenu hospitalMenu);

    /**
     * 删除菜单权限
     *
     * @param menuId 菜单权限主键
     * @return 结果
     */
    public int deleteHospitalMenuByMenuId(Long menuId);

    /**
     * 批量删除菜单权限
     *
     * @param menuIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteHospitalMenuByMenuIds(Long[] menuIds);


   List<String> selectMenuPermsByUserId(Long userId);


    @Select("select distinct m.menu_id, m.parent_id,m.path, m.component, m.menu_name,  m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time\n" +
            "\t\tfrom hospital_menu m where m.menu_type in ('M', 'C') and m.status = 0\n" +
            "\t\torder by m.parent_id, m.order_num")
    public List<HospitalMenu> selectMenuTreeAll();

    List<HospitalMenu> selectMenuTreeByUserId(Long userId);
    @Select("select count(1) from company_menu where parent_id = #{menuId}")
    int hasChildByMenuId(Long menuId);


    @Select({"<script> " +
            "select m.menu_id " +
            "                   from hospital_menu m " +
            "                    left join hospital_role_menu rm on m.menu_id = rm.menu_id " +
            "                    where rm.role_id = #{roleId}" +
            "                    order by m.parent_id, m.order_num"+
            "</script>"})
    List<Integer> selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly);

}
