From 552509ad9e67d7fddd99c98ab38e6dbd633321a2 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 22 Aug 2025 13:39:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrialSiteUser/DTO/UserTrialViewModel.cs | 5 ++ .../TrialSiteUser/TrialMaintenanceService.cs | 48 +++++++++++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs index 047dcd290..7dc54f9ea 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs @@ -472,8 +472,13 @@ namespace IRaCIS.Application.Contracts public class TrialUserAddCommand { + [NotDefault] + public Guid IdentityUserId { get; set; } + + [NotDefault] public Guid UserId { get; set; } + [NotDefault] public Guid TrialId { get; set; } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index 4f9a1e7f6..09a315757 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -165,19 +165,47 @@ namespace IRaCIS.Core.Application.Service public async Task AddTrialUsers(TrialUserAddCommand[] userTrialCommands) { - var addArray = _mapper.Map(userTrialCommands); - - var trialUsers = await _trialUseRoleRepository.AddRangeAsync(addArray); - - foreach (var item in trialUsers) + foreach (var item in userTrialCommands.GroupBy(t => t.IdentityUserId)) { - item.JoinTime = DateTime.Now; + var currentUserRoleList = item.ToList(); + + var first = currentUserRoleList.FirstOrDefault(); + + var findTrialuser = await _trialIdentityUserRepository.Where(t => t.TrialId == first.TrialId && t.IdentityUserId == item.Key, true, true).Include(t => t.TrialUserRoleList).FirstOrDefaultAsync(); + + if (findTrialuser == null) + { + var currentUser = new TrialIdentityUser() + { + TrialId = first.TrialId, + IdentityUserId = item.Key, + JoinTime = DateTime.Now, + TrialUserRoleList = currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId }).ToList() + }; + + + await _trialIdentityUserRepository.AddAsync(currentUser); + } + else + { + if (findTrialuser.IsDeleted == true) + { + findTrialuser.IsDeleted = false; + findTrialuser.DeletedTime = null; + findTrialuser.JoinTime = DateTime.Now; + findTrialuser.RemoveTime = null; + } + + findTrialuser.TrialUserRoleList.AddRange(currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId, TrialUserId = findTrialuser.Id }).ToList()); + } + + + + var success = await _trialIdentityUserRepository.SaveChangesAsync(); + } - - var success = await _trialUseRoleRepository.SaveChangesAsync(); - - return ResponseOutput.Result(success); + return ResponseOutput.Ok(); }