@ -1,9 +1,11 @@
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Configuration ;
using Newtonsoft.Json ;
using Shentun.Peis.Enums ;
using Shentun.Peis.Models ;
using Shentun.Peis.PlugIns.Sms ;
using SqlSugar ;
using System ;
using System.Collections.Generic ;
using System.IO ;
@ -25,13 +27,16 @@ namespace Shentun.Peis.ThirdBookings
{
private readonly IRepository < ThirdBooking , Guid > _thirdBookingRepository ;
private readonly IRepository < ThirdInterface , Guid > _thirdInterfaceRepository ;
private readonly IRepository < CustomerOrg , Guid > _customerOrgRepository ;
public ThirdBookingAppService (
IRepository < ThirdBooking , Guid > thirdBookingRepository ,
IRepository < ThirdInterface , Guid > thirdInterfaceRepository )
IRepository < ThirdInterface , Guid > thirdInterfaceRepository ,
IRepository < CustomerOrg , Guid > customerOrgRepository )
{
_thirdBookingRepository = thirdBookingRepository ;
_thirdInterfaceRepository = thirdInterfaceRepository ;
_customerOrgRepository = customerOrgRepository ;
}
@ -63,12 +68,14 @@ namespace Shentun.Peis.ThirdBookings
{
customerOrgRegisterId = Guid . Parse ( customerOrgRegisterIdPara ) ;
customerOrgId = Guid . Parse ( customerOrgIdPara ) ;
}
}
else
{
throw new UserFriendlyException ( "请开启第三方预约" ) ;
}
var query = await _thirdBookingRepository . GetQueryableAsync ( ) ;
if ( ! string . IsNullOrWhiteSpace ( input . StartDate ) & & ! string . IsNullOrWhiteSpace ( input . StartDate ) )
{
@ -85,7 +92,9 @@ namespace Shentun.Peis.ThirdBookings
query = query . Where ( m = > m . MedicalStatus = = input . MedicalStatus ) ;
}
var entListDto = query . Select ( s = > new GetThirdBookingListDto
var customerOrgList = await _customerOrgRepository . GetListAsync ( ) ;
var entListDto = query . ToList ( ) . Select ( s = > new GetThirdBookingListDto
{
ThirdBookingId = s . Id ,
Age = s . Age ,
@ -96,7 +105,7 @@ namespace Shentun.Peis.ThirdBookings
PatientName = s . PatientName ,
Phone = s . Phone ,
SexId = GetSexId ( s . SexName ) ,
CustomerOrgId = customerOrgId ,
CustomerOrgId = GetCustomerOrgId ( customerOrgList , customerOrgId , s . ChildCompanyName , s . DepartmentName ) ,
CustomerOrgRegisterId = customerOrgRegisterId ,
} ) . ToList ( ) ;
@ -105,6 +114,84 @@ namespace Shentun.Peis.ThirdBookings
}
///// <summary>
///// 体检预约接口
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpPost]
//public async Task CreateBookingMedicalByExcelAsync(PublicRequestDto input)
//{
// string inputStr = DataHelper.GetInputDecrypt(input.DATA, input.SIGN);
// if (!string.IsNullOrWhiteSpace(inputStr))
// {
// var inputPara = JsonConvert.DeserializeObject<CreateBookingMedicalInputDto>(inputStr);
// if (inputPara != null)
// {
// string peisAdminId = _configuration.GetSection("PeisAdminId").Value;
// string sourceChannel = "1"; //1 正式环境 0 测试环境
// if (!string.IsNullOrWhiteSpace(_configuration.GetSection("SourceChannel").Value))
// {
// sourceChannel = _configuration.GetSection("SourceChannel").Value;
// }
// Guid id = Guid.NewGuid();
// int isExe = await _peisDb.Ado.ExecuteCommandAsync("INSERT INTO public.third_booking(id,patient_name,customer_org_group_id,third_medical_center_id," +
// "id_type,id_no, sex_name, age, booking_date, phone, child_company_name, department_name, marital_status_name,concurrency_stamp," +
// " creation_time, creator_id, last_modification_time, last_modifier_id, medical_status,icode,source_channel) " +
// "VALUES (@id,@patient_name,@customer_org_group_id,@third_medical_center_id," +
// "@id_type,@id_no,@sex_name,@age,@booking_date,@phone,@child_company_name,@department_name,@marital_status_name,@concurrency_stamp," +
// "@creation_time,@creator_id,@last_modification_time,@last_modifier_id,@medical_status,@icode,@source_channel) ;",
// new List<SugarParameter>() {
// new SugarParameter("id",id),
// new SugarParameter("patient_name",inputPara.name),
// new SugarParameter("customer_org_group_id",inputPara.exampackagecode),
// new SugarParameter("third_medical_center_id",inputPara.examcenterid),
// new SugarParameter("id_type",inputPara.idtype),
// new SugarParameter("id_no",inputPara.idno),
// new SugarParameter("sex_name",inputPara.sex),
// new SugarParameter("age",inputPara.age),
// new SugarParameter("booking_date",Convert.ToDateTime(inputPara.bookingdata)),
// new SugarParameter("phone",inputPara.phone),
// new SugarParameter("child_company_name",""),
// new SugarParameter("department_name",""),
// new SugarParameter("marital_status_name",""),
// new SugarParameter("concurrency_stamp",Guid.NewGuid().ToString("N")),
// new SugarParameter("creation_time",DateTime.Now),
// new SugarParameter("creator_id",Guid.Parse(peisAdminId)),
// new SugarParameter("last_modification_time",DateTime.Now),
// new SugarParameter("last_modifier_id",Guid.Parse(peisAdminId)),
// new SugarParameter("medical_status",'0'),
// new SugarParameter("icode",input.ICODE),
// new SugarParameter("source_channel",sourceChannel)
// });
// if (isExe > 0)
// {
// var resultDto = new CreateBookingMedicalDto
// {
// error = "0",
// error_msg = "成功",
// data = new CreateBookingMedicalDetailDto { bookingid = id.ToString() }
// };
// result = DataHelper.GetResultEncrypt(JsonConvert.SerializeObject(resultDto), input.ICODE);
// }
// }
// }
// return result;
//}
/// <summary>
/// 转换性别
@ -124,6 +211,36 @@ namespace Shentun.Peis.ThirdBookings
return SexId ;
}
/// <summary>
/// 获取部门ID
/// </summary>
/// <param name="customerOrgList"></param>
/// <param name="topCustomerOrgId">一级单位ID 集团ID</param>
/// <param name="childCompanyName">子公司名称 预约填的</param>
/// <param name="departmentName">部门名称 部门</param>
/// <returns></returns>
private static Guid ? GetCustomerOrgId ( List < CustomerOrg > customerOrgList , Guid ? topCustomerOrgId , string childCompanyName , string departmentName )
{
if ( topCustomerOrgId ! = null )
{
if ( ! string . IsNullOrWhiteSpace ( childCompanyName ) )
{
var childCompanyEnt = customerOrgList . FirstOrDefault ( f = > f . ParentId = = topCustomerOrgId & & f . DisplayName = = childCompanyName ) ;
if ( childCompanyEnt ! = null )
{
topCustomerOrgId = childCompanyEnt . Id ;
if ( ! string . IsNullOrWhiteSpace ( departmentName ) )
{
var departmentNameEnt = customerOrgList . FirstOrDefault ( f = > f . ParentId = = topCustomerOrgId & & f . DisplayName = = departmentName ) ;
if ( departmentNameEnt ! = null )
{
topCustomerOrgId = departmentNameEnt . Id ;
}
}
}
}
}
return topCustomerOrgId ;
}
}
}