53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
|
|
namespace Repository;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 节假日仓储接口
|
||
|
|
/// </summary>
|
||
|
|
public interface IHolidayRepository : IBaseRepository<Holiday>
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 根据年份获取节假日列表
|
||
|
|
/// </summary>
|
||
|
|
Task<List<Holiday>> GetByYearAsync(int year);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 根据日期范围获取节假日列表
|
||
|
|
/// </summary>
|
||
|
|
Task<List<Holiday>> GetByDateRangeAsync(string startDate, string endDate);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 根据年份删除节假日数据(用于刷新)
|
||
|
|
/// </summary>
|
||
|
|
Task<bool> DeleteByYearAsync(int year);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 节假日仓储实现
|
||
|
|
/// </summary>
|
||
|
|
public class HolidayRepository(IFreeSql freeSql)
|
||
|
|
: BaseRepository<Holiday>(freeSql), IHolidayRepository
|
||
|
|
{
|
||
|
|
public async Task<List<Holiday>> GetByYearAsync(int year)
|
||
|
|
{
|
||
|
|
return await freeSql.Select<Holiday>()
|
||
|
|
.Where(h => h.Year == year)
|
||
|
|
.OrderBy(h => h.Date)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<List<Holiday>> GetByDateRangeAsync(string startDate, string endDate)
|
||
|
|
{
|
||
|
|
return await freeSql.Select<Holiday>()
|
||
|
|
.Where(h => h.Date.CompareTo(startDate) >= 0 && h.Date.CompareTo(endDate) <= 0)
|
||
|
|
.OrderBy(h => h.Date)
|
||
|
|
.ToListAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<bool> DeleteByYearAsync(int year)
|
||
|
|
{
|
||
|
|
return await freeSql.Delete<Holiday>()
|
||
|
|
.Where(h => h.Year == year)
|
||
|
|
.ExecuteAffrowsAsync() > 0;
|
||
|
|
}
|
||
|
|
}
|