using F9WebAiTest.Application.Common; using F9WebAiTest.Application.Dtos.SYS.WuziMulus; using F9WebAiTest.Application.Interfaces.Repositories.SYS.WuziMulus; using MediatR; namespace F9WebAiTest.Application.CQRS.SYS.WuziMulus.Queries; // ==================== 物资分组 ==================== /// 全部物资分组(用于构建分组树) public record GetWuziGroupAllQuery() : IRequest>; public class GetWuziGroupAllQueryHandler(IWuziGroupReadRepository readRepository) : IRequestHandler> { public async Task> Handle(GetWuziGroupAllQuery query, CancellationToken ct) => await readRepository.GetAllAsync(); } /// 按 Id 查询分组(编辑回显) public record GetWuziGroupByIdQuery(long Id) : IRequest; public class GetWuziGroupByIdQueryHandler(IWuziGroupReadRepository readRepository) : IRequestHandler { public async Task Handle(GetWuziGroupByIdQuery query, CancellationToken ct) => await readRepository.GetByIdForEditAsync(query.Id); } /// 分组新编号 public record GetWuziGroupNewCodeQuery(long ParentId) : IRequest; public class GetWuziGroupNewCodeQueryHandler(IWuziGroupReadRepository readRepository) : IRequestHandler { public async Task Handle(GetWuziGroupNewCodeQuery query, CancellationToken ct) => await readRepository.GetNewCodeAsync(query.ParentId); } /// 是否存在下级(删除前校验) public record GetWuziGroupExistChildQuery(long Id) : IRequest; public class GetWuziGroupExistChildQueryHandler(IWuziGroupReadRepository readRepository) : IRequestHandler { public async Task Handle(GetWuziGroupExistChildQuery query, CancellationToken ct) => await readRepository.ExistChildAsync(query.Id); } // ==================== 物资目录 ==================== /// 按分组分页查询物资 public record GetWuziMuluPagedQuery(long GroupId = 0, string Keyword = "", int PageIndex = 1, int PageSize = 20) : IRequest>; public class GetWuziMuluPagedQueryHandler(IWuziMuluReadRepository readRepository) : IRequestHandler> { public async Task> Handle(GetWuziMuluPagedQuery query, CancellationToken ct) => await readRepository.GetPagedAsync(query.GroupId, query.Keyword, query.PageIndex, query.PageSize); } /// 按 Id 查询物资(编辑回显) public record GetWuziMuluByIdQuery(long Id) : IRequest; public class GetWuziMuluByIdQueryHandler(IWuziMuluReadRepository readRepository) : IRequestHandler { public async Task Handle(GetWuziMuluByIdQuery query, CancellationToken ct) => await readRepository.GetByIdForEditAsync(query.Id); } /// 物资新编号 public record GetWuziMuluNewCodeQuery(long GroupId) : IRequest; public class GetWuziMuluNewCodeQueryHandler(IWuziMuluReadRepository readRepository) : IRequestHandler { public async Task Handle(GetWuziMuluNewCodeQuery query, CancellationToken ct) => await readRepository.GetNewCodeAsync(query.GroupId); } /// 物资选项(供其它模块选择物资) public record GetWuziMuluOptionsQuery(string Keyword = "", int Limit = 200) : IRequest>; public class GetWuziMuluOptionsQueryHandler(IWuziMuluReadRepository readRepository) : IRequestHandler> { public async Task> Handle(GetWuziMuluOptionsQuery query, CancellationToken ct) => await readRepository.GetOptionsAsync(query.Keyword, query.Limit); }