Kaynağa Gözat

自贡需求号码归属地功能

tangjiang 4 gün önce
ebeveyn
işleme
c99a60f471

+ 208 - 0
src/Hotline.Api/Controllers/SystemMobilAreaController.cs

@@ -0,0 +1,208 @@
+using DocumentFormat.OpenXml.Office2010.Excel;
+using Hotline.Application.CallCenter;
+using Hotline.Application.Systems;
+using Hotline.Caching.Interfaces;
+using Hotline.CallCenter.BlackLists;
+using Hotline.CallCenter.Calls;
+using Hotline.CallCenter.Configs;
+using Hotline.CallCenter.Tels;
+using Hotline.Repository.SqlSugar;
+using Hotline.Settings;
+using Hotline.Share.Dtos.ObservationPiece;
+using Hotline.Share.Dtos.Order;
+using Hotline.Share.Dtos;
+using Hotline.Share.Dtos.Settings;
+using Hotline.Tools;
+using MapsterMapper;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.Extensions.Options;
+using SqlSugar;
+using XF.Domain.Authentications;
+using XF.Domain.Exceptions;
+using XF.Domain.Repository;
+using Hotline.Repository.SqlSugar.Extensions;
+
+namespace Hotline.Api.Controllers
+{
+    public class SystemMobilAreaController : BaseController
+    {
+        private readonly IMapper _mapper;
+        private readonly ISessionContext _sessionContext;
+        private readonly IRepository<SystemMobilArea> _systemMobilAreaRepository;
+        private readonly ISystemMobilAreaApplication _systemMobilAreaApplication;
+
+        public SystemMobilAreaController(
+            IMapper mapper,
+            ISessionContext sessionContext,
+            IRepository<SystemMobilArea> systemMobilAreaRepository,
+           ISystemMobilAreaApplication systemMobilAreaApplication)
+        {
+            _mapper = mapper;
+            _sessionContext = sessionContext;
+            _systemMobilAreaRepository = systemMobilAreaRepository;
+            _systemMobilAreaApplication = systemMobilAreaApplication;
+        }
+
+        /// <summary>
+        /// 新增
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("add-system-mobil-area")]
+        public async Task AddSystemMobilArea([FromBody] AddSystemMobilAreaDto dto)
+        {
+            if (!string.IsNullOrEmpty(dto.TelCode))
+                throw UserFriendlyException.SameMessage("座机编号不能为空!");
+            if (!string.IsNullOrEmpty(dto.MobileCode))
+                throw UserFriendlyException.SameMessage("手机编号不能为空!");
+            if (!string.IsNullOrEmpty(dto.MobileAreaName))
+                throw UserFriendlyException.SameMessage("归属地不能为空!");
+            if (!string.IsNullOrEmpty(dto.OFlag))
+                throw UserFriendlyException.SameMessage("运营商不能为空!");
+            if (!string.IsNullOrEmpty(dto.OperatorName))
+                throw UserFriendlyException.SameMessage("卡类型不能为空!");
+
+            var data = await _systemMobilAreaRepository.AnyAsync(p => p.TelCode == dto.TelCode && p.MobileCode == dto.MobileCode && p.OFlag == p.OFlag, HttpContext.RequestAborted);
+            if (data)
+                throw UserFriendlyException.SameMessage("存在相同数据!");
+
+            SystemMobilArea systemMobilArea = new SystemMobilArea
+            {
+                TelCode = dto.TelCode,
+                MobileCode = dto.MobileCode,
+                MobileAreaName = dto.MobileAreaName,
+                OFlag = dto.OFlag,
+                OperatorName = dto.OperatorName,
+                StaId = "0"
+            };
+            await _systemMobilAreaRepository.AddAsync(systemMobilArea, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 查询详情
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet("get-system-mobil-area-detail/{id}")]
+        public async Task<SystemMobilArea> GetSystemMobilAreaDetail(string id)
+        {
+            var data = await _systemMobilAreaRepository.GetAsync(p => p.Id == id, HttpContext.RequestAborted);
+            if (data == null)
+                return new SystemMobilArea();
+            return data;
+        }
+
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("update-system-mobil-area")]
+        public async Task UpdateSystemMobilAreaDetail([FromBody] UpdateSystemMobilAreaDto dto)
+        {
+            if (!string.IsNullOrEmpty(dto.TelCode))
+                throw UserFriendlyException.SameMessage("座机编号不能为空!");
+            if (!string.IsNullOrEmpty(dto.MobileCode))
+                throw UserFriendlyException.SameMessage("手机编号不能为空!");
+            if (!string.IsNullOrEmpty(dto.MobileAreaName))
+                throw UserFriendlyException.SameMessage("归属地不能为空!");
+            if (!string.IsNullOrEmpty(dto.OFlag))
+                throw UserFriendlyException.SameMessage("运营商不能为空!");
+            if (!string.IsNullOrEmpty(dto.OperatorName))
+                throw UserFriendlyException.SameMessage("卡类型不能为空!");
+            var isCheack = await _systemMobilAreaRepository.AnyAsync(p => p.Id != dto.Id && p.TelCode == dto.TelCode
+            && p.MobileCode == dto.MobileCode && p.OFlag == p.OFlag, HttpContext.RequestAborted);
+            if (isCheack)
+                throw UserFriendlyException.SameMessage("存在相同数据!");
+
+            var data = await _systemMobilAreaRepository.GetAsync(p => p.Id == dto.Id, HttpContext.RequestAborted);
+            if (data == null)
+                throw UserFriendlyException.SameMessage("修改失败!");
+
+            data.TelCode = dto.TelCode;
+            data.MobileCode = dto.MobileCode;
+            data.OFlag = dto.OFlag;
+            data.OperatorName = dto.OperatorName;
+            data.MobileAreaName = dto.MobileAreaName;
+            await _systemMobilAreaRepository.UpdateAsync(data, HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpDelete("delete-system-mobil-area-detail/{id}")]
+        public async Task DeleteSystemMobilAreaDetail(string id)
+        {
+            await _systemMobilAreaRepository.RemoveAsync(id, cancellationToken: HttpContext.RequestAborted);
+        }
+
+        /// <summary>
+        /// 根据号码查询归属地等信息
+        /// </summary>
+        /// <param name="phonenum"></param>
+        /// <returns></returns>
+        [HttpGet("get-phone-card-area/{phonenum}")]
+        public async Task<SystemMobilAreaDto> GetPhoneCardArea(string phonenum)
+        {
+            var data = await _systemMobilAreaApplication.GetPhoneCardArea(phonenum, cancellationToken: HttpContext.RequestAborted);
+            if (data != null)
+            {
+                if (data.OFlag == "1")
+                    data.OFlag = "中国电信";
+                else if (data.OFlag == "2")
+                    data.OFlag = "中国移动";
+                else if (data.OFlag == "3")
+                    data.OFlag = "中国联通";
+            }
+            return data;
+        }
+
+        /// <summary>
+        /// 号码归属地列表
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpGet("get-system-mobil-area-list")]
+        public async Task<PagedDto<SystemMobilAreaListDto>> GetSystemMobilAreaList([FromQuery] SystemMobilAreaRequestDto dto)
+        {
+            var (total, items) = await _systemMobilAreaApplication.GetList(dto)
+                .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+            return new PagedDto<SystemMobilAreaListDto>(total, _mapper.Map<IReadOnlyList<SystemMobilAreaListDto>>(items));
+        }
+
+        /// <summary>
+        /// 号码归属地列表导出
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("get-system-mobil-area-list-export")]
+        public async Task<FileStreamResult> GetSystemMobilAreaListExport([FromBody] ExportExcelDto<SystemMobilAreaRequestDto> dto)
+        {
+            var query = _systemMobilAreaApplication.GetList(dto.QueryDto);
+            List<SystemMobilArea> data;
+            if (dto.IsExportAll)
+            {
+                data = await query.ToListAsync(HttpContext.RequestAborted);
+            }
+            else
+            {
+                var (_, items) = await query.ToPagedListAsync(dto.QueryDto, HttpContext.RequestAborted);
+                data = items;
+            }
+            var dataDtos = _mapper.Map<ICollection<SystemMobilAreaListDto>>(data);
+            dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass<SystemMobilAreaListDto>(dto.ColumnInfos);
+
+            var dtos = dataDtos
+                .Select(stu => _mapper.Map(stu, typeof(SystemMobilAreaListDto), dynamicClass))
+                .Cast<object>()
+                .ToList();
+
+            var stream = ExcelHelper.CreateStream(dtos);
+
+            return ExcelStreamResult(stream, "号码归属地列表");
+        }
+    }
+}

