dss 2 жил өмнө
parent
commit
e65e6ee0d8

+ 17 - 1
src/Hotline.Api/Controllers/TestController.cs

@@ -1,4 +1,5 @@
 using Dapr;
+using Hotline.Application.TimeLimits;
 using Hotline.CallCenter.BlackLists;
 using Hotline.CallCenter.Devices;
 using Hotline.CallCenter.Ivrs;
@@ -9,6 +10,8 @@ using Hotline.Identity.Roles;
 using Hotline.Realtimes;
 using Hotline.Repository.SqlSugar;
 using Hotline.Share.Dtos.Realtime;
+using Hotline.Share.Dtos.Settings;
+using Hotline.Share.Enums.Settings;
 using Hotline.Users;
 using MediatR;
 using Microsoft.AspNetCore.Authorization;
@@ -43,6 +46,8 @@ public class TestController : BaseController
     private readonly IRoleRepository _roleRepository;
     private readonly IMediator _mediator;
 
+    private readonly ITimeLimitApplication _timeLimitApplication;
+
     //private readonly ITypedCache<List<User>> _cache;
     //private readonly ICacheManager<User> _cache;
 
@@ -74,7 +79,8 @@ public class TestController : BaseController
         IIvrDomainService ivrDomainService,
         ISugarUnitOfWork<HotlineDbContext> uow,
         IRoleRepository roleRepository,
-        IMediator mediator
+        IMediator mediator,
+        ITimeLimitApplication timeLimitApplication
     )
     {
         _logger = logger;
@@ -89,6 +95,7 @@ public class TestController : BaseController
         _uow = uow;
         _roleRepository = roleRepository;
         _mediator = mediator;
+        _timeLimitApplication = timeLimitApplication;
     }
 
     [AllowAnonymous]
@@ -104,6 +111,15 @@ public class TestController : BaseController
         return a;
     }
 
+    [AllowAnonymous]
+    [HttpGet("testtime")]
+    public async Task<TimeResult> TestTime(DateTime beginTime, ETimeType timeType, int timeValue)
+    {
+        return _timeLimitApplication.CalcEndTime(beginTime, timeType, timeValue);
+    }
+
+
+
     //[AllowAnonymous]
     [HttpGet("hash")]
     public async Task Hash()

+ 15 - 0
src/Hotline.Application/TimeLimits/ITimeLimitApplication.cs

@@ -0,0 +1,15 @@
+using Hotline.Share.Dtos.Settings;
+using Hotline.Share.Enums.Settings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.TimeLimits
+{
+    public interface ITimeLimitApplication
+    {
+        TimeResult CalcEndTime(DateTime beginTime, ETimeType timeType, int timeValue);
+    }
+}

+ 110 - 0
src/Hotline.Application/TimeLimits/TimeLimitApplication.cs

