diff --git a/Shentun.Sms.Client/CreateSmsTaskDto.cs b/Shentun.Sms.Client/CreateSmsTaskDto.cs index bdff2a4..dd26397 100644 --- a/Shentun.Sms.Client/CreateSmsTaskDto.cs +++ b/Shentun.Sms.Client/CreateSmsTaskDto.cs @@ -85,6 +85,11 @@ namespace Shentun.Sms.Client /// public string? SenderName { get; set; } + /// + /// 短信模板ID + /// + public string TemplateId { get; set; } + } } diff --git a/Shentun.Sms.Client/SmsClientHelper.cs b/Shentun.Sms.Client/SmsClientHelper.cs index 7f1d2a9..bb8f0f4 100644 --- a/Shentun.Sms.Client/SmsClientHelper.cs +++ b/Shentun.Sms.Client/SmsClientHelper.cs @@ -48,7 +48,7 @@ namespace Shentun.Sms.Client throw new Exception("手机号长度必须为11位"); } - if(string.IsNullOrWhiteSpace(createSmsTaskDto.PersonId)) + if (string.IsNullOrWhiteSpace(createSmsTaskDto.PersonId)) { throw new Exception("人员ID不能为空"); @@ -90,10 +90,39 @@ namespace Shentun.Sms.Client { throw new Exception("解析校验短信类别ID错误"); } - + smsDto.SmsTypeId = verifySmsTypeId; await CreateSmsTask(smsDto); } + + + public async static Task CreateAppointSmsTask(CreateSmsTaskDto smsDto) + { + + var appointSmsTypeIdStr = _appConfig.GetSection("Sms") + .GetSection("AppointSmsTypeId").Value; + if (!Guid.TryParse(appointSmsTypeIdStr, out var appointSmsTypeId)) + { + throw new Exception("解析预约成功短信类别ID错误"); + } + + var smsAppIdStr = _appConfig.GetSection("Sms") + .GetSection("SmsAppId").Value; + if (!Guid.TryParse(smsAppIdStr, out var smsAppId)) + { + throw new Exception("解析短信应用ID错误"); + } + + + string appointTemplateId = _appConfig.GetSection("Sms") + .GetSection("AppointTemplateId").Value; + + smsDto.SmsAppId = smsAppId; + smsDto.SmsTypeId = appointSmsTypeId; + smsDto.TemplateId = appointTemplateId; + + var result = await CallAppServiceAsync(_createSmsTaskUrl, smsDto); + } public async static Task CallAppServiceAsync(string url, TInput data, string method = "post") { if (string.IsNullOrWhiteSpace(_baseAddress)) @@ -141,7 +170,7 @@ namespace Shentun.Sms.Client } result = await response.Content.ReadAsStringAsync(); - var resultDto = System.Text.Json.JsonSerializer.Deserialize>(result,jsonOptions); + var resultDto = System.Text.Json.JsonSerializer.Deserialize>(result, jsonOptions); if (resultDto.Code == -1) { throw new Exception($"调用WebApi失败,返回-1,消息:" + resultDto.Message); diff --git a/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs b/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs index 34728a2..a674299 100644 --- a/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs +++ b/Shentun.WebPeis.Plugins/AppQueueRegisterPlugIns.cs @@ -91,7 +91,7 @@ namespace Shentun.WebPeis.Plugins /// public async Task UpdateAppointPatientAsbitemStatusAsync(UpdateAppointPatientAsbitemStatusInputDto input) { - await CallAppServiceAsync(_appUpdateAppointPatientAsbitemStatusUrl, + await CallAppServiceAsync(_appUpdateAppointPatientAsbitemStatusUrl, input); } diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateWeChatOrderRefundDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateWeChatOrderRefundDto.cs new file mode 100644 index 0000000..8c11521 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/CreateWeChatOrderRefundDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.AppointPatientRegisters +{ + public class CreateWeChatOrderRefundDto + { + + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs index 9858a05..a5646ba 100644 --- a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs +++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GerAppointPatientRegisterWithAsbitemListDto.cs @@ -21,6 +21,11 @@ namespace Shentun.WebPeis.AppointPatientRegisters /// public string AppointDate { get; set; } + /// + /// 收费合计金额 + /// + public decimal ChargeSumMoney { get; set; } + /// /// 预约项目 /// diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GetAppointPatientRegisterListDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GetAppointPatientRegisterListDto.cs new file mode 100644 index 0000000..2df5365 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GetAppointPatientRegisterListDto.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.AppointPatientRegisters +{ + public class GetAppointPatientRegisterListDto + { + /// + /// 姓名 + /// + public string PatientName { get; set; } + + /// + /// 手机号 + /// + public string PhoneNumber { get; set; } + + /// + /// 身份证号码 + /// + public string IdNo { get; set; } + + /// + /// 预约日期 + /// + public string AppointDate { get; set; } + + /// + /// 套餐名称 + /// + public string MedicalPackageName { get; set; } + + + /// + /// 分组名称 + /// + public string CustomerOrgGroupName { get; set; } + + /// + /// 单位名称 + /// + public string CustomerOrgName { get; set; } + + /// + /// 部门名称 + /// + public string DepartmentName { get; set; } + + /// + /// 收费状态 0-未收费 1-已收费 2-已退费 + /// + public string ChargeFlagName { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GetAppointPatientRegisterListInputDto.cs b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GetAppointPatientRegisterListInputDto.cs new file mode 100644 index 0000000..9fbf202 --- /dev/null +++ b/src/Shentun.WebPeis.Application.Contracts/AppointPatientRegisters/GetAppointPatientRegisterListInputDto.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.WebPeis.AppointPatientRegisters +{ + public class GetAppointPatientRegisterListInputDto + { + /// + /// 姓名 + /// + public string PatientName { get; set; } + + /// + /// 手机号 + /// + public string PhoneNumber { get; set; } + + /// + /// 身份证号码 + /// + public string IdNo { get; set; } + + + /// + /// 人员类别 0-所有 1-个人 2-单位 默认0 + /// + public char PersonType { get; set; } = '0'; + + /// + /// 预约开始日期 + /// + public string AppointStartDate { get; set; } + + /// + /// 预约结束日期 + /// + public string AppointEndDate { get; set; } + + + /// + /// 收费状态 0-未收费 1-已收费 2-已退费 + /// + public char? ChargeFlag { get; set; } + } +} diff --git a/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs b/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs index 504e10c..54ca9b5 100644 --- a/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs +++ b/src/Shentun.WebPeis.Application/AppointPatientRegisters/AppointPatientRegisterAppService.cs @@ -1,7 +1,10 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Configuration; +using NPOI.Util; +using Shentun.Sms.Client; using Shentun.WebPeis.AppointRegisterAsbitems; using Shentun.WebPeis.AppointScheduleTimes; using Shentun.WebPeis.CustomerOrgs; @@ -84,6 +87,8 @@ namespace Shentun.WebPeis.AppointPatientRegisters private readonly IRepository _weChatOrderRefundRepository; private readonly IConfiguration _configuration; private readonly IWechatTenpayClientFactory _wechatTenpayClientFactory; + + public AppointPatientRegisterAppService(IRepository repository, CacheService cacheService, IRepository itemTypeRepository, @@ -125,7 +130,8 @@ namespace Shentun.WebPeis.AppointPatientRegisters IRepository weChatOrderRepository, IRepository weChatOrderRefundRepository, IConfiguration configuration, - IWechatTenpayClientFactory wechatTenpayClientFactory) + IWechatTenpayClientFactory wechatTenpayClientFactory + ) { _repository = repository; _cacheService = cacheService; @@ -201,12 +207,22 @@ namespace Shentun.WebPeis.AppointPatientRegisters entity.MedicalCenterId = medicalCenterId; entity = await _appointPatientRegisterManager.CreateAsync(entity); - await _repository.InsertAsync(entity); + await _repository.InsertAsync(entity, true); //修改预约数量 await _appointScheduleTimeManager.UpdateAppointNumberAsync(input.AppointDate); var result = ObjectMapper.Map(entity); + + #region 推送预约成功短信 + + var isAppointEnabled = _configuration.GetSection("Sms:IsAppointEnabled").Value; + if (isAppointEnabled == "Y") + { + await PushAppointPatientRegisterSuccessSmsAsync(entity.AppointPatientRegisterId); + } + #endregion + return result; } @@ -1147,7 +1163,132 @@ namespace Shentun.WebPeis.AppointPatientRegisters } } - + /// + /// 获取预约列表,小程序后台统计 + /// + /// + [HttpPost("api/app/AppointPatientRegister/GetAppointPatientRegisterList")] + public async Task> GetAppointPatientRegisterListAsync(GetAppointPatientRegisterListInputDto input) + { + var query = from appointPatientRegister in await _repository.GetQueryableAsync() + join person in await _personRepository.GetQueryableAsync() on appointPatientRegister.PersonId equals person.PersonId + join identityUser in await _identityUserRepository.GetQueryableAsync() on person.PersonId equals identityUser.Id + join patientRegister in await _patientRegisterRepository.GetQueryableAsync() on appointPatientRegister.PatientRegisterId equals patientRegister.PatientRegisterId into patientRegisterTemp + from patientRegisterHaveEmpty in patientRegisterTemp.DefaultIfEmpty() + join patient in await _patientRepository.GetQueryableAsync() on patientRegisterHaveEmpty.PatientId equals patient.PatientId into patientTemp + from patientHaveEmpty in patientTemp.DefaultIfEmpty() + join medicalPackage in await _medicalPackageRepository.GetQueryableAsync() on appointPatientRegister.MedicalPackageId equals medicalPackage.MedicalPackageId into medicalPackageTemp + from medicalPackageHaveEmpty in medicalPackageTemp.DefaultIfEmpty() + join customerOrgGroup in await _customerOrgGroupRepository.GetQueryableAsync() on appointPatientRegister.CustomerOrgGroupId equals customerOrgGroup.CustomerOrgGroupId into customerOrgGroupTemp + from customerOrgGroupHaveEmpty in customerOrgGroupTemp.DefaultIfEmpty() + where appointPatientRegister.CompleteFlag != AppointPatientRegisterCompleteFlag.CancelAppoint + select new + { + patientName = identityUser.Name, + phoneNumber = identityUser.PhoneNumber, + idNo = person.IdNo, + appointPatientRegister, + patientRegisterHaveEmpty, + patientHaveEmpty, + medicalPackageName = medicalPackageHaveEmpty != null ? medicalPackageHaveEmpty.MedicalPackageName : "", + customerOrgGroupName = customerOrgGroupHaveEmpty != null ? customerOrgGroupHaveEmpty.CustomerOrgGroupName : "" + }; + + + + if (!string.IsNullOrWhiteSpace(input.PatientName)) + { + query = query.Where(m => m.patientName == input.PatientName); + } + + if (!string.IsNullOrWhiteSpace(input.PhoneNumber)) + { + query = query.Where(m => m.phoneNumber == input.PhoneNumber); + } + + if (!string.IsNullOrWhiteSpace(input.IdNo)) + { + query = query.Where(m => m.idNo == input.IdNo); + } + + if (input.ChargeFlag != null) + { + query = query.Where(m => m.appointPatientRegister.ChargeFlag == input.ChargeFlag); + } + + if (input.PersonType == '1') + { + query = query.Where(m => m.patientRegisterHaveEmpty == null); + } + else if (input.PersonType == '2') + { + query = query.Where(m => m.patientRegisterHaveEmpty != null); + } + + if (!string.IsNullOrWhiteSpace(input.AppointStartDate) && !string.IsNullOrWhiteSpace(input.AppointEndDate)) + { + query = query.Where(m => m.appointPatientRegister.AppointDate >= Convert.ToDateTime(input.AppointStartDate) && + m.appointPatientRegister.AppointDate < Convert.ToDateTime(input.AppointEndDate).AddDays(1)); + } + + var entListDto = query.ToList().Select(s => new GetAppointPatientRegisterListDto + { + AppointDate = DataHelper.ConversionDateShortToString(s.appointPatientRegister.AppointDate), + ChargeFlagName = s.appointPatientRegister.ChargeFlag == '0' ? "未收费" : s.appointPatientRegister.ChargeFlag == '1' ? "已收费" : "已退费", + IdNo = s.idNo, + PatientName = s.patientName, + PhoneNumber = s.phoneNumber, + DepartmentName = _cacheService.GetCustomerOrgAsync(s.appointPatientRegister.CustomerOrgId).GetAwaiter().GetResult().CustomerOrgName, + CustomerOrgName = _cacheService.GetTopCustomerOrgAsync(s.appointPatientRegister.CustomerOrgId).GetAwaiter().GetResult().CustomerOrgName, + MedicalPackageName = s.medicalPackageName, + CustomerOrgGroupName = s.customerOrgGroupName + }).ToList(); + + return entListDto; + + } + + /// + /// 推送预约成功短信 + /// + /// + /// + private async Task PushAppointPatientRegisterSuccessSmsAsync(Guid appointPatientRegisterId) + { + + var personEnt = (from appointPatientRegister in await _repository.GetQueryableAsync() + join person in await _personRepository.GetQueryableAsync() on appointPatientRegister.PersonId equals person.PersonId + join identityUser in await _identityUserRepository.GetQueryableAsync() on person.PersonId equals identityUser.Id + where appointPatientRegister.AppointPatientRegisterId == appointPatientRegisterId + select new + { + identityUser.Name, + identityUser.PhoneNumber, + person.PersonId + }).FirstOrDefault(); + + if (personEnt != null) + { + var inputDto = new CreateSmsTaskDto + { + Content = "", + CountryCode = "86", + MobileTelephone = personEnt.PhoneNumber, + PersonId = personEnt.PersonId.ToString(), + PersonName = personEnt.Name, + SenderId = "admin", + SenderName = "体检", + StopTime = "", + TaskCorn = "", + TaskCycleType = '0', + ThirdId = personEnt.PersonId.ToString() + }; + + await SmsClientHelper.CreateAppointSmsTask(inputDto); + } + } + + #region 提供给体检系统调用 @@ -1432,13 +1573,16 @@ namespace Shentun.WebPeis.AppointPatientRegisters join appointRegisterAsbitem in await _appointRegisterAsbitemRepository.GetQueryableAsync() on appointPatientRegister.AppointPatientRegisterId equals appointRegisterAsbitem.AppointPatientRegisterId join asbitem in await _asbitemRepository.GetQueryableAsync() on appointRegisterAsbitem.AsbitemId equals asbitem.AsbitemId + join weChatOrder in await _weChatOrderRepository.GetQueryableAsync() on appointPatientRegister.AppointPatientRegisterId equals weChatOrder.AppointPatientRegisterId where appointPatientRegister.ChargeFlag == ChargeFlag.Charge && input.AppointPatientRegisterIds.Contains(appointPatientRegister.AppointPatientRegisterId) + && weChatOrder.Status == "SUCCESS" select new { appointPatientRegister, appointRegisterAsbitem, - asbitem + asbitem, + weChatOrder }).ToList(); @@ -1449,6 +1593,7 @@ namespace Shentun.WebPeis.AppointPatientRegisters AppointPatientRegisterId = s.Key.AppointPatientRegisterId, ChargeFlag = s.Key.ChargeFlag, AppointDate = DataHelper.ConversionDateShortToString(s.Key.AppointDate), + ChargeSumMoney = Convert.ToDecimal(s.FirstOrDefault().weChatOrder.OrderMoney) / 100, AppointRegisterAsbitemDetail = s.Select(ss => new GerAppointPatientRegisterWithAsbitemListChargeAsbitemDto { Amount = ss.appointRegisterAsbitem.Amount, @@ -1463,7 +1608,7 @@ namespace Shentun.WebPeis.AppointPatientRegisters }).ToList(); - + return entListDto; } @@ -1476,7 +1621,7 @@ namespace Shentun.WebPeis.AppointPatientRegisters /// [AllowAnonymous] [HttpPost("api/app/AppointPatientRegister/CreateWeChatOrderRefund")] - public async Task CreateWeChatOrderRefundAsync(CreateWeChatOrderRefundInputDto input) + public async Task CreateWeChatOrderRefundAsync(CreateWeChatOrderRefundInputDto input) { var weChatOrderEnt = await _weChatOrderRepository.FirstOrDefaultAsync(f => f.AppointPatientRegisterId == input.AppointPatientRegisterId @@ -1546,6 +1691,8 @@ namespace Shentun.WebPeis.AppointPatientRegisters { throw new UserFriendlyException("预约Id不正确"); } + + return new CreateWeChatOrderRefundDto(); } #endregion diff --git a/src/Shentun.WebPeis.Domain/CacheService.cs b/src/Shentun.WebPeis.Domain/CacheService.cs index 5c04bc4..5fbb772 100644 --- a/src/Shentun.WebPeis.Domain/CacheService.cs +++ b/src/Shentun.WebPeis.Domain/CacheService.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using Shentun.WebPeis.Enums; using Shentun.WebPeis.Models; +using Shentun.WebPeis.SysParmValues; using System; using System.Collections.Generic; using System.Linq; @@ -33,11 +34,11 @@ namespace Shentun.WebPeis private readonly IRepository _sexRepository; private readonly IRepository _forSexRepository; private readonly IRepository _asbitemRepository; - + private readonly IRepository _itemTypeRepository; private readonly IRepository _customerOrgRepository; private readonly IRepository _maritalStatusRepository; - + private readonly IDistributedCache _customerOrgDisplayModeCache; public CacheService( IDistributedCache userCache, IMemoryCache customerOrgCache, @@ -47,9 +48,9 @@ namespace Shentun.WebPeis IMemoryCache asbitemCache, IMemoryCache itemTypeCache, IDistributedCache maritalStatusCache, - + IRepository sexRepository, - + IDistributedCache forSexCache, IRepository forSexRepository, IRepository asbitemRepository, @@ -57,7 +58,8 @@ namespace Shentun.WebPeis IRepository nationRepository, IRepository customerOrgRepository, IRepository maritalStatusRepository, - IDistributedCache customerOrgTopNameCache) + IDistributedCache customerOrgTopNameCache, + IDistributedCache customerOrgDisplayModeCache) { _userCache = userCache; _userRepository = userRepository; @@ -85,6 +87,7 @@ namespace Shentun.WebPeis _maritalStatusRepository = maritalStatusRepository; _customerOrgTopNameCache = customerOrgTopNameCache; + _customerOrgDisplayModeCache = customerOrgDisplayModeCache; } private async Task GetUserAsync(Guid id) @@ -162,7 +165,7 @@ namespace Shentun.WebPeis return entity.MaritalStatusName; } - + public async Task GetAsbitemAsync(Guid id) { @@ -234,7 +237,7 @@ namespace Shentun.WebPeis _customerOrgCache.Set(id, entity); //entity = (CustomerOrg)_customerOrgCache.Get(id); } - + return entity; } @@ -248,18 +251,32 @@ namespace Shentun.WebPeis return entity.CustomerOrgName; } + /// + /// 获取单位,部门往上推一级 + /// + /// + /// public async Task GetTopCustomerOrgAsync(Guid id) { - var entity = (CustomerOrg)_customerOrgCache.Get(id); - if(entity == null) + + var entity = (CustomerOrg)_customerOrgCache.Get(id); + if (entity == null) { entity = await _customerOrgRepository.GetAsync(o => o.CustomerOrgId == id); _customerOrgCache.Set(id, entity); } - + if (entity.ParentId != null && entity.ParentId != Guid.Empty) { - entity = await GetTopCustomerOrgAsync((Guid)entity.ParentId); + Guid parentId = (Guid)entity.ParentId; + + + entity = (CustomerOrg)_customerOrgCache.Get(parentId); + if (entity == null) + { + entity = await _customerOrgRepository.GetAsync(o => o.CustomerOrgId == parentId); + _customerOrgCache.Set(parentId, entity); + } } return entity; } @@ -294,7 +311,7 @@ namespace Shentun.WebPeis _customerOrgCache.Set(id, entity); } - + if (entity.CustomerOrgId == GuidFlag.PersonCustomerOrgId) { return entity.CustomerOrgName; diff --git a/src/Shentun.WebPeis.HttpApi.Host/appsettings.json b/src/Shentun.WebPeis.HttpApi.Host/appsettings.json index 93605e7..89b04af 100644 --- a/src/Shentun.WebPeis.HttpApi.Host/appsettings.json +++ b/src/Shentun.WebPeis.HttpApi.Host/appsettings.json @@ -48,14 +48,17 @@ } ], "Sms": { - "BaseAddress": "http://62.156.10.86:44382", + "BaseAddress": "http://192.168.2.181:44383", "CreateSmsTaskUrl": "api/app/SmsTask/Create", "User": "admin", "Password": "888888", "VerifySmsTypeId": "3a12e09d-438a-1d08-d4f0-712aef13708d", - "VerifySmsValidTime": "1", + "VerifySmsValidTime": "2", "IsTemplateTime": "N", - "SmsAppId": "3a12e09f-8534-ec43-8c46-e61af0964ab6" + "SmsAppId": "3a12e09f-8534-ec43-8c46-e61af0964ab6", + "IsAppointEnabled": "Y", + "AppointSmsTypeId": "3a167084-3d06-ab95-a9ab-1dffc961b9ac", + "AppointTemplateId": "2316290" }, "Redis": { "IsEnabled": "true",