调休计算
parent
84f4343791
commit
1bbd11bbcd
|
@ -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<string, List<HolidayYear>> 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<DateTime> CompDays { get; set; }
|
||||
public string URL { get; set; }
|
||||
public string Memo { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
public class HolidayHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
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<DateTime> _holidays = new List<DateTime>();
|
||||
private static List<DateTime> _compensatedWorkdays = new List<DateTime>();
|
||||
|
||||
static HolidayHelper()
|
||||
{
|
||||
_holidayCalendar = _client.Get<HolidayCalendar>(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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -83,6 +83,7 @@
|
|||
</PackageReference>
|
||||
<PackageReference Include="NPOI" Version="2.7.1" />
|
||||
<PackageReference Include="Panda.DynamicWebApi" Version="1.2.2" />
|
||||
<PackageReference Include="RestSharp" Version="112.0.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
|
||||
<PackageReference Include="MassTransit.AspNetCore" Version="7.3.1" />
|
||||
|
|
|
@ -117,6 +117,11 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
|
|||
[TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })]
|
||||
public async Task<IResponseOutput> 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
|
||||
|
|
|
@ -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<IResponseOutput> TestEFcore8()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue