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

+ 143 - 2
src/Hotline.Api/Controllers/HotSpotController.cs

@@ -1,6 +1,13 @@
-using Hotline.Orders;
+using Hotline.CallCenter.Ivrs;
+using Hotline.Orders;
+using Hotline.Repository.SqlSugar.Extensions;
+using Hotline.Share.Dtos;
+using Hotline.Share.Dtos.Order;
+using MapsterMapper;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
+using XF.Domain.Exceptions;
+using static Google.Rpc.Context.AttributeContext.Types;
 
 namespace Hotline.Api.Controllers
 {
@@ -10,12 +17,19 @@ namespace Hotline.Api.Controllers
     public class HotspotController : BaseController
     {
         private readonly IHotspotTypeRepository _hotspotTypeRepository;
+        private readonly IMapper _mapper;
+        private readonly ITimeLimitDomainService _timeLimitDomainService;
+        private readonly ITimeLimitRepository _timeLimitRepository;
 
-        public HotspotController(IHotspotTypeRepository hotspotTypeRepository)
+        public HotspotController(IHotspotTypeRepository hotspotTypeRepository,IMapper mapper, ITimeLimitDomainService timeLimitDomainService, ITimeLimitRepository timeLimitRepository)
         {
             _hotspotTypeRepository = hotspotTypeRepository;
+            _mapper = mapper;
+            _timeLimitDomainService = timeLimitDomainService;
+            _timeLimitRepository = timeLimitRepository;
         }
 
+        #region 热点
         /// <summary>
         /// 查询子项
         /// </summary>
@@ -48,5 +62,132 @@ namespace Hotline.Api.Controllers
             hotspots.AddRange(targetList);
             return hotspots.OrderBy(d=>d.HotSpotName).ToList();
         }
+
+        #endregion
+
+
+        #region 时限管理
+        /// <summary>
+        /// 新增时限管理
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns>数据主键</returns>
+        [HttpPost("add-timelimit")]
+        public async Task<string> AddTimeLimit([FromBody]AddTimeLimitDto dto)
+        {
+            var model = _mapper.Map<TimeLimit>(dto);
+            model.TimeLimitState = Share.Enums.Order.ETimeLimitState.Draft;
+            return await _timeLimitDomainService.AddAsync(model, HttpContext.RequestAborted);
+        }
+
+
+        /// <summary>
+        /// 修改时限管理
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("update-timelimit")]
+        public async Task UpdateTimeLimit([FromBody]UpdateTimeLimitDto dto)
+        {
+            var model = _mapper.Map<TimeLimit>(dto);
+            await _timeLimitDomainService.UpdateAsync(model, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 获取对象
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("timelimit/{id}")]
+        public async Task<TimeLimit?> GetTimeLimit(string id)
+        {
+            return await _timeLimitRepository.GetAsync(id, HttpContext.RequestAborted);
+        }
+
+
+        /// <summary>
+        /// 获取时限管理列表
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpGet("paged-timelimit")]
+        public async Task<PagedDto<TimeLimit>> QueryPagedTimeLimit([FromQuery] QueryPagedTimeLimitPagedDto dto)
+        {
+            var (total, items) = await _timeLimitRepository.Queryable()
+                .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.TimeLimitName.Contains(dto.Keyword!))
+                .OrderByDescending(d => d.CreationTime)
+                .ToPagedListAsync(dto.PageIndex,dto.PageSize, HttpContext.RequestAborted);
+            return new PagedDto<TimeLimit>(total, _mapper.Map<IReadOnlyList<TimeLimit>>(items));
+        }
+
+        /// <summary>
+        /// 删除时限(草稿)
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpDelete("deltimelimit")]
+        public async Task DelTimeLimit(string id)
+        {
+            var model = await _timeLimitRepository.GetAsync(id, HttpContext.RequestAborted);
+            if (model==null)
+            {
+                throw UserFriendlyException.SameMessage("无效数据");
+            }
+            if (model.TimeLimitState != Share.Enums.Order.ETimeLimitState.Draft)
+            {
+                throw UserFriendlyException.SameMessage("无法删除,请刷新页面");
+            }
+            await _timeLimitRepository.RemoveAsync(id,true,HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 启用时限
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("enable-timelimit/{id}")]
+        public async Task EnableTimeLimit(string id)
+        {
+            var model = await _timeLimitRepository.GetAsync(id, HttpContext.RequestAborted);
+            if (model==null)
+            {
+                throw UserFriendlyException.SameMessage("无效数据");
+            }
+            if (model.TimeLimitState == Share.Enums.Order.ETimeLimitState.Enable)
+            {
+                throw UserFriendlyException.SameMessage("该配置已生效");
+            }
+            var list = await _timeLimitRepository.QueryAsync(x => x.WorkflowCode == model.WorkflowCode && x.TimeLimitState == Share.Enums.Order.ETimeLimitState.Enable);
+            list.ForEach(x => x.TimeLimitState = Share.Enums.Order.ETimeLimitState.Disable);
+            model.TimeLimitState = Share.Enums.Order.ETimeLimitState.Enable;
+            list.Add(model);
+            await _timeLimitRepository.UpdateRangeAsync(list, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 禁用时限
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("disable-timelimit/{id}")]
+        public async Task DisableTimeLimit(string id)
+        {
+            var model = await _timeLimitRepository.GetAsync(id, HttpContext.RequestAborted);
+            if (model == null)
+            {
+                throw UserFriendlyException.SameMessage("无效数据");
+            }
+            if (model.TimeLimitState == Share.Enums.Order.ETimeLimitState.Draft)
+            {
+                throw UserFriendlyException.SameMessage("该配置未生效,无法禁用");
+            }
+            if (model.TimeLimitState == Share.Enums.Order.ETimeLimitState.Disable)
+            {
+                throw UserFriendlyException.SameMessage("该配置已禁用");
+            }
+            model.TimeLimitState = Share.Enums.Order.ETimeLimitState.Disable;
+            await _timeLimitRepository.UpdateAsync(model, HttpContext.RequestAborted);
+        }
+        #endregion
     }
 }

