Browse Source

短信推送计划

master
wxd 1 year ago
parent
commit
32f904d447
  1. 89
      src/Shentun.ColumnReferencePlugIns/Sms/CreateThirdPartySmsTaskInputDto.cs
  2. 72
      src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs
  3. 5
      src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs

89
src/Shentun.ColumnReferencePlugIns/Sms/CreateThirdPartySmsTaskInputDto.cs

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shentun.Peis.PlugIns.Sms
{
public class CreateThirdPartySmsTaskInputDto
{
/// <summary>
/// 短信类别ID
/// </summary>
public Guid SmsTypeId { get; set; }
/// <summary>
/// 人员ID
/// </summary>
public string PersonId { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string PersonName { get; set; }
/// <summary>
/// 手机号国家代码
/// </summary>
public string CountryCode { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string MobileTelephone { get; set; }
/// <summary>
/// 短信内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 应用ID
/// </summary>
public Guid SmsAppId { get; set; }
/// <summary>
/// 第三方系统唯一ID
/// </summary>
public string? ThirdId { get; set; }
/// <summary>
/// 任务周期类别
/// </summary>
public char TaskCycleType { get; set; }
/// <summary>
/// 任务表达式
/// </summary>
public string? TaskCorn { get; set; }
/// <summary>
/// 停止执行时间
/// </summary>
public string? StopTime { get; set; }
/// <summary>
/// 发送者用户ID
/// </summary>
public string? SenderId { get; set; }
/// <summary>
/// 发送者用户名
/// </summary>
public string? SenderName { get; set; }
/// <summary>
/// 计划发送时间集合
/// </summary>
public List<string> PlanSendTimes { get; set; }
}
}

72
src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs

@ -1,11 +1,14 @@
using Cronos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Shentun.Peis.Enums;
using Shentun.Peis.Models;
using Shentun.Peis.PlugIns.Sms;
using Shentun.Peis.SmsSends;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -27,19 +30,22 @@ namespace Shentun.Peis.SmsSends
private readonly IRepository<FollowUp, Guid> _followUpRepository;
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
private readonly IRepository<Patient, Guid> _patientRepository;
private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
public SmsSendAppService(
CacheService cacheService,
IRepository<FollowUp, Guid> followUpRepository,
IRepository<PatientRegister, Guid> patientRegisterRepository,
IRepository<SmsSend, Guid> smsSendRepository,
IRepository<Patient, Guid> patientRepository)
IRepository<Patient, Guid> patientRepository,
IRepository<ThirdInterface, Guid> thirdInterfaceRepository)
{
_cacheService = cacheService;
_followUpRepository = followUpRepository;
_patientRegisterRepository = patientRegisterRepository;
_smsSendRepository = smsSendRepository;
_patientRepository = patientRepository;
_thirdInterfaceRepository = thirdInterfaceRepository;
}
@ -158,6 +164,7 @@ namespace Shentun.Peis.SmsSends
where followUp.Id == input.FollowUpId
select new
{
patientRegister = patientRegister,
patientName = patientRegister.PatientName,
mobileTelephone = patient.MobileTelephone,
patientId = patient.Id
@ -189,7 +196,7 @@ namespace Shentun.Peis.SmsSends
PatientId = patientRegisterEnt.patientId,
PlanSendDate = occurrence,
SmsTypeId = "01",
IsComplete = 'N'
IsComplete = 'Y'
};
smsSendList.Add(smsSendEntity);
@ -235,7 +242,7 @@ namespace Shentun.Peis.SmsSends
planFollowDate = planFollowDate.AddYears(i);
}
var smsSendEntity = new SmsSend(GuidGenerator.Create())
{
FollowUpId = input.FollowUpId,
@ -245,7 +252,7 @@ namespace Shentun.Peis.SmsSends
PatientId = patientRegisterEnt.patientId,
PlanSendDate = planFollowDate,
SmsTypeId = "01",
IsComplete = 'N'
IsComplete = 'Y'
};
smsSendList.Add(smsSendEntity);
@ -255,6 +262,10 @@ namespace Shentun.Peis.SmsSends
if (smsSendList.Any())
{
await _smsSendRepository.InsertManyAsync(smsSendList);
//生成短信平台推送计划
await PushCriticalSmsAsync(patientRegisterEnt.patientRegister, smsSendList.Select(s => DataHelper.ConversionDateToString(s.PlanSendDate)).ToList());
}
}
@ -272,5 +283,58 @@ namespace Shentun.Peis.SmsSends
}
/// <summary>
/// 推送体检报告通知短信
/// </summary>
/// <param name="patientRegister"></param>
/// <param name="planSendTimes"></param>
/// <returns></returns>
private async Task PushCriticalSmsAsync(PatientRegister patientRegister, List<string> planSendTimes)
{
var smsThirdInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(o => o.ThirdInterfaceType ==
ThirdInterfaceTypeFlag.CriticalSmsPush);
if (smsThirdInterface != null && smsThirdInterface.IsActive == 'Y')
{
var parmValue = smsThirdInterface.ParmValue;
var configurationBuilder = new ConfigurationBuilder()
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
var interfaceConfig = configurationBuilder.Build();
var pushApiAddress = interfaceConfig.GetSection("Interface").GetSection("PushApiAddress").Value;
var isEnableSms = interfaceConfig.GetSection("Interface").GetSection("IsActive").Value;
if (!string.IsNullOrWhiteSpace(isEnableSms)
&& isEnableSms == "Y")
{
SmsPlugIns smsPlugIns = new SmsPlugIns(smsThirdInterface.Id);
var smsAppId = Guid.Parse(interfaceConfig.GetSection("Interface").GetSection("SmsAppId").Value);
var smsTypeId = Guid.Parse(interfaceConfig.GetSection("Interface").GetSection("SmsTypeId").Value);
var patientEnt = await _patientRepository.FirstOrDefaultAsync(f => f.Id == patientRegister.PatientId);
if (patientEnt != null)
{
var inputDto = new CreateThirdPartySmsTaskInputDto
{
SmsAppId = smsAppId,
SmsTypeId = smsTypeId,
Content = patientRegister.PatientName,
CountryCode = "86",
MobileTelephone = patientEnt.MobileTelephone,
PersonId = patientRegister.PatientId.ToString(),
PersonName = patientRegister.PatientName,
SenderId = "admin",
SenderName = "体检",
StopTime = "",
TaskCorn = "",
TaskCycleType = '2',
ThirdId = patientRegister.Id.ToString(),
PlanSendTimes = planSendTimes
};
await smsPlugIns.CallSmsAppServiceAsync<CreateThirdPartySmsTaskInputDto, Task>(pushApiAddress, inputDto);
}
}
}
}
}
}

5
src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs

@ -36,7 +36,10 @@ namespace Shentun.Peis.Enums
[Description("同步组合项目价格")]
public const string SyncAsbitemPrice = "09";
[Description("短信推送")]
[Description("报告短信推送")]
public const string SmsPush = "10";
[Description("危急值随访短信推送")]
public const string CriticalSmsPush = "11";
}
}
Loading…
Cancel
Save