|
@@ -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
|
|
|
+ }
|
|
|
+}
|