Files
DMS/DMS.Infrastructure/Repositories/MenuRepository.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2025-07-03 13:53:29 +08:00
using System.Diagnostics;
2025-07-02 22:07:16 +08:00
using SqlSugar;
using AutoMapper;
using DMS.Infrastructure.Entities;
using DMS.Core.Enums;
2025-07-19 09:25:01 +08:00
using DMS.Core.Helper;
using DMS.Core.Models;
using DMS.Infrastructure.Data;
2025-07-19 11:11:01 +08:00
using DMS.Infrastructure.Interfaces;
namespace DMS.Infrastructure.Repositories;
2025-07-19 22:29:50 +08:00
public class MenuRepository : BaseRepository<DbMenu>,IMenuRepository
{
public MenuRepository(SqlSugarDbContext dbContext)
: base(dbContext)
{
}
public async Task<List<DbMenu>> GetMenuTreesAsync()
{
2025-07-03 13:53:29 +08:00
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
2025-07-19 11:11:01 +08:00
var dbMenuTree = await Db.Queryable<DbMenu>()
.ToTreeAsync(dm => dm.Childrens, dm => dm.ParentId, 0);
2025-07-19 11:11:01 +08:00
stopwatch.Stop();
NlogHelper.Info($"获取菜单树耗时:{stopwatch.ElapsedMilliseconds}ms");
return dbMenuTree;
}
// /// <summary>
// /// 编辑菜单,支持事务
// /// </summary>
// /// <param name="menu"></param>
// /// <returns></returns>
//
// public async Task<DbMenu?> GetMenuByDataIdAsync(int dataId, MenuType menuType)
// {
// Stopwatch stopwatch = new Stopwatch();
// stopwatch.Start();
// var result = await Db.Queryable<DbMenu>()
// .FirstAsync(m => m.DataId == dataId && m.Type == menuType);
// stopwatch.Stop();
// NlogHelper.Info($"根据DataId '{dataId}' 和 MenuType '{menuType}' 获取菜单耗时:{stopwatch.ElapsedMilliseconds}ms");
// return result;
// }
2025-06-30 20:11:21 +08:00
}