diff --git a/IRaCIS.Core.API/appsettings.json b/IRaCIS.Core.API/appsettings.json index 819c73a31..93fe21d06 100644 --- a/IRaCIS.Core.API/appsettings.json +++ b/IRaCIS.Core.API/appsettings.json @@ -77,6 +77,8 @@ "DicomStudyCodePrefix": "ST", + "SystemSiteCodePrefix": "S", + "DefaultPassword": "123456", "DefaultInternalOrganizationName": "ExtImaging", diff --git a/IRaCIS.Core.Application/Service/Institution/DTO/SiteModel.cs b/IRaCIS.Core.Application/Service/Institution/DTO/SiteModel.cs index de32f9643..989616973 100644 --- a/IRaCIS.Core.Application/Service/Institution/DTO/SiteModel.cs +++ b/IRaCIS.Core.Application/Service/Institution/DTO/SiteModel.cs @@ -12,10 +12,14 @@ namespace IRaCIS.Application.Contracts { public Guid? Id { get; set; } public string SiteName { get; set; } = String.Empty; + + public int Code { get; set; } public string SiteCode { get; set; } = String.Empty; public string Address { get; set; } = String.Empty; public string UniqueCode { get; set; } = string.Empty; + + public string AliasName { get; set; } = string.Empty; public string City { get; set; } = string.Empty; public string Country { get; set; } = string.Empty; public Guid? HospitalId { get; set; } @@ -42,6 +46,11 @@ namespace IRaCIS.Application.Contracts public class SiteQueryParam : PageInput { public string SiteName { get; set; } = String.Empty; - public Guid UserId { get; set; } = Guid.Empty; + public string AliasName { get; set; } = string.Empty; + + public string City { get; set; } = string.Empty; + + + public string Country { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/IRaCIS.Core.Application/Service/Institution/SiteService.cs b/IRaCIS.Core.Application/Service/Institution/SiteService.cs index 22470bc55..a01360d7e 100644 --- a/IRaCIS.Core.Application/Service/Institution/SiteService.cs +++ b/IRaCIS.Core.Application/Service/Institution/SiteService.cs @@ -2,15 +2,19 @@ using IRaCIS.Application.Contracts; using IRaCIS.Core.Infra.EFCore; using Microsoft.AspNetCore.Mvc; +using IRaCIS.Core.Domain.Share; +using Nito.AsyncEx; namespace IRaCIS.Application.Services { - [ ApiExplorerSettings(GroupName = "Institution")] + [ApiExplorerSettings(GroupName = "Institution")] public class SiteService : BaseService, ISiteService { private readonly IRepository _siteRepository; private readonly IRepository _trialSiteUserRepository; + private readonly AsyncLock _mutex = new AsyncLock(); + public SiteService(IRepository siteRepository, IRepository trialSiteUserRepository) { _siteRepository = siteRepository; @@ -22,14 +26,17 @@ namespace IRaCIS.Application.Services public async Task> GetSiteList(SiteQueryParam searchModel) { - var siteQueryable = _siteRepository - .WhereIf(!string.IsNullOrWhiteSpace(searchModel.SiteName), t => t.SiteName.Contains(searchModel.SiteName)) - .ProjectTo(_mapper.ConfigurationProvider); + var siteQueryable = _siteRepository + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.SiteName), t => t.SiteName.Contains(searchModel.SiteName)) + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.AliasName), t => t.AliasName.Contains(searchModel.AliasName)) + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.City), t => t.City.Contains(searchModel.City)) + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.Country), t => t.Country.Contains(searchModel.Country)) + .ProjectTo(_mapper.ConfigurationProvider); return await siteQueryable.ToPagedListAsync(searchModel.PageIndex, searchModel.PageSize, string.IsNullOrWhiteSpace(searchModel.SortField) ? "SiteName" : searchModel.SortField, searchModel.Asc); - + } public async Task> GetAllSiteList() @@ -39,31 +46,45 @@ namespace IRaCIS.Application.Services /// 添加研究中心 - - public async Task AddOrUpdateSite(SiteCommand siteCommand) + + public async Task AddOrUpdateSite(SiteCommand siteCommand) { var exp = new EntityVerifyExp() { - VerifyExp = h => h.SiteName.Equals(siteCommand.SiteName)|| h.SiteCode.Equals(siteCommand.SiteCode), + VerifyExp = h => h.SiteName.Equals(siteCommand.SiteName) || h.SiteCode.Equals(siteCommand.SiteCode), VerifyMsg = "已经存在同名的中心,请确认。" }; - var site = await _siteRepository.InsertOrUpdateAsync(siteCommand, true, exp); + using (await _mutex.LockAsync()) + { + if (siteCommand.Id == null) + { + + siteCommand.Code = await _siteRepository.Select(t => t.Code).DefaultIfEmpty().MaxAsync() + 1; + + siteCommand.SiteCode = AppSettings.GetCodeStr(siteCommand.Code, nameof(User)); + } + + var site = await _siteRepository.InsertOrUpdateAsync(siteCommand, true, exp); + + return ResponseOutput.Ok(site.Id.ToString()); + + } + + + - - return ResponseOutput.Ok(site.Id.ToString()); - } /// 删除研究中心 - + [HttpDelete("{siteId:guid}")] public async Task DeleteSite(Guid siteId) { - + if (await _trialSiteUserRepository.AnyAsync(t => t.SiteId == siteId)) { return ResponseOutput.NotOk("该中心已经加入项目,不可以被删除。"); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs index 1148bd3ff..4d6f03f16 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialSiteViewModel.cs @@ -97,12 +97,21 @@ namespace IRaCIS.Core.Application.Contracts.DTO public string SiteName { get; set; } = String.Empty; + public string AliasName { get; set; } = string.Empty; + + public string City { get; set; } = string.Empty; + + + public string Country { get; set; } = string.Empty; + } public class TrialSiteScreeningDTO { public Guid Id { get; set; } public string SiteName { get; set; } = String.Empty; + + public string AliasName { get; set; } = string.Empty; public string SiteCode { get; set; } = String.Empty; public string City { get; set; } = String.Empty; public string Country { get; set; } = String.Empty; diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs index c42a966ed..e618f9e7b 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs @@ -190,18 +190,21 @@ namespace IRaCIS.Core.Application.Services /// [new] Setting页面 Site勾选列表( [HttpPost] - public async Task> GetTrialSiteScreeningList(TrialSiteQuery trialSiteQuery) + public async Task> GetTrialSiteScreeningList(TrialSiteQuery searchModel) { // 之前选择了的不能再次出现在列表,做的时候我就不建议这样搞,搞好了 现在又要改回去。。。 瞎折腾。。。。 var siteQueryable = _siteRepository.AsQueryable(true) - .WhereIf(!string.IsNullOrWhiteSpace(trialSiteQuery.SiteName), t => t.SiteName.Contains(trialSiteQuery.SiteName)) - .ProjectTo(_mapper.ConfigurationProvider, new { trialId = trialSiteQuery.TrialId }); + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.SiteName), t => t.SiteName.Contains(searchModel.SiteName)) + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.AliasName), t => t.AliasName.Contains(searchModel.AliasName)) + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.City), t => t.City.Contains(searchModel.City)) + .WhereIf(!string.IsNullOrWhiteSpace(searchModel.Country), t => t.Country.Contains(searchModel.Country)) + .ProjectTo(_mapper.ConfigurationProvider, new { trialId = searchModel.TrialId }); - return await siteQueryable.ToPagedListAsync(trialSiteQuery.PageIndex, - trialSiteQuery.PageSize, string.IsNullOrWhiteSpace(trialSiteQuery.SortField) ? "SiteName" : trialSiteQuery.SortField, trialSiteQuery.Asc); + return await siteQueryable.ToPagedListAsync(searchModel.PageIndex, + searchModel.PageSize, string.IsNullOrWhiteSpace(searchModel.SortField) ? "SiteName" : searchModel.SortField, searchModel.Asc); } diff --git a/IRaCIS.Core.Domain/Institution/Site.cs b/IRaCIS.Core.Domain/Institution/Site.cs index e18ffed98..f47e1f1e5 100644 --- a/IRaCIS.Core.Domain/Institution/Site.cs +++ b/IRaCIS.Core.Domain/Institution/Site.cs @@ -9,8 +9,12 @@ namespace IRaCIS.Core.Domain.Models { public Hospital Hospital { get; set; } public string SiteName { get; set; } + + public string AliasName { get; set; } = string.Empty; public string SiteCode { get; set; } + public int Code { get; set; } + public string City { get; set; } public string Country { get; set; } public Guid? HospitalId { get; set; } diff --git a/IRaCIS.Core.Domain/_Config/_AppSettings.cs b/IRaCIS.Core.Domain/_Config/_AppSettings.cs index c5a9cbc84..b4dcd8b32 100644 --- a/IRaCIS.Core.Domain/_Config/_AppSettings.cs +++ b/IRaCIS.Core.Domain/_Config/_AppSettings.cs @@ -39,6 +39,10 @@ namespace IRaCIS.Core.Domain.Share public static int ImageShareExpireDays { get; set; } = 7; + public static string SystemSiteCodePrefix { get; set; } + + + /// /// 用户默认密码 /// @@ -61,9 +65,13 @@ namespace IRaCIS.Core.Domain.Share NoneDicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("NoneDicomStudyCodePrefix"); DicomStudyCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("DicomStudyCodePrefix"); DefaultPassword= configuration.GetSection("IRaCISBasicConfig").GetValue("DefaultPassword"); + SystemSiteCodePrefix = configuration.GetSection("IRaCISBasicConfig").GetValue("SystemSiteCodePrefix"); + DefaultInternalOrganizationName = configuration.GetSection("IRaCISBasicConfig").GetValue("DefaultInternalOrganizationName"); ImageShareExpireDays = configuration.GetSection("IRaCISBasicConfig").GetValue("ImageShareExpireDays"); + + } @@ -96,6 +104,10 @@ namespace IRaCIS.Core.Domain.Share return "W" + codeInt.ToString("D5"); + case nameof(Site): + + return SystemSiteCodePrefix + codeInt.ToString("D4"); + default: return string.Empty; }