完善基础数据
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
using FreeSql;
|
||||
using F9WebAiTest.Application.Common;
|
||||
using F9WebAiTest.Application.Dtos.SYS.Zq;
|
||||
using F9WebAiTest.Application.Interfaces.Repositories.SYS.Zq;
|
||||
using F9WebAiTest.Domain.Entities.SYS.Zq;
|
||||
|
||||
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.Zq;
|
||||
|
||||
internal class ZhangqiReadRepository : F9RepositoryBase, IZhangqiReadRepository
|
||||
{
|
||||
public ZhangqiReadRepository(IFreeSql fsql) : base(fsql) { }
|
||||
|
||||
public async Task<PageResult<ZhangqiReadDto_View>> GetPagedAsync(int? year, string keyword, int pageIndex, int pageSize)
|
||||
{
|
||||
if (pageIndex <= 0) pageIndex = 1;
|
||||
if (pageSize <= 0) pageSize = 20;
|
||||
|
||||
var query = Orm.Select<Zhangqi>().Where(x => x.DeletedAt == null);
|
||||
if (year.HasValue && year.Value > 0) query = query.Where(x => x.Year == year.Value);
|
||||
|
||||
// 关键字:纯数字时按年度/月份匹配
|
||||
if (!string.IsNullOrWhiteSpace(keyword) && int.TryParse(keyword.Trim(), out var num))
|
||||
query = query.Where(x => x.Year == num || x.Month == num);
|
||||
|
||||
var total = await query.CountAsync();
|
||||
var items = await query
|
||||
.OrderByDescending(x => x.Year)
|
||||
.OrderByDescending(x => x.Month)
|
||||
.Page(pageIndex, pageSize)
|
||||
.ToListAsync(x => new ZhangqiReadDto_View(x.Id, x.Year, x.Month, x.StartDate, x.EndDate, x.IsZhaZhang));
|
||||
|
||||
return new PageResult<ZhangqiReadDto_View>
|
||||
{
|
||||
Items = items,
|
||||
Total = total,
|
||||
PageIndex = pageIndex,
|
||||
PageSize = pageSize
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<ZhangqiReadDto_Edit> GetByIdForEditAsync(long id)
|
||||
=> await Orm.Select<Zhangqi>()
|
||||
.Where(x => x.Id == id && x.DeletedAt == null)
|
||||
.FirstAsync(x => new ZhangqiReadDto_Edit(x.Id, x.Year, x.Month, x.StartDate, x.EndDate, x.IsZhaZhang));
|
||||
|
||||
public async Task<ZhangqiReadDto_Edit> GetByDateAsync(DateTime date)
|
||||
=> await Orm.Select<Zhangqi>()
|
||||
.Where(x => x.DeletedAt == null && x.StartDate <= date && x.EndDate >= date)
|
||||
.OrderByDescending(x => x.StartDate)
|
||||
.FirstAsync(x => new ZhangqiReadDto_Edit(x.Id, x.Year, x.Month, x.StartDate, x.EndDate, x.IsZhaZhang));
|
||||
|
||||
public async Task<bool> GetIsZhaZhangAsync(int year, int month)
|
||||
{
|
||||
var list = await Orm.Select<Zhangqi>()
|
||||
.Where(x => x.DeletedAt == null && x.Year == year && x.Month == month)
|
||||
.ToListAsync();
|
||||
return list.Any(x => x.IsZhaZhang);
|
||||
}
|
||||
|
||||
public async Task<bool> GetIsZhaZhangByDateAsync(DateTime date)
|
||||
{
|
||||
var dto = await GetByDateAsync(date);
|
||||
return dto != null && dto.IsZhaZhang;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user