@@ -0,0 +1,110 @@
+
+using Hotline.Settings.TimeLimits;
+using Hotline.Share.Dtos.Settings;
+using Hotline.Share.Enums.Settings;
+using XF.Domain.Dependency;
+
+namespace Hotline.Application.TimeLimits
+{
+    public class TimeLimitApplication:ITimeLimitApplication, IScopeDependency
+    {
+        private readonly ITimeLimitRepository _timeLimitRepository;
+        private readonly IDaySettingRepository _daySettingRepository;
+
+        public TimeLimitApplication(ITimeLimitRepository timeLimitRepository, IDaySettingRepository daySettingRepository)
+        {
+            _timeLimitRepository = timeLimitRepository;
+            _daySettingRepository = daySettingRepository;
+        }
+
+
+
+        /// <summary>
+        /// 计算结束时间
+        /// </summary>
+        /// <param name="beginTime"></param>
+        /// <param name="timeType"></param>
+        /// <param name="timeValue"></param>
+        public TimeResult CalcEndTime(DateTime beginTime, ETimeType timeType, int timeValue)
+        {
+            switch (timeType)
+            {
+                //新增对应小时
+                case ETimeType.Hour:
+                    return new TimeResult { EndTime = beginTime.AddHours(timeValue), RuleStr = timeValue + "小时" };
+                //新增工作日
+                case ETimeType.WorkDay:
+                    //检查时间段内是否存在休息日或者工作日
+                    for (int i = 1; i < timeValue+1; i++)
+                    {
+                        if(IsWorkDay(beginTime.AddDays(1)))
+                        {
+                            beginTime = beginTime.AddDays(1);
+                        }
+                        else
+                        {
+                            i--;
+                        }
+                    }
+                    return new TimeResult { EndTime = beginTime, RuleStr = timeValue + "个工作日" };
+                //新增自然日
+                case ETimeType.Day:
+                    return new TimeResult { EndTime = beginTime.AddDays(timeValue), RuleStr = timeValue + "个自然日" };
+                default:
+                    return null;
+            }
+        }
+
+        private bool IsWorkDay(DateTime date)
+        {
+            return _daySettingRepository.IsWorkDay(date).GetAwaiter().GetResult();
+        }
+
+
+
+        //public async Task Get(string WorkflowCode, DateTime BeginTime, Dictionary<string, string> param)
+        //{
+        //    //1>> 取出对应已启用的配置
+        //    var model = await _timeLimitRepository.GetAsync(x => x.WorkflowCode == WorkflowCode && x.TimeLimitState == Share.Enums.Settings.ETimeLimitState.Enable);
+        //    if (model != null)
+        //    {
+        //        #region  组合优先级
+        //        //2>> 优先级 组合逻辑判定 (组合重复取最短时间)
+        //        //if (model.Combination?.Count > 0)
+        //        //{
+        //        //    foreach (var item in model.Combination)
+        //        //    {
+        //        //        int countx = item.CombinationParam.Count(x=> param.Any(d=>d.Key == x.Code && d.Value == x.ParamValue));
+
+        //        //        if (countx== item.CombinationParam.Count)
+        //        //        {
+
+        //        //        }
+        //        //    }
+        //        //}
+        //        #endregion
+
+        //        #region 排序优先级
+        //        //3>> 优先级 排序逻辑判定
+        //        if (model.Priority?.Count > 0)
+        //        {
+        //            var firstModel = model.Priority.OrderBy(x => x.Sort).FirstOrDefault(x => param.Any(d => d.Key == x.Code && d.Value == x.ParamTypeValue));
+        //            #region 计算结束时间
+
+
+        //            #endregion
+        //        }
+        //        #endregion
+
+        //        #region 配置优先级
+
+
+        //        #endregion
+
+        //    }
+        //}
+
+
+
+    }
+}

+ 26 - 0
src/Hotline.Repository.SqlSugar/System/DaySettingRepository.cs

@@ -0,0 +1,26 @@
+using Hotline.Repository.SqlSugar.DataPermissions;
+using Hotline.Settings.TimeLimits;
+using Hotline.Tools;
+using SqlSugar;
+using XF.Domain.Dependency;
+
+namespace Hotline.Repository.SqlSugar.System
+{
+    public class DaySettingRepository : BaseRepository<DaySetting>, IDaySettingRepository, IScopeDependency
+    {
+        public DaySettingRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder) : base(uow, dataPermissionFilterBuilder)
+        {
+        }
+
+        public async Task<bool> IsWorkDay(DateTime date)
+        {
+            var model = await Db.Queryable<DaySetting>().FirstAsync(x=> x.Day.Date == date.Date);
+            if (model!=null)
+            {
+                return model.IsWorkDay;
+            }
+            return WeekTool.IsWorkDay(date);
+        }
+
+    }
+}

+ 21 - 3
src/Hotline.Share/Dtos/Settings/TimeLimitDto.cs

@@ -1,4 +1,5 @@
 using Hotline.Share.Enums.Order;
+using Hotline.Share.Enums.Settings;
 using Hotline.Share.Requests;
 
 namespace Hotline.Share.Dtos.Settings
@@ -64,7 +65,7 @@ namespace Hotline.Share.Dtos.Settings
         /// <summary>
         /// 时限类型
         /// </summary>
-        public string TimeLimit { get; set; }
+        public ETimeType TimeLimit { get; set; }
 
         /// <summary>
         /// 换算时间(小时)
