using Business.Domain;
using Business.EntityFrameworkCore.SqlRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Business.DOP
{
public class HolidayHelper : ApplicationService
{
///
/// 节假日记录表
///
private ISqlRepository _holidayMaster;
public HolidayHelper(ISqlRepository holidayMaster) {
_holidayMaster = holidayMaster;
}
///
/// 向前推进num个工作日,去掉节假日
///
///
///
///
public DateTime GetWorkDateByWorkCalendar(DateTime toTime, int num, List holidayList)
{
DateTime newTime = toTime.AddDays(-num);
//向前推进时间
//1.首先读取时间所处年份的节假日配置
return ForwardDay(newTime, holidayList);
}
private DateTime ForwardDay(DateTime toTime, List holidayList)
{
//2.判断当前月-日是否在补班日期中。
if (holidayList.Where(x => x.Dated.GetValueOrDefault().Date == toTime.Date && x.Ufld1 == "调班").Any())
{
return toTime;
}
//3.判断当前日期是否在法定节假日中
if (holidayList.Where(x => x.Dated.GetValueOrDefault().Date == toTime.Date && x.Ufld1 == "休假").Any())
{
toTime = toTime.AddDays(-1);
return ForwardDay(toTime, holidayList);
}
int week = (int)toTime.DayOfWeek;
if (week != 0 && week != 6)
{
return toTime;
}
else
{
toTime = toTime.AddDays(-1);
return ForwardDay(toTime, holidayList);
}
}
}
}