+ 141 - 0
src/Hotline.Share/Dtos/Order/TimeLimitDto.cs

@@ -0,0 +1,141 @@
+using Hotline.Share.Enums.Order;
+using Hotline.Share.Requests;
+
+namespace Hotline.Share.Dtos.Order
+{
+    public record AddTimeLimitDto
+    {
+        /// <summary>
+        /// 配置名称
+        /// </summary>
+        public string TimeLimitName { get; set; }
+
+        /// <summary>
+        /// 业务名称
+        /// </summary>
+        public string WorkflowName { get; set; }
+
+        /// <summary>
+        /// 业务编码
+        /// </summary>
+        public string WorkflowCode { get; set; }
+
+        /// <summary>
+        /// 已配置参数
+        /// </summary>
+        public List<ParamTypeModel>? ParamArr { get; set; }
+
+        /// <summary>
+        /// 排序
+        /// </summary>
+        public List<PriorityModel>? Priority { get; set; }
+
+        /// <summary>
+        /// 组合
+        /// </summary>
+        public List<CombinationModel>? Combination { get; set; }
+    }
+
+    #region Model
+
+    public class CombinationModel
+    {
+        /// <summary>
+        /// 组合ID
+        /// </summary>
+        public string Id { get; set; }
+
+        /// <summary>
+        /// 组合名称
+        /// </summary>
+        public string CombinationName { get; set; }
+
+
+        /// <summary>
+        /// 组合参数
+        /// </summary>
+        public List<CombinationParamModel> CombinationParam { get; set; }
+
+
+        /// <summary>
+        /// 时限
+        /// </summary>
+        public int TimeLimitValue { get; set; }
+        /// <summary>
+        /// 时限类型
+        /// </summary>
+        public string TimeLimit { get; set; }
+
+        /// <summary>
+        /// 换算时间(小时)
+        /// </summary>
+        public int Hour { get; set; }
+    }
+
+
+    public class CombinationParamModel
+    {
+        /// <summary>
+        /// 组合参数ID
+        /// </summary>
+        public string Id { get; set; }
+
+        /// <summary>
+        /// 组合参数名称
+        /// </summary>
+        public string ParamName { get; set; }
+    }
+
+
+
+    public class PriorityModel
+    {
+        public string Id { get; set; }
+
+        public string ParamTypeName { get; set; }
+
+        public int Sort { get; set; }
+    }
+
+
+    public class ParamTypeModel
+    {
+        public string ParamType { get; set; }
+
+        public List<ParamValueModel> ParamValue { get; set; }
+    }
+
+    public class ParamValueModel
+    {
+        public string Id { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public string ParamTypeName { get; set; }
+        /// <summary>
+        /// 时限
+        /// </summary>
+        public int TimeLimitValue { get; set; }
+        /// <summary>
+        /// 时限类型
+        /// </summary>
+        public string TimeLimit { get; set; }
+
+        /// <summary>
+        /// 换算时间(小时)
+        /// </summary>
+        public int Hour { get; set; }
+    }
+
+    #endregion
+
+    public record UpdateTimeLimitDto:AddTimeLimitDto
+    {
+        public string Id { get; set; }
+    }
+
+    public record QueryPagedTimeLimitPagedDto: PagedKeywordRequest
+    {
+
+    }
+}

+ 14 - 0
src/Hotline/Orders/ITimeLimitDomainService.cs

@@ -3,5 +3,19 @@ namespace Hotline.Orders
 {
     public interface ITimeLimitDomainService
     {
+        /// <summary>
+        /// 新增
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        Task<string> AddAsync(TimeLimit model, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="model"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        Task UpdateAsync(TimeLimit model, CancellationToken cancellationToken);
     }
 }

+ 2 - 84
src/Hotline/Orders/TimeLimit.cs

@@ -1,4 +1,5 @@
-using Hotline.Share.Enums.Order;
+using Hotline.Share.Dtos.Order;
+using Hotline.Share.Enums.Order;
 using SqlSugar;
 using XF.Domain.Repository;
 
@@ -32,87 +33,4 @@ namespace Hotline.Orders
 
 
     }
-
-    public class CombinationModel
-    {
-        /// <summary>
-        /// 组合ID
-        /// </summary>
-        public string Id { get; set; }
-
-        /// <summary>
-        /// 组合名称
-        /// </summary>
-        public string CombinationName { get; set; }
-
-
-        /// <summary>
-        /// 组合参数
-        /// </summary>
-        public List<CombinationParamModel> CombinationParam { get; set; }
-
-
-        /// <summary>
-        /// 时限
-        /// </summary>
-        public int TimeLimitValue { get; set; }
-        /// <summary>
-        /// 时限类型
-        /// </summary>
-        public string TimeLimit { get; set; }
-
-        /// <summary>
-        /// 换算时间(小时)
-        /// </summary>
-        public int Hour { get; set; }
-    }
-
-
-    public class CombinationParamModel
-    {
-        public string Id { get; set; }
-
-        public string ParamName { get; set; }
-    }
-
-
-
-    public class PriorityModel
-    {
-        public string Id { get; set; }
-
-        public string ParamTypeName { get; set; }
-
-        public int Sort { get; set; }
-    }
-
-
-    public class ParamTypeModel
-    {
-        public string ParamType { get; set; }
-
-        public List<ParamValueModel> ParamValue { get; set; }
-    }
-
-    public class ParamValueModel
-    {
-        public string Id { get; set; }
-        /// <summary>
-        /// 
-        /// </summary>
-        public string ParamTypeName { get; set; }
-        /// <summary>
-        /// 时限
-        /// </summary>
-        public int TimeLimitValue { get; set; }
-        /// <summary>
-        /// 时限类型
-        /// </summary>
-        public string TimeLimit { get; set; }
-
-        /// <summary>
-        /// 换算时间(小时)
-        /// </summary>
-        public int Hour { get; set; }
-    }
 }

+ 21 - 0
src/Hotline/Orders/TimeLimitDomainService.cs

@@ -1,8 +1,29 @@
 using XF.Domain.Dependency;
+using XF.Domain.Exceptions;
 
 namespace Hotline.Orders
 {
     public class TimeLimitDomainService: ITimeLimitDomainService, IScopeDependency
     {
+        private readonly ITimeLimitRepository _timeLimitRepository;
+
+        public TimeLimitDomainService(ITimeLimitRepository timeLimitRepository)
+        {
+            _timeLimitRepository = timeLimitRepository;
+        }
+
+        public async Task<string> AddAsync(TimeLimit model,CancellationToken cancellationToken)
+        {
+            return await _timeLimitRepository.AddAsync(model, cancellationToken);
+        }
+
+        public async Task UpdateAsync(TimeLimit model,CancellationToken cancellationToken)
+        {
+            var dbModel = await _timeLimitRepository.GetAsync(model.Id, cancellationToken);
+            if (dbModel == null) {
+                throw new UserFriendlyException("无效数据");
+            }
+            await _timeLimitRepository.UpdateAsync(model, cancellationToken);
+        }
     }
 }