2025-07-03 13:53:29 +08:00
|
|
|
using System.Diagnostics;
|
2025-07-02 22:07:16 +08:00
|
|
|
using SqlSugar;
|
2025-07-15 22:18:37 +08:00
|
|
|
using AutoMapper;
|
2025-07-18 22:21:16 +08:00
|
|
|
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;
|
2025-06-24 20:48:38 +08:00
|
|
|
|
2025-07-18 22:21:16 +08:00
|
|
|
namespace DMS.Infrastructure.Repositories;
|
2025-06-24 20:48:38 +08:00
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
public class MenuRepository : BaseRepository<DbMenu>
|
2025-06-24 20:48:38 +08:00
|
|
|
{
|
2025-07-19 14:36:34 +08:00
|
|
|
public MenuRepository(SqlSugarDbContext dbContext)
|
|
|
|
|
: base(dbContext)
|
2025-06-24 20:48:38 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
public override async Task<int> DeleteAsync(DbMenu menu)
|
2025-07-01 21:34:20 +08:00
|
|
|
{
|
2025-07-19 14:36:34 +08:00
|
|
|
return await base.DeleteAsync(menu);
|
2025-07-01 21:34:20 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
|
2025-07-04 18:33:48 +08:00
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
public async Task<List<DbMenu>> GetMenuTreesAsync()
|
2025-06-24 20:48:38 +08:00
|
|
|
{
|
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.Items, dm => dm.ParentId, 0);
|
|
|
|
|
|
|
|
|
|
stopwatch.Stop();
|
|
|
|
|
NlogHelper.Info($"获取菜单树耗时:{stopwatch.ElapsedMilliseconds}ms");
|
2025-07-19 14:36:34 +08:00
|
|
|
return dbMenuTree;
|
2025-06-24 20:48:38 +08:00
|
|
|
}
|
2025-06-26 19:36:27 +08:00
|
|
|
|
2025-06-30 22:03:49 +08:00
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
public override async Task<DbMenu> AddAsync(DbMenu menu)
|
2025-06-24 20:48:38 +08:00
|
|
|
{
|
2025-07-19 14:36:34 +08:00
|
|
|
return await base.AddAsync(menu);
|
2025-06-24 20:48:38 +08:00
|
|
|
}
|
2025-07-04 18:33:48 +08:00
|
|
|
|
|
|
|
|
|
2025-07-02 22:07:16 +08:00
|
|
|
/// <summary>
|
2025-07-04 18:33:48 +08:00
|
|
|
/// 添加菜单,支持事务
|
2025-07-02 22:07:16 +08:00
|
|
|
/// </summary>
|
2025-07-04 18:33:48 +08:00
|
|
|
/// <param name="menu"></param>
|
2025-07-02 22:07:16 +08:00
|
|
|
/// <param name="db"></param>
|
|
|
|
|
/// <returns></returns>
|
2025-07-19 14:36:34 +08:00
|
|
|
|
2025-06-30 20:11:21 +08:00
|
|
|
|
2025-07-02 22:07:16 +08:00
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
|
2025-06-26 22:40:20 +08:00
|
|
|
|
2025-07-04 18:33:48 +08:00
|
|
|
|
2025-07-02 22:07:16 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加设备菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="device"></param>
|
|
|
|
|
/// <param name="db"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="InvalidOperationException"></exception>
|
2025-07-19 14:36:34 +08:00
|
|
|
|
2025-07-01 21:34:20 +08:00
|
|
|
|
2025-07-04 18:33:48 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="menu"></param>
|
|
|
|
|
/// <returns></returns>
|
2025-07-19 14:36:34 +08:00
|
|
|
public override async Task<int> UpdateAsync(DbMenu menu)
|
2025-07-01 21:34:20 +08:00
|
|
|
{
|
2025-07-19 14:36:34 +08:00
|
|
|
return await base.UpdateAsync(menu);
|
2025-07-01 21:34:20 +08:00
|
|
|
}
|
2025-07-04 18:33:48 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑菜单,支持事务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="menu"></param>
|
|
|
|
|
/// <returns></returns>
|
2025-07-19 14:36:34 +08:00
|
|
|
|
2025-07-05 18:35:40 +08:00
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
public async Task<DbMenu?> GetMenuByDataIdAsync(int dataId, MenuType menuType)
|
2025-07-05 18:35:40 +08:00
|
|
|
{
|
|
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
|
|
stopwatch.Start();
|
2025-07-19 11:11:01 +08:00
|
|
|
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");
|
2025-07-19 14:36:34 +08:00
|
|
|
return result;
|
2025-07-05 18:35:40 +08:00
|
|
|
}
|
2025-07-05 21:49:41 +08:00
|
|
|
|
2025-07-19 14:36:34 +08:00
|
|
|
public async Task<DbMenu> GetMainMenuByNameAsync(string name)
|
2025-07-05 21:49:41 +08:00
|
|
|
{
|
2025-07-19 11:11:01 +08:00
|
|
|
var dbMenu= await Db.Queryable<DbMenu>().FirstAsync(m => m.Name == name && m.Type == MenuType.MainMenu);
|
2025-07-19 14:36:34 +08:00
|
|
|
return dbMenu;
|
2025-07-05 21:49:41 +08:00
|
|
|
}
|
2025-06-30 20:11:21 +08:00
|
|
|
}
|