From a48ae2e79a43e3eac3b33af623694e9a63643e62 Mon Sep 17 00:00:00 2001 From: zhaozhenjing Date: Mon, 3 Nov 2025 16:41:20 +0800 Subject: [PATCH] =?UTF-8?q?[MODIFY]=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/Admins/SMSService.cs | 47 ++++++++++- .../Impl/Admins/UserService.cs | 82 +++++++++++++++++-- .../Interfaces/Admins/SMS/ISMSService.cs | 9 +- .../Admins/User/Input/UserAddInput.cs | 5 +- .../Admins/User/Input/UserUpdateInput.cs | 5 ++ 5 files changed, 136 insertions(+), 12 deletions(-) diff --git a/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs b/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs index 5a6f920..cd373d8 100644 --- a/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs +++ b/src/2.services/ATS.NonCustodial.Application/Impl/Admins/SMSService.cs @@ -130,9 +130,8 @@ namespace ATS.NonCustodial.Application.Impl.Admins .WhereIf(pageInput.SendTimeTo.HasValue, w => w.sendTime <= pageInput.SendTimeTo); return query; } - /// - /// 发送验证码 + /// 被监管人登录发送验证码 /// /// /// @@ -160,16 +159,56 @@ namespace ATS.NonCustodial.Application.Impl.Admins select new { b.SupervisedPersonId }).ToListAsync(); if (datalist.Count == 0) return ResultOutput.NotOk("该手机号不存在运行中的案件"); + // 生成随机验证码(6位数字) + var random = new Random(); + var code = random.Next(100000, 999999).ToString(); + var name = personList.Where(w => datalist.Select(s => s.SupervisedPersonId).Contains(w.Id))?.FirstOrDefault().UserName ?? ""; + var sendMessage = $"您的验证码为:{code},请于五分钟内填写,若非本人操作,请勿泄露。"; + + // 创建验证码记录 + var addSMS = new AppSMS + { + phone = phone, + code = code, + sendTime = DateTime.Now, + expiresTime = DateTime.Now.AddMinutes(5), // 5分钟有效期 + ipAddress = ipAddress, + type = type, + receiver = name, + content = sendMessage + }; + + var sendResult = SendSmsAsync(sendMessage, phone); + // 发送短信 + // var sendResult = SendSMS(phone, new string[] { code, "5" }, "2524683"); + addSMS.result = sendResult.Result; + var sms = await _appSMSRepository.InsertAsync(addSMS); + + return ResultOutput.Ok(true); + } + + /// + /// 监管人创建新用户或更改手机号发送验证码 + /// + /// + /// + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task SendCheckCode(string phone, string ipAddress = "", string type = "CheckCode") + { // 检查是否可以发送(一分钟内只能发送一次) if (!await CanSendCodeAsync(phone)) { return ResultOutput.NotOk("请求过于频繁,请稍后再试"); } + // 生成随机验证码(6位数字) var random = new Random(); var code = random.Next(100000, 999999).ToString(); - var name = personList.Where(w => datalist.Select(s => s.SupervisedPersonId).Contains(w.Id))?.FirstOrDefault().UserName ?? ""; + var name = "新用户注册"; var sendMessage = $"您的验证码为:{code},请于五分钟内填写,若非本人操作,请勿泄露。"; // 创建验证码记录 @@ -225,7 +264,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins if (alert == MessageAlertTypeEnum.Alert) { //[预警处理提醒] {1}您好,您于{2}年{3}月{4}日触发的{5}预警需及时处理,请尽快核查并修正相关事项。 - sendMessage = $"[预警处理提醒] {supervisedPerson}您好,您于{date}触发的{msg}预警需及时处理,请尽快核查并修正相关事项。"; + sendMessage = $"[预警处理提醒] {supervisedPerson}您好,您于{date}触发的{msg}预警需及时处理,请尽快核查并遵守规定。"; addSMS.type = "Alert"; addSMS.receiver = supervisedPerson; } diff --git a/src/2.services/ATS.NonCustodial.Application/Impl/Admins/UserService.cs b/src/2.services/ATS.NonCustodial.Application/Impl/Admins/UserService.cs index 55301a4..84b5ac3 100644 --- a/src/2.services/ATS.NonCustodial.Application/Impl/Admins/UserService.cs +++ b/src/2.services/ATS.NonCustodial.Application/Impl/Admins/UserService.cs @@ -4,11 +4,17 @@ using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.AppDictionaries.O using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Auth.Output; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Menu.Output; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Role.Output; +using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User.Input; using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User.Output; +using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement; +using ATS.NonCustodial.Application.Contracts.Interfaces.Business.PunchRecordServices.Output; +using ATS.NonCustodial.Application.Impl.Business.CaseManagements; using ATS.NonCustodial.Domain.Entities.Admins; +using ATS.NonCustodial.Domain.Entities.Business.CaseManagements; using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos; +using ATS.NonCustodial.Domain.Shared.Enums; using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore; using ATS.NonCustodial.DynamicApi; using ATS.NonCustodial.DynamicApi.Attributes; @@ -28,6 +34,7 @@ using Castle.Components.DictionaryAdapter; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using StackExchange.Profiling.Internal; using Yitter.IdGenerator; namespace ATS.NonCustodial.Application.Impl.Admins @@ -50,16 +57,21 @@ namespace ATS.NonCustodial.Application.Impl.Admins private readonly IEfRepository _rolePermissionRepository; private readonly IEfRepository _MenuRepository; private readonly IAppDictionaryService _appDictionaryService; + private readonly ISMSService _smsService; + private readonly IEfRepository _appCaseManagementRepository; + private readonly IEfRepository _appSupervisedPersonRepository; public UserService( - IEfRepository userRepository, + IEfRepository userRepository, IEfRepository appCaseManagementRepository, + IEfRepository appSupervisedPersonRepository, IEfRepository userRoleRepository, IEfRepository apiRepository, IEfRepository roleRepository, IEfRepository permissionApiRepository, IEfRepository rolePermissionRepository, IEfRepository MenuRepository, - IAppDictionaryService appDictionaryService + IAppDictionaryService appDictionaryService, + ISMSService smsService ) { _userRepository = userRepository; @@ -70,6 +82,10 @@ namespace ATS.NonCustodial.Application.Impl.Admins _rolePermissionRepository = rolePermissionRepository; _appDictionaryService = appDictionaryService; _MenuRepository = MenuRepository; + _smsService = smsService; + _appCaseManagementRepository = appCaseManagementRepository; + _appSupervisedPersonRepository = appSupervisedPersonRepository; + } #endregion Identity @@ -381,7 +397,14 @@ namespace ATS.NonCustodial.Application.Impl.Admins { //if (await _userRepository.AnyAsync(x => x.ReceiveName == input.ReceiveName)) return ResultOutput.NotOk("账号已经存在"); if (await _userRepository.AnyAsync(w => w.UserName == input.UserName)) return ResultOutput.NotOk("姓名已经存在"); + if (!input.Phone.HasValue()) return ResultOutput.NotOk("请输入手机号"); + + var result = await CheckPhone(input.Phone); + if (!result) { return ResultOutput.NotOk("手机号已在系统中已存在"); } + if (!input.Code.HasValue()) return ResultOutput.NotOk("请输入验证码"); + result = await _smsService.CheckCodeAsync(input.Phone, input.Code, "CheckCode"); + if (!result) { return ResultOutput.NotOk("验证码错误"); } var entity = Mapper.Map(input); entity.Id = YitIdHelper.NextId(); entity.PasswordSalt = InfraHelper.Security.GenerateRandomCode(5); @@ -524,7 +547,16 @@ namespace ATS.NonCustodial.Application.Impl.Admins if (!(user?.Id > 0)) return ResultOutput.NotOk("用户不存在!"); //监管人和管理员手机号不能重复 if (await _userRepository.AnyAsync(w => w.Id != input.Id && w.UserName == input.UserName && w.ChatPersonType != ChatPersonTypeEnum.SupervisedPerson)) return ResultOutput.NotOk("姓名不能重复"); + if (!input.Phone.HasValue()) return ResultOutput.NotOk("请输入手机号"); + if (user.Phone != input.Phone) + { + var result = await CheckPhone(input.Phone); + if (!result) { return ResultOutput.NotOk("手机号已在系统中已存在"); } + if (!input.Code.HasValue()) return ResultOutput.NotOk("请输入验证码"); + result = await _smsService.CheckCodeAsync(input.Phone, input.Code, "CheckCode"); + if (!result) { return ResultOutput.NotOk("验证码错误"); } + } Mapper.Map(input, user); await _userRepository.UpdateAsync(user, UpdatingProps( @@ -538,9 +570,9 @@ namespace ATS.NonCustodial.Application.Impl.Admins w => w.DataStatus)!); if (input.RoleIds != null && input.RoleIds.Count() > 0) { - var roleList = await _roleRepository.AsQueryable(false, true) - .Where(w=> w.Code == "admin" || w.Code == "supervisor") - .Select(s=>s.Id).ToListAsync(); + var roleList = await _roleRepository.AsQueryable(false, true) + .Where(w => w.Code == "admin" || w.Code == "supervisor") + .Select(s => s.Id).ToListAsync(); await _userRoleRepository.DeleteAsync(a => a.UserId == user.Id && roleList.Contains(a.RoleId)); @@ -558,6 +590,44 @@ namespace ATS.NonCustodial.Application.Impl.Admins return ResultOutput.Ok(); } + /// + /// 校验手机号是否有运行中的按键 + /// + /// + /// + private async Task CheckPhone(string phone) + { + + var allUsers = await _userRepository.Where(w => w.Phone == phone && !string.IsNullOrEmpty(w.RoleName)).ToListAsync(); + if (allUsers.Any()) + { + foreach (var item in allUsers) + { + var caseList = await (from c in _appCaseManagementRepository.AsQueryable(false, true) + join cspr in _appSupervisedPersonRepository.AsQueryable(false, true) on c.Id equals cspr.CaseId + where c.CaseProgress != CaseProgressEnum.Closed + && item.Id == cspr.SupervisedPersonId + select new CheckPunchRecordForJobOutput() + { + CaseId = c.Id, + CaseName = c.Name, + CaseBeginTime = c.CaseBeginTime, + CheckInFrequency = c.CheckInFrequency, + RestBeginTime = c.RestBeginTime, + RestEndTime = c.RestEndTime, + SupervisedPersonId = cspr.SupervisedPersonId, + SupervisedPersonName = cspr.SupervisedPersonName, + TimedClock = c.TimedClock + }).ToListAsync(); + if(caseList.Any()) + { + return false; + } + + } + } + return true; + } /// /// 更新用户基本信息 /// @@ -863,7 +933,7 @@ namespace ATS.NonCustodial.Application.Impl.Admins var rtn = await _userRepository.AsQueryable(false, true) .Where(w => w.ChatPersonType != ChatPersonTypeEnum.SupervisedPerson && w.DataStatus != DataStatusEnum.Disable && !w.UserName.Contains("_aks")) - .WhereIf(codeList.Count>0,w=> w.PositionId == codeList.FirstOrDefault().Id) + .WhereIf(codeList.Count > 0, w => w.PositionId == codeList.FirstOrDefault().Id) // .WhereIf(!userRoles.IsAdmin, w => w.Id == User.Id) 2025 -10-20 段肖确认修改 .Select(w => new KeyValueDto() { diff --git a/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/SMS/ISMSService.cs b/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/SMS/ISMSService.cs index b49f00c..8df6b40 100644 --- a/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/SMS/ISMSService.cs +++ b/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/SMS/ISMSService.cs @@ -14,7 +14,14 @@ namespace ATS.NonCustodial.Application.Contracts.Interfaces.Admins.SMS /// /// Task SendCheckCodeSMS(string phone, string ipAddress = "", string type = "CheckCode"); - + /// + /// 监管人创建新用户或更改手机号发送验证码 + /// + /// + /// + /// + /// + Task SendCheckCode(string phone, string ipAddress = "", string type = "CheckCode"); /// /// 校验验证码 /// diff --git a/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserAddInput.cs b/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserAddInput.cs index 4a4437d..cc3665f 100644 --- a/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserAddInput.cs +++ b/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserAddInput.cs @@ -49,7 +49,10 @@ namespace ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User.Input /// 部门名称 /// public string? Deptcodename { get; set; } - + /// + /// 验证码 + /// + public string? Code { get; set; } /// /// 角色 /// diff --git a/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserUpdateInput.cs b/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserUpdateInput.cs index 7e11bcd..1e1452b 100644 --- a/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserUpdateInput.cs +++ b/src/3.contracts/ATS.NonCustodial.Application.Contracts/Interfaces/Admins/User/Input/UserUpdateInput.cs @@ -34,6 +34,11 @@ namespace ATS.NonCustodial.Application.Contracts.Interfaces.Admins.User.Input /// public string? Unitname { get; set; } + /// + /// 验证码 + /// + public string? Code { get; set; } + /// /// 部门id ///