HolidayHelper.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Business.Domain;
  2. using Business.EntityFrameworkCore.SqlRepositories;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Volo.Abp.Application.Services;
  9. namespace Business.DOP
  10. {
  11. public class HolidayHelper : ApplicationService
  12. {
  13. /// <summary>
  14. /// 节假日记录表
  15. /// </summary>
  16. private ISqlRepository<HolidayMaster> _holidayMaster;
  17. public HolidayHelper(ISqlRepository<HolidayMaster> holidayMaster) {
  18. _holidayMaster = holidayMaster;
  19. }
  20. /// <summary>
  21. /// 向前推进num个工作日,去掉节假日
  22. /// </summary>
  23. /// <param name="toTime"></param>
  24. /// <param name="day"></param>
  25. /// <returns></returns>
  26. public DateTime GetWorkDateByWorkCalendar(DateTime toTime, int num, List<HolidayMaster> holidayList)
  27. {
  28. DateTime newTime = toTime.AddDays(-num);
  29. //向前推进时间
  30. //1.首先读取时间所处年份的节假日配置
  31. return ForwardDay(newTime, holidayList);
  32. }
  33. private DateTime ForwardDay(DateTime toTime, List<HolidayMaster> holidayList)
  34. {
  35. //2.判断当前月-日是否在补班日期中。
  36. if (holidayList.Where(x => x.Dated.GetValueOrDefault().Date == toTime.Date && x.Ufld1 == "调班").Any())
  37. {
  38. return toTime;
  39. }
  40. //3.判断当前日期是否在法定节假日中
  41. if (holidayList.Where(x => x.Dated.GetValueOrDefault().Date == toTime.Date && x.Ufld1 == "休假").Any())
  42. {
  43. toTime = toTime.AddDays(-1);
  44. return ForwardDay(toTime, holidayList);
  45. }
  46. int week = (int)toTime.DayOfWeek;
  47. if (week != 0 && week != 6)
  48. {
  49. return toTime;
  50. }
  51. else
  52. {
  53. toTime = toTime.AddDays(-1);
  54. return ForwardDay(toTime, holidayList);
  55. }
  56. }
  57. }
  58. }