17 changed files with 862 additions and 16 deletions
-
14src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs
-
37src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.cs
-
12src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs
-
35src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs
-
11src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs
-
35src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs
-
31src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs
-
51src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs
-
11src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs
-
44src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs
-
9src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs
-
259src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs
-
1src/Shentun.Peis.Application/Shentun.Peis.Application.csproj
-
276src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs
-
40src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs
-
5src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs
-
7src/Shentun.Peis.Domain/SmsSends/SmsSend.cs
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.PhoneFollowUps |
|||
{ |
|||
public class PhoneFollowUpDto : AuditedEntityDtoName |
|||
{ |
|||
/// <summary>
|
|||
/// 随访内容
|
|||
/// </summary>
|
|||
public string FollowUpContent { get; set; } |
|||
/// <summary>
|
|||
/// 回复内容
|
|||
/// </summary>
|
|||
public string ReplyContent { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 随访ID
|
|||
/// </summary>
|
|||
public Guid FollowUpId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访日期
|
|||
/// </summary>
|
|||
public string PlanFollowDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否完成
|
|||
/// </summary>
|
|||
public char IsComplete { get; set; } |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.PhoneFollowUps |
|||
{ |
|||
public class PhoneFollowUpIdInputDto |
|||
{ |
|||
public Guid PhoneFollowUpId { get; set; } |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.PhoneFollowUps |
|||
{ |
|||
public class PhoneFollowUpListInputDto |
|||
{ |
|||
/// <summary>
|
|||
/// 随访ID
|
|||
/// </summary>
|
|||
public Guid? FollowUpId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访内容、回复内容 支持模糊查询
|
|||
/// </summary>
|
|||
public string KeyWord { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 随访日期 格式1999-01-01
|
|||
/// </summary>
|
|||
public string StartDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访日期 格式1999-01-01
|
|||
/// </summary>
|
|||
public string EndDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否完成
|
|||
/// </summary>
|
|||
public char? IsComplete { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.PhoneFollowUps |
|||
{ |
|||
public class PhoneFollowUpWithPatientRegisterDto : PhoneFollowUpDto |
|||
{ |
|||
public string PatientName { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.PhoneFollowUps |
|||
{ |
|||
public class UpdatePhoneFollowUpDto |
|||
{ |
|||
/// <summary>
|
|||
/// 主键
|
|||
/// </summary>
|
|||
public Guid PhoneFollowUpId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访内容
|
|||
/// </summary>
|
|||
public string FollowUpContent { get; set; } |
|||
/// <summary>
|
|||
/// 回复内容
|
|||
/// </summary>
|
|||
public string ReplyContent { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访日期
|
|||
/// </summary>
|
|||
public DateTime? PlanFollowDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否完成
|
|||
/// </summary>
|
|||
public char IsComplete { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.SmsSends |
|||
{ |
|||
public class CreateSmsSendDto |
|||
{ |
|||
/// <summary>
|
|||
/// 0-corn表达式 1-按天 2-按周 3-按月 4-按年
|
|||
/// </summary>
|
|||
public char FollowUpMode { get; set; } = '0'; |
|||
|
|||
/// <summary>
|
|||
/// FollowUpMode为0时 为corn表达式 其他模式为具体数字
|
|||
/// </summary>
|
|||
public string ModeValue { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 截止时间
|
|||
/// </summary>
|
|||
public string EndDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访主表ID
|
|||
/// </summary>
|
|||
public Guid FollowUpId { get; set; } |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.SmsSends |
|||
{ |
|||
public class SmsSendDto : AuditedEntityDtoName |
|||
{ |
|||
/// <summary>
|
|||
/// 短信类别ID
|
|||
/// </summary>
|
|||
public string SmsTypeId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访ID
|
|||
/// </summary>
|
|||
public Guid FollowUpId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 人员ID
|
|||
/// </summary>
|
|||
public Guid? PatientId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机号
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 短信内容 默认一个姓名
|
|||
/// </summary>
|
|||
public string Content { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是完成
|
|||
/// </summary>
|
|||
public char IsComplete { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 短信推送时间
|
|||
/// </summary>
|
|||
public string PlanSendDate { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.SmsSends |
|||
{ |
|||
public class SmsSendIdInputDto |
|||
{ |
|||
public Guid SmsSendId { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.SmsSends |
|||
{ |
|||
public class SmsSendListInputDto |
|||
{ |
|||
/// <summary>
|
|||
/// 随访ID
|
|||
/// </summary>
|
|||
public Guid? FollowUpId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
/// <summary>
|
|||
/// 手机号
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是完成
|
|||
/// </summary>
|
|||
public char? IsComplete { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 随访日期 格式1999-01-01
|
|||
/// </summary>
|
|||
public string StartDate { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 随访日期 格式1999-01-01
|
|||
/// </summary>
|
|||
public string EndDate { get; set; } |
|||
|
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,276 @@ |
|||
using Cronos; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Shentun.Peis.Enums; |
|||
using Shentun.Peis.Models; |
|||
using Shentun.Peis.SmsSends; |
|||
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; |
|||
|
|||
namespace Shentun.Peis.SmsSends |
|||
{ |
|||
/// <summary>
|
|||
/// 短信随访记录
|
|||
/// </summary>
|
|||
[ApiExplorerSettings(GroupName = "Work")] |
|||
[Authorize] |
|||
public class SmsSendAppService : ApplicationService |
|||
{ |
|||
private readonly IRepository<SmsSend, Guid> _smsSendRepository; |
|||
private readonly CacheService _cacheService; |
|||
private readonly IRepository<FollowUp, Guid> _followUpRepository; |
|||
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository; |
|||
private readonly IRepository<Patient, Guid> _patientRepository; |
|||
|
|||
public SmsSendAppService( |
|||
CacheService cacheService, |
|||
IRepository<FollowUp, Guid> followUpRepository, |
|||
IRepository<PatientRegister, Guid> patientRegisterRepository, |
|||
IRepository<SmsSend, Guid> smsSendRepository, |
|||
IRepository<Patient, Guid> patientRepository) |
|||
{ |
|||
_cacheService = cacheService; |
|||
_followUpRepository = followUpRepository; |
|||
_patientRegisterRepository = patientRegisterRepository; |
|||
_smsSendRepository = smsSendRepository; |
|||
_patientRepository = patientRepository; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取短信随访记录信息
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/SmsSend/Get")] |
|||
public async Task<SmsSendDto> GetAsync(SmsSendIdInputDto input) |
|||
{ |
|||
var smsSendEnt = await _smsSendRepository.GetAsync(input.SmsSendId); |
|||
var entityDto = ObjectMapper.Map<SmsSend, SmsSendDto>(smsSendEnt); |
|||
entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId); |
|||
entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId); |
|||
return entityDto; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 获取短信随访记录信息
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/SmsSend/GetList")] |
|||
public async Task<List<SmsSendDto>> GetListAsync(SmsSendListInputDto input) |
|||
{ |
|||
var query = from smsSend in await _smsSendRepository.GetQueryableAsync() |
|||
orderby smsSend.FollowUpId, smsSend.PlanSendDate |
|||
select new |
|||
{ |
|||
smsSend |
|||
}; |
|||
|
|||
if (input.FollowUpId != null) |
|||
{ |
|||
query = query.Where(m => m.smsSend.FollowUpId == input.FollowUpId); |
|||
} |
|||
|
|||
if (!string.IsNullOrWhiteSpace(input.PatientName)) |
|||
{ |
|||
query = query.Where(m => !string.IsNullOrWhiteSpace(m.smsSend.PatientName) && m.smsSend.PatientName.Contains(input.PatientName)); |
|||
} |
|||
|
|||
if (!string.IsNullOrWhiteSpace(input.MobileTelephone)) |
|||
{ |
|||
query = query.Where(m => !string.IsNullOrWhiteSpace(m.smsSend.MobileTelephone) && m.smsSend.MobileTelephone.Contains(input.MobileTelephone)); |
|||
} |
|||
|
|||
if (input.IsComplete != null) |
|||
{ |
|||
query = query.Where(m => m.smsSend.IsComplete == input.IsComplete); |
|||
} |
|||
|
|||
if (!string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.EndDate)) |
|||
{ |
|||
query = query.Where(m => m.smsSend.PlanSendDate >= Convert.ToDateTime(input.StartDate) |
|||
&& m.smsSend.PlanSendDate <= Convert.ToDateTime(input.EndDate).AddDays(1)); |
|||
} |
|||
|
|||
var entListDto = query.ToList().Select(s => new SmsSendDto |
|||
{ |
|||
FollowUpId = s.smsSend.FollowUpId, |
|||
CreationTime = s.smsSend.CreationTime, |
|||
CreatorId = s.smsSend.CreatorId, |
|||
Id = s.smsSend.Id, |
|||
IsComplete = s.smsSend.IsComplete, |
|||
LastModificationTime = s.smsSend.LastModificationTime, |
|||
LastModifierId = s.smsSend.LastModifierId, |
|||
CreatorName = _cacheService.GetSurnameAsync(s.smsSend.CreatorId).GetAwaiter().GetResult(), |
|||
LastModifierName = _cacheService.GetSurnameAsync(s.smsSend.LastModifierId).GetAwaiter().GetResult(), |
|||
PatientName = s.smsSend.PatientName, |
|||
Content = s.smsSend.Content, |
|||
MobileTelephone = s.smsSend.MobileTelephone, |
|||
PlanSendDate = DataHelper.ConversionDateToString(s.smsSend.PlanSendDate), |
|||
PatientId = s.smsSend.PatientId, |
|||
SmsTypeId = s.smsSend.SmsTypeId |
|||
}).ToList(); |
|||
|
|||
return entListDto; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 创建短信随访记录
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/SmsSend/Create")] |
|||
public async Task CreateAsync(CreateSmsSendDto input) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(input.ModeValue)) |
|||
{ |
|||
throw new UserFriendlyException("计划周期不能为空"); |
|||
} |
|||
|
|||
if (input.FollowUpMode == FollowUpModeFlag.Corn && string.IsNullOrWhiteSpace(input.EndDate)) |
|||
{ |
|||
throw new UserFriendlyException("采用corn表达式时需要截止日期"); |
|||
} |
|||
|
|||
|
|||
var isSmsSend = await _smsSendRepository.CountAsync(c => c.FollowUpId == input.FollowUpId); |
|||
if (isSmsSend > 0) |
|||
{ |
|||
throw new UserFriendlyException("已存在短信随访记录,不允许重复生成"); |
|||
} |
|||
|
|||
List<SmsSend> smsSendList = new List<SmsSend>(); |
|||
|
|||
var patientRegisterEnt = (from followUp in await _followUpRepository.GetQueryableAsync() |
|||
join patientRegister in await _patientRegisterRepository.GetQueryableAsync() |
|||
on followUp.PatientRegisterId equals patientRegister.Id |
|||
join patient in await _patientRepository.GetQueryableAsync() |
|||
on patientRegister.PatientId equals patient.Id |
|||
where followUp.Id == input.FollowUpId |
|||
select new |
|||
{ |
|||
patientName = patientRegister.PatientName, |
|||
mobileTelephone = patient.MobileTelephone, |
|||
patientId = patient.Id |
|||
}).FirstOrDefault(); |
|||
|
|||
if (patientRegisterEnt == null) |
|||
{ |
|||
throw new UserFriendlyException("随访数据不存在"); |
|||
} |
|||
|
|||
if (input.FollowUpMode == FollowUpModeFlag.Corn) |
|||
{ |
|||
//corn表达式
|
|||
#region 解析Cron表达式
|
|||
|
|||
try |
|||
{ |
|||
var schedule = CronExpression.Parse(input.ModeValue, CronFormat.IncludeSeconds); |
|||
var occurrences = schedule.GetOccurrences(DateTime.UtcNow, Convert.ToDateTime(input.EndDate).ToUniversalTime()); //获取截止时间前所有的计划时间
|
|||
|
|||
foreach (var occurrence in occurrences) |
|||
{ |
|||
var smsSendEntity = new SmsSend(GuidGenerator.Create()) |
|||
{ |
|||
FollowUpId = input.FollowUpId, |
|||
Content = patientRegisterEnt.patientName, |
|||
MobileTelephone = patientRegisterEnt.mobileTelephone, |
|||
PatientName = patientRegisterEnt.patientName, |
|||
PatientId = patientRegisterEnt.patientId, |
|||
PlanSendDate = occurrence, |
|||
SmsTypeId = "01", |
|||
IsComplete = 'N' |
|||
}; |
|||
|
|||
smsSendList.Add(smsSendEntity); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
throw new UserFriendlyException("Corn表达式不正确"); |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
else |
|||
{ |
|||
//其他模式
|
|||
int planCount = 0; |
|||
try |
|||
{ |
|||
planCount = Convert.ToInt32(input.ModeValue); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
throw new UserFriendlyException("Corn表达式不正确"); |
|||
} |
|||
|
|||
for (int i = 0; i < planCount; i++) |
|||
{ |
|||
DateTime planFollowDate = DateTime.Now; |
|||
if (input.FollowUpMode == FollowUpModeFlag.Day) |
|||
{ |
|||
planFollowDate = planFollowDate.AddDays(i); |
|||
} |
|||
else if (input.FollowUpMode == FollowUpModeFlag.Week) |
|||
{ |
|||
planFollowDate = planFollowDate.AddDays(7 * i); |
|||
} |
|||
else if (input.FollowUpMode == FollowUpModeFlag.Month) |
|||
{ |
|||
planFollowDate = planFollowDate.AddMonths(i); |
|||
} |
|||
else if (input.FollowUpMode == FollowUpModeFlag.Year) |
|||
{ |
|||
planFollowDate = planFollowDate.AddYears(i); |
|||
} |
|||
|
|||
|
|||
var smsSendEntity = new SmsSend(GuidGenerator.Create()) |
|||
{ |
|||
FollowUpId = input.FollowUpId, |
|||
Content = patientRegisterEnt.patientName, |
|||
MobileTelephone = patientRegisterEnt.mobileTelephone, |
|||
PatientName = patientRegisterEnt.patientName, |
|||
PatientId = patientRegisterEnt.patientId, |
|||
PlanSendDate = planFollowDate, |
|||
SmsTypeId = "01", |
|||
IsComplete = 'N' |
|||
}; |
|||
|
|||
smsSendList.Add(smsSendEntity); |
|||
} |
|||
} |
|||
|
|||
if (smsSendList.Any()) |
|||
{ |
|||
await _smsSendRepository.InsertManyAsync(smsSendList); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 删除
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost("api/app/SmsSend/Delete")] |
|||
public async Task DeleteAsync(SmsSendIdInputDto input) |
|||
{ |
|||
await _smsSendRepository.DeleteAsync(input.SmsSendId); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.Enums |
|||
{ |
|||
public static class FollowUpModeFlag |
|||
{ |
|||
/// <summary>
|
|||
/// 按corn表达式生成
|
|||
/// </summary>
|
|||
[Description("按corn表达式生成")] |
|||
public const char Corn = '0'; |
|||
|
|||
/// <summary>
|
|||
/// 按天生成
|
|||
/// </summary>
|
|||
[Description("按周生成")] |
|||
public const char Day = '1'; |
|||
|
|||
/// <summary>
|
|||
/// 按周生成
|
|||
/// </summary>
|
|||
[Description("按周生成")] |
|||
public const char Week = '2'; |
|||
|
|||
/// <summary>
|
|||
/// 按月生成
|
|||
/// </summary>
|
|||
[Description("按月生成")] |
|||
public const char Month = '3'; |
|||
|
|||
/// <summary>
|
|||
/// 按年生成
|
|||
/// </summary>
|
|||
[Description("按年生成")] |
|||
public const char Year = '4'; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue