修改site

This commit is contained in:
2022-08-09 15:58:57 +08:00
parent 2b67e4930a
commit 5b74fc6f11
7 changed files with 80 additions and 20 deletions
@@ -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;
}
}
@@ -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<Site> _siteRepository;
private readonly IRepository<TrialSiteUser> _trialSiteUserRepository;
private readonly AsyncLock _mutex = new AsyncLock();
public SiteService(IRepository<Site> siteRepository, IRepository<TrialSiteUser> trialSiteUserRepository)
{
_siteRepository = siteRepository;
@@ -22,14 +26,17 @@ namespace IRaCIS.Application.Services
public async Task<PageOutput<SiteSelectDTO>> GetSiteList(SiteQueryParam searchModel)
{
var siteQueryable = _siteRepository
.WhereIf(!string.IsNullOrWhiteSpace(searchModel.SiteName), t => t.SiteName.Contains(searchModel.SiteName))
.ProjectTo<SiteSelectDTO>(_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<SiteSelectDTO>(_mapper.ConfigurationProvider);
return await siteQueryable.ToPagedListAsync(searchModel.PageIndex, searchModel.PageSize, string.IsNullOrWhiteSpace(searchModel.SortField) ? "SiteName" : searchModel.SortField, searchModel.Asc);
}
public async Task<IEnumerable<SiteSelectionDTO>> GetAllSiteList()
@@ -39,31 +46,45 @@ namespace IRaCIS.Application.Services
/// <summary> 添加研究中心 </summary>
public async Task<IResponseOutput> AddOrUpdateSite(SiteCommand siteCommand)
public async Task<IResponseOutput> AddOrUpdateSite(SiteCommand siteCommand)
{
var exp = new EntityVerifyExp<Site>()
{
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());
}
/// <summary> 删除研究中心 </summary>
[HttpDelete("{siteId:guid}")]
public async Task<IResponseOutput> DeleteSite(Guid siteId)
{
if (await _trialSiteUserRepository.AnyAsync(t => t.SiteId == siteId))
{
return ResponseOutput.NotOk("该中心已经加入项目,不可以被删除。");