@@ -95,10 +96,12 @@ namespace Hotline.Share.Dtos.Settings
 
     public class PriorityModel
     {
-        public string Id { get; set; }
+        public string Code { get; set; }
 
         public string ParamTypeName { get; set; }
 
+        public string ParamTypeValue { get; set; }
+
         public int Sort { get; set; }
     }
 
@@ -124,7 +127,7 @@ namespace Hotline.Share.Dtos.Settings
         /// <summary>
         /// 时限类型
         /// </summary>
-        public string TimeLimit { get; set; }
+        public ETimeType TimeLimit { get; set; }
 
         /// <summary>
         /// 换算时间(小时)
@@ -143,4 +146,19 @@ namespace Hotline.Share.Dtos.Settings
     {
 
     }
+
+
+    #region 时间计算返回参数
+
+    public record TimeResult
+    {
+        public string RuleId { get; set; }
+
+        public DateTime EndTime { get; set; }
+
+        public string RuleStr { get; set; }
+    }
+
+    #endregion
+
 }

+ 15 - 0
src/Hotline.Share/Enums/Settings/ETimeType.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Share.Enums.Settings
+{
+    public enum ETimeType
+    {
+        Hour = 1,
+        WorkDay = 2,
+        Day= 3,
+    }
+}

+ 12 - 0
src/Hotline/Settings/TimeLimits/DaySetting.cs

@@ -0,0 +1,12 @@
+using XF.Domain.Repository;
+
+namespace Hotline.Settings.TimeLimits
+{
+    public class DaySetting : CreationEntity
+    {
+        public DateTime Day { get; set; }
+
+        public bool IsWorkDay { get; set; }
+
+    }
+}

+ 9 - 0
src/Hotline/Settings/TimeLimits/IDaySettingRepository.cs

@@ -0,0 +1,9 @@
+using XF.Domain.Repository;
+
+namespace Hotline.Settings.TimeLimits
+{
+    public interface IDaySettingRepository: IRepository<DaySetting>
+    {
+        Task<bool> IsWorkDay(DateTime date);
+    }
+}

+ 3 - 21
src/Hotline/Settings/TimeLimits/TimeLimitDomainService.cs

@@ -1,4 +1,6 @@
-using XF.Domain.Dependency;
+using Hotline.Share.Dtos.Settings;
+using Hotline.Share.Enums.Settings;
+using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
 
 namespace Hotline.Settings.TimeLimits
@@ -26,25 +28,5 @@ namespace Hotline.Settings.TimeLimits
             }
             await _timeLimitRepository.UpdateAsync(model, cancellationToken);
         }
-
-
-        //public async Task Get(string WorkflowCode, DateTime BeginTime, Dictionary<string, string> param)
-        //{
-        //    //1>> 取出对应已启用的配置
-        //    var model = await _timeLimitRepository.GetAsync(x => x.WorkflowCode == WorkflowCode && x.TimeLimitState == Share.Enums.Settings.ETimeLimitState.Enable);
-        //    if (model != null)
-        //    {
-        //        //组合逻辑
-        //        if (model.Combination.Count > 0)
-        //        {
-        //            foreach (var item in model.Combination)
-        //            {
-        //                item.CombinationParam.
-        //            }
-        //        }
-        //    }
-        //}
-
-
     }
 }

+ 21 - 1
src/Hotline/Tools/WeekTool.cs

@@ -1,4 +1,6 @@
-namespace Hotline.Tools
+using System;
+
+namespace Hotline.Tools
 {
     public static class WeekTool
     {
@@ -49,5 +51,23 @@
                     return -1;
             }
         }
+
+        /// <summary>
+        /// 是否工作日
+        /// </summary>
+        /// <param name="date"></param>
+        /// <returns></returns>
+        public static bool IsWorkDay(DateTime date)
+        {
+            var DayOfWeek = date.DayOfWeek;
+
+            if ((int)DayOfWeek==0 || (int)DayOfWeek==6)
+            {
+                return false;
+            }
+            return true;
+        }
+
+
     }
 }