完善基础数据
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;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using FreeSql;
|
||||
using F9WebAiTest.Domain.Entities.SYS.Zq;
|
||||
using F9WebAiTest.Domain.Interfaces.SYS.Zq;
|
||||
|
||||
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.Zq;
|
||||
|
||||
internal class ZhangqiWriteRepository : F9RepositoryBase, IZhangqiWriteRepository
|
||||
{
|
||||
public ZhangqiWriteRepository(IFreeSql fsql) : base(fsql) { }
|
||||
|
||||
public async Task<Zhangqi> GetByIdAsync(long id, CancellationToken cancellationToken)
|
||||
=> await Orm.Select<Zhangqi>().Where(x => x.Id == id && x.DeletedAt == null).FirstAsync(cancellationToken);
|
||||
|
||||
public async Task<bool> AddAsync(Zhangqi zhangqi)
|
||||
{
|
||||
zhangqi.CreatedAt = DateTime.Now;
|
||||
return await Orm.Insert(zhangqi).ExecuteAffrowsAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(Zhangqi zhangqi)
|
||||
{
|
||||
zhangqi.UpdatedAt = DateTime.Now;
|
||||
return await Orm.Update<Zhangqi>().SetSource(zhangqi).ExecuteAffrowsAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> SoftDeleteAsync(long id)
|
||||
=> await Orm.Update<Zhangqi>()
|
||||
.Set(x => x.IsDeleted, true)
|
||||
.Set(x => x.DeletedAt, DateTime.Now)
|
||||
.Where(x => x.Id == id)
|
||||
.ExecuteAffrowsAsync() > 0;
|
||||
|
||||
public async Task<bool> SetZhaZhangAsync(long id, bool isZhaZhang)
|
||||
=> await Orm.Update<Zhangqi>()
|
||||
.Set(x => x.IsZhaZhang, isZhaZhang)
|
||||
.Set(x => x.UpdatedAt, DateTime.Now)
|
||||
.Where(x => x.Id == id)
|
||||
.ExecuteAffrowsAsync() > 0;
|
||||
}
|
||||
Reference in New Issue
Block a user