diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateAppointPatientRegisterDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateAppointPatientRegisterDto.cs index d067d57..e22fb52 100644 --- a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateAppointPatientRegisterDto.cs +++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateAppointPatientRegisterDto.cs @@ -33,6 +33,6 @@ namespace Shentun.WebPeis.AppointPatientRegisters public decimal? Weight { get; set; } - public List AppointRegisterAsbitems { get; set; } = new List(); + public List Asbitems { get; set; } = new List(); } } diff --git a/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs b/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs index 8047c0d..589490a 100644 --- a/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs +++ b/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Shentun.WebPeis.AppointRegisterAsbitems; using Shentun.WebPeis.Models; using System; using System.Collections.Generic; @@ -36,10 +37,15 @@ namespace Shentun.WebPeis.AppointPatientRegisters } [HttpPost("api/app/AppointPatientRegister/Create")] - public async Task CreateAsync(CreateAppointPatientRegisterDto input) + public async Task CreateAsync(CreateAppointPatientRegisterDto input) { var entity = ObjectMapper.Map(input); + var asbitems = ObjectMapper.Map, List>(input.Asbitems); + entity.AppointRegisterAsbitems = asbitems; entity = await _appointPatientRegisterManager.CreateAsync(entity); + await _repository.InsertAsync(entity); + var result = ObjectMapper.Map(entity); + return result; } } } diff --git a/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs b/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs index 90b993a..5af5a80 100644 --- a/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs +++ b/src/Shentun.WebPeis.Application/WebPeisApplicationAutoMapperProfile.cs @@ -1,6 +1,7 @@ using AutoMapper; using Shentun.Peis.MaritalStatuss; using Shentun.WebPeis.AppointPatientRegisters; +using Shentun.WebPeis.AppointRegisterAsbitems; using Shentun.WebPeis.Kinships; using Shentun.WebPeis.MaritalStatuss; using Shentun.WebPeis.MedicalPackages; @@ -59,5 +60,8 @@ public class WebPeisApplicationAutoMapperProfile : Profile CreateMap(); CreateMap(); + CreateMap(); + + } } diff --git a/src/Shentun.WebPeis.Domain/AppointPatientRegisters/AppointPatientRegisterManager.cs b/src/Shentun.WebPeis.Domain/AppointPatientRegisters/AppointPatientRegisterManager.cs index 36935e4..0a1f375 100644 --- a/src/Shentun.WebPeis.Domain/AppointPatientRegisters/AppointPatientRegisterManager.cs +++ b/src/Shentun.WebPeis.Domain/AppointPatientRegisters/AppointPatientRegisterManager.cs @@ -53,7 +53,11 @@ namespace Shentun.WebPeis.AppointPatientRegisters public async Task CreateAsync(AppointPatientRegister entity) { await Verify(entity); - //entity + entity.AppointPatientRegisterId = GuidGenerator.Create(); + foreach (var appointRegisterAsbitem in entity.AppointRegisterAsbitems) + { + appointRegisterAsbitem.AppointPatientRegisterId = entity.AppointPatientRegisterId; + } return entity; } private async Task Verify(AppointPatientRegister entity) @@ -133,6 +137,7 @@ namespace Shentun.WebPeis.AppointPatientRegisters } foreach (var appointRegisterAsbitem in entity.AppointRegisterAsbitems) { + if(appointRegisterAsbitem.ChargePrice < 0) { throw new UserFriendlyException("价格不能小于0"); @@ -145,6 +150,21 @@ namespace Shentun.WebPeis.AppointPatientRegisters { throw new UserFriendlyException("数量不能小于1"); } + if (customerOrg.CustomerOrgId == GuidFlag.PersonCustomerOrgId) + { + appointRegisterAsbitem.PayTypeFlag = PayTypeFlag.PersonPay; + + } + else + { + //在这里要判断属于分组的免费,不属于分组的自费 + if (appointRegisterAsbitem.PayTypeFlag != PayTypeFlag.PersonPay && + appointRegisterAsbitem.PayTypeFlag != PayTypeFlag.OrgPay) + { + throw new UserFriendlyException("支付类别错误"); + } + } + appointRegisterAsbitem.IsCharge = 'N'; } } } diff --git a/test/Shentun.WebPeis.Application.Tests/AppointPatientRegisterAppServiceTest.cs b/test/Shentun.WebPeis.Application.Tests/AppointPatientRegisterAppServiceTest.cs new file mode 100644 index 0000000..d39839b --- /dev/null +++ b/test/Shentun.WebPeis.Application.Tests/AppointPatientRegisterAppServiceTest.cs @@ -0,0 +1,66 @@ +using Shentun.WebPeis.AppointPatientRegisters; +using Shentun.WebPeis.AppointRegisterAsbitems; +using Shentun.WebPeis.Enums; +using Shentun.WebPeis.Models; +using Shentun.WebPeis.Persons; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Modularity; +using Volo.Abp.Uow; +using Xunit; +using Xunit.Abstractions; + +namespace Shentun.WebPeis +{ + public class AppointPatientRegisterAppServiceTest : WebPeisApplicationTestBase + where TStartupModule : IAbpModule + { + private readonly IRepository _repository; + private readonly AppointPatientRegisterAppService _appService; + private readonly ITestOutputHelper _output; + private readonly IUnitOfWorkManager _unitOfWorkManager; + public AppointPatientRegisterAppServiceTest(ITestOutputHelper output) + { + _unitOfWorkManager = GetRequiredService(); + _repository = GetRequiredService>(); + _appService = GetRequiredService(); + _output = output; + } + + [Fact] + public async Task CreateAsync() + { + using (var unitOfWork = _unitOfWorkManager.Begin(isTransactional: true)) + { + + var entity = new CreateAppointPatientRegisterDto() + { + PersonId = new Guid("3a12d7fa-63f1-d549-c2f8-01123e5b7a8a"), + CustomerOrgGroupId = null, + CustomerOrgId = GuidFlag.PersonCustomerOrgId, + MedicalCenterId = new Guid("150da355-dfbf-466b-9697-355836a862c4"), + MedicalPackageId = null, + MedicalStartDate = DateTime.Now, + CustomerOrgRegisterId = GuidFlag.PersonCustomerOrgRegisterId, + PregnantFlag = PregnantFlag.None, + Height = 170, + Weight = 60 + }; + entity.Asbitems.Add( + new CreateAppointRegisterAsbitemDto() + { + AsbitemId = new Guid("3a126b34-f6f0-56a1-e899-a092874acde7"), + Amount = 1, + ChargePrice = (decimal)30.5 + } + ); + var newEntity = await _appService.CreateAsync(entity); + await unitOfWork.CompleteAsync(); + } + } + } +} diff --git a/test/Shentun.WebPeis.EntityFrameworkCore.Tests/EntityFrameworkCore/Applications/EfCoreAppointPatientRegisterAppServiceTest.cs b/test/Shentun.WebPeis.EntityFrameworkCore.Tests/EntityFrameworkCore/Applications/EfCoreAppointPatientRegisterAppServiceTest.cs new file mode 100644 index 0000000..e47d160 --- /dev/null +++ b/test/Shentun.WebPeis.EntityFrameworkCore.Tests/EntityFrameworkCore/Applications/EfCoreAppointPatientRegisterAppServiceTest.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit.Abstractions; + +namespace Shentun.WebPeis.EntityFrameworkCore.Applications +{ + public class EfCoreAppointPatientRegisterAppServiceTest : AppointPatientRegisterAppServiceTest + { + public EfCoreAppointPatientRegisterAppServiceTest(ITestOutputHelper output) : base(output) { } + } +}