From 1bbd11bbcdb3f96a0bd608826382e23d0f8833f3 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 2 Sep 2024 17:27:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E4=BC=91=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helper/HolidayHelper.cs | 111 ++++++++++++++++++ .../IRaCIS.Core.Application.csproj | 1 + .../Service/ImageAndDoc/StudyService.cs | 6 + IRaCIS.Core.Application/TestService.cs | 6 + 4 files changed, 124 insertions(+) create mode 100644 IRaCIS.Core.Application/Helper/HolidayHelper.cs diff --git a/IRaCIS.Core.Application/Helper/HolidayHelper.cs b/IRaCIS.Core.Application/Helper/HolidayHelper.cs new file mode 100644 index 000000000..0e6886d3f --- /dev/null +++ b/IRaCIS.Core.Application/Helper/HolidayHelper.cs @@ -0,0 +1,111 @@ +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IRaCIS.Core.Application.Helper +{ + + #region 对接模型 + public class HolidayCalendar + { + public string Name { get; set; } + public string Version { get; set; } + public string Generated { get; set; } + public string Timezone { get; set; } + public string Author { get; set; } + public string URL { get; set; } + public Dictionary> Years { get; set; } + } + + public class HolidayYear + { + public string Name { get; set; } + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } + public int Duration { get; set; } + public List CompDays { get; set; } + public string URL { get; set; } + public string Memo { get; set; } + } + #endregion + + + + + public class HolidayHelper + { + /// + /// github 链接:https://github.com/lanceliao/china-holiday-calender?tab=readme-ov-file  + /// 接口请求参考文档:https://www.koudingke.cn/docs/zh-Hans/net-lib-docs/latest/RestSharp/Usage/Usage + /// + private static RestClient _client => new RestClient("https://www.shuyz.com/githubfiles/china-holiday-calender/master/holidayAPI.json"); + + private static HolidayCalendar _holidayCalendar { get; set; } + + + private static List _holidays = new List(); + private static List _compensatedWorkdays = new List(); + + static HolidayHelper() + { + _holidayCalendar = _client.Get(new RestRequest()) ?? new HolidayCalendar(); + + foreach (var year in _holidayCalendar.Years.Values.SelectMany(x => x)) + { + // 添加节假日到假日集合 + for (DateTime date = year.StartDate; date <= year.EndDate; date = date.AddDays(1)) + { + _holidays.Add(date); + } + + // 添加补班日到补班日集合 + foreach (var compDay in year.CompDays) + { + _compensatedWorkdays.Add(compDay); + } + } + + } + + public static TimeSpan GetChinaWorkTimeSpan(DateTime startDate, DateTime endDate) + { + if (startDate > endDate) + { + throw new ArgumentException("结束日期必须大于或等于开始日期"); + } + + var diffTimeSpan = endDate - startDate; + + // 初始化工作日数为0 + int workdays = 0; + + // 找出在给定日期范围内的假期和补班日 + var filteredHolidays = _holidays.Where(d => d >= startDate && d <= endDate).ToList(); + var filteredCompensatedWorkdays = _compensatedWorkdays.Where(d => d >= startDate && d <= endDate).ToList(); + + // 遍历日期范围,计算工作日 注意 这里是小于 + for (DateTime date = startDate.Date; date < endDate.Date; date = date.AddDays(1)) + { + // 判断是否为工作日 + bool isWeekend = date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday; + bool isHoliday = filteredHolidays.Contains(date); + bool isCompensatedWorkday = filteredCompensatedWorkdays.Contains(date); + + // 如果是补班日,或是平日(非假期,非周末),则算作工作日 + if (isCompensatedWorkday || (!isWeekend && !isHoliday)) + { + workdays++; + } + } + + return new TimeSpan(workdays, diffTimeSpan.Hours, diffTimeSpan.Minutes, diffTimeSpan.Seconds); + + + } + + + } +} diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 4f27873ad..436ba3b88 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -83,6 +83,7 @@ + diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs index 9edffb891..7b66dfa33 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs @@ -117,6 +117,11 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] public async Task AddOrUpdateArchiveStudy(NewArchiveStudyCommand incommand) { + //总数为0的检查不允许提交 + if (incommand.Study.SeriesList.SelectMany(t => t.InstanceList).Count() == 0) + { + return ResponseOutput.NotOk("Study_InstanceCountZero"); + } var @uploadLock = _distributedLockProvider.CreateLock($"UploadDicom"); @@ -134,6 +139,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc } } + var modalitys = string.Empty; try diff --git a/IRaCIS.Core.Application/TestService.cs b/IRaCIS.Core.Application/TestService.cs index c5704afdc..d7ca0db8c 100644 --- a/IRaCIS.Core.Application/TestService.cs +++ b/IRaCIS.Core.Application/TestService.cs @@ -105,6 +105,12 @@ namespace IRaCIS.Application.Services } + public string TestHoliday(DateTime startdate,DateTime endDate) + { + var timeSpan= HolidayHelper.GetChinaWorkTimeSpan(startdate, endDate); + + return $"{timeSpan.Days}天,{timeSpan.Hours}小时{timeSpan.Minutes}分钟{timeSpan.Seconds}"; + } public async Task TestEFcore8() {