Эх сурвалжийг харах

新增【特殊号码管理】的功能

libin 1 сар өмнө
parent
commit
8051cbe12f

+ 106 - 0
src/Hotline.Api/Controllers/SpecialController.cs

@@ -0,0 +1,106 @@
+using MapsterMapper;
+using Microsoft.AspNetCore.Mvc;
+using XF.Domain.Authentications;
+using Hotline.Share.Dtos;
+using Hotline.Share.Tools;
+using Hotline.Application.SpecialNumber;
+using Hotline.Share.Dtos.Special;
+
+namespace Hotline.Api.Controllers
+{
+    /// <summary>
+    /// 特殊号码
+    /// </summary>
+    public class SpecialController : BaseController
+    {
+        #region 注入
+
+        private readonly IMapper _mapper;
+        private readonly ISessionContext _sessionContext;
+        private readonly ISpecialNumberApplication _specialNumberApplication;
+
+
+        public SpecialController(
+           IMapper mapper,
+           ISessionContext sessionContext,
+           ISpecialNumberApplication specialNumberApplication)
+        {
+            _mapper = mapper;
+            _sessionContext = sessionContext;
+            _specialNumberApplication = specialNumberApplication;
+        }
+
+        #endregion
+
+        #region 特殊号码
+
+        /// <summary>
+        /// 特殊号码列表
+        /// </summary>
+        /// <param name="pagedDto"></param>
+        /// <returns></returns>
+        [HttpGet("number/list")]
+        public async Task<PagedDto<SpecialNumberInfoDto>> QueryAllSpecialNumberListAsync([FromQuery] SpecialNumberDto pagedDto)
+        {
+            return (await _specialNumberApplication.QueryAllSpecialNumberListAsync(pagedDto, HttpContext.RequestAborted)).ToPaged();
+        }
+
+        /// <summary>
+        /// 特殊号码新增
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("number/add")]
+        public async Task<string> AddSpecialNumberAsync([FromBody] AddSpecialNumberDto dto)
+        {
+            return await _specialNumberApplication.AddSpecialNumberAsync(dto, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 特殊号码编辑
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPut("number/update")]
+        public async Task UpdateSpecialNumberAsync([FromBody] UpdateSpecialNumberDto dto)
+        {
+            await _specialNumberApplication.UpdateSpecialNumberAsync(dto, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 特殊号码删除
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpDelete("number/remove")]
+        public async Task RemoveSpecialNumberAsync([FromBody] DelSpecialNumberDto dto)
+        {
+            await _specialNumberApplication.RemoveSpecialNumberAsync(dto, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 特殊号码详情根据id查询
+        /// </summary>
+        /// <param name="Id"></param>
+        /// <returns></returns>
+        [HttpGet("number/info")]
+        public async Task<SpecialNumberInfoDto> GetSpecialNumberAsync(string Id)
+        {
+            return await _specialNumberApplication.GetSpecialNumberAsync(Id, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 特殊号码详情根据号码查询
+        /// </summary>
+        /// <param name="PhoneNumber"></param>
+        /// <returns></returns>
+        [HttpGet("number/info/num")]
+        public async Task<SpecialNumberInfoDto> GetSpecialNumberByAsync(string PhoneNumber)
+        {
+            return await _specialNumberApplication.GetSpecialNumberByAsync(PhoneNumber, HttpContext.RequestAborted);
+        }
+
+        #endregion
+    }
+}
+

+ 54 - 0
src/Hotline.Application/SpecialNumber/ISpecialNumberApplication.cs

@@ -0,0 +1,54 @@
+using Hotline.Share.Dtos.Special;
+
+namespace Hotline.Application.SpecialNumber
+{
+    public interface ISpecialNumberApplication
+    {
+        #region 特殊号码
+
+        /// <summary>
+        /// 特殊号码 - 列表
+        /// </summary>
+        /// <param name="pagedDto"></param>
+        /// <returns></returns>
+        Task<(int, IList<SpecialNumberInfoDto>)> QueryAllSpecialNumberListAsync(SpecialNumberDto pagedDto, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// 特殊号码 - 新增
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        Task<string> AddSpecialNumberAsync(AddSpecialNumberDto dto, CancellationToken cancellationToken);
+
+        /// <summary>
+        ///特殊号码 - 编辑
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        Task UpdateSpecialNumberAsync(UpdateSpecialNumberDto dto, CancellationToken cancellationToken);
+
+        /// <summary>
+        ///特殊号码 - 删除
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        Task RemoveSpecialNumberAsync(DelSpecialNumberDto dto, CancellationToken cancellationToken);
+
+        /// <summary>
+        ///特殊号码 - 详情
+        /// </summary>
+        /// <param name="Id"></param>
+        /// <returns></returns>
+        Task<SpecialNumberInfoDto> GetSpecialNumberAsync(string Id, CancellationToken cancellationToken);
+
+        /// <summary>
+        ///特殊号码 - 详情
+        /// </summary>
+        /// <param name="PhoneNumber"></param>
+        /// <returns></returns>
+        Task<SpecialNumberInfoDto> GetSpecialNumberByAsync(string PhoneNumber, CancellationToken cancellationToken);
+
+        #endregion
+    }
+}

+ 169 - 0
src/Hotline.Application/SpecialNumber/SpecialNumberApplication.cs

@@ -0,0 +1,169 @@
+using MapsterMapper;
+using SqlSugar;
+using XF.Domain.Authentications;
+using XF.Domain.Dependency;
+using XF.Domain.Exceptions;
+using XF.Domain.Repository;
+using Hotline.Repository.SqlSugar.Extensions;
+using Hotline.Share.Dtos.Special;
+
+namespace Hotline.Application.SpecialNumber
+{
+    public class SpecialNumberApplication : ISpecialNumberApplication, IScopeDependency
+    {
+        #region 注册
+
+        private readonly IRepository<Hotline.Special.SpecialNumber> _specialNumberRepository;
+        private readonly ISessionContext _sessionContext;
+        private readonly IMapper _mapper;
+
+        public SpecialNumberApplication(
+            IRepository<Hotline.Special.SpecialNumber> specialNumberRepository,
+            ISessionContext sessionContext,
+            IMapper mapper)
+        {
+            _specialNumberRepository = specialNumberRepository;
+            _sessionContext = sessionContext;
+            _mapper = mapper;
+        }
+
+        #endregion
+
+        #region 特殊号码
+
+        #region 特殊号码 - 列表
+
+        /// <summary>
+        /// 特殊号码 - 列表
+        /// </summary>
+        /// <param name="pagedDto"></param>
+        /// <returns></returns>
+        public async Task<(int, IList<SpecialNumberInfoDto>)> QueryAllSpecialNumberListAsync(SpecialNumberDto dto, CancellationToken cancellationToken)
+        {
+            var typeSpliceName = string.Empty;
+
+            //单表分页
+            var (total, temp) = await _specialNumberRepository.Queryable()
+
+                .WhereIF(!string.IsNullOrEmpty(dto.PhoneNumber), x => x.PhoneNumber.Contains(dto.PhoneNumber))
+                .WhereIF(!string.IsNullOrEmpty(dto.Notes), x => x.Notes.Contains(dto.Notes))
+                .WhereIF(dto.CreationTimeStart.HasValue, x => x.CreationTime >= dto.CreationTimeStart)
+                .WhereIF(dto.CreationTimeEnd.HasValue, x => x.CreationTime <= dto.CreationTimeEnd)
+                .OrderByIF(dto is { SortField: "creationTime", SortRule: 0 }, x => x.CreationTime, OrderByType.Asc)  //创建时间升序
+                .OrderByIF(dto is { SortField: "creationTime", SortRule: 1 }, x => x.CreationTime, OrderByType.Desc) //创建时间降序
+                .ToPagedListAsync(dto.PageIndex, dto.PageSize, cancellationToken);
+            return (total, _mapper.Map<IList<SpecialNumberInfoDto>>(temp));
+            //return (total, temp);
+        }
+
+        #endregion
+
+        #region 特殊号码 - 新增
+
+        /// <summary>
+        /// 新增
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task<string> AddSpecialNumberAsync(AddSpecialNumberDto dto, CancellationToken cancellationToken)
+        {
+            var data = _mapper.Map<Hotline.Special.SpecialNumber>(dto);
+
+            var any = await _specialNumberRepository.Queryable().Where(x => x.PhoneNumber == dto.PhoneNumber).AnyAsync();
+            if (any)
+                throw UserFriendlyException.SameMessage("特殊号码已存在!");
+
+            data.InitId();
+
+            return await _specialNumberRepository.AddAsync(data, cancellationToken);
+        }
+
+        #endregion
+
+        #region 特殊号码 - 修改
+
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task UpdateSpecialNumberAsync(UpdateSpecialNumberDto dto, CancellationToken cancellationToken)
+        {
+            var data = await _specialNumberRepository.GetAsync(dto.Id);
+
+            if (data == null)
+                throw UserFriendlyException.SameMessage("特殊号码查询失败");
+
+            var any = await _specialNumberRepository.Queryable().Where(x => x.PhoneNumber == dto.PhoneNumber && x.Id != dto.Id).AnyAsync();
+            if (any)
+                throw UserFriendlyException.SameMessage("特殊号码已存在!");
+
+            data.PhoneNumber = dto.PhoneNumber;
+            data.Notes = dto.Notes;
+
+            await _specialNumberRepository.UpdateAsync(data, cancellationToken);
+        }
+
+        #endregion
+
+        #region 特殊号码 - 删除
+
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task RemoveSpecialNumberAsync(DelSpecialNumberDto dto, CancellationToken cancellationToken)
+        {
+            var data = await _specialNumberRepository.GetAsync(dto.Id);
+
+            if (data == null)
+                throw UserFriendlyException.SameMessage("特殊号码查询失败");
+
+            await _specialNumberRepository.RemoveAsync(data, false, cancellationToken);
+        }
+
+        #endregion
+
+        #region 特殊号码 - 详情
+
+        /// <summary>
+        /// 详情
+        /// </summary>
+        /// <param name="Id"></param>
+        /// <returns></returns>
+        public async Task<SpecialNumberInfoDto> GetSpecialNumberAsync(string Id, CancellationToken cancellationToken)
+        {
+            var data = await _specialNumberRepository.Queryable()
+                .Where(x => x.Id == Id).FirstAsync();
+            if (data == null)
+                throw UserFriendlyException.SameMessage("特殊号码查询失败");
+            return _mapper.Map<SpecialNumberInfoDto>(data);
+        }
+
+        #endregion
+
+        #region 特殊号码 - 详情
+
+        /// <summary>
+        /// 详情
+        /// </summary>
+        /// <param name="PhoneNumber"></param>
+        /// <returns></returns>
+        public async Task<SpecialNumberInfoDto> GetSpecialNumberByAsync(string PhoneNumber, CancellationToken cancellationToken)
+        {
+            var data = await _specialNumberRepository.Queryable()
+                .Where(x => x.PhoneNumber == PhoneNumber).FirstAsync();
+            if (data == null)
+                throw UserFriendlyException.SameMessage("特殊号码查询失败");
+            return _mapper.Map<SpecialNumberInfoDto>(data);
+        }
+
+        #endregion
+
+        #endregion
+    }
+}

+ 87 - 0
src/Hotline.Share/Dtos/Special/SpecialNumberDto.cs

@@ -0,0 +1,87 @@
+using Hotline.Share.Requests;
+
+namespace Hotline.Share.Dtos.Special
+{
+    public record AddSpecialNumberDto
+    {
+        /// <summary>
+        /// 电话号码
+        /// </summary>
+        public string PhoneNumber { get; set; }
+
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string? Notes { get; set; }
+    }
+
+    public record UpdateSpecialNumberDto : AddSpecialNumberDto
+    {
+        /// <summary>
+        /// 案例库ID
+        /// </summary>
+        public string Id { get; set; }
+    }
+
+    public record DelSpecialNumberDto
+    {
+        public string Id { get; set; }
+    }
+
+    public record SpecialNumberDto : PagedRequest
+    {
+        /// <summary>
+        /// 电话号码
+        /// </summary>
+        public string PhoneNumber { get; set; }
+
+        /// <summary>
+        /// 备注
+        /// </summary>
+
+        public string? Notes { get; set; }
+
+        /// <summary>
+        /// 创建开始时间
+        /// </summary>
+        public DateTime? CreationTimeStart { get; set; }
+
+        /// <summary>
+        /// 创建结束时间
+        /// </summary>
+        public DateTime? CreationTimeEnd { get; set; }
+
+        /// <summary>
+        /// 排序字段
+        /// </summary>
+        public string? SortField { get; set; } = "creationTime";
+
+        /// <summary>
+        /// 排序方式 // 0 升序 1 降序
+        /// </summary>
+        public int? SortRule { get; set; } = 0;
+    }
+
+    public record SpecialNumberInfoDto
+    {
+        /// <summary>
+        /// 特殊电话ID
+        /// </summary>
+        public string Id { get; set; }
+
+        /// <summary>
+        /// 电话号码
+        /// </summary>
+        public string PhoneNumber { get; set; }
+
+        /// <summary>
+        /// 备注
+        /// </summary>
+        public string? Notes { get; set; }
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        public DateTime? CreationTime { get; set; }
+    }
+}

+ 22 - 0
src/Hotline/Special/SpecialNumber.cs

@@ -0,0 +1,22 @@
+using SqlSugar;
+using System.ComponentModel;
+using XF.Domain.Repository;
+
+namespace Hotline.Special
+{
+    [Description("特殊号码管理")]
+    public class SpecialNumber : CreationEntity
+    {
+        /// <summary>
+        /// 电话号码
+        /// </summary>
+        [SugarColumn(ColumnDescription = "电话号码")]
+        public string PhoneNumber { get; set; }
+
+        /// <summary>
+        /// 备注
+        /// </summary>
+        [SugarColumn(ColumnDescription = "备注")]
+        public string? Notes { get; set; }
+    }
+}