| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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
- {
- /// <summary>
- /// 节假日记录表
- /// </summary>
- private ISqlRepository<HolidayMaster> _holidayMaster;
- public HolidayHelper(ISqlRepository<HolidayMaster> holidayMaster) {
- _holidayMaster = holidayMaster;
- }
- /// <summary>
- /// 向前推进num个工作日,去掉节假日
- /// </summary>
- /// <param name="toTime"></param>
- /// <param name="day"></param>
- /// <returns></returns>
- public DateTime GetWorkDateByWorkCalendar(DateTime toTime, int num, List<HolidayMaster> holidayList)
- {
- DateTime newTime = toTime.AddDays(-num);
- //向前推进时间
- //1.首先读取时间所处年份的节假日配置
-
- return ForwardDay(newTime, holidayList);
- }
- private DateTime ForwardDay(DateTime toTime, List<HolidayMaster> 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);
- }
- }
- }
- }
|