first commit

This commit is contained in:
yanpeng200212
2026-10-08 10:43:59 +08:00
commit 8430ba0452
288 changed files with 29595 additions and 0 deletions
@@ -0,0 +1,61 @@
using FreeSql;
using F9WebAiTest.Application.Dtos.SYS.RBAC.Menus;
using F9WebAiTest.Application.Interfaces.Repositories.SYS.RBAC.Menus;
using F9WebAiTest.Domain.Entities.SYS.RBAC;
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.RBAC.Menus;
internal class MenuReadRepository : F9RepositoryBase, IMenuReadRepository
{
public MenuReadRepository(IFreeSql fsql) : base(fsql) { }
public async Task<MenuReadDto_Menu_Edit?> GetMenuByIdForEditAsync(long id)
=> await Orm.Select<Menu>()
.Where(x => x.Id == id && x.DeletedAt == null)
.FirstAsync(x => new MenuReadDto_Menu_Edit(x.Id, x.Code, x.Name, x.IconSvg, x.MenuType, x.AssemblyName, x.TypeFullName, x.IsActive, x.ParentId, x.SortOrder));
public async Task<bool> ExistMenuByTypeFullnameExcludeIdAsync(string typeFullname, long? excludeId)
{
var query = Orm.Select<Menu>().Where(x => x.TypeFullName == typeFullname && x.DeletedAt == null);
if (excludeId.HasValue)
query = query.Where(x => x.Id != excludeId.Value);
return await query.AnyAsync();
}
public async Task<List<MenuReadDto_Menu_Table>> GetAllMenuAsync(string like, long? parentId)
{
var all = await Orm.Select<Menu>().Where(x => x.DeletedAt == null).ToListAsync();
var dict = all.ToDictionary(x => x.Id, x => x.Name);
var list = all.AsEnumerable();
if (parentId.HasValue)
list = list.Where(x => x.ParentId == parentId.Value);
if (!string.IsNullOrWhiteSpace(like))
list = list.Where(x => x.Name.Contains(like) || x.Code.Contains(like));
return list.OrderBy(x => x.SortOrder).Select(x => ToTable(x, dict)).ToList();
}
public async Task<List<MenuReadDto_Menu_Table>> GetTreeMenuAsync()
{
var all = await Orm.Select<Menu>().Where(x => x.DeletedAt == null).OrderBy(x => x.SortOrder).ToListAsync();
var dict = all.ToDictionary(x => x.Id, x => x.Name);
return BuildTree(all, 0, dict);
}
private static MenuReadDto_Menu_Table ToTable(Menu x, Dictionary<long, string> dict)
=> new(x.Id, x.ParentId, x.Code, x.Name, x.IconSvg, x.MenuType.ToString(),
x.AssemblyName, x.TypeFullName, dict.GetValueOrDefault(x.ParentId, ""), x.Level,
x.IsActive ? "启用" : "禁用", x.SortOrder);
private static List<MenuReadDto_Menu_Table> BuildTree(List<Menu> all, long parentId, Dictionary<long, string> dict)
=> all.Where(x => x.ParentId == parentId).OrderBy(x => x.SortOrder).Select(x =>
{
var children = BuildTree(all, x.Id, dict);
return new MenuReadDto_Menu_Table(
x.Id, x.ParentId, x.Code, x.Name, x.IconSvg, x.MenuType.ToString(),
x.AssemblyName, x.TypeFullName, dict.GetValueOrDefault(x.ParentId, ""), x.Level,
x.IsActive ? "启用" : "禁用", x.SortOrder, false,
children.Count > 0 ? children.ToArray() : default);
}).ToList();
}
@@ -0,0 +1,38 @@
using FreeSql;
using F9WebAiTest.Domain.Entities.SYS.RBAC;
using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Menus;
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.RBAC.Menus;
internal class MenuWriteRepository : F9RepositoryBase, IMenuWriteRepository
{
public MenuWriteRepository(IFreeSql fsql) : base(fsql) { }
public async Task<Menu> GetByIdAsync(long id)
=> await Orm.Select<Menu>().Where(x => x.Id == id ).FirstAsync();
public async Task<bool> AddAsync(Menu menu)
{
menu.CreatedAt = DateTime.Now;
return await Orm.Insert(menu).ExecuteAffrowsAsync() > 0;
}
public async Task<bool> UpdateAsync(Menu menu)
{
menu.UpdatedAt = DateTime.Now;
return await Orm.Update<Menu>().SetSource(menu).ExecuteAffrowsAsync() > 0;
}
public async Task<bool> SoftDeleteAsync(long id)
=> await Orm.Update<Menu>()
.Set(x => x.IsDeleted, true)
.Where(x => x.Id == id )
.ExecuteAffrowsAsync() > 0;
public async Task<bool> ActiveOrDeactive(long id, bool active)
=> await Orm.Update<Menu>()
.Set(x => x.IsActive, active)
.Set(x => x.UpdatedAt, DateTime.Now)
.Where(x => x.Id == id)
.ExecuteAffrowsAsync() > 0;
}