+ 10 - 1
src/Hotline.Application/Systems/ISystemMobilAreaApplication.cs

@@ -1,9 +1,18 @@
-using Hotline.Share.Dtos.Settings;
+using Hotline.Settings;
+using Hotline.Share.Dtos.Settings;
+using SqlSugar;
 
 namespace Hotline.Application.Systems
 {
     public interface ISystemMobilAreaApplication
     {
+        /// <summary>
+        /// 查询列表
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        ISugarQueryable<SystemMobilArea> GetList(SystemMobilAreaRequestDto dto);
+
         /// <summary>
         /// 
         /// </summary>

+ 19 - 0
src/Hotline.Application/Systems/SystemMobilAreaApplication.cs

@@ -2,6 +2,7 @@
 using Hotline.Settings;
 using Hotline.Share.Dtos.Settings;
 using Microsoft.Extensions.Options;
+using SqlSugar;
 using System.Text.RegularExpressions;
 using XF.Domain.Dependency;
 using XF.Domain.Repository;
@@ -25,6 +26,24 @@ namespace Hotline.Application.Systems
             _appOptions = appOptions;
         }
 
+        /// <summary>
+        /// 查询列表
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public ISugarQueryable<SystemMobilArea> GetList(SystemMobilAreaRequestDto dto)
+        {
+            return _systemMobilAreaRepository.Queryable()
+                   .WhereIF(!string.IsNullOrEmpty(dto.TelCode), p => p.TelCode == dto.TelCode)
+                   .WhereIF(!string.IsNullOrEmpty(dto.MobileCode), p => p.MobileCode.Contains(dto.MobileCode))
+                   .WhereIF(!string.IsNullOrEmpty(dto.MobileAreaName), p => p.MobileAreaName.Contains(dto.MobileAreaName))
+                   .WhereIF(!string.IsNullOrEmpty(dto.OFlag), p => p.OFlag == dto.OFlag)
+                   .WhereIF(!string.IsNullOrEmpty(dto.OperatorName), p => p.OperatorName.Contains(dto.OperatorName))
+                   .WhereIF(dto.StartTime.HasValue, p => p.CreationTime >= dto.StartTime)
+                    .WhereIF(dto.EndTime.HasValue, p => p.CreationTime <= dto.EndTime)
+                    .OrderByDescending(p => p.CreationTime);
+        }
+
         /// <summary>
         /// 
         /// </summary>

+ 98 - 1
src/Hotline.Share/Dtos/Settings/SystemMobilAreaDto.cs

@@ -1,4 +1,6 @@
-namespace Hotline.Share.Dtos.Settings
+using Hotline.Share.Requests;
+
+namespace Hotline.Share.Dtos.Settings
 {
     public class SystemMobilAreaDto
     {
@@ -17,4 +19,99 @@
         /// </summary>
         public string? OperatorName { get; set; }
     }
+
+    public class AddSystemMobilAreaDto
+    {
+        /// <summary>
+        /// 座机编号
+        /// </summary>
+        public string TelCode { get; set; }
+
+        /// <summary>
+        /// 手机编号
+        /// </summary>
+        public string MobileCode { get; set; }
+
+        /// <summary>
+        /// 归属地
+        /// </summary>
+        public string MobileAreaName { get; set; }
+
+        /// <summary>
+        /// 运营商
+        /// </summary>
+        public string OFlag { get; set; }
+
+        /// <summary>
+        /// 卡类型
+        /// </summary>
+        public string OperatorName { get; set; }
+    }
+
+    public class UpdateSystemMobilAreaDto : AddSystemMobilAreaDto
+    {
+        public string Id { get; set; }
+    }
+
+    public record SystemMobilAreaRequestDto : PagedKeywordRequest
+    {
+        /// <summary>
+        /// 座机编号
+        /// </summary>
+        public string TelCode { get; set; }
+
+        /// <summary>
+        /// 手机编号
+        /// </summary>
+        public string MobileCode { get; set; }
+
+        /// <summary>
+        /// 归属地
+        /// </summary>
+        public string MobileAreaName { get; set; }
+
+        /// <summary>
+        /// 运营商
+        /// </summary>
+        public string OFlag { get; set; }
+
+        /// <summary>
+        /// 卡类型
+        /// </summary>
+        public string OperatorName { get; set; }
+    }
+
+    public class SystemMobilAreaListDto
+    {
+        public string? Id { get; set; }
+
+        /// <summary>
+        /// 座机编号
+        /// </summary>
+        public string TelCode { get; set; }
+
+        /// <summary>
+        /// 手机编号
+        /// </summary>
+        public string MobileCode { get; set; }
+
+        /// <summary>
+        /// 归属地
+        /// </summary>
+        public string MobileAreaName { get; set; }
+
+        /// <summary>
+        /// 运营商
+        /// </summary>
+        public string OFlag { get; set; }
+
+        /// <summary>
+        /// 卡类型
+        /// </summary>
+        public string OperatorName { get; set; }
+
+        public DateTime? CreationTime { get; set; }
+
+        public string? CreatorName { get; set; }
+    }
 }