From de2d8210d784be09568bb187a71b376c6dd11fdf Mon Sep 17 00:00:00 2001
From: wxd <123@qq.com>
Date: Fri, 20 Sep 2024 15:52:28 +0800
Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E8=AE=BF=E8=AE=B0=E5=BD=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../PhoneFollowUps/CreatePhoneFollowUpDto.cs | 14 +-
.../PhoneFollowUps/PhoneFollowUpDto.cs | 37 +++
.../PhoneFollowUps/PhoneFollowUpIdInputDto.cs | 12 +
.../PhoneFollowUpListInputDto.cs | 35 +++
.../PhoneFollowUpWithPatientRegisterDto.cs | 11 +
.../PhoneFollowUps/UpdatePhoneFollowUpDto.cs | 35 +++
.../SmsSends/CreateSmsSendDto.cs | 31 ++
.../SmsSends/SmsSendDto.cs | 51 ++++
.../SmsSends/SmsSendIdInputDto.cs | 11 +
.../SmsSends/SmsSendListInputDto.cs | 44 +++
.../PeisApplicationAutoMapperProfile.cs | 9 +
.../PhoneFollowUps/PhoneFollowUpAppService.cs | 259 +++++++++++++++-
.../Shentun.Peis.Application.csproj | 1 +
.../SmsSends/SmsSendAppService.cs | 276 ++++++++++++++++++
.../Enums/FollowUpModeFlag.cs | 40 +++
.../PhoneFollowUps/PhoneFollowUp.cs | 5 +
src/Shentun.Peis.Domain/SmsSends/SmsSend.cs | 7 +-
17 files changed, 862 insertions(+), 16 deletions(-)
create mode 100644 src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs
create mode 100644 src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs
create mode 100644 src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs
create mode 100644 src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs
diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs
index 8487e66..17776ce 100644
--- a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs
+++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/CreatePhoneFollowUpDto.cs
@@ -9,9 +9,19 @@ namespace Shentun.Peis.PhoneFollowUps
public class CreatePhoneFollowUpDto
{
///
- /// 表达式
+ /// 0-corn表达式 1-按天 2-按周 3-按月 4-按年
///
- public string CornValue { get; set; }
+ public char FollowUpMode { get; set; } = '0';
+
+ ///
+ /// FollowUpMode为0时 为corn表达式 其他模式为具体数字
+ ///
+ public string ModeValue { get; set; }
+
+ ///
+ /// 截止时间
+ ///
+ public string EndDate { get; set; }
///
/// 随访主表ID
diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.cs
new file mode 100644
index 0000000..e7b590f
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpDto.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
+ {
+ ///
+ /// 随访内容
+ ///
+ public string FollowUpContent { get; set; }
+ ///
+ /// 回复内容
+ ///
+ public string ReplyContent { get; set; }
+
+
+ ///
+ /// 随访ID
+ ///
+ public Guid FollowUpId { get; set; }
+
+ ///
+ /// 随访日期
+ ///
+ public string PlanFollowDate { get; set; }
+
+ ///
+ /// 是否完成
+ ///
+ public char IsComplete { get; set; }
+
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs
new file mode 100644
index 0000000..d7084f1
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpIdInputDto.cs
@@ -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; }
+ }
+
+}
diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs
new file mode 100644
index 0000000..7b04c08
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpListInputDto.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.Peis.PhoneFollowUps
+{
+ public class PhoneFollowUpListInputDto
+ {
+ ///
+ /// 随访ID
+ ///
+ public Guid? FollowUpId { get; set; }
+
+ ///
+ /// 随访内容、回复内容 支持模糊查询
+ ///
+ public string KeyWord { get; set; }
+
+
+ ///
+ /// 随访日期 格式1999-01-01
+ ///
+ public string StartDate { get; set; }
+
+ ///
+ /// 随访日期 格式1999-01-01
+ ///
+ public string EndDate { get; set; }
+
+ ///
+ /// 是否完成
+ ///
+ public char? IsComplete { get; set; }
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs
new file mode 100644
index 0000000..c8a6b44
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/PhoneFollowUpWithPatientRegisterDto.cs
@@ -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; }
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs
new file mode 100644
index 0000000..3782646
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/PhoneFollowUps/UpdatePhoneFollowUpDto.cs
@@ -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
+ {
+ ///
+ /// 主键
+ ///
+ public Guid PhoneFollowUpId { get; set; }
+
+ ///
+ /// 随访内容
+ ///
+ public string FollowUpContent { get; set; }
+ ///
+ /// 回复内容
+ ///
+ public string ReplyContent { get; set; }
+
+ ///
+ /// 随访日期
+ ///
+ public DateTime? PlanFollowDate { get; set; }
+
+ ///
+ /// 是否完成
+ ///
+ public char IsComplete { get; set; }
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs b/src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs
new file mode 100644
index 0000000..bdab375
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/SmsSends/CreateSmsSendDto.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shentun.Peis.SmsSends
+{
+ public class CreateSmsSendDto
+ {
+ ///
+ /// 0-corn表达式 1-按天 2-按周 3-按月 4-按年
+ ///
+ public char FollowUpMode { get; set; } = '0';
+
+ ///
+ /// FollowUpMode为0时 为corn表达式 其他模式为具体数字
+ ///
+ public string ModeValue { get; set; }
+
+ ///
+ /// 截止时间
+ ///
+ public string EndDate { get; set; }
+
+ ///
+ /// 随访主表ID
+ ///
+ public Guid FollowUpId { get; set; }
+
+
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs b/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs
new file mode 100644
index 0000000..c982ce4
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendDto.cs
@@ -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
+ {
+ ///
+ /// 短信类别ID
+ ///
+ public string SmsTypeId { get; set; }
+
+ ///
+ /// 随访ID
+ ///
+ public Guid FollowUpId { get; set; }
+
+ ///
+ /// 人员ID
+ ///
+ public Guid? PatientId { get; set; }
+
+ ///
+ /// 姓名
+ ///
+ public string PatientName { get; set; }
+
+ ///
+ /// 手机号
+ ///
+ public string MobileTelephone { get; set; }
+
+ ///
+ /// 短信内容 默认一个姓名
+ ///
+ public string Content { get; set; }
+
+ ///
+ /// 是完成
+ ///
+ public char IsComplete { get; set; }
+
+ ///
+ /// 短信推送时间
+ ///
+ public string PlanSendDate { get; set; }
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs b/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs
new file mode 100644
index 0000000..c7ff5f5
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendIdInputDto.cs
@@ -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; }
+ }
+}
diff --git a/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs b/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs
new file mode 100644
index 0000000..6b77668
--- /dev/null
+++ b/src/Shentun.Peis.Application.Contracts/SmsSends/SmsSendListInputDto.cs
@@ -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
+ {
+ ///
+ /// 随访ID
+ ///
+ public Guid? FollowUpId { get; set; }
+
+ ///
+ /// 姓名
+ ///
+ public string PatientName { get; set; }
+ ///
+ /// 手机号
+ ///
+ public string MobileTelephone { get; set; }
+
+ ///
+ /// 是完成
+ ///
+ public char? IsComplete { get; set; }
+
+
+ ///
+ /// 随访日期 格式1999-01-01
+ ///
+ public string StartDate { get; set; }
+
+ ///
+ /// 随访日期 格式1999-01-01
+ ///
+ public string EndDate { get; set; }
+
+
+
+ }
+}
diff --git a/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs b/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs
index 2e0cc28..b6b4f13 100644
--- a/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs
+++ b/src/Shentun.Peis.Application/PeisApplicationAutoMapperProfile.cs
@@ -63,6 +63,7 @@ using Shentun.Peis.PatientRegisters;
using Shentun.Peis.Patients;
using Shentun.Peis.PayModes;
using Shentun.Peis.PersonnelTypes;
+using Shentun.Peis.PhoneFollowUps;
using Shentun.Peis.Poisons;
using Shentun.Peis.PoisonTypes;
using Shentun.Peis.PriceItems;
@@ -87,6 +88,7 @@ using Shentun.Peis.SampleTypes;
using Shentun.Peis.SexHormoneReferenceRanges;
using Shentun.Peis.SexHormoneTerms;
using Shentun.Peis.Sexs;
+using Shentun.Peis.SmsSends;
using Shentun.Peis.SumSummaryReports;
using Shentun.Peis.SuspectedOccupationalDiseases;
using Shentun.Peis.Symptoms;
@@ -591,5 +593,12 @@ public class PeisApplicationAutoMapperProfile : Profile
CreateMap();
CreateMap();
+ CreateMap();
+ CreateMap();
+
+
+ CreateMap();
+
+
}
}
diff --git a/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs b/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs
index 10fee82..8246743 100644
--- a/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs
+++ b/src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs
@@ -1,13 +1,19 @@
-using Microsoft.AspNetCore.Authorization;
+using Cronos;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using Shentun.Peis.CriticalFollowValues;
+using Shentun.Peis.Enums;
using Shentun.Peis.Models;
+using SqlSugar;
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;
+using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.PhoneFollowUps
{
@@ -19,21 +25,252 @@ namespace Shentun.Peis.PhoneFollowUps
public class PhoneFollowUpAppService : ApplicationService
{
private readonly IRepository _phoneFollowUpRepository;
+ private readonly CacheService _cacheService;
+ private readonly IRepository _followUpRepository;
+ private readonly IRepository _patientRegisterRepository;
- public PhoneFollowUpAppService(IRepository phoneFollowUpRepository)
+ public PhoneFollowUpAppService(
+ IRepository phoneFollowUpRepository,
+ CacheService cacheService,
+ IRepository followUpRepository,
+ IRepository patientRegisterRepository
+ )
{
_phoneFollowUpRepository = phoneFollowUpRepository;
+ _cacheService = cacheService;
+ _followUpRepository = followUpRepository;
+ _patientRegisterRepository = patientRegisterRepository;
}
- /////
- ///// 创建电话随访记录
- /////
- /////
- /////
- //public async Task CreateAsync(CreatePhoneFollowUpDto input)
- //{
-
- //}
+ ///
+ /// 获取电话随访记录信息
+ ///
+ ///
+ ///
+ [HttpPost("api/app/PhoneFollowUp/Get")]
+ public async Task GetAsync(PhoneFollowUpIdInputDto input)
+ {
+ var phoneFollowUpEnt = await _phoneFollowUpRepository.GetAsync(input.PhoneFollowUpId);
+ var entityDto = ObjectMapper.Map(phoneFollowUpEnt);
+ entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
+ entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
+ return entityDto;
+ }
+
+
+ ///
+ /// 获取电话随访记录信息
+ ///
+ ///
+ ///
+ [HttpPost("api/app/PhoneFollowUp/GetList")]
+ public async Task> GetListAsync(PhoneFollowUpListInputDto input)
+ {
+ var query = from phoneFollowUp in await _phoneFollowUpRepository.GetQueryableAsync()
+ join followUp in await _followUpRepository.GetQueryableAsync() on phoneFollowUp.FollowUpId equals followUp.Id
+ join patientRegister in await _patientRegisterRepository.GetQueryableAsync() on followUp.PatientRegisterId equals patientRegister.Id
+ orderby patientRegister.Id, phoneFollowUp.PlanFollowDate
+ select new
+ {
+ patientName = patientRegister.PatientName,
+ phoneFollowUp
+ };
+
+ if (input.FollowUpId != null)
+ {
+ query = query.Where(m => m.phoneFollowUp.FollowUpId == input.FollowUpId);
+ }
+
+ if (!string.IsNullOrWhiteSpace(input.KeyWord))
+ {
+ query = query.Where(m => (!string.IsNullOrWhiteSpace(m.phoneFollowUp.FollowUpContent) && m.phoneFollowUp.FollowUpContent.Contains(input.KeyWord))
+ || (!string.IsNullOrWhiteSpace(m.phoneFollowUp.ReplyContent) && m.phoneFollowUp.ReplyContent.Contains(input.KeyWord))
+ );
+ }
+
+ if (input.IsComplete != null)
+ {
+ query = query.Where(m => m.phoneFollowUp.IsComplete == input.IsComplete);
+ }
+
+ if (!string.IsNullOrWhiteSpace(input.StartDate) && !string.IsNullOrWhiteSpace(input.EndDate))
+ {
+ query = query.Where(m => m.phoneFollowUp.PlanFollowDate >= Convert.ToDateTime(input.StartDate)
+ && m.phoneFollowUp.PlanFollowDate <= Convert.ToDateTime(input.EndDate).AddDays(1));
+ }
+
+ var entListDto = query.ToList().Select(s => new PhoneFollowUpWithPatientRegisterDto
+ {
+ FollowUpId = s.phoneFollowUp.FollowUpId,
+ CreationTime = s.phoneFollowUp.CreationTime,
+ ReplyContent = s.phoneFollowUp.ReplyContent,
+ PlanFollowDate = DataHelper.ConversionDateToString(s.phoneFollowUp.PlanFollowDate),
+ CreatorId = s.phoneFollowUp.CreatorId,
+ FollowUpContent = s.phoneFollowUp.ReplyContent,
+ Id = s.phoneFollowUp.Id,
+ IsComplete = s.phoneFollowUp.IsComplete,
+ LastModificationTime = s.phoneFollowUp.LastModificationTime,
+ LastModifierId = s.phoneFollowUp.LastModifierId,
+ CreatorName = _cacheService.GetSurnameAsync(s.phoneFollowUp.CreatorId).GetAwaiter().GetResult(),
+ LastModifierName = _cacheService.GetSurnameAsync(s.phoneFollowUp.LastModifierId).GetAwaiter().GetResult(),
+ PatientName = s.patientName
+ }).ToList();
+
+ return entListDto;
+ }
+
+
+ ///
+ /// 创建电话随访记录
+ ///
+ ///
+ ///
+ [HttpPost("api/app/PhoneFollowUp/Create")]
+ public async Task CreateAsync(CreatePhoneFollowUpDto input)
+ {
+ if (string.IsNullOrWhiteSpace(input.ModeValue))
+ {
+ throw new UserFriendlyException("计划周期不能为空");
+ }
+
+ if (input.FollowUpMode == FollowUpModeFlag.Corn && string.IsNullOrWhiteSpace(input.EndDate))
+ {
+ throw new UserFriendlyException("采用corn表达式时需要截止日期");
+ }
+
+
+ var isPhoneFollowUp = await _phoneFollowUpRepository.CountAsync(c => c.FollowUpId == input.FollowUpId);
+ if (isPhoneFollowUp > 0)
+ {
+ throw new UserFriendlyException("已存在电话随访记录,不允许重复生成");
+ }
+
+ List phoneFollowUpList = new List();
+
+ 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 phoneFollowUpEntity = new PhoneFollowUp(GuidGenerator.Create())
+ {
+ FollowUpContent = input.FollowUpContent,
+ FollowUpId = input.FollowUpId,
+ ReplyContent = input.ReplyContent,
+ PlanFollowDate = occurrence,
+ IsComplete = 'N'
+ };
+
+ phoneFollowUpList.Add(phoneFollowUpEntity);
+ }
+ }
+ 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 phoneFollowUpEntity = new PhoneFollowUp(GuidGenerator.Create())
+ {
+ FollowUpContent = input.FollowUpContent,
+ FollowUpId = input.FollowUpId,
+ ReplyContent = input.ReplyContent,
+ PlanFollowDate = planFollowDate,
+ IsComplete = 'N'
+ };
+
+ phoneFollowUpList.Add(phoneFollowUpEntity);
+ }
+ }
+
+ if (phoneFollowUpList.Any())
+ {
+ await _phoneFollowUpRepository.InsertManyAsync(phoneFollowUpList);
+ }
+ }
+
+ ///
+ /// 修改电话随访记录
+ ///
+ ///
+ ///
+ [HttpPost("api/app/PhoneFollowUp/Update")]
+ public async Task UpdateAsync(UpdatePhoneFollowUpDto input)
+ {
+ var entity = await _phoneFollowUpRepository.GetAsync(input.PhoneFollowUpId);
+
+ entity.IsComplete = input.IsComplete;
+ if (input.PlanFollowDate != null)
+ {
+ entity.PlanFollowDate = Convert.ToDateTime(input.PlanFollowDate);
+ }
+
+ if (!string.IsNullOrWhiteSpace(input.ReplyContent))
+ {
+ entity.ReplyContent = input.ReplyContent;
+ }
+
+ if (!string.IsNullOrWhiteSpace(input.FollowUpContent))
+ {
+ entity.FollowUpContent = input.FollowUpContent;
+ }
+
+ await _phoneFollowUpRepository.UpdateAsync(entity);
+
+ }
+
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ [HttpPost("api/app/PhoneFollowUp/Delete")]
+ public async Task DeleteAsync(PhoneFollowUpIdInputDto input)
+ {
+ await _phoneFollowUpRepository.DeleteAsync(input.PhoneFollowUpId);
+ }
+
}
}
diff --git a/src/Shentun.Peis.Application/Shentun.Peis.Application.csproj b/src/Shentun.Peis.Application/Shentun.Peis.Application.csproj
index 767bf27..7fe0d44 100644
--- a/src/Shentun.Peis.Application/Shentun.Peis.Application.csproj
+++ b/src/Shentun.Peis.Application/Shentun.Peis.Application.csproj
@@ -27,6 +27,7 @@
+
diff --git a/src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs b/src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs
new file mode 100644
index 0000000..a80f87e
--- /dev/null
+++ b/src/Shentun.Peis.Application/SmsSends/SmsSendAppService.cs
@@ -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
+{
+ ///
+ /// 短信随访记录
+ ///
+ [ApiExplorerSettings(GroupName = "Work")]
+ [Authorize]
+ public class SmsSendAppService : ApplicationService
+ {
+ private readonly IRepository _smsSendRepository;
+ private readonly CacheService _cacheService;
+ private readonly IRepository _followUpRepository;
+ private readonly IRepository _patientRegisterRepository;
+ private readonly IRepository _patientRepository;
+
+ public SmsSendAppService(
+ CacheService cacheService,
+ IRepository followUpRepository,
+ IRepository patientRegisterRepository,
+ IRepository smsSendRepository,
+ IRepository patientRepository)
+ {
+ _cacheService = cacheService;
+ _followUpRepository = followUpRepository;
+ _patientRegisterRepository = patientRegisterRepository;
+ _smsSendRepository = smsSendRepository;
+ _patientRepository = patientRepository;
+ }
+
+
+ ///
+ /// 获取短信随访记录信息
+ ///
+ ///
+ ///
+ [HttpPost("api/app/SmsSend/Get")]
+ public async Task GetAsync(SmsSendIdInputDto input)
+ {
+ var smsSendEnt = await _smsSendRepository.GetAsync(input.SmsSendId);
+ var entityDto = ObjectMapper.Map(smsSendEnt);
+ entityDto.CreatorName = await _cacheService.GetSurnameAsync(entityDto.CreatorId);
+ entityDto.LastModifierName = await _cacheService.GetSurnameAsync(entityDto.LastModifierId);
+ return entityDto;
+ }
+
+
+ ///
+ /// 获取短信随访记录信息
+ ///
+ ///
+ ///
+ [HttpPost("api/app/SmsSend/GetList")]
+ public async Task> 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;
+ }
+
+
+ ///
+ /// 创建短信随访记录
+ ///
+ ///
+ ///
+ [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 smsSendList = new List();
+
+ 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);
+ }
+ }
+
+
+
+ ///
+ /// 删除
+ ///
+ ///
+ ///
+ [HttpPost("api/app/SmsSend/Delete")]
+ public async Task DeleteAsync(SmsSendIdInputDto input)
+ {
+ await _smsSendRepository.DeleteAsync(input.SmsSendId);
+ }
+
+
+ }
+}
diff --git a/src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs b/src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs
new file mode 100644
index 0000000..29e7a48
--- /dev/null
+++ b/src/Shentun.Peis.Domain.Shared/Enums/FollowUpModeFlag.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Text;
+
+namespace Shentun.Peis.Enums
+{
+ public static class FollowUpModeFlag
+ {
+ ///
+ /// 按corn表达式生成
+ ///
+ [Description("按corn表达式生成")]
+ public const char Corn = '0';
+
+ ///
+ /// 按天生成
+ ///
+ [Description("按周生成")]
+ public const char Day = '1';
+
+ ///
+ /// 按周生成
+ ///
+ [Description("按周生成")]
+ public const char Week = '2';
+
+ ///
+ /// 按月生成
+ ///
+ [Description("按月生成")]
+ public const char Month = '3';
+
+ ///
+ /// 按年生成
+ ///
+ [Description("按年生成")]
+ public const char Year = '4';
+ }
+}
diff --git a/src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs b/src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs
index 5bc83f1..e85db20 100644
--- a/src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs
+++ b/src/Shentun.Peis.Domain/PhoneFollowUps/PhoneFollowUp.cs
@@ -14,6 +14,11 @@ namespace Shentun.Peis.Models
[Table("phone_follow_up")]
public class PhoneFollowUp : AuditedEntity, IHasConcurrencyStamp
{
+ public PhoneFollowUp(Guid id) : base(id)
+ {
+
+ }
+
/////
///// 病人登记ID
/////
diff --git a/src/Shentun.Peis.Domain/SmsSends/SmsSend.cs b/src/Shentun.Peis.Domain/SmsSends/SmsSend.cs
index 88bb632..0fba484 100644
--- a/src/Shentun.Peis.Domain/SmsSends/SmsSend.cs
+++ b/src/Shentun.Peis.Domain/SmsSends/SmsSend.cs
@@ -14,10 +14,11 @@ namespace Shentun.Peis.Models
[Table("sms_send")]
public class SmsSend : AuditedEntity, IHasConcurrencyStamp
{
+ public SmsSend(Guid id) : base(id) { }
+
///
- /// 短信类别ID
+ /// 短信类别ID 随访-01
///
-
[Column("sms_type_id")]
[StringLength(2)]
public string SmsTypeId { get; set; }
@@ -26,7 +27,7 @@ namespace Shentun.Peis.Models
/// 随访ID
///
[Column("follow_up_id")]
- public Guid? FollowUpId { get; set; }
+ public Guid FollowUpId { get; set; }
/////
///// 随访计划ID