From ade2bdf18184f88a2143c14cd48edfdd82c6de34 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 18 Aug 2025 15:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=BF=90=E7=BB=B4=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Management/DTO/UserModel.cs | 12 +++ .../Service/Management/UserService.cs | 15 ++- .../Service/Management/_MapConfig.cs | 5 +- .../TrialSiteUser/DTO/UserTrialViewModel.cs | 87 +++++++++++++++ .../Interface/ITrialMaintenanceService.cs | 4 +- .../TrialSiteUser/TrialMaintenanceService.cs | 102 +++++++++++++----- .../Service/TrialSiteUser/TrialService.cs | 12 ++- .../Service/TrialSiteUser/_MapConfig2.cs | 3 +- .../Management/HospitalGroup.cs | 8 +- 9 files changed, 212 insertions(+), 36 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index eb1bfa916..ac4dab451 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -242,6 +242,8 @@ namespace IRaCIS.Application.Contracts public List UserRoleList { get; set; } + public List HospitalGroupIdList { get; set; } + public string BaseUrl { get; set; } = string.Empty; public string RouteUrl { get; set; } = string.Empty; @@ -321,6 +323,8 @@ namespace IRaCIS.Application.Contracts public List UserRoleList { get; set; } + public List HospitalGroupList { get; set; } + #region 用户来源 @@ -334,6 +338,14 @@ namespace IRaCIS.Application.Contracts public int JoinedTrialCount { get; set; } } + + public class HospitalGroupInfo + { + public Guid Id { get; set; } + public string Name { get; set; } + + public string Code { get; set; } + } public class IdentityUserTypeDTO : UserAddUserType { public Guid Id { get; set; } diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 36d6f5184..bb7ca5979 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -558,6 +558,8 @@ namespace IRaCIS.Core.Application.Service saveItem.UserRoleList = addRoleList; + saveItem.IdentityUserHospitalGroupList = userAddModel.HospitalGroupIdList.Select(t => new HospitalGroupIdentityUser() { HospitalGroupId = t, IsManager = false }).ToList(); + await _identityUserRepository.AddAsync(saveItem); var success = await _identityUserRepository.SaveChangesAsync(); @@ -591,7 +593,7 @@ namespace IRaCIS.Core.Application.Service //await VerifyUserPhoneAsync(model.Id, model.UserTypeId, model.Phone); - var user = await _identityUserRepository.Where(t => t.Id == model.Id, true).Include(t => t.UserRoleList).FirstOrDefaultAsync(); + var user = await _identityUserRepository.Where(t => t.Id == model.Id, true).Include(t => t.UserRoleList).Include(t=>t.IdentityUserHospitalGroupList).FirstOrDefaultAsync(); if (user == null) return Null404NotFound(user); @@ -641,6 +643,17 @@ namespace IRaCIS.Core.Application.Service } + var existHospitalGroupIdList = user.IdentityUserHospitalGroupList.Select(t => t.HospitalGroupId).ToList(); + + var removeIdList= existHospitalGroupIdList.Except(model.HospitalGroupIdList).ToList(); + + user.IdentityUserHospitalGroupList = user.IdentityUserHospitalGroupList.Where(t => !removeIdList.Contains(t.HospitalGroupId)).ToList(); + + var addIdList = model.HospitalGroupIdList.Except(existHospitalGroupIdList).ToList(); + + user.IdentityUserHospitalGroupList.AddRange(addIdList.Select(t => new HospitalGroupIdentityUser() { HospitalGroupId = t, IsManager = false, IdentityUserId = user.Id })); + + var success = await _userRoleRepository.SaveChangesAsync(); await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = model.Id, OptType = UserOptType.UpdateUser }, true); diff --git a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs index 52e2c578d..18f762994 100644 --- a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs @@ -79,7 +79,10 @@ namespace IRaCIS.Core.Application.Service CreateMap() .ForMember(d => d.TrialCode, u => u.MapFrom(s => s.Trial.TrialCode)) .ForMember(d => d.JoinedTrialCount, u => u.MapFrom(s => s.UserTrialList.Count())) - .ForMember(d => d.ResearchProgramNo, u => u.MapFrom(s => s.Trial.ResearchProgramNo)); + .ForMember(d => d.ResearchProgramNo, u => u.MapFrom(s => s.Trial.ResearchProgramNo)) + .ForMember(d => d.HospitalGroupList, u => u.MapFrom(s => s.IdentityUserHospitalGroupList.Select(t=>t.HospitalGroup))); + + CreateMap(); var token = string.Empty; var userId = Guid.Empty; diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs index 3270d3e00..047dcd290 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs @@ -333,6 +333,67 @@ namespace IRaCIS.Application.Contracts } + public class UpdateTrialUserRoleCommand + { + public List IdList { get; set; } + + public bool IsDeleted { get; set; } + } + public class TrialIdentityUserDto + { + public Guid Id { get; set; } + + public Guid TrialId { get; set; } + + public Guid IdentityUserId { get; set; } + + public string Phone { get; set; } = String.Empty; + + public string EMail { get; set; } = string.Empty; + + public string OrganizationName { get; set; } = String.Empty; + + public string UserName { get; set; } = String.Empty; + + public string FullName { get; set; } = String.Empty; + + public bool IsDeleted { get; set; } + + public UserStateEnum Status { get; set; } + + public DateTime CreateTime { get; set; } + public DateTime UpdateTime { get; set; } + + [ExcelFormat("yyyy-MM-dd")] + public DateTime? RemoveTime { get; set; } + + [ExcelFormat("yyyy-MM-dd")] + public DateTime? JoinTime { get; set; } + + //public string JoinTimeStr => JoinTime?.ToString("yyyy-MM-dd") ?? string.Empty; + //public string RemoveTimeStr => RemoveTime?.ToString("yyyy-MM-dd") ?? string.Empty; + + + public List TrialUserRoleList { get; set; } + + } + + public class TrialIdentityUserRoleDto + { + public Guid Id { get; set; } + + public string UserTypeShortName { get; set; } + + public UserTypeEnum UserTypeEnum { get; set; } + + public bool IsUserRoleDisabled { get; set; } + + public bool IsDeleted { get; set; } + + public DateTime CreateTime { get; set; } + public DateTime UpdateTime { get; set; } + } + public class SiteCRCQuery : TrialMaintenanceQuery { [NotDefault] @@ -352,6 +413,8 @@ namespace IRaCIS.Application.Contracts public UserTypeEnum? UserTypeEnum { get; set; } + public bool? IsUserRoleDisabled { get; set; } + public string? EMail { get; set; } } @@ -382,6 +445,30 @@ namespace IRaCIS.Application.Contracts } + public class TrialUserRoleScreeningDto + { + public Guid TrialId { get; set; } + + public Guid UserId => Id; + public Guid Id { get; set; } + + public Guid IdentityUserId { get; set; } + + public string Phone { get; set; } = String.Empty; + + public string EMail { get; set; } = string.Empty; + + public string OrganizationName { get; set; } = String.Empty; + + public string UserName { get; set; } = String.Empty; + + public string FullName { get; set; } = String.Empty; + + public string UserTypeShortName { get; set; } + + public bool IsSelect { get; set; } + } + public class TrialUserAddCommand { diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/Interface/ITrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/Interface/ITrialMaintenanceService.cs index 99668f051..2a58fc54e 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/Interface/ITrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/Interface/ITrialMaintenanceService.cs @@ -7,8 +7,8 @@ namespace IRaCIS.Application.Interfaces { Task AddTrialUsers(TrialUserAddCommand[] userTrialCommands); Task DeleteMaintenanceUser(Guid id, bool isDelete); - Task> GetMaintenanceUserList(TrialMaintenanceQuery param); + Task> GetMaintenanceUserList(TrialMaintenanceQuery inQuery); Task> GetSiteCRCScreeningList(SiteCRCQuery param); - Task> GetTrialUserScreeningList(TrialUserQuery trialUserQuery); + Task> GetTrialUserScreeningList(TrialUserQuery trialUserQuery); } } \ No newline at end of file diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index a72fee833..255a7c9ef 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Core.Application.Service { [ApiExplorerSettings(GroupName = "Trial")] - public class TrialMaintenanceService(IRepository _trialUseRoleRepository, + public class TrialMaintenanceService(IRepository _trialUseRoleRepository, IRepository _trialIdentityUserRepository, IRepository _userRoleRepository, IRepository _trialSiteUserRepository, IRepository _subjectVisitRepository, @@ -29,25 +29,57 @@ namespace IRaCIS.Core.Application.Service /// /// [HttpPost] - public async Task> GetMaintenanceUserList(TrialMaintenanceQuery inQuery) + public async Task> GetMaintenanceUserList(TrialMaintenanceQuery inQuery) { + var query = _trialIdentityUserRepository.Where(t => t.TrialId == inQuery.TrialId).IgnoreQueryFilters() + .WhereIf(inQuery.UserTypeId != null, t => t.TrialUserRoleList.Any(t => t.UserRole.UserTypeId == inQuery.UserTypeId)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserName), t => t.IdentityUser.UserName.Contains(inQuery.UserName)) - var query = _trialUseRoleRepository.Where(t => t.TrialId == inQuery.TrialId).IgnoreQueryFilters() - - .WhereIf(inQuery.UserTypeId != null, t => t.UserRole.UserTypeId == inQuery.UserTypeId) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserName), t => t.UserRole.UserName.Contains(inQuery.UserName)) - - .WhereIf(inQuery.IsDeleted != null, t => t.IsDeleted == inQuery.IsDeleted) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.OrganizationName), t => t.UserRole.OrganizationName.Contains(inQuery.OrganizationName)) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserRealName), t => (t.UserRole.FullName).Contains(inQuery.UserRealName)) - .ProjectTo(_mapper.ConfigurationProvider); - - return await query.ToPagedListAsync(inQuery, nameof(TrialMaintenanceDTO.UpdateTime)); + .WhereIf(inQuery.IsDeleted != null, t => t.IsDeleted == inQuery.IsDeleted) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.OrganizationName), t => t.IdentityUser.OrganizationName.Contains(inQuery.OrganizationName)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserRealName), t => (t.IdentityUser.FullName).Contains(inQuery.UserRealName)) + .Select(t => new TrialIdentityUserDto() + { + Id = t.Id, + TrialId = t.TrialId, + IsDeleted = t.IsDeleted, + CreateTime = t.CreateTime, + EMail = t.IdentityUser.EMail, + FullName = t.IdentityUser.FullName, + IdentityUserId = t.IdentityUserId, + JoinTime = t.JoinTime, + OrganizationName = t.IdentityUser.OrganizationName, + Phone = t.IdentityUser.Phone, + UpdateTime = t.UpdateTime, + UserName = t.IdentityUser.UserName, + RemoveTime = t.RemoveTime, + Status = t.IdentityUser.Status, + TrialUserRoleList = t.TrialUserRoleList.Select(ur => new TrialIdentityUserRoleDto() + { + Id = ur.Id, + UserTypeShortName = ur.UserRole.UserTypeRole.UserTypeShortName, + IsUserRoleDisabled = ur.UserRole.IsUserRoleDisabled, + IsDeleted = ur.IsDeleted, + CreateTime = ur.CreateTime, + UserTypeEnum = ur.UserRole.UserTypeEnum, + UpdateTime = ur.UpdateTime + }).ToList() + }); + return await query.ToPagedListAsync(inQuery, nameof(TrialIdentityUserDto.UpdateTime)); } + [HttpPut] + public async Task UpdateTrialUserRole(UpdateTrialUserRoleCommand updateCommand) + { + DateTime? deleteTime = updateCommand.IsDeleted ? DateTime.Now : null; + + await _trialUseRoleRepository.UpdatePartialFromQueryAsync(t => updateCommand.IdList.Contains(t.Id), u => new TrialUserRole() { IsDeleted = updateCommand.IsDeleted, DeletedTime = deleteTime }, true, true); + + return ResponseOutput.Ok(); + } /// Setting页面 为 site 勾选CRC用户列表 @@ -70,7 +102,7 @@ namespace IRaCIS.Core.Application.Service /// Setting页面 项目参与人员勾选列表 [HttpPost] - public async Task> GetTrialUserScreeningList(TrialUserQuery inQuery) + public async Task> GetTrialUserScreeningList(TrialUserQuery inQuery) { var trialType = _trialRepository.Where(t => t.Id == inQuery.TrialId).Select(t => t.TrialType).FirstOrDefault(); @@ -94,14 +126,27 @@ namespace IRaCIS.Core.Application.Service //.Where(t => userTypeEnums.Contains(t.UserTypeEnum)) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserRealName), t => (t.FullName).Contains(inQuery.UserRealName)) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserName), t => t.UserName.Contains(inQuery.UserName)) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.OrganizationName), t => t.OrganizationName.Contains(inQuery.OrganizationName)) - .WhereIf(!string.IsNullOrWhiteSpace(inQuery.EMail), t => t.EMail.Contains(inQuery.EMail)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserRealName), t => (t.IdentityUser.FullName).Contains(inQuery.UserRealName)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserName), t => t.IdentityUser.UserName.Contains(inQuery.UserName)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.OrganizationName), t => t.IdentityUser.OrganizationName.Contains(inQuery.OrganizationName)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.EMail), t => t.IdentityUser.EMail.Contains(inQuery.EMail)) .WhereIf(inQuery.UserTypeEnum != null, t => t.UserTypeEnum == inQuery.UserTypeEnum) + .WhereIf(inQuery.IsUserRoleDisabled != null, t => t.IsUserRoleDisabled == inQuery.IsUserRoleDisabled) //.WhereIf(_userInfo.IsAdmin, t => t.UserTypeRole.Type == UserTypeGroup.TrialUser) //.WhereIf(!_userInfo.IsAdmin, t => t.UserTypeRole.Type == UserTypeGroup.TrialUser || t.UserTypeEnum != UserTypeEnum.ProjectManager) - .ProjectTo(_mapper.ConfigurationProvider, new { trialId = inQuery.TrialId }); + .Select(t => new TrialUserRoleScreeningDto() + { + Id = t.Id, + TrialId = inQuery.TrialId, + IdentityUserId = t.IdentityUserId, + EMail = t.IdentityUser.EMail, + FullName = t.IdentityUser.FullName, + OrganizationName = t.IdentityUser.OrganizationName, + Phone = t.IdentityUser.Phone, + UserName = t.IdentityUser.UserName, + UserTypeShortName = t.UserTypeRole.UserTypeShortName, + IsSelect = t.UserRoleTrials.Any(t => t.TrialId == inQuery.TrialId), + }); return await query.ToPagedListAsync(inQuery); @@ -142,22 +187,25 @@ namespace IRaCIS.Core.Application.Service [HttpPut] public async Task UpdateTrialUser(UpdateTrialUserCommand updateTrialUserCommand) { - var trialUser = await _trialUseRoleRepository.Where(t => t.Id == updateTrialUserCommand.Id, true, true).FirstOrDefaultAsync(); + var trialUser = await _trialIdentityUserRepository.Where(t => t.Id == updateTrialUserCommand.Id, true, true).FirstOrDefaultAsync(); if (trialUser == null) return Null404NotFound(trialUser); if (updateTrialUserCommand.IsDeleted) { - if (await _trialSiteUserRepository.AnyAsync(t => t.UserId == trialUser.UserId && t.TrialId == trialUser.TrialId)) - { - // ----人员已加入现场维护 - return ResponseOutput.NotOk(_localizer["TrialMaint_PersonnelJoined"]); - } + //可以直接退出,不管中心下的CRC CRA 状态 + //if (await _trialSiteUserRoleRepository.AnyAsync(t => t.UserRole.IdentityUserId == trialUser.IdentityUserId && t.TrialId == trialUser.TrialId)) + //{ + // // ----人员已加入现场维护 + // return ResponseOutput.NotOk(_localizer["TrialMaint_PersonnelJoined"]); + //} - if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IQC) + var findQC = await _trialUseRoleRepository.FirstOrDefaultAsync(t => t.UserRole.IdentityUserId == trialUser.IdentityUserId && t.UserRole.UserTypeEnum == UserTypeEnum.IQC); + + if (findQC != null) { - await _subjectVisitRepository.BatchUpdateNoTrackingAsync(t => t.CurrentActionUserId == trialUser.UserId && t.TrialId == trialUser.TrialId && t.IsTake, u => new SubjectVisit() { CurrentActionUserId = null, CurrentActionUserExpireTime = null, IsTake = false }); + await _subjectVisitRepository.BatchUpdateNoTrackingAsync(t => t.CurrentActionUserId == findQC.Id && t.TrialId == trialUser.TrialId && t.IsTake, u => new SubjectVisit() { CurrentActionUserId = null, CurrentActionUserExpireTime = null, IsTake = false }); } } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs index 90342d6a7..e2f032e06 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialService.cs @@ -16,7 +16,7 @@ namespace IRaCIS.Core.Application.Service [ApiExplorerSettings(GroupName = "Trial")] public class TrialService(IRepository _trialRepository, - IRepository _trialUserRepository, + IRepository _trialIdentityUserRepository, IRepository _croRepository, IRepository _enrollDetailRepository, IRepository _dictionaryRepository, @@ -208,7 +208,15 @@ namespace IRaCIS.Core.Application.Service //如果是PM, 则需要将该人员添加到 运维人员表 //添加运维人员PM - await _trialUserRepository.AddAsync(new TrialUserRole() { TrialId = trial.Id, UserId = _userInfo.UserRoleId, JoinTime = DateTime.Now }); + await _trialIdentityUserRepository.AddAsync(new TrialIdentityUser() + { + TrialId = trial.Id, + IdentityUserId = _userInfo.IdentityUserId, + JoinTime = DateTime.Now, + TrialUserRoleList = new List(){ + new TrialUserRole(){TrialId=trial.Id,UserId=_userInfo.UserRoleId} } + }); + // 添加扩展信息表记录 await _trialPaymentPriceRepository.AddAsync(new TrialPaymentPrice() { TrialId = trial.Id }); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig2.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig2.cs index 6d4fe9422..4bc1ec718 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig2.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig2.cs @@ -1,4 +1,5 @@ using AutoMapper; +using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain.Share; @@ -50,7 +51,7 @@ namespace IRaCIS.Core.Application.Service CreateMap(); - + CreateMap(); } diff --git a/IRaCIS.Core.Domain/Management/HospitalGroup.cs b/IRaCIS.Core.Domain/Management/HospitalGroup.cs index 8dff639a0..8f4c5bbbe 100644 --- a/IRaCIS.Core.Domain/Management/HospitalGroup.cs +++ b/IRaCIS.Core.Domain/Management/HospitalGroup.cs @@ -31,7 +31,7 @@ namespace IRaCIS.Core.Domain.Models public string ContactPhone { get; set; } - + } @@ -66,7 +66,11 @@ namespace IRaCIS.Core.Domain.Models public List UserTrialList { get; set; } [JsonIgnore] - public List UserRoleList { get; set; } + public List UserRoleList { get; set; } + + [JsonIgnore] + + public List IdentityUserHospitalGroupList { get; set; } [Projectable]