diff --git a/src/Shentun.Peis.Application.Contracts/AIMessages/DeepSeekResponse.cs b/src/Shentun.Peis.Application.Contracts/AIMessages/DeepSeekResponse.cs new file mode 100644 index 0000000..ff0be73 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/AIMessages/DeepSeekResponse.cs @@ -0,0 +1,71 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.AIMessages +{ + public class DeepSeekResponse + { + // 唯一请求标识符 + [JsonProperty("id")] + public string Id { get; set; } + + // 响应创建时间戳(Unix时间) + [JsonProperty("created")] + public long Created { get; set; } + + // 使用的模型名称(如deepseek-chat) + [JsonProperty("model")] + public string Model { get; set; } + + // 包含对话结果的集合 + [JsonProperty("choices")] + public List Choices { get; set; } + + // Token使用统计(可选字段) + [JsonProperty("usage")] + public UsageInfo Usage { get; set; } + } + + public class Choice + { + // 结果序号(多结果时区分) + [JsonProperty("index")] + public int Index { get; set; } + + // 消息内容封装 + [JsonProperty("message")] + public Message Message { get; set; } + + // 终止原因(如"stop"表示正常结束) + [JsonProperty("finish_reason")] + public string FinishReason { get; set; } + } + + public class Message + { + // 角色标识(user/assistant) + [JsonProperty("role")] + public string Role { get; set; } + + // AI返回的文本内容 + [JsonProperty("content")] + public string Content { get; set; } + } + + public class UsageInfo + { + // 输入消耗的Token数 + [JsonProperty("prompt_tokens")] + public int PromptTokens { get; set; } + + // 输出消耗的Token数 + [JsonProperty("completion_tokens")] + public int CompletionTokens { get; set; } + + // 总Token消耗 + [JsonProperty("total_tokens")] + public int TotalTokens { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultDto.cs b/src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultDto.cs new file mode 100644 index 0000000..5e7f26f --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.AIMessages +{ + public class GetAIMessageResultDto + { + public string Result { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultInputDto.cs b/src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultInputDto.cs new file mode 100644 index 0000000..8ffe223 --- /dev/null +++ b/src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultInputDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Shentun.Peis.AIMessages +{ + public class GetAIMessageResultInputDto + { + public string Message { get; set; } + } +} diff --git a/src/Shentun.Peis.Application.Contracts/PeisReports/GetPatientRegisterReportRequestDto.cs b/src/Shentun.Peis.Application.Contracts/PeisReports/GetPatientRegisterReportRequestDto.cs index 4ccb625..ac40da6 100644 --- a/src/Shentun.Peis.Application.Contracts/PeisReports/GetPatientRegisterReportRequestDto.cs +++ b/src/Shentun.Peis.Application.Contracts/PeisReports/GetPatientRegisterReportRequestDto.cs @@ -73,6 +73,11 @@ namespace Shentun.Peis.PeisReports /// public string? IdNo { get; set; } + /// + /// 体检结论id集合 空集合查询所有 + /// + public List MedicalConclusionIds { get; set; } = new List(); + } public class GetPeisReportDetailRequest_CustomerOrg diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/GetPatientRegisterCriticalListInputDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/GetPatientRegisterCriticalListInputDto.cs index 3023cf2..6949f44 100644 --- a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/GetPatientRegisterCriticalListInputDto.cs +++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/GetPatientRegisterCriticalListInputDto.cs @@ -85,6 +85,16 @@ namespace Shentun.Peis.PhoneFollowUps /// public char? IsPhoneComplete { get; set; } + /// + /// 开始日期 随访日期检索 + /// + public string? PhoneFollowUpStartDate { get; set; } + + /// + /// 结束日期 随访日期检索 + /// + public string? PhoneFollowUpEndDate { get; set; } + /// /// 诊断级别ID 集合 可以查多个 /// diff --git a/src/Shentun.Peis.Application/AIMessages/AIMessageAppService.cs b/src/Shentun.Peis.Application/AIMessages/AIMessageAppService.cs new file mode 100644 index 0000000..953a606 --- /dev/null +++ b/src/Shentun.Peis.Application/AIMessages/AIMessageAppService.cs @@ -0,0 +1,107 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Shentun.Peis.Enums; +using Shentun.Peis.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Json; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace Shentun.Peis.AIMessages +{ + /// + /// AI对话 + /// + [ApiExplorerSettings(GroupName = "Work")] + [Authorize] + public class AIMessageAppService : ApplicationService + { + private readonly IRepository _thirdInterfaceRepository; + public AIMessageAppService( + IRepository thirdInterfaceRepository + ) + { + _thirdInterfaceRepository = thirdInterfaceRepository; + } + + /// + /// 获取Ai回复内容 + /// + /// + /// + /// + [HttpPost("api/app/AIMessage/GetAIMessageResult")] + public async Task GetAIMessageResultAsync(GetAIMessageResultInputDto input) + { + var messageDto = new GetAIMessageResultDto(); + + if (string.IsNullOrWhiteSpace(input.Message)) + { + throw new UserFriendlyException("请求内容不能为空"); + } + + var thirdInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(f => f.ThirdInterfaceType == ThirdInterfaceTypeFlag.WebAI); + + if (thirdInterface == null) + { + throw new UserFriendlyException("未配置第三方AI接口"); + } + + if (thirdInterface.IsActive != 'Y') + { + throw new UserFriendlyException("该接口已禁用"); + } + + var parmValue = thirdInterface.ParmValue; + var configurationBuilder = new ConfigurationBuilder() + .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue))); + var config = configurationBuilder.Build(); + var apiBaseAddress = config.GetSection("Interface").GetSection("BaseAddress").Value; + var apiKey = config.GetSection("Interface").GetSection("ApiKey").Value; + var aiType = config.GetSection("Interface").GetSection("AIType").Value; + var modelValue = config.GetSection("Interface").GetSection("ModelValue").Value; + + if (aiType == AITypeFlag.DeepSeek) + { + using (HttpClient client = new HttpClient()) + { + client.BaseAddress = new Uri(apiBaseAddress); + // 设置API密钥或其他认证信息(如果有的话) + client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); + + try + { + var requestBody = new + { + model = modelValue, + messages = new[] { new { role = "user", content = input.Message } } + }; + + var response = await client.PostAsJsonAsync("chat/completions", requestBody); + var result = await response.Content.ReadFromJsonAsync(); + string data = result.Choices.First().Message.Content; + messageDto.Result = data; + + } + catch (HttpRequestException e) + { + throw new UserFriendlyException($"获取异常:{e.Message}"); + } + } + } + else + { + throw new UserFriendlyException("AI接口类型不正确"); + } + return messageDto; + } + } +} diff --git a/src/Shentun.Peis.Application/PeisApplicationModule.cs b/src/Shentun.Peis.Application/PeisApplicationModule.cs index 664d1c5..2b739a3 100644 --- a/src/Shentun.Peis.Application/PeisApplicationModule.cs +++ b/src/Shentun.Peis.Application/PeisApplicationModule.cs @@ -52,6 +52,8 @@ public class PeisApplicationModule : AbpModule //{ // options.PlugInSources.AddFolder(@"E:\Whitedolphins\NextPeis\src\Shentun.ColumnReferencePlugIns\bin\Debug\net6.0"); //}); + + //AI } diff --git a/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs b/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs index 3816594..bf43208 100644 --- a/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs +++ b/src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs @@ -116,7 +116,8 @@ namespace Shentun.Peis.PeisReports a.CreatorId, a.MaritalStatusId, a.IsUploadAppoint, - a.SummaryDoctorId + a.SummaryDoctorId, + a.MedicalConclusionId }, //RegisterCheckCompleteFlag = registerCheck.CompleteFlag, //IsCheck = asbitem.IsCheck, @@ -290,6 +291,10 @@ namespace Shentun.Peis.PeisReports } + if (input.MedicalConclusionIds.Any()) + { + sumquery = sumquery.Where(m => m.a.MedicalConclusionId != null && input.MedicalConclusionIds.Contains(m.a.MedicalConclusionId.Value)); + } int totalCount = sumquery.Count(); diff --git a/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs b/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs index 1f57ae4..57f0828 100644 --- a/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs +++ b/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs @@ -41,7 +41,7 @@ namespace Shentun.Peis.PhoneFollowUps private readonly IRepository _patientRepository; private readonly CustomerOrgManager _customerOrgManager; private readonly IRepository _registerCheckSummaryRepository; - private readonly IRepository _smsSendRepository; + private readonly IRepository _smsSendRepository; public PhoneFollowUpAppService( @@ -513,6 +513,14 @@ namespace Shentun.Peis.PhoneFollowUps query = query.Where(m => input.DiagnosisLevelIds.Contains(m.registerCheck.DiagnosisLevelId) || input.DiagnosisLevelIds.Contains(m.registerCheckItem.DiagnosisLevelId)); } + + if (!string.IsNullOrWhiteSpace(input.PhoneFollowUpStartDate) && !string.IsNullOrWhiteSpace(input.PhoneFollowUpEndDate)) + { + query = query.Where(m => m.phoneFollowUpEmpty != null + && m.phoneFollowUpEmpty.PlanFollowDate >= Convert.ToDateTime(input.PhoneFollowUpStartDate) + && m.phoneFollowUpEmpty.PlanFollowDate < Convert.ToDateTime(input.PhoneFollowUpEndDate).AddDays(1)); + } + #endregion @@ -561,46 +569,49 @@ namespace Shentun.Peis.PhoneFollowUps }; - var phoneFollowUpWithPatientRegisterDetail = itemGroup.Where(m => m.phoneFollowUpEmpty != null).Select(s => new PhoneFollowUpWithPatientRegisterDto + + var phoneFollowUpWithPatientRegisterDetail = itemGroup.Where(m => m.phoneFollowUpEmpty != null).GroupBy(g => g.phoneFollowUpEmpty).Select(s => new PhoneFollowUpWithPatientRegisterDto { - FollowUpId = s.phoneFollowUpEmpty.FollowUpId, - CreationTime = s.phoneFollowUpEmpty.CreationTime, - ReplyContent = s.phoneFollowUpEmpty.ReplyContent, - PlanFollowDate = DataHelper.ConversionDateToString(s.phoneFollowUpEmpty.PlanFollowDate), - CreatorId = s.phoneFollowUpEmpty.CreatorId, - FollowUpContent = s.phoneFollowUpEmpty.FollowUpContent, - Id = s.phoneFollowUpEmpty.Id, - IsComplete = s.phoneFollowUpEmpty.IsComplete, - LastModificationTime = s.phoneFollowUpEmpty.LastModificationTime, - LastModifierId = s.phoneFollowUpEmpty.LastModifierId, - CreatorName = _cacheService.GetSurnameAsync(s.phoneFollowUpEmpty.CreatorId).GetAwaiter().GetResult(), - LastModifierName = _cacheService.GetSurnameAsync(s.phoneFollowUpEmpty.LastModifierId).GetAwaiter().GetResult(), + FollowUpId = s.Key.FollowUpId, + CreationTime = s.Key.CreationTime, + ReplyContent = s.Key.ReplyContent, + PlanFollowDate = DataHelper.ConversionDateToString(s.Key.PlanFollowDate), + CreatorId = s.Key.CreatorId, + FollowUpContent = s.Key.FollowUpContent, + Id = s.Key.Id, + IsComplete = s.Key.IsComplete, + LastModificationTime = s.Key.LastModificationTime, + LastModifierId = s.Key.LastModifierId, + CreatorName = _cacheService.GetSurnameAsync(s.Key.CreatorId).GetAwaiter().GetResult(), + LastModifierName = _cacheService.GetSurnameAsync(s.Key.LastModifierId).GetAwaiter().GetResult(), PatientName = firstItem.patientRegister.PatientName }).ToList(); - var smsSendDetail = itemGroup.Where(m => m.smsSendEmpty != null).Select(s => new SmsSendDto + var smsSendDetail = itemGroup.Where(m => m.smsSendEmpty != null).GroupBy(g => g.smsSendEmpty).Select(s => new SmsSendDto { - FollowUpId = s.smsSendEmpty.FollowUpId, - CreationTime = s.smsSendEmpty.CreationTime, - CreatorId = s.smsSendEmpty.CreatorId, - Id = s.smsSendEmpty.Id, - IsComplete = s.smsSendEmpty.IsComplete, - LastModificationTime = s.smsSendEmpty.LastModificationTime, - LastModifierId = s.smsSendEmpty.LastModifierId, - CreatorName = _cacheService.GetSurnameAsync(s.smsSendEmpty.CreatorId).GetAwaiter().GetResult(), - LastModifierName = _cacheService.GetSurnameAsync(s.smsSendEmpty.LastModifierId).GetAwaiter().GetResult(), - PatientName = s.smsSendEmpty.PatientName, - Content = s.smsSendEmpty.Content, - MobileTelephone = s.smsSendEmpty.MobileTelephone, - PlanSendDate = DataHelper.ConversionDateToString(s.smsSendEmpty.PlanSendDate), - PatientId = s.smsSendEmpty.PatientId, - SmsTypeId = s.smsSendEmpty.SmsTypeId + FollowUpId = s.Key.FollowUpId, + CreationTime = s.Key.CreationTime, + CreatorId = s.Key.CreatorId, + Id = s.Key.Id, + IsComplete = s.Key.IsComplete, + LastModificationTime = s.Key.LastModificationTime, + LastModifierId = s.Key.LastModifierId, + CreatorName = _cacheService.GetSurnameAsync(s.Key.CreatorId).GetAwaiter().GetResult(), + LastModifierName = _cacheService.GetSurnameAsync(s.Key.LastModifierId).GetAwaiter().GetResult(), + PatientName = s.Key.PatientName, + Content = s.Key.Content, + MobileTelephone = s.Key.MobileTelephone, + PlanSendDate = DataHelper.ConversionDateToString(s.Key.PlanSendDate), + PatientId = s.Key.PatientId, + SmsTypeId = s.Key.SmsTypeId }).ToList(); temoDto.PhoneFollowUpWithPatientRegisterDetail = phoneFollowUpWithPatientRegisterDetail; temoDto.SmsSendDetail = smsSendDetail; + entListDto.Add(temoDto); + } diff --git a/src/Shentun.Peis.Domain.Shared/Enums/AITypeFlag.cs b/src/Shentun.Peis.Domain.Shared/Enums/AITypeFlag.cs new file mode 100644 index 0000000..a25f71f --- /dev/null +++ b/src/Shentun.Peis.Domain.Shared/Enums/AITypeFlag.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace Shentun.Peis.Enums +{ + public static class AITypeFlag + { + /// + /// DeepSeek + /// + [Description("DeepSeek")] + public const string DeepSeek = "01"; + + } + + +} diff --git a/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs b/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs index 54bbbed..c8b48fb 100644 --- a/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs +++ b/src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs @@ -44,5 +44,8 @@ namespace Shentun.Peis.Enums [Description("第三方预约对接")] public const string ThirdBooking = "12"; + + [Description("AI对接")] + public const string WebAI = "13"; } }