From 548f356f2d8f51ee0ee7a3514663648b93d89a37 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Mon, 3 Jun 2024 20:33:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppointScheduleAppService.cs | 77 ++++++++----------- .../MedicalCenterIdInputDto.cs | 2 +- .../Models/AppointScheduleTemplate.cs | 2 +- .../WebPeisOrganizationUnitManager.cs | 13 +++- .../AppointScheduleTemplateConfigure.cs | 1 + .../AppointScheduleAppServiceTest.cs | 20 +++++ 6 files changed, 69 insertions(+), 46 deletions(-) diff --git a/src/Shentun.WebPeis.Application/AppointSchedules/AppointScheduleAppService.cs b/src/Shentun.WebPeis.Application/AppointSchedules/AppointScheduleAppService.cs index 3ee980d..6d761a6 100644 --- a/src/Shentun.WebPeis.Application/AppointSchedules/AppointScheduleAppService.cs +++ b/src/Shentun.WebPeis.Application/AppointSchedules/AppointScheduleAppService.cs @@ -2,12 +2,14 @@ using Microsoft.AspNetCore.Mvc; using Shentun.WebPeis.AppointScheduleTimes; using Shentun.WebPeis.Models; +using Shentun.WebPeis.OrganizationUnits; using Shentun.WebPeis.SysParmValues; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using static log4net.Appender.RollingFileAppender; @@ -25,6 +27,7 @@ namespace Shentun.WebPeis.AppointSchedules private readonly AppointScheduleManager _appointScheduleManager; private readonly AppointScheduleTimeManager _appointScheduleTimeManager; private readonly SysParmValueManager _sysParmValueManager; + private readonly WebPeisOrganizationUnitManager _webPeisOrganizationUnitManager; public AppointScheduleAppService(IRepository appointScheduleRepository, CacheService cacheService, @@ -32,7 +35,8 @@ namespace Shentun.WebPeis.AppointSchedules IRepository appointScheduleTemplateRepository, IRepository appointScheduleTimeRepository, AppointScheduleTimeManager appointScheduleTimeManager, - SysParmValueManager sysParmValueManager) + SysParmValueManager sysParmValueManager, + WebPeisOrganizationUnitManager webPeisOrganizationUnitManager) { _appointScheduleRepository = appointScheduleRepository; _cacheService = cacheService; @@ -41,6 +45,7 @@ namespace Shentun.WebPeis.AppointSchedules _appointScheduleTimeRepository = appointScheduleTimeRepository; _appointScheduleTimeManager = appointScheduleTimeManager; _sysParmValueManager = sysParmValueManager; + _webPeisOrganizationUnitManager = webPeisOrganizationUnitManager; } /// @@ -51,8 +56,21 @@ namespace Shentun.WebPeis.AppointSchedules [HttpPost("api/app/AppointSchedule/GetAppointScheduleDateList")] public async Task> GetAppointScheduleDateListAsync(MedicalCenterIdInputDto input) { - - var canAppointDaysStr = await _sysParmValueManager.GetSysParmValueAsync(input.MedicalCenterId, "appoint_schedule_can_appoint_days"); + Guid medicalCenterId ; + if (input == null || input.MedicalCenterId == Guid.Empty || input.MedicalCenterId == null) + { + var webPeisOrganizationUnit = await _webPeisOrganizationUnitManager.GetMedicalCenterListAsync(); + if (webPeisOrganizationUnit.Count > 1) + { + throw new UserFriendlyException("体检中心参数不能为空"); + } + medicalCenterId = webPeisOrganizationUnit.First().Id; + } + else + { + medicalCenterId = (Guid)input.MedicalCenterId; + } + var canAppointDaysStr = await _sysParmValueManager.GetSysParmValueAsync(medicalCenterId, "appoint_schedule_can_appoint_days"); if (!int.TryParse(canAppointDaysStr, out var canAppointDays)) { canAppointDays = 30; @@ -61,21 +79,21 @@ namespace Shentun.WebPeis.AppointSchedules var appointSchedules = (from appointSchedule in await _appointScheduleRepository.GetQueryableAsync() join appointScheduleTime in await _appointScheduleTimeRepository.GetQueryableAsync() on appointSchedule.AppointScheduleId equals appointScheduleTime.AppointScheduleId - where appointSchedule.MedicalCenterId == input.MedicalCenterId && + where appointSchedule.MedicalCenterId == medicalCenterId && appointSchedule.AppointDate >= DateTime.Now.Date && appointSchedule.AppointDate <= DateTime.Now.Date.AddDays(canAppointDays) select new - { - appointSchedule, - appointScheduleTime - } + { + appointSchedule, + appointScheduleTime + } ).ToList(); - var list = appointSchedules.GroupBy(o => o.appointSchedule) - .Select(x => new AppointScheduleDateDto() - { - AppointDate = x.Key.AppointDate, - IsWork = (x.Key.AmNumberLimit + x.Key.PmNumberLimit) == 0? 'N':'Y', - IsFull = (x.Key.AmNumberLimit + x.Key.PmNumberLimit)<= x.Key.AppointScheduleTimes.Sum(m=>m.AppointNumber)?'Y':'N' - }).ToList(); + var list = appointSchedules.GroupBy(o => o.appointSchedule) + .Select(x => new AppointScheduleDateDto() + { + AppointDate = x.Key.AppointDate, + IsWork = (x.Key.AmNumberLimit + x.Key.PmNumberLimit) == 0 ? 'N' : 'Y', + IsFull = (x.Key.AmNumberLimit + x.Key.PmNumberLimit) <= x.Key.AppointScheduleTimes.Sum(m => m.AppointNumber) ? 'Y' : 'N' + }).ToList(); return list; } @@ -104,34 +122,7 @@ namespace Shentun.WebPeis.AppointSchedules } - private async Task> GetAppointScheduleDateTestListAsync() - { - var appointScheduleDateDtos = new List(); - DateTime startDate = DateTime.Now.Date; - for (var i = 0; i < 60; i++) - { - var appointScheduleDateDto = new AppointScheduleDateDto() - { - AppointDate = startDate.AddDays(i), - - }; - appointScheduleDateDtos.Add(new AppointScheduleDateDto() - { - AppointDate = startDate.AddDays(i), - - }); - if (appointScheduleDateDto.AppointDate.DayOfWeek == DayOfWeek.Sunday) - { - appointScheduleDateDto.IsWork = 'N'; - } - else if (appointScheduleDateDto.AppointDate.DayOfWeek == DayOfWeek.Wednesday) - { - appointScheduleDateDto.IsFull = 'Y'; - } - } - - return appointScheduleDateDtos; - } + /// diff --git a/src/Shentun.WebPeis.Application/MedicalCenterIdInputDto.cs b/src/Shentun.WebPeis.Application/MedicalCenterIdInputDto.cs index 3be79a6..cd0e5e2 100644 --- a/src/Shentun.WebPeis.Application/MedicalCenterIdInputDto.cs +++ b/src/Shentun.WebPeis.Application/MedicalCenterIdInputDto.cs @@ -8,6 +8,6 @@ namespace Shentun.WebPeis { public class MedicalCenterIdInputDto { - public Guid MedicalCenterId { get; set; } + public Guid? MedicalCenterId { get; set; } } } diff --git a/src/Shentun.WebPeis.Domain/Models/AppointScheduleTemplate.cs b/src/Shentun.WebPeis.Domain/Models/AppointScheduleTemplate.cs index 22faa5e..57e1ff1 100644 --- a/src/Shentun.WebPeis.Domain/Models/AppointScheduleTemplate.cs +++ b/src/Shentun.WebPeis.Domain/Models/AppointScheduleTemplate.cs @@ -57,7 +57,7 @@ public class AppointScheduleTemplate : AuditedEntity, IHasConcurrencyStamp, ID public int DisplayOrder { get; set; } - + public Guid MedicalCenterId { get; set; } public string? ConcurrencyStamp { get; set; } diff --git a/src/Shentun.WebPeis.Domain/OrganizationUnits/WebPeisOrganizationUnitManager.cs b/src/Shentun.WebPeis.Domain/OrganizationUnits/WebPeisOrganizationUnitManager.cs index 31acaae..d76bb6b 100644 --- a/src/Shentun.WebPeis.Domain/OrganizationUnits/WebPeisOrganizationUnitManager.cs +++ b/src/Shentun.WebPeis.Domain/OrganizationUnits/WebPeisOrganizationUnitManager.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using AutoMapper.Internal.Mappers; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Shentun.WebPeis.Models; using System; @@ -91,6 +92,16 @@ namespace Shentun.WebPeis.OrganizationUnits } + public async Task> GetMedicalCenterListAsync() + { + var entlist = (await _appOrganizationUnitRepository.GetQueryableAsync()). + Where(u => u.IsMedicalCenter == 'Y').ToList(); + + return entlist; + + } + + /// /// 获取当前用户的体检中心名称 /// diff --git a/src/Shentun.WebPeis.EntityFrameworkCore/Configures/AppointScheduleTemplateConfigure.cs b/src/Shentun.WebPeis.EntityFrameworkCore/Configures/AppointScheduleTemplateConfigure.cs index b6dd9f8..89321b5 100644 --- a/src/Shentun.WebPeis.EntityFrameworkCore/Configures/AppointScheduleTemplateConfigure.cs +++ b/src/Shentun.WebPeis.EntityFrameworkCore/Configures/AppointScheduleTemplateConfigure.cs @@ -43,6 +43,7 @@ namespace Shentun.WebPeis.Configures entity.Property(e => e.PmStopTime).HasColumnName("pm_stop_time"); entity.Property(e => e.WeekId).IsRequired().HasColumnName("week_id"); entity.Property(e => e.SingleNumberLimit).IsRequired().HasColumnName("single_number_limit"); + entity.Property(e => e.MedicalCenterId).IsRequired().HasColumnName("medical_center_id"); } } } diff --git a/test/Shentun.WebPeis.Application.Tests/AppointScheduleAppServiceTest.cs b/test/Shentun.WebPeis.Application.Tests/AppointScheduleAppServiceTest.cs index 4d547e7..4b32eea 100644 --- a/test/Shentun.WebPeis.Application.Tests/AppointScheduleAppServiceTest.cs +++ b/test/Shentun.WebPeis.Application.Tests/AppointScheduleAppServiceTest.cs @@ -68,5 +68,25 @@ namespace Shentun.WebPeis await unitOfWork.CompleteAsync(); } } + + [Fact] + public async Task GetAppointScheduleDateListNoMedicalCenterAsync() + { + using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true)) + { + + var entity = new MedicalCenterIdInputDto() + { + // MedicalCenterId = new Guid("150da355-dfbf-466b-9697-355836a862c4") + }; + var list = await _appService.GetAppointScheduleDateListAsync(null); + foreach (var item in list) + { + _output.WriteLine(item.AppointDate.ToString()); + + } + await unitOfWork.CompleteAsync(); + } + } } }